Author Topic: MP3 Decoding on STM32G070RBT6  (Read 5170 times)

0 Members and 1 Guest are viewing this topic.

Offline ali_asadzadehTopic starter

  • Super Contributor
  • ***
  • Posts: 1905
  • Country: ca
MP3 Decoding on STM32G070RBT6
« on: June 16, 2022, 12:54:45 pm »
Hi,
I want to try Decoding MP3 on this part, do you recommend any light weight opensource library?
ASiDesigner, Stands for Application specific intelligent devices
I'm a Digital Expert from 8-bits to 64-bits
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5907
  • Country: es
Re: MP3 Decoding on STM32G070RBT6
« Reply #1 on: June 16, 2022, 04:52:32 pm »
This one uses helix mpr decoder:

https://github.com/lamilami/stm32-mp3player
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11260
  • Country: us
    • Personal site
Re: MP3 Decoding on STM32G070RBT6
« Reply #2 on: June 16, 2022, 05:08:07 pm »
Just keep in mind that there is no chance Cortex-M0+ at 64 MHz can decode MP3 in real time for playback.
Alex
 

Offline brichards42

  • Contributor
  • Posts: 32
  • Country: us
Re: MP3 Decoding on STM32G070RBT6
« Reply #3 on: June 16, 2022, 05:17:56 pm »
I have used this:
https://github.com/lieff/minimp3

I found the author very helpful.
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14476
  • Country: fr
Re: MP3 Decoding on STM32G070RBT6
« Reply #4 on: June 16, 2022, 07:08:10 pm »
Just keep in mind that there is no chance Cortex-M0+ at 64 MHz can decode MP3 in real time for playback.

Well well. Probably depends on the compression level and the target sample rate. While it does seem pretty challenging, I wouldn't necessarily say "no chance" upfront. But that would certainly require significant work and probably a good chunk of assembly to get it to work. Not sure it's worth the trouble.
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5907
  • Country: es
Re: MP3 Decoding on STM32G070RBT6
« Reply #5 on: June 17, 2022, 01:59:09 am »
There're mp3 decoders using fixed point math.
While not 100.000000% accurate, they do the job
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11260
  • Country: us
    • Personal site
Re: MP3 Decoding on STM32G070RBT6
« Reply #6 on: June 17, 2022, 02:02:32 am »
But they still need quite a bit of performance to do real time decoding.

Sure, you can artificially create an mp3 file that is bad enough to be decoded on Cortex-M0+, but that does not represent a typical use case.
Alex
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5907
  • Country: es
Re: MP3 Decoding on STM32G070RBT6
« Reply #7 on: June 17, 2022, 02:16:28 am »
IIRC 48MHz where more than enough on an optimized arm system.
Helix is fixed point
« Last Edit: June 17, 2022, 02:19:42 am by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline ali_asadzadehTopic starter

  • Super Contributor
  • ***
  • Posts: 1905
  • Country: ca
Re: MP3 Decoding on STM32G070RBT6
« Reply #8 on: June 18, 2022, 07:40:43 am »
Quote
This one uses helix mpr decoder:

https://github.com/lamilami/stm32-mp3player
Thanks david, But it uses some asm functions that are only supported from Cortex M3 upwards.
ASiDesigner, Stands for Application specific intelligent devices
I'm a Digital Expert from 8-bits to 64-bits
 

Offline ali_asadzadehTopic starter

  • Super Contributor
  • ***
  • Posts: 1905
  • Country: ca
Re: MP3 Decoding on STM32G070RBT6
« Reply #9 on: June 18, 2022, 07:41:32 am »
Quote
Just keep in mind that there is no chance Cortex-M0+ at 64 MHz can decode MP3 in real time for playback.
Thanks Alex for the tip, But I want to do some lower bitrate MP3 files, I think it would be possible.
ASiDesigner, Stands for Application specific intelligent devices
I'm a Digital Expert from 8-bits to 64-bits
 

