Hi, does anyone have an example on how to implemen...
# javascript
r
Hi, does anyone have an example on how to implement an AudioWorkletProcessor in kotlin? According to the documentation it should be possible to just override the external class AudioWorkletProcessor but I get the following error in chrome: AudioWorklet.kt:55 Uncaught TypeError: Failed to execute 'registerProcessor' on 'AudioWorkletGlobalScope': Property "process" doesn't exist This is how I defined the external interface:
Copy code
external interface AudioWorkletProcessor {

    fun process(
        inputs: dynamic,
        outputs: dynamic,
        parameters: dynamic
    ): Boolean

}
This is the actual class:
Copy code
class MyAudioProcessor : AudioWorkletProcessor {

    override fun process(
        inputs: dynamic,
        outputs: dynamic,
        parameters: dynamic
    ): Boolean {
        println("process")
        if (outputs.isNotEmpty()) {
            if (outputs[0].size == 2) {
                println("found one output with 2 channels")
            }
        }

        return true
    }

}
The registerProcessor function expects a class constructor, I use ::MyAudioProcessor. Maybe that should be something else? Btw, firefox gives this error message: TypeError: Return value of AudioWorkletProcessorConstructor does not implement interface AudioWorkletProcessor.
t
Possibly port required
I use ::MyAudioProcessor
Try
MyAudioProcessor::class.js
instead
r
Ah, great. The ::class.js was the problem. Thx!
Hmm, this didn't actually work, it doesn't give an error but it also doesn't give me an actual AudioWorkletProcessor, just some object which doesn't do anything.
Looks like the AudioWorkletProcessor needs to be defined as a class. But if I do that I get the following error: Uncaught TypeError: Failed to construct 'AudioWorkletProcessor': Please use the 'new' operator, this DOM object constructor cannot be called as a function. at new ol (AudioWorklet.kt:24)
Btw, I am trying this with version 1.4-M2, so it wouldn't surprise me if there is a bug in the javascript generation.
t
Looks like you need ES6 target for
AudioWorkletProcessor