From 8ca059be2d9c09c41a7f06fb9bba753265381ddb Mon Sep 17 00:00:00 2001 From: Danut Enachioiu Date: Fri, 12 Jul 2024 20:51:22 +0200 Subject: [PATCH 1/3] Make member fields of StreamInstant pub This allows StreamInstants to be created, which enables testing the data callback function with unit tests. --- src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 74405a4a2..ac1571084 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,7 +33,7 @@ //! ``` //! //! Before we can create a stream, we must decide what the configuration of the audio stream is -//! going to be. +//! going to be. //! You can query all the supported configurations with the //! [`supported_input_configs()`] and [`supported_output_configs()`] methods. //! These produce a list of [`SupportedStreamConfigRange`] structs which can later be turned into @@ -225,7 +225,7 @@ pub type FrameCount = u32; /// behavior of the given host. Note, the default buffer size may be surprisingly /// large, leading to latency issues. If low latency is desired, [`Fixed(FrameCount)`] /// should be used in accordance with the [`SupportedBufferSize`] range produced by -/// the [`SupportedStreamConfig`] API. +/// the [`SupportedStreamConfig`] API. /// /// [`Default`]: BufferSize::Default /// [`Fixed(FrameCount)`]: BufferSize::Fixed @@ -334,8 +334,8 @@ pub struct Data { /// | emscripten | `AudioContext.getOutputTimestamp` | #[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)] pub struct StreamInstant { - secs: i64, - nanos: u32, + pub secs: i64, + pub nanos: u32, } /// A timestamp associated with a call to an input stream's data callback. From 0ce67a50e9c4dd95b13566edc904ead7019dd0fe Mon Sep 17 00:00:00 2001 From: Danut Enachioiu Date: Fri, 12 Jul 2024 20:58:30 +0200 Subject: [PATCH 2/3] Make CallbackInfo timestamp fields also public. --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ac1571084..03fa2c438 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -363,14 +363,14 @@ pub struct OutputStreamTimestamp { /// Information relevant to a single call to the user's input stream data callback. #[derive(Debug, Clone, PartialEq, Eq)] pub struct InputCallbackInfo { - timestamp: InputStreamTimestamp, + pub timestamp: InputStreamTimestamp, } /// Information relevant to a single call to the user's output stream data callback. #[cfg_attr(target_os = "emscripten", wasm_bindgen)] #[derive(Debug, Clone, PartialEq, Eq)] pub struct OutputCallbackInfo { - timestamp: OutputStreamTimestamp, + pub timestamp: OutputStreamTimestamp, } impl SupportedStreamConfig { From a9bf97a318251d79726f7a4edcdcb5d41d2c2720 Mon Sep 17 00:00:00 2001 From: Danut Enachioiu Date: Fri, 12 Jul 2024 21:49:19 +0200 Subject: [PATCH 3/3] Fix broken emscripten build Looks like making the fields public means they are now exposed in JS so they need wasm_bindgen I added the attribute on the input side too: the CI test only needs the output side but it only makes sense to have it both ways. --- src/lib.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 03fa2c438..d588d06dc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -332,6 +332,7 @@ pub struct Data { /// | wasapi | `QueryPerformanceCounter` | /// | asio | `timeGetTime` | /// | emscripten | `AudioContext.getOutputTimestamp` | +#[cfg_attr(target_os = "emscripten", wasm_bindgen)] #[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)] pub struct StreamInstant { pub secs: i64, @@ -339,6 +340,7 @@ pub struct StreamInstant { } /// A timestamp associated with a call to an input stream's data callback. +#[cfg_attr(target_os = "emscripten", wasm_bindgen)] #[derive(Copy, Clone, Debug, Eq, Hash, PartialEq)] pub struct InputStreamTimestamp { /// The instant the stream's data callback was invoked. @@ -350,6 +352,7 @@ pub struct InputStreamTimestamp { } /// A timestamp associated with a call to an output stream's data callback. +#[cfg_attr(target_os = "emscripten", wasm_bindgen)] #[derive(Copy, Clone, Debug, Eq, Hash, PartialEq)] pub struct OutputStreamTimestamp { /// The instant the stream's data callback was invoked. @@ -361,6 +364,7 @@ pub struct OutputStreamTimestamp { } /// Information relevant to a single call to the user's input stream data callback. +#[cfg_attr(target_os = "emscripten", wasm_bindgen)] #[derive(Debug, Clone, PartialEq, Eq)] pub struct InputCallbackInfo { pub timestamp: InputStreamTimestamp,