/* * 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 #include #include #include #include #include #include #include #include #include #include #include #include #if defined(AUDIO_ENGINE_WWISE_EDITOR) #include #endif // AUDIO_ENGINE_WWISE_EDITOR namespace Audio { CAudioLogger g_audioImplLogger_wwise; CAudioWwiseImplCVars g_audioImplCVars_wwise; #if AZ_TRAIT_AUDIOENGINEWWISE_PROVIDE_IMPL_SECONDARY_POOL TMemoryPoolReferenced g_audioImplMemoryPoolSecondary_wwise; #endif // AZ_TRAIT_AUDIOENGINEWWISE_PROVIDE_IMPL_SECONDARY_POOL namespace Platform { void* InitializeSecondaryMemoryPool(size_t& secondarySize, CAudioWwiseImplCVars& audioImplCVars_wwise); } } // namespace Audio namespace AudioEngineWwiseGem { void AudioEngineWwiseGemSystemComponent::Reflect(AZ::ReflectContext* context) { if (AZ::SerializeContext* serialize = azrtti_cast(context)) { serialize->Class() ->Version(0) ; if (AZ::EditContext* ec = serialize->GetEditContext()) { ec->Class("Audio Engine Wwise Gem", "Wwise implementation of the Audio Engine interfaces") ->ClassElement(AZ::Edit::ClassElements::EditorData, "") ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("System")) ->Attribute(AZ::Edit::Attributes::AutoExpand, true) ; } } Audio::Wwise::ConfigurationSettings::Reflect(context); } void AudioEngineWwiseGemSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided) { provided.push_back(AZ_CRC("AudioEngineService")); } void AudioEngineWwiseGemSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible) { incompatible.push_back(AZ_CRC("AudioEngineService")); } void AudioEngineWwiseGemSystemComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required) { required.push_back(AZ_CRC("AudioSystemService")); } void AudioEngineWwiseGemSystemComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent) { dependent.push_back(AZ_CRC("AudioSystemService")); } void AudioEngineWwiseGemSystemComponent::Init() { } void AudioEngineWwiseGemSystemComponent::Activate() { Audio::Gem::AudioEngineGemRequestBus::Handler::BusConnect(); #if defined(AUDIO_ENGINE_WWISE_EDITOR) AudioControlsEditor::EditorImplPluginEventBus::Handler::BusConnect(); #endif // AUDIO_ENGINE_WWISE_EDITOR } void AudioEngineWwiseGemSystemComponent::Deactivate() { Audio::Gem::AudioEngineGemRequestBus::Handler::BusDisconnect(); #if defined(AUDIO_ENGINE_WWISE_EDITOR) AudioControlsEditor::EditorImplPluginEventBus::Handler::BusDisconnect(); #endif // AUDIO_ENGINE_WWISE_EDITOR } bool AudioEngineWwiseGemSystemComponent::Initialize(const SSystemInitParams* initParams) { using namespace Audio; bool success = false; g_audioImplCVars_wwise.RegisterVariables(); // initialize audio impl memory pools if (!AZ::AllocatorInstance::IsReady()) { const size_t poolSize = g_audioImplCVars_wwise.m_nPrimaryMemoryPoolSize << 10; AudioImplAllocator::Descriptor allocDesc; // Generic Allocator: allocDesc.m_allocationRecords = true; allocDesc.m_heap.m_numFixedMemoryBlocks = 1; allocDesc.m_heap.m_fixedMemoryBlocksByteSize[0] = poolSize; allocDesc.m_heap.m_fixedMemoryBlocks[0] = AZ::AllocatorInstance::Get().Allocate(allocDesc.m_heap.m_fixedMemoryBlocksByteSize[0], allocDesc.m_heap.m_memoryBlockAlignment); AZ::AllocatorInstance::Create(allocDesc); } m_engineWwise = AZStd::make_unique(initParams->assetsPlatform); if (m_engineWwise) { #if AZ_TRAIT_AUDIOENGINEWWISE_PROVIDE_IMPL_SECONDARY_POOL size_t secondarySize = 0; void* secondaryMemoryPtr = Platform::InitializeSecondaryMemoryPool(secondarySize, g_audioImplCVars_wwise); g_audioImplMemoryPoolSecondary_wwise.InitMem(secondarySize, static_cast(secondaryMemoryPtr)); #endif // AZ_TRAIT_AUDIOENGINEWWISE_PROVIDE_IMPL_SECONDARY_POOL g_audioImplLogger_wwise.Log(eALT_ALWAYS, "AudioEngineWwise created!"); SAudioRequest oAudioRequestData; oAudioRequestData.nFlags = (eARF_PRIORITY_HIGH | eARF_EXECUTE_BLOCKING); SAudioManagerRequestData oAMData; oAudioRequestData.pData = &oAMData; AudioSystemRequestBus::Broadcast(&AudioSystemRequestBus::Events::PushRequestBlocking, oAudioRequestData); success = true; } else { g_audioImplLogger_wwise.Log(eALT_ALWAYS, "Could not create AudioEngineWwise!"); } return success; } void AudioEngineWwiseGemSystemComponent::Release() { m_engineWwise.reset(); if (AZ::AllocatorInstance::IsReady()) { AZ::AllocatorInstance::Destroy(); } Audio::g_audioImplCVars_wwise.UnregisterVariables(); } #if defined(AUDIO_ENGINE_WWISE_EDITOR) void AudioEngineWwiseGemSystemComponent::InitializeEditorImplPlugin() { m_editorImplPlugin.reset(new AudioControls::CAudioSystemEditor_wwise()); } void AudioEngineWwiseGemSystemComponent::ReleaseEditorImplPlugin() { m_editorImplPlugin.reset(); } AudioControls::IAudioSystemEditor* AudioEngineWwiseGemSystemComponent::GetEditorImplPlugin() { return m_editorImplPlugin.get(); } #endif // AUDIO_ENGINE_WWISE_EDITOR } // namespace AudioEngineWwiseGem