Shop OBEX P1 Docs P2 Docs Learn Events
MP3 playback from Flash — Parallax Forums

MP3 playback from Flash

Wuerfel_21Wuerfel_21 Posts: 5,105
edited 2024-12-11 23:35 in Propeller 2

So the idea came up of making a Bad Apple player that fits in the P2's 16MB boot flash.
The graphics are obviously the challenging part, so I first looked into audio (ostensibly a solved issue).
I went on a little detour trying to get libtremor working for OGG playback, that was too bloated, so in the end I grabbed the Helix MP3 library instead.

Surprisingly it runs really well even without any special optimization. I did optimize a hot spot in PolyphaseStereo to get a nice gain though. Roughly 50% CPU utilization (of one cog) at 280Mhz, not bad. Could certainly be improved much further.

Grab a (rather low bitrate) MP3 here: https://mega.nz/file/mPxQHLbQ#l_rnBF2YR_rrakyvmEHpznfbcrqIC0hOm4xLoc-4dY0
Of course you can use any file you like - though you need to strip any ID3 tags - there'd be a way to skip over them, but you really don't want them in there, anyways.

To program it into flash, you need the latest loadp2 version:

loadp2 @80100000=badapple_cbr.mp3 -FLASH -HIMEM=flash

(this takes a couple seconds to complete)

Then build and load/flash the C program.

Caution: For nebulous reasons having flexspin's experimental flag enabled causes glitched and warbly audio (beyond that which is inherent to MP3). That will be very cool and not at all annoying to debug.

Comments

  • RaymanRayman Posts: 14,752

    Interesting... Don't get the bad apple reference though...

    Was actually thinking of something similar that you might know how to do...
    Think it would be cool to be able to play lossless audio over HDMI while showing a static image.
    Sorta a high quality juke box type thing.

    Would be nice for Xmas time, for example, for playing XMAS music on the TV in a not so annoying way...

  • roglohrogloh Posts: 5,837

    Think it would be cool to be able to play lossless audio over HDMI while showing a static image.

    That would be achievable. I already did WAV playback in my text mode demo so I could quickly whip up another quick binary if there's some nice static gfx image available but maybe not put together a full control gui with mouse control & file selection etc. All it does right now is play/pause, seek+/-, volume +/- and skip to next found WAV file via serial key presses. It would be nicer to add a USB mouse/keyboard interface to control this rather than an attached PC, or better yet via IR remote, but then you need to add learning capabilities. Who knows, maybe Ada will have time to make a version using NeoVGA.

    Right now I've now got a bunch of other things on my plate to sort out before Xmas, so I'm not at all confident my new upcoming driver source release will be done by then, but hopefully I will have more time in Jan to continue to work it after that and wrap up full documentation & more demos.

    I noticed one thing in the source posted above - some apostrophes in numeric constants. Never seen that before in all my C/C++ coding years. Did some googling and found this... you learn something every day.

    "In C++14, integer literals were updated to allow an optional ' separator."

  • roglohrogloh Posts: 5,837
    edited 2024-12-12 05:32

    @Rayman, here's a quick binary demo (LOL I know Ada loves these) that plays 44.1kHz stereo WAV files from SD and displays a static graphics image over HDMI and optionally VGA. Right now it does only 320x240 BMP truecolour 24bpp (no transparency) to fit in HUB RAM. Reads and displays "image.bmp" file from SD root folder along with up to 100 WAV files (in 8.3 filenames) for playback.

    Uses serial console @115200 to control playback - press ? to get help. BMP file parsing is very rudimentary so YMMV. Be sure to make it the correct 320x240 resolution or it won't display right. Top level SPIN2 source is provided so you can see what it's doing.

    You can also customize the base pins for DVI/HDMI and VGA output by placing conf.txt file on the SD card. If a VGA breakout is present it should also playback stereo analog on VGA_base_pin + 6 and +7 offsets as well as over HDMI.

    Let me know if this works for you. I might be able to customize it further for full 640x480 at lower HUB memory use with an 8 bit palette, or full VGA truecolor if using external PSRAM.

    ❯ cat conf.txt
    32 24
    put hdmi base pin first on line 1 followed by vga base pin on same line or omit vga pin number for no vga output

  • pik33pik33 Posts: 2,387

    @Wuerfel_21 said:
    so in the end I grabbed the Helix MP3 library instead.

    Does this work better/faster than this Adafruit mp3 decoder that Eric put here some time ago and then I used it in my media player?

  • roglohrogloh Posts: 5,837
    edited 2024-12-12 11:48

    Here's an updated demo WAV version that now also allows 8bpp mode palettized BMP images - it will display the image as 640x480 pixels if 8, 4, 2, or 1 bpp is defined in the BMP file, otherwise it still displays pixel doubled 320x240 for 24 bpp BMP files so it fits in HUB RAM. I only tested with a single 8bpp image and the previous 24bpp test image file so YMMV. You can use your own 8 bit palette BMP files at 640x480. Just name it image.bmp on the SD card.

    A gorgeous royalty free test image is included in the zip for testing 😂 - sourced from my own photos and converted to an 8bpp palettized BMP using GIMP.

  • @rogloh said:
    A gorgeous royalty free test image is included in the zip for testing 😂 - sourced from my own photos and converted to an 8bpp palettized BMP using GIMP.

    Mitchell & Pollock would be proud !!

  • @pik33 said:

    @Wuerfel_21 said:
    so in the end I grabbed the Helix MP3 library instead.

    Does this work better/faster than this Adafruit mp3 decoder that Eric put here some time ago and then I used it in my media player?

    I don't know! I vaguely remembered someone talking about it, but couldn't find it, so I thought that I just misremembered and just dug this up instead. Considering this runs well with minimal optimizations, it's probably a toss-up?

  • pik33pik33 Posts: 2,387

    Maybe I will try this library and compare.
    You didn't misremember. There was Adafruit's mp3 library that Eric brought here. I converted it to one c file instead of bunch of c/h it originally was.
    Having a working mp3 library I added it my media player so it can play mp3s from SD card. The player is another project I didn't touch for over a year and I have to check if it still compiles using new Flexprop.

Sign In or Register to comment.