// adc-to-dac conversion using a spectral filter to obtain a brick // wall low pass filter. Still, getting some artifacts (grainy sound) though... <<<"usage:", "spec_filter_class.ck adc-to-dac2.ck:output_gain:sr:bits" >>>; Step pulse =>blackhole; //WvOut file => dac; //"adc.wav" => file.wavFilename; second/samp => float chuck_sr => float new_sr; //setting up sample rate: if( me.args() ) Std.atof( me.arg(0) ) => new_sr; chuck_sr/new_sr => float next_samp; OnePole lpf => dac; 1. - new_sr/chuck_sr => lpf.pole; // spectral low pass filters(brickwall filter) // input filter: spec_filter spec_filt; spec_filt.connect( adc, blackhole); spec_filt.freq( new_sr/2. ); spork~ spec_filt.run(); // output filter: spec_filter spec_filt2; spec_filt2.connect( pulse, dac ); spec_filt2.freq( new_sr/2. ); spork~ spec_filt2.run(); //setting up quantisation bits 16 => int nbits; if( me.args() > 2 ) Std.atoi( me.arg(2) ) => nbits; while(true) { now => time T; next_samp::samp +=> T; // quantisation: quantise( spec_filt.last(), nbits ) => pulse.next; // advance time: while( now < T ) { 1::samp => now; } } fun float quantise( float sample, int bits ) { // taken from Ghe's dither.ck if( bits <= 0 || bits > 24 ) { <<< "quantisation bits out of range:", "[1-24]">>>; return 0.; } (1<<24) => int max; (sample*max) $ int => int quantised; // quantised to 24bits // throw away extra resolution: quantised >> (24-bits) << (24-bits) => quantised; quantised $ float / max => sample; return sample; }