software MP3 decoder for Kinetis MK64

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

software MP3 decoder for Kinetis MK64

Jump to solution
6,378 Views
oleglavrukhin
Contributor IV

Hello, community!

I work with FRDM-K64F in CodeWarrior and KDS+KSDK. One part of my big project is a player WAV, MP3 and (may be) AAC and FLAC files.

Without any problem I make  a WAV player (play files from USB stick and FLASH memory) based of example for SDK and MQX, it work finely in baremetal (KDS project) and with MQX (CW project).I get clear sound from external DAC (CS4350 from Cirrus logic) via I2S.

But I have a problem with software MP3 decoder.

I try to ported HELIX MP3 decoder from some projects for STM32. Decoder work (I try to use ASM and C realisations of Polyphase filter),

but in all variants sound have a DISTORTION!

The sound is very similar to roar (or crackles), or like a "overload" of the analog signal. This "roar" is heard only in the moments of the signal, during playback of silence at the beginning and end of the file there are no distortions.

I try to use example for Kinetis K-40, but get same distortions.:smileycry:

Can anyone share your implementation of software MP3 decoder for Kinetis?

Thank you for any help!

Oleg

Tags (2)
0 Kudos
1 Solution
3,540 Views
oleglavrukhin
Contributor IV

I solved the problem. Software MP3 decoder( i use Helix) produced (2*1152) bytes, but MQX SAI driver have a (2*512) bytes buffer as default. of course, I lost some decoded bytes when try send they into SAI buffer.

When I set SAI buffer size to "1152" (in BSP->BSP files->init_sai.c :

KSAI_INIT_STRUCT _bsp_ksai_init = {

0, /* Selected peripheral (HW channel) */

0, /* TX channel */

0, /* RX channel */

I2S_TX_ASYNCHRONOUS | /* TX is asynchronous */

I2S_RX_SYNCHRONOUS | /* RX hooked on TX */

I2S_TX_BCLK_NORMAL | /* Both TX and RX are clocked by the transmitter */

I2S_RX_BCLK_NORMAL, /* bit clock (SAI_TX_BCLK) */

I2S_TX_MASTER | /* SAI transmitter mode */

I2S_RX_MASTER, /* SAI receiver mode */

16, /* Data bits */

I2S_CLK_INT, /* Clock source */

FALSE, /* Tx Dummy */

5, /* Interrupt priority */

1152, /* Buffer size default setting is 512*/

CM_CLOCK_SOURCE_SYSTEM, /* Internal master clock source */

&_bsp_audio_data_init /* Audio init */

};

then i rebuild all the MQX lib's (BSP,PSP,MFS, RTCS, USB).

Now my MP3 decoder work correctly, sound is clear.

I hope my experience will be useful.

And i hope to find  full descriptions for MQX i/o drivers in next release.

i can share my project(MQX mp3 usb player for FRDM-k64f) if someone will need to.

View solution in original post

0 Kudos
24 Replies
3,473 Views
kadirkurt
Contributor I

Hi Oleg,

I am going to start to design mp3 player.

I need road map.

Do you have any suggestion

0 Kudos
3,473 Views
oleglavrukhin
Contributor IV

Hello, Kadir!

I have some worked projects for FRDM-K64f board, and

1) what IDE You use?

2) are You use MQX in your project?

I can send to you my project files for IDE, which you use

regards

0 Kudos
3,482 Views
niddem
Contributor I

Hey,

Disregard my last post, I made an attempt to port in the Helix codec and I got it working. Took about two days, but I now have it integrated with my libMAD project. Its currently not utilizing DMA which is the next thing I am going to do to improve performance. The output is also on the DAC0 & DAC1 which I downsample the 16-but audio stream to 12-bit. Will be doing a stereo codec implementation with the SGTL5000 to get full audio quality output.

Regards,

Bryan

0 Kudos
3,482 Views
oleglavrukhin
Contributor IV

Congratulations, Bryan! in my project I use external DAC CS4350 (Cirrus Logic), it work fine.

I'm intersting, how do You set SAI transmitt buffer size for SGTL5000 , as I have described, or you know another way?

Regards, Oleg

P.s. what IDE you use? i can't ported Libmad in Code Warrior 10.6 :smileyconfused:

0 Kudos
3,482 Views
niddem
Contributor I

Thanks Oleg!  I am using IAR 7.2. I have Codewarrior 10.5 and could make an attempt to port LibMAD into there. Though the LibMAD decoded ouput is not the same as Helix. The pcm data is automatically separated into independent left/right channel buffers. (i.e. pcm[0][sample], pcm[1][sample]) as opposed to Helix which the data format is LRLR. I changed the transmit buffer size for the SAI module the same way you did in MQX under the KSAI_INIT_STRUCT _bsp_ksai_init structure. I was able to get the SGTL5000 codec working with WAV, some issues with crackling sounds. I am now working on integrating it into the MP3 project.

0 Kudos
3,474 Views
oleglavrukhin
Contributor IV

Hi, Bryan!

Can You share a part of your code with Libmad (Libmad library files and in-out functions)?
Because my Libmad project don't work (at program start i init SAI and get "devicei_ptr", but when Libmad execute "mad_synth_mute()", i lost   "devicei_ptr" and can't write to SAI. I make Libmad project based on my Helix project -  i use some functions for work with SAI module and external DAC).

at second, Libmad library have a "imdct_l_arm.S" file, but IAR return many error for this file. i found Libmad implementation without this file (in PIC32 project). maybe this library is incorrect?

Regards, Oleg

0 Kudos
3,473 Views
niddem
Contributor I

Hi Oleg,

I will be glad to share my code for LibMAD. I did get the SGTL5000 codec working but only with Helix. I finished it up last weekend but got busy. Should have it ready for you in a day or two. I will send you the LibMAD project in a day or two.

Best Regards,

Bryan

0 Kudos
3,473 Views
oleglavrukhin
Contributor IV

Hi, Bryan!

I got it!!!  I make a little change in Libmad "output" function and it worked finely. it play 320 kbps from USB without optimization. But i'll be happy to look Your project. and do You have a "scale" function for get 24-bit output?

Regards, Oleg

0 Kudos
3,541 Views
oleglavrukhin
Contributor IV

I solved the problem. Software MP3 decoder( i use Helix) produced (2*1152) bytes, but MQX SAI driver have a (2*512) bytes buffer as default. of course, I lost some decoded bytes when try send they into SAI buffer.

