Skip to content

Commit 69bb93c

Browse files
committed
Worklets. Use AudioWorkletProcessorReference
1 parent 8cb5d7d commit 69bb93c

File tree

3 files changed

+16
-21
lines changed

3 files changed

+16
-21
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package mdn.audioworklet.example
22

33
import web.audio.AudioParamName
4+
import web.audio.AudioWorkletProcessorName
45

5-
internal val HISS_GENERATOR: String =
6-
"hiss-generator"
6+
internal val HISS_GENERATOR: AudioWorkletProcessorName =
7+
AudioWorkletProcessorName("hiss-generator")
78

89
internal val GAIN: AudioParamName =
910
AudioParamName("gain")

tests/worklets/mdn-audioworklet-example/src/commonMain/kotlin/mdn/audioworklet/example/HissGeneratorProcessor.kt

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import js.typedarrays.Float32Array
66
import web.audio.AudioParamDescriptor
77
import web.audio.AudioParamName
88
import web.audio.AudioWorkletProcessor
9-
import web.audio.AudioWorkletProcessorCompanion
9+
import web.audio.AudioWorkletProcessorReference
1010
import kotlin.random.Random
1111

1212
/**
@@ -78,22 +78,15 @@ class HissGeneratorProcessor : AudioWorkletProcessor() {
7878
return true
7979
}
8080

81-
companion object : AudioWorkletProcessorCompanion {
82-
override val parameterDescriptors: ReadonlyArray<AudioParamDescriptor> =
83-
arrayOf(
84-
AudioParamDescriptor(
85-
name = GAIN,
86-
defaultValue = 0.2f,
87-
minValue = 0f,
88-
maxValue = 1f,
89-
)
81+
companion object : AudioWorkletProcessorReference<HissGeneratorProcessor>(
82+
value = HissGeneratorProcessor::class.js,
83+
parameterDescriptors = arrayOf(
84+
AudioParamDescriptor(
85+
name = GAIN,
86+
defaultValue = 0.2f,
87+
minValue = 0f,
88+
maxValue = 1f,
9089
)
91-
92-
// TODO: Remove when `@JsStatic` will work in development mode
93-
val classRef: JsClass<out AudioWorkletProcessor> by lazy {
94-
val klass = HissGeneratorProcessor::class.js
95-
klass.asDynamic().parameterDescriptors = parameterDescriptors
96-
klass
97-
}
98-
}
90+
)
91+
)
9992
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package mdn.audioworklet.example
22

33
import web.audio.AudioWorkletModule
4+
import web.audio.registerProcessor
45

56
val HissGeneratorWorkletModule = AudioWorkletModule { self ->
6-
self.registerProcessor(HISS_GENERATOR, HissGeneratorProcessor.classRef)
7+
self.registerProcessor(HISS_GENERATOR, HissGeneratorProcessor)
78
}

0 commit comments

Comments
 (0)