Go Down

Topic: New library for PWM playback from SD cards: SimpleSDAudio (Read 125185 times) previous topic - next topic

WilliamK Govinda

the buzzing sound can come from anything on the Arduino or stuff connected to it. I don't think that you can get rid of it just by optimizing the software - increasing sample rate will not change things. The quality out of the PWM is already superior, but get's damaged by the noise on the supply lines.
Therefore as I proposed before try to use something that "isolates" the digital PWM lines from power source. Use a buffer or a level shifter. Then filter the supply for that level shifter very thouroughly  using an own linear regulator or at least a serial resistor with a capacitor to gnd between VCC-digital and VCC-analog.

For now I will ignore the buzz sound, I deal with that later on. ;-) Txs bud.

Regarding 4channel mode: If I translate the interrupt function to assembler then it should be possible to have enough computing power for stereo 16 bit playback...

Oh! oh! oh! That would rock!!!!!!!

Regarding pre-load: The function setFile stores internally something about the file in a small structure. By using that struct it should be possible to playback any file with very little latency. Maybe I will add this feature later to the library.

Indeed, shouldn't be too hard for me to just hack the thing out if I really need. So far I'm just using the setFile and it still works great!

Thanks again!

Cheers, WilliamK

WilliamK Govinda

Just wanted to thank you again for such great library.  8)

I managed to find the buzzing sound, it was my wiring, a friend told me to not use too long wires to connect to the SD Card, that was the reason of why the SPI Clock was leaking to the PWM outputs. Its solved now.

I still wonder if it would be possible to handle WAV files (saved at the right sample-rate) but its not a big deal to convert things up, just wondering. (one less step for newbies)

The 16-bit mono support is great, but yes, stereo support would put this lib in a new position.

I plan on using 4 loopers running side-by-side, already got extra ATmega328 + Crystals here to do so. ;-) Just need some extra time, prob next week...


hey guys...

I dusted off my 2009 board.. and want to give this library a try and compare it to the output Im getting using dedicated hardware and the WaveHC library (.wav files)

what is the wiring set-up you guys have going?

I have an SD card (made a little break out board for it).. and plugs into my Arduino 2009 board..  with the correct resistors for level shifting..etc..

reads/writes fine using SDFat libraries to test..

what else is there?  what pins are you using for the speaker output?  what other components are needed?

off to download library now..



The wiring is described on the website. If you are using a shield already for SD card connection, all you need is a capacitor (take anything you get between 100nF and 100uF), connect positive end of capacitor to Arduino-Audio-Outputpin (as described in library documentation) and connect the other to your active speaker/line in. Then also connect GNDs of active speaker/line in and Arduino and you are done. That way you can play back the example file or any other files converted to MONO and FULLRATE or HALFRATE.


Jul 27, 2012, 06:09 am Last Edit: Jul 27, 2012, 07:10 am by xl97 Reason: 1
HI I just downloaded your lib to finally play with it..

I (finally) noticed everything is .ino  or for Arduino 1.0 only?

I tried to put your lib in my libraries folder..but it never showed up (Im still using IDE v.23)

is there a version for older IDEs?


installed IDE v1.0 justto try this..

did minimal (10uF cap, speaker approach)..

sounds great!.. awesome job on using minimal components..with default Arduino!!!

this adds so much more ability/options for projects..

question (since Im a noobie)..

are we free to do whatever we want during the audio playing?  any restrictions?

what about having other components on the SPI bus?

thanks..  =)




>is there a version for older IDEs?
No, currently you need at least Arduino 1.0 IDE.

> are we free to do whatever we want during the audio playing?  any restrictions?
It depends... You have to call the worker()-function frequently enough to avoid buffer underruns. This function reads the next sector from SD card into a ringbuffer to keep audio playing running.