When I set SAI buffer size to "1152" (in BSP->BSP files->init_sai.c :

KSAI_INIT_STRUCT _bsp_ksai_init = {

0, /* Selected peripheral (HW channel) */

0, /* TX channel */

0, /* RX channel */

I2S_TX_ASYNCHRONOUS | /* TX is asynchronous */

I2S_RX_SYNCHRONOUS | /* RX hooked on TX */

I2S_TX_BCLK_NORMAL | /* Both TX and RX are clocked by the transmitter */

I2S_RX_BCLK_NORMAL, /* bit clock (SAI_TX_BCLK) */

I2S_TX_MASTER | /* SAI transmitter mode */

I2S_RX_MASTER, /* SAI receiver mode */

16, /* Data bits */

I2S_CLK_INT, /* Clock source */

FALSE, /* Tx Dummy */

5, /* Interrupt priority */

1152, /* Buffer size default setting is 512*/

CM_CLOCK_SOURCE_SYSTEM, /* Internal master clock source */

&_bsp_audio_data_init /* Audio init */

};

then i rebuild all the MQX lib's (BSP,PSP,MFS, RTCS, USB).

Now my MP3 decoder work correctly, sound is clear.

I hope my experience will be useful.

And i hope to find  full descriptions for MQX i/o drivers in next release.

i can share my project(MQX mp3 usb player for FRDM-k64f) if someone will need to.

0 Kudos
3,481 Views
alexquisi
Contributor I

Hi Oleg,

I am just starting to get MP3 working and it would be for me very useful to get your project as reference.

Could you please send it to my E-mail address: alexander_quinones AT hotmail DOT com?

Thanks in advance.

Regards,

Alex

0 Kudos
3,482 Views
oleglavrukhin
Contributor IV

Hi, Alexander.

i have 3 variants USB MP3 Player, based on Helix Decoder & Freescale MQX 4.1. For Codewarrior 10.6, IAR 7.2 and Keil uVision 5.

Projects have identical algorithm, but different files in Helix decoder library ( assembler implementation of Polyphase filter).

Which project do you want to receive?

0 Kudos
3,481 Views
alexquisi
Contributor I

Hi Oleg,

thanks for your reply.

I am currently using KDS. Not sure which one of your versions will be easier to port/convert to KDS, maybe you have a better idea than me. As Bryan, I am also planning to connect my audio output with the SGTL5000.

It would be interesting to know his experience between Helix codec vs libMAD.

Thanks,

Alex

0 Kudos
3,481 Views
niddem
Contributor I

Hi Alexander,

     I haven't used KDS yet and am curious to know how well it works. I will keep you posted on my progress with the integration of the SGTL5000 codec with LibMAD and Helix.

Best Regards,

Bryan

0 Kudos
3,482 Views
alexquisi
Contributor I

Hi Bryan,

This is my first project with the Kinetis MCU and I just selected KDS because it is free so I could not tell to much comparing it with other IDEs. Do you have some information about memory usage (RAM/ROM) and performance between LibMAD and Helix?

Though my initial project is a hobby, I was also reading about MP3 decoding licensing and theoretically the patent will expire at the end of this year but there could be some issues with the interpretation of the expiring date.

Have you get informed about the MP3 lisencing?

Thanks,

Alex

0 Kudos
3,482 Views
niddem
Contributor I

Hi Alex,

I will be trying to use KDS in the near future to see how it functions.

The RAM/ROM requirement for LibMAD  & Helix with optimization are:

LibMAD

2.67kB [RAM] / 54.6kB [ROM]

Helix

7.1kB [RAM] / 34.1kB [ROM]     (RAM requirement can be reduced by making the input/output buffer smaller)

I haven't looked into the licensing of MP3 as I took on this project as a hobby.

Best Regards,

Bryan

0 Kudos
3,480 Views
alexquisi
Contributor I

Hi Bryan,

thanks a lot for the useful information.

i'm looking forward to hearing from your progress with the SGTL5000 codec together with LibMAD and Helix.

Best wishes,

Alex

0 Kudos
3,479 Views
oleglavrukhin
Contributor IV

Hi, Alex!

i found my old project "USB mp3-wav player" in KDS2.0 + KSDK1.1. it work on FRDM-K64F with external DAC CS4350. You can try to use it, but You need remove my DAC driver and add driver for SGTL5000(or another DAC what you have).

Good Luck. !

0 Kudos
3,479 Views
mariospelekis
Contributor III

Hi Oleg,

Is it possible to explain why you use 2 new spaces in the ram. Unfortunately I am not able to identify where you use them in your code.

MEMORY {

   m_interrupts          (RX)  : ORIGIN = 0x00000000, LENGTH = 0x00000400
  m_text                (RX)  : ORIGIN = 0x00000410, LENGTH = 0x000FFBF0
  m_interrupts_ram      (RW)  : ORIGIN = 0x1FFF0000, LENGTH = 0x00000400
  m_data_1FFF0400       (RW)  : ORIGIN = 0x1FFF0400, LENGTH = 0x0000FC00
  m_data                (RW)  : ORIGIN = 0x20000000, LENGTH = 0x00030000
  m_flash_config        (RX)  : ORIGIN = 0x00000400, LENGTH = 0x00000010
}

Thank you!!

Marios

0 Kudos
3,479 Views
alexquisi
Contributor I

Hi Oleg,

thanks a lot!

I will give it a try in the next days ;-)

Best wishes,

Alexander

0 Kudos
3,478 Views
niddem
Contributor I

Hi Oleg,

I have been working on the MP3 decoder using LibMad and have a working project using the Kinetis K70 with USB and SD with a 25-band spectrum analyzer on a 24-Bit RGB LCD with MQX 4.2. I am able to stream at 320kbps @ 16-bit. I am interested in your project using the Helix MP3 decoder to see the difference in performance. Could you send me your project?

Best Regards,

Bryan

0 Kudos