in src/backend/mod.rs [246:286]
fn create_stream_description(stream_params: &StreamParams) -> Result<AudioStreamBasicDescription> {
assert!(stream_params.rate() > 0);
assert!(stream_params.channels() > 0);
let mut desc = AudioStreamBasicDescription::default();
match stream_params.format() {
SampleFormat::S16LE => {
desc.mBitsPerChannel = 16;
desc.mFormatFlags = kAudioFormatFlagIsSignedInteger;
}
SampleFormat::S16BE => {
desc.mBitsPerChannel = 16;
desc.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsBigEndian;
}
SampleFormat::Float32LE => {
desc.mBitsPerChannel = 32;
desc.mFormatFlags = kAudioFormatFlagIsFloat;
}
SampleFormat::Float32BE => {
desc.mBitsPerChannel = 32;
desc.mFormatFlags = kAudioFormatFlagIsFloat | kAudioFormatFlagIsBigEndian;
}
_ => {
return Err(Error::invalid_format());
}
}
desc.mFormatID = kAudioFormatLinearPCM;
desc.mFormatFlags |= kLinearPCMFormatFlagIsPacked;
desc.mSampleRate = f64::from(stream_params.rate());
desc.mChannelsPerFrame = stream_params.channels();
desc.mBytesPerFrame = (desc.mBitsPerChannel / 8) * desc.mChannelsPerFrame;
desc.mFramesPerPacket = 1;
desc.mBytesPerPacket = desc.mBytesPerFrame * desc.mFramesPerPacket;
desc.mReserved = 0;
Ok(desc)
}