Skip to content

Instantly share code, notes, and snippets.

@tkemp
Created December 11, 2012 20:51
Show Gist options
  • Save tkemp/4262016 to your computer and use it in GitHub Desktop.
Save tkemp/4262016 to your computer and use it in GitHub Desktop.
Set AudioFilePlayer AU stream format
// Get the ASBD from the player unit
UInt32 playerASBDsz;
checkError(AudioUnitGetProperty(_playerUnit,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Output,
BUS_PLAYER_OUTPUT,
&_playerASBD,
&playerASBDsz),
"AudioUnitSetProperty failed: getting stream format from the player unit", false);
// Update with channels and sample rate from the main application:
_playerASBD.mChannelsPerFrame = _outputASBD.mChannelsPerFrame;
_playerASBD.mSampleRate = _outputASBD.mSampleRate;
// Re-apply the ASBD to the player unit
checkError(AudioUnitSetProperty(_playerUnit,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Output,
BUS_PLAYER_OUTPUT,
&_playerASBD,
sizeof(_playerASBD)),
"AudioUnitSetProperty failed: setting channels & sample rate to player output ASBD", false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment