issues with audio glitch and code

Status
Not open for further replies.

Krischomat

Well-known member
Hey Hey!
I got my teensy 4.1 with the audio adaptor today. So I tried my luck with the tutorial codes. There where some issues showing up that I have questions about.
First is when I play an audio file from the sd card with the player tutorial it seems I have some audio glitches there. I am using a 32GB SD Card, maybe better with 16 or 8? When I tried the mixer patch I had even more glitches. There were this periodic noise coming together with the internal LED flickering. The crossfade between the songs worked but still this noise eventhough the tracks didn´t play simultaneously.

I also used my own soundfiles. They were 16 bit and 44100. Maybe to long?

The second thing was about the code. The mixer patch didn´t work in the beginning so I started to write it new. Then there as I wanted to upload the patch it did complain about these part of the code:

mixer1.gain(0, 0.5);
mixer1.gain(1, 0.5);
mixer2.gain(0, 0.5);
mixer2.gain(1, 0.5);

Wich looked the same as in the actual mixer example. Then I copied it from the mixer tutorial in to my new written mixer code (which looked the same actualy) and it didn´t change anything in the code from what I wrote by hand but after this I could upload the code...

I would be greatfull if someone here could help me out =)
Best
Christian
 
Is TeensyDuino 1.54 in use?

If so post a link to actual code in use - maybe use some of the standard TEST sound files and confirm.

Starting with the Tutorial examples to learn the ropes and see function or issues the best start as they need to work and they can be easily set up by others.
 
1) often, the issue are too long wires , or pins not soldered to the audio shield. Can you post a photo?
2) You should post the code you use. That's better and we can see more easyly whats wrong.
 
Okay I am back testing and going through the first audio adaptor tutorial files also with the wavs intended for the tutorials. The first one checking the analog and digital ins with the serial monitor worked, also the second playing a wavefile tutorial. But I have the feeling I have also a bit of glitches there. Then I opend the Blink While Playing file and nothing happend after uploading. I could post the code here but it is basically the tutorial and I did not change anything. Then I copied the part with the LED blinking into the Play Wave code and it again played the wav but there was no LED blinking. Here is the Code:

Code:
// Advanced Microcontroller-based Audio Workshop
//
// http://www.pjrc.com/store/audio_tutorial_kit.html
// https://hackaday.io/project/8292-microcontroller-audio-workshop-had-supercon-2015
// 
// Part 1-3: First "Hello World" program, play a music file
//
// WAV files for this and other Tutorials are here:
// http://www.pjrc.com/teensy/td_libs_AudioDataFiles.html

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

AudioPlaySdWav           playSdWav1;
AudioOutputI2S           i2s1;
AudioConnection          patchCord1(playSdWav1, 0, i2s1, 0);
AudioConnection          patchCord2(playSdWav1, 1, i2s1, 1);
AudioControlSGTL5000     sgtl5000_1;

// Use these with the Teensy Audio Shield
#define SDCARD_CS_PIN    10
#define SDCARD_MOSI_PIN  7
#define SDCARD_SCK_PIN   14

// Use these with the Teensy 3.5 & 3.6 SD card
//#define SDCARD_CS_PIN    BUILTIN_SDCARD
//#define SDCARD_MOSI_PIN  11  // not actually used
//#define SDCARD_SCK_PIN   13  // not actually used

// Use these for the SD+Wiz820 or other adaptors
//#define SDCARD_CS_PIN    4
//#define SDCARD_MOSI_PIN  11
//#define SDCARD_SCK_PIN   13


void setup() {
  Serial.begin(9600);
  AudioMemory(8);
  sgtl5000_1.enable();
  sgtl5000_1.volume(0.5);
  SPI.setMOSI(SDCARD_MOSI_PIN);
  SPI.setSCK(SDCARD_SCK_PIN);
  if (!(SD.begin(SDCARD_CS_PIN))) {
    while (1) {
      Serial.println("Unable to access the SD card");
      delay(500);
    }
  }
  delay(1000);
}

void loop() {
  if (playSdWav1.isPlaying() == false) {
    Serial.println("Start playing");
    playSdWav1.play("SDTEST2.WAV");
    delay(10); // wait for library to parse WAV info
  }
 // print the play time offset
  Serial.print("Playing, now at ");
  Serial.print(playSdWav1.positionMillis());
  Serial.println(" ms");

  // blink LED and print info while playing
  digitalWrite(13, HIGH);
  delay(250);
  digitalWrite(13, LOW);
  delay(250);
}

