sysaudio: webaudio: Set internal buffer size to 512
It was 4096 before. Lower values means lower latency but higher values are needed for clear audio. It should be properly tested across multiple browsers to find out the correct default value, or create a formula to auto calculate it. It should always be a multiple of 2 in the range 256, 512, ..., 8192, 16384.
This commit is contained in:
parent
4c264c80cd
commit
c22e54bcd7
1 changed files with 3 additions and 4 deletions
|
|
@ -54,6 +54,7 @@ pub fn waitEvents(_: Audio) void {}
|
||||||
|
|
||||||
const default_channel_count = 2;
|
const default_channel_count = 2;
|
||||||
const default_sample_rate = 48000;
|
const default_sample_rate = 48000;
|
||||||
|
const default_buffer_size = 512;
|
||||||
|
|
||||||
pub fn requestDevice(audio: Audio, config: DeviceDescriptor) Error!Device {
|
pub fn requestDevice(audio: Audio, config: DeviceDescriptor) Error!Device {
|
||||||
// NOTE: WebAudio only supports F32 audio format, so config.format is unused
|
// NOTE: WebAudio only supports F32 audio format, so config.format is unused
|
||||||
|
|
@ -71,7 +72,7 @@ pub fn requestDevice(audio: Audio, config: DeviceDescriptor) Error!Device {
|
||||||
const input_channels = if (mode == .input) js.createNumber(@intToFloat(f64, channels)) else js.createUndefined();
|
const input_channels = if (mode == .input) js.createNumber(@intToFloat(f64, channels)) else js.createUndefined();
|
||||||
const output_channels = if (mode == .output) js.createNumber(@intToFloat(f64, channels)) else js.createUndefined();
|
const output_channels = if (mode == .output) js.createNumber(@intToFloat(f64, channels)) else js.createUndefined();
|
||||||
|
|
||||||
const node = context.call("createScriptProcessor", &.{ js.createNumber(4096), input_channels, output_channels }).view(.object);
|
const node = context.call("createScriptProcessor", &.{ js.createNumber(default_buffer_size), input_channels, output_channels }).view(.object);
|
||||||
defer node.deinit();
|
defer node.deinit();
|
||||||
|
|
||||||
context.set("node", node.toValue());
|
context.set("node", node.toValue());
|
||||||
|
|
@ -88,9 +89,7 @@ pub fn requestDevice(audio: Audio, config: DeviceDescriptor) Error!Device {
|
||||||
_ = node.call("connect", &.{destination.toValue()});
|
_ = node.call("connect", &.{destination.toValue()});
|
||||||
}
|
}
|
||||||
|
|
||||||
return Device{
|
return Device{ .context = context };
|
||||||
.context = context,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn audioProcessEvent(args: js.Object, _: usize) js.Value {
|
fn audioProcessEvent(args: js.Object, _: usize) js.Value {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue