| 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 0dbfs.wav -W ;;; for file output any platform |
| 8 |
</CsOptions> |
| 9 |
<CsInstruments> |
| 10 |
|
| 11 |
sr = 44100 |
| 12 |
kr = 4410 |
| 13 |
nchnls = 1 |
| 14 |
0dbfs = 1 |
| 15 |
|
| 16 |
zakinit 3,1 |
| 17 |
|
| 18 |
instr 1 ; wavelet synth instrument |
| 19 |
iamp = p4; scaling factor of wavelets |
| 20 |
ifreq = p5; frequency of wavelets |
| 21 |
itab = p6; selected wavelet function |
| 22 |
inum = p7; number of wavelets to be created |
| 23 |
a1 osciln p4, p5, p6, p7 |
| 24 |
out a1 |
| 25 |
endin |
| 26 |
|
| 27 |
instr 2 ; wavelet analysis intrument |
| 28 |
a1 soundin "fox.wav" |
| 29 |
; Decomposition Structure: |
| 30 |
; 1 LEVEL 2 LEVEL |
| 31 |
; HP->ah1 |
| 32 |
; a1->| HP(up2)->ah2 |
| 33 |
; LP->al1->| |
| 34 |
; LP(up2)->al2 |
| 35 |
; |
| 36 |
ain = a1*.5; attenuate input signal |
| 37 |
; since wavelet coefficients |
| 38 |
; could reach big values |
| 39 |
ah1 dconv ain,ftlen(8),8 |
| 40 |
al1 dconv ain,ftlen(7),7 |
| 41 |
ah2 dconv al1,ftlen(10),10 |
| 42 |
al2 dconv al1,ftlen(9),9 |
| 43 |
|
| 44 |
zaw ah1,0 |
| 45 |
zaw al1,1 |
| 46 |
zaw ah2,2 |
| 47 |
zaw al2,3 |
| 48 |
|
| 49 |
aout zar p4 |
| 50 |
out aout |
| 51 |
zacl 0,3 |
| 52 |
endin |
| 53 |
|
| 54 |
</CsInstruments> |
| 55 |
<CsScore> |
| 56 |
|
| 57 |
; First of all, we need several FIR filters which are capable |
| 58 |
; to produce wavelet families. |
| 59 |
; One can input filter coefficients manualy using GEN02 |
| 60 |
; or read them from text file. |
| 61 |
; Most of compact-supported wavelet coefficients can be obtained from |
| 62 |
; Wavelet Browser by PyWavelets wavelets.pybytes.com |
| 63 |
; You can select family and order of filter |
| 64 |
; then copy desired coefficients into txt file. |
| 65 |
; Notice that for correct interpretation of results you should use |
| 66 |
; coeffs of Decomposition low-pass filter. |
| 67 |
|
| 68 |
; Daubechies 2 |
| 69 |
f 1 0 4 -2 -0.1294095226 0.2241438680 0.8365163037 0.4829629131 |
| 70 |
; Symlet 10 |
| 71 |
f 2 0 0 -23 "sym10.txt" |
| 72 |
|
| 73 |
; Now we want to produce some wavelet granules. |
| 74 |
; They can be used in wavelet synthesis etc. |
| 75 |
; Tables of large sizes should produce smoother wavelets. |
| 76 |
; We take array of filter coefficients from ftable 1 |
| 77 |
; and deconvolve it until output length of 16384. |
| 78 |
; The order of filters through the deconvolution process |
| 79 |
; is given by 14 which is 1110 in binary. |
| 80 |
; So the first filter is LP ('0') and others are HP ('1'). |
| 81 |
f 3 0 16384 "wave" 1 14 0 |
| 82 |
f 4 0 16384 "wave" 2 1 0 |
| 83 |
f 5 0 16384 "wave" 2 7 0 |
| 84 |
f 6 0 16384 "wave" 2 6 0 |
| 85 |
; The main purpose of using wavelets is wavelet transform. |
| 86 |
; It is not that easy to perform a classic DWT in Csound since downsampling |
| 87 |
; of audio signal is needed at each step of wavelet decomposition. |
| 88 |
; Anyway, using GENwave it is possible to create a number of upsampled |
| 89 |
; wavelets and perform a so-called undecimated wavelet transform |
| 90 |
; aka stationary wavelet transform (and it is even better). |
| 91 |
; So we need some upsampled childs of mother wavelet. |
| 92 |
f 7 0 16 "wave" 1 0 -1 ;db2 scaling function for 1st iteration |
| 93 |
f 8 0 16 "wave" 1 1 -1 ;db2 wavelet function for 1st iteration |
| 94 |
f 9 0 32 "wave" 1 0 -1 ;db2 scaling function for 2nd iteration |
| 95 |
f 10 0 32 "wave" 1 1 -1 ;db2 wavelet function for 2nd iteration |
| 96 |
|
| 97 |
; Let's hear how some wavelets could sound.. |
| 98 |
; amp frq wave times |
| 99 |
i 1 0 1 0.6 15 3 8 |
| 100 |
i 1 0.5 . 0.9 20 4 5 |
| 101 |
i 1 0.9 . 0.7 8 5 . |
| 102 |
i 1 1.1 . 0.4 30 6 9 |
| 103 |
|
| 104 |
; Now try to decompose input file using wavelets |
| 105 |
i 2 2 4 1; approximation 1st level |
| 106 |
i 2 5 . 2; details 2nd level |
| 107 |
</CsScore> |
| 108 |
</CsoundSynthesizer> |