Page 1 of 1

VS1053b sample counter for mp2

Posted: Tue 2019-01-15 17:21
by nsiva
Hi,

My project includes a streaming application. The details are as follows:
1. Chip used - VS1053b
2. Microcontroller - FPGA
3. PCB - Custom design
4. Boot EEPROM / Flash connected to VS10XX chip - No
5. Patch used - None. Planning to migrate to Rev 2.6

The FPGA receives a transport stream with encoded audio and video. The MCU in the FPGA extracts the MP2 elementary stream (ADTS format) and transfers the encoded audio data to the VS1053b. Video is decoded in the FPGA. In order to synchronize the audio and video I would like to have a audio sample counter.

In patch 2.6, a sample counter is available but only for Ogg Vorbis files. What is the behavior of this counter when other formats such as MP2 or AAC are decoded? Does it increment every time a decoded audio sample is written to the DAC FIFO? Does it increment when zero samples are inserted into audio FIFO whenever new data to be decoded does not arrive quickly enough and the audio buffer is getting too empty.

Also in patch 2.6, Application Hook at 0x60 is provided to disable zero sample insertion. In order to use this hook, I need to write 0x60 to SCI_AIADDR. Can I use my custom plugin at 0x50 along with the disable zero sample insertion application hook?

Re: VS1053b sample counter for mp2

Posted: Fri 2019-01-18 14:05
by pasi
The sample counter increases for every played sample for all formats (and even for idle zero samples).

Ogg Vorbis is just the one decoder that sets the sample counter to a value seen in the Ogg headers.

The patches package uses AIADDR for only starting, it doesn't use it afterwards (it's set to 0). You can first start the patches package by writing the appropriate value to AIADDR (I think the latest version allows 0x50 and 0x300 for compatibility with an older version), then wait for DREQ high and write 0x60 to AIADDR to disable sample insertion. (With 0x60 in AIADDR it seems 1 is written to AICTRL0 whenever audio is output so it's possible to read or reset the sample counter when you start playing.)

Re: VS1053b sample counter for mp2

Posted: Mon 2019-01-28 5:20
by nsiva
Hi Pasi,

I loaded the vs1053b-patches-latm patch and noticed the behavior mentioned by you
1. Sample counter increases for idle samples
2. With 0x60 in AIADDR, 1 is written to AICTRL0 whenever audio is output. This can be cleared by the FPGA microcontroller.

I wasn't able to use the patch by itself to meet my requirement of detecting when one second of audio is decoded. Therefore, after going through the Programming Guide and the VS1003 Plugin Example [http://www.vlsi.fi/fileadmin/software/V ... amples.zip], I was able to code a small plugin which does the following:
1. Turn of idle sample insertion
2. Whenever 48000 (in my application sample rate is always 48000) samples are decoded write the number of samples in DAC FIFO to AICTRL0.
The micro-controller monitors AICTRL0. When the value is not equal to 0, it can calculate when 48000 samples will be output by VS1053b. The micro-controller clears the value of AICTRL0.

I was able to get this plugin working when no patch is loaded. However when I load the vs1053b-patches-latm patch (ver 2.6), the plugin does not work. Since the patch uses some IRAM, I am loading my plugin starting from address 0x0C00. The combinations I have tested so far are:

Patch = None. Plugin Start Address = 0x0050. Behaviour = Works correctly.
Patch = None. Plugin Start Address = 0x0C00. Behaviour = Works correctly.
Patch = vs1053b-patches-latm (ver 2.6). Plugin Start Address = 0x0C00. Behaviour = Idle samples are disabled. After encoded data is provided, sample counter reaches 96000 in approx 900 msecs. After that, sample counter goes to 96000 every 1 second.

Could you please review whether I am compiling and linking the plugin correctly in order for it to work with vs1053b-patches-latm (ver 2.6) I have attached the files along with this post.

Regards,
Siva

Re: VS1053b sample counter for mp2

Posted: Mon 2019-01-28 11:25
by pasi
Your two static variables decodedSampleCount and toggle are linked into the same addresses than the 32-bit sampleCounter of the vs1053b patches. This is why the counter gets increased at double rate.

If you want to sidestep the X memory area the vs1053b-patches-latm uses (seems to be 0x1800..0x1820 in the development version), change the available X mem in mem_desc.vs1003, for example:
data_x: origin = 0x1840, length = 0x40
and link again.

Re: VS1053b sample counter for mp2

Posted: Thu 2019-02-07 16:51
by Mulvaney
Can you mess up something important if you "play around" with X memory area like that?

Re: VS1053b sample counter for mp2

Posted: Thu 2019-02-07 16:55
by pasi
0x1800 to 0x187f in both X and Y memory is reserved for user area, it is not used by the ROM firmware.
(Which is why the patches like to use that area for their own uses.)