Playing WAV (or Audio file) using Arduino - Page 1
Forum section: electronics / general

author: aiq25
author_rank: Regular Contributor
timestamp: July 11, 2017, 07:56:40 pm
content: Hello. I'm working on a fairly big project where I need to play couple of different audio files (preferably using an Arduino). I tried the simple Arduino library for playing WAV files and that works fine for 2-5 second Audio but the files I'm trying to play are quite long, around 3-4 minutes. With the longer audio files I can hear the audio but it's very faint and there is ton of "noise" that I can't seem to filter out (using an LP and HF filters).Is there a shield or board I can get to help with this?I prefer Arduino because I'm using a RTC, SD card, graphic LCD shields so it will be easy to add it on for me. I also have a amplifier for the speakers.Thanks!

author: AloyseTech
author_rank: Regular Contributor
timestamp: July 11, 2017, 08:30:39 pm
content: Hi,I've made a library a few month ago to play wav file on any SAMD21 based arduino board :https://github.com/AloyseTech/ZerodioHope this helps.

author: hamster_nz
author_rank: Super Contributor
timestamp: July 12, 2017, 04:45:14 am
content: Something likehttps://www.adafruit.com/product/94but prebuilt?Adding quality audio to an electronic project is surprisingly difficult. Here is a shield for Arduinos that solves this problem. It can play up to 22KHz 12bit uncompressed audio files of any length. It's low cost, available as an easy-to-make kit. It has an onboard DAC, filter and op-amp for high quality output. Audio files are read off of an SD/MMC card, which are available at nearly any store. Volume can be controlled with the onboard thumbwheel potentiometer.If you don't like the idea of the kit, and want to pay nearly half the price, things like this are around:http://www.dx.com/p/sd-card-mp3-music-shield-audio-expansion-board-white-171917

author: technix
author_rank: Super Contributor
timestamp: July 12, 2017, 10:14:52 am
content: For passable-at-best audio quality on AVR Arduino you can try PWM. But because of the switching frequency being too low on most Arduino boards the audio quality can be very crappy.ARM based Arduino often have built in DAC which can manage slightly better audio quality.If you really want Hi-Fi you will have to use I2S and external DAC/codec chip. I am not sure if any Arduino supports this.For ARM my usual roost is STM32 which supports I2S on higher end parts. Down to specific chips you can try start with STM32F407ZGT6 which have native I2S, SD card and USB.

author: mariush
author_rank: Super Contributor
timestamp: July 12, 2017, 11:16:22 am
content: Or you could use an IC that supports i2s as well as i2c (in 20qfn chip) or SPI (in the 32qfn version of the chip), like for example: SGTL5000https://www.digikey.com/product-detail/en/nxp-usa-inc/SGTL5000XNLA3/SGTL5000XNLA3-ND/2186899

author: Buriedcode
author_rank: Super Contributor
timestamp: July 12, 2017, 04:02:37 pm
content: For the "cheapest" way on an Arduino I've had reasonable success using two output compare modules at 6-bit each, then mixing them with a resistor divider and a passive RC filter. This can give 12-bit resolution, but because each PWM is only 6-bit, pushes up the PWM frequency, allowing it to be attenuated more with a two pole filter.In terms of hardware, the cost is an extra couple of resistors. For MCU hardware, it uses up two PWM's (timer0 and timer2 both have two output compare units, and are 8-bits) in one timer. For software, assuming you've converted the wav's to 12-bit, for each sample you have to split it, shift a few times to get two 6-bit values for the output compare unit. It works with 16-bit, but then your maximum PWM frequency is 16MHz/256 = 62.5kHz, as opposed to 256kHz for 12-bit (2x6-bit) res.Sounds complicated but it essentially gives you double the resolution for free, or, allows you to keep your resolution, and increase the PWM switching frequency allowing for fewer poles on your filter.Whilst its hardly high fidelity, I was quite surprised by the quality, much better than telephone quality, and 'toys' that produce sound effects. If it's going to be played loud then you will need to improve the quality (to reduce noise). These days I'm sure there are piggyback modules/shields, with SDcard slot and a half decent DAC (>16-bit >48kHz) that will do most of it for you.

author: aiq25
author_rank: Regular Contributor
timestamp: July 13, 2017, 07:44:25 pm
content: Thanks for the responses guys.I'm not opposed to using an ARM based Arduino. I already have couple of DAC IC's I can use for this (8-bit and 12-bit).I would like to keep this project as simple as I can. Since I already have the SD card connected to the Arduino and can read from it, might be nice for me to just use a external DAC and amplifier for the sound.If anyone has a sample code that would help a lot. I understand the theory behind reading from the SD card and using the DAC but seeing an example would really help.

author: westfw
author_rank: Super Contributor
timestamp: July 14, 2017, 09:16:58 am
content: The Adafruit board has extensive useful examples.

author: Bruce Abbott
author_rank: Frequent Contributor
timestamp: July 14, 2017, 03:59:51 pm
content: Quote from: aiq25 on July 11, 2017, 07:56:40 pmWhich 'simple Arduino library' were you using, and what format are your WAV files?QuotePart numbers?

author: packetbob
author_rank: Contributor
timestamp: July 14, 2017, 10:48:58 pm
content: I have used a few of these in Arduino based projects:https://www.aliexpress.com/item/Mini-MP3-Player-Module-with-Simplified-Output-Speaker-for-Arduino-UNO/32271665509.htmlPlays MP3 or WAV files...Various options for controlling via serial connection or push buttons...Built in amp that is reasonably loud...Cheap.....