Shop OBEX P1 Docs P2 Docs Learn Events
Sweetest WAV Player Yet — Parallax Forums

Sweetest WAV Player Yet

KyeKye Posts: 2,200
edited 2011-03-24 13:38 in Propeller 1
What the title says.

Attached is a working but somewhat hacked togheter WAV player that should be able to handle most WAV file types. The player actually will play anything but only regular WAV files will produce nice audio.

Just read the "HOW TO USE" file in the Zipped directory and enjoy some tunes.

What makes this WAV player really nice is th included visualization on a VGA display.

The WAV player has a built in terminal so you need to connect to it at 250_000 baud or if you open the main file you change the rate.

---

If you have any problems please tell me and I'll try to fix them for you. Enjoy!



▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,

Comments

  • Agent420Agent420 Posts: 439
    edited 2010-02-08 18:54
    Kye said...
    The player actually will play anything but only regular WAV files will produce nice audio.
    Does this mean it decodes mp3 or other encoded audio?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-02-08 19:10
    I've been working on my own version of Ray Allen's WAV player -- looking forward to seeing what you came up with.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon McPhalen
    Hollywood, CA
  • TappermanTapperman Posts: 319
    edited 2010-02-08 20:51
    Kye,
    In your setup info you asserted; - 7) Type "mount 0" to mount the 0th partition of the SD card and then you can
    play files from it. SD cards that lack a MRB will not be mounted and will fail this process. Just use another SD
    card if this is happening to you.

    Question ... How do I know when I go purchase a new card, if it lacks a MRB?
  • KyeKye Posts: 2,200
    edited 2010-02-08 22:43
    @JonnyMac - I made a generalized version of Ray Allen's WAV player so this process can be really easy for everyone with something called the DAC Engine. The file is inside the zipped DIR.

    You can play ANY wav file with my player except the ones produced by windows media player as they are not standard wav files. The amount of code needed also is reduced down to pretty much two lines in the heart of the playing loop.

    @Tapperman - If you open up disk tools in windows you should be able to format your SD card so that it has an MBR. Its usualy in administrative tools -> computer management -> disk management. You'll want to delete the volume and make a new volume most likely that can support more than one partition. Then you should be fine.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • TappermanTapperman Posts: 319
    edited 2010-02-10 18:11
    Kye said...
    @Tapperman - If you open up disk tools in windows you should be able to format your SD card so that it has an MBR. Its usualy in administrative tools -> computer management -> disk management. You'll want to delete the volume and make a new volume most likely that can support more than one partition. Then you should be fine.

    Windows says:
    1. Right-click an unallocated region of a basic disk, and then click New Partition, or right-click [url=mk:@MSITStore:C:\WINDOWS\help\diskmgmt.chm::/HELP=glossary.hlp%20TOPIC=gls_free_space]free space[/url] in an extended partition, and then click New Logical Drive.
    2. In the New Partition Wizard, click Next, click Primary partition, Extended partition, or Logical drive, and then follow the instructions on your screen.

    However, as the attachment shows ... I do not have the option on my popup menu?· I'm running XP pro

    Post Edited (Tapperman) : 2/10/2010 6:16:12 PM GMT
  • KyeKye Posts: 2,200
    edited 2010-02-11 03:54
    This one should fix your problems.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-03-01 19:25
    Kye,

    I finally had a chance to play with your WAV player. After adjusting for my demo board setup I found:

    A) works well -- thank you
    B) pops pretty loudly at the beginning (zero pop not possible, I'm sure)
    C) "whines" after WAV file ends

    #B -- I think this can be mitigated a bit (and I found this true on my setup) by writing longAdjust ($8000_0000) to frqa and frqb to before setting the dac pins to outputs.

    #C -- When the player is stopped then writing longAdjust to frqa and frqb stops the post-play whine. I added wz for the line that reads the stopped or started value, then used if_z conditionals to write longAdjust to the frqx regs when the player is stopped.

    I hope this information is helpful in improving a program that you clearly worked very hard on.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon McPhalen
    Hollywood, CA
  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-03-01 20:25
    Another little thing that I ran into: If I unmount a card and then try to remount it there is a problem -- the program spits out the copyright notice from the Propeller chip.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon McPhalen
    Hollywood, CA
  • KyeKye Posts: 2,200
    edited 2010-03-01 21:53
    JhonnyMac

    The file system driver I was using for the setup is kinda sketchy. Ignore any problems from it. I was just showing off the DAC engine features. The point of the WAV player was just to debug and get the DACEngine working.

    Also, did you conect a monitor and look at the visualization. That is one of the best features. =)

    ...

    About Audio pops and clicks. Its a waste of time and energy to try to get rid of them. The reason your trick worked is because the filter cap had already been charged to VDD/2. Your trick would not have solved the problem however when the power turns on from a cold start.

    I pretty much gave up on trying to fix the poping noises because of all of that. But I guess its kinda a glass half full thing since you managed to get rid of half the poping problems.

    ...

    Also, It shouldn't whine after the song ends. The DAC should from then on just hold the same value on the output line or play the same value over and over again. I did not have this problem. I can't say why it appeared.

    ...

    "Another little thing that I ran into: If I unmount a card and then try to remount it there is a problem -- the program spits out the copyright notice from the Propeller chip."

    No clue...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-03-01 22:56
    It's very funny how we all think our own code is "easy." What I'm trying to do now is just use your dac engine with FSRW as I'm able to detect a missing SD card with it -- that all works with Ray's original WAV code. At the moment I'm having a hard time wrapping my head around getting data from a file (using FSRW) into the dac engine.

    I don't have an external monitor so, no, I didn't try the visualizer (not important to me)

    While I know one will never completely get rid of them, the pops can be mitigated as my small change demonstrates. You're right, a hard power-up the pops will exist. In your dac engine it popped every time I reprogrammed the propeller and the program restarted -- now it doesn't. That's enough.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon McPhalen
    Hollywood, CA
  • KyeKye Posts: 2,200
    edited 2010-03-02 02:15
    The "transferData" function my friend. It the driver was designed to be really easy to get working. Whenever you see one of my drivers stop thinking hard. It will get in your way. =).

    Basically since my driver supports multiple wav formats you need to read and interpret the WAV file header. If you search for "WAV format" on google it should pop up.

    Then all you need to do is read in the settings that need to be set on the DAC engine from the WAV file and bam your ready to go.

    After that just read in the length of the rest of the WAV chunk of the file, divide that by 512 because its really easy to pass 512 bytes at a time at the fastest possible speed.

    Finally to play the WAV file·just do:

    repeat (wavchunkLength / 512)
      fread(dac.transferData, 512)
    

    And that's it pretty much it. Look at the background WAV player function in my code. It pretty much does everything you need. Note however there's alot of other stuff thrown in there for visualization. Just take it out.



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-03-02 03:17
    I think part of it is programming style -- your style is far more verbose than mine and it just takes me a moment to weed though. That, and I've got 16 other things on my plate....

    I did in fact get a new version of the background player working, but I have to double the sample rate read from the file for it to play properly. Now... I've only tested this with a 16-bit, stereo WAV file; I'm going to go get some yummy Chinese take-out to recharge my soul and my brain, then create 8- and 16-bit mono and stereo test files to run through the player.

    This is my conversion of your background routine to work with FSRW:

    pub playwav(filename) | ok, nchan, rate, bps, nbytes
    
    ' Play wave file
    ' -- pass pointer to z-string with name of file
    
      ok := sd.popen(filename, "r")
      if (ok == 0)
        ok := sd.pread(@header, 44)
        bytemove(@nchan, @header[noparse][[/noparse]22], 2)
        dac.changeNumberOfChannels(nchan)
        bytemove(@rate, @header[noparse][[/noparse]24], 4)
        dac.changeSampleRate(rate << 1)                             ' ? forced to double sample rate
        bytemove(@bps, @header[noparse][[/noparse]34], 2)  
        dac.changeBitsPerSample(bps)
        dac.changeSampleSign(bps == 16)
        dac.changeLeftChannelVolume(leftVolume)       
        dac.changeRightChannelVolume(rightVolume) 
        bytemove(@nbytes, @header[noparse][[/noparse]40], 4)
        dac.startPlayer
        ledmode(2)
    
        ' stream data to buffer
        '
        repeat (nbytes / 512)
          sd.pread(dac.transferData, 512) 
          
        dac.stopPlayer
        dac.clearData  
        sd.pclose
        ledmode(1)
           
      else
        playstatus := -1
      
      wavcog := 0
      cogstop(cogid)
    



    Again, my style differs a bit from yours in that I minimize compound expressions.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon McPhalen
    Hollywood, CA
  • KyeKye Posts: 2,200
    edited 2010-03-02 04:23
    Mmm, I plan to add the ability to read shorts and longs my next version of my driver.

    Everything looks right. Make sure your source files have the correct header data if you are having problems. Also, if you had to double the sample rate to make it play correctly I would look at the code that is used to set the number of channels... It might be getting set incorrectly.

    I've very sure the DAC engine works correctly unless your ASM modifications changed how it worked. You should also look in there and arround what you channged.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-03-02 04:47
    The file is not a problem -- has correct header information.

    My additions to the dacengine are extremely minor and not in the play section -- the only thing I did was set the output to zero when the player is stopped (this minimizes pop and stopped the whining).

    The code above is as close to a direct translation for using FSWR as I could think of; if you compare it to your program it follows the process step-for-step. One very small difference is that I'm reading the entire header at once and then pulling values from that array.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon McPhalen
    Hollywood, CA
  • KyeKye Posts: 2,200
    edited 2010-03-02 06:01
    Good Hunting then!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • DonEduardoDonEduardo Posts: 54
    edited 2010-03-12 21:24
    Hey Jon, could you post the code changes you made to get out the pops and also the whine at the end? You have an English description above but I don't know assembly and can't figure out how to do what you said. Thanks.

    Works pretty nice otherwise. Thanks Kye!
  • KyeKye Posts: 2,200
    edited 2010-03-12 21:30
    I updated the driver in the obex to include what JonnyMac did. You can just download the new version.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • DonEduardoDonEduardo Posts: 54
    edited 2010-03-12 21:41
    SWEET!! Thanks. Worked great.
  • JAGOJAGO Posts: 49
    edited 2011-03-24 09:31
    Hi Kye

    i'm trying with your wavplayer but i can't do it work.... i think that is the format of SD card because i don't understand what do you say with MBR partition.. and i try with the instruction but don't appears the options i'm working with XP... can you help me please..

    Many thanks..
  • KyeKye Posts: 2,200
    edited 2011-03-24 12:30
    JAGO - There are many things that can go wrong in making the WAV player not work. You'll need to give me a detailed description of your setup.
  • JAGOJAGO Posts: 49
    edited 2011-03-24 12:44
    Hi kye,

    I'm using the demo board and i modify the pins in the com object, dac object and fat engine.... and execute the main code then conect with the terminal and use the comands that you indicates in the .txt file... first mount the SD with "mount 0" comand then type the "ls" comand for view the files and then type the "play" comand to execute the wav file but the sound play about 2 seconds and desappears.... i dont know what is wrong...

    amny thanks...
  • RaymanRayman Posts: 14,877
    edited 2011-03-24 12:47
    Just my usual suspect...

    Are you using by any chance a serial communicaitons object on pins 30&31 and not having the USB cable connected to a PC?
  • JAGOJAGO Posts: 49
    edited 2011-03-24 13:15
    i'm conected to PC, the demo board have and i have total comunication because i can send all comands and i have responses..
  • RaymanRayman Posts: 14,877
    edited 2011-03-24 13:38
    In that case, you should listen to Kye... Maybe posting your code would help him...
Sign In or Register to comment.