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

Thread: How does AudioSynthWaveformDc work?

  1. #1

    How does AudioSynthWaveformDc work?

    Hi, since there is no envelope to control waveform frequency modulation or filter frequency modulation I tried to use the "DC" output.

    When I press the MIDI keys I want the Serial monitor to show values going up to 1.0 and when I release the keys to show values going down to -1.
    This code, however, does nothing to the values on the Serial monitor when I press and release keys on my MIDI keyboard:

    Code:
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    
    AudioSynthWaveformDc     pitchEnvelope;
    AudioOutputI2S           i2s1;
    
    void setup() {
      usbMIDI.setHandleNoteOn(OnNoteOn);
      usbMIDI.setHandleNoteOff(OnNoteOff);
    }
    
    int attackTime=1000;
    int releaseTime=1000;
    
    void loop(){ 
      usbMIDI.read(); 
      Serial.println(pitchEnvelope.read());
    } 
      
    void OnNoteOn(byte channel, byte note, byte velocity){
      pitchEnvelope.amplitude(1,attackTime);
    } 
      
    void OnNoteOff(byte channel, byte note, byte velocity){
      pitchEnvelope.amplitude(-1,releaseTime); 
    }

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,951
    You need AudioMemory() in setup(). See any of the examples in File > Examples > Audio.

    To get a ADSR or AD style control signal, you would feed the DC output through an envelope effect. For only attack-decay triggered by a single event, set the sustain level to zero.

Posting Permissions

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