Microphone
Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com>
This commit is contained in:
@@ -5,8 +5,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "Microphone_precompiled.h"
|
||||
|
||||
#include "MicrophoneSystemComponent.h"
|
||||
|
||||
#include <IGem.h>
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "Microphone_precompiled.h"
|
||||
|
||||
#include <AzCore/Serialization/SerializeContext.h>
|
||||
#include <AzCore/Serialization/EditContext.h>
|
||||
|
||||
|
||||
@@ -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 <platform.h> // Many CryCommon files require that this is included first.
|
||||
@@ -5,8 +5,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "Microphone_precompiled.h"
|
||||
|
||||
#include "MicrophoneSystemComponent.h"
|
||||
#include "SimpleDownsample.h"
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "Microphone_precompiled.h"
|
||||
#include <MicrophoneSystemComponent.h>
|
||||
|
||||
namespace Audio
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "Microphone_precompiled.h"
|
||||
|
||||
#include "MicrophoneSystemComponent.h"
|
||||
|
||||
#include <audioclient.h>
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "Microphone_precompiled.h"
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <AudioToolbox/AudioToolbox.h>
|
||||
|
||||
|
||||
@@ -5,19 +5,17 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "Microphone_precompiled.h"
|
||||
|
||||
#include "SimpleDownsample.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
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<AZStd::size_t>(round((float)(offsetResult + 1) * sampleRateRatio));
|
||||
size_t nextOffsetBuffer = static_cast<size_t>(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++;
|
||||
|
||||
@@ -5,11 +5,12 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <AzCore/base.h>
|
||||
|
||||
// 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);
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#
|
||||
|
||||
set(FILES
|
||||
Source/Microphone_precompiled.h
|
||||
Source/MicrophoneSystemComponent.cpp
|
||||
Source/MicrophoneSystemComponent.h
|
||||
Source/SimpleDownsample.cpp
|
||||
|
||||
Reference in New Issue
Block a user