fout
Prev | Orchestra Opcodes and Operators | Next

## fout

fout — Outputs a-rate signals to an arbitrary number of channels.

## Description

fout outputs N a-rate signals to a specified file of N channels.

## Syntax

    fout ifilename, iformat, aout1 [, aout2, aout3,...,aoutN]

    fout ifilename, iformat, array[]

## Initialization

ifilename -- the output file's name (in double-quotes).

iformat -- a flag to choose output file format (note: Csound versions older than 5.0 may only support formats 0, 1, and 2):

- -1 - format exactly as per global csound output format flags (-A, -W, --format=..., etc).

- 0 - 32-bit floating point samples without header (binary PCM multichannel file)

- 1 - 16-bit integers without header (binary PCM multichannel file)

- 2 - 16-bit integers with a header. The header type depends on the render (-o) format. For example, if the user chooses the AIFF format (using the -A flag), the header format will be AIFF type.

- 3 - u-law samples with a header (see iformat=2).

- 4 - 16-bit integers with a header (see iformat=2).

- 5 - 32-bit integers with a header (see iformat=2).

- 6 - 32-bit floats with a header (see iformat=2).

- 7 - 8-bit unsigned integers with a header (see iformat=2).

- 8 - 24-bit integers with a header (see iformat=2).

- 9 - 64-bit floats with a header (see iformat=2).

- 50 - ogg-vorbis format.

In addition, Csound versions 5.0 and later allow for explicitly selecting a particular header type by specifying the format as 10 * fileType + sampleFormat, where fileType may be 1 for WAV, 2 for AIFF, 3 for raw (headerless) files, and 4 for IRCAM; sampleFormat is one of the above values in the range 0 to 9, except sample format 0 is taken from the command line (-o), format 1 is 8-bit signed integers, and format 2 is a-law. So, for example, iformat=25 means 32-bit integers with AIFF header.

## Performance

aout1,... aoutN -- signals to be written to the file. In the case of raw files, the expected range of audio signals is determined by the selected sample format; for sound files with a header like WAV and AIFF, the audio signals should be in the range -0dbfs to 0dbfs.

fout (file output) writes samples of audio signals to a file with any number of channels. Channel number depends by the number of aoutN variables (i.e. a mono signal with only an a-rate argument, a stereo signal with two a-rate arguments etc.) Maximum number of channels is fixed to 64. Multiple fout opcodes can be present in the same instrument, referring to different files.

Notice that, unlike out, outs and outq, fout does not zero the audio variable so you must zero it after calling it. If polyphony is to be used, you can use vincr and clear opcodes for this task.

Notice that fout and foutk uses a string containing a file pathname. Whereas, with fouti and foutir, the target file can be only specified by means of a handle-number.

| Note
If you are using fout to generate an audio file for the global output of csound, you might want to use the monitor opcode, which can tap the output buffer, to avoid having to route

## Examples

Here is a simple example of the fout opcode. It uses the file fout.csd.

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

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

    giSine ftgen 0, 0, 2^10, 10, 1

    instr 1

    asig poscil3 .5, 880, giSine
    ;write a raw file: 32 bits with header
         fout "fout_880.wav", 15, asig
         outs asig, asig

    endin

    instr 2

    klfo lfo 1, 2, 0
    asig poscil3 .5*klfo, 220, giSine
    ;write an aiff file: 32 bits with header
         fout "fout_aif.aiff", 25, asig
    ;        fout "fout_all3.wav", 14, asig
         outs asig, asig

    endin

    instr 99 ;read the stereo csound output buffer

    allL, allR monitor
    ;write the output of csound to an audio file
    ;to a wav file: 16 bits with header
               fout "fout_all.wav", 14, allL, allR

    endin
    </CsInstruments>
    <CsScore>

    i 1 0 2
    i 2 0 3
    i 99 0 3
    e
    </CsScore>
    </CsoundSynthesizer>

Here is another example of fout, using it to save the contents of a table to an audio file. It uses the file fout_ftable.csd and beats.wav.

Example 371. Example of the fout opcode to save the contents of an f-table.

    <CsoundSynthesizer>
    <CsOptions>
    ; Select audio/midi flags here according to platform
    ; Audio out   Audio in    No messages
    -odac           -iadc     -d     ;;;RT audio I/O
    ; For Non-realtime ouput leave only the line below:
    ; -o fout_ftable.wav -W ;;; for file output any platform
    </CsOptions>
    <CsInstruments>
    ; By: Jonathan Murphy 2007

      gilen		=		131072
      gicps		=		sr/gilen
      gitab		ftgen		1, 0, gilen, 10, 1

                    instr 1

      /******** write file to table ********/

      ain		diskin2		"beats.wav", 1, 0, 1
      aphs		phasor		gicps
      andx		=		aphs * gilen
    		tablew		ain, andx, gitab

      /******** write table to file ********/

      aosc		table		aphs, gitab, 1
    		out		aosc
    		fout		"beats_copy.wav", 6, aosc

                    endin

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

## See Also

fiopen, fouti, foutir, foutk, monitor

## Credits

Author: Gabriel Maldonado
Italy
1999
Author: John ffitch
NUIM, 2013

New in Csound version 3.56

October 2002. Added a note from Richard Dobson.

Array version new in 6.01

Prev | Up | Next
foscili | Home | fouti