filelen

filelen — Returns the length of a sound file.

Description

Returns the length of a sound file.

Syntax

ir filelen ifilcod, [iallowraw]

Initialization

ifilcod -- sound file to be queried

iallowraw -- Allow raw sound files (default=1)

Performance

filelen returns the length of the sound file ifilcod in seconds. filelen can return the length of convolve and PVOC files if the "allow raw sound file" flag is not zero (it is non-zero by default).

Examples

Here is an example of the filelen opcode. It uses the file filelen.csd, fox.wav, and kickroll.wav.

Example 250. Example of the filelen opcode.

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 filelen.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

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

instr 1 ; choose between mono or stereo file

ilen   filelen p4	;calculate length of soundfile
print  ilen
ichn filenchnls  p4	;check number of channels
;print  ichn

if (ichn == 1) then
;mono signal
asig diskin2 p4, 1	
     outs    asig, asig

else
;stereo signal
aL, aR diskin2 p4, .5, 0, 1 
       outs    aL, aR

endif

endin
</CsInstruments>
<CsScore>

i 1 0 3 "fox.wav"	;mono signal
i 1 5 2 "kickroll.wav"	;stereo signal

e
</CsScore>
</CsoundSynthesizer>


The mono audio file fox.wav is 2.8 seconds long, and the stereo file kickroll.wav is 0.9 seconds. So filelen's output should include a line for the mono and the stereo file like this:

instr 1:  ilen = 2.757
instr 1:  ilen = 0.857
      

See Also

filebit, filenchnls, filepeak, filesr

Credits

Author: Matt Ingalls
July 1999

New in Csound version 3.57