- Home /
Loading Audio Files at Runtime for Playback and Processing
Hi,
I am currently trying to implement something where (on Android, iOS & PC) mp3s are loaded at runtime and played back to the user. I also need to be able to access the raw PCM data to do some processing on it.
Using the WWW class is no option, because that eats memory like no other. (Even if that weren't a problem, due to a bug in the getData method of AudioClip I can not access the raw data, once I've created an AudioClip from a file loaded through the WWW class. And then it also won't read mp3s on some platforms)
I have tried various libraries and so far only paid ones worked (fmod, etc), but these are not an option for me. (I need an open source solution)
Currently trying to get ffmpeg to work, but none of the C# wrappers I have found seem to be any good. The neat thing about it is that it uses streams though, which greatly reduces memory usage especially when handling PCM data. ....If I could just get it to work.
Does anyone have any experience in that regard? Help with either ffmpeg or another approach would be greatly appreciated! :)
Thanks!
Answer by jack_rabbit · Aug 22, 2012 at 10:54 AM
Update: Getting to the end of the project and thought I'd let everyone know how we worked around it.
As stated before, loading the entire song into unity through WWW eats memory. It allocates roughly 2x-3x the songs full PCM size (which for a 3 minute mp3 means about 2x-3x 60MB!).
So what we did was to compile mpg123 for ARMv7, find a C# wrapper for it and decode the mp3's "by hand". This was a bit of a hassle to get working, but it works and does so quick(ish). Because we use plugins this means that only pro/mobile users can do this though.
This approach limits us to solely mp3s (and WAVs), but due to licensing we wouldn't be able to afford to decode m4a/aac anyway.
dear jack rabbit! i'am searching for a solution to playback mp3 from filesystem. i still don't now why but the www class doesn't support the playback on iOS from filesytem "file://". i was researching on a solution using mpg123 but if i think of a commerical game - isn't mpg123 gpl? and isn't the mp3 license expensive aswell? can you help me with some background information? kind regards.
Your answer
Follow this Question
Related Questions
Which AudioClip formats will decompress using hardware? 0 Answers
How to Import .mp3 and use it as AudioClip 1 Answer
Android play mp3 file 0 Answers
Playing mp3 files on Android 1 Answer