Re: Granular in club music?
Kevin Conder <[email protected]>
| Newsgroups | gmane.comp.audio.csound.tekno |
|---|---|
| Message-ID | <[email protected]> |
On Mon, 13 Oct 2003 Nohohondesu-jqGaMwjwha9Wk0Htik3J/[email protected] wrote: > Can someone point me to granular synthesis in action, in dance music?? > In theory granular synthesis is as potent as any other methods, but what I > could do with it was not that interesting so far. Once upon a time, Istvan Varga posted a message that included a way to use granular synthesis to emulate an analog synthesizer. Take note of Instrument #5 in the message below. -- Kevin Conder, kevin-NPx+F0K3cJ/[email protected] From **SNIP EMAIL** Thu Apr 18 14:10:57 2002 Date: Thu, 18 Apr 2002 12:13:47 +0200 From: Istvan Varga **SNIP EMAIL** Reply-To: [email protected], Istvan Varga **SNIP EMAIL** To: Iain Duncan **SNIP EMAIL** Cc: [email protected] Subject: Re: [Csnd] Anti aliasing and saw/pulse waves ; ---- analog2.orc ---- sr = 44100 kr = 4410 ksmps = 10 nchnls = 1 ; Sawtooth wave (also used for PWM). itmp ftgen 1, 0, 16384, 7, 1, 16384, -1 ; The sawtooth-triangle ramp can be generated by integrating ; a pulse-width modulated square wave (which is the difference of ; two sawtooth waves with different phase); however, it is more ; efficient (and also eliminates problems related to the use of ; a leaky integrator in the instruments) to start from an already ; integrated waveform. The sawtooth wave (x is in the range 0 to 1) ; is: ; y = 1 - 2*x ; after integrating this we get: ; y = x - x^2 ; GEN03 generates the polynomial (with normalization, the function ; is actually 4*(x - x^2), as the maximum value was originally 0.25 ; at x = 0.5) itmp ftgen 2, 0, 16384, 3, 0, 1, 0, 1, -1 ; Downsample tables. We could have started with a table size of ; 4096 above, but this method allows slightly more accurate output; ; on the other hand, the new, smaller size is useful to make GEN30 ; run faster. A table with 4096 samples has 2048 harmonic partials, ; so maxh is set to this value; using minh = 1 removes DC offset ; from 4*(x - x^2). The tables should not be normalized now. itmp ftgen 3, 0, 4096, -30, 1, 1, 2048 ; saw itmp ftgen 4, 0, 4096, -30, 2, 1, 2048 ; 4*(x - x^2) ; Sine (to be used by LFOs). Read with interpolation, so a small ; table is sufficient. itmp ftgen 5, 0, 256, 10, 1 ; Window for 1/16 overlap (used by "soft sync"). If the total length ; is 16384 samples, the lengths of the three segments are (note that ; for an overlap of 1/16 we actually have to divide table length by ; 17, and not 16): ; 16384 * (1/17) = 963.7647 ; 16384 * (15/17) = 14456.4706 ; 16384 * (1/17) = 963.7647 itmp ftgen 6, 0, 16384, 7, 0, 964, 1, 14456, 1, 964, 0 ; Generate bandlimited waveforms using GEN30, in this case, one ; table for each MIDI note number (0 - 127), so the total number ; of tables for a waveform is 128. i0 = 0 ; note number (counts from 0 to 127) iblimit = sr * 0.5 ; bandwidth in Hz (<= sr/2) loop1: ; Calculate number of harmonic partials which is ; bandwidth / note frequency ; the frequency of a MIDI note is (is there an opcode for this ; already ?) ; 440 * pow(2, ((note number) - 69) / 12) imaxh = iblimit / (440.0 * exp(log(2.0) * (i0 - 69) / 12)) ; Table 100 to 227: sawtooth waves, source table is 3 (see above). ; Again, GEN30 output should not be normalized. itmp ftgen i0 + 100, 0, 4096, -30, 3, 1, imaxh ; Table 300 to 427: 4*(x - x^2) waves, source table is 4. itmp ftgen i0 + 300, 0, 4096, -30, 4, 1, imaxh i0 = i0 + 1 ; next note if (i0 < 127.5) igoto loop1 /* ---- instr 1: sawtooth wave with i-rate table ---- */ instr 1 ; For many cases, it is sufficient to use i-rate table numbers, ; which allows using the (faster) oscili opcode instead of ; phasor + tableikt. To get a "clean" bandwidth of about 16000 Hz ; with sr = 44100 Hz, the minimum and maximum transpose factors (for ; e.g. vibrato or pitch bend) are: ; 16000 / 22050 = 0.7256 (-5.5 semitones) ; (44100 - 16000) / 22050 = 1.2744 (+4.2 semitones) icps = 440 ; base frequency ; The table number can be calculated from the oscillator frequency ; with the following formula: ; (base ftable) + 69 + 12 * (log(frequency / 440) / log (2)) ; this is rounded to the nearest integer by adding 0.5 and using ; int(). "base ftable" is 100 for sawtooth wave. ifnum = int(169.5 + 12 * log(icps / 440) / log(2)) ; add some variation to the frequency within the allowed limits ktrans lfo 0.25, 1 / p3, 0 ktrans = ktrans + 1 ; range: 0.75 to 1.25 ; oscillator a1 oscili 20000, icps * ktrans, ifnum out a1 endin /* ---- instr 2: sawtooth wave with k-rate table ---- */ instr 2 ; This instrument is similar to instr 1, but uses a k-rate table ; number to allow more variation in frequency (however, at high ; oscillator frequency, the switching of tables may result in ; clicks; this is audible if frequency is higher than about 2 kHz). ; This also means that the table read opcode has to support k-rate ; table number; some of such units: ; tablekt (not recommended as the lack of interpolation ; reduces quality) ; tableikt ; tablexkt (faster than tableikt but has more parameters) ; grain2/3 (these are useful for generating more complex ; oscbnk sounds) ; oscillator frequency kfrq expon 50, p3, 3200 ; frequency -> table number kfn = int(169.5 + 12 * log(kfrq / 440) / log(2)) ; phase a1 phasor kfrq ;a1 tableikt a1, kfn, 1, 0, 1 ; tablexkt is currently faster than tableikt. Window size is set ; to 2 to use linear interpolation; kwarp is not used so it is 0. a1 tablexkt a1, kfn, 0, 2, 1, 0, 1 out a1 * 20000 endin /* ---- instr 3: PWM ---- */ instr 3 ; Pulse-width modulation is implemented by calculating the ; difference of two sawtooth waves with different phase. kfrq expon 200, p3, 400 ; frequency -> table number kfn = int(169.5 + 12 * log(kfrq / 440) / log(2)) ; a2 = pulse width (0 - 1) a2 oscili 0.45, 0.8, 5, 0 a2 = a2 + 0.5 ; 0.05 to 0.95 a1 phasor kfrq ;a01 tableikt a1, kfn, 1, 0, 1 ;a02 tableikt a1 - a2, kfn, 1, 0, 1 a01 tablexkt a1, kfn, 0, 2, 1, 0, 1 a02 tablexkt a1 - a2, kfn, 0, 2, 1, 0, 1 a1 = a01 - a02 ; Correct DC offset to get +/- 1 range: ; Pulse width Original min, max Offset to get -1 to 1 ; 0.0 0, 2 -1 ; 0.5 -1, 1 0 ; 1.0 -2, 0 1 ; this means that the required offset is 2*(pulse width) - 1 a1 = a1 + 2 * a2 - 1 out a1 * 20000 endin /* ---- instr 4: sawtooth-triangle morph ---- */ instr 4 ; The sawtooth-triangle ramp is very similar to PWM, the only ; difference is that the base waveform is not sawtooth but ; 4*(x - x^2), and amplitude correction is needed instead of ; offset correction kfrq expon 200, p3, 400 ; frequency -> table number ; use 4x(1-x) waveform (i.e. integrated sawtooth) kfn = int(369.5 + 12 * log(kfrq / 440) / log(2)) ; a2 = pulse width (0.01 - 0.99). 0 and 1 are not allowed as ; these values would result in division by zero later. ; 0.01: sawtooth down, 0.5: triangle, 0.99: sawtooth up a2 oscili 0.45, 0.8, 5, 0 a2 = a2 + 0.5 ; 0.05 to 0.95 a1 phasor kfrq ;a01 tableikt a1, kfn, 1, 0, 1 ;a02 tableikt a1 - a2, kfn, 1, 0, 1 a01 tablexkt a1, kfn, 0, 2, 1, 0, 1 a02 tablexkt a1 - a2, kfn, 0, 2, 1, 0, 1 a1 = a01 - a02 ; Correct amplitude, which is actually ; 4*((pulse width) - (pulse width)^2) ; i.e. simply the output value at pulse width; however, this should ; not be read from the band-limited tables, so we use table 2. ; The division here is the reason why pulse width is not allowed to be ; 0 or 1. a2 tablei a2, 2, 1, 0, 0 a1 = a1 / a2 out a1 * 20000 endin /* ---- instr 5: granular "soft sync" with PWM ---- */ instr 5 ; This instrument is based on instr 3 (PWM), but grain3 is used to ; generate overlapping windows. ; sync frequency kfrqs expon 100, p3, 200 ; oscillator frequency kfrq expon 1000, p3, 500 ; frequency -> table number kfn = int(169.5 + 12 * log(kfrq / 440) / log(2)) ; k2 = pulse width (0 - 1) k2 oscili 0.45, 0.6, 5, 0 k2 = k2 + 0.5 ; 0.05 to 0.95 ; Interpolate and correct for start value (0.5); grain3 also ; interpolates phase internally, so these calculations ensure ; that the DC correction code will use the same value as grain3. a2 interp k2 - 0.5 a2 = a2 + 0.5 ; granular synthesis parameters: ; density = sync ("master") frequency ; grain frequency = oscillator ("slave") frequency ; grain duration = (1 + 1/16) / density (to get 1/16 overlap) ; imode is set to 2 to get grain parameters continuously controlled ; by phase and frequency, instead of the default of keeping the ; settings the grain was launched with. ; Randomization is not used, so all parameters related to it are 0. a01 grain3 kfrq, 0, 0, 0, 1.0625 / kfrqs, kfrqs, 2, kfn, 6, \ 0, 0, 0, 2 a02 grain3 kfrq, 1 - k2, 0, 0, 1.0625 / kfrqs, kfrqs, 2, \ kfn, 6, 0, 0, 0, 2 a1 = a01 - a02 ; correct DC offset (see instr 3) a1 = a1 + 2 * a2 - 1 out a1 * 20000 endin ; ---- analog2.sco ---- i 1 0 3 i 2 4 3 i 3 8 3 i 4 12 3 i 5 16 5 e _______________________________________________ csoundtekno mailing list [email protected] Subscribe, unsubscribe, change mailing list options: http://plot.bek.no/mailman/listinfo/csoundtekno