0

Play audio (MP3) using VS1053 breakoutboard & Teensy 3.1
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Play audio (MP3) using VS1053 breakoutboard & Teensy 3.1

by galeviel on Sun Oct 26, 2014 12:45 pm

Hi!

I was wondering if anybody has successfully used the VS1053 breakoutboard and a Teensy 3.1 to play any audiofile from a SD card.
If so how did you do this? what value did you set the SPI_CLOCK_DIVx to?

Thank you!

galeviel
 
Posts: 4
Joined: Wed Oct 15, 2014 12:44 pm

Re: Play audio (MP3) using VS1053 breakoutboard & Teensy 3.1

by cebrusjki5 on Wed Nov 26, 2014 9:45 pm

Hi Galeviel!

I'm working with these boards too. I'm using the wiring they use in this tutorial.
About the SPI_CLK value, I can't tell you because I haven't done it yet xD.
As soon I put the things to work here I tell you how I did so.

cebrusjki5
 
Posts: 2
Joined: Wed Nov 26, 2014 9:14 pm

Re: Play audio (MP3) using VS1053 breakoutboard & Teensy 3.1

by paulstoffregen on Fri Nov 28, 2014 6:00 pm

There's now a MP3 decoding on Teensy 3.1, done entirely in software. It's very new, but if you're ok to trying out bleeding edge code (without a lot of nice documentation), here's the info:

http://forum.pjrc.com/threads/27059-MP3 ... #post58482

paulstoffregen
 
Posts: 431
Joined: Sun Oct 11, 2009 11:23 am
Location: Portland, Oregon, USA

Re: Play audio (MP3) using VS1053 breakoutboard & Teensy 3.1

by cebrusjki5 on Tue Dec 02, 2014 2:18 pm

I did see it, but as I could not understand the code I didn't went so far with it.

cebrusjki5
 
Posts: 2
Joined: Wed Nov 26, 2014 9:14 pm

Re: Play audio (MP3) using VS1053 breakoutboard & Teensy 3.1

by galeviel on Thu Dec 11, 2014 4:47 pm

Hi,

thx for all your replies.
I got the VS1053 up and running on the Teensy 3.1 and found the issue: the VS1053 will only work with CPU Spped of 24 MHz or below. So I don't need to fiddle around with the SPI_CLOCK_DIVx.

galeviel

galeviel
 
Posts: 4
Joined: Wed Oct 15, 2014 12:44 pm

Re: Play audio (MP3) using VS1053 breakoutboard & Teensy 3.1

by paulstoffregen on Thu Dec 11, 2014 7:06 pm

Which VS1053 library and sketch are you using?

I've added this to my list of issue to (eventually) investigate. So, imagine a perfect world where tomorrow I get a VS1053 breakout and wire it up to a Teensy 3.1.

Then what? Which library do I download, so I can recreate the problem you're seeing. Can you confirm a particular example from the library clearly reproduces the problem? Or if your particular sketch is needed, can you please post it here?

I do investigate and fix issues with libraries. Usually I spend much more time trying to recreate the problem than it takes me to actually find and fix it. Please, give me very specific details about EXACTLY what code I need to run and steps I need to take to recreate this issue? Imagine I've never used a VS1053 (actually, I never have...) so I'm coming into this absolutely cold. Help me quickly recreate the issue here, so I can investigate it.

paulstoffregen
 
Posts: 431
Joined: Sun Oct 11, 2009 11:23 am
Location: Portland, Oregon, USA

Re: Play audio (MP3) using VS1053 breakoutboard & Teensy 3.1

by galeviel on Fri Dec 12, 2014 3:52 am

Hi!

[*] VS1053 Lib used: the one provided on git-hub from the adafruit tutorial: https://github.com/adafruit/Adafruit_VS ... master.zip

[*] I tried several sketches and had the same issue with all of them: so to recreate the problem, use player_simple or player_interrupted provided in the VS1053-library

[*] wiring of the VS1053 to the teensy 3.1:

    VS1053 ==> Teensy 3.1

    3v3 ==> 3v3
    GND ==> GND
    SCLK ==> 13 (SCK)
    MISO ==> 12 (DIN)
    MOSI ==> 11 (DOUT)
    CS ==> 9
    RST ==> 8
    XDCS ==> 23
    SDCS ==> 22
    DREQ ==> 21

[*] Choose any CPU Speed above 24 MHz and you should have the issue that either you don't get any sound or in some instances accelerated distorted sound - the last one I couldn't reliably recreate.

I hope this helped to recreate the issue :) If you need any additional information, just write :)
Thank you for your time and energy :)

galeviel
 
Posts: 4
Joined: Wed Oct 15, 2014 12:44 pm

