readk

readk — Periodically reads an orchestra control-signal value from an external file.

Description

Periodically reads an orchestra control-signal value from a named external file in a specific format.

Syntax

kres readk 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 signal is 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

kres -- output of the signal read from ifilname.

This opcode allows a generated control signal value 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 ASCII text formats, the values are assumed to be separated by at least one whitespace character. There may be any number of readk opcodes in an instrument or orchestra and they may read from the same or different files.

Examples

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

Example 721. Example of the readk 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
-odac           -iadc    ;;;RT audio I/O
; For Non-realtime ouput leave only the line below:
; -o readk.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

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

0dbfs = 1
; By Andres Cabrera 2008

instr 1
; Read a number from the file every 0.5 seconds
  kfibo readk "fibonacci.txt", 7, 0.5
  kpitchclass = 8 +  ((kfibo % 12)/100)
  printk2 kpitchclass
  kcps = cpspch( kpitchclass )
  printk2 kcps
  a1 oscil 0.5, kcps, 1
  out a1
endin


</CsInstruments>
<CsScore>
f 1 0 1024 10 1
i 1 0 10
e


</CsScore>
</CsoundSynthesizer>


Here is another example of the readk opcode. It uses the file readk-2.csd.

Example 722. Example 2 of the readk opcode.

<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 readk-2.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 a control signal to a file
kfreq randh  100, 1, 2, 1, 500 ;generates one random number between 400 and 600 per second
      dumpk  kfreq, "dumpk.txt", 8, 1 ;writes the control signal
      printk 1, kfreq 				 ;prints it
endin

instr 2 ;reads the file written by instr 1
kfreq readk  "dumpk.txt", 8, 1
      printk 1, kfreq ;prints it
aout  poscil .2, kfreq, giSine
      outs   aout, aout
endin

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


Its output should include lines like this:

WARNING: Seeding from current time 683384022

 i   1 time     1.00033:   463.64510
 i   1 time     2.00000:   463.64510
 i   1 time     3.00000:   483.14200
 i   1 time     4.00000:   567.55973
 i   1 time     5.00000:   576.37060
 i   1 time     6.00000:   460.66550

 i   2 time     6.00033:   463.64510
 i   2 time     7.00000:   463.64510
 i   2 time     8.00000:   483.14200
 i   2 time     9.00000:   567.55970
 i   2 time    10.00000:   576.37060
 i   2 time    11.00000:   460.66550

See Also

dumpk, dumpk2, dumpk3, dumpk4, readk2, readk3, readk4

Credits

By: John ffitch and Barry Vercoe

1999 or earlier