User-Defined Opcode Database

Print_a

Prints an audio signal (vector) every kPeriod seconds.

Download UDO File

Description

Prints the values of an audio signal. As this is a list of single sample values in the length of ksmps, ksmps values are printed in []. Like in the printk opcode, you can specify the period between print operations, and the starting spaces.
You may have to set the flag -+max_str_len=10000 to avoid buffer overflow.

Syntax

Print_a aSig [,kPeriod [,kSpaces]]

Performance

aSig - input signal to be printed
kPeriod - time in seconds between print operations (default = 1). 0 means that printing is performed in each control cycle.
kSpaces - number of spaces to insert before printing (default = 0)

Code

  opcode Print_a, 0, aPO
aSig, kPeriod, kSpaces xin
kTim       timeinsts
kNextPeriod init      0
kPrevTim   init       0 
;perform printout if period has been reached
if kTim >= kPrevTim + kNextPeriod - ksmps/sr then
kIndx      =          0
Sformat    sprintfk   "%%%ds %%.6f: [", kSpaces + 5
Sout       sprintfk   Sformat, "Time:", kTim
;collect all values in a string
printloop:
kVal       vaget      kIndx, aSig
Sval       sprintfk   "%f, ", kVal
Sout       strcatk    Sout, Sval
           loop_lt    kIndx, 1, ksmps, printloop
;remove the last comma and close the bracket
kLen       strlenk    Sout
Scut       strsubk    Sout, 0, kLen-2
           printf     "%s]\n", kTim, Scut
;reset previous time and next period
kPrevTim   =          kTim      
kNextPeriod =         kPeriod
endif
  endop

Examples

<CsoundSynthesizer>
<CsOptions>
-+max_str_len=10000 -ndm128
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 32
0dbfs = 1
nchnls = 1

  opcode Print_a, 0, aPO
aSig, kPeriod, kSpaces xin
kTim       timeinsts
kNextPeriod init      0
kPrevTim   init       0 
;perform printout if period has been reached
if kTim >= kPrevTim + kNextPeriod - ksmps/sr then
kIndx      =          0
Sformat    sprintfk   "%%%ds %%.6f: [", kSpaces + 5
Sout       sprintfk   Sformat, "Time:", kTim
;collect all values in a string
printloop:
kVal       vaget      kIndx, aSig
Sval       sprintfk   "%f, ", kVal
Sout       strcatk    Sout, Sval
           loop_lt    kIndx, 1, ksmps, printloop
;remove the last comma and close the bracket
kLen       strlenk    Sout
Scut       strsubk    Sout, 0, kLen-2
           printf     "%s]\n", kTim, Scut
;reset previous time and next period
kPrevTim   =          kTim      
kNextPeriod =         kPeriod
endif
  endop


  instr test1
  ;print the first three k-cycles
           puts       "\ntest 1:", 1
aSin       oscils     1, 400, 0
           Print_a    aSin, 0
  endin
  
  instr test2
  ;print once a second (default)
           puts       "\ntest 2:", 1
aSin       oscils     1, 400, 0
           Print_a    aSin
  endin

  instr test3
  ;print faster at the beginning, then once a second
           puts       "\ntest 3:", 1
aSin       oscils     1, 400, 0
kPeriod    linseg     0, 1, 1
           Print_a    aSin, kPeriod
  endin

  instr test4
  ;printing with different starting spaces
           puts       "\ntest 4:", 1
aSin       oscils     1, 400, 0
kSpaces    linseg     0, p3/2, 10, p3/2, 0
           Print_a    aSin, .5, kSpaces
  endin

</CsInstruments>
<CsScore>
i "test1" 0 [3*32/44100]
i "test2" 1 5
i "test3" 7 5
i "test4" 13 5.1
</CsScore>
</CsoundSynthesizer>

output for test 1:
Time: 0.000726: [0.000000, 0.056959, 0.113734, 0.170139, 
0.225992, 0.281111, 0.335317, 0.388435, 0.440291, 0.490718, 
0.539551, 0.586632, 0.631808, 0.674933, 0.715867, 0.754476, 
0.790635, 0.824227, 0.855143, 0.883282, 0.908553, 0.930874, 
0.950172, 0.966385, 0.979460, 0.989355, 0.996038, 0.999486, 
0.999689, 0.996646, 0.990367, 0.980872]
Time: 0.001451: [0.968192, 0.952369, 0.933453, 0.911506, 
0.886599, 0.858814, 0.828240, 0.794977, 0.759132, 0.720823, 
0.680173, 0.637314, 0.592386, 0.545535, 0.496912, 0.446676, 
0.394989, 0.342020, 0.287940, 0.232926, 0.177155, 0.120809, 
0.064070, 0.007124, -0.049846, -0.106654, -0.163115, 
-0.219047, -0.274268, -0.328598, -0.381861, -0.433884]
Time: 0.002177: [-0.484498, -0.533539, -0.580848, -0.626271, 
-0.669660, -0.710875, -0.749781, -0.786253, -0.820172, 
-0.851428, -0.879919, -0.905554, -0.928248, -0.947927, 
-0.964529, -0.977999, -0.988294, -0.995379, -0.999233, 
-0.999841, -0.997204, -0.991328, -0.982234, -0.969950, 
-0.954517, -0.935984, -0.914413, -0.889872, -0.862442, 
-0.832211, -0.799278, -0.763750]

Credits

joachim heintz 2013


Previous Home Next
PitchShifter   pvshift