ATSread — reads data from an ATS file.
ATSread returns the amplitude (kamp) and frequency (kfreq) information of a user specified partial contained in the ATS analysis file at the time indicated by the time pointer ktimepnt.
iatsfile – the ATS number (n in ats.n) or the name in quotes of the analysis file made using ATSA.
ipartial – the number of the analysis partial to return the frequency in Hz and amplitude.
kfreq, kamp - outputs of the ATSread unit. These values represent the frequency and amplitude of a specific partial selected by the user using ipartial. The partials' informations are derived from an ATS analysis. ATSread linearly interpolates the frequency and amplitude between frames in the ATS analysis file at k-rate. The output is dependent on the data in the analysis file and the pointer ktimepnt.
ktimepnt – The time pointer in seconds used to index the ATS file. Used for ATSread exactly the same as for pvoc and ATSadd.
Here is an example of the ATSread opcode. It uses the file ATSread.csd.
Example 78. Example of the ATSread opcode.
<CsoundSynthesizer> <CsOptions> ; Select audio/midi flags here according to platform -odac ;;;RT audio out ;-iadc ;;;uncomment -iadc if RT audio input is needed too ; For Non-realtime ouput leave only the line below: ; -o ATSread.wav -W ;;; for file output any platform </CsOptions> <CsInstruments> sr = 44100 ksmps = 32 nchnls = 2 0dbfs = 1 ; by Menno Knevel - 2021 ires system_i 1,{{ atsa fox.wav fox.ats }} ; default settings instr 1 ktime line 0, p3, 2 kfreq, kamp ATSread ktime, "beats.ats", 10 ; take the 10th partial aenv linen 1, 0, p3, .1 ; envelope to avoid clicks aout oscili 0.8, kfreq, 1 outs aout * aenv, aout * aenv endin </CsInstruments> <CsScore> f 1 0 16384 10 1 ;sine wave. i 1 0 1 ; fast speed i 1 2 2 ; normal i 1 5 10 ; 5x slower e </CsScore> </CsoundSynthesizer>
Here we are using ATSread to get the 10th partial's frequency and amplitude data out of the 'beats.ats' ATS analysis file. We are using that data to drive an oscillator, but we could use it for anything else that can take a k-rate input, like the bandwidth and resonance of a filter etc.
Here is a musical example of the ATSread opcode. It uses the file ATSread-musical.csd.
Example 79. Example 2 of the ATSread opcode.
<CsoundSynthesizer> <CsOptions> -odac -d -m128 </CsOptions> <CsInstruments> ;example by joachim heintz sr = 44100 ksmps = 32 nchnls = 2 0dbfs = 1 ires1 system_i 1,{{ atsa fox.wav fox.ats }} ; default settings giSine ftgen 0, 0, 1024, 10, 1 gSfile = "fox.ats" giNumParts ATSinfo gSfile, 3 ;overall number of partials giDur ATSinfo gSfile, 7 ;duration seed 0 instr ReadOnePartial iPartial = p4 p3 = giDur ktime line 0, giDur, giDur prints "Resynthesizing partial number %d.\n", iPartial kFq,kAmp ATSread ktime, gSfile, iPartial kAmp port kAmp, .1 ;smooth amplitudes - still not satisfactoring aOut poscil kAmp, kFq, giSine aOut linen aOut, 0, p3, .01 ;anti-click outs aOut*10, aOut*10 ;start next instr: normal speed, three loops, pause between loops one second event_i "i", "MasterRand", giDur+3, 1, 1, 3, 2 endin instr MasterRand ;random selections of 10 partials per second, overlapping iSpeed = p4 ;speed of reading / playing iNumLoops = p5 ;number of loops iPause = p6 ;length of pause between loops prints "Resynthesizing random partials.\n" p3 = (giDur/iSpeed+iPause) * iNumLoops ;start next instr: half speed, three loops, three seonds pause between loops event_i "i", "MasterArp", p3+3, 1, .5, 3, 3 ;loop over duration plus pause loop: timout 0, giDur/iSpeed+iPause, play reinit loop play: gkTime line 0, giDur/iSpeed, giDur ;start time from 0 in each loop kTrig metro 10 ;10 new partials per second ;call subinstrument if trigger and no pause if kTrig == 1 && gkTime < giDur then kPart random 1, giNumParts+.999 event "i", "PlayRand", 0, 1, int(kPart) endif endin instr MasterArp ;argeggio-like reading and playing of partials iSpeed = p4 ;speed of reading / playing iNumLoops = p5 ;number of loops iPause = p6 ;length of pause between loops prints "Arpeggiating partials.\n" p3 = (giDur/iSpeed+iPause) * iNumLoops loop: timout 0, giDur/iSpeed+iPause, play reinit loop play: gkTime line 0, giDur/iSpeed, giDur kArp linseg 1, (giDur/iSpeed)/2, giNumParts, (giDur/iSpeed)/2, 1 ;arp up and down kTrig metro 10 ;10 new partials per second if kTrig == 1 && gkTime < giDur then event "i", "PlayArp", 0, 5, int(kArp) endif ;exit csound when finished event_i "i", "End", p3+5, 1 endin instr PlayRand iPartial = p4 kFq,kAmp ATSread gkTime, gSfile, iPartial kamp port kAmp, .15 ;smooth amplitudes aOut poscil kAmp, kFq, giSine aOut linen aOut, .01, p3, .01 outs aOut, aOut endin instr PlayArp kCount init 1 ;k-cycle iPartial = p4 kFq,kAmp ATSread gkTime, gSfile, iPartial if kCount == 1 then ;get freq from first k-cycle kModFq = kFq ;avoid to go with 0 Hz as this blocks the mode filter if kModFq == 0 then turnoff endif endif iVol random -42, -12 ;db iOffset random .01, .1 ;no too regularily ... aImp mpulse ampdb(iVol), p3, iOffset iQ random 500, 5000 aOut mode aImp, kModFq, iQ aOut linen aOut, 0, p3, p3/3 outs aOut, aOut kCount = 2 endin instr End exitnow endin </CsInstruments> <CsScore> i "ReadOnePartial" 0 1 10 e 999 </CsScore> </CsoundSynthesizer>