MP3 Decoding on STM32G070RBT6 - Page 1
Forum section: electronics / general

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: June 16, 2022, 12:54:45 pm
content: Hi,I want to try Decoding MP3 on this part, do you recommend any light weight opensource library?

author: DavidAlfa
author_rank: Super Contributor
timestamp: June 16, 2022, 04:52:32 pm
content: This one uses helix mpr decoder:https://github.com/lamilami/stm32-mp3player

author: ataradov
author_rank: Super Contributor
timestamp: June 16, 2022, 05:08:07 pm
content: Just keep in mind that there is no chance Cortex-M0+ at 64 MHz can decode MP3 in real time for playback.

author: brichards42
author_rank: Contributor
timestamp: June 16, 2022, 05:17:56 pm
content: I have used this:https://github.com/lieff/minimp3I found the author very helpful.

author: SiliconWizard
author_rank: Super Contributor
timestamp: June 16, 2022, 07:08:10 pm
content: Quote from: ataradov on June 16, 2022, 05:08:07 pmWell 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.

author: DavidAlfa
author_rank: Super Contributor
timestamp: June 17, 2022, 01:59:09 am
content: There're mp3 decoders using fixed point math.While not 100.000000% accurate, they do the job

author: ataradov
author_rank: Super Contributor
timestamp: June 17, 2022, 02:02:32 am
content: 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.

author: DavidAlfa
author_rank: Super Contributor
timestamp: June 17, 2022, 02:16:28 am
content: IIRC 48MHz where more than enough on an optimized arm system.Helix is fixed point

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: June 18, 2022, 07:40:43 am
content: QuoteThanks david, But it uses some asm functions that are only supported from Cortex M3 upwards.

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: June 18, 2022, 07:41:32 am
content: QuoteThanks Alex for the tip, But I want to do some lower bitrate MP3 files, I think it would be possible.

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: June 18, 2022, 07:46:54 am
content: QuoteThanks 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.

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: June 18, 2022, 12:40:12 pm
content: 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?

author: brichards42
author_rank: Contributor
timestamp: June 18, 2022, 10:25:29 pm
content: 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.

author: SiliconWizard
author_rank: Super Contributor
timestamp: June 18, 2022, 10:36:38 pm
content: 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.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: June 19, 2022, 02:12:45 pm
content: Quote from: ataradov on June 17, 2022, 02:02:32 amSo 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.pdfMP3 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.

author: wraper
author_rank: Unknown
timestamp: June 19, 2022, 02:23:26 pm
content: Quote from: Doctorandus_P on June 19, 2022, 02:12:45 pmPatents expired 6 years later than when document was created.https://www.iis.fraunhofer.de/en/ff/amm/consumer-electronics/mp3.html

author: ataradov
author_rank: Super Contributor
timestamp: June 19, 2022, 04:04:27 pm
content: Quote from: Doctorandus_P on June 19, 2022, 02:12:45 pmI 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.

author: GromBeestje
author_rank: Frequent Contributor
timestamp: June 19, 2022, 04:34:48 pm
content: Quote from: Doctorandus_P on June 19, 2022, 02:12:45 pmI 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.

author: SiliconWizard
author_rank: Super Contributor
timestamp: June 19, 2022, 06:49:45 pm
content: 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.

author: westfw
author_rank: Super Contributor
timestamp: June 20, 2022, 09:02:10 am
content: 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.)

author: mariush
author_rank: Super Contributor
timestamp: June 20, 2022, 10:08:46 am
content: 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 microcontrollersThis 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.pdfMaybe 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 popularfree VLC player, however, as you can see in the last table, the porting of the actualversion of libmadon an ARM7 (@60 MHz) loads the CPU from the 40 % to 70 %of itspower, so only one audio channel can be decoded in real time. Browsing the web wefound one interesting alternative represented by the Helix MP3 Decoder suitable todecode, in real time, a stereo MP3 stream. Additional audio codec is also available, likeAAC. All these codecs have a specific RCSL and RPSL license. For more info about thiscodec please refer to:

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: June 20, 2022, 11:28:40 am
content: QuoteThere is no link

author: ataradov
author_rank: Super Contributor
timestamp: June 20, 2022, 04:18:12 pm
content: Even without hardware decoders ARM7 has a lot more performance compared to Cortex-M0+.

author: mariush
author_rank: Super Contributor
timestamp: June 20, 2022, 09:09:17 pm
content: Quote from: ali_asadzadeh on June 20, 2022, 11:28:40 amLinks are in appnote but they redirect to a dead page on helixcomunity .. this was the page redirecting to in 2017https://web.archive.org/web/20171123171114/https://www.helixcommunity.org/projects/datatype/Mp3dec

author: Doctorandus_P
author_rank: Super Contributor
timestamp: June 22, 2022, 12:05:04 am
content: 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.

author: DavidAlfa
author_rank: Super Contributor
timestamp: June 22, 2022, 10:43:13 am
content: 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.YouIt 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.comThe 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 havemodules.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.pdfIts says the WT2003H series have other versions with 80 and 800s of audio storage.

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: June 23, 2022, 06:50:28 am
content: Thanks david for the info