Skip to content

Using With Heaps or OpenFL

Using grig's audio callback in heaps or openfl

When linking to both and heaps haxelibs, uses heaps' NativeAudioChannel for AudioInterface. That can be disabled by defining DISABLE_HEAPS_AUDIO_INTERFACE (using -D DISABLE_HEAPS_AUDIO_INTERFACE) if you wish to use grig's other abstractions instead. You can also define your own if you disable any other predefined audio interface. See AudioInterface.hx. This might be useful if you want to use heaps or openfl for visual component, but bypass its audio system.

It may be confusing that heaps is a dependency whether you're using heaps or openfl. This is simply because detects if heaps is available and by default uses it's NativeAudioChannel interface. When linking to both heaps and openfl, heaps' NativeAudioChannel actually abstracts over openfl's audio system. Don't worry. Due to dead code elimination, only the relevant code will end up in the final output so it's not akin to, say, linking an additional redundant graphic framework's dll in a c++ application.

Simply connect as you usually would with an audio callback, but the options have no effect if you're using heaps' or openfl's audio system:

var audioInterface_ = new AudioInterface();
var = { outputNumChannels: 2 };
audioInterface_.openPort(options).handle(function(audioOutcome) {
switch audioOutcome {
case Success(_):
audioInterface = audioInterface_;
case Failure(error):

With audioInterface being an audio callback:

private function audioCallback(,, sampleRate:Float,
// Write audio to output here