1<CsoundSynthesizer> 2<CsOptions> 3; Select audio/midi flags here according to platform 4-odac ;;;realtime audio out 5;-iadc ;;;uncomment -iadc if RT audio input is needed too 6; For Non-realtime ouput leave only the line below: 7; -o upsamp.wav -W ;;; for file output any platform 8</CsOptions> 9<CsInstruments> 10;;with code from Steven Cook / David Akbari, Menno Knevel and Joachim Heintz 11 12sr = 44100 13ksmps = 32 14nchnls = 2 150dbfs = 1 16 17seed 1000 18 19 opcode Decimator, a, akk ;UDO Sample rate / Bit depth reducer 20 ;see http://www.csounds.com/udo/displayOpcode.php?opcode_id=73 21 setksmps 1 22ain, kbit, ksrate xin 23 24kbits = 2^kbit ;bit depth (1 to 16) 25kfold = (sr/ksrate) ;sample rate 26kin downsamp ain ;convert to kr 27kin = (kin+0dbfs) ;add DC to avoid (-) 28kin = kin*(kbits/(0dbfs*2)) ;scale signal level 29kin = int(kin) ;quantise 30aout upsamp kin ;convert to sr 31aout = aout*(2/kbits)-0dbfs ;rescale and remove DC 32a0ut fold aout, kfold ;resample 33 xout a0ut 34 endop 35 36 37instr 1 ;avoid playing this too loud 38 39kbit = p4 40ksr = 44100 41asig diskin "fox.wav", 1 42aout Decimator asig, kbit, ksr 43 printks "bitrate = %d, ", 3, kbit 44 printks "with samplerate = %d\\n", 3, ksr 45 outs aout*.7, aout*.7 46endin 47 48 49instr 2 ;moving randomly between different bit values (1 - 6) 50 51kbit randomi 1, 6, .5, 1 52asig diskin "fox.wav", 1, 0, 1 ;loop play 53aout Decimator asig, kbit, 44100 54 printks "bitrate = %f\n", .3, kbit 55 outs aout*.7, aout*.7 56 57endin 58 59</CsInstruments> 60<CsScore> 61i 1 0 3 16 ;sounds allright but 62i 1 + 3 5 ;it's getting worse 63i 1 + 3 2 ;and worse... 64i 2 9 22 ;or quality moves randomly 65e 66</CsScore> 67</CsoundSynthesizer> 68