| 1 |
// "Greyhole" demo with decimation/down/upsampling |
| 2 |
// By Perry R. Cook, October 2012 |
| 3 |
// This demonstrates a couple of things |
| 4 |
// 1) using FIR Sinc filters for bandlimiting and reconstruction |
| 5 |
// 2) decimation, for doing signal processing at lower rates |
| 6 |
// or just for fun |
| 7 |
|
| 8 |
int decFactor; // can specify like: chuck TestDownUpSample.ck:8 |
| 9 |
if (me.args() > 0) Std.atoi(me.arg(0)) => decFactor; |
| 10 |
else 16 => decFactor; // or it will default to what is here |
| 11 |
|
| 12 |
Gain decimate; // anything chucked to here will run at lower rate |
| 13 |
adc => FIR lowpass => blackhole; // initial band limiting if needed |
| 14 |
Step holdout => FIR lp2 => WvOut w => dac; // hold and reconstruct |
| 15 |
"test.wav" => w.wavFilename; |
| 16 |
0.1 => w.fileGain; |
| 17 |
|
| 18 |
// lowpass is here to bandlimit before downsampling |
| 19 |
1.0 => lowpass.gain; 128 => lowpass.order; decFactor => lowpass.sinc; |
| 20 |
// lp2 is here to get rid of decimation critters after upsampling |
| 21 |
// but doesn't have to be as high order (driven by a step) |
| 22 |
1.0 => lp2.gain; 64 => lp2.order; decFactor => lp2.sinc; |
| 23 |
|
| 24 |
spork ~ decimateBy(decFactor); |
| 25 |
|
| 26 |
1 => int notDone; |
| 27 |
|
| 28 |
SinOsc s => decimate; // test to prove decimation works |
| 29 |
10000.0 => s.freq; // sine freq won't be this, it will |
| 30 |
0.1 => s.gain; // be thisFreq / decFactor because it |
| 31 |
// only runs at the lower rate!! |
| 32 |
|
| 33 |
1.0 => lowpass.gain; // this sets/mutes the microphone input |
| 34 |
|
| 35 |
while(notDone) |
| 36 |
{ |
| 37 |
0.05 :: second => now; // hang out here and do nothing |
| 38 |
} |
| 39 |
|
| 40 |
fun void decimateBy(int factor) { |
| 41 |
while (notDone) { // only take every factor-th |
| 42 |
lowpass => decimate; // sample from our input(s) |
| 43 |
decimate => blackhole; // hook things up and let |
| 44 |
1 :: samp => now; // one sample through |
| 45 |
decimate.last()=> holdout.next; // sample to output |
| 46 |
lowpass =< decimate; // now disconnect everybody |
| 47 |
decimate =< blackhole; // (probably too enthusiastically) |
| 48 |
(factor - 1) :: samp => now; // and hang around between |
| 49 |
} |
| 50 |
} |