Skip to content
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

Fix input and output scope and element usage. #104

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/audio_unit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,27 +290,28 @@ impl AudioUnit {
&mut self,
stream_format: StreamFormat,
scope: Scope,
element: Element,
) -> Result<(), Error> {
let id = sys::kAudioUnitProperty_StreamFormat;
let asbd = stream_format.to_asbd();
self.set_property(id, scope, Element::Output, Some(&asbd))
self.set_property(id, scope, element, Some(&asbd))
}

/// Return the current Stream Format for the AudioUnit.
pub fn stream_format(&self, scope: Scope) -> Result<StreamFormat, Error> {
pub fn stream_format(&self, scope: Scope, element: Element) -> Result<StreamFormat, Error> {
let id = sys::kAudioUnitProperty_StreamFormat;
let asbd = self.get_property(id, scope, Element::Output)?;
let asbd = self.get_property(id, scope, element)?;
StreamFormat::from_asbd(asbd)
}

/// Return the current output Stream Format for the AudioUnit.
pub fn output_stream_format(&self) -> Result<StreamFormat, Error> {
self.stream_format(Scope::Output)
self.stream_format(Scope::Input, Element::Output)
}

/// Return the current input Stream Format for the AudioUnit.
pub fn input_stream_format(&self) -> Result<StreamFormat, Error> {
self.stream_format(Scope::Input)
self.stream_format(Scope::Output, Element::Input)
}
}

Expand Down
8 changes: 2 additions & 6 deletions src/audio_unit/render_callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,7 @@ impl AudioUnit {
{
// First, we'll retrieve the stream format so that we can ensure that the given callback
// format matches the audio unit's format.
let id = sys::kAudioUnitProperty_StreamFormat;
let asbd = self.get_property(id, Scope::Input, Element::Output)?;
let stream_format = super::StreamFormat::from_asbd(asbd)?;
let stream_format = self.output_stream_format()?;

// If the stream format does not match, return an error indicating this.
if !D::does_stream_format_match(&stream_format) {
Expand Down Expand Up @@ -540,9 +538,7 @@ impl AudioUnit {
{
// First, we'll retrieve the stream format so that we can ensure that the given callback
// format matches the audio unit's format.
let id = sys::kAudioUnitProperty_StreamFormat;
let asbd = self.get_property(id, Scope::Output, Element::Input)?;
let stream_format = super::StreamFormat::from_asbd(asbd)?;
let stream_format = self.input_stream_format()?;

// If the stream format does not match, return an error indicating this.
if !D::does_stream_format_match(&stream_format) {
Expand Down