playing a wav file only results in a click (Teensy 4.1, PT8211)

Status
Not open for further replies.

sleepyams

New member
Hello, I'm using the Teensy 4.1 with the PT8211 audio kit. I'm trying to figure out what I'm doing wrong here: I'm trying to make a simple program where when I press a key on my midi keyboard the teensy will play a pre-defined sample, however when I do this I can only hear a very faint click in my headphones. From the serial output it is clear that the MIDI is working fine but something is happening when the wav file is playing. Here is my code:

Code:
#include <USBHost_t36.h>

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

// GUItool: begin automatically generated code
AudioPlaySdWav           playSdWav1;     //xy=272,942
AudioOutputPT8211_2      pt8211_2_1;     //xy=557,951
AudioConnection          patchCord1(playSdWav1, 0, pt8211_2_1, 0);
AudioConnection          patchCord2(playSdWav1, 1, pt8211_2_1, 1);
// GUItool: end automatically generated code

// USB
USBHost myusb;
USBHub hub1(myusb);
USBHub hub2(myusb);
MIDIDevice midi1(myusb);

const char* wavFile = "1B.WAV";


void play() {
  if (!playSdWav1.isPlaying()) {
    Serial.println("Playing from SD card...");
    if (!playSdWav1.play(wavFile)) {
      Serial.println("Could not play from SD card!");
      return;
    }
    delay(5);
    while (playSdWav1.isPlaying()) {
      Serial.println("Playing...");
      delay(100);
    }
    Serial.println("Done playing.");
  }
}

void myNoteOn(byte channel, byte note, byte velocity) {
  Serial.print("Note On, ch=");
  Serial.print(channel, DEC);
  Serial.print(", note=");
  Serial.print(note, DEC);
  Serial.print(", velocity=");
  Serial.println(velocity, DEC);

  play();
}


void setup() {
  Serial.begin(115200);

  myusb.begin();
  midi1.setHandleNoteOn(myNoteOn);

  if (!(SD.begin(BUILTIN_SDCARD))) {
    Serial.println("Unable to access the SD card");
  }

  if (SD.exists(wavFile)) {
    Serial.println("File exists.");
    play();
  }
  else {
    Serial.println("File doesn't exist.");
  }
}

void loop() {
  myusb.Task();
  midi1.read();
}

Sample output:

File exists.
Playing from SD card...
Done playing.
Note On, ch=1, note=62, velocity=63
Playing from SD card...
Done playing.
Note On, ch=1, note=53, velocity=121
Playing from SD card...
Done playing.
 
Thanks for the reply. I added some memory and am getting the same result unfortunately (the output also looks the same).
 
You are using
AudioOutputPT8211_2 pt8211_2_1; //xy=557,951

Are you sure you are using the correct pins? Can you show your a photo of your hardware, please`?
And did you try one of the audio examples?
 
..and what is the format of the wave file? It needs to be 44kHz, 16 Bit, Stereo. Everything else does not work..
 
Okay I fixed it! The issue turned out to be a combination of the fact that my wav file was actually encoded with 48kHz, and as you mentioned I was using the wrong PT8211 object in the audio system design tool. Once I changed both of those things it worked, thanks for your help :)
 
Status
Not open for further replies.
Back
Top