Debian Codegraph @

examples/upsamp.csd

raw
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
12 sr = 44100
13 ksmps = 32
14 nchnls = 2
15 0dbfs = 1
16
17 seed 0
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
22 ain, kbit, ksrate xin
23
24 kbits = 2^kbit ;bit depth (1 to 16)
25 kfold = (sr/ksrate) ;sample rate
26 kin downsamp ain ;convert to kr
27 kin = (kin+0dbfs) ;add DC to avoid (-)
28 kin = kin*(kbits/(0dbfs*2)) ;scale signal level
29 kin = int(kin) ;quantise
30 aout upsamp kin ;convert to sr
31 aout = aout*(2/kbits)-0dbfs ;rescale and remove DC
32 a0ut fold aout, kfold ;resample
33 xout a0ut
34 endop
35
36
37 instr 1 ;avoid playing this too loud
38
39 kbit = p4
40 ksr = 44100
41 asig diskin "fox.wav", 1
42 aout Decimator asig, kbit, ksr
43 printks "bitrate = %d, ", 3, kbit
44 printks "with samplerate = %d\\n", 3, ksr
45 outs aout*.7, aout*.7
46 endin
47
48
49 instr 2 ;moving randomly between different bit values (1 - 6)
50
51 kbit randomi 1, 6, .5, 1
52 asig diskin "fox.wav", 1, 0, 1 ;loop play
53 aout Decimator asig, kbit, 44100
54 printks "bitrate = %f\n", .3, kbit
55 outs aout*.7, aout*.7
56
57 endin
58
59 </CsInstruments>
60 <CsScore>
61 i 1 0 3 16 ;sounds allright but
62 i 1 + 3 5 ;it's getting worse
63 i 1 + 3 2 ;and worse...
64 i 2 9 22 ;or quality moves randomly
65 e
66 </CsScore>
67 </CsoundSynthesizer>