Skip to content

Commit

Permalink
add filter most basic
Browse files Browse the repository at this point in the history
  • Loading branch information
chee committed Mar 18, 2021
1 parent 55a2b1b commit 259d600
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions bleepbloopmachine/src/main.cc
Expand Up @@ -134,6 +134,7 @@ Point getCoord(int idx) {

class SoundBlock {
public:
enum Filter { low };
int note = 0;
int octave = 3;
bool active = false;
Expand All @@ -143,17 +144,28 @@ class SoundBlock {
float pan = 0.0;
float amp = 1.0;
float sustain = 0.4;
Waveform waveform;
float filterType = Filter::low;
float filterQ = 0.618;
float filterFreq = 8000.0;
int filterStage = 0;
float frequency() { return freq[note][octave]; }
void activate(int n, int o) {
note = n;
octave = o;
active = true;
}
void activate() { active = true; }
void noteUp() {
note = wrapping_add(note, 11);
void filterDown() {
filterFreq = saturating_sub(filterFreq, 10000.0, 100.0, 40.0);
}
void filterUp() {
filterFreq = saturating_add(filterFreq, 10000.0, 100.0, 40.0);
}
void filterQDown() {
filterFreq = saturating_sub(filterFreq, 1.0, 0.0234, 0);
}
void filterQUp() { filterFreq = saturating_add(filterFreq, 1.0, 0.0234, 0); }
void noteUp() { note = wrapping_add(note, 11); }
void noteDown() { note = wrapping_sub(note, 11); }
void octaveUp() { octave = wrapping_add(octave, 8); }
void octaveDown() { octave = wrapping_sub(octave, 8); }
Expand All @@ -179,6 +191,9 @@ class SoundBlock {
s.amp = amp;
s.pan = pan;
s.sustain = sustain;
s.filterFreq = filterFreq;
s.filterQ = filterQ;
s.filterType = filterType;
return s;
}
SoundBlock() {}
Expand Down Expand Up @@ -249,6 +264,10 @@ class Wave {
envR.sustain(sound->sustain);
mixerL.gain(0, sound->amp / 2);
mixerR.gain(0, sound->amp / 2);
if (sound->filterType == SoundBlock::Filter::low) {
filterL.setLowpass(sound->filterStage, sound->filterFreq, sound->filterQ);
filterR.setLowpass(sound->filterStage, sound->filterFreq, sound->filterQ);
}
if (sound->pan < 0) {
mixerL.gain(0, (sound->amp / 2) + (abs(sound->pan) / 2));
mixerR.gain(0, (sound->amp / 2) - (abs(sound->pan) / 2));
Expand Down Expand Up @@ -536,6 +555,21 @@ class BleepBloopMachine {
sound->ampDown();
}
}
} else if (selectedMenu1Control == Menu1Selection::filter) {
if (b_mode) {
if (released & PAD_LEFT) {
sound->filterDown();
}
if (released & PAD_RIGHT) {
sound->filterUp();
}
if (released & PAD_UP) {
sound->filterQUp();
}
if (released & PAD_DOWN) {
sound->filterQDown();
}
}
}
break;
case MenuMode::menu2:
Expand Down

0 comments on commit 259d600

Please sign in to comment.