So just the play music code with the print play time offset and blink LED part added.
 
Thats how my board looks:
https://drive.google.com/drive/folders/1-IM-4_4ldAMqbU-8X-jiV8dcc1nXId2_?usp=sharing

(didnt let me upload directly in to the forum...)

The audio board is a bit uneven on the teensy don´t know if that can bring any trouble? but it looks like all connections are good.

Edit: the serial monitor just shows "start playing" and nothing else is happening.

Edit#2: Okay a bit more trouble shoot. I took the play music code and part by part added this which worked

Code:
  // print the play time offset
  Serial.print("Playing, now at ");
  Serial.print(playSdWav1.positionMillis());
  Serial.println(" ms");

and than this
Code:
  // blink LED and print info while playing
  digitalWrite(13, HIGH);
  delay(250);
  digitalWrite(13, LOW);
  delay(250);

and the moment I wrote
Code:
  pinMode(13, OUTPUT); // LED on pin 13
into the setup it did not work anymore. no sound and no blinking
 
Last edited:
You are right, in the post before, pinMode() was missing.
So.. I have no Idea how your program looks like now (exactly), so please post it.


Edit: Do you understand what you're doing, or is it just copy&paste? Do you know C, or are you learning? Don't take this as an offense, but it helps us to help :)
 
Code:
// Advanced Microcontroller-based Audio Workshop
//
// http://www.pjrc.com/store/audio_tutorial_kit.html
// https://hackaday.io/project/8292-microcontroller-audio-workshop-had-supercon-2015
// 
// Part 1-4: Blink LED while Playing Music
//
// Do something while playing a music file.  Admittedly
// only blink Teensy's LED and print info about the
// playing time in the file.  The point is that Arduino
// sketch code is free to do other work while the audio
// library streams data from the SD card to the headphones.

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

AudioPlaySdWav           playSdWav1;
AudioOutputI2S           audioOutput;
AudioConnection          patchCord1(playSdWav1, 0, audioOutput, 0);
AudioConnection          patchCord2(playSdWav1, 1, audioOutput, 1);
AudioControlSGTL5000     sgtl5000_1;

// Use these with the Teensy Audio Shield
#define SDCARD_CS_PIN    10
#define SDCARD_MOSI_PIN  7
#define SDCARD_SCK_PIN   14

// Use these with the Teensy 3.5 & 3.6 SD card
//#define SDCARD_CS_PIN    BUILTIN_SDCARD
//#define SDCARD_MOSI_PIN  11  // not actually used
//#define SDCARD_SCK_PIN   13  // not actually used

// Use these for the SD+Wiz820 or other adaptors
//#define SDCARD_CS_PIN    4
//#define SDCARD_MOSI_PIN  11
//#define SDCARD_SCK_PIN   13

void setup() {
  Serial.begin(9600);
  AudioMemory(8);
  sgtl5000_1.enable();
  sgtl5000_1.volume(0.45);
  SPI.setMOSI(SDCARD_MOSI_PIN);
  SPI.setSCK(SDCARD_SCK_PIN);
  if (!(SD.begin(SDCARD_CS_PIN))) {
    while (1) {
      Serial.println("Unable to access the SD card");
      delay(500);
    }
  }
  pinMode(13, OUTPUT); // LED on pin 13
  delay(1000);
}

void loop() {
  if (playSdWav1.isPlaying() == false) {
    //Serial.println("Start playing");
    playSdWav1.play("SDTEST2.WAV");
    delay(10); // wait for library to parse WAV info
    //Serial.println("started");
  }

  // print the play time offset
  Serial.print("Playing, now at ");
  Serial.print(playSdWav1.positionMillis());
  Serial.println(" ms");

   //blink LED and print info while playing
  digitalWrite(13, HIGH);
  delay(250);
  digitalWrite(13, LOW);
  delay(250);

  // read the knob position (analog input A2)
  /*
  int knob = analogRead(A2);
  float vol = (float)knob / 1280.0;
  sgtl5000_1.volume(vol);
  Serial.print("volume = ");
  Serial.println(vol);
  */
}

The Serial Monitor just puts out "Start playing". When I remove the pinMode it plays the audio and shows the position in ms...
 
Just found this post by Pul Stoffregen in another thread from 2014 "You can't use pin 13 when running the audio shield, because it needs pin 13 for incoming I2S data." .... Okay...
 
Status
Not open for further replies.
Back
Top