The library uses timer1 on most Arduinos (timer5 on mega arduino). This should be no issues for standard libraries, but libraries which uses those timers may not work correctly. analogWrite() functions should work even with that modified timer. The timer's interrupt is used to for audio playback, disabling interrupts for more than 10 micro seconds could result in playback distortions. In general, very much of the available computing power of the Arduino is used during playback...

> what about having other components on the SPI bus?
The lib could work with other stuff on the SPI bus as long as it has its own chip-select and does not need to change the spi transfer parameters (SD lib uses full speed). It seems to work with the Ethernet-Shield - also an example to start playback via webbrowser is included in the examples. For other SPI stuff it depends - just try it...


Hehe, I now got stereo at fullrate working - I've rewritten the audio output interrupt routine completely in ASM. Next step is heading to 4-channel audio output at 8-bit or stereo-16-bit-output...


I think this is VERY awesome!!..


I had a (now defunct) PIC project that played audio through PWM output as well.. was very easy/low components too..  missed it!

Now we have this!!!

I read about thew buzz/hiss on the output a little bit.. what was the verdict?

dirty power lines?  or something with the SPI bus/lines?


can you easily change the speaker out pin used on the Arduino?

I tried to change this:

uint8_t const SSDA_PWM1_PIN =  9; // OC1A PB1


uint8_t const SSDA_PWM1_PIN =  5;

but didnt seem to work on getting output on PWM pin 5



no, you can not change the speaker output because it need very special PWM pins. It it would be that easy I'd already implemented it in the library. May I ask why you need the output pins to be changed?


I figured..  I was hoping another PWM pin could be substituted.  :)

I was just trying to test it out on a specific (custom) board I had... to see if this lent even more flexibility to it..

I have one more (custom) board I want to try this with..

my 'goal' on my board/project was to have a very small footprint/sized board (which I need for the things I like to do..and full sized dev boards dont cut it).... that had several on-board things that we buy/use shields for.. (SD card.. .wav playback.etc..etc..)

but still be generic enough to apply to many different projects.

(here it is: http://dmstudios.net/misc/scab_assembly/flash_board.jpg)
using the WaveHC library.. it plays .wav files off the SD card..
can also just be used as a data logger or to access stuff on the SD card is audio playback is NOT the focus for the board..etc

here it compared to an Arduino & WaveShield.. (which this was based off...sorta merged together)



I had a failed version of this project I wanted ot test your lib with.. (but no D9 available on that)

the one above.. (current project) does have it (D9) available, so will be testing on that as well..


I've been playing with this library today and have to say it's awesome for what I need, being able to play simple sound effects from game props.

I've just been using a single pin today for 8 Bit Full Rate Mono, but the quality seems really good for what we need. Unfortunately I was using an Ethernet shield for the SD cardso couldn't use D10 to try 16 Bit. That's the only downside I can see, the pin conflict with Ethernet and some LCD Shields (pin 10 is used for backlight brightness control).

Just thought I'd say a big thanks for the time put into this. It's a great piece of work to show what can be done direct from the MCU, without additional hardware.

I connected up to a set of PC amplified speakers and it sounds great with both voice, item and vehicle sounds.


Hehe, I now got stereo at fullrate working - I've rewritten the audio output interrupt routine completely in ASM. Next step is heading to 4-channel audio output at 8-bit or stereo-16-bit-output...

Hi there,

just stumbled upon your library, it's great!
Many thanks!!

The last version on your website (v1.01) seems to date previous to this rewrite.
Any chance of posting this new version?
I would like to do 16-bit mono @8mhz, so I could use the extra resources...

Thanks again for sharing this!!

Regards Dennis



This looks like a great library. Any chance that it could be ported over to include support for the chipkit Uno32? How difficult do you think it would be to do so? It appears that PWM would be relatively simple to port over, but I am not sure about the SD card interface. Any ideas?

With the 80MHz 32bit processor on chipkit, you could have faster SD card read times and high sample rates that would enable more processor free time and better sound. The chipkit is also natively 3.3V, so no level shifters are necessary.


Go Up