/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ #include "Microphone_precompiled.h" #include #include #include "MicrophoneSystemComponent.h" namespace Audio { void MicrophoneSystemComponent::Reflect(AZ::ReflectContext* context) { if (AZ::SerializeContext* serializeContext = azrtti_cast(context)) { serializeContext->Class() ->Version(1) ; if (AZ::EditContext* editContext = serializeContext->GetEditContext()) { editContext->Class("Microphone", "Provides access to a connected Microphone Device to capture and read the data") ->ClassElement(AZ::Edit::ClassElements::EditorData, "") ->Attribute(AZ::Edit::Attributes::Category, "Audio") ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("System", 0xc94d118b)) ->Attribute(AZ::Edit::Attributes::AutoExpand, true) ; } } } void MicrophoneSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided) { provided.push_back(AZ_CRC("MicrophoneService", 0xa3a5c9d0)); } void MicrophoneSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible) { incompatible.push_back(AZ_CRC("MicrophoneService", 0xa3a5c9d0)); } void MicrophoneSystemComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required) { AZ_UNUSED(required); } void MicrophoneSystemComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent) { AZ_UNUSED(dependent); } MicrophoneSystemComponent::MicrophoneSystemComponent() : m_impl(Implementation::Create()) { } MicrophoneSystemComponent::~MicrophoneSystemComponent() { delete m_impl; m_impl = nullptr; } void MicrophoneSystemComponent::Init() { } void MicrophoneSystemComponent::Activate() { InitializeDevice(); MicrophoneRequestBus::Handler::BusConnect(); } void MicrophoneSystemComponent::Deactivate() { MicrophoneRequestBus::Handler::BusDisconnect(); EndSession(); ShutdownDevice(); } bool MicrophoneSystemComponent::InitializeDevice() { if (m_impl) { m_initialized = m_impl->InitializeDevice(); if (!m_initialized) { AZ_TracePrintf("MicrophoneSystemComponent", "Failed to initialize a Microphone device, check your OS audio device settings.\n"); ShutdownDevice(); } return m_initialized; } return false; } void MicrophoneSystemComponent::ShutdownDevice() { if (m_impl) { m_impl->ShutdownDevice(); m_initialized = false; } } bool MicrophoneSystemComponent::StartSession() { if (m_impl && m_initialized) { return m_impl->StartSession(); } return false; } void MicrophoneSystemComponent::EndSession() { if (m_impl && m_initialized) { m_impl->EndSession(); } } bool MicrophoneSystemComponent::IsCapturing() { if (m_impl && m_initialized) { return m_impl->IsCapturing(); } return false; } SAudioInputConfig MicrophoneSystemComponent::GetFormatConfig() const { if (m_impl) { return m_impl->GetFormatConfig(); } return SAudioInputConfig(); } AZStd::size_t MicrophoneSystemComponent::GetData(void** outputData, AZStd::size_t numFrames, const SAudioInputConfig& targetConfig, bool shouldDeinterleave) { if (m_impl && IsCapturing()) { return m_impl->GetData(outputData, numFrames, targetConfig, shouldDeinterleave); } return 0; } } // namespace Audio