Skip to content

Commit

Permalink
use AudioParamDescriptor automation rate
Browse files Browse the repository at this point in the history
  • Loading branch information
b-ma committed May 9, 2024
1 parent a47694f commit 493d9f4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
8 changes: 7 additions & 1 deletion js/AudioWorkletGlobalScope.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,13 @@ parentPort.on('message', event => {
};

processorOptions[kHiddenOptions] = hiddenOptions;
const instance = new ctor(processorOptions);
let instance;

try {
instance = new ctor(processorOptions);
} catch (err) {
console.log(err.message);
}
// store in global so that Rust can match the JS processor
// with its corresponding NapiAudioWorkletProcessor
globalThis[`${id}`] = instance;
Expand Down
2 changes: 1 addition & 1 deletion src/audio_param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fn set_automation_rate(ctx: CallContext) -> Result<JsUndefined> {
let value = match utf8_str.as_str() {
"a-rate" => AutomationRate::A,
"k-rate" => AutomationRate::K,
_ => panic!("TypeError - The provided value '{:?}' is not a valid enum value of type AutomationRate.", utf8_str),
_ => unreachable!(),
};
obj.set_automation_rate(value);

Expand Down
14 changes: 11 additions & 3 deletions src/audio_worklet_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use web_audio_api::worklet::{
AudioParamValues, AudioWorkletGlobalScope, AudioWorkletNode, AudioWorkletNodeOptions,
AudioWorkletProcessor,
};
use web_audio_api::AudioParamDescriptor;
use web_audio_api::{AudioParamDescriptor, AutomationRate};

use std::cell::Cell;
use std::collections::HashMap;
Expand Down Expand Up @@ -322,12 +322,20 @@ fn constructor(ctx: CallContext) -> Result<JsUndefined> {
.get_double()
.unwrap() as f32;

let param_descriptor = web_audio_api::AudioParamDescriptor {
let js_str = param.get_named_property::<JsString>("automationRate")?;
let utf8_str = js_str.coerce_to_string()?.into_utf8()?.into_owned()?;
let automation_rate = match utf8_str.as_str() {
"a-rate" => AutomationRate::A,
"k-rate" => AutomationRate::K,
_ => unreachable!(),
};

let param_descriptor = AudioParamDescriptor {
name,
min_value,
max_value,
default_value,
automation_rate: web_audio_api::AutomationRate::A,
automation_rate,
};

rs_params.insert(i, param_descriptor);
Expand Down

0 comments on commit 493d9f4

Please sign in to comment.