Adding "timbre" to (almost) pure modulated sin tones

Hello everybody, I am new to audacity. I want to produce songs using it. I do not like DAWs because they sound “digital”.
My problem is I invented some songs requiring many kind of different instruments, but I can only play the guitar.
E.g. in one sound I need the trumpet (I tried MIDI, it sounds really bad and it’s very time-consuming to write). What I did is this: I recorded myself whistling the melody I wanted the trumpet to play. Then I lowered down the pitch by 2 octaves. It sounds good! But my whistle is almost a pure tone, although it is modulated in frequency and amplitude (these modulations are what I would find time-expensive to reproduce in MIDI).

What I would like to do is process my transposed whistle and for each wave I would like to add some frequencies to make it more similar to a trumpet (trumpet is just an example here, the same process should work for any instruments). It should be a bit like adding to each period of my whistle one one or more sin functions with greater frequencies but lesser amplitude, but in phase with it (because of frequency modulation I would like to do it period by period).

So what I would like to do is to change and almost purely sin tone to imitate the envelope of real musical instruments, by retaining the same main frequency and amplitude. This is basically the idea. I am open to suggestion and criticism on how to put it into practice. ASAIK there is no audacity plugin to do this, so I would need to develop it. Unfortunately I am very new to signal processing, although I know Lisp and programming in general.

I don’t guarantee that this will produce the musical timbre that you want, but this is a bit of information concerning adding harmonics to sine waves:

A sine wave can be said to be the “simplest” waveform in that it may be fully described as a single periodic oscillation (with a given phase and amplitude). If we change (“distort”) the “shape” of the waveform, then it is o longer a sine wave and can no longer be described as a single frequency - in other words, we have added harmonic frequencies to the tone.

One of the easiest ways to change the shape of the waveform is to clip off the peaks. This is called “hard clipping” and sounds similar to a “fuzz box” effect.
The “Limiter” effect in Audacity can produce this effect if you select the “hard clipping” option (http://manual.audacityteam.org/o/man/limiter.html).
Clipping off the peaks as a straight line (as shown below) produces an infinite series of harmonics that are exact odd multiples of the original sine wave. For example, if the original tone is 100 Hz, the harmonics will be at 300, 500, 700, 900…Hz with gradually diminishing amplitude.
clipping.png
We can also clip audio using the Nyquist function “clip”.
For example, to clip at a linear amplitude of 0.75 (about -2.5 dB) we can use the code:

(clip *track* 0.75)

This code may be run in the Nyquist Prompt effect (http://manual.audacityteam.org/o/man/nyquist_prompt.html).
track” represents the sound that is passed by Audacity from the track selection to Nyquist.

If we want to produce even harmonics rather than odd harmonics, we can clip just one side of the waveform - say the positive going peaks.
The code above clipped at +0.75 and -0.75. If we want to clip at (only) +0.75, one way that we can do it is to raise the waveform by +0.25 (add 0.25 to the value of every sample), and then clip at +/- 1.0. Because we have raised the sine tone by +0.25, it is now in the range of -0.75 to +1.25, so when we clip at +/- 1.0 it only clips the peaks that are above +1.0 (there are no peaks below -1.0). Then we need to drop the waveform back down so that it is not so offset from the zero line. We can get it reasonably close by subtracting 0.25 from every sample, or, adding -0.25 (minus 0.25).
Here it is written as three distinct steps:

(setf *track* (sum 0.25 *track*))
(setf *track* (clip *track* 1.0))
(sum *track* -0.25)

The first line modified track by adding 0.25.
The second line modified the new value of track by clipping at +/- 1.0
The third then adds -0.5 and that produces the “value” (which is a “sound”) that is passed back to Audacity.
top-clipping.png
Nyquist includes other functions that may be used for “wave shaping”, in particular the function “SHAPE” (http://www.cs.cmu.edu/~rbd/doc/nyquist/part8.html#index447)
You can see some examples of the SHAPE function in this “waveshaper distortion” effect: https://forum.audacityteam.org/t/distortion-effect/33184/1

One limitation that you will find using this on “natural” sounds, is that the shaping is a function of amplitude. If we consider the simple clipping effect in the first example, if the “input” sound is bellow the clipping threshold, then the sound will be unmodified. One possible way to work around this limitation would be to even out the amplitude before applying the waveshaping function. The “Limiter” effect could help here by using the “Soft Limiter” setting, with “makeup gain” enabled, ensuring that the limiter threshold is low enough that it catches all of the sound that you want to processes. You may then want to shape the amplitude of each individual note after apply the waveshaper (possibly using the Envelope tool, or another Nyquist script).

I see, thanks. But as an electronic music artist, I would need to reshape the sin waveform into another one. I wish to have complete control of all harmonics and overtones if I want to sintetize my virtual instruments. What I would really need is to process individual samples between two zero crossings. Can Nyquist do that and do that quickly? If not, I won’t invest time in learning Nyquist but rather do it in C, reading and writing WAV files using libsndfile. I will then feed the output to Audacity for further processing that audacity does so well.

If you’re familiar with programming in C (I’m not) then you may be better to program in C.

Audacity is a DAW too, even if some would rather call it an audio editor.

My problem is I invented some songs requiring many kind of different instruments, but I can only play the guitar.
E.g. in one sound I need the trumpet (I tried MIDI, it sounds really bad and it’s very time-consuming to write).

It’s time consuming allright. And to get a good sound, you’ll need one of the top-level instruments banks. These are very, very expensive. But they are what’s used for most movie scores these days. Only big budget flicks can still afford a symphony orchestra and real recordings.

What I did is this: I recorded myself whistling the melody I wanted the trumpet to play. Then I lowered down the pitch by 2 octaves. It sounds good! But my whistle is almost a pure tone, although it is modulated in frequency and amplitude (these modulations are what I would find time-expensive to reproduce in MIDI).

I’m not sure, but it sounds like a vocoder plugin would do that.

What I would like to do is process my transposed whistle and for each wave I would like to add some frequencies to make it more similar to a trumpet (trumpet is just an example here, the same process should work for any instruments). It should be a bit like adding to each period of my whistle one or more sin functions with greater frequencies but lesser amplitude, but in phase with it (because of frequency modulation I would like to do it period by period).

There must be some synthesizer plugin around that is capable of doing just that. Unfortunately, I don’t know much about synths, but have you considered asking on one of the many synth fora?

I’ve seen this done live. So I know it is possible.

So what I would like to do is to change and almost purely sin tone to imitate the envelope of real musical instruments, by retaining the same main frequency and amplitude. This is basically the idea. I am open to suggestion and criticism on how to put it into practice. ASAIK there is no audacity plugin to do this, so I would need to develop it. Unfortunately I am very new to signal processing, although I know Lisp and programming in general.

If you know Lisp, Nyquist is where I would start. But I don’t know anything about programming for audio, so take this as an utterly uninformed reflection. :laughing: