Wave Modulation Synthesis For Programmers Last ... - Impala Utopia

May 7, 2005 - Making Music with ... Fourier theory, all sounds are constructed from a multitude of sine waves at differing ..... There are probably hundreds of different methods, but in my infinite mathematical wisdom. (not!), these were the ...
422KB taille 14 téléchargements 275 vues
Modulation

http://www.analoguesque.com/modsynthesis.htm

Sound Designs

Wave Modulation Synthesis For Programmers

Last Changed 01/19/2005

Some Books on the subject ...

Computer MusicThe Csound Book Real Sound Sound Synthesis Computer Sound Software Charles Dodge Richard Boulanger Synthesis for and Sampling Design Synthesizers Interactive... Best Price $45.00Best Price $47.55 Martin Russ Eduardo Miranda Jim Aikin Perry R. Cook or or Best Price $29.99Best Price $46.94Best Price $17.37 Buy New $71.95 Buy New $65.00Best Price $36.82 or or or or Buy New $32.95 Buy New $49.99 Buy New $19.77 Buy New $39.00

Analog Synthesis Power Tools for Users' Guide to Computer Sound Synthesizer Sound Synthesis Synthesis for the Digital Sound Quick Guide to Reinhard Schmitz Programm... with... Ele... Synthesis by Analogue Best Price $99.98 Jim Aikin Simon Millward Eduardo Reck Physical ... Synthesis or Buy New Best Price $14.47 Miran... Best Price $0.50 Lutz Trautmann Ian Waugh or Best Price $39.99 or Buy New Best Price $109.19 Best Price $10.73 Buy New $16.47 Sound synthesis Sound Synthesis Terence Thomas Terence Thomas Best Price $24.95Best Price $15.99 or Buy New or Buy New Analog Days Synthesizer Making Music with Synthesizers Frank Trocco Programming Your Computer 2E and Computers Best Price $18.95 Brent Hurtig Brent Edstrom Brent Hurtig or Buy New Best Price $9.50 Best Price $16.15 Best Price $3.40 or or or Buy New Buy New $10.17 Buy New $33.96 Sound Synthesis and Sampling CD-ROM Martin Russ Best Price $89.95

A. Sine Wave Modulation (FM Variant) Variables used throughout the document: Variables Description Hz

1 sur 12

Frequency in Hertz (cycles per second)

5/07/05 13:58

Modulation

http://www.analoguesque.com/modsynthesis.htm

SR

Sampling Rate in Hertz

O

Operator/Output

F

Frequency of Operator

A

Amplitude of Operator

FB

Feedback of Operator into itself

FI

Feed-In of an Operator into another Operator

T

Samples/Ticks (time)

L

Length of sample (in samples)

p

Pi = 3.1415

Phase

Phase Offset Percentage

PH

Phase Offset

1. The Basis of all Sounds - The Sine Wave The smallest building block of any sound in the real world is the Sine wave, and according to Fourier theory, all sounds are constructed from a multitude of sine waves at differing frequencies and amplitudes. I won't explain the dynamics of this theory, but it essentially means that you could create any sound by adding different frequencies of sine wave together. Harmonic sounds generally consist of sine waves which are multiples of each other, while noises or inharmonic sounds consist of sine waves at inharmonic frequencies. Since we now know that sine waves are what we need, let us start off by defining how a single sine wave is generated. The formula for a simple sine wave is as follows: Equation A1 - Simple Sine Wave O = A * (sin(F * T)) To correctly calculate the waveform, we first need to calculate the value of F in the equation, which determines the period (frequency) of the waveform in Hertz. This is calculated as follows: F = (2p * Hz) / SR Obviously Hz is the actual frequency we are looking for, but in the equation F is required to produce a waveform at Hz frequency. Thus if we wanted to render 1000 samples of a 440 Hz sine wave, at a maximum amplitude of 32760 (this is around the maximum amplitude value for 16-bit recording), and at a sampling rate of 22000 Hz, we would use the following Visual Basic code: VB5 Code A1 Dim F, Pi as Single Dim SR, A, L, Hz, O as Integer Hz = 440 L = 1000 A = 32760 SR = 22000 Pi = 3.1415 F = (2 * Pi * Hz) / SR For T = 0 to L O = int(A * (sin(F * T))) Next T

This coding will produce 1000 samples of a 440 Hz sine wave at a maximum amplitude of

2 sur 12

5/07/05 13:58

Modulation

http://www.analoguesque.com/modsynthesis.htm 32760. Plotting each value of O on an X-Y graph will produce the following representation of a sine wave: Figure 1 - Simple Sine Wave

It is clear that if sounds are made up of a multitude of sine waves, using only a single sine wave is not going to produce very interesting results. A first suggestion would be to add several sine waves together and see what we get. This brings us to our first form of synthesis - Additive Synthesis. 2. Additive Synthesis In its most crude form, Additive Synthesis is simply the result of adding different frequencies of sine wave together to form a sound. If you created several sine waves using Equation 1, to implement additive synthesis you would simply need to add their outputs together to create an additive sound. Let us say you create two sine waves: O1 at 800 Hz, and O2 at 1200 Hz. Using Additive synthesis you would create your sound (O3) as follows: Equation A2 - Additive Waveform O 3 = (O1 + O2 ) / 2 Here, O3 would be the resultant Additive waveform, which would look as follows: Figure 2 - Additive Wave

If you plan to do this, make sure that your result (O3) stays below the ABS(32760) amplitude, since this is the maximum amplitude for a 16-bit waveform. For this reason I have divided my result by the number of waves being added together - In this case, 2. Now I guess if your PC is fast enough to calculate thousands of sine waves very quickly, additive synthesis may produce some great results. The only problem is, how does one arrange the different frequencies to achieve a desired sound? What different frequencies do we use? What amplitudes must we apply to each waveform? The answer to all of these is, "with difficulty!" If you build a house out of tiny bricks, it takes a very long time to complete, but you have ultimate control as to how your house is to be structured. If you build it with larger bricks, it is completed a lot quicker, but you can't get the precision you did with the smaller bricks. Compare Additive Synthesis to the small bricks, and other forms of synthesis to the larger bricks, and you'll see that most computers just don't have the resources for generating hundreds of sine waves and being able to build sounds from them. If we could distort these sine waves, perhaps we could use less to create more, if you will. This brings us to feedback.. 3. The Feedback Sine Wave One simple way of warping (Warping? Scott me up, Beamie!) a sine wave is to allow the output of the wave to effect the input of the wave. i.e. Allowing each sample of the waveform to affect each successive sample thereafter. Well, there is an easy solution to this: Just include some of the output from the RHS side of the simple sine wave equation and plug it into the LHS of the equation. What this does is, it allows the sine wave to modulate itself by

3 sur 12

5/07/05 13:58

Modulation

http://www.analoguesque.com/modsynthesis.htm mixing back into the equation, some of the output itself. The way to achieve this is to add one expression (·) to the simple sine wave equation (Equation 1). With this new addition, the equation changes as follows: Equation A3 - Feedback Sine Wave O = A * (sin((F * T) + (FB * O))) Here, FB is a feedback constant for Operator O, which forces O on the RHS of the equation to be affected by previous calculations of O on the LHS of the equation. With low values of FB, the waveform produced by this equation resembles a distorted sine wave, but with successively higher values the waveform begins to resemble white noise. I find that keeping the value of FB between -1 and 1 produces the best results, but take note that extremely slight changes in FB (even FB = 0.000001) can affect the waveform produced by the Feedback Sine Wave. I use the following formula for working with FB values: FB = (-1 >= Value 2 -> X (FM Synthesis) 2 -> 3 -> Y (FM Synthesis) X + Y -> Output (Additive)

1 + 2 + 3 -> X (Additive) X -> 4 -> Output (FM Synthesis)

1 + 2 -> X (Additive) X -> 3 -> Y (FM Synthesis) Y + 4 -> Output (Additive)

Now, the great thing about making your own waveform-rendering programs is that you have Carte Blanche editability - If you don't like the way the algorithm does things, you are free to implement any additions or subtractions to change it. Something I have found useful in this regard is to keep the previous iteration of a waveform and use it as input to one you are currently rendering. Let me explain exactly what I mean by this: Say you have created a program for generating 2-op (two waveforms) FM waveforms. In your two original feedback FM algorithms, you would have your first waveform with feedback, and your second waveform with feedback, and a feed-in from the first waveform into the second. This immediately gives you 5 parameters to play with, over-and-above those for frequency, amplitude and the like. Your 5 parameters are the 2 actual sine waves themselves, the Feedback for waveform 1, Feedback for waveform 2, and Feed-In from waveform 1 into waveform 2. If you generated a 100Hz sine wave for waveform 1, wouldn't it be great if you could modulate it without touching waveform 2 ... yet? Well, you would probably have your waveforms stored in an array or pointer, so why not have a loop-back value from your old waveform array/pointer into the one currently being rendered? Take a look at figure 7 below: Figure 7 - Two-Stage FM Synthesis

This shows how we can use only 1 waveform-generating routine to create 2-op FM synthesis, by including previously generated versions of waveform 1 back into current versions of the same waveform. So, you generate a 100Hz sine wave for Operator 1. Then you set a loop-back value (red portion of wave 1 above) and generate, say, a 200Hz sine wave for Operator 1. The previous 100Hz sine wave will modulate the current 200Hz sine wave, and

6 sur 12

5/07/05 13:58

Modulation

http://www.analoguesque.com/modsynthesis.htm there you have 2-op FM synthesis without needing 2 sets of information - well, sort-of! If you include the same concept in Operator 2, we have another 2 variables to add to our list of parameters, bringing the total now to 7 - 2 waveform outputs, 2 feedback loops, 2 loop-back loops, and 1 feed-in loop. Whew! What if we decide that this feed-in should perform AM synthesis, or perhaps Additive synthesis instead of Frequency Modulation? Your algorithms would need some adjustments, but this again increases the number of parameters now available, which of course increases the complexity of resulting sounds. The more parameters you have at your disposal the more complex you can make your sounds. Unfortunately, this also means that making sounds becomes more difficult, because you have so many parameters to work with. With careful control of these, however, this should pose limited problems. You could, for instance, set up a list of default settings or templates for achieving certain sounds. That way you have something to start with each time you load in the settings. In fact, this is almost a necessity because things become extremely complicated with so many options. Just think, if you were using 6 operators, you already have 64 different ways in which these can interact with each other using only Additive and FM synthesis. Then you go and add several parameters on top of that, like Frequency, Decay, Sample-Length, Feedback ... etc. This can become a nightmare if you're not careful about how you structure everything. Then you go and add Amplitude Modulation to go with your FM and Additive ... things get a little bit too exciting. 5. Adding Complexities As I mentioned earlier, the more variables you can add to your formula, the more complex you can make your sounds. So, what ways are there of making the formula more complex? Let's look at what we already have, in the light of a 4-op example: 2 types of synthesis - FM and Additive. 16 different combinations for the Operators. 4 Frequencies. 4 Amplitudes. 4 Feedbacks. 3 Feed-Ins. What else is there? What about a Phase Offset value? Remember in our first example code we showed how to programatically produce a sine wave. Look at the variable T (samples/ticks) that determines exactly where we are in the wave cycle. Starting with T at 0, the sine wave starts at 0. But what if we started with T at some other value? This produces a shift as shown in the following examples : Figure 8 - Phase = 0%

Figure 9 - Phase = 25%

The easiest way of implementing this phase shift is to work in percentages of a waveform cycle, and the calculations are as follows ... Let's simplify things, and use a sampling rate of, say 10000Hz. This would mean that to generate 1 second of a waveform would require 10000 samples, since we are sampling at 10000 times per second (10000 samples/sec). If we set a frequency of 100 Hz for our sine wave, this would mean that we would get 100 sine wave cycles in 1 second. How do we get this figure? 10000Hz/100Hz = 100 samples. So, we now have the cycle size : 1 cycle = 100 samples. Now we use a percentage of this to offset the waveform. If the above descriptions are a bit difficult to fathom, don't worry ... here's the code :

7 sur 12

5/07/05 13:58

Modulation

http://www.analoguesque.com/modsynthesis.htm Equation A6 - Phase Offset Sine Wave O = A * (sin(F * (T + PH))) Now lets make this a bit easier by using some actual code which references our variables defined at the start of this document. VB Code A2 Dim F, Pi as Single Dim SR, A, L, Hz, O, PH as Integer Dim Phase as Single Hz = 100 ' Frequency of Waveform L = 10000 ' Length in Samples A = 32760 ' Amplitude SR = 10000 ' Sampling Rate Pi = 3.1415 Phase = 25 ' 25 % of 1 cycle PH = (Phase / 100) * (SR / Hz) ' PH = a percentage of 1 cycle F = (2 * Pi * Hz) / SR For T = 0 to L O = int(A * (sin(F * (T * PH)))) Next T

B. Wave Distortion (PD Variant) 1. A Little Information This type of synthesis was used extensively on the mid '80s Casio CZ synthesizers. The name brand Casio didn't do much to promote the synthesisers at all, mainly because Casio was well known for making home keyboards worthy of toy status, rather than real instruments. But, if you're like me you believe that anything emitting a sound is worth something in music, and Casio's CZ range of synthesisers were certainly worth more than they were given credit for. In my humble opinion, the Casio CZ synths are some of the most underrated in the business. PD synthesis and FM synthesis, as used in Yamaha's DX range, were often lumped into the same category, and although they use similar synthesis techniques, they are most certainly very different beasts. Firstly, PD synthesis is easier to program than FM, and secondly it also produces sounds which are almost worthy of analog status - Almost, but not quite. You could extract a grunginess, almost a distortion effect from PD synths which was not possible with FM. Ask Vince Clarke (ex Depeche Mode, Yazoo and Erasure front-runner) if he thinks the Casio CZ101 synth is a cheap piece of junk. He was so enthralled by them that he used a bank load of several running in parallel to get the effects he wanted. All they lacked was huge polyphony, hence the bank load of CZ101's. With today's technology combined with the resurgence of vintage sounds over the past 6 years, it is very surprising (almost shocking, actually) that Casio has not attempted a CZ revival of sorts. A revamped CZ synth with all the modern trimmings (polyphony, timbrality, more waveforms ... etc) could quite easily be the biggest thing since Virtual Analog! 2. What is PD Synthesis? So how does PD synthesis work? Well, in a lot of ways it is very similar to FM synthesis, but the fundamental operations performed on waveforms are not quite the same. In simple terms, PD works by distorting a sine wave, and depending on what sort of algorithms you are using to distort the wave, this can be quite dramatic. The easiest way of imagining this is to use the feedback sine wave as an example, where the feedback loop distorts the sine wave. If you use an algorithm to perform the distortion, this is where PD synthesis sets in. Actually, let's jump directly into some algorithms and equations, since this is a lot easier to

8 sur 12

5/07/05 13:58

Modulation

http://www.analoguesque.com/modsynthesis.htm understand and visualise. Besides, I'm getting a little lost myself without the algorithms in front of me. Firstly, we need an algorithm which will provide us with an undistorted sine wave. You may be tempted to use the original formula from the beginning of the FM tutorial (re. The simple sine wave), but there is a better formula which is more flexible, and can be used for PD and FM synthesis, and much else inbetween. The coding is as follows : VB5 Code B1 Dim T, F, SR, A, O, SR As Integer Dim Phase_Add, Phase As Single Dim Pi2 As Double Pi2 = 6.28318530717958 ' 2*Pi SR = 22000 ' Sampling Rate F = 880 ' Frequency in Hz Phase_Add = F / SR ' Used to output F Hz A = 32760 ' Amplitude For T = 0 To 100 O = A * Sin(Pi2 * Phase) Phase = Phase + Phase_Add If Phase > 1 Then Phase = Phase - 1 Next T Firstly, Phase is a variable which fluctuates between 0 and 1 - this is where we get the sine wave from. Secondly, this variable is kept between 0 and 1 by the coding indicated in yellow, and thirdly, Phase_Add determines the frequency of the resultant sine wave. There you have it - a new formula for generating a sine wave. Okay then, so how does PD synthesis fit into this equation? The simple answer to this is that PD synthesis relies on distorting Phase in a periodic manner. i.e. An algorithm is used to distort Phase over a period of time. In FM synthesis, the feed-in loop had a similar effect in that the first waveform modulated the second waveform using this feed-in value. In the case of PD, the waveform is not modulated by another waveform, but distorted by an algorithm. The easiest way of understanding a distortion algorithm is to imagine Phase being manipulated in such a way that it forces a different waveform from the above equation - Say for instance, producing a square wave output rather than a sine wave. First off, you need to develop several algorithms which will force the output of specific waveforms from the above equation. Set each different routine up as a separate function, and then call a specific function within the above equation. Yes, this is a real mouthful, but take a look at the code and see how easy it actually is : Equation B1 - The Distortion Algorithm O = A * Sin(Pi2 * PD(Phase)) ## Here, PD(Phase) is actually calling a function which distorts Phase and forces the equation to give O a different waveform. Now depending on what your function PD( ) does, you could produce square waves, white noise, triangles and the like. Let's take an example where this function produces a square wave. We would need to add the following function to the above code # # to produce a square wave : VB5 Code B2 Function PD(Phh) As Double If Phh < 0.5 Then PD = 0.25 Else PD = 0.75 End If End Function

9 sur 12

5/07/05 13:58

Modulation

http://www.analoguesque.com/modsynthesis.htm

This function takes the Phase value, and manipulates it so that the Distortion Algorithm outputs a square wave. There are of course other waveforms to think about too, like sawtooth, triangle, pulse-width and noise, and these are detailed as follows : VB5 Code B3 Function Square(Phh, PW) As Double ' Square If Phh < PW Then ' 0 < PW < 1 Square = 0.25 Else Square = 0.75 End If End Function Here you would need to send the distortion algorithm an extra parameter (PW), denoting what percentage of pulse-width you require (e.g. 0 to 100%). Here are a few more distortion algorithms : VB5 Code B4 Function Sine(Phh) As Double Sine = Phh ' Mmm, not much here is there End Function Function Saw(Phh) as Double ' Sawtooth If Phh < 0.5 Then Saw = 0.35 * Sin(Phh) Else Saw = (0.35 * Sin(1 - Phh)) + 0.5 End If End Function Function Tri(Phh) as Double ' Triangle Static Ph As Single Static Flag As Integer If Flag = 0 Then Flag = 1 Ph = 0.25 End If Ph = Phh + 0.25 If Ph > 1 Then Ph = Ph - 1 If Ph < 0.5 Then Tri = 0.7 * (Ph - 0.25) Else Tri = 0.7 * (0.75 - Ph) End If End Function Function Noise(Phh) As Double ' White Noise Noise = ((Rnd * 1000000000) / 1000000000) End Function Now don't take the above algorithms as the only method of getting the desired waveforms. There are probably hundreds of different methods, but in my infinite mathematical wisdom (not!), these were the ones I came up with. There are also an infinite number of other distortion algorithms you could use too, but these are the basis of analog synthesis so they are probably the best to start off with. 3. Changing the Phasing - Phase Distortion

10 sur 12

5/07/05 13:58

Modulation

