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]

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

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

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 can use either a string containing a file pathname, or a handle-number generated by fiopen. Whereas, with fouti and foutir, the target file can be only specified by means of a handle-number.

[Note] Note

If you are usinf 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 160. 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
; Audio out   Audio in    No messages
-odac           -iadc     -d     ;;;RT audio I/O
; For Non-realtime ouput leave only the line below:
; -o fout.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

; Initialize the global variables.
sr = 44100
kr = 4410
ksmps = 10
nchnls = 1

; Instrument #1.
instr 1
  iamp = 10000
  icps = 440
  iphs = 0

  ; Create an audio signal.
  asig oscils iamp, icps, iphs

  ; Write the audio signal to a headerless audio file 
  ; called "fout.raw".
  fout "fout.raw", 1, asig
endin


</CsInstruments>
<CsScore>

; Play Instrument #1 for 2 seconds.
i 1 0 2
e


</CsScore>
</CsoundSynthesizer>


Here is an example of the fout opcode with a polyphonic score. It uses the file fout_poly.csd and beats.wav.

Example 161. Example of the fout opcode with a polyphonic score.

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

; Initialize the global variables.
sr = 44100
kr = 44100
ksmps = 1
nchnls = 1

; Instrument #1 - Play an audio file.
instr 1
  ; Generate an audio signal using 
  ; the audio file "beats.wav".
  asig soundin "beats.wav"

  out asig
endin

; Instrument #2 - Create a basic tone.
instr 2
  iamp = 5000
  icps = 440
  iphs = 0

  ; Create an audio signal.
  asig oscils iamp, icps, iphs

  out asig
endin

; Instrument #99 - Save the global signal to a file.
instr 99
  ; Read the csound output buffer
  aoutput monitor
  ; Write the output of csound to a headerless 
  ; audio file called "fout_poly.raw".
  fout "fout_poly.raw", 1, aoutput

endin


</CsInstruments>
<CsScore>

; Play Instrument #1 for two seconds.
i 1 0 2

; Play Instrument #2 every quarter-second.
i 2 0.00 0.1
i 2 0.25 0.1
i 2 0.50 0.1
i 2 0.75 0.1
i 2 1.00 0.1
i 2 1.25 0.1
i 2 1.50 0.1
i 2 1.75 0.1

; Make sure the global instrument, #99, is running
; during the entire performance (2 seconds).
i 99 0 2
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 162. 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		diskin		"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

The simple example was written by Kevin Conder.

New in Csound version 3.56

October 2002. Added a note from Richard Dobson.