Skip to content

Commit ca8ef60

Browse files
committed
Merge pull request #83 from mitchmindtree/master
Improved debug formatting for flags, added stream format support check to examples.
2 parents 76dd0f2 + 94b4f24 commit ca8ef60

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22

33
name = "portaudio"
4-
version = "0.4.7"
4+
version = "0.4.8"
55
authors = ["Jeremy Letang <[email protected]>",
66
"Mitchell Nordine <[email protected]>"]
77
description = "PortAudio bindings for Rust."

examples/blocking.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ fn main() {
7171
suggested_latency : output_info.default_low_output_latency
7272
};
7373

74+
// Check that the stream format is supported.
75+
if let Err(err) = pa::is_format_supported(&input_stream_params, &output_stream_params, SAMPLE_RATE) {
76+
panic!("The given stream format is unsupported: {:?}", err.description());
77+
}
78+
7479
let mut stream : pa::Stream<f32, f32> = pa::Stream::new();
7580

7681
match stream.open(Some(&input_stream_params),

examples/non_blocking.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ fn main() {
6969
suggested_latency : output_info.default_low_output_latency
7070
};
7171

72+
// Check that the stream format is supported.
73+
if let Err(err) = pa::is_format_supported(&input_stream_params, &output_stream_params, SAMPLE_RATE) {
74+
panic!("The given stream format is unsupported: {:?}", err.description());
75+
}
76+
7277
// Construct a stream with input and output sample types of f32.
7378
let mut stream : pa::Stream<f32, f32> = pa::Stream::new();
7479

src/pa/types.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,20 @@ pub mod stream_flags {
106106
const PA_PLATFORM_SPECIFIC_FLAGS = ffi::PA_PLATFORM_SPECIFIC_FLAGS,
107107
}
108108
}
109+
110+
impl ::std::fmt::Debug for StreamFlags {
111+
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
112+
write!(f, "{:?}", match self.bits() {
113+
ffi::PA_NO_FLAG => "NO_FLAG",
114+
ffi::PA_CLIP_OFF => "CLIP_OFF",
115+
ffi::PA_DITHER_OFF => "DITHER_OFF",
116+
ffi::PA_NEVER_DROP_INPUT => "NEVER_DROP_INPUT",
117+
ffi::PA_PRIME_OUTPUT_BUFFERS_USING_STREAM_CALLBACK => "PRIME_OUTPUT_BUFFERS_USING_STREAM_CALLBACK",
118+
ffi::PA_PLATFORM_SPECIFIC_FLAGS => "PLATFORM_SPECIFIC_FLAGS",
119+
_ => "<Unknown StreamFlags>",
120+
})
121+
}
122+
}
109123
}
110124

111125
/// Describes stream availability and the number for frames available for reading/writing if there
@@ -156,6 +170,19 @@ pub mod stream_callback_flags {
156170
const PRIMING_OUTPUT = ffi::PRIMING_OUTPUT,
157171
}
158172
}
173+
174+
impl ::std::fmt::Debug for StreamCallbackFlags {
175+
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
176+
write!(f, "{:?}", match self.bits() {
177+
ffi::INPUT_UNDERFLOW => "INPUT_UNDERFLOW",
178+
ffi::INPUT_OVERFLOW => "INPUT_OVERFLOW",
179+
ffi::OUTPUT_UNDERFLOW => "OUTPUT_UNDERFLOW",
180+
ffi::OUTPUT_OVERFLOW => "OUTPUT_OVERFLOW",
181+
ffi::PRIMING_OUTPUT => "PRIMING_INPUT",
182+
_ => "<Unknown StreamCallbackFlags>",
183+
})
184+
}
185+
}
159186
}
160187

161188
/// User defined callback function.

0 commit comments

Comments
 (0)