readk4

readk4 — Periodically reads four orchestra control-signal values from an external file.

Description

Periodically reads four orchestra control-signal values from an external file.

Syntax

kr1, kr2, kr3, kr4 readk4 ifilname, iformat, iprd

Initialization

ifilname -- an integer N denoting a file named "readk.N" or a character string (in double quotes, spaces permitted) denoting the external file name. For a string, it may either be a full path name with directory specified or a simple filename. In the later case, the file is sought first in the current directory, then in SSDIR, and finally in SFDIR.

iformat -- specifies the input data format:

  • 1 = 8-bit signed integers (char)

  • 4 = 16-bit short integers

  • 5 = 32-bit long integers

  • 6 = 32-bit floats

  • 7 = ASCII long integers (plain text)

  • 8 = ASCII floats (plain text)

Note that A-law and U-law formats are not available, and that all formats except the last two are binary. The input file should be a "raw", headerless data file.

iprd -- the rate (period) in seconds, rounded to the nearest orchestra control period, at which the signals are read from the input file. A value of 0 implies one control period (the enforced minimum), which will read new values at the orchestra control rate. Longer periods will cause the same values to repeat for more than one control period.

Performance

kr1, kr2, kr3, kr4 -- output of the signals read from ifilname.

This opcode allows four generated control signal values to be read from a named external file. The file should contain no header information but it should contain a regularly sampled time series of control values. For binary formats, the individual samples of each signal are interleaved. For ASCII text formats, the values are assumed to be separated by at least one whitespace character. The four "channels" in a sample frame may be on the same line or separated by newline characters, it does not matter. There may be any number of readk4 opcodes in an instrument or orchestra and they may read from the same or different files.

Examples

Here is an example of the readk4 opcode. It uses the file readk4.csd.

Example 748. Example of the readk4 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 readk4.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 ;writes four control signals to a file
kcf       randh     950, 1, 2, 1, 1050 ;generates one random number between 100 and 2000 per second
kq        randh     10, 1, 2, 1, 11 ;generates another random number between 1 and 21 per second
kdb       randh     9, 1, 2, 1, -15 ;amplitudes in dB between -24 and -6
kpan      randh     .5, 1, 2, 1, .5 ;panning between 0 and 1
          dumpk4    kcf, kq, kdb, kpan, "dumpk4.txt", 8, 1 ;writes the control signals
          prints    "WRITING:\n"
          printks   "kcf = %f, kq = %f, kdb = %f, kpan = %f\n", 1, kcf, kq, kdb, kpan  ;prints them
endin

instr 2 ;reads the file written by instr 1
kcf,kq,kdb,kp readk4 "dumpk4.txt", 8, 1
          prints    "READING:\n"
          printks   "kcf = %f, kq = %f, kdb = %f, kpan = %f\n", 1, kcf, kq, kdb, kp  ;prints values
kdb       lineto    kdb, .1 ;smoothing amp transition
kp        lineto    kp, .1 ;smoothing pan transition
anoise    rand      ampdb(kdb), 2, 1
kbw       =         kcf/kq ;bandwidth of resonant filter
abp       reson     anoise, kcf, kbw
aout      balance   abp, anoise
aL, aR    pan2      aout, kp
          outs      aL, aR
endin

</CsInstruments>
<CsScore>
i 1 0 5
i 2 5 5
e
</CsScore>
</CsoundSynthesizer>


The output should include lines like these:

WRITING:
kcf = 1122.469723, kq = 11.762839, kdb = -14.313445, kpan = 0.538142
kcf = 1122.469723, kq = 11.762839, kdb = -14.313445, kpan = 0.538142
kcf = 1148.638412, kq = 12.040490, kdb = -14.061868, kpan = 0.552205
kcf = 165.796855, kq = 18.523179, kdb = -15.816977, kpan = 0.901528
kcf = 147.729960, kq = 13.071911, kdb = -11.924531, kpan = 0.982518
kcf = 497.430113, kq = 13.605512, kdb = -21.586611, kpan = 0.179229

READING:
WARNING: Seeding from current time 3308160476

kcf = 1122.469700, kq = 11.762800, kdb = -14.313400, kpan = 0.538100
kcf = 1122.469700, kq = 11.762800, kdb = -14.313400, kpan = 0.538100
kcf = 1148.638400, kq = 12.040500, kdb = -14.061900, kpan = 0.552200
kcf = 165.796900, kq = 18.523200, kdb = -15.817000, kpan = 0.901500
kcf = 147.730000, kq = 13.071900, kdb = -11.924500, kpan = 0.982500
kcf = 497.430100, kq = 13.605500, kdb = -21.586600, kpan = 0.179200
      

See Also

dumpk, dumpk2, dumpk3, dumpk4, readk, readk2, readk3

Credits

By: John ffitch and Barry Vercoe

1999 or earlier