Skip to content

atsbufread

Reads an ATS data file and stores frequency and amplitude pairs in an internal table.

📝 Note

Up to Csound 6, this opcode was called ATSbufread.

Syntax

atsbufread(ktimepnt, kfmod, iatsfile, ipartials [, ipartialoffset, \
           ipartialincr])
ATSbufread ktimepnt, kfmod, iatsfile, ipartials [, ipartialoffset, \
           ipartialincr]

Initialization

iatsfile – the ATS number (n in ats.n) or the name in quotes of the analysis file made using ATSA.

ipartials – number of partials that will be used in the resynthesis (the noise has a maximum of 25 bands)

ipartialoffset (optional) – is the first partial used (defaults to 0).

ipartialincr (optional) – sets an increment by which these synthesis opcodes counts up from ipartialoffset for ibins components in the re-synthesis (defaults to 1).

Performance

ktimepnt – The time pointer in seconds used to index the ATS file. Used for atsbufread exactly the same as for pvoc.

kfmod – an input for performing pitch transposition or frequency modulation on all of the synthesized partials, if no fm or pitch change is desired then use a 1 for this value.

atsbufread is based on pvbufread by Richard Karpen. It stores data for atscross, atsinterpread and atspartialtap, without producing an output signal itself. The time pointer ktimepnt selects a position in the file. The arguments ipartials, ipartialoffset and ipartialincr select the partials to store, and kfmod scales their frequencies.

Reader scope and order

In Csound 7, each instrument instance has its own current atsbufread. Each UDO and subinstrument instance also has its own reader. A reader inside a UDO or subinstrument does not replace its parent's reader, and a consumer inside it cannot use the parent's reader. Separate notes cannot share a reader through this implicit connection, even when they use the same instrument number.

Put atsbufread and its consumers in the same instance, with the reader before the consumers. If several readers run there, each consumer uses the last reader that ran in that instance. During performance, this follows execution order, so a consumer can use a different reader on a later control cycle.

atspartialtap and atsinterpread need a local reader when they initialize. atscross can initialize before its reader, but the reader must have filled its buffer before atscross runs during performance. Keeping the reader first handles both cases.

Older versions used one current reader across Csound. To update an orchestra that relied on a reader in another note, UDO or subinstrument, add an atsbufread in the instance that consumes the data. These scope rules also apply to the uppercase aliases and to both filename and numeric file arguments.

Examples

Here is an example of the atsbufread opcode. It uses the file atsbufread-modern.csd.

Example of the atsbufread opcode.
<CsoundSynthesizer>
<CsOptions>
; Select audio/midi flags here according to platform
-odac   --limiter=.95  ;;;RT audio out
;-iadc    ;;;uncomment -iadc for RT audio input is needed too
; For Non-realtime ouput leave only the line below:
; -o ATSbufread.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

sr = 44100
ksmps = 32
nchnls = 2
0dbfs  = 1

; by Menno Knevel - 2023

;ATSA wants a mono file!
;it takes a while to analyze these files...
res1:i = systemi(1, {{ atsa finneganswake1.flac finneganswake.ats }})
prints("\n***1st analyzed file is ready***\n\n")
ires2 = systemi(1, {{ atsa drumsMlp.wav drumsMlp.ats }})
prints("\n***2nd analyzed file is ready***\n\n")

instr 1
  res1:i = atsinfo("finneganswake.ats", 3)  ; get number of partials
  res2:i = atsinfo("drumsMlp.ats", 3)       ; get number of partials
  prints("\n***number of partials of finneganswake.ats = %d***\n\n", res1)
  prints("\n***number of partials of drumsMlp.ats = %d***\n\n", res2)

  time1:k = line(0, p3, 12.67)
  time2:k = line(0, p3, 2)
  Line:k = line(0, p3, 1)            ; cross from voice to the beats
  atsbufread(time1, 1, "finneganswake.ats", res1)
  Out:a = atscross(time2, 1, "drumsMlp.ats", 1, Line, 1, res2)
  out(Out*2.5, Out*2.5)
endin

</CsInstruments>
<CsScore>
; sinoid wave.
f 1 0 16384 10 1 .3 .1 .5

i 1 0 12.7
e
</CsScore>
</CsoundSynthesizer>

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

Example of the ATSbufread opcode.
<CsoundSynthesizer>
<CsOptions>
; Select audio/midi flags here according to platform
-odac   --limiter=.95  ;;;RT audio out
;-iadc    ;;;uncomment -iadc for RT audio input is needed too
; For Non-realtime ouput leave only the line below:
; -o ATSbufread.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

sr = 44100
ksmps = 32
nchnls = 2
0dbfs  = 1

; by Menno Knevel - 2023

;ATSA wants a mono file!
;it takes a while to analyze these files...
ires1 system_i 1,{{ atsa finneganswake1.flac finneganswake.ats }} 
prints "\n***1st analyzed file is ready***\n\n"
ires2 system_i 1,{{ atsa drumsMlp.wav drumsMlp.ats }} 
prints "\n***2nd analyzed file is ready***\n\n"

instr 1
ires1 ATSinfo "finneganswake.ats", 3                  ; get number of partials
ires2 ATSinfo "drumsMlp.ats", 3                  ; get number of partials
prints "\n***number of partials of finneganswake.ats = %d***\n\n", ires1
prints "\n***number of partials of drumsMlp.ats = %d***\n\n", ires2

ktime1  line    0, p3, 12.67
ktime2  line    0, p3, 2
kline   line    0, p3, 1                            ; cross from voice to the beats
        ATSbufread ktime1, 1, "finneganswake.ats", ires1
aout    ATScross   ktime2, 1, "drumsMlp.ats", 1, kline, 1, ires2
        outs aout*2.5, aout*2.5

endin

</CsInstruments>
<CsScore>
; sinoid wave.
f 1 0 16384 10 1 .3 .1 .5

i 1 0 12.7
e
</CsScore>
</CsoundSynthesizer>

See also the examples for atscross, atsinterpread and atspartialtap

See also

ATS Spectral Processing

Credits

Author: Alex Norman
Seattle,Washington
2004