Rewind and fast forward with VS1053

Designing hardware that uses VLSI Solution's devices as slave codecs such as an external MP3 decoder chip for a host microcontroller.
Post Reply
DaveM
User
Posts: 3
Joined: Thu 2015-06-04 0:35

Rewind and fast forward with VS1053

Post by DaveM »

Hello there,
I have the Adafruid Music shield with the VS1053B. I tried to realize the rewind and fast forward functionallity described in VS1053b Datasheet (Version: 1.20, 2012-12-03) in capture 10.5.4 on page 51.
There is written that after send at least 2048 bytes of endFillByte I can jump forwards or backwards in the file. For me it is unclear how this works:
1) With a wma-file or ogg-vorbis-file I see the positionMsec. But if I change this value that takes no effect
2) Only with a wma-file I see values of JumpPoints, but it is unclear how I can read this correct out (2, 4 or 8 Byte values) and how it is possible to set this.
Which one of this two options would realize rewind and fast forward or is there another option for this issue?

Regards
David
User avatar
pasi
VLSI Staff
Posts: 1793
Joined: Thu 2010-07-15 16:04

Re: Rewind and fast forward with VS1053

Post by pasi »

The positionMsec is read-only, it indicates what the current decoding position is. (The slave decoder is not able to seek in the file anyway.) It is only updated for formats that specify a decoding position in the audio data or in the container format.

In practice the jumppoints are too hard to use and format-specific. We usually just recommend taking advantage of the automatic resynchronization feature and just jumping in the file data (datasheet chapter 10.5.4).

So, when there is a proper value in parametric_x.resync (32767, the default after reset), the decoder will spend some effort trying to resynchronize after disruptions in the audio file. So, you can just start sending data from another position in the file. The endfillbytes sent before that should guarantee that the decoder notices that the data position has changed.
Visit https://www.facebook.com/VLSISolution VLSI Solution on Facebook
DaveM
User
Posts: 3
Joined: Thu 2015-06-04 0:35

Re: Rewind and fast forward with VS1053

Post by DaveM »

Hi pasi,
thanks for your answer. Regarding your reply I tried to send data from another position in the file after sent endfillbytes before. I created this function in Adafruit_VS1053.cpp but I had no success although endFillByte returns everytime zero. Do I use the endFillByte in a wrong way?

Code: Select all

void Adafruit_VS1053_FilePlayer::seekPosition(uint32_t position) {
  // read endFillByte
  sciWrite(VS1053_REG_WRAMADDR, 0x1e06);
  if (sciRead(VS1053_REG_WRAM) == 0) {
    currentTrack.seek(position);
  }
}
After this trail I thought I can set a new position before the playing starts. So I added to the buffer feeder an if-block that seeks a new position. But that also didn´t work. Is the function 'seek' the wrong way?

Code: Select all

  // Feed the hungry buffer! :)
  while (readyForData()) {
    //UDR0 = '.';

    //Before the first read from file set a new file position
    if (firstCall == true) {
      firstCall = false;
      currentTrack.seek(1800000);
      Serial.println("FirstCall");
    }

    // Read some audio data from the SD card file
    int bytesread = currentTrack.read(mp3buffer, VS1053_DATABUFFERLEN);

    if (bytesread == 0) {
      // must be at the end of the file, wrap it up!
      playingMusic = false;
      currentTrack.close();
      running = 0;
      return;
    }
    playData(mp3buffer, bytesread);
  }
I tried the function seek with other fileformats and that works fine but not with audio files. Have you any idea what I have to do to jump correctly within the audio file?

Regards
David
Last edited by DaveM on Fri 2015-06-05 20:12, edited 1 time in total.
User avatar
Panu
VSDSP Expert
Posts: 2818
Joined: Tue 2010-06-22 13:43

Re: Rewind and fast forward with VS1053

Post by Panu »

I don't know about this but just a little piece of info:

If you start playing from other location than the beginning, it will only work with MP3 because all other fomats have headers only in the beginning of the file. MP3 has headers within each block (MP3 format was designed for satellite radio originally, you know).

MP3 you can start playing from anywhere. Other formats you need to start playing from the beginning so that the VS10xx sees the header and then you can jump elsewhere.

I have no idea how file seeking works in adafruit.

-Panu
User avatar
pasi
VLSI Staff
Posts: 1793
Joined: Thu 2010-07-15 16:04

Re: Rewind and fast forward with VS1053

Post by pasi »

Endfillbyte is 0 for most of the formats, so it probably works fine.

Like Panu reminds us, for most of the audio files though, you need to start playing from the beginning of the file, because the audio files have headers that need to be read and processed before the actual audio can be decoded. SCI_STATUS bit DO_NOT_JUMP will be set when any of these formats are detected. You should keep sending data until the bit clears. You are then allowed to jump sending data from another location in the file.

Mp3, mp2 and aac in the ADTS format are different, DO_NOT_JUMP is never set for them, because each audio frame contains all information required to decode it (samplerate, bitrate, etc.). (Well, excluding the bit reservoir of mp3.)
Visit https://www.facebook.com/VLSISolution VLSI Solution on Facebook
DaveM
User
Posts: 3
Joined: Thu 2015-06-04 0:35

Re: Rewind and fast forward with VS1053

Post by DaveM »

Hello together,

today I have success with both code-snippets. If I use mp3-Format and I seek a new position before the music starts to play that works :)
The same works if I set 'firstCall' later during the music plays.

I learned that I have to respect the buffer-feeder-cycle to seek through the music file. If I wait on buffer empty and seek before the buffer is filled again I can jump in the song forward and backward.

Thanks all

Regards
David
Post Reply