attemp at removing buffer 2

This commit is contained in:
DMSDeveloper 2018-04-26 15:25:04 +10:00 committed by mitchmindtree
parent ab7e17558f
commit c8c00793c0
1 changed files with 44 additions and 38 deletions

View File

@ -63,41 +63,55 @@ impl EventLoop {
let channel_len = cpal_num_samples let channel_len = cpal_num_samples
/ num_channels as usize; / num_channels as usize;
enum CpalBuffer{ struct I16Buffer{
I16(Vec<i16>), cpal: Vec<i16>,
U16(Vec<u16>), channel: Vec<Vec<i16>>,
F32(Vec<f32>),
} }
enum ChannelBuffer{ struct U16Buffer{
I16(Vec<Vec<i16>>), cpal: Vec<u16>,
U16(Vec<Vec<u16>>), channel: Vec<Vec<u16>>,
F32(Vec<Vec<f32>>),
} }
let (mut cpal_buffer, struct F32Buffer{
mut channels) = match format.data_type{ cpal: Vec<f32>,
channel: Vec<Vec<f32>>,
}
struct BufferTypes<T>(T);
impl BufferTypes<I16Buffer>{
fn into_buff(self) -> I16Buffer{
self.0
}
}
impl BufferTypes<U16Buffer>{
fn into_buff(self) -> U16Buffer{
self.0
}
}
impl BufferTypes<F32Buffer>{
fn into_buff(self) -> F32Buffer{
self.0
}
}
let mut buffers = match format.data_type{
SampleFormat::I16 => { SampleFormat::I16 => {
let mut cpal_buffer = CpalBuffer::I16(vec![0 as i16; cpal_num_samples]); BufferTypes(I16Buffer{
let mut channels = ChannelBuffer::I16( cpal: vec![0 as i16; cpal_num_samples],
(0..num_channels) channel: (0..num_channels)
.map(|_| Vec::with_capacity(channel_len)) .map(|_| Vec::with_capacity(channel_len))
.collect()); .collect()})
(cpal_buffer, channels)
} }
SampleFormat::U16 => { SampleFormat::U16 => {
let mut cpal_buffer = CpalBuffer::U16(vec![0 as u16; cpal_num_samples]); BufferTypes(U16Buffer{
let mut channels = ChannelBuffer::U16( cpal: vec![0 as u16; cpal_num_samples],
(0..num_channels) channel: (0..num_channels)
.map(|_| Vec::with_capacity(channel_len)) .map(|_| Vec::with_capacity(channel_len))
.collect()); .collect()})
(cpal_buffer, channels)
} }
SampleFormat::F32 => { SampleFormat::F32 => {
let mut cpal_buffer = CpalBuffer::F32(vec![0 as f32; cpal_num_samples]); BufferTypes(F32Buffer{
let mut channels = ChannelBuffer::F32( cpal: vec![0 as f32; cpal_num_samples],
(0..num_channels) channel: (0..num_channels)
.map(|_| Vec::with_capacity(channel_len)) .map(|_| Vec::with_capacity(channel_len))
.collect()); .collect()})
(cpal_buffer, channels)
} }
}; };
@ -168,25 +182,17 @@ impl EventLoop {
}; };
// Generic over types // Generic over types
// TODO check for endianess // TODO check for endianess
match (stream_type, cpal_buffer, channels) { match stream_type {
(sys::AsioSampleType::ASIOSTInt32LSB, sys::AsioSampleType::ASIOSTInt32LSB => {
CpalBuffer::I16(cpal_buffer),
ChannelBuffer::I16(channels))=> {
try_callback!(I16, i16, i16, i32, i32); try_callback!(I16, i16, i16, i32, i32);
} }
(sys::AsioSampleType::ASIOSTInt16LSB, sys::AsioSampleType::ASIOSTInt16LSB => {
CpalBuffer::I16(cpal_buffer),
ChannelBuffer::I16(channels))=> {
try_callback!(I16, i16, i16, i16, i16); try_callback!(I16, i16, i16, i16, i16);
} }
(sys::AsioSampleType::ASIOSTFloat32LSB, sys::AsioSampleType::ASIOSTFloat32LSB => {
CpalBuffer::F32(cpal_buffer),
ChannelBuffer::F32(channels))=> {
try_callback!(F32, f32, f32, f32, f32); try_callback!(F32, f32, f32, f32, f32);
} }
(sys::AsioSampleType::ASIOSTFloat64LSB, sys::AsioSampleType::ASIOSTFloat64LSB => {
CpalBuffer::F32(cpal_buffer),
ChannelBuffer::F32(channels))=> {
try_callback!(F32, f32, f32, f64, f64); try_callback!(F32, f32, f32, f64, f64);
} }
_ => println!("unsupported format {:?}", stream_type), _ => println!("unsupported format {:?}", stream_type),