Skip to content

Commit

Permalink
minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nico-franco-gomez committed Nov 13, 2024
1 parent 9757d9d commit c79edf3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
28 changes: 17 additions & 11 deletions src/host/asio/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,9 @@ fn from_be<T: PrimInt>(t: T) -> T {
}

/// Shorthand for retrieving the asio buffer slice associated with a channel.
///
/// The channel length is automatically inferred from the buffer size or some
/// value can be passed to enforce a certain length (for odd sized sample formats)
unsafe fn asio_channel_slice<T>(
asio_stream: &sys::AsioStream,
buffer_index: usize,
Expand All @@ -730,6 +733,9 @@ unsafe fn asio_channel_slice<T>(
}

/// Shorthand for retrieving the asio buffer slice associated with a channel.
///
/// The channel length is automatically inferred from the buffer size or some
/// value can be passed to enforce a certain length (for odd sized sample formats)
unsafe fn asio_channel_slice_mut<T>(
asio_stream: &mut sys::AsioStream,
buffer_index: usize,
Expand Down Expand Up @@ -769,7 +775,6 @@ fn i24_bytes_to_i32(i24_bytes: &[u8; 3], little_endian: bool) -> i32 {
}
}

/// Only for i24 formats
unsafe fn process_output_callback_i24<D>(
data_callback: &mut D,
interleaved: &mut [u8],
Expand Down Expand Up @@ -839,8 +844,6 @@ unsafe fn process_output_callback_i24<D>(
}
}

/// 1. Write from the ASIO buffer to the interleaved CPAL buffer.
/// 2. Deliver the CPAL buffer to the user callback.
unsafe fn process_input_callback_i24<A, D>(
data_callback: &mut D,
interleaved: &mut [u8],
Expand Down Expand Up @@ -905,12 +908,13 @@ unsafe fn apply_output_callback_to_data<A, D>(
A: Copy,
D: FnMut(&mut Data, &OutputCallbackInfo) + Send + 'static,
{
let data = interleaved.as_mut_ptr() as *mut ();
let len = interleaved.len();
let mut data = Data::from_parts(data, len, sample_format);
let mut data = Data::from_parts(
interleaved.as_mut_ptr() as *mut (),
interleaved.len(),
sample_format,
);
let callback = system_time_to_stream_instant(asio_info.system_time);
let n_frames = asio_stream.buffer_size as usize;
let delay = frames_to_duration(n_frames, sample_rate);
let delay = frames_to_duration(asio_stream.buffer_size as usize, sample_rate);
let playback = callback
.add(delay)
.expect("`playback` occurs beyond representation supported by `StreamInstant`");
Expand All @@ -931,9 +935,11 @@ unsafe fn apply_input_callback_to_data<A, D>(
A: Copy,
D: FnMut(&Data, &InputCallbackInfo) + Send + 'static,
{
let data = interleaved.as_mut_ptr() as *mut ();
let len = interleaved.len();
let data = Data::from_parts(data, len, format);
let data = Data::from_parts(
interleaved.as_mut_ptr() as *mut (),
interleaved.len(),
format,
);
let callback = system_time_to_stream_instant(asio_info.system_time);
let delay = frames_to_duration(asio_stream.buffer_size as usize, sample_rate);
let capture = callback
Expand Down
8 changes: 4 additions & 4 deletions src/samples_formats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ impl SampleFormat {
match *self {
SampleFormat::I8 | SampleFormat::U8 => mem::size_of::<i8>(),
SampleFormat::I16 | SampleFormat::U16 => mem::size_of::<i16>(),
SampleFormat::I24 => mem::size_of::<i32>(), // Use internal size of i32
// SampleFormat::U24 => 3,
SampleFormat::I24 => mem::size_of::<i32>(),
// SampleFormat::U24 => mem::size_of::<i32>(),
SampleFormat::I32 | SampleFormat::U32 => mem::size_of::<i32>(),

// SampleFormat::I48 => 6,
// SampleFormat::U48 => 6,
// SampleFormat::I48 => mem::size_of::<i64>(),
// SampleFormat::U48 => mem::size_of::<i64>(),
SampleFormat::I64 | SampleFormat::U64 => mem::size_of::<i64>(),
SampleFormat::F32 => mem::size_of::<f32>(),
SampleFormat::F64 => mem::size_of::<f64>(),
Expand Down

0 comments on commit c79edf3

Please sign in to comment.