- Home /
Why is Unity3d strictly using PCM Buffer size with 32bit floating in AudioClip?
unity3d includes below of PCM audio functions:
AudioClip.Create, AudioClip.PCMReaderCallback, AudioClip.SetData ---> it is a 32bit float array.
Usually, MP3, OGG Vorbis and WAV use 16bit buffer size because of the hardware size and Ram issues. However, In Unity3d, AudioDatas Convert 32bit float (-1.0f ~ 1.0f) instead of 16bit short (-32767 ~ 32767) as usual. ie) 2min 16bit stereo 44100 hz Audio File Converted as below
120sec x 2(stereo) x 2(16bit-short) x 44100 = 21168000 byte
21168000 / 1024 / 1024 = 20.2 MB.
But in Unity3d,
120sec x 2(stereo) x 4(32bit-float) x 44100 = 42336000 byte
42336000 / 1024 / 1024 = 40.4 MB. (twice bigger than ordinary audio converted system)
It means whenever I convert audio datas(such as ogg/mp3) to PCM, It uses twice data size than other platforms.
It doesn’t matter when using unity3d in PC or MAC, But the problem is in Mobile platform for our team which uses many soundData files to make music games. (I already have some issues with ‘iOS – didReceiveMemoryWarning()’ Problems which caused by twice bigger converted memory)
Do I Have to Using OpenAL or OpenSL-ES instead of Unity3d Audiosystem to avoid this issue?
(FYI : Unity3d uses mp3 which restrict converted from ogg, I uses ogg vorbis decoder(from http://ogg.org) to using ogg in mobile platform. Do you guys can include ogg decoder in unity3d as a standard library?)
Answer by ipeerbhai · Mar 15, 2017 at 09:13 PM
The answer is quanitzation noise. PCM16 is much more susceptible to this kind of noise when mixing channels. Most audio engines that mix samples use IEEEFloat32 for audio samples today, and PCM16 is really relegated to Windows or other "ancient" Wav formats.
Converting samples between Float and PCM16 is easy -- just do: int16 thisSample = (int16)(AudioClip.Data[sampleIndex] * int16.MaxValue);
Your answer
Follow this Question
Related Questions
Existing solution for load MP3 from disc ? 2 Answers
Decrease volume of individual sounds over time 0 Answers
Audio: -3db automatic attenuation on any audio playing? 0 Answers
Question about audio (AudioSource). My ingame sound doesn't sound like the original audio file? 3 Answers
Stop audiosource clip from playing 1 Answer