allpole
Allpole filter implementation using direct convolution.
Syntax
kCoef[] -- all-pole filter coefficients (iord-size array)
asig -- audio input
ares -- audio output
This opcode is part of a suite of streaming linear prediction opcodes. It implements an allpole filter using coefficients passed to it via a k-rate array. The filter length is determined by the array size.
The typical application is compute the coefficients via some method and then pass these to the opcode. The set of coefficients passed to allpole need to implement a stable filter, since this is an IIR filter and stability is not guaranteed by default.
The most common method of coefficient derivation is linear prediction analysis, produced for instance by lpcanal. Other methods may be employed, including direct calculation of coefficients from a known filter recipe (e.g. resonators etc).
Examples
Modern Classic Modern Classic
Here is an example of the allpole opcode using an audio input
signal as lpc source. It uses the file allpole-modern.csd .
Example of the allpole opcode. <CsoundSynthesizer>
<CsOptions>
-odac -d
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 64
nchnls = 1
0dbfs = 1
f w @ global : i = ftgen ( 0 , 0 , 1024 , 20 , 2 , 1 )
instr 1
a 1 = diskin ( "fox.wav" , 1 , 0 , 1 )
cfs : k [], k rms , err : k , cps : k = lpcanal ( a 1 , 1 , 128 , 1024 , 64 , f w )
if cps > 180 then
cps = 180
endif
a 2 = buzz ( 0dbfs , cps , sr / ( cps * 2 ), - 1 )
a 3 = allpole ( a 2 * k rms * err , cfs )
out ( dcblock ( a 3 ))
endin
</CsInstruments>
<CsScore>
i 1 0 30
</CsScore>
</CsoundSynthesizer>
Here is an example of the allpole opcode using an audio input
signal as lpc source. It uses the file allpole.csd .
Example of the allpole opcode. <CsoundSynthesizer>
<CsOptions>
-odac -d
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 64
nchnls = 1
0dbfs = 1
gi fw ftgen 0 , 0 , 1024 , 20 , 2 , 1
instr 1
a 1 diskin "fox.wav" , 1 , 0 , 1
k cfs [], k rms , k err , k cps lpcanal a 1 , 1 , 128 , 1024 , 64 , gi fw
if k cps > 180 then
k cps = 180
endif
a 2 buzz 0dbfs , k cps , sr / ( k cps * 2 ), - 1
a 3 allpole a 2 * k rms * k err , k cfs
a 3 dcblock a 3
out a 3
endin
</CsInstruments>
<CsScore>
i 1 0 30
</CsScore>
</CsoundSynthesizer>
Here is another example of the allpole opcode, now using a
function table as lpc source. It uses the file allpole-2-modern.csd .
Another example of the allpole opcode. <CsoundSynthesizer>
<CsOptions>
-odac -d
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1
f n @ global : i = ftgen ( 0 , 0 , 0 , 1 , "Mathews.wav" , 0 , 0 , 1 )
f w @ global : i = ftgen ( 0 , 0 , 1024 , 20 , 2 , 1 )
instr 1
k 1 init 0
ts : k = p4
cfs : k [], k rms , err : k , cps : k = lpcanal ( k 1 , 1 , f n , 1024 , ksmps , f w )
if cps > 120 then
cps = 120
endif
a 1 = buzz ( 0dbfs , cps , sr / ( cps * 2 ), - 1 )
a 3 = allpole ( a 1 * k rms * err , cfs )
k 1 += ksmps * ts
if k 1 > ftlen ( f n ) then
k 1 = 0
endif
a 3 = dcblock ( a 3 )
outs ( a 3 * 10 , a 3 * 10 )
endin
</CsInstruments>
<CsScore>
i 1 0 10 1
i 1 10 10 .2
i 1 20 10 1.5
</CsScore>
</CsoundSynthesizer>
Here is another example of the allpole opcode, now using a
function table as lpc source. It uses the file allpole-2.csd .
Another example of the allpole opcode. <CsoundSynthesizer>
<CsOptions>
-odac -d
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1
gi fn ftgen 0 , 0 , 0 , 1 , "Mathews.wav" , 0 , 0 , 1
gi fw ftgen 0 , 0 , 1024 , 20 , 2 , 1
instr 1
k 1 init 0
k ts = p4
k cfs [], k rms , k err , k cps lpcanal k 1 , 1 , gi fn , 1024 , ksmps , gi fw
if k cps > 120 then
k cps = 120
endif
a 1 buzz 0dbfs , k cps , sr / ( k cps * 2 ), - 1
a 3 allpole a 1 * k rms * k err , k cfs
k 1 += ksmps * k ts
if k 1 > ftlen ( gi fn ) then
k 1 = 0
endif
a 3 dcblock a 3
outs a 3 * 10 , a 3 * 10
endin
</CsInstruments>
<CsScore>
i 1 0 10 1
i 1 10 10 .2
i 1 20 10 1.5
</CsScore>
</CsoundSynthesizer>
See also
Streaming Linear Predictive Coding (SLPC) Resynthesis