AudioStreamBasicDescription asbdWithInfo(Boolean isFloat,int numberOfChannels,Boolean interleavedIfStereo){
AudioStreamBasicDescription asbd = {0};
int sampleSize = isFloat ? sizeof(float) : sizeof(SInt16);
asbd.mChannelsPerFrame = (numberOfChannels == 1) ? 1 : 2;
asbd.mBitsPerChannel = 8 * sampleSize;
asbd.mFramesPerPacket = 1;
asbd.mSampleRate = 44100.0;
asbd.mBytesPerFrame = interleavedIfStereo ? sampleSize * asbd.mChannelsPerFrame : sampleSize;
asbd.mBytesPerPacket = asbd.mBytesPerFrame;
asbd.mReserved = 0;
asbd.mFormatID = kAudioFormatLinearPCM;
if (isFloat) {
asbd.mFormatFlags = kAudioFormatFlagIsFloat;
if (interleavedIfStereo) {
if (numberOfChannels == 1) {
asbd.mFormatFlags = asbd.mFormatFlags | kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsPacked | kAudioFormatFlagIsNonInterleaved;
}
}
else{
asbd.mFormatFlags = asbd.mFormatFlags | kAudioFormatFlagIsNonInterleaved | kAudioFormatFlagIsPacked ;
}
}
else{
asbd.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsPacked;
if (!interleavedIfStereo) {
if (numberOfChannels > 1) {
asbd.mFormatFlags = asbd.mFormatFlags | kAudioFormatFlagIsNonInterleaved;
}
}
}
return asbd;
}