times

times — Read absolute time in seconds.

Description

Read absolute time, in seconds, since the start of the performance.

Syntax

ires times
kres times

Performance

Time in seconds is available with times. This would return 0.5 after half a second.

times can both produce a k-rate variable for output. There are no input parameters.

times can also operate at the start of the instance of the instrument. It produces an i-rate variable (starting with i or gi) as its output.

Examples

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

Example 1093. Example of the times 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 times_complex.wav -W ;;; for file output any platform 
</CsOptions> 
<CsInstruments> 
;by joachim heintz and rory walsh 
sr = 44100 
ksmps = 32 
nchnls = 2 
0dbfs = 1 

giWave   ftgen      0, 0, 1024, 10, 1, .5, .25 

instr again 

instance =          p4 
 ;reset the duration of this instance 
iDur     rnd31      5, 3				;shorter values are more probable 
iDur     =          abs(iDur) + 0.2 
p3       =          iDur 
 ;trigger the effect instrument of this instance 
         event_i    "i", "fx_processor", 0, iDur, instance 
 ;print the status quo 
kTime    times 
         prints     "instance = %d, start = %f, duration = %f\n", instance, i(kTime), iDur 
 ;make sound 
iamp     active     1					;scale amplitudes 
iOct     random     5, 10				;find pitch 
aEnv     transeg    0, 0.02, 0, 1/iamp, p3-0.02, -6, 0	;output envelope 
aSend    poscil     aEnv, cpsoct(iOct), giWave		;audio signal 
 ;send signal to effect instrument 
Sbus     sprintf    "audio_%d", instance		;create unique software bus 
         chnset     aSend/2, Sbus			;send audio on this bus 
 ;get the last k-cycle of this instance and trigger the successor in it 
kLast    release 
         schedkwhen kLast, 0, 0, "again", 0, 1, instance+1 
endin 

instr fx_processor 
 ;apply feedback delay to the above instrument 
iwhich    =         p4					;receive instance number ... 
Sbus      sprintf   "audio_%d", iwhich			; ... and related software bus 
audio     chnget    Sbus				;receive audio on this bus 
irvbtim   random    1, 5				;find reverb time 
p3        =         p3+irvbtim				;adjust instrument duration 
iltptmL   random    .1, .5				;find looptime left ... 
iltptmR   random    .1, .5				;...and right 
ipan      random    0, 1				; pan and ... 
imix      random    0, 1				;... mix audio 
aL,aR     pan2      audio, ipan				;create stereo 
awetL     comb      aL, irvbtim, iltptmL		;comb filter 
awetR     comb      aR, irvbtim, iltptmR 
aoutL     ntrpol    aL, awetL, imix			;wet-dry mix 
aoutR     ntrpol    aR, awetR, imix 
          outs      aoutL/2, aoutR/2 
endin 

</CsInstruments> 
<CsScore> 
i "again" 0 1 1 

e 3600 
</CsScore> 
</CsoundSynthesizer>


Its output should include lines like these:

new alloc for instr again:
instance = 1, start = 0.000000, duration = 0.650439
new alloc for instr fx_processor:
instance = 2, start = 0.650884, duration = 0.411043
new alloc for instr fx_processor:
instance = 3, start = 1.061587, duration = 0.231085
new alloc for instr fx_processor:
instance = 4, start = 1.292336, duration = 0.543473
new alloc for instr fx_processor:
instance = 5, start = 1.835828, duration = 1.777097
      

See Also

timeinstk, timeinsts, timek

Credits

Author: Robin Whittle
Australia
May 1997