Shop OBEX P1 Docs P2 Docs Learn Events
having a problem with a .wav object — Parallax Forums

having a problem with a .wav object

mikeamikea Posts: 283
edited 2012-05-29 16:19 in Propeller 1
I downloaded an object for reading and playing wav files from an sd card. I haven't been able to make it work yet, and during the course of this somehow made my sd card write protected. I think when i ran the code it write protected it so i can't change anything on it from my computer.There is a format option, but this doesnt seem to cure the write protection problem. The object link is http://obex.parallax.com/objects/567/ If anyone can point me in the right direction on any of these issues i would appreciate it. It looks like this object plays back a certain file at different rates. The ideal thing for me would be to play a certain wav file based on a condition.Thanks.-mike

Comments

  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2012-05-27 21:46
    Here's a simple demo that will work with that object. Uses Parallax Serial Terminal.
    '' Simple Parallax Serial Terminal Wav Player Demo
    '' Uses WAV-Player_DACEngine.spin by Kwabena W. Agyeman
    ''
    '' The WAV-Player program can play any standard WAV file. E.g. 16/8-Bit 16000/22050/44100-Hz.  
    ''
    '' A useful tool for converting wav files to 16bit PCM is Audacity
    '' Audacity is available for Windows, Mac, GNU/Linux, and other operating systems.
    '' http://audacity.sourceforge.net/
    ''
    CON
    
      _clkmode = xtal1 + pll16x 
      _xinfreq = 5_000_000 
    
      do  = 0
      clk = 1
      di  = 2
      cs  = 3
    
      laudio = 11 ' -1 if unused.
      raudio = 10 ' -1 if unused.
      volume = 20 ' Default volume.
     
    OBJ
    
       wav : "WAV-Player_DACEngine.spin"
       pst : "Parallax Serial Terminal"
       
    VAR
    
      long spinPlayerStack[100]
      byte key
    
    PUB demo
     
      pst.start(115200)
      wav.FATEngineStart(do, clk, di, cs, -1, -1, -1, -1, -1)
      wav.DACEngineStart(laudio, raudio, volume)  
    
       repeat
        key := pst.CharIn
        pst.clear
        pst.str(@Music)
        case key
          "1":
              wav.playWAVFile(@file1) 
    
          "2":
              wav.playWAVFile(@file2) 
    
          "3":
              wav.playWAVFile(@file3) 
    
          "4":
              wav.playWAVFile(@file4) 
    
    
    
    DAT
    
    Music                   byte    "==================", 13
                            byte    " Wav Audio Player ", 13
                            byte    "==================", 13,13
                            byte    "[1] Wilhelm scream  ", 13
                            byte    "[2] Angel theme     ", 13
                            byte    "[3] Benny Hill      ", 13
                            byte    "[4] Barney Miller   ", 13,0
    
    file1                   byte    "wilhelm.wav", 0
    file2                   byte    "angel.wav", 0
    file3                   byte    "bhill.wav", 0
    file4                   byte    "bmiller.wav", 0
    
    
    {{
    
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //                                                  TERMS OF USE: MIT License
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
    // files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
    // modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
    // Software is furnished to do so, subject to the following conditions:
    //
    // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
    // Software.
    //
    // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
    // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
    // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
    // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    }}
    
  • pik33pik33 Posts: 2,397
    edited 2012-05-28 01:21
    This object worked for me from first run.

    Problems with sd can be caused by hardware. In my environment, SD card added to Propeller Demo Board sometime caused resets and other strange symptoms. After one of these resets SD card was empty, all files disappeared.

    Then I added 100 uF capacitor between vcc and vdd, soldered directly to SD slot and this solved all my problems with SD card
  • mikeamikea Posts: 283
    edited 2012-05-28 04:14
    im still struggling to get this to work. i have the prop. prof,dev,board. the four pins are connected..... do p0, sclk p1, di p2, cs p3. as in the comments, same as gangster gadget tutorial. although this object has 3.3k resistors between i/o pins and card (except vdd and vss). the card would only register without the resistors when i used code from the tutorial. the micro sd format is fat 32...32 kilobytes. ive tried combinations of other fat formats and 16 kilobytes. as well as 2 different wav programs that export the files as "pcm uncompressed 16 bit mono" im using txt to speech and saving the file name as the words spoken and substituting that file name after jeff's (from above reply) "file 1" location.when i load the program into the prop i can hear a very brief noise like the "pop"of an open mike in the earphones. also the serial terminal isnt displying anything. if anyone has ideas i would appreciate them.thanks-mike
  • mikeamikea Posts: 283
    edited 2012-05-28 05:24
    ....also the card im using is micro sdhc i dont know if the "hc" has anything to do with the problem. so far ive loaded it with wav files playable on a computer wav program. And thank you Jeff for the code, and pik33 for the info.
  • pik33pik33 Posts: 2,397
    edited 2012-05-28 08:39
    SDHC is "high capacity" >2GB card. It should work with wav player. This is Kye's driver, it can work with sdhc and fat32 - tested :) with a Propeller demo board. It works even @118 MHz clock.

    There is no resistors In my configuration. Only this 100 uF capacitor added after these stability problems.
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2012-05-28 12:01
    The specification calls for the 10k resistors.. That's interesting that the 100uF cap did the job.

    OBC
  • mikeamikea Posts: 283
    edited 2012-05-28 16:01
    Hi guys, i just tried it with the 10k resistors on pins (except 3.3, grd)...no luck. tomorrow i will get a 100 uf cap and try that. also i will try erasing these files and re-download.-mike
  • mikeamikea Posts: 283
    edited 2012-05-29 04:28
    Hi guys, still no luck! i tried the 100 mf cap between 3.3 and grd, with and without resistors on the pins. i've erased and re-downloaded the objects associated with the file from Jeffs post . I'm curiuos what size sd card others are using mine is 4 gb scandisk micro sdhc. In the read-me folder the size index only went to 2 gb, but in another location there were specs for an 8 gig sd...bigger is ok, right?

    What i am doing is just replacing "wilhelm.wav", with the file name my wav file is saved under in my laptop that i copied to the sd card "whatever.wav". Is this correct?...I feel like i'm making a simple mistake somewhere and not sure how to proceed.-mike
    DAT
    
    Music                   byte    "==================", 13
                            byte    " Wav Audio Player ", 13
                            byte    "==================", 13,13
                            byte    "[1] Wilhelm scream  ", 13
                            byte    "[2] Angel theme     ", 13
                            byte    "[3] Benny Hill      ", 13
                            byte    "[4] Barney Miller   ", 13,0
    
    file1                   byte    "wilhelm.wav", 0
    file2                   byte    "angel.wav", 0
    file3                   byte    "bhill.wav", 0
    file4                   byte    "bmiller.wav", 0
    
    
    
  • pik33pik33 Posts: 2,397
    edited 2012-05-29 04:46
    In Kye's object -

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

    there is a demo wave player program

    You have to rename your wave file to wav.wav or change this name in the code

    Try this. I use this program ( after I remove all this tempo change stuff) to play wav files.

    {{
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // WAV-Player Program
    //
    // Author: Kwabena W. Agyeman
    // Updated: 7/20/2011
    // Designed For: P8X32A
    // Version: 1.2
    //
    // Copyright (c) 2011 Kwabena W. Agyeman
    // See end of file for terms of use.
    //
    // Update History:
    //
    // v1.0 - Original release - 7/6/2011.
    // v1.1 - Tested with updated driver - 7/18/2011.
    // v1.2 - Added support for dither mode - 7/20/2011.
    //
    // Plays a WAV file over and over again at different sample rates. The WAV file is specified by its file path name string that
    // can be found in the code below. The WAV-Player program can play any standard WAV file. E.g. 16/8-Bit 16000/22050/44100-Hz.
    //
    // Nyamekye,
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    }}
    
    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.
    
    {{
    
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //                                                  TERMS OF USE: MIT License
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
    // files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
    // modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
    // Software is furnished to do so, subject to the following conditions:
    //
    // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
    // Software.
    //
    // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
    // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
    // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
    // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2012-05-29 05:13
    A couple questions from this direction...

    Are you using supported wav files? 16bit or 8bit. Note the information on this in the top of the file I posted. There is a free program to convert them.

    Also, I'm having some doubts about your SD configuration. Could you test it with another known program like Femtobasic and see if the "files" command works for you?

    OBC
  • mikeamikea Posts: 283
    edited 2012-05-29 05:19
    YES!!! I took out the resistors, and cap. Also removed pin cd-p4. It works, thank you pic33, and jeff i appreciate the help.-mike
  • mikeamikea Posts: 283
    edited 2012-05-29 05:44
    The main source of trouble was the wav file names i used were all longer than 8 letters. when i renamed the file "Wav.wav" as in the object it worked. i went up to 8 letters and it worked until i went over.-thanks again pic33, and jeff for your help-mike
  • pik33pik33 Posts: 2,397
    edited 2012-05-29 07:51
    When using this code, try to lower dither level until you get lowest possible noise. For me, 6 was the best, but I think it depends on used hardware. Overclocking can lower noise level, there is audible difference between 80 and 118 MHz clocked Propeller.
    Could you test it with another known program like Femtobasic

    FemtoBasic doesn't work with SDHC.
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2012-05-29 07:53
    @pik33

    Has anyone written a "simple", "one-trick" test program to simply display a list of files from SD using K's code?

    This would have been handy in debugging this.

    OBC
  • KyeKye Posts: 2,200
    edited 2012-05-29 07:57
    Please see http://en.wikipedia.org/wiki/8.3_filename. You cannot name files anything you want.
  • pik33pik33 Posts: 2,397
    edited 2012-05-29 08:28
    @pik33

    Has anyone written a "simple", "one-trick" test program to simply display a list of files from SD using K's code?

    This would have been handy in debugging this.

    OBC

    I have a KyeDos. I had to modify it to work with my environment - I replaced SD driver to newest version from OBEX. Its "dir" command seems to work, displaying names in 8.3 format.

    I plan to write my own code for this as soon as I finish this "VGA Nostalgia" driver which I want to use with it. First program I want to do with it is media player (sid/ym/wav) with sdhc/fat32 support - Ahle's version is written for TV driver and I am listening to these tunes without any video output and it doesn't support fat32 (it can see only a few files in it)
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2012-05-29 16:19
    I have a KyeDos. I had to modify it to work with my environment - I replaced SD driver to newest version from OBEX. Its "dir" command seems to work, displaying names in 8.3 format.

    Yes good idea, as Kye updated the driver after Kyedos was published.
    First program I want to do with it is media player (sid/ym/wav) with sdhc/fat32 support - Ahle's version is written for TV driver and I am listening to these tunes without any video output and it doesn't support fat32 (it can see only a few files in it)
    ]

    That sounds fun. Back in the olden days when memory was precious everyone compressed to .mp3. But SD cards have so much capacity now you can easily just expand your music collection back to .wav files. A media player would be cool.
Sign In or Register to comment.