haxe-fmod icon indicating copy to clipboard operation
haxe-fmod copied to clipboard

[Enhancement] Support user created sound

Open EliteMasterEric opened this issue 2 years ago • 1 comments

I have a use case where I am being provided with a stream of PCM audio bytes (from video decoding) and I want to play the sound over the user's speakers. OpenFL doesn't provide a means to implement this (I checked, this class is not implemented on most platforms, just Flash). Thankfully, FMod does, but haxe-fmod has not implemented a user-facing interface for it.

Implement the ability to create a sound which, rather than loading from a sound file, continuously executes a callback to retrieve the sound data to be output.

The sound should be created with the FMOD_OPENUSER, and be initialized with an FMOD_CREATESOUNDEXINFO to specify format, defaultfrequency, numchannels, and a read callback. The read callback would probably need to be a wrapper callback, which would call a Haxe function (not a CPP function) provided by the user, which would return an openfl.utils.ByteArray. The wrapper callback would then provide the pointer and length to the sound for playback.

See the api/core/examples/user_created_sound.cpp for an example of this, but in CPP rather than Haxe.

EliteMasterEric avatar Sep 27 '21 08:09 EliteMasterEric