kira
kira copied to clipboard
Implementing a custom file format is annoying
I am writing a game engine that has to support some custom audio format that wouldn't make sense to include in the library, so I am trying to make my own types to implement SoundData and Sound traits.
It does seem possible to implement it, but I have to duplicate a lot of code from kira: managing volume, panning, resampling audio... Ideally I would like to implement some trait that returns sample rate & decodes audio packets on demand, without copying half of kira into my impls.
One simple solution would be to use StaticSoundData, but I need to use streaming for better loading latency.
My original intention was that people who need support for different formats should just contribute to Symphonia, but in the case of custom formats that wouldn't make sense. IIRC the current streaming sound implementation does have a Decoder interface, so I'll likely expose that in the next version of Kira.
@DCNick3 following up on this, can you tell me about your game engine? Why do you have a custom audio format?
It's a re-implementation of an existing commercial VN game engine, to make it possible run games written for it on new platforms (PC and maybe web). I want it to work on purely original game files, without any conversions, hence the need for custom format support.
The audio format is just a weird container for opus btw, nothing fancy.
The kira glue is implemented here: https://github.com/DCNick3/shin/tree/master/shin-audio/src. It duplicates a lot of functionality...
As a side note, IDK if it's a good idea, but I do audio decoding in the audio thread. Seems to work fine and has an added bonus of being more easy to port to wasm
Kira v0.8.0 exposes the Decoder trait, although streaming sounds do still create an extra thread for scheduling the decoder, so that won't work on wasm just yet.