diff --git a/Gems/Microphone/Code/Source/Platform/Android/MicrophoneSystemComponent_Android.cpp b/Gems/Microphone/Code/Source/Platform/Android/MicrophoneSystemComponent_Android.cpp index f30bef03ae..1e696f7978 100644 --- a/Gems/Microphone/Code/Source/Platform/Android/MicrophoneSystemComponent_Android.cpp +++ b/Gems/Microphone/Code/Source/Platform/Android/MicrophoneSystemComponent_Android.cpp @@ -121,53 +121,51 @@ namespace Audio AZStd::size_t GetData(void** outputData, AZStd::size_t numFrames, const SAudioInputConfig& targetConfig, bool shouldDeinterleave) { - - bool changeSampleType = (targetConfig.m_sampleType != m_config.m_sampleType); - bool changeSampleRate = (targetConfig.m_sampleRate != m_config.m_sampleRate); - bool changeNumChannels = (targetConfig.m_numChannels != m_config.m_numChannels); - #if defined(USE_LIBSAMPLERATE) return {}; #else - if (changeSampleType || changeNumChannels) - { - // Without the SRC library, any change is unsupported! - return {}; - } - else if (changeSampleRate) - { - if(targetConfig.m_sampleRate > m_config.m_sampleRate) + bool changeSampleType = (targetConfig.m_sampleType != m_config.m_sampleType); + bool changeSampleRate = (targetConfig.m_sampleRate != m_config.m_sampleRate); + bool changeNumChannels = (targetConfig.m_numChannels != m_config.m_numChannels); + if (changeSampleType || changeNumChannels) { - AZ_Error("MacOSMicrophone", false, "Target sample rate is larger than source sample rate, this is not supported"); + // Without the SRC library, any change is unsupported! return {}; } - - auto sourceBuffer = new AZ::s16[numFrames]; - AZStd::size_t targetSize = GetDownsampleSize(numFrames, m_config.m_sampleRate, targetConfig.m_sampleRate); - auto targetBuffer = new AZ::s16[targetSize]; - - numFrames = m_captureData->ConsumeData(reinterpret_cast(&sourceBuffer), numFrames, m_config.m_numChannels, false); - - - if(numFrames > 0) + else if (changeSampleRate) { - Downsample(sourceBuffer, numFrames, m_config.m_sampleRate, targetBuffer, targetSize, targetConfig.m_sampleRate); + if(targetConfig.m_sampleRate > m_config.m_sampleRate) + { + AZ_Error("MacOSMicrophone", false, "Target sample rate is larger than source sample rate, this is not supported"); + return {}; + } - numFrames = targetSize; - // swap target data to output - ::memcpy(*outputData, targetBuffer, targetSize * 2); //*2 as two bytes per frame + auto sourceBuffer = new AZ::s16[numFrames]; + AZStd::size_t targetSize = GetDownsampleSize(numFrames, m_config.m_sampleRate, targetConfig.m_sampleRate); + auto targetBuffer = new AZ::s16[targetSize]; + + numFrames = m_captureData->ConsumeData(reinterpret_cast(&sourceBuffer), numFrames, m_config.m_numChannels, false); + + + if(numFrames > 0) + { + Downsample(sourceBuffer, numFrames, m_config.m_sampleRate, targetBuffer, targetSize, targetConfig.m_sampleRate); + + numFrames = targetSize; + // swap target data to output + ::memcpy(*outputData, targetBuffer, targetSize * 2); //*2 as two bytes per frame + } + + delete [] sourceBuffer; + delete [] targetBuffer; + + return numFrames; + } + else + { + // No change to the data from Input to Output + return m_captureData->ConsumeData(outputData, numFrames, m_config.m_numChannels, shouldDeinterleave); } - - delete [] sourceBuffer; - delete [] targetBuffer; - - return numFrames; - } - else - { - // No change to the data from Input to Output - return m_captureData->ConsumeData(outputData, numFrames, m_config.m_numChannels, shouldDeinterleave); - } #endif }