Offline ali_asadzadehTopic starter

  • Super Contributor
  • ***
  • Posts: 1905
  • Country: ca
Re: MP3 Decoding on STM32G070RBT6
« Reply #10 on: June 18, 2022, 07:46:54 am »
Quote
I have used this:
https://github.com/lieff/minimp3

I found the author very helpful.
Thanks brichards42,Did you use it on an embedded Part like ARM Cortex?  since I take a brief look at the minimp3.h file and see some asm functions.
ASiDesigner, Stands for Application specific intelligent devices
I'm a Digital Expert from 8-bits to 64-bits
 

Offline ali_asadzadehTopic starter

  • Super Contributor
  • ***
  • Posts: 1905
  • Country: ca
Re: MP3 Decoding on STM32G070RBT6
« Reply #11 on: June 18, 2022, 12:40:12 pm »
I have compiled the code for M3 minimp3 and it would compile fine, But for M0 it would complain about this ASM function,

I have started a new thread here,
https://www.eevblog.com/forum/microcontrollers/converting-to-cortex-m0-asm/

brichards42 Have you done it for M0 or do you suggest rewriting it for M0?
ASiDesigner, Stands for Application specific intelligent devices
I'm a Digital Expert from 8-bits to 64-bits
 

Offline brichards42

  • Contributor
  • Posts: 32
  • Country: us
Re: MP3 Decoding on STM32G070RBT6
« Reply #12 on: June 18, 2022, 10:25:29 pm »
On my project I was using a STM32F446RET.  I don't recall using any asm functions (it was several years ago), but maybe it can't work on a M0, sorry.
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14476
  • Country: fr
Re: MP3 Decoding on STM32G070RBT6
« Reply #13 on: June 18, 2022, 10:36:38 pm »
A tiny remark, the M0 and M0+ have two options for the hardware multiplier: a fast and a small one.
Fortunately, the STM32G070 has a M0+ with a single-cycle multiplier, so all hopes are not lost. If it had the "small" multiplier option, that would be a 32-cycle multiply, and then forget about it.
Of course you need to use an integer/fixed-point decoder. It has no FPU either, so any decoding using floating point would be catastrophically slow.
 

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 3360
  • Country: nl
Re: MP3 Decoding on STM32G070RBT6
« Reply #14 on: June 19, 2022, 02:12:45 pm »
But they still need quite a bit of performance to do real time decoding.

Sure, you can artificially create an mp3 file that is bad enough to be decoded on Cortex-M0+, but that does not represent a typical use case.
So what would be a typical use case for mp3 in a small microcontroller?
It's unlikely to be a HiFi quality audio player.
I'd say typical use for MP3 in a small microcontroller would be from doorbel chimes to sections of voice for an phone-connected alarm system.
I'd say that low / medium quality mono audio would be a much more "typical" use of mp3 on a small uC then full blown HiFi stereo.

I do wonder why the document below mentions patents and royalties.
https://datasheet.octopart.com/STM32-MP3NL-DEC-STMicroelectronics-datasheet-16349441.pdf

MP3 is well over 20 years old and patents have expired.

But does it have to be MP3? OGG-vorbis has always been license free and is quite comparable to MP3, and there are hundreds more specialized  codecs for more specilized codes tuned to for example use cases such as voice.
 

Offline wraper

  • Supporter
  • ****
  • Posts: 16864
  • Country: lv
Re: MP3 Decoding on STM32G070RBT6
« Reply #15 on: June 19, 2022, 02:23:26 pm »
I do wonder why the document below mentions patents and royalties.
https://datasheet.octopart.com/STM32-MP3NL-DEC-STMicroelectronics-datasheet-16349441.pdf

MP3 is well over 20 years old and patents have expired.
Patents expired 6 years later than when document was created. https://www.iis.fraunhofer.de/en/ff/amm/consumer-electronics/mp3.html
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11260
  • Country: us
    • Personal site
