Shop OBEX P1 Docs P2 Docs Learn Events
wav_play Issues - Limited Play Times — Parallax Forums

wav_play Issues - Limited Play Times

BTL24BTL24 Posts: 54
edited 2013-10-12 17:00 in Propeller 1
I am attempting to have a wav file play over and over again... indefinitely (until I stop program), but am having issues as it only plays 5 times then stops.

When I utilize the wav_play function as shown in the code below, the wav file "yay" only plays 5 times... then goes silent. The code continues to run as evidenced in the serial terminal. If I reload the program, it will play 5 times again.. then stop again.

FYI...I am running code on the Prop Activity board through the simple IDE. The Yay.wav file is from the Parallax tutorials.

Is there an issue that the wav_play function keeps opening new cogs... then eventually runs out? Am I exceeding a stack somewhere? Any help would be appreciated.

Regards,
Brian
/*
  Test WAV Volume (10).c
*/

#include "simpletools.h"
#include "wavplayer.h"

int main()                                          // main function
{
  int DO = 22, CLK = 23, DI = 24, CS = 25;         // SD I/O pins
  sd_mount(DO, CLK, DI, CS);                       // Mount SD card
  
  const char yay[] = {"yay.wav"};

  while(1)
  {
      print("Play Wave File\n");
      wav_play(yay);                               // Pass to wav player  
      wav_volume(6);                              // Adjust volume
      print("Play medium\n");
      pause(3000);                                 // Play for 5 sec
      wav_stop();                                   // Stop playing
  }

}

