// this KickInstrument will make a sound that is like an analog kick drum class KickInstrument implements Instrument { // our kick sound is just an sine wave Oscil sineOsc; // which we will quickly sweep the frequency of using this line Line freqLine; Damp release; UGen out; KickInstrument( UGen iOut ) { sineOsc = new Oscil(100.f, 0.4f, Waves.SINE); freqLine = new Line( 0.08f, 200.f, 50.f ); release = new Damp(0, 0.3, 1, 1, 0); // patch the line to the frequency of the osc freqLine.patch( sineOsc.frequency ); out = iOut; } // every instrument must have a noteOn( float ) method void noteOn(float dur) { // patch our oscil to the summer we were given and start the line freqLine.activate(); sineOsc.patch(release).patch(out); } // every instrument must have a noteOff() method void noteOff() { release.activate(); release.unpatchAfterDamp(out); } } // this SnareInstrument will make an analog snare kind of sound class SnareInstrument implements Instrument { // to make a snare sound we'll just filter some noise Noise noize; BandPass bpFilt; SnareInstrument() { this( 600.f, 0.f ); } SnareInstrument( float cutoff, float p ) { // amplitude and noise tint noize = new Noise( 2.f, Noise.Tint.WHITE); // make a bandpass with center frequency of 400Hz, bandwidth of 20Hz and sample rate of 44100. bpFilt = new BandPass( cutoff, 200.f, 44100.f ); Pan pan = new Pan(p); // patch the noise through the filter noize.patch( pan ).patch( bpFilt ); } // called by the note manager when this instrument should play void noteOn(float dur) { bpFilt.patch(mainOut); } // called by the note manager when this instrument should stop playing void noteOff() { bpFilt.unpatch(mainOut); } } class BlipInstrument implements Instrument { Oscil osc; Damp release; Pan pan; BlipInstrument( float freq, float p ) { osc = new Oscil( freq, 0.2f, Waves.SQUARE ); release = new Damp( 0.001f, 0.05f, 1.f, 1.f, 0.f ); pan = new Pan(p); osc.patch(pan).patch(release); } void noteOn( float dur ) { release.activate(); release.patch( mainOut ); } void noteOff() { release.unpatchAfterDamp( mainOut ); } } class BassInstrument implements Instrument { Oscil osc; LowPassFS filt; Line cutLine; BassInstrument( float freq ) { osc = new Oscil( freq, 0.2f, Waves.SAW ); filt = new LowPassFS( 1000.f, mainOut.sampleRate() ); cutLine = new Line( 0.1f, 10000.f, 100.f ); cutLine.patch( filt.cutoff ); osc.patch(filt); } void noteOn( float dur ) { cutLine.activate(); filt.patch(mainOut); } void noteOff() { filt.unpatch(mainOut); } } class WhineInstrument implements Instrument { Oscil osc; BandPass filt; ADSR env; Line cutLine; Summer freqLFO; Multiplier envScale; WhineInstrument( float freq ) { osc = new Oscil( freq, 0.8f, Waves.SAW ); filt = new BandPass(2000.f, 50.f, mainOut.sampleRate()); env = new ADSR( 1.f, 0.1, 0.f, 1.f, 0.1, 0.f, 0.f ); cutLine = new Line(5.f, 1000.f, 60.f); cutLine.patch( filt.cutoff ); osc.patch(filt).patch(env); Oscil lfo = new Oscil( 6f, 4.f, Waves.SINE ); Constant centerFreq = new Constant( freq ); freqLFO = new Summer(); lfo.patch(freqLFO); centerFreq.patch(freqLFO); envScale = new Multiplier( freq * 0.3f ); envScale.patch( freqLFO ); freqLFO.patch( osc.frequency ); } void noteOn( float dur ) { // detune the whine instrument using the envelope from the kicks envFollow.patch( envScale ); cutLine.activate(); env.noteOn(); env.patch( mainOut ); } void noteOff() { env.noteOff(); env.unpatchAfterRelease( mainOut ); envFollow.unpatch( envScale ); } }