-
Notifications
You must be signed in to change notification settings - Fork 16
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
Refactor message passing #337
Conversation
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
Ok I think this is all done, just two notes on the PannerNode:
Edit: I tried to follow the pattern proposed by @uklotzde in the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be easier for review to refactor the node types one after another. All these changes are not dependent on each other.
src/node/convolver.rs
Outdated
atomic::{AtomicBool, Ordering}, | ||
Arc, Mutex, | ||
}; | ||
use super::{AudioNode, ChannelConfig, ChannelConfigOptions, ChannelInterpretation}; | ||
|
||
/// Scale buffer by an equal-power normalization | ||
fn normalization(buffer: &AudioBuffer) -> f32 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated: Why does this function name does not start with a verb as usual?
ref_distance: Arc<AtomicF64>, | ||
max_distance: Arc<AtomicF64>, | ||
rolloff_factor: Arc<AtomicF64>, | ||
cone_inner_angle: AtomicF64, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why still individual atomics instead of an inner typed wrapped into a single RefCell
as demonstrated in in the AudioBufferSourceNode
? This also applies to all other node types as far as I could see.
This PR does not seem to fix the soundness errors that are potentially causing inconsistencies in multi-threaded contexts. |
Yeah, I think @b-ma is keeping these things separate for now. Edit, I just read
but I still think it is fine to keep matters separate for now |
Yup that was the idea, I was actually thinking about the post_message / onmessage pattern used for the AudioBuffer and control messages |
@@ -11,8 +11,11 @@ use super::{AudioNode, AudioScheduledSourceNode, ChannelConfig}; | |||
// dictionary ConstantSourceOptions { | |||
// float offset = 1; | |||
// }; | |||
// @note: this does not extend AudioNodeOptions in the spec, why? | |||
// https://webaudio.github.io/web-audio-api/#ConstantSourceOptions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AudioNodeOptions
are useless for source nodes, because they instruct how to upmix the inputs.
This is a common source of confusion, see e.g. mdn/content#18472
Also for the spec editors because they accidentally let OscillatorOptions extend AudioNodeOptions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added your note and link to the comment, so we don't forget again. I will try to align this to other nodes as well later
src/node/convolver.rs
Outdated
// dummy convolver used to init renderer | ||
fn tombstone() -> Self { | ||
// just use arbitrary common sample rate | ||
let padded_buffer = AudioBuffer::from(vec![vec![0.; 0]; 1], 48000.); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This allocates (non-empty vec). I think you can reuse the tombstone from AudioBufferSourceRenderer
Edit: oh this is not very important because we don't use it in the renderer..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found a way to make it more clean in any case
I have improved the HRTF-loading in the panner node. I will have a closer look at the other changes tomorrow. |
Ok thanks! Think I got it (until next time borrow checker shows up :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the hard work. I will pick up the stuff I have mentioned.
src/node/convolver.rs
Outdated
}) | ||
}); | ||
|
||
// renderer has been sent to render thread, we can sent it messages |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// renderer has been sent to render thread, we can sent it messages | |
// renderer has been sent to render thread, we can send it messages |
src/node/convolver.rs
Outdated
@@ -359,6 +345,17 @@ impl ConvolverRendererInner { | |||
} | |||
} | |||
|
|||
// dummy convolver used to init renderer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I could better rewrite this like the HRTF-renderer. I'm not too sure what Fft::new(0),
does behind the scenes. Also, it will make it more succinct and clear.
Stay tuned for updates
@@ -414,6 +411,11 @@ impl ConvolverRendererInner { | |||
} | |||
} | |||
|
|||
struct ConvolverRenderer { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As said, I will rewrite this.
A pattern of is_set
and a tombstone value is way better represented as simply Option<ConvolverRendererInner>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure this is a bit redondant
src/node/waveshaper.rs
Outdated
/// distortion curve | ||
curve: Vec<f32>, | ||
/// whether the distortion curve has been set | ||
curve_set: bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar, I will rewrite this to simply curve: Option<Vec<f32>>
src/node/waveshaper.rs
Outdated
@@ -135,9 +128,7 @@ pub struct WaveShaperNode { | |||
/// distortion curve | |||
curve: OnceCell<Vec<f32>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed this node in #347 . I will need to rewrite this one to use a OnceLock
instead
483a22c
to
13cda2c
Compare
/bench |
Ready to merge but I want to publish a release before merging as we still have some bugfixes lined up. |
|
Work in progress regarding #315