User-Defined Opcode Database |
---|
Sample rate / Bit depth reduce. Based on the work of Steven Cook. k-rate parameters.
Download UDO FileThis opcode implements one possible algorithm for sample rate / bit depth reduction. It is based on the work of Steven Cook but varies in that it utilizes the local ksmps feature of the UDO and has k-rate input parameters (the original was i-rate and can be viewed here http://www.csounds.com/cook/csound/Decimator.orc)
aout decimator ain, kbitdepth, ksrate
ain - Audio input signal.
kbitdepth - The bit depth of signal aout. Typically in range (1-16). Floats are OK.
ksrate - The sample rate of signal aout. Non-integer values are OK.
opcode decimator, a, akk setksmps 1 ain, kbit, ksrate xin kbits = 2^kbit ; Bit depth (1 to 16) kfold = (sr/ksrate) ; Sample rate kin downsamp ain ; Convert to kr kin = (kin + 32768) ; Add DC to avoid (-) kin = kin*(kbits / 65536) ; Divide signal level kin = int(kin) ; Quantise aout upsamp kin ; Convert to sr aout = aout * (65536/kbits) - 32768 ; Scale and remove DC a0ut fold aout, kfold ; Resample xout a0ut endop
<CsoundSynthesizer> <CsInstruments> sr = 44100 kr = 441 ksmps = 100 nchnls = 2 #include "decimator.udo" /*--- ---*/ instr 1 kbet ctrl7 1, 1, 1, 16 kser ctrl7 1, 7, 11025, 44100 asig diskin "/loops/dl_break2.aif", 1, 0, 1 aout decimator asig, kbet, kser printk2 kbet printk2 kser outs aout, aout endin /*--- ---*/ </CsInstruments> <CsScore> i1 0 100 e </CsScore> </CsoundSynthesizer>
Steven Cook. Implemented as a UDO by David Akbari - 2005.
Previous | Home | Next |
cpsmid | declick |