Go Down

Topic: SimpleSDaudio sound has a lot of static (Read 185 times) previous topic - next topic

Dar_T

I'm using SimpleSDaudio (http://www.hackerspace-ffm.de/wiki/index.php?title=SimpleSDAudio) to play wav files. The connections are as follows:

MISO pin 12

SCK pin 13

SS pin 4

MOSI pin 11

Speaker pin 9


    /*
     Simple SD Audio bare minimum example, plays file EXAMPLE.AFM from root folder of SD card.
     
     This example shows how to use the SimpleSDAudio library for audio playback.
     You need:
     - An Arduino with ATmega368 or better
     - An SD-Card connected to Arduinos SPI port (many shields will do)
       -> copy EXAMPLE.AFM on freshly formated SD card into root folder
     - A passive loudspeaker and resistor or better: active speakers (then stereo output will be possible)
     
     Audio signal output is at the following pin:
     - Arduino with ATmega328       (many non-mega Arduinos): Pin 9
     - Arduino with ATmega1280/2560 (many mega Arduinos)    : Pin 44
     
     Using passive speaker:   
        Audio-Pin --- -[100 Ohm resistor]- ---- Speaker ---- GND
       
     Using amplifier / active speaker / line-in etc.:
        Audio-Pin --||--------------[10k resistor]----+----[1k resistor]---- GND
                  100nF capacitor                   to amp
     
     See SimpleSDAudio.h or our website for more information:
     http://www.hackerspace-ffm.de/wiki/index.php?title=SimpleSDAudio
     
     created  20 Jan 2013 by Lutz Lisseck
     */
    #include <SimpleSDAudio.h>
   
    void setup()
    {
     // Open serial communications and wait for port to open:
      Serial.begin(9600);
       while (!Serial) {
        ; // wait for serial port to connect. Needed for Leonardo only
      }
   
      // Using F("...") to avoid wasting RAM 
      Serial.print(F("\nInitializing SD card...")); 
     
      // If your SD card CS-Pin is not at Pin 4, enable and adapt the following line:
      // SdPlay.setSDCSPin(10);
     
      if (!SdPlay.init(SSDA_MODE_FULLRATE | SSDA_MODE_MONO | SSDA_MODE_AUTOWORKER)) {
        Serial.println(F("initialization failed. Things to check:"));
        Serial.println(F("* is a card is inserted?"));
        Serial.println(F("* Is your wiring correct?"));
        Serial.println(F("* maybe you need to change the chipSelect pin to match your shield or module?"));
        Serial.print(F("Error code: "));
        Serial.println(SdPlay.getLastError());
        while(1);
      } else {
       Serial.println(F("Wiring is correct and a card is present."));
      }
   
      Serial.print(F("Looking for on.wav... "));
      if(!SdPlay.setFile("hi.wav")) {
        Serial.println(F(" not found on card! Error code: "));
        Serial.println(SdPlay.getLastError());
        while(1);
      } else {
       Serial.println(F("found."));
      }   
   
      Serial.print(F("Playing... "));
      SdPlay.play();
      while(!SdPlay.isStopped()) {
        ;   // no worker needed anymore :-)
      }
      Serial.println(F("done."));
      SdPlay.deInit();
    }
   
   
    void loop(void) {
   
    }

The problem is when playing the wav files. It plays with a lot of static. I've tried adding a 1k resistor between the speaker and gnd but that just lowered the overall volume. I resampled the wav files in itunes to 32khz, 8bit, mono. If I lower to 16khz then the audio volume becomes very low and the song just plays extremely fast. Here is a google drive link to one of the sounds:
https://drive.google.com/file/d/0B3yAl4G-mcC4dlppN3dtczJvT1k/view?usp=sharing

I really need help. I'm not sure what to do!

DVDdoug

That doesn't sound bad for 8-bits.  Is that the way it sounds, or is that just the file?

I don't know what kind of sound quality to expect without using a real DAC but I'd be really surprised if it sounds as good as a DAC.   

Your sample is only hitting -12dB on the peaks.   If that's representative and if the original is 16-bits (or more) you can normalize the file before downsampling.   That will improve your signal-to-noise ratio by about 12dB.

Quote
If I lower to 16khz then the audio volume becomes very low and the song just plays extremely fast.
That shouldn't change the volume.  But if your playback sample rate isn't also lowered to 16kHz to match the sample-rate of the file, of course it will play back too fast.     (A "proper" WAV library will handle that, but I don't know anything about reading WAV files with the Arduino.)

Lucario448

(A "proper" WAV library will handle that, but I don't know anything about reading WAV files with the Arduino.)
The TMRpcm library does that thing. In fact, I'm pretty impressed about how well does it's job. Even 8-bit samples at 16 KHz sounds pretty good!

Dar_T

Is there a way to increase the volume of .AFM files?

DVDdoug

Quote
Is there a way to increase the volume of .AFM files?
I've never heard of an AFM file.   

Any audio editor can normalize (maximize) a WAV file or any audio format it can read/write.   

Audacty is a free (open source) audio editor.    In Audacity, the Amplify  effect will scan the file and automatically default to the maximum amplification you can get (if any) without clipping (distorting).

But, if you are driving an 8-Ohm speaker (through the required current limiting resistor) you're only getting a few milliwatts maximum and it's not going to get loud.

Lucario448

Is there a way to increase the volume of .AFM files?
If you are not sure about that file, then attach it into your next reply (put it in a zip archive first, otherwise you can't do that). Or, share the file as you did before.

The idea is to let me check that file, if there is any kind of uncompressed raw audio data in it.

Lucario448

Update:

Now I don't need your file, because I've downloaded the library; and there I've found a file called "EXAMPLE.AFM".
I've checked that file, and it appears that it's like a "headerless" WAV audio file (in other words, it has uncompressed raw audio data, just as I expected).

Maybe this happens because that library has a rudimentary way to handle files (but faster than the SD library). So that's why in the URL's webpage you posted at first, says that files should not be fragmented ("fragments" of a file sparsed across the SD card's space, caused by previously deleted ones).

Furthermore, for the sake of performance, looks like this library is not meant to handle RIFF/WAVE file headers. So this is why working with an audio file for this library might be a little tricky (but is not that difficult, actually). The ".AFM" extension is a "convention" for the library, to easily identifiy (and maybe for the library itself too) how the data is encoded.

If you want, I can teach you how to create (or edit) those kind of audio files, using Audacity.

About your noise problem, there are two reasons for that:

  • 8-bit sampled audio usally makes this during "silence", or quiet parts.
  • The output signal is too weak even for headphones. So when you try to amplify that signal, you also amplify random noise (aka "white noise" or "static") along the way.


This what I think about all this...

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy