lpanal

lpanal — Performs both linear predictive and pitch-tracking analysis on a soundfile.

Description

Linear predictive analysis for the Csound Linear Predictive Coding (LPC) Resynthesis opcodes.

Syntax

csound -U lpanal [flags] infilename outfilename
lpanal [flags] infilename outfilename

Initialization

lpanal performs both lpc and pitch-tracking analysis on a soundfile to produce a time-ordered sequence of frames of control information suitable for Csound resynthesis. Analysis is conditioned by the control flags below. A space is optional between the flag and its value.

-a -- [alternate storage] asks lpanal to write a file with filter poles values rather than the usual filter coefficient files. When lpread / lpreson are used with pole files, automatic stabilization is performed and the filter should not get wild. (This is the default in the Windows GUI) - Changed by Marc Resibois.

-s srate -- sampling rate of the audio input file. This will over-ride the srate of the soundfile header, which otherwise applies. If neither is present, the default is 10000.

-c channel -- channel number sought. The default is 1.

-b begin -- beginning time (in seconds) of the audio segment to be analyzed. The default is 0.0

-d duration -- duration (in seconds) of the audio segment to be analyzed. The default of 0.0 means to the end of the file.

-p npoles -- number of poles for analysis. The default is 34, the maximum 50.

-h hopsize -- hop size (in samples) between frames of analysis. This determines the number of frames per second (srate / hopsize) in the output control file. The analysis framesize is hopsize * 2 samples. The default is 200, the maximum 500.

-C string -- text for the comments field of the lpfile header. The default is the null string.

-P mincps -- lowest frequency (in Hz) of pitch tracking. -P0 means no pitch tracking.

-Q maxcps -- highest frequency (in Hz) of pitch tracking. The narrower the pitch range, the more accurate the pitch estimate. The defaults are -P70, -Q200.

-v verbosity -- level of terminal information during analysis.

  • 0 = none

  • 1 = verbose

  • 2 = debug

The default is 0.

-X -- write machine independent format analysis file.

File Format

Output is a file comprised of an identifiable header plus a set of frames of floating point analysis data. Each frame contains four values of pitch and gain information, followed by npoles filter coefficients. The file is readable by Csound's lpread.

lpanal is an extensive modification of Paul Lanksy's lpc analysis programs.

Examples

lpanal -a -p26 -d2.5 -P100 -Q400 audiofile.test lpfil22

will analyze the first 2.5 seconds of file "audiofile.test", producing srate/200 frames per second, each containing 26-pole filter coefficients and a pitch estimate between 100 and 400 Hertz. Stabilized (-a) output will be placed in "lpfil22" in the current directory.

Here is an example of the lpanal utility. It uses the file lpanal.csd.

Example 1345. Example of the lpanal utility.

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
-odac     ;;;realtime audio out
;-iadc    ;;;uncomment -iadc if realtime audio input is needed too
; For Non-realtime ouput leave only the line below:
; -o lpanal.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

sr = 44100
ksmps = 32
nchnls = 2
0dbfs  = 1

; by Menno Knevel 2021

ires system_i 1,{{ lpanal -p34 -h200 -P50 -Q500 -v1 finneganswake1.flac finneganswake11.lpc }}       ; filter coefficient file
ires system_i 1,{{ lpanal -a -p50 -h300 -P70 -Q100 -v1 finneganswake1.flac finneganswake12.lpc }}    ; create pole file

instr 1 ; untreated signal
asig    diskin2   "finneganswake1.flac", 1
outs    asig, asig
endin

instr 2
ilen  filelen "finneganswake1.flac"	    ; get length of soundfile
prints "\nfinneganswake1.flac = %f seconds\\n",ilen
prints  "\n---***YOU NOW HEAR THE RESULT OF THIS ANALYZED FILE:***---\n"
ktime line 0, p3, ilen-0.1                  ; timepointer
krmsr,krmso,kerr,kcps lpread ktime, p4
krmso *=.00005			                ; lower volume
aout  foscil krmso, kcps, 1, 10, 1
aout  butlp aout, 5000                  ; filter low pass
krmsr *=.0003			                ; lower volume
asig  rand krmsr                        ; use residual for the noise 
      outs aout+asig, aout+asig	        ; add saw wave and noise

endin
</CsInstruments>
<CsScore>

s
i1 0  12.7       ; original sample
s
i2 0  12.7 "finneganswake11.lpc"	; whole sentence
i2 15 12.7 "finneganswake12.lpc"	; whole sentence, pole file
e
</CsScore>
</CsoundSynthesizer>