From c8c00793c0816f897877c2df31d2bb23675f12c2 Mon Sep 17 00:00:00 2001 From: DMSDeveloper Date: Thu, 26 Apr 2018 15:25:04 +1000 Subject: [PATCH] attemp at removing buffer 2 --- src/platform/windows/asio/stream.rs | 82 ++++++++++++++++------------- 1 file changed, 44 insertions(+), 38 deletions(-) diff --git a/src/platform/windows/asio/stream.rs b/src/platform/windows/asio/stream.rs index 0e5ecd3..b1ad6f5 100644 --- a/src/platform/windows/asio/stream.rs +++ b/src/platform/windows/asio/stream.rs @@ -63,41 +63,55 @@ impl EventLoop { let channel_len = cpal_num_samples / num_channels as usize; - enum CpalBuffer{ - I16(Vec), - U16(Vec), - F32(Vec), + struct I16Buffer{ + cpal: Vec, + channel: Vec>, } - enum ChannelBuffer{ - I16(Vec>), - U16(Vec>), - F32(Vec>), + struct U16Buffer{ + cpal: Vec, + channel: Vec>, } - let (mut cpal_buffer, - mut channels) = match format.data_type{ + struct F32Buffer{ + cpal: Vec, + channel: Vec>, + } + struct BufferTypes(T); + impl BufferTypes{ + fn into_buff(self) -> I16Buffer{ + self.0 + } + } + impl BufferTypes{ + fn into_buff(self) -> U16Buffer{ + self.0 + } + } + impl BufferTypes{ + fn into_buff(self) -> F32Buffer{ + self.0 + } + } + let mut buffers = match format.data_type{ SampleFormat::I16 => { - let mut cpal_buffer = CpalBuffer::I16(vec![0 as i16; cpal_num_samples]); - let mut channels = ChannelBuffer::I16( - (0..num_channels) + BufferTypes(I16Buffer{ + cpal: vec![0 as i16; cpal_num_samples], + channel: (0..num_channels) .map(|_| Vec::with_capacity(channel_len)) - .collect()); - (cpal_buffer, channels) + .collect()}) } SampleFormat::U16 => { - let mut cpal_buffer = CpalBuffer::U16(vec![0 as u16; cpal_num_samples]); - let mut channels = ChannelBuffer::U16( - (0..num_channels) + BufferTypes(U16Buffer{ + cpal: vec![0 as u16; cpal_num_samples], + channel: (0..num_channels) .map(|_| Vec::with_capacity(channel_len)) - .collect()); - (cpal_buffer, channels) + .collect()}) } SampleFormat::F32 => { - let mut cpal_buffer = CpalBuffer::F32(vec![0 as f32; cpal_num_samples]); - let mut channels = ChannelBuffer::F32( - (0..num_channels) + BufferTypes(F32Buffer{ + cpal: vec![0 as f32; cpal_num_samples], + channel: (0..num_channels) .map(|_| Vec::with_capacity(channel_len)) - .collect()); - (cpal_buffer, channels) + .collect()}) } }; @@ -168,25 +182,17 @@ impl EventLoop { }; // Generic over types // TODO check for endianess - match (stream_type, cpal_buffer, channels) { - (sys::AsioSampleType::ASIOSTInt32LSB, - CpalBuffer::I16(cpal_buffer), - ChannelBuffer::I16(channels))=> { + match stream_type { + sys::AsioSampleType::ASIOSTInt32LSB => { try_callback!(I16, i16, i16, i32, i32); } - (sys::AsioSampleType::ASIOSTInt16LSB, - CpalBuffer::I16(cpal_buffer), - ChannelBuffer::I16(channels))=> { + sys::AsioSampleType::ASIOSTInt16LSB => { try_callback!(I16, i16, i16, i16, i16); } - (sys::AsioSampleType::ASIOSTFloat32LSB, - CpalBuffer::F32(cpal_buffer), - ChannelBuffer::F32(channels))=> { + sys::AsioSampleType::ASIOSTFloat32LSB => { try_callback!(F32, f32, f32, f32, f32); } - (sys::AsioSampleType::ASIOSTFloat64LSB, - CpalBuffer::F32(cpal_buffer), - ChannelBuffer::F32(channels))=> { + sys::AsioSampleType::ASIOSTFloat64LSB => { try_callback!(F32, f32, f32, f64, f64); } _ => println!("unsupported format {:?}", stream_type),