pol2rect — Polar to rectangular format conversion.
kout[] -- output array containing the complex-valued real-imaginary output. It will be created if it does not exist.
kin[] -- input array containing the complex-valued magnitude-phase input.
kmags[] -- input array containing the real-valued magnitude input. This is expected to contain only the non-negative spectrum (0 to Nyquist, inclusive).
kphs[] -- input array containing the real-valued phase input. This is expected to contain only the non-negative spectrum (0 to Nyquist, inclusive).
NB: the second version of the opcode with two inputs is designed to produce a "packed" real FFT spectrum where the two positions in the array contain the real parts of zero Hz and Nyquist frequency. Therefore the output array length will be 2*L - 2, where L is the length of the input arrays (which should match).
Here is an example of the pol2rect opcode. It uses the file pol2rect.csd.
Example 770. Example of the pol2rect opcode.
See the sections Real-time Audio and Command Line Flags for more information on using command line flags.
<CsoundSynthesizer> <CsOptions> -d -o dac </CsOptions> <CsInstruments> /* ksmps needs to be an integer div of hopsize */ ksmps = 64 instr 1 ihopsize = 256 ; hopsize ifftsize = 1024 ; FFT size iolaps = ifftsize/ihopsize ; overlaps ibw = sr/ifftsize ; bin bandwidth kcnt init 0 ; counting vars krow init 0 kOla[] init ifftsize ; overlap-add buffer kIn[] init ifftsize ; input buffer kOut[][] init iolaps, ifftsize ; output buffers a1 diskin2 "fox.wav",1,0,1 ; audio input /* every hopsize samples */ if kcnt == ihopsize then /* window and take FFT */ kWin[] window kIn,krow*ihopsize kSpec[] rfft kWin kSpec rect2pol kSpec /* reduce mags between high and low freqs */ ilow = 0 ihigh = 1000 ki = int(ilow/ibw) until ki >= int(ihigh/ibw) do kSpec[ki] = kSpec[ki]*0.1 ki += 2 od kSpec pol2rect kSpec /* IFFT + window */ kRow[] rifft kSpec kWin window kRow, krow*ihopsize /* place it on out buffer */ kOut setrow kWin, krow /* zero the ola buffer */ kOla = 0 /* overlap-add */ ki = 0 until ki == iolaps do kRow getrow kOut, ki kOla = kOla + kRow ki += 1 od /* update counters */ krow = (krow+1)%iolaps kcnt = 0 endif /* shift audio in/out of buffers */ kIn shiftin a1 a2 shiftout kOla out a2/iolaps /* increment counter */ kcnt += ksmps endin </CsInstruments> <CsScore> i1 0 10 </CsScore> </CsoundSynthesizer>