-
Notifications
You must be signed in to change notification settings - Fork 16
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
Implement input options #136
Implement input options #136
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ork821, thanks for contributing! Could you have a look at my comments?
Also the CI checks fail, could you run cargo fmt
and commit those changes too?
Are you planning to add latency_hint
too in this PR?
src/media/mic.rs
Outdated
/// | ||
/// Field is optional and will be set to hardcoded value. | ||
#[derive(Clone, Debug, Default)] | ||
pub struct MicrophoneInitOptions { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the name MicrophoneOptions
would be more consistent with AudioContextOptions
src/io.rs
Outdated
Some(sample_rate)=> supported_configs_range | ||
.next() | ||
.expect("no supported config?!") | ||
.with_sample_rate(CpalSampleRate(sample_rate)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requesting a specific sample rate should be done after determining the fallback config.
The fallback config is put in the variable default_config
and should only contain values that were actually supplied by cpal, so they should never fail.
Could you try to set the requested sample rate only on the config
settings?
Hi, @orottier! I appreciate you for commenting my first contribution and my first Rust open source experience! |
src/io.rs
Outdated
@@ -425,6 +427,10 @@ pub fn build_input() -> (Stream, StreamConfig, Receiver<AudioBuffer>) { | |||
|
|||
let mut config: StreamConfig = supported_config.into(); | |||
config.buffer_size = cpal::BufferSize::Fixed(input_buffer_size); | |||
if options.sample_rate.is_some() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be written better as:
if let Some(sample_rate) = options.sample_rate {
// do stuff with sample_rate
}
This avoids the panic
path of the unwrap
call. See also https://doc.rust-lang.org/rust-by-example/flow_control/if_let.html
This is going in the right direction :) I left one nitpick on your code, please have a look. Also, the build is still failing, you can check it locally with After that we can merge and leave the latency for another time |
I fixed this. Thank you for your help. This is very important for my skills.
Also fixed this. As for other issues, maybe I would try #101. Or will find another issue to fix :) |
Great. You forgot about |
Add a note that we currently ignore the value. Since the constructor options are now identical for the AudioContext, we can use the AudioBufferOptions for the mic too.
@ork821 Since we are nearing a v1 release we need to take care of API stability. |
Hi, @orottier. Thank you for fixing my small I am not sure that usage same struct |
That's a valid point, however I would prefer to keep it this way, because either way we need breaking changes when we add the features that you mention to Let's op for a new constructor in the future |
Yes, you are actually right about breaking changes. It would be better to implement mentioned method later if we need it. I think you can merge if everything is okay. |
Partial implement of #51