Re: MP3 Decoding on STM32G070RBT6
« Reply #16 on: June 19, 2022, 04:04:27 pm »
So what would be a typical use case for mp3 in a small microcontroller?
I would say the only justifiable use of MP3 in this case is you accept user files from an SDCard, for example. But in that case requiring very strict compression and quality  settings is not going to work. It is much easier to just ask people use uncompressed wave files, especially given the minimal size of the cards you can get.

If you are using it with predefined files where you are in control, then there are easier do decode compression algorithms.
Alex
 

Offline GromBeestje

  • Frequent Contributor
  • **
  • Posts: 280
  • Country: nl
Re: MP3 Decoding on STM32G070RBT6
« Reply #17 on: June 19, 2022, 04:34:48 pm »
But does it have to be MP3? OGG-vorbis has always been license free and is quite comparable to MP3, and there are hundreds more specialized  codecs for more specilized codes tuned to for example use cases such as voice.

I believe decoding OGG Vorbis requires more computational power then decoding MP3, therefore considering the target is a Cortex M0, I'd say MP3 has an advantage over OGG Vorbis.
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14476
  • Country: fr
Re: MP3 Decoding on STM32G070RBT6
« Reply #18 on: June 19, 2022, 06:49:45 pm »
You could also consider a dedicated IC such as the VLSI VS10xx series. Some support MP3 and Ogg vorbis. Dead easy to use. Of course, that's an extra cost, but only requires minimal CPU from the MCU to feed it with data. The CPU can do other things too. Unless you're using a pretty powerful MCU, if you manage to decode MP3 in real time, it's likely not going to be able to process anything else much.

 

Online westfw

  • Super Contributor
  • ***
  • Posts: 4199
  • Country: us
Re: MP3 Decoding on STM32G070RBT6
« Reply #19 on: June 20, 2022, 09:02:10 am »
Is there a compression algorithm that does somewhat better than phone-quality audio with less computational complexity it the decode phase?


(Keeping in mind that a $5 sd (4GB) card holds like 5 hours of cd-quality music with NO compression.)

 

Offline mariush

  • Super Contributor
  • ***
  • Posts: 5029
  • Country: ro
  • .
Re: MP3 Decoding on STM32G070RBT6
« Reply #20 on: June 20, 2022, 10:08:46 am »
The Sandisk Sansa Clip music players used a SoC from AMS  (Austria Micro Systems)  which ran at around 40 or 48 Mhz if my memory is correct... installed Rockbox on it and played Opus and FLAC on it just fine. But, I think the SoC had some extra hardware decoding functionality.

As for is there a compression algorithm with less computational complexity  ...  I would investigate if the old AC3 and mpeg 1 layer 2 (or whatever was used in Video CD / SVCD and old SD satellite transmissions) are lighter, as the patents expired for them ... both would use more bitrate to get same quality as MP3 but should be a bit easier to decode.

I know of libMAD , a mpeg decoding library which does everything in fixed point so it may be suited for conversion to microcontrollers

This page has a bunch of projects and mentions using libMAD with Arduino but the examples in the page use helix : https://www.pschatzmann.ch/home/2021/08/13/audio-decoders-for-microcontrollers/

Found this appnote / document which shows using libMAD and LPC2148  but that's ARM7 chip and kind of expensive at around 15-20$ : https://www.nxp.com/docs/en/application-note/AN10583.pdf

Maybe could be used with a microcontroller that has less memory and storage and more reasonably priced.
but browsing the appnote they still had to tweak it a bit to fit in the 32 KB of ram the microcontroller has, and they only used mono mp3 files because there's only one built in DAC. Not sure if the chip had enough processing power to do two channels.
edit : Ah, on page 23  it says  :
Libmad is a well-known library to decode MP3 files. Libmad is also used in the popular
free VLC player, however, as you can see in the last table, the porting of the actual
version of libmad on an ARM7 (@60 MHz) loads the CPU from the 40 % to 70 % of its
power, so only one audio channel can be decoded in real time. Browsing the web we
found one interesting alternative represented by the Helix MP3 Decoder suitable to
decode, in real time, a stereo MP3 stream. Additional audio codec is also available, like
AAC. All these codecs have a specific RCSL and RPSL license. For more info about this
codec please refer to:
 

