cvanal

cvanal — Converts a soundfile into a single Fourier transform frame.

Description

Impulse Response Fourier Analysis for convolve operator

Syntax

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

Initialization

cvanal -- converts a soundfile into a single Fourier transform frame. The output file can be used by the convolve operator to perform Fast Convolution between an input signal and the original impulse response. Analysis is conditioned by the flags below. A space is optional between the flag and its argument.

-s rate -- 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. If omitted, the default is to process all channels. If a value is given, only the selected channel will be processed.

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

-X -- write machine independent format analysis file.

Files

The output file has a special convolve header, containing details of the source audio file. The analysis data is stored as float, in rectangular (real/imaginary) form.

[Note] Note

The analysis file is not system independent! Ensure that the original impulse recording/data is retained. If/when required, the analysis file can be recreated.

Examples

cvanal asound cvfile

will analyze the soundfile "asound" to produce the file "cvfile" for the use with convolve

To use data that is not already contained in a soundfile, a soundfile converter that accepts text files may be used to create a standard audio file, e.g., the .DAT format for SOX. This is useful for implementing FIR filters.

Here is an example of the cvanal utility. Play cvanal.csd

Example 1353. Example of the cvanal 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   -m0  --limiter=.99 ;;;realtime audio out, with limiter protection
; For Non-realtime ouput leave only the line below:
; -o cvanal.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

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

; by Menno Knevel 2021

gilen  filelen "rv_stereo.wav"	    ; get length of impulse soundfile

; analyze sound file and output result to 3 convolve files
ires1 system_i 1,{{ cvanal rv_stereo.wav rv_stereo1.con }}                  ; default settings
ires2 system_i 1,{{ cvanal -d.15 rv_stereo.wav rv_stereo2.con }}            ; use only first portion
ires3 system_i 1,{{ cvanal -b.25 -d.001 rv_stereo.wav rv_stereo3.con }}    ; take very short portion from the end


instr 1 ; untreated signal
asig    diskin2   "beats.wav", 1
prints  "\n---***YOU NOW HEAR THE UNTREATED SOUND SAMPLE***---\n"
outs    asig, asig
endin

instr 2

prints  "\n---***YOU NOW HEAR THE RESULT OF THIS ANALYZED FILE:***---\n"
prints "--**used duration of impulse file = %5.3f seconds (total =%5.2f)**--\\n", p5, gilen

adry    diskin2 "beats.wav"                 ; input (dry) audio
awet1, awet2 convolve adry*.8, p4           ; stereo convolved (wet) audio
awet1  *=  p6                               ; scale amplitude of impulse sound, Left
awet2  *=  p6                               ; & Right channel
adrydel delay   adry, p5                    ; delay dry signal to align it with convolved signal
outs    (adrydel+awet1)*.8,(adrydel+awet2)*.8 ; mix wet & dry signals 
endin

</CsInstruments>
<CsScore>

i1 1 2          ; untreated signal

i2 4 3  "rv_stereo1.con"    0.39    .01	; use total impulse
i2 8 3  "rv_stereo2.con"    0.15    .01	; first portion of impulse
i2 12 3 "rv_stereo3.con"    0.001    1	; very short portion of impulse, starting from 0.25 sec, & scale amp
e
</CsScore>
</CsoundSynthesizer>


Credits

Author: Greg Sullivan

Based on algorithm given in Elements Of Computer Music, by F. Richard Moore.