Shop OBEX P1 Docs P2 Docs Learn Events
Playing Music — Parallax Forums

Playing Music

AndroidAndroid Posts: 82
edited 2013-04-10 12:10 in Propeller 1
So I already get the piezospeaker and how to do that, but was wondering if there's an easy way to directly upload lets say an itunes song to the propeller and have it play through whatever is hooked up to the earphone jack. Thanks in advance!
-Android

Comments

  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2013-04-08 18:00
    There are a couple ways to accomplish this..

    First, you can use the Propeller itself to create reasonable .wav file playback. It won't be "music listening" quality, but is reasonable enough for simple audio playback and only requires the Propeller and a connected SD card. (One of these players can be found here: http://forums.parallax.com/showthread.php/99726-Ray-s-ASM-Wav-Player)

    Secondly, you can incorporate an outside MP3, (or cheaper .OGG) playback chip/circuit which would connect and be controlled by the Propeller.
    (An example of this can be found here: http://www.instructables.com/id/Building-an-OGG-Player-using-the-Pocket-Mini-Comp/)

    Jeff
  • AndroidAndroid Posts: 82
    edited 2013-04-08 18:14
    Jeff,
    How do I use the WAV file player do you just attach SD card with the music on it? Does the propeller have a port for SD?
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2013-04-08 18:22
    I'll see if I can round up an existing tutorial on this.. surely we have one posted somewhere on this don't we gang?
    Android wrote: »
    Jeff,
    How do I use the WAV file player do you just attach SD card with the music on it? Does the propeller have a port for SD?
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2013-04-08 18:35
    How do I use the WAV file player do you just attach SD card with the music on it? Does the propeller have a port for SD?

    Not a port as such. An SD card needs 4 pins connected and you just connect those to 4 pins on the propeller, then in software tell the program which 4 pins you chose. For hardware you will need an SD socket, and four 10k resistors. For the audio side, you need one headphone socket, two capacitors and two resistors. Pick two propeller pins for audio output and then tell the software which two pins you chose.

    There is code around to read .wav files and to play them. It is pretty easy to convert .mp3 to .wav - lots of free converters on the internet including some online ones.

    The code you will need to write is only a few lines, as most of the work is already done.
  • AndroidAndroid Posts: 82
    edited 2013-04-08 18:40
    How do i connect those pins to the propeller?
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2013-04-08 18:49
    Lots of ways. Solder. Breadboard. Premade SD modules. Make your own PCB. Buy a development board from parallax with a propeller chip and a breadboard and SD socket.

    Ok, how I do it is I buy SD sockets on ebay at a good price, and then I measure up the spacing on the socket, design my own part on Eagle PCB and get a board made. I like to use the large SD sockets as they are easier to solder. Once you have a propeller chip running with the regulated supply etc, total cost to get music playing might be a dollar or so for the SD socket, and maybe 50c for the resistors and capacitors.

    But... there are much simpler ways than that. eg premade SD boards http://www.futurlec.com/Mini_SC.shtml and there are cheaper ones on ebay if you look around. They bring out the SD pins to header pins and you can fit a board like that into a Breadboard http://www.futurlec.com/Breadboards.shtml along with the propeller chip and then you don't need to do any soldering.

    BTW re sound quality, if you start off with a good .mp3 file and use decent headphones, it sounds very good.

    Even better, there may well be premade boards around that have an SD socket and the audio components. Others should chime in soon with advice. http://www.parallax.com/Store/Microcontrollers/PropellerDevelopmentBoards/tabid/514/List/0/CategoryID/73/Level/a/SortField/0/Default.aspx

    As a general question, at what level would your electronics skills be?
  • AndroidAndroid Posts: 82
    edited 2013-04-08 18:57
    Out of 10... 4 or 5. I need to do some work on that...:innocent:
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2013-04-08 19:03
    ok, in that case a premade board would be better. The audio part is pretty easy. Anyone can solder capacitors and resistors, or plug them into a breadboard. The SD socket can be a bit tricky to solder so ideally we need a board with an SD socket on it.

    Off to the parallax store to rummage around...
  • AndroidAndroid Posts: 82
    edited 2013-04-08 19:03
    Is there any way to just hook it up to prop BOE's breadboard?
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2013-04-08 19:08
    How about this board http://www.parallax.com/Store/Microcontrollers/PropellerDevelopmentBoards/tabid/514/CategoryID/73/List/0/SortField/0/Level/a/ProductID/802/Default.aspx

    All the hardware is already done - it has audio out and an SD socket, plus lots of other goodies.

    Ok, it is $129, but you don't need to solder anything.

    Or at the other extreme - buy an individual propeller chip for $8, and have fun soldering or using a breadboard. You could do this with another $3 worth of components.
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2013-04-08 19:09
    oops, cross post.

    If you already have a BOE, then this might just be a software problem...

    BOE has a stereo socket and an SD card. Let's check the schematic....
  • AndroidAndroid Posts: 82
    edited 2013-04-08 19:13
    It has a built in SD chip!!!! That is awesome......:thumb:
  • AndroidAndroid Posts: 82
    edited 2013-04-08 19:15
    Then do I just upload the music to the SD card and then upload the program?
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2013-04-08 19:35
    It may indeed be that simple!

    I need to find the schematic. The .jpg photo is a bit blurry but I think the SD is pins 22-25 and the audio out is 26 and 27. So those values will go into the program. I'd like to double check that though.

    Re software, I think there is something in the obex written by Kye that does almost everything you want.
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2013-04-08 20:01
    Schematic is here - multiple sheets. http://www.parallax.com/Portals/0/Downloads/docs/prod/prop/32900_PropBOE_RevA_Schematic.pdf

    Looks like audio is P26 and 27 so that will be easy.

    SD is CS=25, MOSI is 24 (DI), CLK is 23 and MISO (DO) is 22.

    Ok, hardware all sorted. Now for software...
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2013-04-08 20:07
    This is probably the easiest object.

    http://obex.parallax.com/objects/567/

    I can't believe one of use hasn't done a step-by-step for this yet. (Just added to my list)

    Jeff
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2013-04-08 20:10
    Post edit: Double post with OBC. We are on a roll here!

    Take a look at this wav player - has the SD card and the wav player as part of the same package http://obex.parallax.com/objects/567/
    CON
    
      _clkmode = xtal1 + pll16x ' The clkfreq is 80MHz.
      _xinfreq = 5_000_000 ' Demo board compatible.
    
      _dopin = 0
      _clkpin = 1
      _dipin = 2
      _cspin = 3
      _cdpin = 4 ' -1 if unused.
      _wppin = 5 ' -1 if unused.
    
      _rtcres1 = -1 ' -1 always.
      _rtcres2 = -1 ' -1 always.
      _rtcres3 = -1 ' -1 always.
    
      _lpin = 11 ' -1 if unused.
      _rpin = 10 ' -1 if unused.
    
      _volume = 10 ' Default volume.
    
      _ditherEnable = true ' "true" or "false" please.
      _ditherLevel = 4 ' 0 = Most Dither ... 31 = Least Dither.
      
    OBJ dac: "WAV-Player_DACEngine.spin"
    
    VAR long spinPlayerStack[100]
    
    PUB demo
    
      dac.FATEngineStart(_dopin, _clkpin, _dipin, _cspin, _wppin, _cdpin, _rtcres1, _rtcres2, _rtcres3)
      dac.DACEngineStart(constant(_lpin | (not(not(_ditherEnable)))), constant(_rpin | (not(not(_ditherEnable)))), _volume)
    
      ' Above Never fail - no need to check return value.    
      
      if(_ditherEnable)
        dac.DACDitherEngineStart(_lpin, _rpin, _ditherLevel) ' Never fails - no need to check return value.
      
      cognew(spinPlayer, @spinPlayerStack) ' Startup separate process.
    
      repeat ' Repeat forever.
        repeat until(dac.wavePlayerState) ' Wait until start.
        
        repeat until(dac.fileSamplePosition > (dac.fileSampleNumber / 3)) ' Wait until 1/3rds in.
        dac.fileSampleRateSetup((dac.fileSampleRate * 4) / 3) ' Sample rate set to 4/3rds the original.
    
        repeat until(dac.fileSamplePosition > ((dac.fileSampleNumber / 3) * 2)) ' Wait until 2/3rds in.
        dac.fileSampleRateSetup((dac.fileSampleRate * 3) / 4) ' Sample rate set to 3/4ths the original.
    
        repeat while(dac.wavePlayerState) ' Wait until stop. 
    
    PUB spinPlayer ' Plays a WAV file over and over again.
    
      repeat ' Forever
        dac.playWAVFile(string("WAV.wav")) ' Supports WAV files up to ~2GB.
    

    ok so change the dopin from 0 to 22, clk pin from 1 to 23, di pin from 2 to 24 and cs pin from 3 to 25. Make cdpin and wppin both -1 as they are not used.

    Change the audio pins from 10 to 26, and 11 to 27.

    The default filename to play is "wav.wav" so find any .wav file, rename it to that and put it on the sd card. If that works, have fun converting other .mp3 files to .wav and playing them
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2013-04-08 21:03
    IIRC, you'll need to downsample your wav files. I've used the free program Audacity (http://audacity.sourceforge.net/) to do this in the past.

    Jeff
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2013-04-08 21:27
    Convert your files to 16bit PCM as shown in the image.

    click_pic_wav.png


    Then choose, File and Export to save them at Microsoft 16bit PCM format.

    Jeff
    783 x 627 - 52K
  • skylightskylight Posts: 1,915
    edited 2013-04-09 04:20
    I'm using the ASM Wav Player and I have to say the quality is excellent through headphones.
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2013-04-09 07:05
    I agree re the quality. Kye's driver also sounds excellent through headphones. Initially tested with some Rammstein, but then re-tested with Bach's Brandenburg Concerto. Classical music really sorts out quality - larger dynamic range, no distortion in the instruments etc.

    I've had professional music teachers comment on how good the quality is.

    Search for online mp3 wav will find various online converters. Just copy the resulting .wav to the sd card.

    I'd be interested to hear how our original poster is going.
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2013-04-10 08:11
    Hey Android, How are you making out on this project?

    Jeff
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-04-10 10:21
    I haven't done this yet myself, but it should be possible to record sounds directly to the uSD using the PropBOE's microphone.

    Besides writing a nice wav player, Kye also wrote a wav recorder. I'm off to find a link. I'll edit this post when I find it. (I bet I have it listed in my index somewhere.) Here it is (it was listed in post #5 of my index).

    So, if you wanted really poor quality music, record the music directly with the PropBOE. I'd be surprised if this sounded any good though. I think the record feature is better used with normal human speech.

    BTW, There are lots of other ways of playing music with a Propeller. Ahle2 has some cool retro music players. I think Jeff has some tutorials on using his stuff. The Propeller can also play MIDI files. A lot of digital pianos will output MIDI files from the notes played on it. There are lots of songs which have been converted to MIDI. I wont go into the advantages of MIDI here but it allows songs to be captured with very little memory.

    You might want to take a look at the Scribbler 2's GUI. I use it generate sounds to be played back on the Propeller later. It also has a lot of nice beeps an other robot noises. It might take a bit of figuring to know how to play them back on a Propeller other the S2's built in sound circuit, but I don't think it would be very hard.
  • pik33pik33 Posts: 2,366
    edited 2013-04-10 11:46
    Some time ago I started to make a player. Now, studying for PhD degree, I have no time for this, but here you can find it:

    http://forums.parallax.com/showthread.php/140767-A-new-topic-for-vga-%28not-only%29-sid-player?highlight=propplay

    Compile this with BST/unused method removal, else it doesn't fit in 32k... :(
  • WBA ConsultingWBA Consulting Posts: 2,934
    edited 2013-04-10 12:10
    Been keeping an eye on this thread as it is fueling solutions for my PROP-DAR project. (Digital Audio Recorder for recording radio programs for later listening) I found some RTC help from this thread as well.
Sign In or Register to comment.