Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experiment with thread local pool of audio render quanta #511

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
2 changes: 1 addition & 1 deletion .github/workflows/msrv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:

- name: Install Rust toolchain
# Aligned with `rust-version` in `Cargo.toml`
uses: dtolnay/rust-toolchain@1.71
uses: dtolnay/rust-toolchain@1.73

- name: Check out repository
uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ include = [
"LICENSE",
"README.md",
]
rust-version = "1.71"
rust-version = "1.73"

[dependencies]
arc-swap = "1.6"
Expand Down
25 changes: 10 additions & 15 deletions src/param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1658,10 +1658,9 @@ pub(crate) fn audio_param_pair(
mod tests {
use float_eq::assert_float_eq;

use crate::context::{BaseAudioContext, OfflineAudioContext};
use crate::render::Alloc;

use super::*;
use crate::context::{BaseAudioContext, OfflineAudioContext};
use crate::render::AudioRenderQuantumChannel;

#[test]
#[should_panic]
Expand Down Expand Up @@ -3397,8 +3396,6 @@ mod tests {

#[test]
fn test_varying_param_size_modulated() {
let alloc = Alloc::with_capacity(1);

// buffer length is 1 and input is silence (no modulation)
{
let context = OfflineAudioContext::new(1, 1, 48000.);
Expand All @@ -3417,10 +3414,10 @@ mod tests {
assert_float_eq!(vs, &[0.; 1][..], abs_all <= 0.);

// mix to output step, input is silence
let signal = alloc.silence();
let signal = AudioRenderQuantumChannel::silence();
let input = AudioRenderQuantum::from(signal);

let signal = alloc.silence();
let signal = AudioRenderQuantumChannel::silence();
let mut output = AudioRenderQuantum::from(signal);

render.mix_to_output(&input, &mut output);
Expand All @@ -3447,11 +3444,11 @@ mod tests {
assert_float_eq!(vs, &[0.; 1][..], abs_all <= 0.);

// mix to output step, input is not silence
let signal = alloc.silence();
let signal = AudioRenderQuantumChannel::silence();
let mut input = AudioRenderQuantum::from(signal);
input.channel_data_mut(0)[0] = 1.;

let signal = alloc.silence();
let signal = AudioRenderQuantumChannel::silence();
let mut output = AudioRenderQuantum::from(signal);

render.mix_to_output(&input, &mut output);
Expand All @@ -3466,7 +3463,6 @@ mod tests {

#[test]
fn test_k_rate_makes_input_single_valued() {
let alloc = Alloc::with_capacity(1);
let context = OfflineAudioContext::new(1, 1, 48000.);

let opts = AudioParamDescriptor {
Expand All @@ -3483,13 +3479,13 @@ mod tests {
assert_float_eq!(vs, &[0.; 1][..], abs_all <= 0.);

// mix to output step, input is not silence
let signal = alloc.silence();
let signal = AudioRenderQuantumChannel::silence();
let mut input = AudioRenderQuantum::from(signal);
input.channel_data_mut(0)[0] = 1.;
input.channel_data_mut(0)[1] = 2.;
input.channel_data_mut(0)[2] = 3.;

let signal = alloc.silence();
let signal = AudioRenderQuantumChannel::silence();
let mut output = AudioRenderQuantum::from(signal);

render.mix_to_output(&input, &mut output);
Expand All @@ -3501,7 +3497,6 @@ mod tests {

#[test]
fn test_full_render_chain() {
let alloc = Alloc::with_capacity(1);
// prevent regression between the different processing stage
let context = OfflineAudioContext::new(1, 1, 48000.);

Expand All @@ -3528,10 +3523,10 @@ mod tests {
}
assert_float_eq!(intrinsic_values, &expected[..], abs_all <= 0.);

let signal = alloc.silence();
let signal = AudioRenderQuantumChannel::silence();
let mut input = AudioRenderQuantum::from(signal);
input.channel_data_mut(0)[0] = f32::NAN;
let signal = alloc.silence();
let signal = AudioRenderQuantumChannel::silence();
let mut output = AudioRenderQuantum::from(signal);

render.mix_to_output(&input, &mut output);
Expand Down
13 changes: 7 additions & 6 deletions src/render/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ use std::panic::{self, AssertUnwindSafe};
use crate::context::AudioNodeId;
use smallvec::{smallvec, SmallVec};

use super::{Alloc, AudioParamValues, AudioProcessor, AudioRenderQuantum, NodeCollection};
use super::{
AudioParamValues, AudioProcessor, AudioRenderQuantum, AudioRenderQuantumChannel, NodeCollection,
};
use crate::node::{ChannelConfigInner, ChannelCountMode, ChannelInterpretation};
use crate::render::AudioWorkletGlobalScope;

Expand Down Expand Up @@ -122,8 +124,6 @@ impl Node {
pub(crate) struct Graph {
/// Processing Nodes
nodes: NodeCollection,
/// Allocator for audio buffers
alloc: Alloc,
/// Message channel to notify control thread of reclaimable AudioNodeIds
reclaim_id_channel: llq::Producer<AudioNodeId>,
/// Topological ordering of the nodes
Expand Down Expand Up @@ -151,7 +151,6 @@ impl Graph {
pub fn new(reclaim_id_channel: llq::Producer<AudioNodeId>) -> Self {
Graph {
nodes: NodeCollection::new(),
alloc: Alloc::with_capacity(64),
reclaim_id_channel,
ordered: vec![],
marked: vec![],
Expand Down Expand Up @@ -180,8 +179,10 @@ impl Graph {

// set input and output buffers to single channel of silence, will be upmixed when
// necessary
let inputs = vec![AudioRenderQuantum::from(self.alloc.silence()); number_of_inputs];
let outputs = vec![AudioRenderQuantum::from(self.alloc.silence()); number_of_outputs];
let inputs =
vec![AudioRenderQuantum::from(AudioRenderQuantumChannel::silence()); number_of_inputs];
let outputs =
vec![AudioRenderQuantum::from(AudioRenderQuantumChannel::silence()); number_of_outputs];

self.nodes.insert(
index,
Expand Down
Loading
Loading