From f91c4a31040c57326e536012e593af37ec2dbc00 Mon Sep 17 00:00:00 2001 From: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> Date: Mon, 12 Jul 2021 20:01:53 -0700 Subject: [PATCH] Microphone Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> --- .../Code/Source/MicrophoneModule.cpp | 2 -- .../Code/Source/MicrophoneSystemComponent.cpp | 2 -- .../Code/Source/Microphone_precompiled.h | 10 ------ .../MicrophoneSystemComponent_Android.cpp | 2 -- .../None/MicrophoneSystemComponent_None.cpp | 1 - .../MicrophoneSystemComponent_Windows.cpp | 32 +++++++++++++++---- .../iOS/MicrophoneSystemComponent_iOS.mm | 2 -- .../Code/Source/SimpleDownsample.cpp | 20 ++++++------ .../Microphone/Code/Source/SimpleDownsample.h | 7 ++-- Gems/Microphone/Code/microphone_files.cmake | 1 - 10 files changed, 38 insertions(+), 41 deletions(-) delete mode 100644 Gems/Microphone/Code/Source/Microphone_precompiled.h diff --git a/Gems/Microphone/Code/Source/MicrophoneModule.cpp b/Gems/Microphone/Code/Source/MicrophoneModule.cpp index 6830ce7fc2..eea9c98bee 100644 --- a/Gems/Microphone/Code/Source/MicrophoneModule.cpp +++ b/Gems/Microphone/Code/Source/MicrophoneModule.cpp @@ -5,8 +5,6 @@ * */ -#include "Microphone_precompiled.h" - #include "MicrophoneSystemComponent.h" #include diff --git a/Gems/Microphone/Code/Source/MicrophoneSystemComponent.cpp b/Gems/Microphone/Code/Source/MicrophoneSystemComponent.cpp index 1dee506d97..023062e8f7 100644 --- a/Gems/Microphone/Code/Source/MicrophoneSystemComponent.cpp +++ b/Gems/Microphone/Code/Source/MicrophoneSystemComponent.cpp @@ -5,8 +5,6 @@ * */ -#include "Microphone_precompiled.h" - #include #include diff --git a/Gems/Microphone/Code/Source/Microphone_precompiled.h b/Gems/Microphone/Code/Source/Microphone_precompiled.h deleted file mode 100644 index eefa26c318..0000000000 --- a/Gems/Microphone/Code/Source/Microphone_precompiled.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ - -#pragma once - -#include // Many CryCommon files require that this is included first. diff --git a/Gems/Microphone/Code/Source/Platform/Android/MicrophoneSystemComponent_Android.cpp b/Gems/Microphone/Code/Source/Platform/Android/MicrophoneSystemComponent_Android.cpp index 3bf4fb7410..3b6cb90c09 100644 --- a/Gems/Microphone/Code/Source/Platform/Android/MicrophoneSystemComponent_Android.cpp +++ b/Gems/Microphone/Code/Source/Platform/Android/MicrophoneSystemComponent_Android.cpp @@ -5,8 +5,6 @@ * */ -#include "Microphone_precompiled.h" - #include "MicrophoneSystemComponent.h" #include "SimpleDownsample.h" diff --git a/Gems/Microphone/Code/Source/Platform/None/MicrophoneSystemComponent_None.cpp b/Gems/Microphone/Code/Source/Platform/None/MicrophoneSystemComponent_None.cpp index ac64680b31..19c27087c7 100644 --- a/Gems/Microphone/Code/Source/Platform/None/MicrophoneSystemComponent_None.cpp +++ b/Gems/Microphone/Code/Source/Platform/None/MicrophoneSystemComponent_None.cpp @@ -5,7 +5,6 @@ * */ -#include "Microphone_precompiled.h" #include namespace Audio diff --git a/Gems/Microphone/Code/Source/Platform/Windows/MicrophoneSystemComponent_Windows.cpp b/Gems/Microphone/Code/Source/Platform/Windows/MicrophoneSystemComponent_Windows.cpp index 2b72c58b76..e0dec84ac7 100644 --- a/Gems/Microphone/Code/Source/Platform/Windows/MicrophoneSystemComponent_Windows.cpp +++ b/Gems/Microphone/Code/Source/Platform/Windows/MicrophoneSystemComponent_Windows.cpp @@ -5,8 +5,6 @@ * */ -#include "Microphone_precompiled.h" - #include "MicrophoneSystemComponent.h" #include @@ -101,7 +99,11 @@ namespace Audio } PropVariantClear(&endpointName); - SAFE_RELEASE(m_deviceProps); + if (m_deviceProps) + { + m_deviceProps->Release(); + m_deviceProps = nullptr; + } } return true; @@ -115,8 +117,16 @@ namespace Audio // Assert: m_audioClient and m_audioCaptureClient are both nullptr! (i.e. the capture thread is not running) AZ_Assert(!m_audioClient && !m_audioCaptureClient, "ShutdownDevice - Audio Client pointers are not null! You need to call EndSession first!\n"); - SAFE_RELEASE(m_device); - SAFE_RELEASE(m_enumerator); + if (m_device) + { + m_device->Release(); + m_device = nullptr; + } + if (m_enumerator) + { + m_enumerator->Release(); + m_enumerator = nullptr; + } CoUninitialize(); } @@ -317,8 +327,16 @@ namespace Audio } } - SAFE_RELEASE(m_audioCaptureClient); - SAFE_RELEASE(m_audioClient); + if (m_audioCaptureClient) + { + m_audioCaptureClient->Release(); + m_audioCaptureClient = nullptr; + } + if (m_audioClient) + { + m_audioClient->Release(); + m_audioClient = nullptr; + } CoTaskMemFree(m_streamFormat); m_streamFormat = nullptr; diff --git a/Gems/Microphone/Code/Source/Platform/iOS/MicrophoneSystemComponent_iOS.mm b/Gems/Microphone/Code/Source/Platform/iOS/MicrophoneSystemComponent_iOS.mm index 3601ff3c4b..55af31c6d6 100644 --- a/Gems/Microphone/Code/Source/Platform/iOS/MicrophoneSystemComponent_iOS.mm +++ b/Gems/Microphone/Code/Source/Platform/iOS/MicrophoneSystemComponent_iOS.mm @@ -5,8 +5,6 @@ * */ -#include "Microphone_precompiled.h" - #import #import diff --git a/Gems/Microphone/Code/Source/SimpleDownsample.cpp b/Gems/Microphone/Code/Source/SimpleDownsample.cpp index 854451b830..15e6778e72 100644 --- a/Gems/Microphone/Code/Source/SimpleDownsample.cpp +++ b/Gems/Microphone/Code/Source/SimpleDownsample.cpp @@ -5,19 +5,17 @@ * */ -#include "Microphone_precompiled.h" - #include "SimpleDownsample.h" #include -AZStd::size_t GetDownsampleSize(AZStd::size_t sourceSize, AZ::u32 sourceSampleRate, AZ::u32 targetSampleRate) +size_t GetDownsampleSize(size_t sourceSize, AZ::u32 sourceSampleRate, AZ::u32 targetSampleRate) { - return (AZStd::size_t)round((float)sourceSize / ((float)sourceSampleRate / (float)targetSampleRate)); + return (size_t)round((float)sourceSize / ((float)sourceSampleRate / (float)targetSampleRate)); } -void Downsample(AZ::s16* inBuffer, AZStd::size_t inBufferSize, AZ::u32 inBufferSampleRate, - AZ::s16* outBuffer, AZStd::size_t outBufferSize, AZ::u32 outBufferSampleRate) +void Downsample(AZ::s16* inBuffer, size_t inBufferSize, AZ::u32 inBufferSampleRate, + AZ::s16* outBuffer, size_t outBufferSize, AZ::u32 outBufferSampleRate) { if(inBufferSampleRate == outBufferSampleRate) { @@ -31,14 +29,14 @@ void Downsample(AZ::s16* inBuffer, AZStd::size_t inBufferSize, AZ::u32 inBufferS } float sampleRateRatio = (float)inBufferSampleRate / (float)outBufferSampleRate; - AZStd::size_t offsetResult = 0; - AZStd::size_t offsetBuffer = 0; + size_t offsetResult = 0; + size_t offsetBuffer = 0; while(offsetResult < outBufferSize) { - AZStd::size_t nextOffsetBuffer = static_cast(round((float)(offsetResult + 1) * sampleRateRatio)); + size_t nextOffsetBuffer = static_cast(round((float)(offsetResult + 1) * sampleRateRatio)); AZ::s32 accum = 0; // this must be int 32 so it doesn't overflow with multiple int 16's possibly at max - AZStd::size_t count = 0; - for(AZStd::size_t i = offsetBuffer; i < nextOffsetBuffer && i < inBufferSize; ++i) + size_t count = 0; + for(size_t i = offsetBuffer; i < nextOffsetBuffer && i < inBufferSize; ++i) { accum += inBuffer[i]; count++; diff --git a/Gems/Microphone/Code/Source/SimpleDownsample.h b/Gems/Microphone/Code/Source/SimpleDownsample.h index abc87f191a..4a782975ee 100644 --- a/Gems/Microphone/Code/Source/SimpleDownsample.h +++ b/Gems/Microphone/Code/Source/SimpleDownsample.h @@ -5,11 +5,12 @@ * */ +#include // determine the new buffer size for downsampling -AZStd::size_t GetDownsampleSize(AZStd::size_t sourceSize, AZ::u32 sourceSampleRate, AZ::u32 targetSampleRate); +size_t GetDownsampleSize(size_t sourceSize, AZ::u32 sourceSampleRate, AZ::u32 targetSampleRate); // down sample a 16 bit audio buffer from on sample rate frequency to another lower sample rate frequency // outBuffer must already be allocated and large enough to hold the downsampled result -void Downsample(AZ::s16* inBuffer, AZStd::size_t inBufferSize, AZ::u32 inBufferSampleRate, - AZ::s16* outBuffer, AZStd::size_t outBufferSize, AZ::u32 outBufferSampleRate); +void Downsample(AZ::s16* inBuffer, size_t inBufferSize, AZ::u32 inBufferSampleRate, + AZ::s16* outBuffer, size_t outBufferSize, AZ::u32 outBufferSampleRate); diff --git a/Gems/Microphone/Code/microphone_files.cmake b/Gems/Microphone/Code/microphone_files.cmake index 233ce8eb91..6ebb8223ae 100644 --- a/Gems/Microphone/Code/microphone_files.cmake +++ b/Gems/Microphone/Code/microphone_files.cmake @@ -6,7 +6,6 @@ # set(FILES - Source/Microphone_precompiled.h Source/MicrophoneSystemComponent.cpp Source/MicrophoneSystemComponent.h Source/SimpleDownsample.cpp