Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 2 of 2

Thread: polyphonic code example

  1. #1

    polyphonic code example

    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);
    
     
     }

  2. #2
    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);
    
     
     }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •