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