Shop OBEX P1 Docs P2 Docs Learn Events
Reading from an SD card and Decoding mp3 files — Parallax Forums

Reading from an SD card and Decoding mp3 files

ejwongejwong Posts: 21
edited 2011-08-24 10:52 in General Discussion
first of all, i just registered... well you know what that means.

my dad bought propeller and it looks interesting. so, as the title says, is it possible to read an SD card using propeller? and how do you program propeller to decode mp3 files from the SD card?

if theres an existing topic about this out there would you kindly link it? =P

Comments

  • Ken GraceyKen Gracey Posts: 7,387
    edited 2011-08-23 09:08
    ejwong, welcome to the forums! Finally, I was faster than the other members of the welcome committee.

    I've seen two *.wav examples but none for *.mp3. One is from http://forums.parallax.com/showthread.php?123900-EFX-TEK-shows-the-Propeller-AP-16-WAV-Audio-Player-at-Parallax-wow! - I'm pretty certain the code for this board is available for download on the product page. Also, Kwabena made a fantastic demo this summer at Parallax which played back wav files. Kye's code should be posted somewhere in these forums, but I just did a quick search and couldn't find it. The forum has many members who will be quite familiar with his examples and may direct you to their location.

    Ken Gracey
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2011-08-23 09:20
    @ejwong: Welcome to the forums! Without adding an MP3 decoding chip of some sort, you'll be playing .wav files with your Propeller.

    @KenG: China makes CHEAP MP3 players, and yet all of the MP3 kits I've seen are expensive. If Parallax could add a sub $20 MP3 module to it's line up it would be a real hit!

    OBC
  • ejwongejwong Posts: 21
    edited 2011-08-23 09:24
    ^ more like a decoding technique/code to decode mp3(maybe flac too) just for propeller, that`ll be a revolution, you`ll see diy kits under 30$ to make your own mp3 player? sweet deal~ you`ll be able to program the features you want XD
  • namochannamochan Posts: 7
    edited 2011-08-23 09:34
    This is how I wired my SD-Card:
    sd-pinout.PNG

    ( ) = is how I'd wire it next time.
    802 x 597 - 749K
  • ejwongejwong Posts: 21
    edited 2011-08-23 09:49
    thanks! wait... what about the 8th pin? no connection in particular?
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2011-08-23 09:53
  • Mike GreenMike Green Posts: 23,101
    edited 2011-08-23 09:58
    MP3 decoding is relatively complex and computationally intensive. See the Wikipedia's article on MP3 for links to details. In addition, there are several patents on the technique and the patent holders have a history of vigorously defending their patents and charging licensing fees for their use. The only compressed sound codec that seems to be "patent-free" is Ogg/Vorbis (see the Wikipedia article on this). I'm sure it's possible to translate the existing Linux decoder for MP3 into C and compile it with Catalina, but I doubt you could get anywhere near adequate performance on a Propeller.

    SparkFun has some nice MP3 decoder modules that could be used with a Propeller.
  • ejwongejwong Posts: 21
    edited 2011-08-23 10:07
    ohh... well, dedicating a whole COG or two should be able to decode mp3s but sadly, as you mentioned, the decoding technique maker is stingy...

    another question, whats the max SD capacity that the propeller can detect? hopefully it can detect 16gb SD?

    Edit: how about using this? http://lame.sourceforge.net/index.php
  • ejwongejwong Posts: 21
    edited 2011-08-24 07:52
    sorry for the bump... as no one answered the questions yet...
    another question, whats the max SD capacity that the propeller can detect? hopefully it can detect 16gb SD?

    Edit: how about using this? http://lame.sourceforge.net/index.php
    adding another set of questions:
    how much watts does the parallax chip consume in average and peak? P8X32A to be more precise.

    how much volts and current can the outputs release? in watts as well, wouldn't wanna burn my chip now would i?

    is it possible to program it to react to analog inputs? i mean programming the controls to react by voltage difference so i`d need only one pin to perform as a control input. to give you a vague example, 1.1volts = turn on LED1, 1.2volts = turn off LED1, 1.3volts = turn on LED2, and so on.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-08-24 08:57
    A lot of the existing software uses SD card drivers that are limited to 2GB (FAT16 format) SD cards. The latest version of Rokicki's and Kye's I/O driver object both accept FAT32 SD cards. These should work with a 16GB card. Kye's driver is the only one that supports subdirectories which you really need for cards that large.

    Download and read the Propeller Datasheet. It has a variety of graphs that characterize the Propeller's current drain (thus power drain) under different circumstances. The datasheet also defines how much current the outputs can provide

    The Propeller can perform Sigma-Delta Analog to Digital conversions. Download and look at the Application Note AN001. It requires the use of two I/O pins as well as two resistors and two capacitors mounted close to the chip. For simple voltage dependent control, you could use something like the RCTIME technique described in the "app notes" section of this website. The description is for the Basic Stamps, but the same technique can be used with the Propeller. There are sample RCTIME routines in the BS2 Functions object in the Propeller Object Exchange.

    Sure, LAME is an MP3 decoder. The problem is getting adequate performance (speed and code size). You're not going to get adequate speed just compiling it. It would have to be translated into assembly for speed. It's not at all clear that the algorithms would fit into the available memory.

    You're welcome to give it a try, but, from the experience with getting quality audio from WAV files on an SD card, that's enough of a challenge. Look at EFX-TEK's AP-16+ for an example of this.
  • ejwongejwong Posts: 21
    edited 2011-08-24 09:13
    thanks for the input, gladly appreciated the datasheet, been trying to find it on the box but couldnt find it.

    yea the speed is an issue... but didnt know getting quality output was that hard o.o hmmm, what about decoding the file into digital and feeding it into a DAC? that should eliminate most of the noise.
  • DonEduardoDonEduardo Posts: 54
    edited 2011-08-24 09:25
    @OBC: yeah, I bought a car MP3 player that had an LCD screen, SD card slot, USB slot, an FM radio transmitter, and remote control for about $8. Stick in some media, and it plays all the MP3 songs. I hacked it apart. It had a single chip (except for the FM transmitter) that handled everything. I couldn't find any documentation on the chip. I figured there must be a way to hack this guy to play what we want. The only way I could figure out how to play select songs was to use the remote control. Type in a number, and it would play that song (I guess based on where it was in the file directory). I've been using the wav players mentioned above and they do the trick very well, but yeah, I've always wondered why we can't get a cheaper MP3 trigger board. Mike's response above does help explain, patent rights.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-08-24 09:29
    Have you actually looked at the LAME decoder? It's quite large and it uses floating point. How are you going to fit even a portion of all that code into one or more cogs with at most 496 instructions? The main (hub / shared) memory is only 32K bytes and quite a hunk of that would need to be used for the SD card I/O including the FAT16/32 file system code. Floating point is done in software and that would take at least one cog plus code space. Even multiplication and division have to be done in software. There are techniques for using external RAM for storing code and/or data, but these all come with a significant hit in terms of execution speed since you'd actually be running an interpreter in native code along with caching routines to speed up virtual memory access.
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2011-08-24 09:41
    This seems like a perfect opportunity to beat the drum again for an MP3/MIDI accessory board. The VS1053 chip combines both, requires few external parts, is properly licensed, etc. The Sparkfun boards are good examples of what can be done. I have several variations of them, and they're inexpensive and fun.

    I've mentioned this in previous posts, but if Parallax were to do an MP3/MIDI board I recommend putting a small 1W amplifier on it, in addition to providing the earphone capability. A buffered line out would be a plus. The SF boards don't have the amp or buffered line out.

    LAME isn't a licensed variation of MP3 (legitimate users of LAME obtain the MP3 licensing separately), so it's hardly practical for Parallax to recommend or demonstrate its use in a Parallax product, even if it were technically possible.

    -- Gordon
  • ejwongejwong Posts: 21
    edited 2011-08-24 10:36
    i`m starting to love you guys =P

    well yea, allocating a whole prop for just LAME would be a good idea wouldn't it? then i`ll need two props to run the whole thing... yea i know its costy, and impractical as theres a couple of decent mp3 player out there for under 10$ BUT the big profit on this is the learning part, plus developing an effective way to decode mp3.

    a rough idea i came up with, is to use one COG to decode the file to split the channels and allocate one COG per channel. this should give it a little more room to decode the mp3.

    Edit: ahh... no i havent tried LAME yet... i still have to find a powersupply to powerup my starter kit...
  • rod1963rod1963 Posts: 752
    edited 2011-08-24 10:52
    Looking at LAME, it's certainly a non-trivial port to the Prop and then factoring in you have to integrate with SD card I/O code makes it even more complicated. Then there is the performance issue.

    You'd certainly need at the very least one extended memory Prop boards that some of the posters sell.

    Better off letting Sparkfun's MP3 board do all the heavy lifting and letting the Prop handle the human I/O stuff.
Sign In or Register to comment.