filesr
Prev | Orchestra Opcodes and Operators | Next

## filesr

filesr — Returns the sample rate of a sound file.

## Description

Returns the sample rate of a sound file.

## Syntax

    ir filesr ifilcod [, iallowraw]

## Initialization

ifilcod -- sound file to be queried

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

## Performance

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

## Examples

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

Example 224. Example of the filesr 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 filesr.wav -W ;;; for file output any platform
    </CsOptions>
    <CsInstruments>

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

    ;after an example from Jonathan Murphy

    instr 1
    ;load sound into an ftable
      Sfile	    strcpy    "beats.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
    loop:
      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

    endin
    </CsInstruments>
    <CsScore>

    i1 0 2
    e
    </CsScore>
    </CsoundSynthesizer>

The audio file “beats.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

filebit, filelen, filenchnls, filepeak

## Credits

Author: Matt Ingalls
July 1999

New in Csound version 3.57

Prev | Up | Next
filepeak | Home | filevalid