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

Thread: Vibrato - Using software on a MIDI Note

  1. #1
    Member
    Join Date
    Apr 2020
    Location
    HyŤres, France
    Posts
    25

    Vibrato - Using software on a MIDI Note

    Hi All

    I'm creating a midi project and Id like to add vibrato (modulation) to a note automatically via the code. For various reasons, I don't have the option of using a bite sensor like you would see on an EWI which measures the bite sensor with an analog input and this variation in analog signal is mapped to CC1 Modulation.

    I'm wondering is it possible to add modulation automatically with code without any analog input, or alternatively providing a signal from the DAC or PWM channel and feeding it into an analog channel to simulate modulation?

    I should mention, I am using a Teensy 3.2

    Can the Teensy Audio Library do this?

    all comments are welcome, thanks in advance for any support.

    Ged.

  2. #2
    Senior Member
    Join Date
    Jul 2020
    Posts
    1,778
    Do you mean vibrato (pitch modulation) or tremolo (volume modulation)?
    Yes its easy to generate low frequency modulation signals with the various oscillator (waveform) classes.
    There is the modulated waveform class, AudioSynthWaveformModulated, that you can frequency modulate.
    Amplitude modulation would be done with AudioEffectMultiply

  3. #3
    Member
    Join Date
    Apr 2020
    Location
    HyŤres, France
    Posts
    25
    Hi MarkT

    Its pitch modulation I want to do and I'm wondering if I can add it to a velocity command as well. Could you elaborate a little more on "There is the modulated waveform class, AudioSynthWaveformModulated, that you can frequency modulate.
    Amplitude modulation would be done with AudioEffectMultiply".

    Perhaps you could drop me a code example?

  4. #4
    Senior Member
    Join Date
    Jul 2020
    Posts
    1,778
    There's a whole slew of docs for the audio library, and a video, and it comes with lots of examples.

  5. #5
    Member
    Join Date
    Apr 2020
    Location
    HyŤres, France
    Posts
    25
    The video seems to be about manipulating an mp3 file, but I wont to basically know how I can use the pitch bend midi command with velocity to create vibrato.....

    Maybe you can point me to the documentation please...

  6. #6
    Senior Member
    Join Date
    Jul 2020
    Posts
    1,778
    Not sure its possible to miss the design tool:

    https://www.pjrc.com/teensy/gui/
    click on to each object on the left to see its docs.

  7. #7
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,910
    You can use pitch bend to generate vibrato but you have to generate every pitch bend message yourself.
    This demo code sends a MIDI note on and then generates pitch bend messages based on sine wave for two seconds. Then it resets pitch bend to zero, let's the note play one more second and then turns the note off.
    It sends MIDI messages to both a MIDI device (e.g. keyboard) on Serial1 and also through USB to the PC.
    Code:
    /*
    DEMO by Pete (El_Supremo)
      Play MIDI Note On followed by modulated pitchbend
      messages to cause vibrato.
      To play this through MIDI-OX to the MS GS Wavetable Synth
      on the PC, in MIDI-Ox set
      Options|Midi Devices
        Select Teensy MIDI as the input
        Select MS GS Wavetable Synth as the output
        Click on OK
      In theory, that is all that is needed but if it fails
      try turning on the Keyboard as well:
      Actions
        Turn on Keyboard
    */
    #if !defined(USB_MIDI) && !defined(USB_MIDI_SERIAL)
    #error Must set as Tools|USB Type "MIDI" or "Serial + MIDI"
    #endif
    
    //#define ACTIVE_LED_PIN LED_BUILTIN
    #define ACTIVE_LED_PIN 27
    
    #include <MIDI.h>
    MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
    
    // Toggle the LED whenever Active Sense is received
    uint8_t ledbit = 0;
    void get_active_sense(void)
    {
      ledbit ^= 1;
      digitalWrite(ACTIVE_LED_PIN,ledbit);
    }
    
    void setup()
    {
      Serial.begin(115200);
    
      delay(500);
      Serial.println(__FILE__);
      Serial.println("MIDI Modulation test");
      delay(10);
    
      // LED is toggled when an Active Sense MIDI message is
      // received (from SY77).
      pinMode(ACTIVE_LED_PIN,OUTPUT);
      digitalWrite(ACTIVE_LED_PIN,0);
    
    // Start the serial MIDI interface to the SY77
      MIDI.begin(MIDI_CHANNEL_OMNI);
    
      // The SY77 sends Active Sense. The flashing LED will
      // give a positive indication that the keyboard is on
      // and being seen by the Teensy
      MIDI.setHandleActiveSensing(get_active_sense);
    
      uint8_t note = 60;
      Serial.println("Send Note On");
      MIDI.sendNoteOn(note, 100, 1);
      usbMIDI.sendNoteOn(note, 100, 1);
    
    
      // Send pitch bend messages at the specified sample rate
      // Pitchbend varies from -8192 to +8191
      // Amplitude of the "bend"  +/-amp
      float amp = 3000;
      // phase varies from zero to one and is converted
      // to a fraction of zero to TWO_PI when calling
      // the sin function
      float phase = 0.0;
      // Pitch bend rate
      float freq = 8;
      // sampling frequency 
      float sampling_freq = 50.;
    
      // Play for 2 seconds
      for(int i = 0; i < 2*sampling_freq; i++) {
        int pitch = (int) (amp*sin(phase*TWO_PI));
        MIDI.sendPitchBend(pitch,1);
        usbMIDI.sendPitchBend(pitch,1);
        // Increment the phase
        phase += freq/sampling_freq;
        // If phase is at least 1, reduce it by 1.
        if(phase >= 1) phase -= 1;
        delay(1000./sampling_freq);
      }
      // Turn pitchbend off and play for one more second
      MIDI.sendPitchBend(0x0,1);
      usbMIDI.sendPitchBend(0x0,1);
      delay(1000);
    
      Serial.println("Send Note Off");
      // Turn off the note
      MIDI.sendNoteOff(note, 0, 1);
      usbMIDI.sendNoteOff(note, 0, 1);
    }
    
    void loop()
    {
      MIDI.read();
    }
    Pete

Posting Permissions

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