User-Defined Opcode Database

MS2S

Converts a floating point number in the format min.sec to seconds

Download UDO File

Description

Converts a floating point number in the format min.sec to seconds

Syntax

isec MS2S iminsec

Initialization

iminsec - a float in the format min.sec. the first two digits of the fractional part are the full seconds, the following ones mean 1/10, 1/100, ... seconds. See the examples below.
isec - number of seconds equating iminsec

Code

  opcode MS2S, i, i
ifloat		xin
imin		=		int(ifloat)
isec		=		frac(ifloat) * 100
		xout		imin*60 + isec
  endop

Examples

<CsoundSynthesizer>
<CsOptions>
-n
</CsOptions>
<CsInstruments>

  opcode MS2S, i, i
;converts a float in the format min.sec to seconds
ifloat		xin
imin		=		int(ifloat)
isec		=		frac(ifloat) * 100
		xout		imin*60 + isec
  endop

instr 1
isec		MS2S		p4
		prints		"%f\n", isec
endin

</CsInstruments>
<CsScore>
i 1 0 0 4.33
i 1 0 0 60 ;one hour
i 1 0 0 0.20 ;twenty seconds
i 1 0 0 0.2 ;also twenty seconds
i 1 0 0 0.02 ;two seconds
i 1 0 0 0.00001 ;one millisecond
i 1 0 0 26.011499 ;26' 1.1499''
</CsScore>
</CsoundSynthesizer>

Credits

joachim heintz 2011


Previous Home Next
Linek   KeyOnce