Using the Audio Shield alongside a Synth chip

I have it!
I was using the wrong I2s object (AudioInputI2S2 instead of AudioInputI2S).
My life is substantially improved!
Thanks for your responses and advice, @JayShoe!

I have not connected the GBUF from the vs1053 to anything on the Audio Shield.
Is there any need to use this GBUF signal in my design?
 
In summary, the VS1053 can be used as a MIDI Synth, via serial MIDI over UART or SPI connection from the Teensy.
Audio from the headphone OUTs of the VS1053 can be hooked to the Line In inputs on the Teensy Audio Adaptor (Rev D2 tested here with a Teensy 4.1)

The updated code at the bottom works and is simplified.
Hookup:
- the Audio Adaptor board is on top of the Teensy 4. in the usual position
- Teensy pin 01 (Tx) to VS1053 Rx
- VS1053 LOUT and ROUT to Audio Adaptor pins LINEINL and LINEINR
- Teensy GPIO 09 connected to VS1053 Reset
- VS1053 GPIO 0 tied LOW & VS1053 GPIO 0 tied HIGH to enable VS1053 "Realtime MIDI"

Code:
#include <SoftwareSerial.h>
// define the pins used
#define VS1053_RX  1 // This is the pin that connects to the RX pin on VS1053
#define VS1053_RESET 9 // This is the pin that connects to the RESET pin on VS1053

// See http://www.vlsi.fi/fileadmin/datasheets/vs1053.pdf Pg 31
#define VS1053_BANK_DEFAULT 0x00
#define VS1053_BANK_DRUMS1 0x78
#define VS1053_BANK_DRUMS2 0x7F
#define VS1053_BANK_MELODY 0x79

// See http://www.vlsi.fi/fileadmin/datasheets/vs1053.pdf Pg 32 for more!
#define VS1053_GM1_OCARINA 80

#define MIDI_NOTE_ON  0x90
#define MIDI_NOTE_OFF 0x80
#define MIDI_CHAN_MSG 0xB0
#define MIDI_CHAN_BANK 0x00
#define MIDI_CHAN_VOLUME 0x07
#define MIDI_CHAN_PROGRAM 0xC0

#include <Audio.h>
#include <Wire.h>
#include <SD.h>
#include <SPI.h>
#include <SerialFlash.h>
#include <Bounce.h>

// Audio Library "wiring"
AudioInputI2S            i2sInput;       //xy=55,248.99999237060547
AudioOutputI2S           i2sOutput;      //xy=499,173.99999237060547
AudioConnection          patchCord1(i2sInput, 0, i2sOutput, 0);
AudioConnection          patchCord2(i2sInput, 1, i2sOutput, 1);
AudioControlSGTL5000     sgtl5000_1;     //xy=138,346.99999237060547

SoftwareSerial VS1053_MIDI(0, VS1053_RX); // TX only, do not use the 'rx' side

void setup() {
  Serial.begin(9600);
  Serial.println("VS1053 MIDI test with Teensy Audio Board");
  
  // Audio Board Setup
  AudioMemory(10);
  sgtl5000_1.inputSelect(AUDIO_INPUT_LINEIN);
  sgtl5000_1.enable();
  sgtl5000_1.volume(0.2);

  // VS1053 setup
  VS1053_MIDI.begin(31250); // MIDI uses a 'strange baud rate'
  pinMode(VS1053_RESET, OUTPUT);
  digitalWrite(VS1053_RESET, LOW);
  delay(10);
  digitalWrite(VS1053_RESET, HIGH);
  delay(10);
  
  // MIDI setup
  midiSetChannelBank(0, VS1053_BANK_MELODY);
  midiSetInstrument(0, VS1053_GM1_OCARINA);
  midiSetChannelVolume(0, 127);
}

unsigned long swapTime = 0;
void loop() {  
  for (uint8_t i=60; i<69; i++) {
    midiNoteOn(0, i, 127);
    delay(100);
    midiNoteOff(0, i, 127);
  }

  delay(1000);
}

void midiSetInstrument(uint8_t chan, uint8_t inst) {
  if (chan > 15) return;
  inst --; // page 32 has instruments starting with 1 not 0 :(
  if (inst > 127) return;
  
  VS1053_MIDI.write(MIDI_CHAN_PROGRAM | chan);  
  VS1053_MIDI.write(inst);
}

void midiSetChannelVolume(uint8_t chan, uint8_t vol) {
  if (chan > 15) return;
  if (vol > 127) return;
  
  VS1053_MIDI.write(MIDI_CHAN_MSG | chan);
  VS1053_MIDI.write(MIDI_CHAN_VOLUME);
  VS1053_MIDI.write(vol);
}

void midiSetChannelBank(uint8_t chan, uint8_t bank) {
  if (chan > 15) return;
  if (bank > 127) return;
  
  VS1053_MIDI.write(MIDI_CHAN_MSG | chan);
  VS1053_MIDI.write((uint8_t)MIDI_CHAN_BANK);
  VS1053_MIDI.write(bank);
}

void midiNoteOn(uint8_t chan, uint8_t n, uint8_t vel) {
  if (chan > 15) return;
  if (n > 127) return;
  if (vel > 127) return;
  
  VS1053_MIDI.write(MIDI_NOTE_ON | chan);
  VS1053_MIDI.write(n);
  VS1053_MIDI.write(vel);
}

void midiNoteOff(uint8_t chan, uint8_t n, uint8_t vel) {
  if (chan > 15) return;
  if (n > 127) return;
  if (vel > 127) return;
  
  VS1053_MIDI.write(MIDI_NOTE_OFF | chan);
  VS1053_MIDI.write(n);
  VS1053_MIDI.write(vel);
}
 
I have other questions about signal quality, though I'll start another thread. Thanks all for helping me get this to work!
 
Back
Top