From 5eb311d8beb397278a9a674e8c043195e88bbdb3 Mon Sep 17 00:00:00 2001 From: Tom Gowan Date: Wed, 7 Nov 2018 21:54:27 +1100 Subject: [PATCH] float conversion fix --- src/platform/windows/asio/stream.rs | 88 ++++++++++++++++++++++++++++- 1 file changed, 86 insertions(+), 2 deletions(-) diff --git a/src/platform/windows/asio/stream.rs b/src/platform/windows/asio/stream.rs index bddf875..9ee121b 100644 --- a/src/platform/windows/asio/stream.rs +++ b/src/platform/windows/asio/stream.rs @@ -281,19 +281,61 @@ impl EventLoop { // Macro to convert sample from ASIO to CPAL type macro_rules! convert_sample { // floats types required different conversion + (f32, + f32, + $SampleTypeIdent:ident, + $Sample:expr + ) => { + *$Sample + }; + (f64, + f64, + $SampleTypeIdent:ident, + $Sample:expr + ) => { + *$Sample + }; + (f64, + f32, + $SampleTypeIdent:ident, + $Sample:expr + ) => { + *$Sample as f32 + }; + (f32, + f64, + $SampleTypeIdent:ident, + $Sample:expr + ) => { + *$Sample as f64 + }; ($AsioTypeIdent:ident, f32, $SampleTypeIdent:ident, $Sample:expr ) => { - (*$Sample as f64 / ::std::$SampleTypeIdent::MAX as f64) as f32 + (*$Sample as f64 / ::std::$AsioTypeIdent::MAX as f64) as f32 }; ($AsioTypeIdent:ident, f64, $SampleTypeIdent:ident, $Sample:expr ) => { - *$Sample as f64 / ::std::$SampleTypeIdent::MAX as f64 + *$Sample as f64 / ::std::$AsioTypeIdent::MAX as f64 + }; + (f32, + $SampleType:ty, + $SampleTypeIdent:ident, + $Sample:expr + ) => { + (*$Sample as f64 * ::std::$SampleTypeIdent::MAX as f64) as $SampleType + }; + (f64, + $SampleType:ty, + $SampleTypeIdent:ident, + $Sample:expr + ) => { + (*$Sample as f64 * ::std::$SampleTypeIdent::MAX as f64) as $SampleType }; ($AsioTypeIdent:ident, $SampleType:ty, @@ -565,6 +607,48 @@ impl EventLoop { // Convert sample depending on the sample type macro_rules! convert_sample { + ($AsioTypeIdent:ident, + f64, + f64, + $Sample:expr + ) => { + *$Sample + }; + ($AsioTypeIdent:ident, + f32, + f32, + $Sample:expr + ) => { + *$Sample + }; + ($AsioTypeIdent:ident, + f64, + f32, + $Sample:expr + ) => { + *$Sample as f64 + }; + ($AsioTypeIdent:ident, + f32, + f64, + $Sample:expr + ) => { + *$Sample as f32 + }; + ($AsioTypeIdent:ident, + $AsioType:ty, + f32, + $Sample:expr + ) => { + (*$Sample as f64 * ::std::$AsioTypeIdent::MAX as f64) as $AsioType + }; + ($AsioTypeIdent:ident, + $AsioType:ty, + f64, + $Sample:expr + ) => { + (*$Sample as f64 * ::std::$AsioTypeIdent::MAX as f64) as $AsioType + }; ($AsioTypeIdent:ident, f32, $SampleTypeIdent:ident,