Comments

  • BTL24BTL24 Posts: 54
    edited 2013-10-06 21:47
    After consulting with another user (GeeksGoneBad), I tried an alternate approach to getting way_play to play wave files continuously by starting and stopping the cog responsible for executing the wave player code (at least I think it is). Thanks GeeksGoneBad!

    However, tests proved futile, as the player again only played the "yay.wav" file 5 times before ceasing to play it anymore in my rendition of the code (See attached). Other code continues to run per the serial terminal output.

    Observation: Upon examining the documentation for wav_play, it really doesn't explain how the routine executes and how many cogs it uses (presumed 2 cogs). It would be nice to have a little more explanation on how this function operates so as to provide insight into it use in various applications. For example, upon execution how the cogs are assigned, does the function release the cogs or sustain their usage.

    Please understand, I am not complaining here. There is a lot of great work coming up with these cool functions to help us all out in getting the prop to jump through hoops.... Kudos! It is just a suggestion to better understand the function.

    Any other suggestions/recommendations?

    Regards,
    Brian (BTL24)
    #include "simpletools.h"
    #include "wavplayer.h"
    
    void talking();
    
    unsigned int stack1[75];
    
    const char yay[] = {"yay.wav"};
    
    int DO = 22, CLK = 23, DI = 24, CS = 25;    // SD I/O pins
    
    int main()                                    // main function
    {
      while(1) {
        sd_mount(DO, CLK, DI, CS);                  // Mount SD card
        print("Play Wave File\n");
        int talkingCog = cogstart(&talking, NULL, stack1, sizeof(stack1));  
        pause(4000);
        cogstop(talkingCog);
      }
    };
    
    void talking()
    {
      wav_volume(6);
      wav_play(yay);
      pause(3000);  
      wav_stop();
    }
    
  • David BetzDavid Betz Posts: 14,516
    edited 2013-10-07 08:32
    BTL24 wrote: »
    I am attempting to have a wav file play over and over again... indefinitely (until I stop program), but am having issues as it only plays 5 times then stops.

    When I utilize the wav_play function as shown in the code below, the wav file "yay" only plays 5 times... then goes silent. The code continues to run as evidenced in the serial terminal. If I reload the program, it will play 5 times again.. then stop again.

    FYI...I am running code on the Prop Activity board through the simple IDE. The Yay.wav file is from the Parallax tutorials.

    Is there an issue that the wav_play function keeps opening new cogs... then eventually runs out? Am I exceeding a stack somewhere? Any help would be appreciated.

    Regards,
    Brian
    /*
      Test WAV Volume (10).c
    */
    
    #include "simpletools.h"
    #include "wavplayer.h"
    
    int main()                                          // main function
    {
      int DO = 22, CLK = 23, DI = 24, CS = 25;         // SD I/O pins
      sd_mount(DO, CLK, DI, CS);                       // Mount SD card
      
      const char yay[] = {"yay.wav"};
    
      while(1)
      {
          print("Play Wave File\n");
          wav_play(yay);                               // Pass to wav player  
          wav_volume(6);                              // Adjust volume
          print("Play medium\n");
          pause(3000);                                 // Play for 5 sec
          wav_stop();                                   // Stop playing
      }
    
    }
    
    Does wav_stop() close the file? It sounds like you're running out of file descriptors. I haven't looked at this module but is there a wav_close() function or something like that?
  • jazzedjazzed Posts: 11,803
    edited 2013-10-07 09:17
    David is right.

    The library has a global FILE *fp and a local FILE *fp which means the wav_stop function is not closing the file.

    For the moment, change line 115 of this file: Documents\SimpleIDE\Learn\Simple Libraries\Audio\libwavplayer\wavplayer.c

    //FILE* fp = fopen(trackp, "r");
    fp = fopen(trackp, "r");

    Rebuild libwavplayer for CMM, LMM, XMMC.
  • David BetzDavid Betz Posts: 14,516
    edited 2013-10-07 09:17
    The problem is that there is a minor bug in the WAV player. It uses a local variable "fp" instead of the global that is in the same module.
    void wav_reader(void *par)
    {
      waitcnt(CLKFREQ+CNT);
       
      char b[4];
      int v;
      unsigned short int w;
      
      const char* trackp = (const char*) track;
      
      FILE *fp = fopen(trackp, "r");
      if(fp)
      {
    

    It's quite easy to fix though. Just change this section of code to:
    void wav_reader(void *par)
    {
      waitcnt(CLKFREQ+CNT);
       
      char b[4];
      int v;
      unsigned short int w;
      
      const char* trackp = (const char*) track;
      
      fp = fopen(trackp, "r");
      if(fp)
      {
    

    Edit: This code is in wavplayer.c.
  • BTL24BTL24 Posts: 54
    edited 2013-10-07 09:54
    David & Jazzed....

    Thanks for the quick feedback and solution. I cant wait to give it a try.!

    Now that I know where to check out the function code, I will better understand its operation.

    I am new to Prop C....but learning fast...thanks to guys like you.

    Regards,
    Brian (BTL24)
  • Steph LindsaySteph Lindsay Posts: 767
    edited 2013-10-07 14:53
    Thanks everyone for the heads-up about this bug, I will let Andy know. And my apologies for the inconvenience BTL24!
  • BTL24BTL24 Posts: 54
    edited 2013-10-07 19:12
    Steph....

    No worries... and no inconvenience. It is all a learning process for me as I adopt the propeller as my new processor of choice. The Prop C approach is fantastic and I appreciate the leg work that has gone into this new C language platform. This is why its called Beta... LOL.

    I have been a huge fan of Stamps and SX processors and incorporated them into many embedded systems. I have been slow to come off the SX as it is so versatile. I see great things with the 8 cog propeller chip though... great things...especially in my work with stage lighting and DMX busses.

    Regards,
    Brian (BTL24)
  • Invent-O-DocInvent-O-Doc Posts: 768
    edited 2013-10-09 09:15
    What a great question, it ended up uncovering a bug in the library. I'm sure that's the sort of thing they are looking for during this test period. Haven't played with the wav player yet, but am looking forward to it...
  • BTL24BTL24 Posts: 54
    edited 2013-10-12 17:00
    I have successfully made the suggested code changes as noted above, rebuilt the libraries and am happy to report that my issue with way player is now resolved!

    My code is playing the "Yay" wav file over and over again... indefinitely. It is now up to over 200 plays and still going!

    Thanks to jazzed and David for all their help. Fantastic!!!

    To rebuild libraries, see jazzed post (http://forums.parallax.com/showthread.php/150727-How-Are-Libraries-Compiled-Built-and-or-Updated). He gives a very precise list of instructions how to do it.

    (P.S. I have been on travel this last week and just got back to my laptop to run these tests... thus the delay in responding)

    Regards,
    Brian (BTL24)

    Edit: It works for two different methods of calling way_play....1) the one in first post and 2) the one posted here that I am now testing...
    #include "simpletools.h"
    #include "wavplayer.h"
    
    void talking();
    
    unsigned int stack1[75];
    
    const char yay[] = {"yay.wav"};
    
    int DO = 22, CLK = 23, DI = 24, CS = 25;    // SD I/O pins
    
    
    int main()                                    // main function
    {
      sd_mount(DO, CLK, DI, CS);                  // Mount SD card
      int n = 1;
    
      while(1) 
      {
        print("Play Wave File %d\n", n);
        int talkingCog = cogstart(&talking, NULL, stack1, sizeof(stack1));  
        pause(4000);
        cogstop(talkingCog);
        n++;
      }
    };
    
    
    void talking()
    {
      wav_volume(6);
      wav_play(yay);
      pause(3000);  
      wav_stop();
    }
    
Sign In or Register to comment.