.module FILTER; {----------------------------------------------------------------------- FILTER v0.2 http://www.urbanjazznaturals.com/xjn http://www.booyaka.com/~oncken http://www.mp3.com/xjn Shifty's SVF code modified with the following features: 1. controllable resonance. 2. selectable output band. cc1: frequency. cc2: resonance. (low values, high resonance) cc3: output band. (highpass, lowpass, bandpass, notch) Much respect to Shifty for the template and the original SVF code. It sounds very nice... its a 'singer', not a 'screamer' or a 'skreecher' like some analogs. You can definately tell its digital... at least its not a 'moaner' :) Very efficient code AFAICT. Somebody should add some level detection code and some attack/decay amount code to turn it into an autowah... or add an ADSR and key scaling params and trigger it with midi notes. You could put the kit after your favorite digital synth and use it as a nice little midi note controlled ADSR filter that follows your playing... All the usual GCC stuff applies to this, as it was developed from Shifty's code. ------------------------------------------------------------------------} .include <../template/system.k>; .include <../template/midi.k>; .include <../template/setup.dsp>; .global handle_MIDI_controller; .global newsound; .global killsound; .external process_midi; { signal processing variables here } .var K2,K3,K4; .init K2:0x3fff; .init K3:0x1000; .init K4:0x1000; .var low,band,high,notch; .init low:0; .init band:0; .init high:0; .init notch:0; .var input; .var outputs[4]; .var outband; .init outband: 1; { internal variables } .var last_input; .var last_output; .init last_output:0; { parameters here } { do any dynamic memory/variable initializing you need to here } init_params: nop; nop; nop; rts; { command loop - check for incoming data on serial port } main_loop: ar = dm (CHAR_WAITING_FLAG); { check serial port for MIDI data } none = pass ar; if ne jump main_loop; call process_midi; { if MIDI byte received } jump main_loop; { SPORT0 interrupt handler -- this is called at 44.1KHz } input_samples: ena sec_reg; { use shadow register bank } my0 = dm(rx_buf +1); { read a/d converters } my1 = dm(rx_buf +2); { leave left/right values in my0,my1 } { insert your DSP code here } {-----------------------------------------------------------------------} dm(input)=my0; call filter; i1 = ^outputs; m1 = dm(outband); mx0 = dm(i1, m1); mx0 = dm(i1, m1); my0 = mx0; my1 = mx0; {-----------------------------------------------------------------------} dm(tx_buf+ 1)=my0; { write d/a converters } dm(tx_buf+ 2)=my1; { write left/right values from my0, my1 } { save output value (for possible feedback) } dm(last_output)=mr1; thatwasfun: rti; filter: { $H=$input - $K2*$B + $L; } { dm(high)=dm(input) - dm(K2) * dm(band) + dm(low); } mr = 0; mr1 = dm(input); { input } mx0 = dm(K2); my0 = dm(band); mr = mr - mx0*my0(ss); { + K2 * band } if mv sat mr; mx0 = 0x7fff; my0 = dm(low); mr = mr + mx0*my0(ss); { + low } if mv sat mr; dm(high) = mr1; dm(outputs) = mr1; { $B= $B + $K3*$H; } { dm(band)= dm(band) + dm(K3*dm(high); } mr = 0; mr1 = dm(band); { band } mx0 = dm(K3); my0 = dm(high); mr = mr + mx0*my0(ss); { + K3 * high } if mv sat mr; dm(band) = mr1; dm(outputs +2) = mr1; { $L= $L - $K4*$B; } { dm(low)= dm(low) - dm(K4)*dm(band); } mr = 0; mx0 = dm(K4); mr1 = dm(low); { low } my0 = dm(band); mr = mr - mx0*my0(ss); if mv sat mr; dm(low) = mr1; dm(outputs +1) = mr1; { $N=($H+$L)/2; } { dm(notch)=(dm(high)+dm(low))/2; } my0 = dm(high); my1 = dm(low); mx0 = 0x3fff; mr = mx0*my0(ss); mr = mr + mx0*my1(ss); dm(notch) = mr1; dm(outputs +3) = mr1; rts; { Here is where MIDI messages are used to set variables in your Effect! } { remove a sound from the sound queue ---------------------------------- } killsound: rts; { Use MIDI note number....euh ---------------------------- } newsound: ax1 = dm(midi_ch); rts; {do CC stuff-----------------------------------} handle_MIDI_controller: ax1 = dm(midi_cont); ar = dm(midi_val); ay1 = 1;none = ax1-ay1;if eq jump set_freq; ay1 = 2;none = ax1-ay1;if eq jump set_res; ay1 = 3;none = ax1-ay1;if eq jump set_band; rts; set_freq: ar = dm(midi_val); sr = lshift ar by 8(lo); ar = sr0 or ay1; dm(K3) = ar; dm(K4) = ar; rts; set_res: ar = dm(midi_val); sr = lshift ar by 7(lo); ar = sr0 or ay1; dm(K2) = ar; rts; set_band: ar = dm(midi_val); sr = lshift ar by -5(lo); dm(outband) = sr0; rts; .endmod;