Audioshield playing sound from SD and microphone

Status
Not open for further replies.

digi128pci

New member
Hi,

First of all thank you for this amazing project! :cool:

My goal is mixing the sound of a headset microphone with sound playing from a SD card and playing it back on the headphone (high impedance headphone 150 ohm).

I got most examples working but I'm having a few issues.

  1. Clicking sound in headset when using microphone and playing sound from SD card
  2. can't play sound from internal SD card (teensy 3.6)


First issue:
When playing sound from the sdcard (audio shield) and connecting both microphone and headphone from the same headset I get a clicking sound mixed in the music.
The clicking sound stops if I remove the microphone wire or use a separate headphone (mic and headphones separated).
If I play the sound stored in the teensy memory there is no clicking sound.
If I use an external microphone amplifier they clicking noise stays, but when I connect the amplifier to a separate power supply the noise is not noticeable.
When i connect the ground wires of the separate PSU's the noise is back.

I suspect that there is some kind of noise introduced by reading the SD card on the power supply and it transfers though the wire of the headphone to the mic.

I made some measurements of the 3.3V when playing sound from the SD card and when I stop playing from SD card.

Image one is 3.3V rail no sound playing from SD card (CH1 is 3.3V from teensy, CH2 is 3.3V from separate PSU)
DS1Z_QuickPrint3.png

Next Image is when the SD card is playing
DS1Z_QuickPrint2.png

I tried adding 0.1µF cap and 47µF. The signal gets smaller but clicking sound stays the same.

Any idea's to resolve this problem without the need of a separate PSU?


Second issue:

I tried fixing the SD card issue by using the internal SD card from the teensy 3.6.
I changed the ports in the software but no sound is playing from the internal SD card. (If i do not insert SD card on the teensy i get an 'Unable to access the SD card', so its detecting the SD card)
I tried the example listing all files on the internal SD-card and that is working fine.
So no sound from internal SD card.

Any idea's how I can get the internal SD card to work?

  • Arduino 1.8.9
  • Teensyduino 1.46
  • Teensy 3.6


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 2-4: Using The Microphone


///////////////////////////////////
// copy the Design Tool code here
///////////////////////////////////


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


// GUItool: begin automatically generated code
AudioPlaySdWav           playSdWav1;     //xy=257,314
AudioInputI2S            i2s2;           //xy=263,223
AudioMixer4              mixer1;         //xy=517,198
AudioMixer4              mixer2;         //xy=518,294
AudioOutputI2S           i2s1;           //xy=712,253
AudioConnection          patchCord1(playSdWav1, 0, mixer1, 1);
AudioConnection          patchCord2(playSdWav1, 1, mixer2, 1);
AudioConnection          patchCord3(i2s2, 0, mixer1, 0);
AudioConnection          patchCord4(i2s2, 0, mixer2, 0);
AudioConnection          patchCord5(mixer1, 0, i2s1, 0);
AudioConnection          patchCord6(mixer2, 0, i2s1, 1);
AudioControlSGTL5000     sgtl5000_1;     //xy=394,448
// GUItool: end automatically generated code


Bounce button0 = Bounce(0, 15);
Bounce button2 = Bounce(2, 15);  // 15 = 15 ms debounce time

// Use these with the Teensy Audio Shield
// Works
/*#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


void setup() {
  Serial.begin(9600);
  AudioMemory(20);
  sgtl5000_1.enable();
  sgtl5000_1.volume(0.8);
  sgtl5000_1.dacVolume(1);
  //sgtl5000_1.inputSelect(AUDIO_INPUT_LINEIN);
  sgtl5000_1.inputSelect(AUDIO_INPUT_MIC);
  sgtl5000_1.micGain(50);

  mixer1.gain(0, 0.8);
  mixer1.gain(1, 0.2);
  mixer2.gain(0, 0.8);
  mixer2.gain(1, 0.2);


  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(0, INPUT_PULLUP);
  pinMode(2, INPUT_PULLUP);

  delay(1000);
}

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


 /* // read pushbuttons
  button0.update();
  if (button0.fallingEdge()) {
    playSdWav1.stop();
  }
  button2.update();
  if (button2.fallingEdge()) {
    playSdWav1.stop();
    playSdWav1.play("SDTEST2.WAV");
    delay(10);
  }*/
}

Thx for the feedback!
 
Update:

Found the SD-card problem on the forum. Issue in Teesyduino 1.46

https://forum.pjrc.com/threads/56355-AudioPlaySdWav-DMA-timing-and-buffer-misalignment-issues

FIX:
Code:
In hardware\teensy\avr\libraries\Audio\play_sd_wav.h 
Changed:

//uint8_t buffer[512];		// buffer one block of data

TO
uint8_t buffer[512] __attribute__ ((aligned (4)));

And in play_sd_wav.cpp

commented out: __disable_irq();

	//__disable_irq();
	wavfile = SD.open(filename);
	__enable_irq();
	if (!wavfile) {
 
Status
Not open for further replies.
Back
Top