http://www.analoguesque.com/modsynthesis.htm Now the above algorithm certainly gives you several types of waveform, and depending on how many algorithms you have, there will probably be way too many waveforms to choose from. Beyond this, you won't get many interesting effects because ultimately the sounds need to change over time to employ the full effect of PD synthesis. In FM synthesis this change is achieved with the different ADSR settings of each waveform, and the changes are sometimes quite dramatic. In PD synthesis these changes are usually set up as a phasing between different algorithms, controlled either by an LFO or by an ADSR. Basically, with the above PD algorithms you will achieve a sound whose timbre remains constant throughout the ADSR process - like an organ with an Amplitude ADSR envelope. The question is, how do we introduce some form of dynamic change throughout the ADSR of the sounds? As far as I am aware, traditional PD synthesis employs a transition or phasing between different waveforms - you can think of this transition as a morphing between algorithms. Don't make the mistake of thinking that this is a morphing between sounds. It's not, but in some respects it is similar. How we achieve this transition is to allow the waveform output to swing between one distortion algorithm and another. Say for instance, you choose 2 algorithms for your transition - Square and Sine. Now what happens in PD synthesis is that your output swings between a sine wave and a square wave at a specific frequency, giving you an almost filtering effect. The way of doing this is to create a formula where the value of one distortion algorithm is negatively proportional to the value of another - As the value of one increases, the other decreases proportionately. This looks as follows : Equation B2 - The PD Algorithm y = ((1 - z) * Sine(Phase)) + (z * Square(Phase)) O = A * Sin(Pi2 * PD(y)) Here, z is a variable much like Phase, which swings between 0 and 1 at a specific frequency. The frequency can be set in exactly the same manner as the variable Phase by using a variable z_Add = Phase_Frequency (in Hz) / SR. Now employ the same formula used with Phase and Phase_Add in VB5 Code Example 1, and z will swing between 0 and 1, forcing the above equation to swing between a Sine and a Square wave at frequency = Phase_Frequency. It works because with z = 0, O is at a full Sine wave. At z = 1, O is at a full Square wave. So, the speed (frequency) at which z swings between 0 and 1 determines how quickly O swings between a Sine Wave and a Square wave. There certainly is no need to exclusively use this sort of linear phasing. A better method is to set up an ADSR envelope which will be used to control the level of one algorithm against the level of another. Depending on how many points of change you have allowed in your envelope, this would probably be a lot more fruitful than simply using an LFO as shown above. 4. Using PD Synthesis Want to make it more complex? Sure, just add in everything you know about FM, Additive and AM synthesis. Add in the feedback loop, or add in some FM and we now have an even more complex system. With feedback and FM added to the PD equation, it now looks as follows : Equation B3 - PD, with Feedback and FM O2 = A * Sin((Pi2 * PD(y)) + (FB * O2) + (FI * O1)) I won't explain much about FM, AM, Additive, and PD synthesis together because with the above algorithm, and the previous explanations of FM synthesis you should be able to create some great techniques for melting these all together. In fact, once you understand the techniques involved in PD synthesis, you may choose to use these algorithms above those developed in the earlier sections of FM synthesis. The reason for this is that it is easier to work with the variables as given in the PD equations, and manipulating the waveforms is a lot easier. I am no expert on this, but my feeling is that PD synthesis is very limited without the introduction of other forms of synthesis to enhance it. Perhaps a resonant-filter algorithm would give it a real kick, but then again a resonant-filter is useful for any type of synthesis.

11 sur 12

5/07/05 13:58

Modulation

http://www.analoguesque.com/modsynthesis.htm PD synthesis as described above will most definitely give you very thin sounding textures, so you would need to layer a couple of waves on top of each other (additive synthesis), and even better, sew the PD waveforms into some AM and Fm synthesis as well. I have not yet delved very far in the area of mixing the fundamental principles of FM and PD synthesis, but I can only imagine how much PD synthesis can enhance traditional FM theory. In the earliest FM synths, there was exclusive use of sine waves for producing sounds. Later on Yamaha added a few extra waveforms in synths like the TX81Z. This allowed the 4-op TX81Z synth to perform as well as a 6-op synth, but only because the fundamental waveforms were not always sine waves. With PD synthesis you have as many waveforms as you have distortion algorithms, so applying these to FM and AM synthesis could be quite exciting. Earlier FM synths using a variety of waveforms employed the use of very few extra waveforms - perhaps 5 or 6. This, however, allowed for many variations in sound texture over sine waves, so the necessity to have lots of operators was reduced. Now with PD algorithms there are many fundamental waveforms to choose from, so the sonic possibilities are huge. Then add to this the fact that we now know how to phase between different algorithms, and this makes the whole process even more complex. Phasing, distortion, different frequencies and amplitudes, different ADSR envelopes, different FM and AM algorithms ...... these are all starting to constitute something BIG. The trick will obviously be to harness the power somehow, so as not to make the whole process too complex. This certainly will not be an easy task ... but I'll leave that up to you ... _____________________________________________________ All contents Copyright © 2000-2003 Analoguesque Sound Designs

12 sur 12

5/07/05 13:58