filesr — Returns the sample rate of a sound file.


Returns the sample rate of a sound file.


ir filesr ifilcod [, iallowraw]


ifilcod -- sound file to be queried

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


filesr returns the sample rate of the sound file ifilcod. filesr can return the sample rate of convolve and PVOC files if the iallowraw flag is not zero (it is non-zero by default).


Here is an example of the filesr opcode. It uses the file filesr.csd, and drumsMlp.wav.

Example 303. Example of the filesr opcode.

See the sections Real-time Audio and Command Line Flags for more information on using command line flags.

; 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 filesr.wav -W ;;; for file output any platform

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

;after an example from Jonathan Murphy

instr 1 
;load sound into an ftable
  Sfile	    strcpy    "drumsMlp.wav" 
  ilen	    filelen   Sfile 
  isr	    filesr    Sfile 
  isamps    =  ilen * isr 
;adjust the length of the table to be a power of two closest
;to the actual size of the sound 
  isize	    init      1 
  isize	    =  isize * 2 
  if (isize < isamps) igoto loop 
  itab	    ftgen     0, 0, isize, 1, Sfile, 0, 0, 0 
prints  "sample rate = %f, size = %f\n", isr, isize ;prints them

i1 0 2

The audio file drumsMlp.wav was sampled at 44.1 KHz. So filesr's output should include a line like this:

sample rate = 44100.000000, size = 131072.000000

See also

Sound File Queries


Author: Matt Ingalls
July 1999

New in Csound version 3.57