OPCODE GUIDE: DATA
BUFFER / FUNCTION TABLES
See the chapter about function tables for more detailled information.
Creating Function Tables (Buffers)
Writing To Tablestableiw / tablew: Write values to a function table at i-rate (tableiw), k-rate and a-rate (tablew). These opcodes provide many options and are safe because of boundary check, but you may have problems with non-power-of-two tables.
tabw_i / tabw: Write values to a function table at i-rate (tabw_i), k-rate or a-rate (tabw). Offer less options than the tableiw/tablew opcodes, but work also for non-power-of-two tables. They do not provide a boundary check, which makes them fast but also give the user the resposability not writing any value off the table boundaries.
Reading From Tables
table / tablei / table3: Read values from a function table at any rate, either by direct indexing (table), or by linear (tablei) or cubic (table3) interpolation. These opcodes provide many options and are safe because of boundary check, but you may have problems with non-power-of-two tables.
tab_i / tab: Read values from a function table at i-rate (tab_i), k-rate or a-rate (tab). Offer no interpolation and less options than the table opcodes, but they work also for non-power-of-two tables. They do not provide a boundary check, which makes them fast but also give the user the resposability not reading any value off the table boundaries.
Saving Tables To Files
ftsave / ftsavek: Save a function table as a file, at i-time (ftsave) or k-time (ftsavek). This can be a text file or a binary file, but not a soundfile. If you want to save a soundfile, use the User Defined Opcode TableToSF.
Reading Tables From FilesGEN23 transfers a text file into a function table.
SIGNAL INPUT/OUTPUT, SAMPLE AND LOOP PLAYBACK, SOUNDFONTS
Signal Input And Output
outch writes any audio signal(s) to any output channel(s). If Csound is in realtime mode (by the flag '-o dac' or by the 'Render in Realtime' mode of a frontend like QuteCsound), the output channels are the channels of your output device. If Csound is in 'Render to file' mode (by the flag '-o mysoundfile.wav' or the the frontend's choice), the output channels are the channels of the soundfile which is being written. Make sure you have the nchnls value in the orchestra header set properly to get the number of channels you wish to have.
monitor can be used (in an instrument with the highest number) to get the sum of all audio on the different output channels.
Sample Playback With Optional Looping
flooper2 is a function-table-based crossfading looper.
sndloop records input audio and plays it back in a loop with user-defined duration and crossfade time.
Note that there are also User Defined Opcodes for sample playback of buffers / function tables.
Soundfonts And Fluid Opcodes
fluidEngine instantiates a FluidSynth engine.
fluidSetInterpMethod sets an interpolation method for a channel in a FluidSynth engine.
fluidLoad loads SoundFonts.
fluidProgramSelect assigns presets from a SoundFont to a FluidSynth engine's MIDI channel.
fluidNote plays a note on a FluidSynth engine's MIDI channel.
fluidCCi sends a controller message at i-time to a FluidSynth engine's MIDI channel.
fluidCCk sends a controller message at k-rate to a FluidSynth engine's MIDI channel.
fluidControl plays and controls loaded Soundfonts (using 'raw' MIDI messages).
fluidOut receives audio from a single FluidSynth engine.fluidAllOut receives audio from all FluidSynth engines.
FILE INPUT AND OUTPUT
Sound File Input
diskin is like soundin, but can also alter the speed of reading (resulting in higher or lower pitches) and you have an option to loop the file.
diskin2 is like diskin, but automatically converts the sample rate of the soundfile if it does not match the sample rate of the orchestra, and it offers different interpolation methods for reading the soundfile at altered speed.
GEN01 reads soundfile into a function table (buffer).mp3in lets you play mp3 sound files.
Sound File Queries
filelen returns the length of a soundfile in seconds.
filesr returns the sample rate of a soundfile.
filenchnls returns the number of channels of a soundfile.
filepeak returns the peak absolute value of a soundfile, either of one specified channel, or from all channels. Make sure you have set 0dbfs to 1; otherwise you will get values relative to Csound's default 0dbfs value of 32768.filebit returns the bit depth of a soundfile.
Sound File Output
Keep in mind that Csound always writes output to a file if you have set the '-o' flag to the name of a soundfile (or if you choose 'render to file' in a frontend like QuteCound).
fout writes any audio signal(s) to a file, regardless Csound is in realtime or render-to-file mode. So you can record your live performance with this opcode.
Non-Soundfile Input And Output
readk can read data from external files (for instance a text file) and transform them to k-rate values.
GEN23 transfers a text file into a function table.
dumpk writes k-rate signals to a text file.
fprints / fprintks write any formatted string to a file. If you call this opcode several times during one performance, the strings are appended. If you write to an already existing file, the file will be overwritten.
CONVERTERS OF DATA TYPES
i <- k
i(k) returns the value of a k-variable at init-time. This can be useful to get the value of GUI controllers, or when using the reinit feature.
k <- a
downsamp converts an a-rate signal to a k-rate signal, with optional averaging.max_k returns the maximum of an a-rate signal in a certain time span, with different options of calculation
a <- k
upsamp converts a k-rate signal to an a-rate signal by simple repetitions. It is the same as the statement asig=ksig.interp converts a k-rate signal to an a-rate signal by interpolation.
PRINTING AND STRINGS
print is a simple opcode for printing i-variables. Note that the printed numbers are rounded to 3 decimal places.
printk is its counterpart for k-variables. The itime argument specifies the time in seconds between printings (itime=0 means one printout in each k-cycle which is usually some thousand printings per second).
printk2 prints a k-variable whenever it has changed.puts prints S-variables. The ktrig argument lets you print either at i-time or at k-time.
prints lets you print a format string at i-time. The format is similar to the C-style syntax (verweis). There is no %s format, therefore no string variables can be printed.
printf_i is very similar to prints. It also works at init-time. The advantage in comparision to prints is the ability of printing string variables. On the other hand, you need a trigger and at least one input argument.
printks is like prints, but takes k-variables, and like at printk you must specify a time between printing.printf is like printf_i, but works at k-rate.
sprintf works like printf_i, but stores the output in a string variable, instead of printing it out.
sprintfk is the same for k-rate arguments.
strset links any string with a numeric value.strget transforms a strset number back to a string.
String Manipulation And Conversion