Shop OBEX P1 Docs P2 Docs Learn Events
entire song isn't played — Parallax Forums

entire song isn't played

laurent974laurent974 Posts: 77
edited 2017-02-23 07:01 in Propeller 1
How long a wav song can be played ?

i tried this code, but the song is stopped after around 10sec. i tried also with only one pause and the length of the song 2 min = pause(120 000 )
but the result is the same.


#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 techloop[] = {"luftbal.wav"};       // Set up techloop string
  wav_play(techloop);                             // Pass to wav player
 
  wav_volume(10);
  pause(5000);
  pause(5000);
  pause(5000);
  pause(5000);
  pause(5000);

  wav_stop();                                      // Stop playing
}



Edit : Forget my question. it works

Comments

  • Edit 2 : what is the max value for Pause ? i tested 50 000 it worked but if i put 80 000 the song is stopped just after a while.
  • Could max value perhaps be 65535 then?
  • i'll tested tonight when at home.

    But I don't understand why, because pause is defined with an int (see code below), and int is as large as 0xFFFF FFFF (and not 0xFFFF)

    from pause.c in simpletool
    https://github.com/parallaxinc/Simple-Libraries/blob/master/Learn/Simple%20Libraries/Utility/libsimpletools/source/pause.c
    void pause(int time)                          // pause function definition
    { // If st_pauseTicks not initialized, set it up to 1 ms.
      // if(!st_pauseTicks) set_pause_dt(CLKFREQ/1000);
      time *= st_pauseTicks;                         // Calculate system clock ticks
      waitcnt(time+CNT);                          // Wait for system clock target
    }
    
  • laurent974 wrote: »
    i'll tested tonight when at home.

    But I don't understand why, because pause is defined with an int (see code below), and int is as large as 0xFFFF FFFF (and not 0xFFFF)

    from pause.c in simpletool
    https://github.com/parallaxinc/Simple-Libraries/blob/master/Learn/Simple%20Libraries/Utility/libsimpletools/source/pause.c
    void pause(int time)                          // pause function definition
    { // If st_pauseTicks not initialized, set it up to 1 ms.
      // if(!st_pauseTicks) set_pause_dt(CLKFREQ/1000);
      time *= st_pauseTicks;                         // Calculate system clock ticks
      waitcnt(time+CNT);                          // Wait for system clock target
    }
    

    Because the parameter is multiplied by st_pauseTicks. Assuming the clock is 80MHz then 1ms = 80000000/1000 = 80000 ticks, if you pass a time value of 80000ms the result is 80000*80.000=6400000000 or $17D784000 well above the limit. The maximum allowed time should be 4294967295 / 80000 = 53687 milliseconds.
  • thank you. That value (or a max value) should be noticed in the document of simpleIDE. @Andy Lindsay
  • edited 2017-02-24 16:55
    Your code doesn't necessarily have to synchronize itself with the song. Sometimes, it's beneficial to just make it loop and check if it's still playing. That way, it can also pay attention to sensor events without launching another cog.
    ...
    wav_play("filename.wav");
    while(wav_playing())
    {
      // code to run while playing goes here
    }
    

    Here's another approach:
    ...
    wav_play("filename.wav");
    while(1)
    {
      if(!wave_playing())
      {
        // code to run while playing goes here
      }
      else
      {
        // code to run after music stops here
      }
    }
    

    A variation on that would be if(!wav_playing()) { //code that runs once, followed by break; to exit the playing loop and move on to other things }.

    A third approach is to just loop without paying attention to if the song is playing. Here is an example of how that can be used:

    App
    http://learn.parallax.com/tutorials/robot/activitybot/remote-control-rock-talk-and-roll-activitybot

    Code
    http://learn.parallax.com/tutorials/robot/activitybot/remote-control-rock-talk-and-roll-activitybot/how-does-it-all-work

    P.S.
    I got a bug report about pause saying that it only plays for half that time, so I'd recommend using pause(26000) as a max for the time being.
  • oh great.

    i understand where my mistake came from: i was following the tutorial on how to play wav
    http://learn.parallax.com/tutorials/language/propeller-c/propeller-c-simple-devices/play-wav-files

    and it's written :
    Each call to wav_play also needs to be followed by a pause. The call to pause dictates how long the wav file will play. To hear an entire wav file, the call to pause must be about 900 ms longer than the length of the file.
    i was thinking i had to dedicate a 3rd cog just to play and insert some pause. indeed the pause is there just to prevent the main loop stopping.

    I did not reach the last tutorial you mentioned. i 'll change the code of my roaming jukeBOT.
  • laurent974laurent974 Posts: 77
    edited 2017-02-24 22:46
    Arg !

    the wav_playing() isn't working. here is my code

    it never enters in the first clause of if

    maybe because it runs out of cog due to bouge() function
    char *techloop[] = {"goldo.wav","crush.wav","rita.wav","luftbal.wav"};       // Set up techloop string
      int i=3;
    
      wav_volume(10);
      wav_play(techloop[i]);                             // Pass to wav player
    
      while(1) 
      {
        if (wav_playing()==0) {
          print ("que passo");
    
          i++;
          
          wav_play(techloop[i%4]);                             // Pass to wav player
          
          }  
         else  bouge();   
      }    
    }  
    
    void bouge(){
        drive_setRampStep(10);                      // 10 ticks/sec / 20 ms
    
      drive_ramp(128, 128);                       // Forward 2 RPS
    
      // While disatance greater than or equal
      // to 20 cm, wait 5 ms & recheck.
      while(ping_cm(17) >= 20) pause(5);           // Wait until object in range
    
      drive_ramp(0, 0);                           // Then stop
    
      // Turn in a random direction
      turn = rand() % 2;                          // Random val, odd = 1, even = 0
    
      if(turn == 1)                               // If turn is odd
        drive_speed(64, -64);                     // rotate right
      else                                        // else (if turn is even)
        drive_speed(-64, 64);                     // rotate left
    
      // Keep turning while object is in view
      while(ping_cm(17) < 20);                     // Turn till object leaves view
    
      drive_ramp(0, 0);                           // Stop & let program end
    
    }  
    
    
    
    
  • edited 2017-02-25 06:21
    It might need to be unsigned int. I'll be working on that soon.
Sign In or Register to comment.