Skip to content

Commit

Permalink
Merge pull request #104 from akhudek/master
Browse files Browse the repository at this point in the history
Fix input and output scope and element usage.
  • Loading branch information
simlay authored Apr 4, 2024
2 parents a128519 + 939e503 commit 3233a54
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
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

0 comments on commit 3233a54

Please sign in to comment.