mono/MonoGame — pull request #1841 by flibitijibibo (2013-07-06 21:08:35+00:00)
Title: Significantly improve OpenAL performance/memory usage.

This pull request addresses two primary flaws in the current OpenAL audio backend for MonoGame:

___1. Audio data is needlessly held on to after it has been given to OpenAL.___

You will notice that we remove byte[] arrays in OALSoundBuffer and SoundEffectInstance in this patch. The code in those files implies that we need the data for purposes other than loading directly into OpenAL, but no code in MonoGame currently uses this. So, we essentially keep a duplicate copy of _every single OpenAL buffer_ for the duration of the program's runtime unless we explicitly destroy the data ourselves.

By simply removing these from the files, we improve memory use drastically, and for XACT, we improve it _by at least 50%_.

___2. Redundant decoding/rewriting of wavedata is performed presumably to reuse the public API.___

While it makes sense on paper, the fact is we're decoding wavedata only to reencode it when we're "done" in a single method multiple times for every single audio file that gets loaded into MonoGame. This can possibly introduce memory problems like those found in bullet one, and it's also a pretty goofy waste of resources when we can just send the data to internal methods that will eventually give it to OpenAL.

By fixing these two issues, performance for XACT/SoundEffects on OpenAL has improved immensely (mostly in regard to memory use, CPU use certainly improves but is not noticeable on high-end machines).