filenchnls
Prev | Orchestra Opcodes and Operators | Next

## filenchnls

filenchnls — Returns the number of channels in a sound file.

## Description

Returns the number of channels in a sound file.

## Syntax

    ir filenchnls ifilcod [, iallowraw]

## Initialization

ifilcod -- sound file to be queried

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

## Performance

filenchnls returns the number of channels in the sound file ifilcod. filechnls can return the number of channels 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 filenchnls opcode. It uses the file filenchnls.csd, fox.wav, and drumsSlp.wav.

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

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

    ; by Menno Knevel 2022

    instr 1 ; choose between mono or stereo file

    ichn filenchnls  p4	            ; check number of channels
    prints  "\nnumber of channels = %d\n\n", ichn

    if (ichn == 1) then
        asig diskin2 p4, 1              ; mono signal
        outs    asig, asig
    else
        aL, aR diskin2 p4, 1            ; stereo signal
        outs    aL, aR
    endif

    endin

    </CsInstruments>
    <CsScore>

    i 1 0 3 "fox.wav"	;mono signal
    i 1 5 4 "drumsSlp.wav"	;stereo signal
    e
    </CsScore>
    </CsoundSynthesizer>

The audio file “fox.wav” is monoaural (1 channel), while “drumsSlp.wav” is stereo (2 channels) So filenchnls's output should include lines like this:

    number of channels = 1
    number of channels = 2

## See also

Sound File Queries

## Credits

Author: Matt Ingalls
July 1999

New in Csound version 3.57

Prev | Up | Next
filelen | Home | filepeak