Home Forums Sparkfun MP3 Shield Library Support Forum Changing Volume while paused.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #1833
    Anonymous
    Inactive

    MP3player.pauseDataStream();
    MP3player.SetVolume(2,2);

    The call to SetVolume will unpause your music.

     

    #1834
    Bill
    Member

    PauseDataStream() should NOT be used to pause music. It is intended to simple free up the SPI bus for other uses with no risk of data collision. Using it to pause music will produce unexpected results.

    #1835
    Anonymous
    Inactive

    /* Get and Display the Audio Information */
    } else if (key_command == 'i') {
    MP3player.getAudioInfo();

    } else if (key_command == 'p') {
    MP3player.pauseDataStream();
    Serial.println(F("Pausing"));

    } else if (key_command == 'r') {
    MP3player.resumeDataStream();
    Serial.println(F("Resuming"));

    } else if (key_command == 'R') {
    MP3player.stopTrack();
    MP3player.vs_init();
    Serial.println(F("Reseting VS10xx chip"));

    The above is quoted from MP3Shield_Library_Demo.ino, so that is where I got the idea. I have attempted to use the below code:

    time = MP3player.currentPosition();
    MP3player.stopTrack();
    delay(5000);
    MP3player.playMP3(currentTrackName);
    MP3player.skipTo(time);

    This produces an audible skip as a fraction of the start of the song is played before the skipTo happens.

    I am open to other suggestions.

    #1836
    Bill
    Member

    Sorry, the confusion stems from two developers on this library. I wasn’t aware Michael put this in the example. The original intent for the said function is as I said, to avoid data collisions. Using it to pause the music is a side effect (if you stop the data stream long enough eventually the decoder runs out of song to decode).

    I’m going to suggest the library get a additional and discrete “pauseMusic” function instead to clarify the difference between communication collision management and song controls. I’ll work with Michael on that. He should see this message and respond here, or I’ll email him otherwise.

    #1837

    I have been out of town.

    Yes, the restart from volume became obvious from another thread. A pre-release version has that fixed. This version’s example works. But has some new features and different file handling that I am still evaluating.

    Also note there is no need to pause the music as to change the volume. There is a mechanism under the hood to avoid collision for that process.

    Yes, I saw the pause was originally intended for quick SPI access. Where as I was not able to get the internal pause of the chip to work. Due to refill(). And this works reasonably. Note that stopTrack actually flushes the VS1053 buffer and pauseDataStream simply pause the refill.

    In that pauseDataStream and playMP3 are coupled to the VS1053 buffer, the MP3Play makes an initial fill of the buffer, and the VS1053 will play that regardless. as the pauseDataStream  simply stops filling it. hence your initial blast.

    The pre-release version may with its state fullness may handle this better. But may need tweak to the skip for it to work better.

    Where your above examples issue is not in the pause but the fact that the playMP3 makes the initial fill of the buffer.

    I am not sure why

    MP3player.pauseDataStream();
    delay(5000);
    MP3player.resumeDataStream();

    does not do the job in place of your above snippet. where you could set the volume either before or after the pause. And in the pre-release in between.

    An overload of resumeDataStream(uint32_t timecode) that does the skip to, may be the solution. Likewise a an overload of the playMP3(char* fileName, uint32_t timecode). Where as I note that uint32_t timecode is somewhat limited as to the maximum time it can skip to).

    #1839
    Anonymous
    Inactive

    Michael, your suggested code does work fine, and it has been what I’m using.

    I had been updating the volume upon every cycle of loop(), which would cause MP3player.pauseDataStream() to resume immediately. Now I store the paused state in a global variable and check against it, as follows:

    if (!time_paused && MP3player.isPlaying()) volumeChange();
    (where volumeChange() is a private function that reads data and calls MP3player.SetVolume())

    #1848

    The pre-release version  version has getState() to query if paused, etc… It is how pause is now toggled in the example.

    enum state_m {
      uninitialized,
      initialized,
      deactivated,
      loading,
      ready, // aka IDLE!
      playback,
      paused_playback,
      testing_memory,
      testing_sinewave,
      }; //enum state_m
    
    if( MP3player.getState() == paused_playback) {
      MP3player.resumeMusic();
      Serial.println(F("Resuming"));
    }

    I would think the below would accomplish the same goal.

    if (MP3player.getState() == paused_playback) volumeChange();
Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.