User-Defined Opcode Database

FileToPvsBuf

Writes an audio file to a pvs buffer

Download UDO File

Description

Writes an audio file in the first k-cycle to a pvs buffer. The buffer is written with pvsbuffer and can be read with pvsread.
This Opcode accepts either Mono or Stereo files as input (from a stereo file, just the first channel is used).

Syntax

ibuf, ilen, ktim FileToPvsBuf Sfile, ifftsize, ioverlap, iwinsize, iwinshape

Initialization

ibuf - variable of the buffer (the value is generated by pvsbuffer)
ilen - length of Sfile (as FileToPvsBuf queries the file length, it puts it out)
Sfile - audio file name in double quotes
ifftsize - fftsize (see Csound manual under pvsanal)
ioverlap - overlap in samples (see Csound manual under pvsanal)
iwinsize - window size (see Csound manual under pvsanal)
iwinshape - 0=Hamming, 1=von-Hann (see Csound manual under pvsanal)

Performance

ktim - current time of writing the buffer

Code

opcode FileToPvsBuf, iik, Siiii
;;writes an audio file at the first k-cycle to a fft-buffer (via pvsbuffer)
;;from a stereo file, just the first channel is used
Sfile, ifftsize, ioverlap, iwinsize, iwinshape xin
ktimek		timeinstk
if ktimek == 1 then
ilen		filelen	Sfile
ichn		filenchnls	Sfile
kcycles	=		ilen * kr; number of k-cycles to write the fft-buffer
kcount		init		0
if ichn == 1 then
loop1:
ain		soundin	Sfile
fftin		pvsanal	ain, ifftsize, ioverlap, iwinsize, iwinshape
ibuf, ktim	pvsbuffer	fftin, ilen + (ifftsize / sr)
		loop_lt	kcount, 1, kcycles, loop1
else
loop2:
ain, ano	soundin	Sfile
fftin		pvsanal	ain, ifftsize, ioverlap, iwinsize, iwinshape
ibuf, ktim	pvsbuffer	fftin, ilen + (ifftsize / sr)
		loop_lt	kcount, 1, kcycles, loop2
endif
		xout		ibuf, ilen, ktim
endif
endop

Examples

<CsoundSynthesizer>
<CsOptions>
-odac
</CsOptions>
<CsInstruments>

sr = 44100
ksmps = 16
nchnls = 1
0dbfs = 1

;; uses the file "fox.wav" (which is part of the Csound Manual)

opcode FileToPvsBuf, iik, Siiii
;;writes an audio file at the first k-cycle to a fft-buffer (via pvsbuffer)
;;from a stereo file, just the first channel is used
Sfile, ifftsize, ioverlap, iwinsize, iwinshape xin
ktimek		timeinstk
if ktimek == 1 then
ilen		filelen	Sfile
ichn		filenchnls	Sfile
kcycles	=		ilen * kr; number of k-cycles to write the fft-buffer
kcount		init		0
if ichn == 1 then
loop1:
ain		soundin	Sfile
fftin		pvsanal	ain, ifftsize, ioverlap, iwinsize, iwinshape
ibuf, ktim	pvsbuffer	fftin, ilen + (ifftsize / sr)
		loop_lt	kcount, 1, kcycles, loop1
else
loop2:
ain, ano	soundin	Sfile
fftin		pvsanal	ain, ifftsize, ioverlap, iwinsize, iwinshape
ibuf, ktim	pvsbuffer	fftin, ilen + (ifftsize / sr)
		loop_lt	kcount, 1, kcycles, loop2
endif
		xout		ibuf, ilen, ktim
endif
endop

instr 1
ifftsize	=		1024
ioverlap	=		ifftsize / 4
iwinsize	=		ifftsize
iwinshape	=		1; von-Hann window
ibuffer, ilen, k0		FileToPvsBuf	"fox.wav", ifftsize, ioverlap, iwinsize, iwinshape
ktmpnt		linseg		0, ilen * 2, ilen; time stretching
fread 		pvsbufread  	ktmpnt, ibuffer
aout		pvsynth	fread
		out		aout
endin

</CsInstruments>
<CsScore>
i 1 0 6
e
</CsScore>
</CsoundSynthesizer>

Credits

joachim heintz 2009


Previous Home Next
FreqByCentTab   TabPermRand_i