Go Down

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

DavidFMarks

Thanks once again .. I'll get to work on that. It's amazing how I can spend several hours getting nowhere and then you guys come up with a nice straightforward solution that leaves me wondering why I didn't think of that ! GRRRR. Anyway many thanks for the help, its greatly appreciated.

Tuttut

Hi,
@tack: have you looked inside the new version? I think I've put your stuff in, but it would be nice if you can try if also autoworker works on your platform as it needs additional stuff in those hardware-settings.

@xl97: You still need the init function that does a lot internally like setting up the file-system and configuring the audio ports. For Button example see the doorbell example that is also new in my library.

g_u_e_s_t

hello Tuttut

i just finished an analysis of pwm distortion, and then thought it would be cool to make a good and cheap wav player.  and it turns out it is cool, and you have already done it.  thanks for the work, i always enjoy finding projects like this.  if you are open to suggestions, here are some things that my research has shown to make improvements in the audio quality.

1. use 14b, phase correct pwm, at 62khz clock rate.  you never really get the full 16b anyways, even with perfect resistors, due to distortions building up in the noise floor.  also, perfect resistors are difficult to come by, even with trimming, due to the variability of the internal resistance of the arduino.

2. use 3.9k / 499k resistors for the mixing.  the output resistance is around 40ohms, so this keeps its error component low in comparison to the 3.9k.

3. dont bother with the external logic chips, they have a lot of jitter in comparison to the arduino itself, and introduce phase modulation and associated distortions.  also, the noise floor on the arduino i tested was -110dB, which was below the pwm noise floor for frequencies above 1kHz.  with the usb disconnected, the arduino isnt that bad.

4. you can try changing the depth / location of pwm to get further gains, but its probably not too significant for audio (as compared to pure tones), as the maximum amplitude is usually low anyways.

here are the writeups if youre interested:

distortion analysis:
http://www.openmusiclabs.com/learning/digital/pwm-dac/pwm-distortion-analysis/

dual pwms:
http://www.openmusiclabs.com/learning/digital/pwm-dac/dual-pwm-circuits/

again, great work, im looking forward to trying it out.

WilliamK Govinda

I'm loving this, already using it in a solar-powered project.

Now, maybe I'm daydreaming, but I would love to be able to output AM Radio Modulation instead of audio.  ]:D

http://dangerousprototypes.com/2011/10/05/am-sofware-radio-using-arduino/

Code:
http://dangerousprototypes.com/forum/download/file.php?id=5107&sid=9ed56f436c83604b287f75ec73f11146


Tuttut

Hi g_u_e_s_t,
a warm welcome on the journey of pushing the audio quality from 1-bit (and 2-bit) outputs to new frontiers! Raising audio quality from such limited systems is a challenging task but I am amazed how far we get. Some years ago I also shared the opinion that without an additional DAC it would be hard to get audio out of an AVR that sound far better than telephone.   
 
I read your writeups about PWM distortion and - at least - tried to understand them. I think you did a very good theoretical work, even I didn't understand everything yet. But I think you did a really great work toward raising audio quality out of such constrained systems and breaking actual known limits. Some time ago I started my journey by coding a high-order delta-sigma-modulator that converts audio-files to pulse-dense-modulated single bit-streams that I played back through the SPI port of the AVR at rates of up to 2 MBit/s. That way I moved most of the quantization noise out of the audible band, but for whatever reason, the quality on real-world hardware was worse than expected and because it is not possible to do mixing easily with pulse-width-modulated data I stopped my efforts. I wanted then to make something that makes good audio quality playback as easy as possible to use and with minimum hardware effort and started SimpleSDAudio.

With your research results I think we should try to get a step further in quality, but it's time to leave theoretic and try it at the real thing. Let's try if and when phase-correct PWM really sound better than fast PWM. Does it make sense for 2-bit systems to go from 16-bit to 14-bit (or even less) for better results? How about pre-filtering the input audio files to something like PWM-Freq/4? We will loose some high-frequency audio-information but maybe reduce perceived noise also.

You measured -110dB noise floor, I can't believe this really. When SimpleSDAudio stopped at a fixed PWM value, there is really no audible noise, but how about when it is accessing SD card and the AVR has to work harder? I thought the noise is much higher than but maybe I am wrong and that noise is really only from those artifacts you described - I have to try again...

Also interesting that Ti-paper about logic outputs. I wondered why it is so hard to drive speakers at reasonable volume, but with a 74AC14 it should be again worth a try  to drive a speaker as this thing cost only a quarter Euro.

Keep on your good work! I look forward to see what happens if you apply your thoughts to real hardware...

@WilliamK: Interesting thing that AM modulation. BTW: hook up a laser-pointer or a focused LED to the digital audio output pin and receive it over quite a distance using a small solar-panel from garden-light connected to an amplifier - it works great.

Go Up