Re: Play audio (MP3) using VS1053 breakoutboard & Teensy 3.1

by paulstoffregen on Fri Dec 12, 2014 5:22 am

Thanks. That really helps. But I do need one more piece of information.

Adafruit has 3 different boards based on the VS1053, plus the raw chip. Exactly which Adafruit product are you using?

paulstoffregen
 
Posts: 431
Joined: Sun Oct 11, 2009 11:23 am
Location: Portland, Oregon, USA

Re: Play audio (MP3) using VS1053 breakoutboard & Teensy 3.1

by galeviel on Fri Dec 12, 2014 6:00 am

I got the VS1053 Audio with MicroSD breakout Version 2 as shown here: https://www.adafruit.com/product/1381
thx,
galeviel

galeviel
 
Posts: 4
Joined: Wed Oct 15, 2014 12:44 pm

Re: Play audio (MP3) using VS1053 breakoutboard & Teensy 3.1

by paulstoffregen on Fri Dec 12, 2014 7:48 am

I've got the hardware connected here. I have managed to reproduce the problem. I'm investigating now....

vs1053.jpg
vs1053.jpg (140.88 KiB) Viewed 1148 times

paulstoffregen
 
Posts: 431
Joined: Sun Oct 11, 2009 11:23 am
Location: Portland, Oregon, USA

Re: Play audio (MP3) using VS1053 breakoutboard & Teensy 3.1

by paulstoffregen on Fri Dec 12, 2014 8:25 am

Ok, it looks like there's multiple problems in play here.

The main one is poor handling of SPI clock speeds. The VS1053 uses 2 different SPI interfaces, one for control (CS pin), one for data (DCS pin). The control interface only allows very slow clock speeds. The data interface needs a faster clock.

The library configures SPI_CLOCK_DIV128 only once, in begin(). Amazingly, that tends to work, because all the config stuff is done before you call SD.begin(). The SD library then configures the clock faster. Thereafter, the VS1053 library uses whatever speed the SD library used. It's all very haphazard, to depend on the interaction of these 2 libraries reconfiguring the SPI hardware.

There's also something going wrong with musicPlayer.useInterrupt(VS1053_FILEPLAYER_TIMER0_INT). Using VS1053_FILEPLAYER_PIN_INT works great. I'm still trying to figure out why the timer isn't working...

paulstoffregen
 
Posts: 431
Joined: Sun Oct 11, 2009 11:23 am
Location: Portland, Oregon, USA

Re: Play audio (MP3) using VS1053 breakoutboard & Teensy 3.1

by paulstoffregen on Fri Dec 12, 2014 9:05 am

Ok, I've figured out the timer problem. It wasn't anything related to the actual timer.

The trouble is with feedBuffer(). It gets called from both main program and interrupt contexts. If called from an interrupt at just the wrong moment, while another copy is also running from main program context, havoc can occur. The library lacks any sort of mutex to prevent simultaneous access to the hardware!

Amazingly, AVR and 24 MHz Teensy aren't fast enough to cause this feedBuffer() to interrupt itself in really bad ways. But at 48 and 96 MHz, Teensy is able to run it a lot more from main program context, greatly increasing the odds of a conflict. I'm sure if VS1053 is used with other interrupt-based libraries on AVR, this bug could probably strike AVR users too.

Fortunately, the solution is pretty simple. I've added a flag in feedBuffer(), implementing a mutex. I also added SPI transactions, to properly manage the SPI clock speeds and keep them separate from the SD library. I did some verification with my oscilloscope, to make sure all 3 SPI devices were using their proper clock speeds. I'm listening to it now, running from a Teensy 3.1 at 96 MHz (which is plenty fast enough to do all the MP3 decoding in software, though Frank's MP3 library is still a work-in-progress)

Here's the fixed code.

https://github.com/PaulStoffregen/Adafr ... 53_Library

paulstoffregen
 
Posts: 431
Joined: Sun Oct 11, 2009 11:23 am
Location: Portland, Oregon, USA

Re: Play audio (MP3) using VS1053 breakoutboard & Teensy 3.1

by Michael_R on Mon Jan 05, 2015 10:05 pm

Paul
Is there anything special that I need to do to replace the Arduino library? I deleted the folder: \Arduino\libraries\Adafruit_VS1053 and replaced it with the contents download above. I still get the same results as before, which is basically just a digital hiss. If I set the CPU Speed to 24 MHz, it works as expected.

I have a teensy 3.1 with a Adafruit VS1053 BoB v4 breakoutboard.

Any thoughts on what I might be doing wrong?

Michael_R
 
Posts: 1
Joined: Mon Jan 05, 2015 9:45 pm

Please be positive and constructive with your questions and comments.