GEN30

GEN30 — Generates harmonic partials by analyzing an existing table.

Description

Extracts a range of harmonic partials from an existing waveform.

Syntax

f # time size  30  src  minh maxh [ref_sr] [interp]

Performance

src -- source ftable

minh -- lowest harmonic number

maxh -- highest harmonic number

ref_sr (optional) -- maxh is scaled by (sr / ref_sr). The default value of ref_sr is sr. If ref_sr is zero or negative, it is now ignored.

interp (optional) -- if non-zero, allows changing the amplitude of the lowest and highest harmonic partial depending on the fractional part of minh and maxh. For example, if maxh is 11.3 then the 12th harmonic partial is added with 0.3 amplitude. This parameter is zero by default.

GEN30 does not support tables with an extended guard point (ie. table size = power of two + 1). Although such tables will work both for input and output, when reading source table(s), the guard point is ignored, and when writing the output table, guard point is simply copied from the first sample (table index = 0).

The reason of this limitation is that GEN30 uses FFT, which requires power of two table size. GEN32 allows using linear interpolation for resampling and phase shifting, which makes it possible to use any table size (however, for partials calculated with FFT, the power of two limitation still exists).

Examples

Here is an example of the GEN30 routine. It uses the files gen30.csd.

Example 1317. Example of the GEN30 routine.

See the sections Real-time Audio and Command Line Flags for more information on using command line flags.

<CsoundSynthesizer>
<CsOptions>
; Select audio/midi flags here according to platform
; Audio out   Audio in    No messages
-odac     ;;;realtime audio out
; For Non-realtime ouput leave only the line below:
; -o gen30.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

;a simplified example of Istvan Varga
sr =  44100
ksmps =  32
nchnls =  2
0dbfs   = 1

isaw	ftgen 1, 0, 16384, 7, 1, 16384, -1						;sawtooth wave 
iFM	ftgen 3, 0, 4096, 7, 0, 512, 0.25, 512, 1, 512, 0.25, 512,	\
			     0, 512, -0.25, 512, -1, 512, -0.25, 512, 0			;FM waveform
iAM	ftgen 4, 0, 4096, 5, 1, 4096, 0.01						;AM waveform
iEQ	ftgen 5, 0, 1024, 5, 1, 512, 32, 512, 1						;FM to EQ
isine	ftgen 6, 0, 1024, 10, 1								;sine wave

/* generate bandlimited sawtooth waves */
i0	=  0
loop1:
imaxh	=  sr / (2 * 440.0 * exp(log(2.0) * (i0 - 69) / 12))
i_	ftgen i0 + 10, 0, 4096, -30, 1, 1, imaxh					;use gen 30
i0	=  i0 + 1
	if (i0 < 127.5) igoto loop1

instr 1

kcps	=  440.0 * exp(log(2.0) * (p4 - 69) / 12)					;note frequency
klpmaxf	limit p5 * kcps, 1000.0, 12000.0						;lowpass max. frequency

kfmd1	=  0.03 * kcps									;FM depth in Hz
kamfr	=  kcps * 0.02									;AM frequency
kamfr2	=  kcps * 0.1

kfnum	=  (10 + 69 + 0.5 + 12 * log(kcps / 440.0) / log(2.0))				;table number
aenv	linseg 0, p3*0.25, 1, p3*0.75, 0						;amp. envelope

asig	oscbnk kcps, 0.0, kfmd1, 0.0, 40, 200, 0.1, 0.2, 0, 0, 144,	      \
		0.0, klpmaxf, 0.0, 0.0, 1.5, 1.5, 2, kfnum, 3, 0, 5, 5, 5
asig	= asig * aenv*.03
outs asig, asig

endin

</CsInstruments>
<CsScore>
s
i 1 0 6 41 10
i 1 0 6 60
i 1 0 6 65
i 1 0 6 69
s
i 1 0 6 41 64
i 1 0 6 60
i 1 0 6 65
i 1 0 6 69

e
</CsScore>
</CsoundSynthesizer>


Credits

Author: Istvan Varga

New in version 4.16