Manage compressed sounds from VPX (mp3, ogg)
For now, we only support uncompressed PCM sounds from VPX for creating AudioClips. Compressed sounds are almost loaded (except the WaveForm skip for non Wav files, which crash).
In VPX, compressed sounds are totally handled by Bass audio engine.
In Unity, there is no AudioClip format conversion API, as we have on Textures. The conversion is only done by AudioAssetImporter afaik.
I found some workarounds to create AudioClip directly from byte[] embedded in VPX SoundData, only one seemed to almost working, Using a UnityWebRequestMultimedia to extract an AudioClip from an url. It can be made in two ways : - write the byte[] content in a temporary file then read it back using a file:// url - set a HttpListener on localhost and catch the reading callbacks to feed the buffer with the byte[] content. I tried the second version, had some results with the Vorbis format sound only, trying wth a mp3 fired an exception saying mpeg format was not handled for streaming.
So i was wondering if we want to create sound assets as we do for textures then create AudioClips from those? Or if we want to find a way to create AudioClips on the fly directly from the SoundData.Data field using some multi-platform sound conversion library ?
Having sounds assets will also make the SoundManager sound creation/import/export process closer to the ImageManager way of handling Textures.
I would definitely extract the data and create audio assets. A) I'm pretty sure this will be considerably easier, and B) It puts them into the regular asset pipeline so they can be appropriately encoded for the final target platform, etc.
Thanks @ecurtz , yeah totally agree with you, Asset will be way better. Do you know why Mesh, Material & Textures assets are not visible in the Project Window ? If i do the same for Sounds, using AssetDatabase.CreateAsset, will they be also invisible ?
I believe they don't show up in the project because the other objects are being created in memory from the VPX data rather than converted into Unity assets during load. Anything created with AssetDatabase.CreateAsset will be persistent (and visible in the project unless you deliberately go out of your way to hide it.)