Pages: [1] 2 3 ... 14   Go Down
Author Topic: New library for PWM playback from SD cards: SimpleSDAudio  (Read 43705 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 6
Posts: 75
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,
I like to promote my new library which makes playback of audio from SD cards very simple. The audio quality is 8-bit, but a PWM frequency of 62.5 kHz is used which gives decent sound quality at very low effort. The library is completely free, fully documented and includes some example projects for quick start. Enjoy, feedback here if you like it.

Edit/New: I updated the library (ported the core output part to hand-optimized ASM) and now also 16 Bit audio output (even in stereo) is possible (combining two PWM outputs using 2 resistors, known as 256R-R-network).

Edit/New: I updated the library again and now you don't have to call the .worker() function anymore if you provide a flag at init. Also added more examples like a doorbell with ding-dong sound as well as an example that shows file access from SD card using this library.

Regards,
Lutz
« Last Edit: January 22, 2013, 07:24:32 pm by Tuttut » Logged

Offline Offline
Jr. Member
**
Karma: 6
Posts: 75
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Forgot the link: http://hackerspace-ffm.de/wiki/index.php?title=SimpleSDAudio
Logged

0
Offline Offline
Edison Member
*
Karma: 8
Posts: 1250
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

cant wait to play with it!..


Audio & Arduino is a hard thing for noobies (like myself) to achieve...

havent read it yet.. does it play .wav files? or do you have to convert to a specific format first to play off SD?


update: read link.. yep I saw you have to convert the files to another format..

thanks
« Last Edit: July 05, 2012, 11:10:44 am by xl97 » Logged


Offline Offline
Jr. Member
**
Karma: 6
Posts: 75
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, you have to convert the files, but for Windows users the conversion is a simple drag'n'drop operation of the wav-file to a batch-file. I also show a very simple and cheap approach to build an SD-card adapter just from two standard pin-headers.
 
Logged

0
Offline Offline
Edison Member
*
Karma: 8
Posts: 1250
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

nice!..

would be better if it played straight .wav files though  smiley-wink


Logged


Offline Offline
Jr. Member
**
Karma: 6
Posts: 75
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I also thought about that, but the thing is that it is hard to get a high quality playback if PWM runs not at an integer multiple of the sample rate. That is the magic behind my library and that is why I can get such good quality. With high-speed PWM as available in ATtiny85 then it makes more sense to use the original playback rate (as Elm-Chan does).
Logged

0
Offline Offline
Edison Member
*
Karma: 8
Posts: 1250
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

cool!

I'm still wanting to play with it!

anything that helps do audio is a bonus!  Im sure others will appreciate it too!
Logged


Wisconsin
Offline Offline
Edison Member
*
Karma: 4
Posts: 1001
I LOVE THIS STUFF!!!!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

bump
Logged

Accelerate to 88 miles per hour.

Brazil
Offline Offline
God Member
*****
Karma: 3
Posts: 626
Beat707.com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you so much for this, will try out ASAP!
Logged


Brazil
Offline Offline
God Member
*****
Karma: 3
Posts: 626
Beat707.com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I love this, thank you, sounds pretty good, a bit of hiss, so I have to see how to clean it up.

Questions:

1) could you add an option for 20Mhz too? I got some 20Mhz crystals and ATmega328 chips lying around, wondering if at 20Mhz I could play stereo files better?

2) I did a PWM output that was nearly 10 bits, with a better audio. Check this out:
https://github.com/Beat707/BeatVox
Logged


Offline Offline
Jr. Member
**
Karma: 6
Posts: 75
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

1)
it would work with 20 MHz, but not better regarding stereo playback at full rate, because this is just a matter of free cycles. But with 20 MHz fullrate will be 78kHz, so just a little better. I think the next improvement I will make is to use a 256R-R network to go from 8 bit to 16 bit with just another port and 3 resistors.

2)
I don't find the circuit for the audio output. Increasing bit resolution is always about decreasing PWM frequency, the only way around is to use either a AVR with high-speed PWM (like Elm-Chan did with ATtiny85) or combining two PWM outputs.
Logged

Brazil
Offline Offline
God Member
*****
Karma: 3
Posts: 626
Beat707.com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I think the next improvement I will make is to use a 256R-R network to go from 8 bit to 16 bit with just another port and 3 resistors.

Niiice, I wonder about that.

Plus, I wonder about the ATtiny85 too.

Thanks!  smiley-cool
Logged


Brazil
Offline Offline
God Member
*****
Karma: 3
Posts: 626
Beat707.com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Question about the ATtiny85, as I also use those and have a few to test out, what kind of bit-depth are we talking with those? I'm not talking about SD card playback, just internal flash playback, as I'm doing another project, and all I need is to be able to play a single drum sound from the ATtiny85, but I need better quality, as better possible. ;-)

Thanks again!  smiley-mr-green
Logged


Brazil
Offline Offline
God Member
*****
Karma: 3
Posts: 626
Beat707.com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Maybe this could help you getting 16-bit using 2 PWM outputs?

http://embeddednewbie.blogspot.com.br/2011/02/review-of-arduino-dac-solutions.html

Resistor/PWM hybrid DAC

This is a good explanation on how to combine two PWM outputs in order to double the bit resolution. So combining two 8-bit arduino PWM outputs you can get a 16-bit PWM output! Remember Arduino's limits if you plan on going down this road. I mean, the Atmega chip is just 8-bit...

Logged


Offline Offline
Jr. Member
**
Karma: 6
Posts: 75
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
now I tried the 16-bit thing with the R256-R DAC and it gives a big advantage. It is not as good as you would expect from 16-Bit because it is hard to get rid of all those digital noise in such a circuit. The problem with all those circuits is to keep away the digital noise from supply from audio output. As long as a digital output pin that is supplied from uC is used, you also hear all the uC noise. Maybe it gets better if you decouple the uC better or use something like a buffer. But simply said, using just those two additional resistors you get rid of those hiss noise. After playing a little bit around it seems that most noise comes from the USB port - maybe you get acceptable results by using battery power.

What I did is the following: I set the following mode in software:
Code:
SdPlay.init(SSDA_MODE_HALFRATE | SSDA_MODE_STEREO)

Then I prepared my file with the following modified batch-file:
Code:
@echo off
cd %~dp0
mkdir converted
FOR %%A IN (%*) DO sox %%A --norm=-1 -e unsigned-integer -b 16 -r 31250 -c 1 -t raw "converted\%%~nA.ahd"  
pause

Connections I made:
Code:
Pin 9  ----[220k]------+
                       |  100nF
Pin 10 -[1k trimmer]---+---||----[10k]--AudioOut--[1k]--GND

With trimmer the sound can adjusted for minimum hiss, I prepared also a special audio-file for easier trimming.
« Last Edit: July 16, 2012, 05:05:35 pm by Tuttut » Logged

Pages: [1] 2 3 ... 14   Go Up
Jump to: