fiopen — Opens a file in a specific mode.
ihandle -- a number which specifies this file.
ifilename -- the target file's name (in double-quotes).
imode -- choose the mode of opening the file. imode can be a value chosen among the following:
0 - open a text file for writing
1 - open a text file for reading
2 - open a binary file for writing
3 - open a binary file for reading
fiopen opens a file to be used by the fout family of opcodes. It is safer to use it in the header section, external to any instruments. It returns a number, ihandle, which unequivocally refers to the opened file.
If fiopen is called on an already open file, it just returns the same handle again, and does not close the file.
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.
Here is an example of the fiopen opcode. Play fiopen.csd Note that the example must be run from a directory for which the user has write access.
Example 307. Example of the fiopen 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 fiopen.wav -W ;;; for file output any platform </CsOptions> <CsInstruments> sr = 44100 ksmps = 32 nchnls = 2 0dbfs = 1 gihand fiopen "test1.txt", 0 instr 1 ires random 0, 100 fouti gihand, 0, 1, ires ficlose gihand endin </CsInstruments> <CsScore> i 1 0 1 e </CsScore> </CsoundSynthesizer>