Shop OBEX P1 Docs P2 Docs Learn Events
Ray's ASM Wav Player — Parallax Forums

Ray's ASM Wav Player

RaymanRayman Posts: 14,826
edited 2013-02-14 17:18 in Propeller 1
Update (Feb 2013): I finally got around to fixing this up... Here's the new version:
Attachment not found.


I wasn't particulary pleased with my previous mono, 16ksps SPIN WAV player...

I just converted it to ASM (on my lunch break) and now it does up to 48 ksps in stereo!

Songs must be 16-bit PCM stereo WAV.

Downside is that full songs are now very big!· I can only upload 10 second clips here...

Post Edited (Rayman) : 12/21/2007 1:26:48 PM GMT
«1

Comments

  • BTXBTX Posts: 674
    edited 2007-12-18 19:22
    Now my new custom is: "wait for what will Rayman·do now" ??

    Great job guy !!!
    Congratulations.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Regards.

    Alberto.
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2007-12-18 22:08
    Kudos Ray!!

    Nice work indeed!

    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    New to the Propeller?

    Getting started with the Protoboard? - Propeller Cookbook
    Got an SD card? - PropDOS
    A Living Propeller FAQ - The Propeller Wiki
    (Got the Knowledge? Got a Moment? Add something today!)

  • OzStampOzStamp Posts: 377
    edited 2007-12-18 22:20
    Hey Rayman..
    How long are your lunch breaks ??
    Well done ..

    cheers Ron Melbourne OZ
  • kittmasterkittmaster Posts: 77
    edited 2007-12-18 23:09
    make it play mp3's and you'll have a true winner
  • ToleyToley Posts: 16
    edited 2007-12-18 23:15
    Wowww what a great project.

    If Elvis was the king of twist, Rayman is probably the king of Spin!!! lol.gif
  • RaymanRayman Posts: 14,826
    edited 2007-12-19 13:38
    I found some adaptable C code for MP3 decoding, but I'm not sure the Prop is fast enough to do it real time...
  • ToleyToley Posts: 16
    edited 2007-12-19 14:05
    MP3 decoding would be awsome. If the propeller can't do it, it could be make with a VS1011 or a STA015. I'm new to the propeller so my programming skill is not good enough to do this myself for now sad.gif .

    By the way do you expect to make a keyboard routine for changing song, play pause etc...
  • kittmasterkittmaster Posts: 77
    edited 2007-12-19 14:10
    If the thing is running at 80Mhz, the upper sample rates are 44.1 Khz with 128Kbps streams, I would think one cog could pass the data in, one to process, the other to output.......no?
  • aempireiaempirei Posts: 6
    edited 2007-12-19 20:01
    i was working on the exact same thing last night from your first piece of spin code!!! i posted my mods and then realized you just posted yours!
  • RaymanRayman Posts: 14,826
    edited 2007-12-19 22:28
    I hope you're working on MP3 playback next smile.gif!
    ·
  • ClemensClemens Posts: 236
    edited 2007-12-20 23:20
    Thank you so much, Ray. Just played back a 4 Minutes 40MB Song with crisp sound and no glitches! Wow!
  • RaymanRayman Posts: 14,826
    edited 2007-12-21 00:39
    Thanks for trying it! One thing that bothers me a bit is the pop when it first starts. Many players do this actually... I think it is due to the analog output going from 0 to 50%. I'm contemplating how to gently force the output to 50% before starting....
  • BTXBTX Posts: 674
    edited 2007-12-21 01:11
    Ray.

    Maybe doing it,· 0 to 50% with a smooth ramp ?



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Regards.

    Alberto.
  • toru173toru173 Posts: 17
    edited 2007-12-21 03:17
    For mp3 playback there's the libmad project. It uses purely integer maths to decode the mp3 stream, and it has a freely availible source. It may be possible to use some of the low level maths involved here in a prop-based mp3 decode algorithm.
  • Forest GodfreyForest Godfrey Posts: 38
    edited 2007-12-21 06:24
    Wow, this is fantastic! I'm building an 8 channel audio playback system using the Prop for some of my theater work (I sound design a lot) and this may allow me to not have to have 8 external DAC's.

    So, your code is likely to be "coming soon to a theater near you" (if you're near Minneapolis...)

    One minor bug that bit me - You define the output pins twice, and or the two together. They are defined in OPinL and OPinR, but they're also in the low 6 bits of CountModeR/L.

    Again, this is fantastic! I'll probably sound better when I add the resistor and the two caps.
  • RaymanRayman Posts: 14,826
    edited 2007-12-21 13:14
    toru: That's the one I was looking at... I took a peek at http://coolplayer.sourceforge.net/ which is based on MAD. I looks doable, just don't know if it can be done in real time...
  • RaymanRayman Posts: 14,826
    edited 2007-12-21 13:24
    Forest:· Definitely a bug...· Thanks for pointing that out!· Here's a revised version:

    Also, it's very possible that I have left and right channels reversed.· If anybody figures this out, pls let me know...
  • toru173toru173 Posts: 17
    edited 2007-12-22 11:56
    Rayman: it may not be possible to do in realtime with one cog. Perhaps there could be two options - using many cogs (each decoding a frame, essentially pipelining it) to get real-time playback, or have the ability and memory to decode an MP3 to a WAV file, store the WAV to some memory medium, play it back once sufficient "buffering" is availbile and delete the decoded file once it's done?

    The former requires many cogs, the latter a lot of memory. However, I think both would have their place.
  • Ym2413aYm2413a Posts: 630
    edited 2007-12-23 04:46
    MP3 sure would be awesome. [noparse]:)[/noparse]
    Might be quite a bit of work though to get it up and running on the Prop.

    I like Rayman's WAV player. It should work in most places where MP3 would be used.
    MP3 would only be good for if you wanna load a SD card with a lot of audio or something.
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2007-12-23 04:58
    I'm becoming increasingly convinced that there isn't much the Propeller can't do.


    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    New to the Propeller?

    Getting started with the Protoboard? - Propeller Cookbook
    Got an SD card? - PropDOS
    A Living Propeller FAQ - The Propeller Wiki
    (Got the Knowledge? Got a Moment? Add something today!)

  • deSilvadeSilva Posts: 2,967
    edited 2007-12-23 08:35
    I could direct you to the basic works of Alan Turing smile.gif
    Consider: You can reach many places on earth afoot and in a canoe... But it is a minority making it their living to prove this...
  • TheWizard65TheWizard65 Posts: 91
    edited 2007-12-24 00:40
    Nice Job Ray, I just downloaded your wav files. Can't wait to try them out jumpin.giffreaked.gifhop.gifroll.gifyeah.gif
  • DelusDelus Posts: 79
    edited 2009-03-20 16:52
    I know it's been a year since anyone has posted to this topic but there is one small bug i've found in this and the WAV player in the object exchange with a very simple fix.· Though i don't know much about the data I tampered with i haven't noticed any problems since the change and it now plays the Mario Brothers Over World wav i've been playing with correctly.
    the problem is were the spin code loads the wave file it checks for buff[noparse][[/noparse]n] ==0 but this is some times set to 0 by the read it's self causing it to overrite the buffer on the next itteration of the loop.

    [noparse][[/noparse]code]
    repeat while (j==buffsize*4)· 'repeat until end of file
    ··· if (buff1[noparse][[/noparse]n]==0)
    ····· j:=sd.pread(@buff1, buffSize*4) 'read data words to input stereo buffer
    ··· if (buff2[noparse][[/noparse]n]==0)
    ····· j:=sd.pread(@buff2, buffSize*4) 'read data words to input stereo buffer
    [noparse][[/noparse]/code]

    My Fix

    [noparse][[/noparse]code]
    repeat while (j==buffsize*4)· 'repeat until end of file
    ··· if (buff1[noparse][[/noparse]n]==0)
    ····· j:=sd.pread(@buff1, buffSize*4) 'read data words to input stereo buffer
    ····· if(buff1[noparse][[/noparse]n]==0)
    ······· buff1[noparse][[/noparse]n]:=1
    ··· if (buff2[noparse][[/noparse]n]==0)
    ····· j:=sd.pread(@buff2, buffSize*4) 'read data words to input stereo buffer
    ····· if (buff2[noparse][[/noparse]n]==0)
    ······· buff2[noparse][[/noparse]n]:=1
    [noparse][[/noparse]/code]

    Atached is my slightly altered version of PlayWav_16bitSreteo.spin from the object exchange.· one other thing to note is I changed the first part of the asm code so as not to break anything if·I accidentaly changed the order of the initialized variables.· It should still do what it's supposed to.

    David
  • RaymanRayman Posts: 14,826
    edited 2009-03-20 17:56
    Thanks for pointing that out and offering a fix.· I was aware of the potential for a problem, but I didn't think it would happen in practice...· I think this can only happen if a song is overly amplified so that it "hits the rails", so to speak...

    But, it's been a while...· I'll have to re-examine this to see if "0" corresponds to the middle of the range or an extreme of the range...



    Post Edited (Rayman) : 3/20/2009 6:02:43 PM GMT
  • RaymanRayman Posts: 14,826
    edited 2009-03-20 18:07
    On second thought, I think it is a good idea to fix this issue to avoid any possible problem... I'll try to find time to fix the OBEX version with your idea, or something similar.
  • DelusDelus Posts: 79
    edited 2009-03-20 19:02
    The file I've been using was converted from a midi file and the difference between the two versions of code is very noticable.· But it's a great player and with the four added lines of code works wonerfully.· Here's the·smallest .wav file·I've been using, if your interested.
  • RaymanRayman Posts: 14,826
    edited 2009-03-20 21:15
    Ok, I took a close look at that wav file and it doesn't go to extremes, but it spends a lot of time at exactly midrange...
    So, I would have to guess that a zero value means midrange. I would further guess that most files wouldn't stay at exactly zero for long due to noise at least, but because this was computer generated it does...

    Anyway, the player definitely needs to be fixed! I'll add your code (if you don't mind) or something equivalent soon...
  • DelusDelus Posts: 79
    edited 2009-03-25 16:11
    Sorry for not gatting back untill now...scrambling to get the software working for a laser harp project (hence the interest in your code). no i don't mind at all if you use my code. It's only four lines after all.
  • RaymanRayman Posts: 14,826
    edited 2009-03-25 16:51
    I think maybe a more pure fix would be to increase the buffer sizes by one and use the first element in the buffer as the empty flag.

    But, you're fix is also fine as the change in output is trivial. But, it doesn't change a 0 to a 1 until after the buffer is filled. This is a potential problem if the buffer is being read as it is being filled. But, you say you've tested it already and found it to work. Still, that could be a problem if the buffer size is reduced...
  • DelusDelus Posts: 79
    edited 2009-03-25 21:24
    I'm working on my own wav player which uses a separate varialbe for handling filling the buffer. So far I'm having great success at reducing the high pich noise in the back ground. My curent version seems to be twice as loud as yours but I'll have to make sure this isn't a mistake that will lead to chopping off the extreems. As the basic player will be for synthisizing notes we've decided to reduce it to 9 bits inorder to generate frequencies all the way up to 20K but it still plays 16 bit waves, it just ignore's the lower ones. Currently filling the buffers is hard wired for a specific song, but i will post my code once I clean it up and test it with a few more songs with different sampling rates.
Sign In or Register to comment.