Hello,
I have been reading with great interest that the VS1053 can support custom codecs as plugins (loaded and run from RAM), however I am unclear on a couple of details which I hope you can clarify.
I believe that custom ‘C’ code runs on the actual DSP and that there are a number functions which can be called such as ‘WmaStereoCopy()’ to help pass/process the audio. Are there a list of these ROM entry points and a description of what they do?
I would be particular interested if custom code could make use of inbuilt FFTs and the like.
Is there a overview document for the DSP core which gives an approximation of computational power? I would want to gauge whether our custom codec would be able to reach real-time performance.
Yours faithfully,
Simon Wood
VS1053 custom codec
Re: VS1053 custom codec
Hi!
It's possible to write custom codecs for VS1053, but it's perhaps a bit esoteric (certain guru level required) aspect of programming, so it's not very well documented.
But I'll mention this question when they emerge from the cave to see some daylight again...
The VS_DSP4 architecture manual is not released to the public, but maybe you can draw comparisons from some of the figures our datasheets expose of existing codecs; MP3 at 48 kHz and 320 kbps takes less than 24 MHz to decode. VS1053 can run up to 49 MHz over the allowed core VDD range, and 55 MHz with more voltage. The core is a fairly normal kind of integer DSP, with 40 bit multiply-and-accumulate path and two 16 bit data buses. The integer multiplier is 16 x 16 = 32 bits and the barrel shifter is 40 bits wide.
-Panu
It's possible to write custom codecs for VS1053, but it's perhaps a bit esoteric (certain guru level required) aspect of programming, so it's not very well documented.
The software tools contain a list of entry points (function names and entry addresses) so that the tools can link code against the ROM. The implementations of the ROM functions are secrets, but in some cases the API is documented in the form of example code from us. The function names can provide interesting clues as to what's included in the ROM. And we can help with specific problems...I believe that custom ‘C’ code runs on the actual DSP and that there are a number functions which can be called such as ‘WmaStereoCopy()’ to help pass/process the audio. Are there a list of these ROM entry points and a description of what they do?
This would be an example of "We can help with specific problems..." But our codec gurus are busy finalizing the MP3 encoder code for VS1063 so they are quite busy at the moment...I would be particular interested if custom code could make use of inbuilt FFTs and the like.


Is there a overview document for the DSP core which gives an approximation of computational power? I would want to gauge whether our custom codec would be able to reach real-time performance.
The VS_DSP4 architecture manual is not released to the public, but maybe you can draw comparisons from some of the figures our datasheets expose of existing codecs; MP3 at 48 kHz and 320 kbps takes less than 24 MHz to decode. VS1053 can run up to 49 MHz over the allowed core VDD range, and 55 MHz with more voltage. The core is a fairly normal kind of integer DSP, with 40 bit multiply-and-accumulate path and two 16 bit data buses. The integer multiplier is 16 x 16 = 32 bits and the barrel shifter is 40 bits wide.
-Panu
Info: Line In and Line Out, VS1000 User interface, Overlay howto, Latest VSIDE, MCU Howto, Youtube
Panu-Kristian Poiksalo, VLSI Solution Oy
Panu-Kristian Poiksalo, VLSI Solution Oy
Re: VS1053 custom codec
We have begun the work of 'opening up' the rom routines with VSIDE, but it must go in some priority order (and by request like Panu mentioned).mungewell wrote:I would be particular interested if custom code could make use of inbuilt FFTs and the like.
Is there a overview document for the DSP core which gives an approximation of computational power? I would want to gauge whether our custom codec would be able to reach real-time performance.
What primitives/ops do you need? What bit widths?
16 x 16 -> 32 FIR is one cycle per tap, 16 x 32 is twice that when programmed correctly (usually 16-bit coefficient is enough). IIRs take a bit more.
The 32-bit imdct used by wma, aac, and ogg vorbis can also be used to implement complex ffts and such.
Visit https://www.facebook.com/VLSISolution VLSI Solution on Facebook
Re: VS1053 custom codec
I think disassembling the official FLAC decoder plugin may be a practical way to learn how to write a custom codec. Last month I tried wring a decoder for Monkey's Audio (APE) format.I could't find any documents on how to implement custom codecs for VS1053,so I had to write a small disassembler and disassemble the official FLAC plugin code.After some research I found the entry point of the FLAC decoder.Then I did some modifications to the decoder entry point. This is a little tricky, but at least it works...
Here is a fragment of disassembled code of "VS1053B Patches and FLAC Decoder (V1.5)". I explain my modifications in comments.
I optimized my code a lot, and almost rewrote the whole decoder in assembly.However, unfortunately, I found out it seems that VS1053 cannot decode Monkey's Audio in real-time; overclocking the chip to about 80M is necessary to decode most APE file
.
I hope my experience may help
.
Here is a fragment of disassembled code of "VS1053B Patches and FLAC Decoder (V1.5)". I explain my modifications in comments.
Code: Select all
......
/* 0x0361 */ /* 0x00141b01 */ LDC 0x506c,A1 // 'Pl'
/* 0x0362 */ /* 0x280ac505 */ JZS 0x2b14
/* 0x0363 */ /* 0x0000190d */ LDC 0x0064,LC
/* 0x0364 */ /* 0x001559c0 */ LDC 0x5567,A0 // 'Ug'
/* 0x0365 */ /* 0x6fc20024 */ SUB D,A,A
/* register D contains last four bytes received in SDI Data */
/* 0x0366 */ /* 0x00199301 */ LDC 0x664c,A1 // 'fL'. fLaC signature
/* 0x0367 */ /* 0x2800e295 */ JZC 0x038a /* not tags in SDI Data*/
/* 0x0368 */ /* 0x001850c0 */ LDC 0x6143,A0 // 'aC'
/* change the magic number in two LDC instructions to your own magic number */
......
/* 0x038a */ /* 0x6fc20024 */ SUB D,A,A /* compare */
/* 0x038b */ /* 0x00000024 */ NOP
/* 0x038c */ /* 0x2800e1d5 */ JZC 0x0387 /* not a flac file */
/* 0x038d */ /* 0x00000024 */ NOP
/* 0x038e */ /* 0x28025a00 */ J 0x0968 /* FLAC decoder entry point */
/* change the jump instruction above and jump to your codec :-) */
/* 0x038f */ /* 0x000acac8 */ LDC 0x2b2b,LR0
/* return address must be 0x2b2b */
......
.sect code,code_0x968
.org 0x968
//FLAC Decoder Entry
/* replace it with your own code :-) */
/* 0x0968 */ /* 0x36130024 */ LDX (I6)+1,NULL;
/* 0x0969 */ /* 0x3e12b817 */ STX MR0,(I6)+1; STY I7,(I6)
/* 0x096a */ /* 0x3e123815 */ STX LR0,(I6)+1; STY I5,(I6)
/* 0x096b */ /* 0x3e05b814 */ STX I6,(I6); STY I4,(I6)
/* 0x096c */ /* 0x36150024 */ LDX (I6)+1,I4;
/* 0x096d */ /* 0x0000800a */ LDC 0x0200,MR0
/* 0x096e */ /* 0x3e103801 */ STX A0,(I6)+1; STY A1,(I6)
/* 0x096f */ /* 0x00199300 */ LDC 0x664c,A0 // 'fL'
/* 0x0970 */ /* 0x3e143811 */ STX I0,(I6)+1; STY I1,(I6)
/* 0x0971 */ /* 0x00300250 */ LDC 0xc009,I0 //SCI_HDAT1
/* 0x0972 */ /* 0x3e04b813 */ STX I2,(I6); STY I3,(I6)
......

I hope my experience may help

Last edited by victor on Fri 2011-02-18 7:05, edited 2 times in total.
Re: VS1053 custom codec
@victor - impressive reverse engineering... not sure I'm at that stage yet.
@pasi:
The codec in question is Codec2 (http://www.rowetel.com/blog/?page_id=452), which is at the alpha stage at present. We are running everything as floats, but plan to move to UINT32's (maybe 16's) in the near future. The frame rate is 10ms with 8K sampling. The encoder uses 4 FFT512's and a FIR (48 tap) per frame, and the decoder uses 6 FFT512's.
Obviously we have some (lots?) optimisation to perform before we move to the embedded platform, but it's good to know that the VS1053 is opening up as the many dev/breakout boards would a great asset for our potential users.
Cheers,
Simon.
@pasi:
The codec in question is Codec2 (http://www.rowetel.com/blog/?page_id=452), which is at the alpha stage at present. We are running everything as floats, but plan to move to UINT32's (maybe 16's) in the near future. The frame rate is 10ms with 8K sampling. The encoder uses 4 FFT512's and a FIR (48 tap) per frame, and the decoder uses 6 FFT512's.
Obviously we have some (lots?) optimisation to perform before we move to the embedded platform, but it's good to know that the VS1053 is opening up as the many dev/breakout boards would a great asset for our potential users.
Cheers,
Simon.