minor fixes 2
This commit is contained in:
parent
a1740a9282
commit
892024f5d8
|
@ -102,57 +102,30 @@ impl Device {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn default_output_format(&self) -> Result<Format, DefaultFormatError> {
|
pub fn default_output_format(&self) -> Result<Format, DefaultFormatError> {
|
||||||
let format = Format{channels: 0, sample_rate: SampleRate(0),
|
let num_channels = sys::get_channels(&self.driver_name)
|
||||||
// TODO Not sure about how to set the data type
|
.map(|c| c.outs as u16);
|
||||||
data_type: SampleFormat::F32};
|
let sample_rate = sys::get_sample_rate(&self.driver_name)
|
||||||
|
.map(|s| SampleRate(s.rate));
|
||||||
let format = match sys::get_channels(&self.driver_name) {
|
let data_type = sys::get_data_type(&self.driver_name);
|
||||||
Ok(channels) => {
|
let data_type = match data_type{
|
||||||
Format{channels: channels.outs as u16,
|
Ok(sys::AsioSampleType::ASIOSTInt16MSB) => Ok(SampleFormat::I16),
|
||||||
sample_rate: format.sample_rate,
|
Ok(sys::AsioSampleType::ASIOSTFloat32MSB) => Ok(SampleFormat::F32),
|
||||||
data_type: format.data_type}
|
Ok(sys::AsioSampleType::ASIOSTInt16LSB) => Ok(SampleFormat::I16),
|
||||||
},
|
// TODO This should not be set to 16bit but is for testing
|
||||||
Err(e) => {
|
Ok(sys::AsioSampleType::ASIOSTInt32LSB) => Ok(SampleFormat::I16),
|
||||||
println!("Error retrieving channels: {}", e);
|
Ok(sys::AsioSampleType::ASIOSTFloat32LSB) => Ok(SampleFormat::F32),
|
||||||
format
|
_ => Err(DefaultFormatError::StreamTypeNotSupported),
|
||||||
},
|
};
|
||||||
|
let format = match (num_channels, sample_rate, data_type){
|
||||||
|
(Ok(num_channels), Ok(sample_rate), Ok(data_type)) =>{
|
||||||
|
Ok(Format{channels: num_channels,
|
||||||
|
sample_rate: sample_rate,
|
||||||
|
data_type: data_type})
|
||||||
|
}
|
||||||
|
_ => Err(DefaultFormatError::StreamTypeNotSupported),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
format
|
||||||
let format = match sys::get_sample_rate(&self.driver_name) {
|
|
||||||
Ok(sample_rate) => {
|
|
||||||
Format{channels: format.channels,
|
|
||||||
sample_rate: SampleRate(sample_rate.rate),
|
|
||||||
data_type: format.data_type}
|
|
||||||
},
|
|
||||||
Err(e) => {
|
|
||||||
println!("Error retrieving sample rate: {}", e);
|
|
||||||
format
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
let format = match sys::get_data_type(&self.driver_name) {
|
|
||||||
Ok(data_type) => {
|
|
||||||
let data_type = match data_type{
|
|
||||||
sys::AsioSampleType::ASIOSTInt16MSB => SampleFormat::I16,
|
|
||||||
sys::AsioSampleType::ASIOSTFloat32MSB => SampleFormat::F32,
|
|
||||||
sys::AsioSampleType::ASIOSTInt16LSB => SampleFormat::I16,
|
|
||||||
// TODO This should not be set to 16bit but is for testing
|
|
||||||
sys::AsioSampleType::ASIOSTInt32LSB => SampleFormat::I16,
|
|
||||||
sys::AsioSampleType::ASIOSTFloat32LSB => SampleFormat::F32,
|
|
||||||
_ => panic!("Unsupported Audio Type: {:?}", data_type),
|
|
||||||
};
|
|
||||||
Format{channels: format.channels,
|
|
||||||
sample_rate: format.sample_rate,
|
|
||||||
data_type: data_type}
|
|
||||||
},
|
|
||||||
Err(e) => {
|
|
||||||
println!("Error retrieving sample rate: {}", e);
|
|
||||||
format
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(format)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,10 +13,11 @@ use UnknownTypeInputBuffer;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use self::itertools::Itertools;
|
use self::itertools::Itertools;
|
||||||
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||||
|
|
||||||
pub struct EventLoop {
|
pub struct EventLoop {
|
||||||
asio_stream: Arc<Mutex<Option<sys::AsioStream>>>,
|
asio_stream: Arc<Mutex<Option<sys::AsioStream>>>,
|
||||||
stream_count: Cell<usize>,
|
stream_count: Arc<AtomicUsize>,
|
||||||
callbacks: Arc<Mutex<Vec<&'static mut (FnMut(StreamId, StreamData) + Send)>>>,
|
callbacks: Arc<Mutex<Vec<&'static mut (FnMut(StreamId, StreamData) + Send)>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +35,7 @@ impl EventLoop {
|
||||||
pub fn new() -> EventLoop {
|
pub fn new() -> EventLoop {
|
||||||
EventLoop {
|
EventLoop {
|
||||||
asio_stream: Arc::new(Mutex::new(None)),
|
asio_stream: Arc::new(Mutex::new(None)),
|
||||||
stream_count: Cell::new(0),
|
stream_count: Arc::new(AtomicUsize::new(0)),
|
||||||
callbacks: Arc::new(Mutex::new(Vec::new())),
|
callbacks: Arc::new(Mutex::new(Vec::new())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,8 +51,8 @@ impl EventLoop {
|
||||||
{
|
{
|
||||||
*self.asio_stream.lock().unwrap() = Some(stream);
|
*self.asio_stream.lock().unwrap() = Some(stream);
|
||||||
}
|
}
|
||||||
let count = self.stream_count.get();
|
let count = self.stream_count.load(Ordering::SeqCst);
|
||||||
self.stream_count.set(count + 1);
|
self.stream_count.store(count + 1, Ordering::SeqCst);
|
||||||
let asio_stream = self.asio_stream.clone();
|
let asio_stream = self.asio_stream.clone();
|
||||||
let callbacks = self.callbacks.clone();
|
let callbacks = self.callbacks.clone();
|
||||||
let bytes_per_channel = format.data_type.sample_size();
|
let bytes_per_channel = format.data_type.sample_size();
|
||||||
|
@ -95,9 +96,9 @@ impl EventLoop {
|
||||||
// Also need to check for Endian
|
// Also need to check for Endian
|
||||||
|
|
||||||
for (i, channel) in channels.iter_mut().enumerate(){
|
for (i, channel) in channels.iter_mut().enumerate(){
|
||||||
let buff_ptr = (asio_stream
|
let buff_ptr = asio_stream
|
||||||
.buffer_infos[i]
|
.buffer_infos[i]
|
||||||
.buffers[index as usize] as *mut $AsioType);
|
.buffers[index as usize] as *mut $AsioType;
|
||||||
//.offset(asio_stream.buffer_size as isize * i as isize);
|
//.offset(asio_stream.buffer_size as isize * i as isize);
|
||||||
let asio_buffer: &'static [$AsioType] =
|
let asio_buffer: &'static [$AsioType] =
|
||||||
std::slice::from_raw_parts(
|
std::slice::from_raw_parts(
|
||||||
|
@ -171,8 +172,8 @@ pub fn build_output_stream(
|
||||||
{
|
{
|
||||||
*self.asio_stream.lock().unwrap() = Some(stream);
|
*self.asio_stream.lock().unwrap() = Some(stream);
|
||||||
}
|
}
|
||||||
let count = self.stream_count.get();
|
let count = self.stream_count.load(Ordering::SeqCst);
|
||||||
self.stream_count.set(count + 1);
|
self.stream_count.store(count + 1, Ordering::SeqCst);
|
||||||
let asio_stream = self.asio_stream.clone();
|
let asio_stream = self.asio_stream.clone();
|
||||||
let callbacks = self.callbacks.clone();
|
let callbacks = self.callbacks.clone();
|
||||||
let bytes_per_channel = format.data_type.sample_size();
|
let bytes_per_channel = format.data_type.sample_size();
|
||||||
|
|
Loading…
Reference in New Issue