polyphonic code example

Status
Not open for further replies.

colorado_hick

Well-known member
I am experimenting with multiple notes, here is my code example. I would think that it would play one note, then the other note on top of it, then be silent. But when waveform2 starts waveform1 turns off. Any pointers? Teensy 3.6 board with no audio shield
Code:
#include <Audio.h>
#include <Wire.h>

AudioSynthWaveform       waveform1;
AudioSynthWaveform       waveform2;
AudioMixer4              mixer1;   
AudioOutputAnalogStereo  dacs1;     
AudioConnection          patchCord1(waveform1, 0, mixer1, 0);
AudioConnection          patchCord2(waveform2, 0, mixer1, 0);
AudioConnection          patchCord3(mixer1, 0, dacs1, 0);


void setup() {
  AudioMemory(10);
 waveform1.begin(WAVEFORM_TRIANGLE);
 waveform2.begin(WAVEFORM_TRIANGLE);

}

void loop() {
  waveform2.frequency(200);
  waveform2.amplitude(0.3);
delay(2000);
  waveform1.frequency(440);
  waveform1.amplitude(0.3);
delay(2000);
  waveform1.amplitude(0.0);
  waveform2.amplitude(0.0);
delay(2000);

 
 }
 
Nevermind, i found it. I had to have separate channels as the input to the mixer.

Code:
#include <Audio.h>
#include <Wire.h>

AudioSynthWaveform       waveform1;
AudioSynthWaveform       waveform2;
AudioMixer4              mixer1;   
AudioOutputAnalogStereo  dacs1;     
AudioConnection          patchCord1(waveform1, 0, mixer1, 0);
AudioConnection          patchCord2(waveform2, 0, mixer1, 1);
AudioConnection          patchCord3(mixer1, 0, dacs1, 0);


void setup() {
  AudioMemory(10);
 waveform1.begin(WAVEFORM_TRIANGLE);
 waveform2.begin(WAVEFORM_TRIANGLE);

}

void loop() {
  waveform2.frequency(200);
  waveform2.amplitude(0.3);
delay(2000);
  waveform1.frequency(440);
  waveform1.amplitude(0.3);
delay(2000);
  waveform1.amplitude(0.0);
  waveform2.amplitude(0.0);
delay(2000);

 
 }
 
Status
Not open for further replies.
Back
Top