mirror of
https://github.com/id-Software/DOOM-3-BFG.git
synced 2024-12-03 09:22:45 +00:00
Copied neo/sound/XAudio2/XA2_* to neo/sound/OpenAL/AL_*
This commit is contained in:
parent
946768ad9f
commit
9a40f246b6
8 changed files with 2286 additions and 25 deletions
|
@ -12,8 +12,8 @@ option(MONOLITH
|
|||
option(SDL2
|
||||
"Use SDL2 instead of SDL1.2" OFF)
|
||||
|
||||
#option(STANDALONE
|
||||
# "Skip Doom 3 base/ folder" ON)
|
||||
option(OPENAL
|
||||
"Use OpenAL soft instead of XAudio2" ON)
|
||||
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
|
||||
|
@ -382,6 +382,16 @@ set(XAUDIO2_SOURCES
|
|||
sound/XAudio2/XA2_SoundHardware.cpp
|
||||
sound/XAudio2/XA2_SoundSample.cpp
|
||||
sound/XAudio2/XA2_SoundVoice.cpp)
|
||||
|
||||
set(OPENAL_INCLUDES
|
||||
sound/OpenAL/AL_SoundHardware.h
|
||||
sound/OpenAL/AL_SoundSample.h
|
||||
sound/OpenAL/AL_SoundVoice.h)
|
||||
|
||||
set(OPENAL_SOURCES
|
||||
sound/OpenAL/AL_SoundHardware.cpp
|
||||
sound/OpenAL/AL_SoundSample.cpp
|
||||
sound/OpenAL/AL_SoundVoice.cpp)
|
||||
|
||||
set(STUBAUDIO_INCLUDES
|
||||
sound/stub/SoundStub.h)
|
||||
|
@ -798,6 +808,9 @@ source_group("sound" FILES ${SOUND_SOURCES})
|
|||
source_group("sound\\XAudio2" FILES ${XAUDIO2_INCLUDES})
|
||||
source_group("sound\\XAudio2" FILES ${XAUDIO2_SOURCES})
|
||||
|
||||
source_group("sound\\OpenAL" FILES ${OPENAL_INCLUDES})
|
||||
source_group("sound\\OpenAL" FILES ${OPENAL_SOURCES})
|
||||
|
||||
source_group("sound\\stub" FILES ${STUBAUDIO_INCLUDES})
|
||||
source_group("sound\\stub" FILES ${STUBAUDIO_SOURCES})
|
||||
|
||||
|
@ -1003,8 +1016,6 @@ include_directories(
|
|||
|
||||
if(MSVC)
|
||||
|
||||
add_definitions(-DUSE_DOOMCLASSIC)
|
||||
|
||||
if(MSVC_VERSION EQUAL 1700)
|
||||
set(DirectX_LIBRARIES
|
||||
dinput8
|
||||
|
@ -1014,11 +1025,41 @@ if(MSVC)
|
|||
Xinput
|
||||
xaudio2.lib
|
||||
)
|
||||
add_definitions(-DUSE_XINPUT)
|
||||
|
||||
if(NOT OPENAL)
|
||||
list(APPEND DirectX_LIBRARIES xaudio2.lib)
|
||||
endif()
|
||||
|
||||
else()
|
||||
find_package(DirectX REQUIRED)
|
||||
include_directories(${DirectX_INCLUDE_DIR})
|
||||
add_definitions(-DUSE_XINPUT)
|
||||
endif()
|
||||
|
||||
if(OPENAL)
|
||||
add_definitions(-DUSE_OPENAL)
|
||||
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/libs/openal-soft/include)
|
||||
|
||||
if(CMAKE_CL_64)
|
||||
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/libs/openal-soft/lib/win64)
|
||||
else()
|
||||
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/libs/openal-soft/lib/win32)
|
||||
endif()
|
||||
|
||||
list(APPEND RBDOOM3_INCLUDES ${OPENAL_INCLUDES})
|
||||
list(APPEND RBDOOM3_SOURCES ${OPENAL_SOURCES})
|
||||
else()
|
||||
add_definitions(-DUSE_DOOMCLASSIC)
|
||||
|
||||
list(APPEND RBDOOM3_INCLUDES
|
||||
${XAUDIO2_INCLUDES}
|
||||
${DOOMCLASSIC_INCLUDES}
|
||||
${TIMIDITY_INCLUDES})
|
||||
|
||||
list(APPEND RBDOOM3_SOURCES
|
||||
${XAUDIO2_SOURCES}
|
||||
${DOOMCLASSIC_SOURCES}
|
||||
${TIMIDITY_SOURCES})
|
||||
endif()
|
||||
|
||||
if(USE_MFC_TOOLS)
|
||||
|
@ -1026,9 +1067,9 @@ if(MSVC)
|
|||
include_directories(libs/atlmfc/include)
|
||||
if(CMAKE_CL_64)
|
||||
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/libs/atlmfc/lib/amd64)
|
||||
else(CMAKE_CL_64)
|
||||
else()
|
||||
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/libs/atlmfc/lib)
|
||||
endif(CMAKE_CL_64)
|
||||
endif()
|
||||
|
||||
add_definitions(-DUSE_MFC_TOOLS)
|
||||
|
||||
|
@ -1051,19 +1092,11 @@ if(MSVC)
|
|||
endif()
|
||||
|
||||
list(APPEND RBDOOM3_INLCUDES
|
||||
${DOOMCLASSIC_INCLUDES}
|
||||
${TIMIDITY_INCLUDES}
|
||||
|
||||
${SYS_INCLUDES}
|
||||
${XAUDIO2_INCLUDES}
|
||||
${WIN32_INCLUDES})
|
||||
|
||||
list(APPEND RBDOOM3_SOURCES
|
||||
${DOOMCLASSIC_SOURCES}
|
||||
${TIMIDITY_SOURCES}
|
||||
|
||||
${SYS_SOURCES}
|
||||
${XAUDIO2_SOURCES}
|
||||
${WIN32_SOURCES})
|
||||
|
||||
list(REMOVE_DUPLICATES RBDOOM3_SOURCES)
|
||||
|
@ -1122,13 +1155,13 @@ if(MSVC)
|
|||
)
|
||||
|
||||
#CMAKE_BINARY_DIR
|
||||
# if(CMAKE_CL_64)
|
||||
# install(TARGETS RBDoom3BFG
|
||||
# RUNTIME DESTINATION ../bin/win64)
|
||||
# else()
|
||||
# install(TARGETS RBDoom3BFG
|
||||
# RUNTIME DESTINATION ../bin/win32)
|
||||
# endif()
|
||||
if(CMAKE_CL_64)
|
||||
install(TARGETS RBDoom3BFG
|
||||
RUNTIME DESTINATION ../bin/win64)
|
||||
else()
|
||||
install(TARGETS RBDoom3BFG
|
||||
RUNTIME DESTINATION ../bin/win32)
|
||||
endif()
|
||||
|
||||
else()
|
||||
|
||||
|
|
662
neo/sound/OpenAL/AL_SoundHardware.cpp
Normal file
662
neo/sound/OpenAL/AL_SoundHardware.cpp
Normal file
|
@ -0,0 +1,662 @@
|
|||
/*
|
||||
===========================================================================
|
||||
|
||||
Doom 3 BFG Edition GPL Source Code
|
||||
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
|
||||
Copyright (C) 2012 Robert Beckebans
|
||||
|
||||
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
|
||||
|
||||
Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
|
||||
|
||||
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
|
||||
|
||||
===========================================================================
|
||||
*/
|
||||
#pragma hdrstop
|
||||
#include "precompiled.h"
|
||||
#include "../snd_local.h"
|
||||
//#include "../../../doomclassic/doom/i_sound.h"
|
||||
|
||||
idCVar s_showLevelMeter( "s_showLevelMeter", "0", CVAR_BOOL | CVAR_ARCHIVE, "Show VU meter" );
|
||||
idCVar s_meterTopTime( "s_meterTopTime", "1000", CVAR_INTEGER | CVAR_ARCHIVE, "How long (in milliseconds) peaks are displayed on the VU meter" );
|
||||
idCVar s_meterPosition( "s_meterPosition", "100 100 20 200", CVAR_ARCHIVE, "VU meter location (x y w h)" );
|
||||
idCVar s_device( "s_device", "-1", CVAR_INTEGER | CVAR_ARCHIVE, "Which audio device to use (listDevices to list, -1 for default)" );
|
||||
idCVar s_showPerfData( "s_showPerfData", "0", CVAR_BOOL, "Show XAudio2 Performance data" );
|
||||
extern idCVar s_volume_dB;
|
||||
|
||||
/*
|
||||
========================
|
||||
idSoundHardware_OpenAL::idSoundHardware_OpenAL
|
||||
========================
|
||||
*/
|
||||
idSoundHardware_OpenAL::idSoundHardware_OpenAL()
|
||||
{
|
||||
pXAudio2 = NULL;
|
||||
pMasterVoice = NULL;
|
||||
pSubmixVoice = NULL;
|
||||
|
||||
vuMeterRMS = NULL;
|
||||
vuMeterPeak = NULL;
|
||||
|
||||
outputChannels = 0;
|
||||
channelMask = 0;
|
||||
|
||||
voices.SetNum( 0 );
|
||||
zombieVoices.SetNum( 0 );
|
||||
freeVoices.SetNum( 0 );
|
||||
|
||||
lastResetTime = 0;
|
||||
}
|
||||
|
||||
void listDevices_f( const idCmdArgs& args )
|
||||
{
|
||||
|
||||
IXAudio2* pXAudio2 = soundSystemLocal.hardware.GetIXAudio2();
|
||||
|
||||
if( pXAudio2 == NULL )
|
||||
{
|
||||
idLib::Warning( "No xaudio object" );
|
||||
return;
|
||||
}
|
||||
|
||||
// RB: not available on Windows 8 SDK
|
||||
#if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/)
|
||||
|
||||
// FIXME
|
||||
|
||||
idLib::Warning( "No audio devices found" );
|
||||
return;
|
||||
#else
|
||||
UINT32 deviceCount = 0;
|
||||
if( pXAudio2->GetDeviceCount( &deviceCount ) != S_OK || deviceCount == 0 )
|
||||
{
|
||||
idLib::Warning( "No audio devices found" );
|
||||
return;
|
||||
}
|
||||
|
||||
for( unsigned int i = 0; i < deviceCount; i++ )
|
||||
{
|
||||
XAUDIO2_DEVICE_DETAILS deviceDetails;
|
||||
if( pXAudio2->GetDeviceDetails( i, &deviceDetails ) != S_OK )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
idStaticList< const char*, 5 > roles;
|
||||
if( deviceDetails.Role & DefaultConsoleDevice )
|
||||
{
|
||||
roles.Append( "Console Device" );
|
||||
}
|
||||
if( deviceDetails.Role & DefaultMultimediaDevice )
|
||||
{
|
||||
roles.Append( "Multimedia Device" );
|
||||
}
|
||||
if( deviceDetails.Role & DefaultCommunicationsDevice )
|
||||
{
|
||||
roles.Append( "Communications Device" );
|
||||
}
|
||||
if( deviceDetails.Role & DefaultGameDevice )
|
||||
{
|
||||
roles.Append( "Game Device" );
|
||||
}
|
||||
idStaticList< const char*, 11 > channelNames;
|
||||
if( deviceDetails.OutputFormat.dwChannelMask & SPEAKER_FRONT_LEFT )
|
||||
{
|
||||
channelNames.Append( "Front Left" );
|
||||
}
|
||||
if( deviceDetails.OutputFormat.dwChannelMask & SPEAKER_FRONT_RIGHT )
|
||||
{
|
||||
channelNames.Append( "Front Right" );
|
||||
}
|
||||
if( deviceDetails.OutputFormat.dwChannelMask & SPEAKER_FRONT_CENTER )
|
||||
{
|
||||
channelNames.Append( "Front Center" );
|
||||
}
|
||||
if( deviceDetails.OutputFormat.dwChannelMask & SPEAKER_LOW_FREQUENCY )
|
||||
{
|
||||
channelNames.Append( "Low Frequency" );
|
||||
}
|
||||
if( deviceDetails.OutputFormat.dwChannelMask & SPEAKER_BACK_LEFT )
|
||||
{
|
||||
channelNames.Append( "Back Left" );
|
||||
}
|
||||
if( deviceDetails.OutputFormat.dwChannelMask & SPEAKER_BACK_RIGHT )
|
||||
{
|
||||
channelNames.Append( "Back Right" );
|
||||
}
|
||||
if( deviceDetails.OutputFormat.dwChannelMask & SPEAKER_FRONT_LEFT_OF_CENTER )
|
||||
{
|
||||
channelNames.Append( "Front Left of Center" );
|
||||
}
|
||||
if( deviceDetails.OutputFormat.dwChannelMask & SPEAKER_FRONT_RIGHT_OF_CENTER )
|
||||
{
|
||||
channelNames.Append( "Front Right of Center" );
|
||||
}
|
||||
if( deviceDetails.OutputFormat.dwChannelMask & SPEAKER_BACK_CENTER )
|
||||
{
|
||||
channelNames.Append( "Back Center" );
|
||||
}
|
||||
if( deviceDetails.OutputFormat.dwChannelMask & SPEAKER_SIDE_LEFT )
|
||||
{
|
||||
channelNames.Append( "Side Left" );
|
||||
}
|
||||
if( deviceDetails.OutputFormat.dwChannelMask & SPEAKER_SIDE_RIGHT )
|
||||
{
|
||||
channelNames.Append( "Side Right" );
|
||||
}
|
||||
char mbcsDisplayName[ 256 ];
|
||||
wcstombs( mbcsDisplayName, deviceDetails.DisplayName, sizeof( mbcsDisplayName ) );
|
||||
idLib::Printf( "%3d: %s\n", i, mbcsDisplayName );
|
||||
idLib::Printf( " %d channels, %d Hz\n", deviceDetails.OutputFormat.Format.nChannels, deviceDetails.OutputFormat.Format.nSamplesPerSec );
|
||||
if( channelNames.Num() != deviceDetails.OutputFormat.Format.nChannels )
|
||||
{
|
||||
idLib::Printf( S_COLOR_YELLOW "WARNING: " S_COLOR_RED "Mismatch between # of channels and channel mask\n" );
|
||||
}
|
||||
if( channelNames.Num() == 1 )
|
||||
{
|
||||
idLib::Printf( " %s\n", channelNames[0] );
|
||||
}
|
||||
else if( channelNames.Num() == 2 )
|
||||
{
|
||||
idLib::Printf( " %s and %s\n", channelNames[0], channelNames[1] );
|
||||
}
|
||||
else if( channelNames.Num() > 2 )
|
||||
{
|
||||
idLib::Printf( " %s", channelNames[0] );
|
||||
for( int i = 1; i < channelNames.Num() - 1; i++ )
|
||||
{
|
||||
idLib::Printf( ", %s", channelNames[i] );
|
||||
}
|
||||
idLib::Printf( ", and %s\n", channelNames[channelNames.Num() - 1] );
|
||||
}
|
||||
if( roles.Num() == 1 )
|
||||
{
|
||||
idLib::Printf( " Default %s\n", roles[0] );
|
||||
}
|
||||
else if( roles.Num() == 2 )
|
||||
{
|
||||
idLib::Printf( " Default %s and %s\n", roles[0], roles[1] );
|
||||
}
|
||||
else if( roles.Num() > 2 )
|
||||
{
|
||||
idLib::Printf( " Default %s", roles[0] );
|
||||
for( int i = 1; i < roles.Num() - 1; i++ )
|
||||
{
|
||||
idLib::Printf( ", %s", roles[i] );
|
||||
}
|
||||
idLib::Printf( ", and %s\n", roles[roles.Num() - 1] );
|
||||
}
|
||||
}
|
||||
#endif
|
||||
// RB end
|
||||
}
|
||||
|
||||
/*
|
||||
========================
|
||||
idSoundHardware_OpenAL::Init
|
||||
========================
|
||||
*/
|
||||
void idSoundHardware_OpenAL::Init()
|
||||
{
|
||||
|
||||
cmdSystem->AddCommand( "listDevices", listDevices_f, 0, "Lists the connected sound devices", NULL );
|
||||
|
||||
DWORD xAudioCreateFlags = 0;
|
||||
|
||||
// RB: not available on Windows 8 SDK
|
||||
#if (_WIN32_WINNT < 0x0602 /*_WIN32_WINNT_WIN8*/) && defined(_DEBUG)
|
||||
xAudioCreateFlags |= XAUDIO2_DEBUG_ENGINE;
|
||||
#endif
|
||||
// RB end
|
||||
|
||||
XAUDIO2_PROCESSOR xAudioProcessor = XAUDIO2_DEFAULT_PROCESSOR;
|
||||
|
||||
// RB: not available on Windows 8 SDK
|
||||
if( FAILED( XAudio2Create( &pXAudio2, xAudioCreateFlags, xAudioProcessor ) ) )
|
||||
{
|
||||
#if (_WIN32_WINNT < 0x0602 /*_WIN32_WINNT_WIN8*/) && defined(_DEBUG)
|
||||
if( xAudioCreateFlags & XAUDIO2_DEBUG_ENGINE )
|
||||
{
|
||||
// in case the debug engine isn't installed
|
||||
xAudioCreateFlags &= ~XAUDIO2_DEBUG_ENGINE;
|
||||
if( FAILED( XAudio2Create( &pXAudio2, xAudioCreateFlags, xAudioProcessor ) ) )
|
||||
{
|
||||
idLib::FatalError( "Failed to create XAudio2 engine. Try installing the latest DirectX." );
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
// RB end
|
||||
{
|
||||
idLib::FatalError( "Failed to create XAudio2 engine. Try installing the latest DirectX." );
|
||||
return;
|
||||
}
|
||||
}
|
||||
#ifdef _DEBUG
|
||||
XAUDIO2_DEBUG_CONFIGURATION debugConfiguration = { 0 };
|
||||
debugConfiguration.TraceMask = XAUDIO2_LOG_WARNINGS;
|
||||
debugConfiguration.BreakMask = XAUDIO2_LOG_ERRORS;
|
||||
pXAudio2->SetDebugConfiguration( &debugConfiguration );
|
||||
#endif
|
||||
|
||||
// Register the sound engine callback
|
||||
pXAudio2->RegisterForCallbacks( &soundEngineCallback );
|
||||
soundEngineCallback.hardware = this;
|
||||
|
||||
// RB: not available on Windows 8 SDK
|
||||
#if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/)
|
||||
|
||||
// FIXME
|
||||
|
||||
idLib::Warning( "No audio devices found" );
|
||||
pXAudio2->Release();
|
||||
pXAudio2 = NULL;
|
||||
return;
|
||||
#else
|
||||
UINT32 deviceCount = 0;
|
||||
if( pXAudio2->GetDeviceCount( &deviceCount ) != S_OK || deviceCount == 0 )
|
||||
{
|
||||
idLib::Warning( "No audio devices found" );
|
||||
pXAudio2->Release();
|
||||
pXAudio2 = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
idCmdArgs args;
|
||||
listDevices_f( args );
|
||||
|
||||
int preferredDevice = s_device.GetInteger();
|
||||
if( preferredDevice < 0 || preferredDevice >= ( int )deviceCount )
|
||||
{
|
||||
int preferredChannels = 0;
|
||||
for( unsigned int i = 0; i < deviceCount; i++ )
|
||||
{
|
||||
XAUDIO2_DEVICE_DETAILS deviceDetails;
|
||||
if( pXAudio2->GetDeviceDetails( i, &deviceDetails ) != S_OK )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if( deviceDetails.Role & DefaultGameDevice )
|
||||
{
|
||||
// if we find a device the user marked as their preferred 'game' device, then always use that
|
||||
preferredDevice = i;
|
||||
preferredChannels = deviceDetails.OutputFormat.Format.nChannels;
|
||||
break;
|
||||
}
|
||||
|
||||
if( deviceDetails.OutputFormat.Format.nChannels > preferredChannels )
|
||||
{
|
||||
preferredDevice = i;
|
||||
preferredChannels = deviceDetails.OutputFormat.Format.nChannels;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
idLib::Printf( "Using device %d\n", preferredDevice );
|
||||
|
||||
XAUDIO2_DEVICE_DETAILS deviceDetails;
|
||||
if( pXAudio2->GetDeviceDetails( preferredDevice, &deviceDetails ) != S_OK )
|
||||
{
|
||||
// One way this could happen is if a device is removed between the loop and this line of code
|
||||
// Highly unlikely but possible
|
||||
idLib::Warning( "Failed to get device details" );
|
||||
pXAudio2->Release();
|
||||
pXAudio2 = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
DWORD outputSampleRate = 44100; // Max( (DWORD)XAUDIO2FX_REVERB_MIN_FRAMERATE, Min( (DWORD)XAUDIO2FX_REVERB_MAX_FRAMERATE, deviceDetails.OutputFormat.Format.nSamplesPerSec ) );
|
||||
|
||||
if( FAILED( pXAudio2->CreateMasteringVoice( &pMasterVoice, XAUDIO2_DEFAULT_CHANNELS, outputSampleRate, 0, preferredDevice, NULL ) ) )
|
||||
{
|
||||
idLib::Warning( "Failed to create master voice" );
|
||||
pXAudio2->Release();
|
||||
pXAudio2 = NULL;
|
||||
return;
|
||||
}
|
||||
pMasterVoice->SetVolume( DBtoLinear( s_volume_dB.GetFloat() ) );
|
||||
|
||||
outputChannels = deviceDetails.OutputFormat.Format.nChannels;
|
||||
channelMask = deviceDetails.OutputFormat.dwChannelMask;
|
||||
|
||||
idSoundVoice::InitSurround( outputChannels, channelMask );
|
||||
|
||||
// ---------------------
|
||||
// Initialize the Doom classic sound system.
|
||||
// ---------------------
|
||||
I_InitSoundHardware( outputChannels, channelMask );
|
||||
|
||||
// ---------------------
|
||||
// Create VU Meter Effect
|
||||
// ---------------------
|
||||
IUnknown* vuMeter = NULL;
|
||||
XAudio2CreateVolumeMeter( &vuMeter, 0 );
|
||||
|
||||
XAUDIO2_EFFECT_DESCRIPTOR descriptor;
|
||||
descriptor.InitialState = true;
|
||||
descriptor.OutputChannels = outputChannels;
|
||||
descriptor.pEffect = vuMeter;
|
||||
|
||||
XAUDIO2_EFFECT_CHAIN chain;
|
||||
chain.EffectCount = 1;
|
||||
chain.pEffectDescriptors = &descriptor;
|
||||
|
||||
pMasterVoice->SetEffectChain( &chain );
|
||||
|
||||
vuMeter->Release();
|
||||
|
||||
// ---------------------
|
||||
// Create VU Meter Graph
|
||||
// ---------------------
|
||||
|
||||
vuMeterRMS = console->CreateGraph( outputChannels );
|
||||
vuMeterPeak = console->CreateGraph( outputChannels );
|
||||
vuMeterRMS->Enable( false );
|
||||
vuMeterPeak->Enable( false );
|
||||
|
||||
memset( vuMeterPeakTimes, 0, sizeof( vuMeterPeakTimes ) );
|
||||
|
||||
vuMeterPeak->SetFillMode( idDebugGraph::GRAPH_LINE );
|
||||
vuMeterPeak->SetBackgroundColor( idVec4( 0.0f, 0.0f, 0.0f, 0.0f ) );
|
||||
|
||||
vuMeterRMS->AddGridLine( 0.500f, idVec4( 0.5f, 0.5f, 0.5f, 1.0f ) );
|
||||
vuMeterRMS->AddGridLine( 0.250f, idVec4( 0.5f, 0.5f, 0.5f, 1.0f ) );
|
||||
vuMeterRMS->AddGridLine( 0.125f, idVec4( 0.5f, 0.5f, 0.5f, 1.0f ) );
|
||||
|
||||
const char* channelNames[] = { "L", "R", "C", "S", "Lb", "Rb", "Lf", "Rf", "Cb", "Ls", "Rs" };
|
||||
for( int i = 0, ci = 0; ci < sizeof( channelNames ) / sizeof( channelNames[0] ); ci++ )
|
||||
{
|
||||
if( ( channelMask & BIT( ci ) ) == 0 )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
vuMeterRMS->SetLabel( i, channelNames[ ci ] );
|
||||
i++;
|
||||
}
|
||||
|
||||
// ---------------------
|
||||
// Create submix buffer
|
||||
// ---------------------
|
||||
if( FAILED( pXAudio2->CreateSubmixVoice( &pSubmixVoice, 1, outputSampleRate, 0, 0, NULL, NULL ) ) )
|
||||
{
|
||||
idLib::FatalError( "Failed to create submix voice" );
|
||||
}
|
||||
|
||||
// XAudio doesn't really impose a maximum number of voices
|
||||
voices.SetNum( voices.Max() );
|
||||
freeVoices.SetNum( voices.Max() );
|
||||
zombieVoices.SetNum( 0 );
|
||||
for( int i = 0; i < voices.Num(); i++ )
|
||||
{
|
||||
freeVoices[i] = &voices[i];
|
||||
}
|
||||
#endif // #if (_WIN32_WINNT < 0x0602 /*_WIN32_WINNT_WIN8*/)
|
||||
// RB end
|
||||
}
|
||||
|
||||
/*
|
||||
========================
|
||||
idSoundHardware_OpenAL::Shutdown
|
||||
========================
|
||||
*/
|
||||
void idSoundHardware_OpenAL::Shutdown()
|
||||
{
|
||||
for( int i = 0; i < voices.Num(); i++ )
|
||||
{
|
||||
voices[ i ].DestroyInternal();
|
||||
}
|
||||
voices.Clear();
|
||||
freeVoices.Clear();
|
||||
zombieVoices.Clear();
|
||||
|
||||
// ---------------------
|
||||
// Shutdown the Doom classic sound system.
|
||||
// ---------------------
|
||||
//I_ShutdownSoundHardware();
|
||||
|
||||
if( pXAudio2 != NULL )
|
||||
{
|
||||
// Unregister the sound engine callback
|
||||
pXAudio2->UnregisterForCallbacks( &soundEngineCallback );
|
||||
}
|
||||
|
||||
if( pSubmixVoice != NULL )
|
||||
{
|
||||
pSubmixVoice->DestroyVoice();
|
||||
pSubmixVoice = NULL;
|
||||
}
|
||||
if( pMasterVoice != NULL )
|
||||
{
|
||||
// release the vu meter effect
|
||||
pMasterVoice->SetEffectChain( NULL );
|
||||
pMasterVoice->DestroyVoice();
|
||||
pMasterVoice = NULL;
|
||||
}
|
||||
if( pXAudio2 != NULL )
|
||||
{
|
||||
XAUDIO2_PERFORMANCE_DATA perfData;
|
||||
pXAudio2->GetPerformanceData( &perfData );
|
||||
idLib::Printf( "Final pXAudio2 performanceData: Voices: %d/%d CPU: %.2f%% Mem: %dkb\n", perfData.ActiveSourceVoiceCount, perfData.TotalSourceVoiceCount, perfData.AudioCyclesSinceLastQuery / ( float )perfData.TotalCyclesSinceLastQuery, perfData.MemoryUsageInBytes / 1024 );
|
||||
pXAudio2->Release();
|
||||
pXAudio2 = NULL;
|
||||
}
|
||||
if( vuMeterRMS != NULL )
|
||||
{
|
||||
console->DestroyGraph( vuMeterRMS );
|
||||
vuMeterRMS = NULL;
|
||||
}
|
||||
if( vuMeterPeak != NULL )
|
||||
{
|
||||
console->DestroyGraph( vuMeterPeak );
|
||||
vuMeterPeak = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
========================
|
||||
idSoundHardware_OpenAL::AllocateVoice
|
||||
========================
|
||||
*/
|
||||
idSoundVoice* idSoundHardware_OpenAL::AllocateVoice( const idSoundSample* leadinSample, const idSoundSample* loopingSample )
|
||||
{
|
||||
if( leadinSample == NULL )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
if( loopingSample != NULL )
|
||||
{
|
||||
if( ( leadinSample->format.basic.formatTag != loopingSample->format.basic.formatTag ) || ( leadinSample->format.basic.numChannels != loopingSample->format.basic.numChannels ) )
|
||||
{
|
||||
idLib::Warning( "Leadin/looping format mismatch: %s & %s", leadinSample->GetName(), loopingSample->GetName() );
|
||||
loopingSample = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// Try to find a free voice that matches the format
|
||||
// But fallback to the last free voice if none match the format
|
||||
idSoundVoice* voice = NULL;
|
||||
for( int i = 0; i < freeVoices.Num(); i++ )
|
||||
{
|
||||
if( freeVoices[i]->IsPlaying() )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
voice = ( idSoundVoice* )freeVoices[i];
|
||||
if( voice->CompatibleFormat( ( idSoundSample_OpenAL* )leadinSample ) )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( voice != NULL )
|
||||
{
|
||||
voice->Create( leadinSample, loopingSample );
|
||||
freeVoices.Remove( voice );
|
||||
return voice;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
========================
|
||||
idSoundHardware_OpenAL::FreeVoice
|
||||
========================
|
||||
*/
|
||||
void idSoundHardware_OpenAL::FreeVoice( idSoundVoice* voice )
|
||||
{
|
||||
voice->Stop();
|
||||
|
||||
// Stop() is asyncronous, so we won't flush bufferes until the
|
||||
// voice on the zombie channel actually returns !IsPlaying()
|
||||
zombieVoices.Append( voice );
|
||||
}
|
||||
|
||||
/*
|
||||
========================
|
||||
idSoundHardware_OpenAL::Update
|
||||
========================
|
||||
*/
|
||||
void idSoundHardware_OpenAL::Update()
|
||||
{
|
||||
if( pXAudio2 == NULL )
|
||||
{
|
||||
int nowTime = Sys_Milliseconds();
|
||||
if( lastResetTime + 1000 < nowTime )
|
||||
{
|
||||
lastResetTime = nowTime;
|
||||
Init();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if( soundSystem->IsMuted() )
|
||||
{
|
||||
pMasterVoice->SetVolume( 0.0f, OPERATION_SET );
|
||||
}
|
||||
else
|
||||
{
|
||||
pMasterVoice->SetVolume( DBtoLinear( s_volume_dB.GetFloat() ), OPERATION_SET );
|
||||
}
|
||||
|
||||
pXAudio2->CommitChanges( XAUDIO2_COMMIT_ALL );
|
||||
|
||||
// IXAudio2SourceVoice::Stop() has been called for every sound on the
|
||||
// zombie list, but it is documented as asyncronous, so we have to wait
|
||||
// until it actually reports that it is no longer playing.
|
||||
for( int i = 0; i < zombieVoices.Num(); i++ )
|
||||
{
|
||||
zombieVoices[i]->FlushSourceBuffers();
|
||||
if( !zombieVoices[i]->IsPlaying() )
|
||||
{
|
||||
freeVoices.Append( zombieVoices[i] );
|
||||
zombieVoices.RemoveIndexFast( i );
|
||||
i--;
|
||||
}
|
||||
else
|
||||
{
|
||||
static int playingZombies;
|
||||
playingZombies++;
|
||||
}
|
||||
}
|
||||
|
||||
if( s_showPerfData.GetBool() )
|
||||
{
|
||||
XAUDIO2_PERFORMANCE_DATA perfData;
|
||||
pXAudio2->GetPerformanceData( &perfData );
|
||||
idLib::Printf( "Voices: %d/%d CPU: %.2f%% Mem: %dkb\n", perfData.ActiveSourceVoiceCount, perfData.TotalSourceVoiceCount, perfData.AudioCyclesSinceLastQuery / ( float )perfData.TotalCyclesSinceLastQuery, perfData.MemoryUsageInBytes / 1024 );
|
||||
}
|
||||
|
||||
if( vuMeterRMS == NULL )
|
||||
{
|
||||
// Init probably hasn't been called yet
|
||||
return;
|
||||
}
|
||||
|
||||
vuMeterRMS->Enable( s_showLevelMeter.GetBool() );
|
||||
vuMeterPeak->Enable( s_showLevelMeter.GetBool() );
|
||||
|
||||
if( !s_showLevelMeter.GetBool() )
|
||||
{
|
||||
pMasterVoice->DisableEffect( 0 );
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
pMasterVoice->EnableEffect( 0 );
|
||||
}
|
||||
|
||||
float peakLevels[ 8 ];
|
||||
float rmsLevels[ 8 ];
|
||||
|
||||
XAUDIO2FX_VOLUMEMETER_LEVELS levels;
|
||||
levels.ChannelCount = outputChannels;
|
||||
levels.pPeakLevels = peakLevels;
|
||||
levels.pRMSLevels = rmsLevels;
|
||||
|
||||
if( levels.ChannelCount > 8 )
|
||||
{
|
||||
levels.ChannelCount = 8;
|
||||
}
|
||||
|
||||
pMasterVoice->GetEffectParameters( 0, &levels, sizeof( levels ) );
|
||||
|
||||
int currentTime = Sys_Milliseconds();
|
||||
for( int i = 0; i < outputChannels; i++ )
|
||||
{
|
||||
if( vuMeterPeakTimes[i] < currentTime )
|
||||
{
|
||||
vuMeterPeak->SetValue( i, vuMeterPeak->GetValue( i ) * 0.9f, colorRed );
|
||||
}
|
||||
}
|
||||
|
||||
float width = 20.0f;
|
||||
float height = 200.0f;
|
||||
float left = 100.0f;
|
||||
float top = 100.0f;
|
||||
|
||||
sscanf( s_meterPosition.GetString(), "%f %f %f %f", &left, &top, &width, &height );
|
||||
|
||||
vuMeterRMS->SetPosition( left, top, width * levels.ChannelCount, height );
|
||||
vuMeterPeak->SetPosition( left, top, width * levels.ChannelCount, height );
|
||||
|
||||
for( uint32 i = 0; i < levels.ChannelCount; i++ )
|
||||
{
|
||||
vuMeterRMS->SetValue( i, rmsLevels[ i ], idVec4( 0.5f, 1.0f, 0.0f, 1.00f ) );
|
||||
if( peakLevels[ i ] >= vuMeterPeak->GetValue( i ) )
|
||||
{
|
||||
vuMeterPeak->SetValue( i, peakLevels[ i ], colorRed );
|
||||
vuMeterPeakTimes[i] = currentTime + s_meterTopTime.GetInteger();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
================================================
|
||||
idSoundEngineCallback
|
||||
================================================
|
||||
*/
|
||||
|
||||
/*
|
||||
========================
|
||||
idSoundEngineCallback::OnCriticalError
|
||||
========================
|
||||
*/
|
||||
void idSoundEngineCallback::OnCriticalError( HRESULT Error )
|
||||
{
|
||||
soundSystemLocal.SetNeedsRestart();
|
||||
}
|
127
neo/sound/OpenAL/AL_SoundHardware.h
Normal file
127
neo/sound/OpenAL/AL_SoundHardware.h
Normal file
|
@ -0,0 +1,127 @@
|
|||
/*
|
||||
===========================================================================
|
||||
|
||||
Doom 3 BFG Edition GPL Source Code
|
||||
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
|
||||
Copyright (C) 2012 Robert Beckebans
|
||||
|
||||
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
|
||||
|
||||
Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
|
||||
|
||||
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
|
||||
|
||||
===========================================================================
|
||||
*/
|
||||
#ifndef __AL_SOUNDHARDWARE_H__
|
||||
#define __AL_SOUNDHARDWARE_H__
|
||||
|
||||
class idSoundSample_OpenAL;
|
||||
class idSoundVoice_OpenAL;
|
||||
// RB
|
||||
class idSoundHardware_OpenAL;
|
||||
|
||||
/*
|
||||
================================================
|
||||
idSoundEngineCallback
|
||||
================================================
|
||||
*/
|
||||
class idSoundEngineCallback : public IXAudio2EngineCallback
|
||||
{
|
||||
public:
|
||||
idSoundHardware_OpenAL* hardware;
|
||||
|
||||
private:
|
||||
// Called by XAudio2 just before an audio processing pass begins.
|
||||
STDMETHOD_( void, OnProcessingPassStart )( THIS ) {}
|
||||
|
||||
// Called just after an audio processing pass ends.
|
||||
STDMETHOD_( void, OnProcessingPassEnd )( THIS ) {}
|
||||
|
||||
// Called in the event of a critical system error which requires XAudio2
|
||||
// to be closed down and restarted. The error code is given in Error.
|
||||
STDMETHOD_( void, OnCriticalError )( THIS_ HRESULT Error );
|
||||
};
|
||||
|
||||
/*
|
||||
================================================
|
||||
idSoundHardware_OpenAL
|
||||
================================================
|
||||
*/
|
||||
|
||||
class idSoundHardware_OpenAL
|
||||
{
|
||||
public:
|
||||
idSoundHardware_OpenAL();
|
||||
|
||||
void Init();
|
||||
void Shutdown();
|
||||
|
||||
void Update();
|
||||
|
||||
idSoundVoice* AllocateVoice( const idSoundSample* leadinSample, const idSoundSample* loopingSample );
|
||||
void FreeVoice( idSoundVoice* voice );
|
||||
|
||||
// video playback needs this
|
||||
IXAudio2* GetIXAudio2() const
|
||||
{
|
||||
return pXAudio2;
|
||||
};
|
||||
|
||||
int GetNumZombieVoices() const
|
||||
{
|
||||
return zombieVoices.Num();
|
||||
}
|
||||
int GetNumFreeVoices() const
|
||||
{
|
||||
return freeVoices.Num();
|
||||
}
|
||||
|
||||
protected:
|
||||
friend class idSoundSample_OpenAL;
|
||||
friend class idSoundVoice_OpenAL;
|
||||
|
||||
private:
|
||||
IXAudio2* pXAudio2;
|
||||
IXAudio2MasteringVoice* pMasterVoice;
|
||||
IXAudio2SubmixVoice* pSubmixVoice;
|
||||
|
||||
idSoundEngineCallback soundEngineCallback;
|
||||
int lastResetTime;
|
||||
|
||||
int outputChannels;
|
||||
int channelMask;
|
||||
|
||||
idDebugGraph* vuMeterRMS;
|
||||
idDebugGraph* vuMeterPeak;
|
||||
int vuMeterPeakTimes[ 8 ];
|
||||
|
||||
// Can't stop and start a voice on the same frame, so we have to double this to handle the worst case scenario of stopping all voices and starting a full new set
|
||||
idStaticList<idSoundVoice_OpenAL, MAX_HARDWARE_VOICES* 2 > voices;
|
||||
idStaticList<idSoundVoice_OpenAL*, MAX_HARDWARE_VOICES* 2 > zombieVoices;
|
||||
idStaticList<idSoundVoice_OpenAL*, MAX_HARDWARE_VOICES* 2 > freeVoices;
|
||||
};
|
||||
|
||||
/*
|
||||
================================================
|
||||
idSoundHardware
|
||||
================================================
|
||||
*/
|
||||
class idSoundHardware : public idSoundHardware_OpenAL
|
||||
{
|
||||
};
|
||||
|
||||
#endif
|
550
neo/sound/OpenAL/AL_SoundSample.cpp
Normal file
550
neo/sound/OpenAL/AL_SoundSample.cpp
Normal file
|
@ -0,0 +1,550 @@
|
|||
/*
|
||||
===========================================================================
|
||||
|
||||
Doom 3 BFG Edition GPL Source Code
|
||||
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
|
||||
|
||||
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
|
||||
|
||||
Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
|
||||
|
||||
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
|
||||
|
||||
===========================================================================
|
||||
*/
|
||||
#pragma hdrstop
|
||||
#include "precompiled.h"
|
||||
#include "../snd_local.h"
|
||||
|
||||
extern idCVar s_useCompression;
|
||||
extern idCVar s_noSound;
|
||||
|
||||
#define GPU_CONVERT_CPU_TO_CPU_CACHED_READONLY_ADDRESS( x ) x
|
||||
|
||||
const uint32 SOUND_MAGIC_IDMSA = 0x6D7A7274;
|
||||
|
||||
extern idCVar sys_lang;
|
||||
|
||||
/*
|
||||
========================
|
||||
AllocBuffer
|
||||
========================
|
||||
*/
|
||||
static void* AllocBuffer( int size, const char* name )
|
||||
{
|
||||
return Mem_Alloc( size, TAG_AUDIO );
|
||||
}
|
||||
|
||||
/*
|
||||
========================
|
||||
FreeBuffer
|
||||
========================
|
||||
*/
|
||||
static void FreeBuffer( void* p )
|
||||
{
|
||||
return Mem_Free( p );
|
||||
}
|
||||
|
||||
/*
|
||||
========================
|
||||
idSoundSample_OpenAL::idSoundSample_OpenAL
|
||||
========================
|
||||
*/
|
||||
idSoundSample_OpenAL::idSoundSample_OpenAL()
|
||||
{
|
||||
timestamp = FILE_NOT_FOUND_TIMESTAMP;
|
||||
loaded = false;
|
||||
neverPurge = false;
|
||||
levelLoadReferenced = false;
|
||||
|
||||
memset( &format, 0, sizeof( format ) );
|
||||
|
||||
totalBufferSize = 0;
|
||||
|
||||
playBegin = 0;
|
||||
playLength = 0;
|
||||
|
||||
lastPlayedTime = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
========================
|
||||
idSoundSample_OpenAL::~idSoundSample_OpenAL
|
||||
========================
|
||||
*/
|
||||
idSoundSample_OpenAL::~idSoundSample_OpenAL()
|
||||
{
|
||||
FreeData();
|
||||
}
|
||||
|
||||
/*
|
||||
========================
|
||||
idSoundSample_OpenAL::WriteGeneratedSample
|
||||
========================
|
||||
*/
|
||||
void idSoundSample_OpenAL::WriteGeneratedSample( idFile* fileOut )
|
||||
{
|
||||
fileOut->WriteBig( SOUND_MAGIC_IDMSA );
|
||||
fileOut->WriteBig( timestamp );
|
||||
fileOut->WriteBig( loaded );
|
||||
fileOut->WriteBig( playBegin );
|
||||
fileOut->WriteBig( playLength );
|
||||
idWaveFile::WriteWaveFormatDirect( format, fileOut );
|
||||
fileOut->WriteBig( ( int )amplitude.Num() );
|
||||
fileOut->Write( amplitude.Ptr(), amplitude.Num() );
|
||||
fileOut->WriteBig( totalBufferSize );
|
||||
fileOut->WriteBig( ( int )buffers.Num() );
|
||||
for( int i = 0; i < buffers.Num(); i++ )
|
||||
{
|
||||
fileOut->WriteBig( buffers[ i ].numSamples );
|
||||
fileOut->WriteBig( buffers[ i ].bufferSize );
|
||||
fileOut->Write( buffers[ i ].buffer, buffers[ i ].bufferSize );
|
||||
};
|
||||
}
|
||||
/*
|
||||
========================
|
||||
idSoundSample_OpenAL::WriteAllSamples
|
||||
========================
|
||||
*/
|
||||
void idSoundSample_OpenAL::WriteAllSamples( const idStr& sampleName )
|
||||
{
|
||||
idSoundSample_OpenAL* samplePC = new idSoundSample_OpenAL();
|
||||
{
|
||||
idStrStatic< MAX_OSPATH > inName = sampleName;
|
||||
inName.Append( ".msadpcm" );
|
||||
idStrStatic< MAX_OSPATH > inName2 = sampleName;
|
||||
inName2.Append( ".wav" );
|
||||
|
||||
idStrStatic< MAX_OSPATH > outName = "generated/";
|
||||
outName.Append( sampleName );
|
||||
outName.Append( ".idwav" );
|
||||
|
||||
if( samplePC->LoadWav( inName ) || samplePC->LoadWav( inName2 ) )
|
||||
{
|
||||
idFile* fileOut = fileSystem->OpenFileWrite( outName, "fs_basepath" );
|
||||
samplePC->WriteGeneratedSample( fileOut );
|
||||
delete fileOut;
|
||||
}
|
||||
}
|
||||
delete samplePC;
|
||||
}
|
||||
|
||||
/*
|
||||
========================
|
||||
idSoundSample_OpenAL::LoadGeneratedSound
|
||||
========================
|
||||
*/
|
||||
bool idSoundSample_OpenAL::LoadGeneratedSample( const idStr& filename )
|
||||
{
|
||||
idFileLocal fileIn( fileSystem->OpenFileReadMemory( filename ) );
|
||||
if( fileIn != NULL )
|
||||
{
|
||||
uint32 magic;
|
||||
fileIn->ReadBig( magic );
|
||||
fileIn->ReadBig( timestamp );
|
||||
fileIn->ReadBig( loaded );
|
||||
fileIn->ReadBig( playBegin );
|
||||
fileIn->ReadBig( playLength );
|
||||
idWaveFile::ReadWaveFormatDirect( format, fileIn );
|
||||
int num;
|
||||
fileIn->ReadBig( num );
|
||||
amplitude.Clear();
|
||||
amplitude.SetNum( num );
|
||||
fileIn->Read( amplitude.Ptr(), amplitude.Num() );
|
||||
fileIn->ReadBig( totalBufferSize );
|
||||
fileIn->ReadBig( num );
|
||||
buffers.SetNum( num );
|
||||
for( int i = 0; i < num; i++ )
|
||||
{
|
||||
fileIn->ReadBig( buffers[ i ].numSamples );
|
||||
fileIn->ReadBig( buffers[ i ].bufferSize );
|
||||
buffers[ i ].buffer = AllocBuffer( buffers[ i ].bufferSize, GetName() );
|
||||
fileIn->Read( buffers[ i ].buffer, buffers[ i ].bufferSize );
|
||||
buffers[ i ].buffer = GPU_CONVERT_CPU_TO_CPU_CACHED_READONLY_ADDRESS( buffers[ i ].buffer );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/*
|
||||
========================
|
||||
idSoundSample_OpenAL::Load
|
||||
========================
|
||||
*/
|
||||
void idSoundSample_OpenAL::LoadResource()
|
||||
{
|
||||
FreeData();
|
||||
|
||||
if( idStr::Icmpn( GetName(), "_default", 8 ) == 0 )
|
||||
{
|
||||
MakeDefault();
|
||||
return;
|
||||
}
|
||||
|
||||
if( s_noSound.GetBool() )
|
||||
{
|
||||
MakeDefault();
|
||||
return;
|
||||
}
|
||||
|
||||
loaded = false;
|
||||
|
||||
for( int i = 0; i < 2; i++ )
|
||||
{
|
||||
idStrStatic< MAX_OSPATH > sampleName = GetName();
|
||||
if( ( i == 0 ) && !sampleName.Replace( "/vo/", va( "/vo/%s/", sys_lang.GetString() ) ) )
|
||||
{
|
||||
i++;
|
||||
}
|
||||
idStrStatic< MAX_OSPATH > generatedName = "generated/";
|
||||
generatedName.Append( sampleName );
|
||||
|
||||
{
|
||||
if( s_useCompression.GetBool() )
|
||||
{
|
||||
sampleName.Append( ".msadpcm" );
|
||||
}
|
||||
else
|
||||
{
|
||||
sampleName.Append( ".wav" );
|
||||
}
|
||||
generatedName.Append( ".idwav" );
|
||||
}
|
||||
loaded = LoadGeneratedSample( generatedName ) || LoadWav( sampleName );
|
||||
|
||||
if( !loaded && s_useCompression.GetBool() )
|
||||
{
|
||||
sampleName.SetFileExtension( "wav" );
|
||||
loaded = LoadWav( sampleName );
|
||||
}
|
||||
|
||||
if( loaded )
|
||||
{
|
||||
if( cvarSystem->GetCVarBool( "fs_buildresources" ) )
|
||||
{
|
||||
fileSystem->AddSamplePreload( GetName() );
|
||||
WriteAllSamples( GetName() );
|
||||
|
||||
if( sampleName.Find( "/vo/" ) >= 0 )
|
||||
{
|
||||
for( int i = 0; i < Sys_NumLangs(); i++ )
|
||||
{
|
||||
const char* lang = Sys_Lang( i );
|
||||
if( idStr::Icmp( lang, ID_LANG_ENGLISH ) == 0 )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
idStrStatic< MAX_OSPATH > locName = GetName();
|
||||
locName.Replace( "/vo/", va( "/vo/%s/", Sys_Lang( i ) ) );
|
||||
WriteAllSamples( locName );
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if( !loaded )
|
||||
{
|
||||
// make it default if everything else fails
|
||||
MakeDefault();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
========================
|
||||
idSoundSample_OpenAL::LoadWav
|
||||
========================
|
||||
*/
|
||||
bool idSoundSample_OpenAL::LoadWav( const idStr& filename )
|
||||
{
|
||||
|
||||
// load the wave
|
||||
idWaveFile wave;
|
||||
if( !wave.Open( filename ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
idStrStatic< MAX_OSPATH > sampleName = filename;
|
||||
sampleName.SetFileExtension( "amp" );
|
||||
LoadAmplitude( sampleName );
|
||||
|
||||
const char* formatError = wave.ReadWaveFormat( format );
|
||||
if( formatError != NULL )
|
||||
{
|
||||
idLib::Warning( "LoadWav( %s ) : %s", filename.c_str(), formatError );
|
||||
MakeDefault();
|
||||
return false;
|
||||
}
|
||||
timestamp = wave.Timestamp();
|
||||
|
||||
totalBufferSize = wave.SeekToChunk( 'data' );
|
||||
|
||||
if( format.basic.formatTag == idWaveFile::FORMAT_PCM || format.basic.formatTag == idWaveFile::FORMAT_EXTENSIBLE )
|
||||
{
|
||||
|
||||
if( format.basic.bitsPerSample != 16 )
|
||||
{
|
||||
idLib::Warning( "LoadWav( %s ) : %s", filename.c_str(), "Not a 16 bit PCM wav file" );
|
||||
MakeDefault();
|
||||
return false;
|
||||
}
|
||||
|
||||
playBegin = 0;
|
||||
playLength = ( totalBufferSize ) / format.basic.blockSize;
|
||||
|
||||
buffers.SetNum( 1 );
|
||||
buffers[0].bufferSize = totalBufferSize;
|
||||
buffers[0].numSamples = playLength;
|
||||
buffers[0].buffer = AllocBuffer( totalBufferSize, GetName() );
|
||||
|
||||
|
||||
wave.Read( buffers[0].buffer, totalBufferSize );
|
||||
|
||||
if( format.basic.bitsPerSample == 16 )
|
||||
{
|
||||
idSwap::LittleArray( ( short* )buffers[0].buffer, totalBufferSize / sizeof( short ) );
|
||||
}
|
||||
|
||||
buffers[0].buffer = GPU_CONVERT_CPU_TO_CPU_CACHED_READONLY_ADDRESS( buffers[0].buffer );
|
||||
|
||||
}
|
||||
else if( format.basic.formatTag == idWaveFile::FORMAT_ADPCM )
|
||||
{
|
||||
|
||||
playBegin = 0;
|
||||
playLength = ( ( totalBufferSize / format.basic.blockSize ) * format.extra.adpcm.samplesPerBlock );
|
||||
|
||||
buffers.SetNum( 1 );
|
||||
buffers[0].bufferSize = totalBufferSize;
|
||||
buffers[0].numSamples = playLength;
|
||||
buffers[0].buffer = AllocBuffer( totalBufferSize, GetName() );
|
||||
|
||||
wave.Read( buffers[0].buffer, totalBufferSize );
|
||||
|
||||
buffers[0].buffer = GPU_CONVERT_CPU_TO_CPU_CACHED_READONLY_ADDRESS( buffers[0].buffer );
|
||||
|
||||
}
|
||||
else if( format.basic.formatTag == idWaveFile::FORMAT_XMA2 )
|
||||
{
|
||||
|
||||
if( format.extra.xma2.blockCount == 0 )
|
||||
{
|
||||
idLib::Warning( "LoadWav( %s ) : %s", filename.c_str(), "No data blocks in file" );
|
||||
MakeDefault();
|
||||
return false;
|
||||
}
|
||||
|
||||
int bytesPerBlock = format.extra.xma2.bytesPerBlock;
|
||||
assert( format.extra.xma2.blockCount == ALIGN( totalBufferSize, bytesPerBlock ) / bytesPerBlock );
|
||||
assert( format.extra.xma2.blockCount * bytesPerBlock >= totalBufferSize );
|
||||
assert( format.extra.xma2.blockCount * bytesPerBlock < totalBufferSize + bytesPerBlock );
|
||||
|
||||
buffers.SetNum( format.extra.xma2.blockCount );
|
||||
for( int i = 0; i < buffers.Num(); i++ )
|
||||
{
|
||||
if( i == buffers.Num() - 1 )
|
||||
{
|
||||
buffers[i].bufferSize = totalBufferSize - ( i * bytesPerBlock );
|
||||
}
|
||||
else
|
||||
{
|
||||
buffers[i].bufferSize = bytesPerBlock;
|
||||
}
|
||||
|
||||
buffers[i].buffer = AllocBuffer( buffers[i].bufferSize, GetName() );
|
||||
wave.Read( buffers[i].buffer, buffers[i].bufferSize );
|
||||
buffers[i].buffer = GPU_CONVERT_CPU_TO_CPU_CACHED_READONLY_ADDRESS( buffers[i].buffer );
|
||||
}
|
||||
|
||||
int seekTableSize = wave.SeekToChunk( 'seek' );
|
||||
if( seekTableSize != 4 * buffers.Num() )
|
||||
{
|
||||
idLib::Warning( "LoadWav( %s ) : %s", filename.c_str(), "Wrong number of entries in seek table" );
|
||||
MakeDefault();
|
||||
return false;
|
||||
}
|
||||
|
||||
for( int i = 0; i < buffers.Num(); i++ )
|
||||
{
|
||||
wave.Read( &buffers[i].numSamples, sizeof( buffers[i].numSamples ) );
|
||||
idSwap::Big( buffers[i].numSamples );
|
||||
}
|
||||
|
||||
playBegin = format.extra.xma2.loopBegin;
|
||||
playLength = format.extra.xma2.loopLength;
|
||||
|
||||
if( buffers[buffers.Num() - 1].numSamples < playBegin + playLength )
|
||||
{
|
||||
// This shouldn't happen, but it's not fatal if it does
|
||||
playLength = buffers[buffers.Num() - 1].numSamples - playBegin;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Discard samples beyond playLength
|
||||
for( int i = 0; i < buffers.Num(); i++ )
|
||||
{
|
||||
if( buffers[i].numSamples > playBegin + playLength )
|
||||
{
|
||||
buffers[i].numSamples = playBegin + playLength;
|
||||
// Ideally, the following loop should always have 0 iterations because playBegin + playLength ends in the last block already
|
||||
// But there is no guarantee for that, so to be safe, discard all buffers beyond this one
|
||||
for( int j = i + 1; j < buffers.Num(); j++ )
|
||||
{
|
||||
FreeBuffer( buffers[j].buffer );
|
||||
}
|
||||
buffers.SetNum( i + 1 );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
idLib::Warning( "LoadWav( %s ) : Unsupported wave format %d", filename.c_str(), format.basic.formatTag );
|
||||
MakeDefault();
|
||||
return false;
|
||||
}
|
||||
|
||||
wave.Close();
|
||||
|
||||
if( format.basic.formatTag == idWaveFile::FORMAT_EXTENSIBLE )
|
||||
{
|
||||
// HACK: XAudio2 doesn't really support FORMAT_EXTENSIBLE so we convert it to a basic format after extracting the channel mask
|
||||
format.basic.formatTag = format.extra.extensible.subFormat.data1;
|
||||
}
|
||||
|
||||
// sanity check...
|
||||
assert( buffers[buffers.Num() - 1].numSamples == playBegin + playLength );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
========================
|
||||
idSoundSample_OpenAL::MakeDefault
|
||||
========================
|
||||
*/
|
||||
void idSoundSample_OpenAL::MakeDefault()
|
||||
{
|
||||
FreeData();
|
||||
|
||||
static const int DEFAULT_NUM_SAMPLES = 256;
|
||||
|
||||
timestamp = FILE_NOT_FOUND_TIMESTAMP;
|
||||
loaded = true;
|
||||
|
||||
memset( &format, 0, sizeof( format ) );
|
||||
format.basic.formatTag = idWaveFile::FORMAT_PCM;
|
||||
format.basic.numChannels = 1;
|
||||
format.basic.bitsPerSample = 16;
|
||||
format.basic.samplesPerSec = XAUDIO2_MIN_SAMPLE_RATE;
|
||||
format.basic.blockSize = format.basic.numChannels * format.basic.bitsPerSample / 8;
|
||||
format.basic.avgBytesPerSec = format.basic.samplesPerSec * format.basic.blockSize;
|
||||
|
||||
assert( format.basic.blockSize == 2 );
|
||||
|
||||
totalBufferSize = DEFAULT_NUM_SAMPLES * 2;
|
||||
|
||||
short* defaultBuffer = ( short* )AllocBuffer( totalBufferSize, GetName() );
|
||||
for( int i = 0; i < DEFAULT_NUM_SAMPLES; i += 2 )
|
||||
{
|
||||
defaultBuffer[i + 0] = SHRT_MIN;
|
||||
defaultBuffer[i + 1] = SHRT_MAX;
|
||||
}
|
||||
|
||||
buffers.SetNum( 1 );
|
||||
buffers[0].buffer = defaultBuffer;
|
||||
buffers[0].bufferSize = totalBufferSize;
|
||||
buffers[0].numSamples = DEFAULT_NUM_SAMPLES;
|
||||
buffers[0].buffer = GPU_CONVERT_CPU_TO_CPU_CACHED_READONLY_ADDRESS( buffers[0].buffer );
|
||||
|
||||
playBegin = 0;
|
||||
playLength = DEFAULT_NUM_SAMPLES;
|
||||
}
|
||||
|
||||
/*
|
||||
========================
|
||||
idSoundSample_OpenAL::FreeData
|
||||
|
||||
Called before deleting the object and at the start of LoadResource()
|
||||
========================
|
||||
*/
|
||||
void idSoundSample_OpenAL::FreeData()
|
||||
{
|
||||
if( buffers.Num() > 0 )
|
||||
{
|
||||
soundSystemLocal.StopVoicesWithSample( ( idSoundSample* )this );
|
||||
for( int i = 0; i < buffers.Num(); i++ )
|
||||
{
|
||||
FreeBuffer( buffers[i].buffer );
|
||||
}
|
||||
buffers.Clear();
|
||||
}
|
||||
amplitude.Clear();
|
||||
|
||||
timestamp = FILE_NOT_FOUND_TIMESTAMP;
|
||||
memset( &format, 0, sizeof( format ) );
|
||||
loaded = false;
|
||||
totalBufferSize = 0;
|
||||
playBegin = 0;
|
||||
playLength = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
========================
|
||||
idSoundSample_OpenAL::LoadAmplitude
|
||||
========================
|
||||
*/
|
||||
bool idSoundSample_OpenAL::LoadAmplitude( const idStr& name )
|
||||
{
|
||||
amplitude.Clear();
|
||||
idFileLocal f( fileSystem->OpenFileRead( name ) );
|
||||
if( f == NULL )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
amplitude.SetNum( f->Length() );
|
||||
f->Read( amplitude.Ptr(), amplitude.Num() );
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
========================
|
||||
idSoundSample_OpenAL::GetAmplitude
|
||||
========================
|
||||
*/
|
||||
float idSoundSample_OpenAL::GetAmplitude( int timeMS ) const
|
||||
{
|
||||
if( timeMS < 0 || timeMS > LengthInMsec() )
|
||||
{
|
||||
return 0.0f;
|
||||
}
|
||||
if( IsDefault() )
|
||||
{
|
||||
return 1.0f;
|
||||
}
|
||||
int index = timeMS * 60 / 1000;
|
||||
if( index < 0 || index >= amplitude.Num() )
|
||||
{
|
||||
return 0.0f;
|
||||
}
|
||||
return ( float )amplitude[index] / 255.0f;
|
||||
}
|
186
neo/sound/OpenAL/AL_SoundSample.h
Normal file
186
neo/sound/OpenAL/AL_SoundSample.h
Normal file
|
@ -0,0 +1,186 @@
|
|||
/*
|
||||
===========================================================================
|
||||
|
||||
Doom 3 BFG Edition GPL Source Code
|
||||
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
|
||||
|
||||
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
|
||||
|
||||
Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
|
||||
|
||||
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
|
||||
|
||||
===========================================================================
|
||||
*/
|
||||
#ifndef __AL_SOUNDSAMPLE_H__
|
||||
#define __AL_SOUNDSAMPLE_H__
|
||||
|
||||
/*
|
||||
================================================
|
||||
idSoundSample_OpenAL
|
||||
================================================
|
||||
*/
|
||||
class idSampleInfo;
|
||||
class idSoundSample_OpenAL
|
||||
{
|
||||
public:
|
||||
idSoundSample_OpenAL();
|
||||
|
||||
// Loads and initializes the resource based on the name.
|
||||
virtual void LoadResource();
|
||||
|
||||
void SetName( const char* n )
|
||||
{
|
||||
name = n;
|
||||
}
|
||||
const char* GetName() const
|
||||
{
|
||||
return name;
|
||||
}
|
||||
ID_TIME_T GetTimestamp() const
|
||||
{
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
// turns it into a beep
|
||||
void MakeDefault();
|
||||
|
||||
// frees all data
|
||||
void FreeData();
|
||||
|
||||
int LengthInMsec() const
|
||||
{
|
||||
return SamplesToMsec( NumSamples(), SampleRate() );
|
||||
}
|
||||
int SampleRate() const
|
||||
{
|
||||
return format.basic.samplesPerSec;
|
||||
}
|
||||
int NumSamples() const
|
||||
{
|
||||
return playLength;
|
||||
}
|
||||
int NumChannels() const
|
||||
{
|
||||
return format.basic.numChannels;
|
||||
}
|
||||
int BufferSize() const
|
||||
{
|
||||
return totalBufferSize;
|
||||
}
|
||||
|
||||
bool IsCompressed() const
|
||||
{
|
||||
return ( format.basic.formatTag != idWaveFile::FORMAT_PCM );
|
||||
}
|
||||
|
||||
bool IsDefault() const
|
||||
{
|
||||
return timestamp == FILE_NOT_FOUND_TIMESTAMP;
|
||||
}
|
||||
bool IsLoaded() const
|
||||
{
|
||||
return loaded;
|
||||
}
|
||||
|
||||
void SetNeverPurge()
|
||||
{
|
||||
neverPurge = true;
|
||||
}
|
||||
bool GetNeverPurge() const
|
||||
{
|
||||
return neverPurge;
|
||||
}
|
||||
|
||||
void SetLevelLoadReferenced()
|
||||
{
|
||||
levelLoadReferenced = true;
|
||||
}
|
||||
void ResetLevelLoadReferenced()
|
||||
{
|
||||
levelLoadReferenced = false;
|
||||
}
|
||||
bool GetLevelLoadReferenced() const
|
||||
{
|
||||
return levelLoadReferenced;
|
||||
}
|
||||
|
||||
int GetLastPlayedTime() const
|
||||
{
|
||||
return lastPlayedTime;
|
||||
}
|
||||
void SetLastPlayedTime( int t )
|
||||
{
|
||||
lastPlayedTime = t;
|
||||
}
|
||||
|
||||
float GetAmplitude( int timeMS ) const;
|
||||
|
||||
protected:
|
||||
friend class idSoundHardware_OpenAL;
|
||||
friend class idSoundVoice_OpenAL;
|
||||
|
||||
~idSoundSample_OpenAL();
|
||||
|
||||
bool LoadWav( const idStr& name );
|
||||
bool LoadAmplitude( const idStr& name );
|
||||
void WriteAllSamples( const idStr& sampleName );
|
||||
bool LoadGeneratedSample( const idStr& name );
|
||||
void WriteGeneratedSample( idFile* fileOut );
|
||||
|
||||
struct sampleBuffer_t
|
||||
{
|
||||
void* buffer;
|
||||
int bufferSize;
|
||||
int numSamples;
|
||||
};
|
||||
|
||||
idStr name;
|
||||
|
||||
ID_TIME_T timestamp;
|
||||
bool loaded;
|
||||
|
||||
bool neverPurge;
|
||||
bool levelLoadReferenced;
|
||||
bool usesMapHeap;
|
||||
|
||||
uint32 lastPlayedTime;
|
||||
|
||||
int totalBufferSize; // total size of all the buffers
|
||||
idList<sampleBuffer_t, TAG_AUDIO> buffers;
|
||||
|
||||
int playBegin;
|
||||
int playLength;
|
||||
|
||||
idWaveFile::waveFmt_t format;
|
||||
|
||||
idList<byte, TAG_AMPLITUDE> amplitude;
|
||||
};
|
||||
|
||||
/*
|
||||
================================================
|
||||
idSoundSample
|
||||
|
||||
This reverse-inheritance purportedly makes working on
|
||||
multiple platforms easier.
|
||||
================================================
|
||||
*/
|
||||
class idSoundSample : public idSoundSample_OpenAL
|
||||
{
|
||||
public:
|
||||
};
|
||||
|
||||
#endif
|
574
neo/sound/OpenAL/AL_SoundVoice.cpp
Normal file
574
neo/sound/OpenAL/AL_SoundVoice.cpp
Normal file
|
@ -0,0 +1,574 @@
|
|||
/*
|
||||
===========================================================================
|
||||
|
||||
Doom 3 BFG Edition GPL Source Code
|
||||
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
|
||||
|
||||
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
|
||||
|
||||
Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
|
||||
|
||||
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
|
||||
|
||||
===========================================================================
|
||||
*/
|
||||
#pragma hdrstop
|
||||
#include "precompiled.h"
|
||||
#include "../snd_local.h"
|
||||
|
||||
idCVar s_skipHardwareSets( "s_skipHardwareSets", "0", CVAR_BOOL, "Do all calculation, but skip XA2 calls" );
|
||||
idCVar s_debugHardware( "s_debugHardware", "0", CVAR_BOOL, "Print a message any time a hardware voice changes" );
|
||||
|
||||
// The whole system runs at this sample rate
|
||||
static int SYSTEM_SAMPLE_RATE = 44100;
|
||||
static float ONE_OVER_SYSTEM_SAMPLE_RATE = 1.0f / SYSTEM_SAMPLE_RATE;
|
||||
|
||||
/*
|
||||
========================
|
||||
idStreamingVoiceContext
|
||||
========================
|
||||
*/
|
||||
class idStreamingVoiceContext : public IXAudio2VoiceCallback
|
||||
{
|
||||
public:
|
||||
STDMETHOD_( void, OnVoiceProcessingPassStart )( UINT32 BytesRequired ) {}
|
||||
STDMETHOD_( void, OnVoiceProcessingPassEnd )() {}
|
||||
STDMETHOD_( void, OnStreamEnd )() {}
|
||||
STDMETHOD_( void, OnBufferStart )( void* pContext )
|
||||
{
|
||||
idSoundSystemLocal::bufferContext_t* bufferContext = ( idSoundSystemLocal::bufferContext_t* ) pContext;
|
||||
bufferContext->voice->OnBufferStart( bufferContext->sample, bufferContext->bufferNumber );
|
||||
}
|
||||
STDMETHOD_( void, OnLoopEnd )( void* ) {}
|
||||
STDMETHOD_( void, OnVoiceError )( void*, HRESULT hr )
|
||||
{
|
||||
idLib::Warning( "OnVoiceError( %d )", hr );
|
||||
}
|
||||
STDMETHOD_( void, OnBufferEnd )( void* pContext )
|
||||
{
|
||||
idSoundSystemLocal::bufferContext_t* bufferContext = ( idSoundSystemLocal::bufferContext_t* ) pContext;
|
||||
soundSystemLocal.ReleaseStreamBufferContext( bufferContext );
|
||||
}
|
||||
} streamContext;
|
||||
|
||||
/*
|
||||
========================
|
||||
idSoundVoice_OpenAL::idSoundVoice_OpenAL
|
||||
========================
|
||||
*/
|
||||
idSoundVoice_OpenAL::idSoundVoice_OpenAL()
|
||||
: pSourceVoice( NULL ),
|
||||
leadinSample( NULL ),
|
||||
loopingSample( NULL ),
|
||||
formatTag( 0 ),
|
||||
numChannels( 0 ),
|
||||
sampleRate( 0 ),
|
||||
paused( true ),
|
||||
hasVUMeter( false )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
========================
|
||||
idSoundVoice_OpenAL::~idSoundVoice_OpenAL
|
||||
========================
|
||||
*/
|
||||
idSoundVoice_OpenAL::~idSoundVoice_OpenAL()
|
||||
{
|
||||
DestroyInternal();
|
||||
}
|
||||
|
||||
/*
|
||||
========================
|
||||
idSoundVoice_OpenAL::CompatibleFormat
|
||||
========================
|
||||
*/
|
||||
bool idSoundVoice_OpenAL::CompatibleFormat( idSoundSample_OpenAL* s )
|
||||
{
|
||||
if( pSourceVoice == NULL )
|
||||
{
|
||||
// If this voice has never been allocated, then it's compatible with everything
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
========================
|
||||
idSoundVoice_OpenAL::Create
|
||||
========================
|
||||
*/
|
||||
void idSoundVoice_OpenAL::Create( const idSoundSample* leadinSample_, const idSoundSample* loopingSample_ )
|
||||
{
|
||||
if( IsPlaying() )
|
||||
{
|
||||
// This should never hit
|
||||
Stop();
|
||||
return;
|
||||
}
|
||||
leadinSample = ( idSoundSample_OpenAL* )leadinSample_;
|
||||
loopingSample = ( idSoundSample_OpenAL* )loopingSample_;
|
||||
|
||||
if( pSourceVoice != NULL && CompatibleFormat( leadinSample ) )
|
||||
{
|
||||
sampleRate = leadinSample->format.basic.samplesPerSec;
|
||||
}
|
||||
else
|
||||
{
|
||||
DestroyInternal();
|
||||
formatTag = leadinSample->format.basic.formatTag;
|
||||
numChannels = leadinSample->format.basic.numChannels;
|
||||
sampleRate = leadinSample->format.basic.samplesPerSec;
|
||||
|
||||
soundSystemLocal.hardware.pXAudio2->CreateSourceVoice( &pSourceVoice, ( const WAVEFORMATEX* )&leadinSample->format, XAUDIO2_VOICE_USEFILTER, 4.0f, &streamContext );
|
||||
if( pSourceVoice == NULL )
|
||||
{
|
||||
// If this hits, then we are most likely passing an invalid sample format, which should have been caught by the loader (and the sample defaulted)
|
||||
return;
|
||||
}
|
||||
if( s_debugHardware.GetBool() )
|
||||
{
|
||||
if( loopingSample == NULL || loopingSample == leadinSample )
|
||||
{
|
||||
idLib::Printf( "%dms: %p created for %s\n", Sys_Milliseconds(), pSourceVoice, leadinSample ? leadinSample->GetName() : "<null>" );
|
||||
}
|
||||
else
|
||||
{
|
||||
idLib::Printf( "%dms: %p created for %s and %s\n", Sys_Milliseconds(), pSourceVoice, leadinSample ? leadinSample->GetName() : "<null>", loopingSample ? loopingSample->GetName() : "<null>" );
|
||||
}
|
||||
}
|
||||
}
|
||||
sourceVoiceRate = sampleRate;
|
||||
pSourceVoice->SetSourceSampleRate( sampleRate );
|
||||
pSourceVoice->SetVolume( 0.0f );
|
||||
}
|
||||
|
||||
/*
|
||||
========================
|
||||
idSoundVoice_OpenAL::DestroyInternal
|
||||
========================
|
||||
*/
|
||||
void idSoundVoice_OpenAL::DestroyInternal()
|
||||
{
|
||||
if( pSourceVoice != NULL )
|
||||
{
|
||||
if( s_debugHardware.GetBool() )
|
||||
{
|
||||
idLib::Printf( "%dms: %p destroyed\n", Sys_Milliseconds(), pSourceVoice );
|
||||
}
|
||||
pSourceVoice->DestroyVoice();
|
||||
pSourceVoice = NULL;
|
||||
hasVUMeter = false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
========================
|
||||
idSoundVoice_OpenAL::Start
|
||||
========================
|
||||
*/
|
||||
void idSoundVoice_OpenAL::Start( int offsetMS, int ssFlags )
|
||||
{
|
||||
|
||||
if( s_debugHardware.GetBool() )
|
||||
{
|
||||
idLib::Printf( "%dms: %p starting %s @ %dms\n", Sys_Milliseconds(), pSourceVoice, leadinSample ? leadinSample->GetName() : "<null>", offsetMS );
|
||||
}
|
||||
|
||||
if( !leadinSample )
|
||||
{
|
||||
return;
|
||||
}
|
||||
if( !pSourceVoice )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if( leadinSample->IsDefault() )
|
||||
{
|
||||
idLib::Warning( "Starting defaulted sound sample %s", leadinSample->GetName() );
|
||||
}
|
||||
|
||||
bool flicker = ( ssFlags & SSF_NO_FLICKER ) == 0;
|
||||
|
||||
if( flicker != hasVUMeter )
|
||||
{
|
||||
hasVUMeter = flicker;
|
||||
|
||||
if( flicker )
|
||||
{
|
||||
IUnknown* vuMeter = NULL;
|
||||
if( XAudio2CreateVolumeMeter( &vuMeter, 0 ) == S_OK )
|
||||
{
|
||||
|
||||
XAUDIO2_EFFECT_DESCRIPTOR descriptor;
|
||||
descriptor.InitialState = true;
|
||||
descriptor.OutputChannels = leadinSample->NumChannels();
|
||||
descriptor.pEffect = vuMeter;
|
||||
|
||||
XAUDIO2_EFFECT_CHAIN chain;
|
||||
chain.EffectCount = 1;
|
||||
chain.pEffectDescriptors = &descriptor;
|
||||
|
||||
pSourceVoice->SetEffectChain( &chain );
|
||||
|
||||
vuMeter->Release();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pSourceVoice->SetEffectChain( NULL );
|
||||
}
|
||||
}
|
||||
|
||||
assert( offsetMS >= 0 );
|
||||
int offsetSamples = MsecToSamples( offsetMS, leadinSample->SampleRate() );
|
||||
if( loopingSample == NULL && offsetSamples >= leadinSample->playLength )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
RestartAt( offsetSamples );
|
||||
Update();
|
||||
UnPause();
|
||||
}
|
||||
|
||||
/*
|
||||
========================
|
||||
idSoundVoice_OpenAL::RestartAt
|
||||
========================
|
||||
*/
|
||||
int idSoundVoice_OpenAL::RestartAt( int offsetSamples )
|
||||
{
|
||||
offsetSamples &= ~127;
|
||||
|
||||
idSoundSample_OpenAL* sample = leadinSample;
|
||||
if( offsetSamples >= leadinSample->playLength )
|
||||
{
|
||||
if( loopingSample != NULL )
|
||||
{
|
||||
offsetSamples %= loopingSample->playLength;
|
||||
sample = loopingSample;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int previousNumSamples = 0;
|
||||
for( int i = 0; i < sample->buffers.Num(); i++ )
|
||||
{
|
||||
if( sample->buffers[i].numSamples > sample->playBegin + offsetSamples )
|
||||
{
|
||||
return SubmitBuffer( sample, i, sample->playBegin + offsetSamples - previousNumSamples );
|
||||
}
|
||||
previousNumSamples = sample->buffers[i].numSamples;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
========================
|
||||
idSoundVoice_OpenAL::SubmitBuffer
|
||||
========================
|
||||
*/
|
||||
int idSoundVoice_OpenAL::SubmitBuffer( idSoundSample_OpenAL* sample, int bufferNumber, int offset )
|
||||
{
|
||||
|
||||
if( sample == NULL || ( bufferNumber < 0 ) || ( bufferNumber >= sample->buffers.Num() ) )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
idSoundSystemLocal::bufferContext_t* bufferContext = soundSystemLocal.ObtainStreamBufferContext();
|
||||
if( bufferContext == NULL )
|
||||
{
|
||||
idLib::Warning( "No free buffer contexts!" );
|
||||
return 0;
|
||||
}
|
||||
|
||||
bufferContext->voice = this;
|
||||
bufferContext->sample = sample;
|
||||
bufferContext->bufferNumber = bufferNumber;
|
||||
|
||||
XAUDIO2_BUFFER buffer = { 0 };
|
||||
if( offset > 0 )
|
||||
{
|
||||
int previousNumSamples = 0;
|
||||
if( bufferNumber > 0 )
|
||||
{
|
||||
previousNumSamples = sample->buffers[bufferNumber - 1].numSamples;
|
||||
}
|
||||
buffer.PlayBegin = offset;
|
||||
buffer.PlayLength = sample->buffers[bufferNumber].numSamples - previousNumSamples - offset;
|
||||
}
|
||||
buffer.AudioBytes = sample->buffers[bufferNumber].bufferSize;
|
||||
buffer.pAudioData = ( BYTE* )sample->buffers[bufferNumber].buffer;
|
||||
buffer.pContext = bufferContext;
|
||||
if( ( loopingSample == NULL ) && ( bufferNumber == sample->buffers.Num() - 1 ) )
|
||||
{
|
||||
buffer.Flags = XAUDIO2_END_OF_STREAM;
|
||||
}
|
||||
pSourceVoice->SubmitSourceBuffer( &buffer );
|
||||
|
||||
return buffer.AudioBytes;
|
||||
}
|
||||
|
||||
/*
|
||||
========================
|
||||
idSoundVoice_OpenAL::Update
|
||||
========================
|
||||
*/
|
||||
bool idSoundVoice_OpenAL::Update()
|
||||
{
|
||||
if( pSourceVoice == NULL || leadinSample == NULL )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
XAUDIO2_VOICE_STATE state;
|
||||
pSourceVoice->GetState( &state );
|
||||
|
||||
const int srcChannels = leadinSample->NumChannels();
|
||||
|
||||
float pLevelMatrix[ MAX_CHANNELS_PER_VOICE * MAX_CHANNELS_PER_VOICE ] = { 0 };
|
||||
CalculateSurround( srcChannels, pLevelMatrix, 1.0f );
|
||||
|
||||
if( s_skipHardwareSets.GetBool() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
pSourceVoice->SetOutputMatrix( soundSystemLocal.hardware.pMasterVoice, srcChannels, dstChannels, pLevelMatrix, OPERATION_SET );
|
||||
|
||||
assert( idMath::Fabs( gain ) <= XAUDIO2_MAX_VOLUME_LEVEL );
|
||||
pSourceVoice->SetVolume( gain, OPERATION_SET );
|
||||
|
||||
SetSampleRate( sampleRate, OPERATION_SET );
|
||||
|
||||
// we don't do this any longer because we pause and unpause explicitly when the soundworld is paused or unpaused
|
||||
// UnPause();
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
========================
|
||||
idSoundVoice_OpenAL::IsPlaying
|
||||
========================
|
||||
*/
|
||||
bool idSoundVoice_OpenAL::IsPlaying()
|
||||
{
|
||||
if( pSourceVoice == NULL )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
XAUDIO2_VOICE_STATE state;
|
||||
pSourceVoice->GetState( &state );
|
||||
return ( state.BuffersQueued != 0 );
|
||||
}
|
||||
|
||||
/*
|
||||
========================
|
||||
idSoundVoice_OpenAL::FlushSourceBuffers
|
||||
========================
|
||||
*/
|
||||
void idSoundVoice_OpenAL::FlushSourceBuffers()
|
||||
{
|
||||
if( pSourceVoice != NULL )
|
||||
{
|
||||
pSourceVoice->FlushSourceBuffers();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
========================
|
||||
idSoundVoice_OpenAL::Pause
|
||||
========================
|
||||
*/
|
||||
void idSoundVoice_OpenAL::Pause()
|
||||
{
|
||||
if( !pSourceVoice || paused )
|
||||
{
|
||||
return;
|
||||
}
|
||||
if( s_debugHardware.GetBool() )
|
||||
{
|
||||
idLib::Printf( "%dms: %p pausing %s\n", Sys_Milliseconds(), pSourceVoice, leadinSample ? leadinSample->GetName() : "<null>" );
|
||||
}
|
||||
pSourceVoice->Stop( 0, OPERATION_SET );
|
||||
paused = true;
|
||||
}
|
||||
|
||||
/*
|
||||
========================
|
||||
idSoundVoice_OpenAL::UnPause
|
||||
========================
|
||||
*/
|
||||
void idSoundVoice_OpenAL::UnPause()
|
||||
{
|
||||
if( !pSourceVoice || !paused )
|
||||
{
|
||||
return;
|
||||
}
|
||||
if( s_debugHardware.GetBool() )
|
||||
{
|
||||
idLib::Printf( "%dms: %p unpausing %s\n", Sys_Milliseconds(), pSourceVoice, leadinSample ? leadinSample->GetName() : "<null>" );
|
||||
}
|
||||
pSourceVoice->Start( 0, OPERATION_SET );
|
||||
paused = false;
|
||||
}
|
||||
|
||||
/*
|
||||
========================
|
||||
idSoundVoice_OpenAL::Stop
|
||||
========================
|
||||
*/
|
||||
void idSoundVoice_OpenAL::Stop()
|
||||
{
|
||||
if( !pSourceVoice )
|
||||
{
|
||||
return;
|
||||
}
|
||||
if( !paused )
|
||||
{
|
||||
if( s_debugHardware.GetBool() )
|
||||
{
|
||||
idLib::Printf( "%dms: %p stopping %s\n", Sys_Milliseconds(), pSourceVoice, leadinSample ? leadinSample->GetName() : "<null>" );
|
||||
}
|
||||
pSourceVoice->Stop( 0, OPERATION_SET );
|
||||
paused = true;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
========================
|
||||
idSoundVoice_OpenAL::GetAmplitude
|
||||
========================
|
||||
*/
|
||||
float idSoundVoice_OpenAL::GetAmplitude()
|
||||
{
|
||||
if( !hasVUMeter )
|
||||
{
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
float peakLevels[ MAX_CHANNELS_PER_VOICE ];
|
||||
float rmsLevels[ MAX_CHANNELS_PER_VOICE ];
|
||||
|
||||
XAUDIO2FX_VOLUMEMETER_LEVELS levels;
|
||||
levels.ChannelCount = leadinSample->NumChannels();
|
||||
levels.pPeakLevels = peakLevels;
|
||||
levels.pRMSLevels = rmsLevels;
|
||||
|
||||
if( levels.ChannelCount > MAX_CHANNELS_PER_VOICE )
|
||||
{
|
||||
levels.ChannelCount = MAX_CHANNELS_PER_VOICE;
|
||||
}
|
||||
|
||||
if( pSourceVoice->GetEffectParameters( 0, &levels, sizeof( levels ) ) != S_OK )
|
||||
{
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
if( levels.ChannelCount == 1 )
|
||||
{
|
||||
return rmsLevels[0];
|
||||
}
|
||||
|
||||
float rms = 0.0f;
|
||||
for( uint32 i = 0; i < levels.ChannelCount; i++ )
|
||||
{
|
||||
rms += rmsLevels[i];
|
||||
}
|
||||
|
||||
return rms / ( float )levels.ChannelCount;
|
||||
}
|
||||
|
||||
/*
|
||||
========================
|
||||
idSoundVoice_OpenAL::ResetSampleRate
|
||||
========================
|
||||
*/
|
||||
void idSoundVoice_OpenAL::SetSampleRate( uint32 newSampleRate, uint32 operationSet )
|
||||
{
|
||||
if( pSourceVoice == NULL || leadinSample == NULL )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
sampleRate = newSampleRate;
|
||||
|
||||
XAUDIO2_FILTER_PARAMETERS filter;
|
||||
filter.Type = LowPassFilter;
|
||||
filter.OneOverQ = 1.0f; // [0.0f, XAUDIO2_MAX_FILTER_ONEOVERQ]
|
||||
float cutoffFrequency = 1000.0f / Max( 0.01f, occlusion );
|
||||
if( cutoffFrequency * 6.0f >= ( float )sampleRate )
|
||||
{
|
||||
filter.Frequency = XAUDIO2_MAX_FILTER_FREQUENCY;
|
||||
}
|
||||
else
|
||||
{
|
||||
filter.Frequency = 2.0f * idMath::Sin( idMath::PI * cutoffFrequency / ( float )sampleRate );
|
||||
}
|
||||
assert( filter.Frequency >= 0.0f && filter.Frequency <= XAUDIO2_MAX_FILTER_FREQUENCY );
|
||||
filter.Frequency = idMath::ClampFloat( 0.0f, XAUDIO2_MAX_FILTER_FREQUENCY, filter.Frequency );
|
||||
|
||||
pSourceVoice->SetFilterParameters( &filter, operationSet );
|
||||
|
||||
float freqRatio = pitch * ( float )sampleRate / ( float )sourceVoiceRate;
|
||||
assert( freqRatio >= XAUDIO2_MIN_FREQ_RATIO && freqRatio <= XAUDIO2_MAX_FREQ_RATIO );
|
||||
freqRatio = idMath::ClampFloat( XAUDIO2_MIN_FREQ_RATIO, XAUDIO2_MAX_FREQ_RATIO, freqRatio );
|
||||
|
||||
// if the value specified for maxFreqRatio is too high for the specified format, the call to CreateSourceVoice will fail
|
||||
if( numChannels == 1 )
|
||||
{
|
||||
assert( freqRatio * ( float )SYSTEM_SAMPLE_RATE <= XAUDIO2_MAX_RATIO_TIMES_RATE_XMA_MONO );
|
||||
}
|
||||
else
|
||||
{
|
||||
assert( freqRatio * ( float )SYSTEM_SAMPLE_RATE <= XAUDIO2_MAX_RATIO_TIMES_RATE_XMA_MULTICHANNEL );
|
||||
}
|
||||
pSourceVoice->SetFrequencyRatio( freqRatio, operationSet );
|
||||
}
|
||||
|
||||
/*
|
||||
========================
|
||||
idSoundVoice_OpenAL::OnBufferStart
|
||||
========================
|
||||
*/
|
||||
void idSoundVoice_OpenAL::OnBufferStart( idSoundSample_OpenAL* sample, int bufferNumber )
|
||||
{
|
||||
SetSampleRate( sample->SampleRate(), XAUDIO2_COMMIT_NOW );
|
||||
|
||||
idSoundSample_OpenAL* nextSample = sample;
|
||||
int nextBuffer = bufferNumber + 1;
|
||||
if( nextBuffer == sample->buffers.Num() )
|
||||
{
|
||||
if( sample == leadinSample )
|
||||
{
|
||||
if( loopingSample == NULL )
|
||||
{
|
||||
return;
|
||||
}
|
||||
nextSample = loopingSample;
|
||||
}
|
||||
nextBuffer = 0;
|
||||
}
|
||||
|
||||
SubmitBuffer( nextSample, nextBuffer, 0 );
|
||||
}
|
119
neo/sound/OpenAL/AL_SoundVoice.h
Normal file
119
neo/sound/OpenAL/AL_SoundVoice.h
Normal file
|
@ -0,0 +1,119 @@
|
|||
/*
|
||||
===========================================================================
|
||||
|
||||
Doom 3 BFG Edition GPL Source Code
|
||||
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
|
||||
|
||||
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
|
||||
|
||||
Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
|
||||
|
||||
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
|
||||
|
||||
===========================================================================
|
||||
*/
|
||||
#ifndef __AL_SOUNDVOICE_H__
|
||||
#define __AL_SOUNDVOICE_H__
|
||||
|
||||
static const int MAX_QUEUED_BUFFERS = 3;
|
||||
|
||||
/*
|
||||
================================================
|
||||
idSoundVoice_OpenAL
|
||||
================================================
|
||||
*/
|
||||
class idSoundVoice_OpenAL : public idSoundVoice_Base
|
||||
{
|
||||
public:
|
||||
idSoundVoice_OpenAL();
|
||||
~idSoundVoice_OpenAL();
|
||||
|
||||
void Create( const idSoundSample* leadinSample, const idSoundSample* loopingSample );
|
||||
|
||||
// Start playing at a particular point in the buffer. Does an Update() too
|
||||
void Start( int offsetMS, int ssFlags );
|
||||
|
||||
// Stop playing.
|
||||
void Stop();
|
||||
|
||||
// Stop consuming buffers
|
||||
void Pause();
|
||||
// Start consuming buffers again
|
||||
void UnPause();
|
||||
|
||||
// Sends new position/volume/pitch information to the hardware
|
||||
bool Update();
|
||||
|
||||
// returns the RMS levels of the most recently processed block of audio, SSF_FLICKER must have been passed to Start
|
||||
float GetAmplitude();
|
||||
|
||||
// returns true if we can re-use this voice
|
||||
bool CompatibleFormat( idSoundSample_OpenAL* s );
|
||||
|
||||
uint32 GetSampleRate() const
|
||||
{
|
||||
return sampleRate;
|
||||
}
|
||||
|
||||
// callback function
|
||||
void OnBufferStart( idSoundSample_OpenAL* sample, int bufferNumber );
|
||||
|
||||
private:
|
||||
friend class idSoundHardware_OpenAL;
|
||||
|
||||
// Returns true when all the buffers are finished processing
|
||||
bool IsPlaying();
|
||||
|
||||
// Called after the voice has been stopped
|
||||
void FlushSourceBuffers();
|
||||
|
||||
// Destroy the internal hardware resource
|
||||
void DestroyInternal();
|
||||
|
||||
// Helper function used by the initial start as well as for looping a streamed buffer
|
||||
int RestartAt( int offsetSamples );
|
||||
|
||||
// Helper function to submit a buffer
|
||||
int SubmitBuffer( idSoundSample_OpenAL* sample, int bufferNumber, int offset );
|
||||
|
||||
// Adjust the voice frequency based on the new sample rate for the buffer
|
||||
void SetSampleRate( uint32 newSampleRate, uint32 operationSet );
|
||||
|
||||
IXAudio2SourceVoice* pSourceVoice;
|
||||
idSoundSample_OpenAL* leadinSample;
|
||||
idSoundSample_OpenAL* loopingSample;
|
||||
|
||||
// These are the fields from the sample format that matter to us for voice reuse
|
||||
uint16 formatTag;
|
||||
uint16 numChannels;
|
||||
|
||||
uint32 sourceVoiceRate;
|
||||
uint32 sampleRate;
|
||||
|
||||
bool hasVUMeter;
|
||||
bool paused;
|
||||
};
|
||||
|
||||
/*
|
||||
================================================
|
||||
idSoundVoice
|
||||
================================================
|
||||
*/
|
||||
class idSoundVoice : public idSoundVoice_OpenAL
|
||||
{
|
||||
};
|
||||
|
||||
#endif
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
Doom 3 BFG Edition GPL Source Code
|
||||
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
|
||||
Copyright (C) 2013 Robert Beckebans
|
||||
|
||||
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
|
||||
|
||||
|
@ -110,11 +111,17 @@ typedef enum
|
|||
#if (_WIN32_WINNT < 0x0602 /*_WIN32_WINNT_WIN8*/)
|
||||
#include <xma2defs.h>
|
||||
#endif
|
||||
// RB end
|
||||
|
||||
#if defined(USE_OPENAL)
|
||||
#include "OpenAL/AL_SoundSample.h"
|
||||
#include "OpenAL/AL_SoundVoice.h"
|
||||
#include "OpenAL/AL_SoundHardware.h"
|
||||
#else
|
||||
#include "XAudio2/XA2_SoundSample.h"
|
||||
#include "XAudio2/XA2_SoundVoice.h"
|
||||
#include "XAudio2/XA2_SoundHardware.h"
|
||||
#endif
|
||||
// RB end
|
||||
|
||||
#else // not _MSC_VER => MinGW, GCC, ...
|
||||
// just a stub for now
|
||||
|
@ -490,7 +497,10 @@ public:
|
|||
bufferNumber( 0 )
|
||||
{ }
|
||||
|
||||
#ifdef _MSC_VER // XAudio backend
|
||||
#if defined(USE_OPENAL)
|
||||
idSoundVoice_OpenAL* voice;
|
||||
idSoundSample_OpenAL* sample;
|
||||
#elif defined(_MSC_VER) // XAudio backend
|
||||
// DG: because the inheritance is kinda strange (idSoundVoice is derived
|
||||
// from idSoundVoice_XAudio2), casting the latter to the former isn't possible
|
||||
// so we need this ugly #ifdef ..
|
||||
|
|
Loading…
Reference in a new issue