Created
May 11, 2017 05:31
-
-
Save arion/c3a269c4741dd457d93a448a30fdd486 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <MozziGuts.h> | |
#include <Oscil.h> | |
#include <tables/chum9_int8.h> // recorded audio wavetable | |
#include <tables/cos512_int8.h> // for filter modulation | |
#include <LowPassFilter.h> | |
#include <mozzi_rand.h> // for rand() | |
#include <EventDelay.h> // for scheduling events | |
#define CONTROL_RATE 64 // powers of 2 please | |
const int LDR0_PIN=A0; | |
const int LDR1_PIN=A1; | |
const int LDR2_PIN=A2; | |
const int LDR3_PIN=A8; | |
const int LDR4_PIN=A3; | |
Oscil<CHUM9_NUM_CELLS, AUDIO_RATE> aCrunchySound1(CHUM9_DATA); //audio oscillator | |
Oscil<CHUM9_NUM_CELLS, AUDIO_RATE> aCrunchySound2(CHUM9_DATA); //audio oscillator | |
Oscil<COS512_NUM_CELLS, CONTROL_RATE> kFilterMod1(COS512_DATA); // to modulate filter frequency | |
Oscil<COS512_NUM_CELLS, CONTROL_RATE> kFilterMod2(COS512_DATA); // to modulate filter frequency | |
LowPassFilter lpf1; | |
LowPassFilter lpf2; | |
EventDelay kWhoseTurnDelay; | |
int lastkv = 0; | |
int lastkv1 = 0; | |
int lastkv2 = 0; | |
int lastkv3 = 0; | |
int lastkv4 = 0; | |
int lastfv = 4; | |
int fvdir = 3; | |
unsigned int speed_lfo; | |
const unsigned int MILLIS_PER_SWEEP = 500; | |
void setup(){ | |
startMozzi(CONTROL_RATE); | |
aCrunchySound1.setFreq(2.f); | |
aCrunchySound2.setFreq(1.f); | |
kFilterMod1.setFreq(1.3f); | |
kFilterMod2.setFreq(0.7f); | |
lpf1.setResonance(180); | |
lpf2.setResonance(220); | |
kWhoseTurnDelay.set(MILLIS_PER_SWEEP); | |
kWhoseTurnDelay.start(); | |
Serial.begin(9600); | |
} | |
void updateControl(){ | |
int knob1_value = mozziAnalogRead(LDR0_PIN); | |
knob1_value = map(knob1_value, 0, 800, 0, 255); | |
// map the modulation depth into the filter range, 0-255 to represent 0-8192 Hz | |
if(lastkv1 != knob1_value) { | |
lpf2.setResonance(knob1_value); | |
lastkv1 = knob1_value; | |
} | |
int knob2_value = mozziAnalogRead(LDR1_PIN); | |
knob2_value = map(knob2_value, 0, 800, 0, 255); | |
if(lastkv2 != knob2_value) { | |
lpf1.setResonance(knob2_value); | |
lastkv2 = knob2_value; | |
} | |
int knob3_value = mozziAnalogRead(LDR2_PIN); | |
knob3_value = map(knob3_value, 0, 800, 16.0f, 0.1f); | |
if(lastkv3 != knob3_value) { | |
kFilterMod1.setFreq(knob3_value); | |
lastkv3 = knob3_value; | |
} | |
int knob4_value = mozziAnalogRead(LDR3_PIN); | |
knob4_value = map(knob4_value, 0, 800, 16.0f, 0.1f); | |
if(lastkv4 != knob4_value) { | |
kFilterMod2.setFreq(knob4_value); | |
lastkv4 = knob4_value; | |
} | |
int knob_value = mozziAnalogRead(LDR4_PIN); | |
knob_value = map(knob_value, 250, 1024, 5, 250); | |
//Serial.println(knob_value); | |
// map the modulation depth into the filter range, 0-255 to represent 0-8192 Hz | |
if(lastkv != knob_value) { | |
//aCrunchySound1.setFreq(knob_value); | |
kWhoseTurnDelay.set(knob_value); | |
lastkv = knob_value; | |
} | |
if(kWhoseTurnDelay.ready()){ | |
int freq_value = (byte) lastfv % 18; | |
if(lastfv%18>=15 || lastfv<=0) { | |
fvdir = -fvdir; | |
} | |
lastfv = lastfv + fvdir; | |
kWhoseTurnDelay.start(); | |
aCrunchySound1.setFreq(freq_value); | |
} | |
byte cutoff_freq1 = 100 + kFilterMod1.next()/2; // 100 ± 63 | |
lpf1.setCutoffFreq(cutoff_freq1); | |
// also update lpf2 cutoff | |
byte cutoff_freq2 = 70 + kFilterMod2.next()/4; // 70 ± 31 | |
lpf2.setCutoffFreq(cutoff_freq2); | |
} | |
int updateAudio(){ | |
return (((char)lpf1.next(aCrunchySound1.next()))>>1) + (char)lpf2.next(aCrunchySound2.next()); | |
} | |
void loop(){ | |
audioHook(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment