if (pDescription->mFormatID != kAudioFormatLinearPCM) {
return MAL_FORMAT_NOT_SUPPORTED;
}
// We don't support any non-packed formats that are aligned high.
if ((pDescription->mFormatFlags & kLinearPCMFormatFlagIsAlignedHigh) != 0) {
return MAL_FORMAT_NOT_SUPPORTED;
}
if ((pDescription->mFormatFlags & kLinearPCMFormatFlagIsFloat) != 0) {
if (pDescription->mBitsPerChannel == 32) {
*pFormatOut = mal_format_f32;
return MAL_SUCCESS;
}
} else {
if ((pDescription->mFormatFlags & kLinearPCMFormatFlagIsSignedInteger) != 0) {
if (pDescription->mBitsPerChannel == 16) {
*pFormatOut = mal_format_s16;
return MAL_SUCCESS;
} else if (pDescription->mBitsPerChannel == 24) {
if (pDescription->mBytesPerFrame == (pDescription->mBitsPerChannel/8 * pDescription->mChannelsPerFrame)) {
*pFormatOut = mal_format_s24;
return MAL_SUCCESS;
} else {
if (pDescription->mBytesPerFrame/pDescription->mChannelsPerFrame == sizeof(mal_int32)) {
// TODO: Implement mal_format_s24_32.
//*pFormatOut = mal_format_s24_32;
//return MAL_SUCCESS;
return MAL_FORMAT_NOT_SUPPORTED;
}
}
} else if (pDescription->mBitsPerChannel == 32) {
*pFormatOut = mal_format_s32;
return MAL_SUCCESS;
}
} else {
if (pDescription->mBitsPerChannel == 8) {
*pFormatOut = mal_format_u8;
return MAL_SUCCESS;
}
}
}
// Getting here means the format is not supported.
return MAL_FORMAT_NOT_SUPPORTED;
}
mal_result mal_get_device_object_ids__coreaudio(mal_context* pContext, UInt32* pDeviceCount, AudioObjectID** ppDeviceObjectIDs) // NOTE: Free the returned buffer with mal_free().
// Ignore this description if the internal sample rate is out of range.
if (sampleRate < description.mSampleRateRange.mMinimum || sampleRate > description.mSampleRateRange.mMaximum) {
continue;
}
mal_format format;
result = mal_format_from_AudioStreamBasicDescription(&description.mFormat, &format);
if (result != MAL_SUCCESS) {
continue;
}
*pFormatOut = format;
break;
}
mal_free(pStreamDescriptions);
if (*pFormatOut == mal_format_unknown) {
return MAL_FORMAT_NOT_SUPPORTED;
} else {
return MAL_SUCCESS;
}
}
mal_result mal_get_AudioObject_channel_layout(AudioObjectID deviceObjectID, mal_device_type deviceType, AudioChannelLayout** ppChannelLayout) // NOTE: Free the returned pointer with mal_free().