lpcanal

lpcanal — Streaming linear prediction analysis.

Description

This opcode implements streaming linear prediction analysis. Two versions exist, one taking input from an audio signal, and the other from a function table.

Syntax

kCoef[],krms,kerr,kcps lpcanal asrc, kflg,
    kprd, isiz, iord[,iwin] 
kCoef[],krms,kerr,kcps lpcanal koff, kflg,
    ifn, isiz, iord[,iwin] 
iCoef[],irms,ierr,icps lpcanal ioff, iflg,
    ifn, isiz, iord[,iwin] 

Initialization

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)

Performance

kCoef[] -- all-pole filter coefficients (iord-size array)

krms - RMS estimate of source signal.

kerr - linear prediction error (or residual).

kcps - fundamental frequency estimate, from the autocorrelation function.

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. These coefficients are placed in a k-rate array, and output along with other analysis measurements.

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. Decreasing 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 produced.

Examples

Here is an example of the lpcanal opcode using an audio input signal as lpc source. It uses the file lpcanal.csd.

Example 524. Example of the lpcanal 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
kcfs[],krms,kerr,kcps lpcanal a1,1,128,1024,64,gifw
if kcps > 180 then
  kcps = 180
endif
a2 buzz 0dbfs, kcps, sr/(kcps*2), -1
a3 allpole a2*krms*kerr,kcfs
a3 dcblock a3
out a3
endin

</CsInstruments>
<CsScore>
i1 0 30
</CsScore>
</CsoundSynthesizer>


Here is another example of the lpcanal opcode, now using a function table as lpc source. It uses the file lpcanal-2.csd.

Example 525. Another example of the lpcanal 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
k1 init 0
kts = p4
kcfs[],krms,kerr,kcps lpcanal k1,1,gifn,1024,ksmps,gifw
if kcps > 180 then
  kcps = 180
endif
a1 buzz 0dbfs, kcps, sr/(kcps*2), -1
a3 allpole a1*krms*kerr,kcfs
k1 += ksmps*kts
if k1 > ftlen(gifn) then
 k1 = 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>


See Also

lpcfilter, allpole