| 1 |
<CsoundSynthesizer> |
| 2 |
<CsOptions> |
| 3 |
; Select audio/midi flags here according to platform |
| 4 |
; Audio out Audio in No messages |
| 5 |
-odac -iadc -d ;;;RT audio I/O |
| 6 |
; For Non-realtime ouput leave only the line below: |
| 7 |
; -o hilbert_barberpole.wav -W ;;; for file output any platform |
| 8 |
</CsOptions> |
| 9 |
<CsInstruments> |
| 10 |
|
| 11 |
; Initialize the global variables. |
| 12 |
sr = 44100 |
| 13 |
; kr must equal sr for the barberpole effect to work. |
| 14 |
kr = 44100 |
| 15 |
ksmps = 1 |
| 16 |
nchnls = 2 |
| 17 |
|
| 18 |
; Instrument #1 |
| 19 |
instr 1 |
| 20 |
idur = p3 |
| 21 |
ibegshift = p4 |
| 22 |
iendshift = p5 |
| 23 |
|
| 24 |
; sawtooth wave, not bandlimited |
| 25 |
asaw phasor 100 |
| 26 |
; add offset to center phasor amplitude between -.5 and .5 |
| 27 |
asaw = asaw - .5 |
| 28 |
; sawtooth wave, with amplitude of 10000 |
| 29 |
ain = asaw * 20000 |
| 30 |
|
| 31 |
; The envelope of the frequency shift. |
| 32 |
kfreq linseg ibegshift, idur, iendshift |
| 33 |
|
| 34 |
; Phase quadrature output derived from input signal. |
| 35 |
areal, aimag hilbert ain |
| 36 |
|
| 37 |
; The quadrature oscillator. |
| 38 |
asin oscili 1, kfreq, 1 |
| 39 |
acos oscili 1, kfreq, 1, .25 |
| 40 |
|
| 41 |
; Based on trignometric identities. |
| 42 |
amod1 = areal * acos |
| 43 |
amod2 = aimag * asin |
| 44 |
|
| 45 |
; Calculate the up-shift and down-shift. |
| 46 |
aupshift = (amod1 + amod2) * 0.7 |
| 47 |
adownshift = (amod1 - amod2) * 0.7 |
| 48 |
|
| 49 |
; Mix in the original signal to achieve the barberpole effect. |
| 50 |
amix1 = aupshift + ain |
| 51 |
amix2 = aupshift + ain |
| 52 |
|
| 53 |
; Make sure the output doesn't get louder than the original signal. |
| 54 |
aout1 balance amix1, ain |
| 55 |
aout2 balance amix2, ain |
| 56 |
|
| 57 |
outs aout1, aout2 |
| 58 |
endin |
| 59 |
|
| 60 |
|
| 61 |
</CsInstruments> |
| 62 |
<CsScore> |
| 63 |
|
| 64 |
; Table 1: A sine wave for the quadrature oscillator. |
| 65 |
f 1 0 16384 10 1 |
| 66 |
|
| 67 |
; The score. |
| 68 |
; p4 = frequency shifter, starting frequency. |
| 69 |
; p5 = frequency shifter, ending frequency. |
| 70 |
i 1 0 6 -10 10 |
| 71 |
e |
| 72 |
|
| 73 |
|
| 74 |
</CsScore> |
| 75 |
</CsoundSynthesizer> |