kira icon indicating copy to clipboard operation
kira copied to clipboard

Implementing a custom file format is annoying

Open DCNick3 opened this issue 2 years ago • 4 comments
trafficstars

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.

DCNick3 avatar Jan 06 '23 23:01 DCNick3

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.

tesselode avatar Mar 18 '23 04:03 tesselode

@DCNick3 following up on this, can you tell me about your game engine? Why do you have a custom audio format?

tesselode avatar Apr 02 '23 19:04 tesselode

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

DCNick3 avatar Apr 03 '23 12:04 DCNick3

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.

tesselode avatar May 23 '23 02:05 tesselode