Go Down

Topic: Wav from SD Card - reproduction very very poor (Read 2316 times) previous topic - next topic

brewmaster123

Hi there - Hoping someone can help as I've been struggling with this for a while.  Couldn't get any joy out of an SDcard module, so I'm now running an Ethernet shield with a micro SD card.

I have a WAV file formatted to 8-bit unsigned, 8000khz, Mono. (using the http://audio.online-convert.com/ tool).

Connected speaker between pin 10 and gnd (code below)

When I load up the sound does play to the speaker, best at about volume "4".  If I up the volume the sounds clips horribly.  If I lower the volume all I can hear is a flickering rumble (rumble is replicating flashing led on the Ethernet card, prob around 6hz).  Also, if I then connect to a powered PC speaker rather than a blank speaker, the sound goes entirely to a robotic sounding mess that eventually causes the sound to fail entirely.

I can't believe this is what anyone else is getting, so I must be doing something fundamental wrong - anyone got any ideas?  Really frustrating me...

The two main issues are;
Quality of unpowered output - rumbling interference at low vol, bad clipping above 5
Not working with powered pc speakers - it sounds just like a random digital signal

BTW  - I have tested the PC speakers and they work fine playing the same sound file straight from the PC.

#include <TMRpcm.h>

#include <SPI.h>
#include <SD.h>

char mychar;
const int CS_PIN = 8;
TMRpcm tmrpcm;


void setup() {
  tmrpcm.speakerPin = 10;
  tmrpcm.setVolume(5);
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.println("Initializing Card");
  pinMode(CS_PIN, OUTPUT);
  if(!SD.begin(CS_PIN)) {
    Serial.println("Card Failure");
    return;
  }
  Serial.println("Card Ready");
  tmrpcm.play("1.WAV");
  Serial.println("Done");

}

void loop() {
}


Regards,
Mark

Grumpy_Mike

Have you fitted a reconstruction filer on the output, a 1K series resistor followed by a 10nF to ground.

Quote
I have a WAV file formatted to 8-bit unsigned, 8000khz, Mono.
When you recorder the sample did you filter the sound so that no greater frequency than 4KHz got through? You need to do that to prevent aliasing, which sounds horrible.

This is the sort of quality I got with the same technique but not the same libiary. https://youtu.be/WShVFcrFpwU
It takes the sample code out of the program memory.

brewmaster123

Thanks for the reply and suggestions.

So I've never built the filter you refer to before, and no it wasn't in place - Would you have a simple wiring diagram for such a filter?  Is it literally the line from pin 10 to the speaker is also connected to ground via the resistor and capacitor?  Will this make a big difference (guess you wouldn't have suggested it if not)?

I saw examples online of folks just hooking straight into the pin, so thought I would get as good a result...

When I recorded the sound I didn't put a pass filter on it - but I've just done that now and the only real difference I found was that there was slightly less robotic sounding (but not significantly) and that the sounds was more muffled (as I would expect).  It still didn't work at all when the speakers were powered, and still had the rumbling frequency undertone.

The clarity and volume you're getting is far beyond what I'm getting.

Will the filter-to-ground sort me out do you think, or is there anything else I could try?

el_supremo

The default CS pin for SPI is pin 10 - why not use it? Try changing CS_PIN to 10 and speakerPin to 8.

The example SD code does not set pinMode for CS_PIN. Try removing that statement.

Pete
Don't send me technical questions via Private Message.

DVDdoug

Quote
Also, if I then connect to a powered PC speaker rather than a blank speaker,
You should NOT connect a regular 4 or 8-Ohm speaker directly to an Arudino output because you'll get excess current and bad things can happen, including overheating and frying your Arduino.   The minimum resistance/impedance is 125 Ohms.   Any lower than that you'll exceed the 40mA "absolute maximum" rating for the ATmega chip. 

   

Grumpy_Mike

Quote
Is it literally the line from pin 10 to the speaker is also connected to ground via the resistor and capacitor?
No.
Arduino output pin to one end of the resistor. The other end of the resistor to the amplifier input and also to the 10nF capacitor. The other end of the capacitor to ground.

How does your quality compare with that video?

el_supremo

Correction - Pin 8 can't do PWM. Try pin 9.

Pete
Don't send me technical questions via Private Message.

brewmaster123

Hi all - thanks very much again for the input.  So it's all sorted now by a combination of factors;

1.  I added the recommended resistor and capacitor - this cleaned the audio output very well, and allowed me to run to the powered speaker too.
2.  Adjusted the code as recommended to CS pin 8 and Speaker pin  9

I still found volume setting 4-5 about maximum, after which I just get distortion, but that's fine.  My original WAVs run well enough too, even without a pass filter on the audio file.

brewmaster123

So I thought this was fixed, but a couple of new issues arose almost immediately;

SD initialisation on power-up (after power down)
So I was running CS pin 8 and Speaker pin 9, with the filter suggested and all worked well.  However, when I unplug or power down the board, and then bring it back up 5 min later, the SD card fails to initialise.  The only way I can get it to initialise is with CS pin 4. 

However, with CS pin 4, I'm back to getting noise again from pin 9 to my speaker - even with the filter.  Without the filter it's bad too.

If I upload CSpin4 code and run it, then upload CSpin10 code it will work, but clearly I can't do that double upload everytime I want to power up the project.

9v Battery interference
One other problem I had with the speaker which may be unconnected, was that when it was working, if I power with a 9v battery rather than the usb supply, the audio has another pulsing noise - is that because 9v is too much to feed in?

Any ideas?  Thanks in advance...

Xmooker

Hi guys,  i need some information in .wav reproduction. 
What quality can i get playing wave files, considering its mono 44khz? 8, 16bits..?
Thanks in advance.

Grumpy_Mike

What quality can i get playing wave files, considering its mono 44khz? 8, 16bits..?
On a Uno from an SD card - zero quality.
One other piece of advice - don't hijack threads.  >:(

Go Up