-
Notifications
You must be signed in to change notification settings - Fork 434
Add support for OpenBSD platform via sndio host #493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AaronM04
wants to merge
19
commits into
RustAudio:master
Choose a base branch
from
conwayste:aaron/openbsd_sndio_host
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
2abb970
Add support for OpenBSD platform via sndio host
AaronM04 37600dd
Restore incorrectly modified line in asio-sys build-deps
AaronM04 07ceda7
sndio: refactor adapters
AaronM04 8e7227b
sndio: simpler endianness check
AaronM04 7f11fd1
sndio: simplify Devices iterator
AaronM04 2e0c63b
rustfmt fix
AaronM04 eeafe6f
sndio: avoid unsafe impl Send on InnerState
AaronM04 47877cf
sndio: refactor InnerState to be enum (reduce the Options and unwraps)
AaronM04 51d3486
sndio: address feedback from code review
AaronM04 d419f0f
sndio: change input/output_callbacks storage to a HashMap indexed by …
AaronM04 ce57c56
Merge remote-tracking branch 'upstream/master' into aaron/openbsd_snd…
AaronM04 2e00be6
sndio: test CI with linux-sndio feature
AaronM04 842069b
Wrap (usize, HashMap) into a struct
blackgnezdo 96a7447
Shrink input_adapter_callback by parametrizing by type
blackgnezdo aefb585
Add TypeSampleFormat - type-level counterpart to SampleFormat
blackgnezdo f64997d
Deduplicate output_adapter_callback and avoid indexing
blackgnezdo 2a068cc
Deduplicate config_ranges
blackgnezdo ddd08e3
cargo fmt
AaronM04 bd1da41
Merge branch 'master' into aaron/openbsd_sndio_host
AaronM04 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
.DS_Store | ||
recorded.wav | ||
rls*.log | ||
rusty-tags.* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
use crate::{Data, InputCallbackInfo, OutputCallbackInfo, Sample, SampleFormat}; | ||
|
||
/// When given an input data callback that expects samples in the specified sample format, return | ||
/// an input data callback that expects samples in the I16 sample format. The `buffer_size` is in | ||
/// samples. | ||
pub(super) fn input_adapter_callback<D>( | ||
mut original_data_callback: D, | ||
buffer_size: usize, | ||
sample_format: SampleFormat, | ||
) -> Box<dyn FnMut(&Data, &InputCallbackInfo) + Send + 'static> | ||
where | ||
D: FnMut(&Data, &InputCallbackInfo) + Send + 'static, | ||
{ | ||
if sample_format == SampleFormat::I16 { | ||
// no-op | ||
return Box::new(original_data_callback); | ||
} | ||
|
||
// Make the backing buffer for the Data used in the closure. | ||
let mut buf: Vec<u8> = vec![0].repeat(buffer_size * sample_format.sample_size()); | ||
|
||
Box::new(move |data: &Data, info: &InputCallbackInfo| { | ||
// Note: we construct adapted_data here instead of in the parent function because buf needs | ||
// to be owned by the closure. | ||
let mut adapted_data = | ||
unsafe { Data::from_parts(buf.as_mut_ptr() as *mut _, buffer_size, sample_format) }; | ||
let data_slice: &[i16] = data.as_slice().unwrap(); // unwrap OK because data is always i16 | ||
match sample_format { | ||
SampleFormat::F32 => { | ||
let adapted_slice: &mut [f32] = adapted_data.as_slice_mut().unwrap(); // unwrap OK because of the match | ||
assert_eq!(data_slice.len(), adapted_slice.len()); | ||
for (i, adapted_ref) in adapted_slice.iter_mut().enumerate() { | ||
*adapted_ref = data_slice[i].to_f32(); | ||
} | ||
} | ||
SampleFormat::U16 => { | ||
let adapted_slice: &mut [u16] = adapted_data.as_slice_mut().unwrap(); // unwrap OK because of the match | ||
assert_eq!(data_slice.len(), adapted_slice.len()); | ||
for (i, adapted_ref) in adapted_slice.iter_mut().enumerate() { | ||
*adapted_ref = data_slice[i].to_u16(); | ||
} | ||
} | ||
SampleFormat::I16 => { | ||
AaronM04 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
unreachable!("i16 should've already been handled above"); | ||
} | ||
} | ||
original_data_callback(&adapted_data, info); | ||
}) | ||
} | ||
|
||
/// When given an output data callback that expects a place to write samples in the specified | ||
/// sample format, return an output data callback that expects a place to write samples in the I16 | ||
/// sample format. The `buffer_size` is in samples. | ||
pub(super) fn output_adapter_callback<D>( | ||
mut original_data_callback: D, | ||
buffer_size: usize, | ||
sample_format: SampleFormat, | ||
) -> Box<dyn FnMut(&mut Data, &OutputCallbackInfo) + Send + 'static> | ||
where | ||
D: FnMut(&mut Data, &OutputCallbackInfo) + Send + 'static, | ||
{ | ||
if sample_format == SampleFormat::I16 { | ||
// no-op | ||
return Box::new(original_data_callback); | ||
} | ||
|
||
// Make the backing buffer for the Data used in the closure. | ||
let mut buf: Vec<u8> = vec![0].repeat(buffer_size * sample_format.sample_size()); | ||
|
||
Box::new(move |data: &mut Data, info: &OutputCallbackInfo| { | ||
// Note: we construct adapted_data here instead of in the parent function because buf needs | ||
// to be owned by the closure. | ||
let mut adapted_data = | ||
unsafe { Data::from_parts(buf.as_mut_ptr() as *mut _, buffer_size, sample_format) }; | ||
|
||
// Populate buf / adapted_data. | ||
original_data_callback(&mut adapted_data, info); | ||
|
||
let data_slice: &mut [i16] = data.as_slice_mut().unwrap(); // unwrap OK because data is always i16 | ||
match sample_format { | ||
SampleFormat::F32 => { | ||
let adapted_slice: &[f32] = adapted_data.as_slice().unwrap(); // unwrap OK because of the match | ||
assert_eq!(data_slice.len(), adapted_slice.len()); | ||
for (i, data_ref) in data_slice.iter_mut().enumerate() { | ||
*data_ref = adapted_slice[i].to_i16(); | ||
} | ||
} | ||
SampleFormat::U16 => { | ||
let adapted_slice: &[u16] = adapted_data.as_slice().unwrap(); // unwrap OK because of the match | ||
assert_eq!(data_slice.len(), adapted_slice.len()); | ||
for (i, data_ref) in data_slice.iter_mut().enumerate() { | ||
*data_ref = adapted_slice[i].to_i16(); | ||
} | ||
} | ||
SampleFormat::I16 => { | ||
unreachable!("i16 should've already been handled above"); | ||
} | ||
} | ||
}) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#[derive(Copy, Clone, Debug, PartialEq, Eq)] | ||
pub(super) enum Endian { | ||
BE, | ||
LE, | ||
} | ||
|
||
pub(super) fn get_endianness() -> Endian { | ||
AaronM04 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let n: i16 = 1; | ||
match n.to_ne_bytes()[0] { | ||
1 => Endian::LE, | ||
0 => Endian::BE, | ||
_ => unreachable!("unexpected value in byte"), | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.