Categories
Making

LilyPad MP3 Player

2015-12-05 lilypad

December 5, 2015

After a long break from Arduino, and electronics in general, I wanted to jump back in with an easy/medium difficulty task or project. With the many holiday discount sales out there for companies like Adafruit and Sparkfun, I went ahead and got a few projects to keep me busy over the winter.

First up is the LilyPad MP3 Player by Sparkfun. While it isn’t exactly taking me into new territory, the form factor of a round board was something I hadn’t worked with before, and the pre-configuration as a trigger device was a nice feature to get up and running quickly. But how does the board perform?

My setup consisted of the LilyPad, a 3.7 V 1200 mAh LiPo from Adafruit and two 8GB microSD cards from an old Android phone (formatted FAT32)

It took longer to charge the battery and format the SD card than it did to test the Trigger sketch on the LilyPad. For the test I started with free loops from Loopmasters (I’ve got literally hundreds of these), and some MIDI drum performances from Odd Grooves, a company that produces MIDI performances of live drummers.

LilyPad file specs from Sparkfun (at time of this posting):

MPEG layer III (.MP3)
Two channels max
Sample rates: 8 through 48 kHz
Bitrates: 32 through 320 kbit/s
Variable bit rate (VBR) supported
Layer I and II also supported with additional setup, see the VS1053B datasheet for more
information.

Ogg Vorbis (.OGG)
Two channels max
Window size: 64 – 4096 samples
Sample rate: 48 kHz max
Bitrate: 500 kbit/s max

AAC (.AAC .MP4 .M4A)
Two channels max
Sample rates from 8 kHz to 96 kHz (rates > 48 kHz are downsampled to 48 kHz)
Bitrates to 576 kbit/s
ATDS (streaming) format recommended

WMA (.WMA)
Two channels max
Sample rates from 8 kHz to 48 kHz
Bitrates from 5 kbits/s to 192 kbits/s
Variable bit rate (VBR) supported

(.WAV)
Two channels max
PCM format
8 or 16 bits, sample rates < 48 kHz
IMA_ADPCM format
Sample rates < 48 kHz
MPEG LAYER 3 format
Same as MP3 modes

MIDI (.MID)
General MIDI and SP-MIDI format 0
Format 1 and 2 files must be converted to format 0
Maximum polyphony: 64
Actual polyphony: 19-31 notes at 3.5X clock
Two instrument banks:
GM1 (instruments)
GM2 (percussion)

All you need to do is rename the audio files on the micro-SD card so that the first character of each filename
is the number “1” to “5”, corresponding to the trigger that you want to play that file. You don’t need to change anything else about the file name.

This might be the first time I’ve mixed WAV and MIDI data for a project. Usually they are treated separately. Having the ability to use both is helpful for saving disk space because a MIDI performance takes up very little space. Sound boards like LilyPad and Adafruit’s Sound FX boards are getting more sophisticated and can handle both without much, if any, additional coding. This is impressive, since both file types are significantly different. WAV, MP3 and most other file types that consumers use for music contain actual audio data. MIDI is not audio data at all, but control information for music – the notes, rhythms, etc but not the sounds (wave forms).

MIDI files played just fine. Initial tests with my 44.1 Khz 16 bit stereo WAV files resulted in noise:

Then I realized my WAV loops were 24 bit, but the LilyPad only handles 16 bit. So I converted them to 16 bit with Adobe Audition, and had same issue – terrible distorted noise – in time with where the music should be, but obviously not played back correctly. According to the specs, 44.1 Khz 16 bit stereo audio is supported, so I reported the issue to Sparkfun, but continued to test.

Additional tests:
1. Loaded into Audacity and resaved files but had same issue.
2. NTFS card format didn’t work at all.
3. Tried MP3 files (320 bps) and they work fine.
4. Tried using Switch on Mac to generate the WAVs – still same problem
5. Audition offers 4 GB Plus support (RF64) and a Multiple Data Chunks format for Legacy Audition. Too many options if you ask me, but niether seemed to matter for the current issue.
6. Confirmed 8.3 file format (though this doesn’t appear to matter much).

Why am I insistent on using WAV? Besides the fact that the device is documented as supporting it, the main reason is that conversion from MP3 to WAV involves extra steps – steps that take time, even when using batch converters. I’d like to be able to work with WAV audio – directly out of my DAW or stereo editor of choice (which is Adobe Audition right now). There’s that, and the fact that I’ve run into many boards with the same issue, and it seems a fatal flaw in the way these boards are designed (and marketed).

12/6/15 Continued testing
1. Recorded new file with Audacity, saved as 44.1 khz, 16 bit and it failed.
2. Did same with Audition and it failed.
3. Using Audition, downgraded to 8 bit and this played back… sort of. More recognizable, but not as clear as MP3.
4. ExFat card format – failed
5. Created new audio in Reason and Ableton, using the native WAV export from those programs (both on Mac) – Both failed.
6. Downgraded WAVs to 32khz, same issue.

Conclusion: While documented to play 44.1 Khz, 16-bit stereo WAV files, the LilyPad does not do so without significant distortion that makes the audio unrecognizable. 8 bit is somewhat better. If anyone has a workaround for this – for the LilyPad specifically, or for this wide spread problem in general – I’d love to hear from you!

MORE TESTS

12/6/15
Based on past experience, sometimes smaller cards work better for these devices, but a 1 GB FAT16 MicroSD also failed for WAV playback.

12/7/15
Sparkfun asked me some questions about how I am powering the device. “The MP3 Player pulls a lot more power than a regular USB port can provide. If you are only providing power through the FTDI and a computer’s USB port, it will not be sufficient to play tracks with the LilyPad MP3 Player.”

Of course, I was using battery, so not sure why this is an issue. Sparkfun noted the obvious (and what my research shows) – any little deviation in the WAV format can cause problems. My issue is that I can not find a way – with industry-standard programs – to create WAV files that these little boards will play. So I sent them the link to this page so they could see the testing I’ve done.

12/8/15
Bring in the (WAV) strippers
During one of my last experiments, I recall having to use a WAV file stripper, so I did a search to see what’s out there these days…

https://github.com/TooTallNate/node-wav
Command line is pain in the butt.

http://www.lightlink.com/tjweber/StripWav/StripWav.html
Performed Quick Strip process and this made no difference.
Performed Slow Strip process and this made no difference.

Free Audio Converter
Confirms file is pcm_s16le (PCM signed 16 bit little-endian)
Otherwise, no effect on the result.

12/11/15
Sparkfun was in touch again and asked for copies of some WAV files to examine, so I sent them a bunch of stuff to review.

In case I didn’t note this before, I am working mostly on Win 8.1 for this project. But I also use Mac in the studio.

Further testing with an SD card formatted from my Macbook, but no difference there with WAV playback. In this case, the card format and size seem to be fine. So focusing rest of my testing on WAVs.

Found an old WAV file from 2013 that was used in a previous audio experiment and had been stripped of any unnecessary data. Even that file didn’t work.

Tried a command line stripping program RiffStrip, but this resulted in an unplayable file on the PC.If the WAV file is a normal WAV-PCM, the output file will be a RAW-PCM.
C:\Riffstrip\4_auditRS.wav
Error: The byte stream type of the given URL is unsupported.

AudioShare for iPad – Stereo 44.1 16 bit – fail
RecordHQ for iPad – Stereo 44.1 16 bit – fail
Android SmartVoice Recorder app MONO 44.1 16 bit – fail (but better than most attempts, possibly because it was MONO)

12/12/15

Sparkfun response:

Testing the files, I am seeing the same thing that you are seeing. I tried other sample wav files that I had around my computer with the same noisy muffled output on my speakers. For some strange reason, reducing the sampling rate to a lower rate in the preferences of Audacity helped. While I could hear the track better with less noise, the quality of the output was muffled and bad. =( Looking at the datasheet, the tracks were within the sample rate range so it should have played distinctly like an MP3 track. I am currently waiting on the designer/engineer of the LilyPad MP3 Player to see if he knows of any way to resolve this issue.

So at least this shows they can reproduce the problem, and I am not crazy! Well… mostly.

Epilogue:

12/16/15 Response from Sparkfun:

I just talked to the engineer and he is not quite sure why the wav files are failing. When creating the LilyPad MP3 Player tutorial, he was basing the Supported Audio Formats off the VS1053B IC’s datasheet. He wasn’t able to test out your setup yet but he was able look at your tutorial/review briefly. I’m not sure when he will be able to test it since it is not at the top of his priority list right now.

Quick Fix
I do remember another engineer had somehow got it working so I tested out the .wav files from this tutorial => https://learn.sparkfun.com/tutorials/sound-page-guide#hacking-your-kit . I was able to get those .wav files working from the tutorial. It looks like he reduced the file size to mono and 22050 Hz for the project rate in Audacity. Testing this on your .wav files exported as a “signed 16-bit PCM”, I was able to get a clearer sound. Try modifying the .wav files with that configuration. The issue is that the rate is reduced and the audio track has been converted from stereo to mono. I’m not exactly sure why 32000 Hz and 44100 Hz rates with stereo and .wav files as signed 16-bit PCM do not work. Maybe the VS1053B cannot handle the quality of the .wav files and the datasheet is wrong?

avatar

By jjdeprisco

Sonic explorer, sound artist, guitarist in Fricknadorable, software designer.