lpcfilter — Streaming linear prediction all-pole filter.
This opcode implements an all-pole filter whose coefficients are obtained from streaming linear prediction analysis. Two versions exist, one taking input from an audio signal, and the other from a function table.
ares lpcfilter asig, asrc, kflg,
kprd, isiz, iord[,iwin]
ares lpcfilter asig, koff, kflg,
ifn, isiz, iord[,iwin]
isiz -- size of lpc input frame in samples.
iord -- linear predictor order.
ifn -- streaming LPC analysis source function table
iwin -- window function table number (optional)
ares -- output
asig - audio input
asrc -- streaming LPC analysis source signal
kflg -- compute flag, non-zero values switch on linear prediction analysis replacing filter coefficients, zero switch it off, keeping current filter coefficients.
kprd -- analysis period in samples, determining how often new coefficients are computed.
koff -- function table position offset, in samples, determining the start position of analysis frame.
This opcode is part of a suite of streaming linear prediction opcodes. It analyses an input signal, either as an audio input or stored in a function table and produces a set of coefficients for an all-pole filter that models the signal's spectral envelope. This filter is then applied to an arbitrary input, producing a cross-synthesis result.
The fundamental analysis parameters are input frame size and filter order. Longer input frames will produce a more accurate result in terms of frequency resolution, but will also involve more computation. This is due to the computation of the autocorrelation function, which is then used in the coefficient computation. This part is more efficient and depends only on the linear prediction order, which is also the number of coefficients computed. Typical lp orders may range from about 30 to 100 coefficients, but larger values can also be used.
If the LPC source signal is derived from an audio input, then the computation of coefficients is dependent on two parameters, kflg and kprd. The first is an on/off switch that determines whether coefficients are replaced by newly-computed ones or the coefficients are kept fixed to their last value. The other determines the frequency of analyses, by setting a time interval (in samples) between new coefficient computation. This ranges from coefficients being replaced every sample, to never replaced (if the period is larger than the synthesis duration). Overlapped analyses will take place if the value of kprd is less than the input size. Decreasng the spacing of analyses will also increase computation demands.
If the LPC source signal is derived from a function table, then kflg determines wheter an analysis should be performed or not (1 or 0). The value of koff is then used as an offset (in samples) into the function table determining the position of the analysis frame. For example, if kflg is permanently set to 1 and koff is set to ksmps, then at every kcycle an analysis frame will be taken from successive positions in the function table. Changing koff to fewer samples will produce a timestretched result and increasing it will time compress.
Once the signal is extracted from either an audio input or function table then it can be optionally windowed if a function table is provided. While this is optional, it is a recommended procedure (GEN20 can provide the most common windows). The signal is then analysed and coefficients replaced. The all-pole filter is computed as a direct convolution in the time domain.
Here is an example of the lpcfilter opcode using an audio input signal as lpc source. Play lpcfilter.csd
Example 545. Example of the lpcfilter opcode.
See the sections Real-time Audio and Command Line Flags for more information on using command line flags.
<CsoundSynthesizer> <CsOptions> -odac -d </CsOptions> <CsInstruments> sr = 44100 ksmps = 64 nchnls = 1 0dbfs = 1 gifw ftgen 0,0,1024,20,2,1 instr 1 a1 diskin "fox.wav",1,0,1 a2 diskin "beats.wav",1,0,1 a3 lpcfilter a2,a1,1,128,1024,64,gifw a3 dcblock2 a3 out a3 endin </CsInstruments> <CsScore> i1 0 30 </CsScore> </CsoundSynthesizer>
Here is another example of the lpcfilter opcode, now using a function table as lpc source. Play lpcfilter-2.csd
Example 546. Another example of the lpcfilter opcode.
See the sections Real-time Audio and Command Line Flags for more information on using command line flags.
<CsoundSynthesizer> <CsOptions> -odac -d </CsOptions> <CsInstruments> sr = 44100 ksmps = 64 nchnls = 1 0dbfs = 1 gifn ftgen 0,0,0,1,"fox.wav",0,0,1 gifw ftgen 0,0,1024,20,2,1 instr 1 koff init 0 kts = p4 // timescale a1 diskin "beats.wav",1,0,1 a3 lpcfilter a1,koff,1,gifn,1024,ksmps,gifw koff += ksmps*kts if koff > ftlen(gifn) then koff = 0 endif a3 dcblock a3 out a3 endin </CsInstruments> <CsScore> i1 0 10 1 i1 10 10 .75 i1 20 10 1.5 </CsScore> </CsoundSynthesizer>