From 04074f5d74fe86f3a4e1cee086231c29d60cc864 Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Mon, 22 Feb 2021 20:48:23 -0800 Subject: [PATCH] Fix Core Audio input to report and decode format native bits per sample, and report file bitrate --- Plugins/CoreAudio/CoreAudioDecoder.h | 1 + Plugins/CoreAudio/CoreAudioDecoder.m | 31 ++++++++++++++++++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/Plugins/CoreAudio/CoreAudioDecoder.h b/Plugins/CoreAudio/CoreAudioDecoder.h index 416b95b03..dde98eec7 100644 --- a/Plugins/CoreAudio/CoreAudioDecoder.h +++ b/Plugins/CoreAudio/CoreAudioDecoder.h @@ -20,6 +20,7 @@ #import +#include #include #import "Plugin.h" diff --git a/Plugins/CoreAudio/CoreAudioDecoder.m b/Plugins/CoreAudio/CoreAudioDecoder.m index 4d20636e3..8ced2c93a 100644 --- a/Plugins/CoreAudio/CoreAudioDecoder.m +++ b/Plugins/CoreAudio/CoreAudioDecoder.m @@ -126,6 +126,7 @@ static SInt64 getSizeProc(void* clientData) { OSStatus err; UInt32 size; AudioStreamBasicDescription asbd; + AudioFileID afi; // Get input file information size = sizeof(asbd); @@ -144,17 +145,39 @@ static SInt64 getSizeProc(void* clientData) { } totalFrames = total; - //Is there a way to get bitrate with extAudioFile? - bitrate = 0; + size = sizeof(afi); + err = ExtAudioFileGetProperty(_in, kExtAudioFileProperty_AudioFile, &size, &afi); + if(err != noErr) { + err = ExtAudioFileDispose(_in); + return NO; + } + + SInt32 formatBitsPerSample; + size = sizeof(formatBitsPerSample); + err = AudioFileGetProperty(afi, kAudioFilePropertySourceBitDepth, &size, &formatBitsPerSample); + if(err != noErr) { + err = ExtAudioFileDispose(_in); + return NO; + } + + UInt32 _bitrate; + size = sizeof(_bitrate); + err = AudioFileGetProperty(afi, kAudioFilePropertyBitRate, &size, &_bitrate); + if(err != noErr) { + err = ExtAudioFileDispose(_in); + return NO; + } + bitrate = (_bitrate + 500) / 1000; + // Set our properties - bitsPerSample = asbd.mBitsPerChannel; + bitsPerSample = formatBitsPerSample; channels = asbd.mChannelsPerFrame; frequency = asbd.mSampleRate; floatingPoint = NO; // mBitsPerChannel will only be set for lpcm formats - if(0 == bitsPerSample) { + if(bitsPerSample <= 0) { bitsPerSample = 32; floatingPoint = YES; }