Offline ali_asadzadehTopic starter

  • Super Contributor
  • ***
  • Posts: 1905
  • Country: ca
Re: MP3 Decoding on STM32G070RBT6
« Reply #21 on: June 20, 2022, 11:28:40 am »
Quote
All these codecs have a specific RCSL and RPSL license. For more info about this
codec please refer to:
There is no link  :'(
ASiDesigner, Stands for Application specific intelligent devices
I'm a Digital Expert from 8-bits to 64-bits
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11260
  • Country: us
    • Personal site
Re: MP3 Decoding on STM32G070RBT6
« Reply #22 on: June 20, 2022, 04:18:12 pm »
Even without hardware decoders ARM7 has a lot more performance compared to Cortex-M0+.
Alex
 

Offline mariush

  • Super Contributor
  • ***
  • Posts: 5029
  • Country: ro
  • .
Re: MP3 Decoding on STM32G070RBT6
« Reply #23 on: June 20, 2022, 09:09:17 pm »
Quote
All these codecs have a specific RCSL and RPSL license. For more info about this
codec please refer to:
There is no link  :'(

Links are in appnote but they redirect to a dead page on helixcomunity .. this was the page redirecting to in 2017

https://web.archive.org/web/20171123171114/https://www.helixcommunity.org/projects/datatype/Mp3dec
 
The following users thanked this post: ali_asadzadeh

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 3360
  • Country: nl
Re: MP3 Decoding on STM32G070RBT6
« Reply #24 on: June 22, 2022, 12:05:04 am »
I thought a bit more about it, and I think you should turn it around.

If you want to be able to decode and play MP3's, then first go fetch a library that can do it, and then choose a uC that can do it relatively comfortably. If you go squeezing pennies and go for the smallest uC that should sort of be able to maybe do it, then it's quite likely you spend an exorbitant amount of time on tuning the software or fabricating audio files that are quick enough to decode, and this is only cost effective if you plan to sell really big numbers of devices, and even then it may be best to get to market quick with a "too big" uC, and get some experience with MP3 decoding in the beginning, and then later downscale to a smaller uC.
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5907
  • Country: es
Re: MP3 Decoding on STM32G070RBT6
« Reply #25 on: June 22, 2022, 10:43:13 am »
Doesn't make sense at all. Just use some unexpensive dedicated solution.
Then you can take a much cheaper mcu, as you no longer need heavy processing.
You

It took me 15 minutes to get the DFplayer working:



There're lots of low-cost specialized decoders like these.
Check Waytronic products... You might want to contact them, here's the english site: www.wtsoundic.com

The WT2003Hx series are interesting: Decode MP3, have different control bus types (UART, 1-wire, i2c...), integrate a 0.5W amplifier and some have built-in storage.
WT2003H0-16S, $0.70 buying 30, uart control, no storage (external SPI flash).
WT2003H4-16S, Same but adding 4M storage, giving about 340 seconds of audio.
They also have modules.
Attached the google-translated WT2003x datasheet.

English catalog: https://www.wtsoundic.com//wp-content/uploads/dlm_uploads/2021/12/Waytronic-Catalog-updated-on-17-Feb-2022.pdf
Its says the WT2003H series have other versions with 80 and 800s of audio storage.
« Last Edit: June 22, 2022, 11:36:10 am by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 
The following users thanked this post: evb149, brichards42

Offline ali_asadzadehTopic starter

  • Super Contributor
  • ***
  • Posts: 1905
  • Country: ca
Re: MP3 Decoding on STM32G070RBT6
« Reply #26 on: June 23, 2022, 06:50:28 am »
Thanks david for the info
ASiDesigner, Stands for Application specific intelligent devices
I'm a Digital Expert from 8-bits to 64-bits
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf