aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuillaume Riou <guiloua2@hotmail.com>2014-05-13 14:35:01 -0400
committerGuillaume Riou <guiloua2@hotmail.com>2014-05-13 14:35:01 -0400
commit768b41fb5433e556239e92eb0237a1c9720b7cde (patch)
treeb3ebdf2146792387956b484fb08a1025c30fb551
parent301ec25ed8dc6b627930a3842c4e94c4788b0dda (diff)
...
-rw-r--r--squelette_synth_midi.ino103
1 files changed, 73 insertions, 30 deletions
diff --git a/squelette_synth_midi.ino b/squelette_synth_midi.ino
index ea272d4..20374db 100644
--- a/squelette_synth_midi.ino
+++ b/squelette_synth_midi.ino
@@ -16,8 +16,8 @@
int tableChange = 0;
-Oscil <SAW256_NUM_CELLS, AUDIO_RATE> ncoOne(SAW256_DATA),
-ncoTwo(SAW256_DATA), ncoThree(SAW256_DATA);
+Oscil <SAW256_NUM_CELLS, AUDIO_RATE> nco[] =
+{(SAW256_DATA), (SAW256_DATA), (SAW256_DATA)};
Oscil <SIN256_NUM_CELLS, CONTROL_RATE> lfoOne(SIN256_DATA),
lfoTwo(SIN256_DATA);
@@ -26,15 +26,17 @@ ADSR <CONTROL_RATE> adsr_envelope;
ADSR <CONTROL_RATE> adsr_filter;
-float lastFreq = 0;
+
int noteBuffer[4];
int bufferIndex = 0;
float pbAmount = 0.0;
float lastMidiNote = 0.0;
+float oscDet[2];
LowPassFilter lpf;
int lastLfoValues[2];
Multifilter mf(0);
-bool lfoEffect[2][5]; //0:oscil1, 1:oscil2, 2:oscil3, 3:envelope, 4:detune
+bool lfoEffect[2][7]; //0:oscil1, 1:oscil2, 2:oscil3, 3:envelope, 4:cutoff, 5: det osc2, 6: det osc3
+int lastFilter = 0;
void handlePitchBend(byte channel, byte lsb, byte msb) {
@@ -56,15 +58,25 @@ void handleNoteOn(byte channel, byte note, byte velocity) {
noteBuffer[0] = note;
jouerNote((float)note);
+ adsr_filter.noteOn();
+ adsr_envelope.noteOn();
}
void jouerNote(float note) {
+ // Note joué sur le clavier additionnée du pitch bend.
float totalNote = note + pbAmount;
- lastFreq = Q16n16_to_float(Q16n16_mtof(float_to_Q16n16(totalNote)));
- ncoOne.setFreq(lastFreq);
+ nco[0].setFreq(Q16n16_to_float(Q16n16_mtof(float_to_Q16n16(totalNote))));
+ for(int i = 0; i < 2; i++) {
+ // Note globale plus le désacordage de l'oscillateur.
+ float noteOscil = oscDet[i] + totalNote;
+ nco[i+1].setFreq(Q16n16_to_float(Q16n16_mtof(float_to_Q16n16(noteOscil))));
+ }
+ //lastFreq = Q16n16_to_float(Q16n16_mtof(float_to_Q16n16(totalNote)));
+ //nco[0].setFreq(lastFreq);
+ // nco[1].setFreq(Q16n16_to_float(Q16n16_mtof(float_to_Q16n16(totalNote+12))));
+ // nco[2].setFreq(lastFreq);
lastMidiNote = note;
- adsr_filter.noteOn();
- adsr_envelope.noteOn();
+
}
void handleNoteOff(byte channel, byte note, byte velocity) {
@@ -93,10 +105,13 @@ void setup() {
MIDI.setHandleNoteOn(handleNoteOn);
MIDI.setHandleNoteOff(handleNoteOff);
MIDI.setHandlePitchBend(handlePitchBend);
- ncoOne.setFreq(400);
+ nco[0].setFreq(400);
+ nco[1].setFreq(333);
+ //nco[2].setFreq(300);
startMozzi(CONTROL_RATE);
MIDI.begin();
- lfoOne.setFreq(1);
+ lfoOne.setFreq((float)0.3);
+ lfoTwo.setFreq(5);
for(int i = 0; i < 3; i++) {
noteBuffer[i] = -1;
}
@@ -108,7 +123,7 @@ void setup() {
lastLfoValues[1] = 0;
}
-int lastFilter = 0;
+
void updateControl() {
lastLfoValues[0] = lfoOne.next();
lastLfoValues[1] = lfoTwo.next();
@@ -120,39 +135,67 @@ void updateControl() {
lastFilter = filterReading;
}
+ for (int i = 0; i < 2; i ++){
+ if(lfoEffect[i][5] || true){
+ oscDet[0] = pgm_read_float_near(PB_ARRAY+((lastLfoValues[i]+127)>>1));
+ }
+ if(lfoEffect[i][6]){
+ oscDet[1] = pgm_read_float_near(PB_ARRAY+((lastLfoValues[i]+127)>>1));
+ }
+ }
+
+ // TODO : Lire la valeur sur des knobs.
+ int cutoff = 255;
+ for (int i = 0 ; i <2 ; i++){
+ if(lfoEffect[i][4]){
+ //cutoff = (cutoff * (lastLfoValues[i]+127)) >>7;
+ }
+ }
+
+ mf.setCutoffFreq(cutoff * adsr_envelope.next() >> 8);
+ // Lis et traite les valeurs midi.
MIDI.read();
+ jouerNote(lastMidiNote);
+ // Update l'adsr.
adsr_envelope.update();
- mf.setCutoffFreq(255 * adsr_envelope.next() >> 8);
+
}
int updateAudio() {
//adsr.next();
- /**
- int osc1 = ncoOne.next();
- int osc2 = ncoTwo.next();
- int osc3 = ncoThree.next();
- */
- /** for(int i=0;i<2;i++) {
- if(lfoEffect[i][0] {
- osc1 = osc1*lastLfoValues[i];
+
+ int osc1 = nco[0].next();
+ int osc2 = nco[1].next();
+ int osc3 = /*nco[2].next()*/0;
+
+ for(int i=0;i<2;i++) {
+ if(lfoEffect[i][0] || true) {
+ //osc1 = (osc1*lastLfoValues[i])>>7;
}
- if(lfoEffect[i][1] {
- osc2 = osc2*lastLfoValues[i];
+ if(lfoEffect[i][1] || true) {
+ //osc2 = (osc2*lastLfoValues[i])>>7;
}
- if(lfoEffect[i][2] {
- osc3 = osc3*lastLfoValues[i];
+ if(lfoEffect[i][2] || true) {
+ //osc3 = (osc3*lastLfoValues[i])>>7;
}
- if(lfoEffect[i][3] {
- //envelope
+ /**if(lfoEffect[i][4]) {
+ total = ((osc1+osc2+osc3)*lastLfoValues[i])>>9;
}
- if(lfoEffect[i][4] {
- //detune
+ else {
+ total = (osc1+osc2+osc3)>>2;
+ }*/
+ }
+ int total = (osc1+osc2+osc3)>>2;
+
+ for(int i=0; i<2; i++){
+ if(lfoEffect[i][3] || true) {
+ //total = (total*lastLfoValues[i])>>7;
}
- } */
+ }
- return (int) (adsr_envelope.next()*(mf.next((ncoOne.next() + ncoTwo.next() + ncoThree.next()) >> 2))) >> 2;
+ return (int) (adsr_envelope.next()*(mf.next(total)))>>2;
}
void loop() {