Increase the number of audio channels to PS2 count and some small audio fixes

This commit is contained in:
Sergeanur 2021-05-23 16:47:16 +03:00
parent b5bc3a9000
commit 60bb16d26c
10 changed files with 134 additions and 107 deletions

View file

@ -43,9 +43,9 @@
#include "Script.h" #include "Script.h"
#include "Wanted.h" #include "Wanted.h"
const int channels = ARRAY_SIZE(AudioManager.m_asActiveSamples); #ifndef GTA_PS2
const int policeChannel = channels + 1; #define CHANNEL_PLAYER_VEHICLE_ENGINE m_nActiveSamples
const int allChannels = channels + 2; #endif
enum PLAY_STATUS { PLAY_STATUS_STOPPED = 0, PLAY_STATUS_PLAYING, PLAY_STATUS_FINISHED }; enum PLAY_STATUS { PLAY_STATUS_STOPPED = 0, PLAY_STATUS_PLAYING, PLAY_STATUS_FINISHED };
enum LOADING_STATUS { LOADING_STATUS_NOT_LOADED = 0, LOADING_STATUS_LOADED, LOADING_STATUS_FAILED }; enum LOADING_STATUS { LOADING_STATUS_NOT_LOADED = 0, LOADING_STATUS_LOADED, LOADING_STATUS_FAILED };
@ -246,23 +246,25 @@ cAudioManager::ResetAudioLogicTimers(uint32 timer)
} }
ClearMissionAudio(0); ClearMissionAudio(0);
ClearMissionAudio(1); ClearMissionAudio(1);
SampleManager.StopChannel(policeChannel); SampleManager.StopChannel(CHANNEL_POLICE_RADIO);
} }
void void
cAudioManager::ProcessReverb() const cAudioManager::ProcessReverb() const
{ {
#ifdef FIX_BUGS #ifdef FIX_BUGS
const uint32 numChannels = channels; const uint32 numChannels = NUM_CHANNELS_GENERIC;
#else #else
const uint32 numChannels = 28; const uint32 numChannels = NUM_CHANNELS_GENERIC+1;
#endif #endif
if (SampleManager.UpdateReverb() && m_bDynamicAcousticModelingStatus) { if (SampleManager.UpdateReverb() && m_bDynamicAcousticModelingStatus) {
#ifndef GTA_PS2
for (uint32 i = 0; i < numChannels; i++) { for (uint32 i = 0; i < numChannels; i++) {
if (m_asActiveSamples[i].m_bReverbFlag) if (m_asActiveSamples[i].m_bReverbFlag)
SampleManager.SetChannelReverbFlag(i, TRUE); SampleManager.SetChannelReverbFlag(i, TRUE);
} }
#endif
} }
} }
@ -347,7 +349,7 @@ cAudioManager::ProcessSpecial()
if (playerPed->m_audioEntityId >= 0 && m_asAudioEntities[playerPed->m_audioEntityId].m_bIsUsed) { if (playerPed->m_audioEntityId >= 0 && m_asAudioEntities[playerPed->m_audioEntityId].m_bIsUsed) {
if (playerPed->EnteringCar()) { if (playerPed->EnteringCar()) {
if(!playerPed->bInVehicle && CWorld::Players[CWorld::PlayerInFocus].m_pRemoteVehicle == nil) if(!playerPed->bInVehicle && CWorld::Players[CWorld::PlayerInFocus].m_pRemoteVehicle == nil)
SampleManager.StopChannel(m_nActiveSamples); SampleManager.StopChannel(CHANNEL_PLAYER_VEHICLE_ENGINE);
} }
} }
} }
@ -1316,7 +1318,7 @@ cAudioManager::ProcessVehicleEngine(cVehicleParams& params)
playerVeh = FindPlayerVehicle(); playerVeh = FindPlayerVehicle();
veh = params.m_pVehicle; veh = params.m_pVehicle;
if (playerVeh == veh && veh->GetStatus() == STATUS_WRECKED) { if (playerVeh == veh && veh->GetStatus() == STATUS_WRECKED) {
SampleManager.StopChannel(m_nActiveSamples); SampleManager.StopChannel(CHANNEL_PLAYER_VEHICLE_ENGINE);
return; return;
} }
if (!veh->bEngineOn) if (!veh->bEngineOn)
@ -1682,7 +1684,7 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams& params, CVehicle* veh
accelerateState = Pads[0].GetAccelerate(); accelerateState = Pads[0].GetAccelerate();
brakeState = Pads[0].GetBrake(); brakeState = Pads[0].GetBrake();
} }
channelUsed = SampleManager.GetChannelUsedFlag(m_nActiveSamples); channelUsed = SampleManager.GetChannelUsedFlag(CHANNEL_PLAYER_VEHICLE_ENGINE);
if (isMoped) { if (isMoped) {
CurrentPretendGear = params.m_pTransmission->nNumberOfGears; CurrentPretendGear = params.m_pTransmission->nNumberOfGears;
currentGear = CurrentPretendGear; currentGear = CurrentPretendGear;
@ -1846,7 +1848,7 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams& params, CVehicle* veh
if (accelerateState <= 0) { if (accelerateState <= 0) {
if (params.m_fVelocityChange < -0.001f) { if (params.m_fVelocityChange < -0.001f) {
if (channelUsed) { if (channelUsed) {
SampleManager.StopChannel(m_nActiveSamples); SampleManager.StopChannel(CHANNEL_PLAYER_VEHICLE_ENGINE);
bAccelSampleStopped = TRUE; bAccelSampleStopped = TRUE;
} }
if (wheelsOnGround == 0 || params.m_pVehicle->bIsHandbrakeOn || lostTraction) if (wheelsOnGround == 0 || params.m_pVehicle->bIsHandbrakeOn || lostTraction)
@ -1858,7 +1860,7 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams& params, CVehicle* veh
*gasPedalAudioPtr = Max(0.0f, gasPedalAudio); *gasPedalAudioPtr = Max(0.0f, gasPedalAudio);
} else if (LastAccel > 0) { } else if (LastAccel > 0) {
if (channelUsed) { if (channelUsed) {
SampleManager.StopChannel(m_nActiveSamples); SampleManager.StopChannel(CHANNEL_PLAYER_VEHICLE_ENGINE);
bAccelSampleStopped = TRUE; bAccelSampleStopped = TRUE;
} }
nCruising = 0; nCruising = 0;
@ -1919,7 +1921,7 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams& params, CVehicle* veh
if (engineSoundType == SFX_BANK_TRUCK) if (engineSoundType == SFX_BANK_TRUCK)
freq /= 2; freq /= 2;
if (channelUsed) { if (channelUsed) {
SampleManager.StopChannel(m_nActiveSamples); SampleManager.StopChannel(CHANNEL_PLAYER_VEHICLE_ENGINE);
bAccelSampleStopped = TRUE; bAccelSampleStopped = TRUE;
} }
if (params.m_pVehicle->bIsDrowning) if (params.m_pVehicle->bIsDrowning)
@ -1934,55 +1936,55 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams& params, CVehicle* veh
bAccelSampleStopped = FALSE; bAccelSampleStopped = FALSE;
} }
if (channelUsed) { if (channelUsed) {
SampleManager.SetChannelEmittingVolume(m_nActiveSamples, 120); SampleManager.SetChannelEmittingVolume(CHANNEL_PLAYER_VEHICLE_ENGINE, 120);
SampleManager.SetChannel3DPosition(m_nActiveSamples, pos.x, pos.y, pos.z); SampleManager.SetChannel3DPosition(CHANNEL_PLAYER_VEHICLE_ENGINE, pos.x, pos.y, pos.z);
SampleManager.SetChannel3DDistances(m_nActiveSamples, 50.0f, 12.5f); SampleManager.SetChannel3DDistances(CHANNEL_PLAYER_VEHICLE_ENGINE, 50.0f, 12.5f);
freq = (GearFreqAdj[CurrentPretendGear] + freqModifier + 22050) ; freq = (GearFreqAdj[CurrentPretendGear] + freqModifier + 22050) ;
if (engineSoundType == SFX_BANK_TRUCK) if (engineSoundType == SFX_BANK_TRUCK)
freq /= 2; freq /= 2;
SampleManager.SetChannelFrequency(m_nActiveSamples, freq); SampleManager.SetChannelFrequency(CHANNEL_PLAYER_VEHICLE_ENGINE, freq);
if (!channelUsed) { if (!channelUsed) {
SampleManager.SetChannelReverbFlag(m_nActiveSamples, m_bDynamicAcousticModelingStatus != FALSE); SampleManager.SetChannelReverbFlag(CHANNEL_PLAYER_VEHICLE_ENGINE, m_bDynamicAcousticModelingStatus != FALSE);
SampleManager.StartChannel(m_nActiveSamples); SampleManager.StartChannel(CHANNEL_PLAYER_VEHICLE_ENGINE);
} }
} else if (processedAccelSampleStopped) { } else if (processedAccelSampleStopped) {
gearSoundStartTime = CTimer::GetTimeInMilliseconds(); gearSoundStartTime = CTimer::GetTimeInMilliseconds();
params.m_pVehicle->bAudioChangingGear = TRUE; params.m_pVehicle->bAudioChangingGear = TRUE;
if (!SampleManager.InitialiseChannel(m_nActiveSamples, soundOffset + SFX_CAR_ACCEL_1, SFX_BANK_0)) if (!SampleManager.InitialiseChannel(CHANNEL_PLAYER_VEHICLE_ENGINE, soundOffset + SFX_CAR_ACCEL_1, SFX_BANK_0))
return; return;
SampleManager.SetChannelLoopCount(m_nActiveSamples, 1); SampleManager.SetChannelLoopCount(CHANNEL_PLAYER_VEHICLE_ENGINE, 1);
SampleManager.SetChannelLoopPoints(m_nActiveSamples, 0, -1); SampleManager.SetChannelLoopPoints(CHANNEL_PLAYER_VEHICLE_ENGINE, 0, -1);
SampleManager.SetChannelEmittingVolume(m_nActiveSamples, 120); SampleManager.SetChannelEmittingVolume(CHANNEL_PLAYER_VEHICLE_ENGINE, 120);
SampleManager.SetChannel3DPosition(m_nActiveSamples, pos.x, pos.y, pos.z); SampleManager.SetChannel3DPosition(CHANNEL_PLAYER_VEHICLE_ENGINE, pos.x, pos.y, pos.z);
SampleManager.SetChannel3DDistances(m_nActiveSamples, 50.0f, 12.5f); SampleManager.SetChannel3DDistances(CHANNEL_PLAYER_VEHICLE_ENGINE, 50.0f, 12.5f);
freq = (GearFreqAdj[CurrentPretendGear] + freqModifier + 22050); freq = (GearFreqAdj[CurrentPretendGear] + freqModifier + 22050);
if (engineSoundType == SFX_BANK_TRUCK) if (engineSoundType == SFX_BANK_TRUCK)
freq /= 2; freq /= 2;
SampleManager.SetChannelFrequency(m_nActiveSamples, freq); SampleManager.SetChannelFrequency(CHANNEL_PLAYER_VEHICLE_ENGINE, freq);
if (!channelUsed) { if (!channelUsed) {
SampleManager.SetChannelReverbFlag(m_nActiveSamples, m_bDynamicAcousticModelingStatus != FALSE); SampleManager.SetChannelReverbFlag(CHANNEL_PLAYER_VEHICLE_ENGINE, m_bDynamicAcousticModelingStatus != FALSE);
SampleManager.StartChannel(m_nActiveSamples); SampleManager.StartChannel(CHANNEL_PLAYER_VEHICLE_ENGINE);
} }
} else if (CurrentPretendGear < params.m_pTransmission->nNumberOfGears - 1) { } else if (CurrentPretendGear < params.m_pTransmission->nNumberOfGears - 1) {
++CurrentPretendGear; ++CurrentPretendGear;
gearSoundStartTime = CTimer::GetTimeInMilliseconds(); gearSoundStartTime = CTimer::GetTimeInMilliseconds();
params.m_pVehicle->bAudioChangingGear = TRUE; params.m_pVehicle->bAudioChangingGear = TRUE;
if (!SampleManager.InitialiseChannel(m_nActiveSamples, soundOffset + SFX_CAR_ACCEL_1, SFX_BANK_0)) if (!SampleManager.InitialiseChannel(CHANNEL_PLAYER_VEHICLE_ENGINE, soundOffset + SFX_CAR_ACCEL_1, SFX_BANK_0))
return; return;
SampleManager.SetChannelLoopCount(m_nActiveSamples, 1); SampleManager.SetChannelLoopCount(CHANNEL_PLAYER_VEHICLE_ENGINE, 1);
SampleManager.SetChannelLoopPoints(m_nActiveSamples, 0, -1); SampleManager.SetChannelLoopPoints(CHANNEL_PLAYER_VEHICLE_ENGINE, 0, -1);
SampleManager.SetChannelEmittingVolume(m_nActiveSamples, 120); SampleManager.SetChannelEmittingVolume(CHANNEL_PLAYER_VEHICLE_ENGINE, 120);
SampleManager.SetChannel3DPosition(m_nActiveSamples, pos.x, pos.y, pos.z); SampleManager.SetChannel3DPosition(CHANNEL_PLAYER_VEHICLE_ENGINE, pos.x, pos.y, pos.z);
SampleManager.SetChannel3DDistances(m_nActiveSamples, 50.0f, 12.5f); SampleManager.SetChannel3DDistances(CHANNEL_PLAYER_VEHICLE_ENGINE, 50.0f, 12.5f);
freq = (GearFreqAdj[CurrentPretendGear] + freqModifier + 22050); freq = (GearFreqAdj[CurrentPretendGear] + freqModifier + 22050);
if (engineSoundType == SFX_BANK_TRUCK) if (engineSoundType == SFX_BANK_TRUCK)
freq /= 2; freq /= 2;
SampleManager.SetChannelFrequency(m_nActiveSamples, freq); SampleManager.SetChannelFrequency(CHANNEL_PLAYER_VEHICLE_ENGINE, freq);
if (!channelUsed) { if (!channelUsed) {
SampleManager.SetChannelReverbFlag(m_nActiveSamples, m_bDynamicAcousticModelingStatus != FALSE); SampleManager.SetChannelReverbFlag(CHANNEL_PLAYER_VEHICLE_ENGINE, m_bDynamicAcousticModelingStatus != FALSE);
SampleManager.StartChannel(m_nActiveSamples); SampleManager.StartChannel(CHANNEL_PLAYER_VEHICLE_ENGINE);
} }
} else { } else {
nCruising = 1; nCruising = 1;
@ -1992,7 +1994,7 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams& params, CVehicle* veh
} else { } else {
PlayCruising: PlayCruising:
bAccelSampleStopped = TRUE; bAccelSampleStopped = TRUE;
SampleManager.StopChannel(m_nActiveSamples); SampleManager.StopChannel(CHANNEL_PLAYER_VEHICLE_ENGINE);
if (isMoped || accelerateState >= 150 && wheelsOnGround && brakeState <= 0 && !params.m_pVehicle->bIsHandbrakeOn if (isMoped || accelerateState >= 150 && wheelsOnGround && brakeState <= 0 && !params.m_pVehicle->bIsHandbrakeOn
&& !lostTraction && currentGear >= params.m_pTransmission->nNumberOfGears - 1) { && !lostTraction && currentGear >= params.m_pTransmission->nNumberOfGears - 1) {
if (accelerateState >= 220 && params.m_fVelocityChange + 0.001f >= velocityChangeForAudio) { if (accelerateState >= 220 && params.m_fVelocityChange + 0.001f >= velocityChangeForAudio) {

View file

@ -14,10 +14,6 @@
cAudioManager AudioManager; cAudioManager AudioManager;
const int channels = ARRAY_SIZE(AudioManager.m_asActiveSamples);
const int policeChannel = channels + 1;
const int allChannels = channels + 2;
#define SPEED_OF_SOUND 343.f #define SPEED_OF_SOUND 343.f
#define TIME_SPENT 40 #define TIME_SPENT 40
@ -28,7 +24,7 @@ cAudioManager::cAudioManager()
field_6 = 0; field_6 = 0;
m_fSpeedOfSound = SPEED_OF_SOUND / TIME_SPENT; m_fSpeedOfSound = SPEED_OF_SOUND / TIME_SPENT;
m_nTimeSpent = TIME_SPENT; m_nTimeSpent = TIME_SPENT;
m_nActiveSamples = NUM_SOUNDS_SAMPLES_SLOTS; m_nActiveSamples = NUM_CHANNELS_GENERIC;
m_nActiveSampleQueue = 1; m_nActiveSampleQueue = 1;
ClearRequestedQueue(); ClearRequestedQueue();
m_nActiveSampleQueue = 0; m_nActiveSampleQueue = 0;
@ -276,7 +272,7 @@ cAudioManager::ResetTimers(uint32 time)
ClearActiveSamples(); ClearActiveSamples();
ClearMissionAudio(0); ClearMissionAudio(0);
ClearMissionAudio(1); ClearMissionAudio(1);
SampleManager.StopChannel(policeChannel); SampleManager.StopChannel(CHANNEL_POLICE_RADIO);
SampleManager.SetEffectsFadeVolume(0); SampleManager.SetEffectsFadeVolume(0);
SampleManager.SetMusicFadeVolume(0); SampleManager.SetMusicFadeVolume(0);
MusicManager.ResetMusicAfterReload(); MusicManager.ResetMusicAfterReload();
@ -446,7 +442,7 @@ cAudioManager::ServiceSoundEffects()
{ {
m_bFifthFrameFlag = (m_FrameCounter++ % 5) == 0; m_bFifthFrameFlag = (m_FrameCounter++ % 5) == 0;
if (m_nUserPause && !m_nPreviousUserPause) { if (m_nUserPause && !m_nPreviousUserPause) {
for (int32 i = 0; i < allChannels; i++) for (int32 i = 0; i < NUM_CHANNELS; i++)
SampleManager.StopChannel(i); SampleManager.StopChannel(i);
ClearRequestedQueue(); ClearRequestedQueue();
@ -773,7 +769,12 @@ cAudioManager::UpdateReflections()
void void
cAudioManager::AddReleasingSounds() cAudioManager::AddReleasingSounds()
{ {
bool8 toProcess[44]; // why not 27? // in case someone would want to increase it
#ifdef FIX_BUGS
bool8 toProcess[NUM_CHANNELS_GENERIC];
#else
bool8 toProcess[44];
#endif
int8 queue = m_nActiveSampleQueue == 0 ? 1 : 0; int8 queue = m_nActiveSampleQueue == 0 ? 1 : 0;

View file

@ -205,10 +205,10 @@ public:
int32 m_nTimer; int32 m_nTimer;
tSound m_sQueueSample; tSound m_sQueueSample;
uint8 m_nActiveSampleQueue; uint8 m_nActiveSampleQueue;
tSound m_asSamples[NUM_SOUNDS_SAMPLES_BANKS][NUM_SOUNDS_SAMPLES_SLOTS]; tSound m_asSamples[NUM_SOUNDS_SAMPLES_BANKS][NUM_CHANNELS_GENERIC];
uint8 m_abSampleQueueIndexTable[NUM_SOUNDS_SAMPLES_BANKS][NUM_SOUNDS_SAMPLES_SLOTS]; uint8 m_abSampleQueueIndexTable[NUM_SOUNDS_SAMPLES_BANKS][NUM_CHANNELS_GENERIC];
uint8 m_SampleRequestQueuesStatus[NUM_SOUNDS_SAMPLES_BANKS]; uint8 m_SampleRequestQueuesStatus[NUM_SOUNDS_SAMPLES_BANKS];
tSound m_asActiveSamples[NUM_SOUNDS_SAMPLES_SLOTS]; tSound m_asActiveSamples[NUM_CHANNELS_GENERIC];
tAudioEntity m_asAudioEntities[NUM_AUDIOENTITIES]; tAudioEntity m_asAudioEntities[NUM_AUDIOENTITIES];
int32 m_anAudioEntityIndices[NUM_AUDIOENTITIES]; int32 m_anAudioEntityIndices[NUM_AUDIOENTITIES];
int32 m_nAudioEntitiesTotal; int32 m_nAudioEntitiesTotal;

View file

@ -15,9 +15,6 @@
#include "sampman.h" #include "sampman.h"
#include "Wanted.h" #include "Wanted.h"
const int channels = ARRAY_SIZE(AudioManager.m_asActiveSamples);
const int policeChannel = channels + 1;
struct tPoliceRadioZone { struct tPoliceRadioZone {
char m_aName[8]; char m_aName[8];
uint32 m_nSampleIndex; uint32 m_nSampleIndex;
@ -68,7 +65,7 @@ cAudioManager::InitialisePoliceRadio()
for (int32 i = 0; i < ARRAY_SIZE(m_sPoliceRadioQueue.crimes); i++) for (int32 i = 0; i < ARRAY_SIZE(m_sPoliceRadioQueue.crimes); i++)
m_sPoliceRadioQueue.crimes[i].type = CRIME_NONE; m_sPoliceRadioQueue.crimes[i].type = CRIME_NONE;
SampleManager.SetChannelReverbFlag(policeChannel, FALSE); SampleManager.SetChannelReverbFlag(CHANNEL_POLICE_RADIO, FALSE);
gSpecialSuspectLastSeenReport = FALSE; gSpecialSuspectLastSeenReport = FALSE;
for (int32 i = 0; i < ARRAY_SIZE(gMinTimeToNextReport); i++) for (int32 i = 0; i < ARRAY_SIZE(gMinTimeToNextReport); i++)
gMinTimeToNextReport[i] = m_FrameCounter; gMinTimeToNextReport[i] = m_FrameCounter;
@ -78,7 +75,7 @@ void
cAudioManager::ResetPoliceRadio() cAudioManager::ResetPoliceRadio()
{ {
if (!m_bIsInitialised) return; if (!m_bIsInitialised) return;
if (SampleManager.GetChannelUsedFlag(policeChannel)) SampleManager.StopChannel(policeChannel); if (SampleManager.GetChannelUsedFlag(CHANNEL_POLICE_RADIO)) SampleManager.StopChannel(CHANNEL_POLICE_RADIO);
InitialisePoliceRadio(); InitialisePoliceRadio();
} }
@ -168,7 +165,7 @@ cAudioManager::ServicePoliceRadioChannel(uint8 wantedLevel)
if (!m_bIsInitialised) return; if (!m_bIsInitialised) return;
if (m_nUserPause != 0) { if (m_nUserPause != 0) {
if (SampleManager.GetChannelUsedFlag(policeChannel)) SampleManager.StopChannel(policeChannel); if (SampleManager.GetChannelUsedFlag(CHANNEL_POLICE_RADIO)) SampleManager.StopChannel(CHANNEL_POLICE_RADIO);
if (g_nMissionAudioSfx != NO_SAMPLE && bMissionAudioPhysicalPlayingStatus == 1 && if (g_nMissionAudioSfx != NO_SAMPLE && bMissionAudioPhysicalPlayingStatus == 1 &&
SampleManager.IsStreamPlaying(1)) { SampleManager.IsStreamPlaying(1)) {
SampleManager.PauseStream(TRUE, 1); SampleManager.PauseStream(TRUE, 1);
@ -200,7 +197,7 @@ cAudioManager::ServicePoliceRadioChannel(uint8 wantedLevel)
} }
return; return;
} }
} else if (!SampleManager.GetChannelUsedFlag(policeChannel)) { } else if (!SampleManager.GetChannelUsedFlag(CHANNEL_POLICE_RADIO)) {
SampleManager.PreloadStreamedFile(g_nMissionAudioSfx, 1); SampleManager.PreloadStreamedFile(g_nMissionAudioSfx, 1);
SampleManager.SetStreamedVolumeAndPan(MAX_VOLUME, 63, TRUE, 1); SampleManager.SetStreamedVolumeAndPan(MAX_VOLUME, 63, TRUE, 1);
SampleManager.StartPreloadedStreamedFile(1); SampleManager.StartPreloadedStreamedFile(1);
@ -211,7 +208,7 @@ cAudioManager::ServicePoliceRadioChannel(uint8 wantedLevel)
} }
if (bChannelOpen) DoPoliceRadioCrackle(); if (bChannelOpen) DoPoliceRadioCrackle();
if ((g_nMissionAudioSfx == NO_SAMPLE || g_nMissionAudioPlayingStatus != 1) && if ((g_nMissionAudioSfx == NO_SAMPLE || g_nMissionAudioPlayingStatus != 1) &&
!SampleManager.GetChannelUsedFlag(policeChannel) && m_sPoliceRadioQueue.policeChannelTimer) { !SampleManager.GetChannelUsedFlag(CHANNEL_POLICE_RADIO) && m_sPoliceRadioQueue.policeChannelTimer) {
if (m_sPoliceRadioQueue.policeChannelTimer) { if (m_sPoliceRadioQueue.policeChannelTimer) {
sample = m_sPoliceRadioQueue.crimesSamples[m_sPoliceRadioQueue.policeChannelCounterSeconds]; sample = m_sPoliceRadioQueue.crimesSamples[m_sPoliceRadioQueue.policeChannelCounterSeconds];
m_sPoliceRadioQueue.policeChannelTimer--; m_sPoliceRadioQueue.policeChannelTimer--;
@ -230,7 +227,7 @@ cAudioManager::ServicePoliceRadioChannel(uint8 wantedLevel)
if (sample == NO_SAMPLE) { if (sample == NO_SAMPLE) {
if (!processed) cWait = 30; if (!processed) cWait = 30;
} else { } else {
SampleManager.InitialiseChannel(policeChannel, sample, 0); SampleManager.InitialiseChannel(CHANNEL_POLICE_RADIO, sample, 0);
switch (sample) { switch (sample) {
case SFX_POLICE_RADIO_MESSAGE_NOISE_1: case SFX_POLICE_RADIO_MESSAGE_NOISE_1:
freq = m_anRandomTable[4] % 2000 + 10025; freq = m_anRandomTable[4] % 2000 + 10025;
@ -239,12 +236,12 @@ cAudioManager::ServicePoliceRadioChannel(uint8 wantedLevel)
default: freq = SampleManager.GetSampleBaseFrequency(sample); break; default: freq = SampleManager.GetSampleBaseFrequency(sample); break;
} }
PoliceChannelFreq = freq; PoliceChannelFreq = freq;
SampleManager.SetChannelFrequency(policeChannel, freq); SampleManager.SetChannelFrequency(CHANNEL_POLICE_RADIO, freq);
SampleManager.SetChannelVolume(policeChannel, 100); SampleManager.SetChannelVolume(CHANNEL_POLICE_RADIO, 100);
SampleManager.SetChannelPan(policeChannel, 63); SampleManager.SetChannelPan(CHANNEL_POLICE_RADIO, 63);
SampleManager.SetChannelLoopCount(policeChannel, 1); SampleManager.SetChannelLoopCount(CHANNEL_POLICE_RADIO, 1);
SampleManager.SetChannelLoopPoints(policeChannel, 0, -1); SampleManager.SetChannelLoopPoints(CHANNEL_POLICE_RADIO, 0, -1);
SampleManager.StartChannel(policeChannel); SampleManager.StartChannel(CHANNEL_POLICE_RADIO);
} }
if (processed) ResetPoliceRadio(); if (processed) ResetPoliceRadio();
} }

View file

@ -137,3 +137,26 @@ enum eAudioType
AUDIOTYPE_POLICERADIO, AUDIOTYPE_POLICERADIO,
TOTAL_AUDIO_TYPES, TOTAL_AUDIO_TYPES,
}; };
#ifdef GTA_PS2
enum
{
NUM_CHANNELS_GENERIC = 42,
CHANNEL_POLICE_RADIO = NUM_CHANNELS_GENERIC,
CHANNEL_MISSION_AUDIO_1,
CHANNEL_MISSION_AUDIO_2,
CHANNEL_PLAYER_VEHICLE_ENGINE,
NUM_CHANNELS
};
#else
enum
{
#ifdef PS2_AUDIO_CHANNELS
NUM_CHANNELS_GENERIC = 42,
#else
NUM_CHANNELS_GENERIC = 27,
#endif
CHANNEL_POLICE_RADIO,
NUM_CHANNELS
};
#endif

View file

@ -10,9 +10,9 @@
extern bool IsFXSupported(); extern bool IsFXSupported();
ALuint alSources[MAXCHANNELS+MAX2DCHANNELS]; ALuint alSources[NUM_CHANNELS];
ALuint alFilters[MAXCHANNELS+MAX2DCHANNELS]; ALuint alFilters[NUM_CHANNELS];
ALuint alBuffers[MAXCHANNELS+MAX2DCHANNELS]; ALuint alBuffers[NUM_CHANNELS];
bool bChannelsCreated = false; bool bChannelsCreated = false;
int32 CChannel::channelsThatNeedService = 0; int32 CChannel::channelsThatNeedService = 0;
@ -22,10 +22,10 @@ uint8 tempStereoBuffer[PED_BLOCKSIZE * 2];
void void
CChannel::InitChannels() CChannel::InitChannels()
{ {
alGenSources(MAXCHANNELS+MAX2DCHANNELS, alSources); alGenSources(NUM_CHANNELS, alSources);
alGenBuffers(MAXCHANNELS+MAX2DCHANNELS, alBuffers); alGenBuffers(NUM_CHANNELS, alBuffers);
if (IsFXSupported()) if (IsFXSupported())
alGenFilters(MAXCHANNELS + MAX2DCHANNELS, alFilters); alGenFilters(NUM_CHANNELS, alFilters);
bChannelsCreated = true; bChannelsCreated = true;
} }
@ -34,13 +34,13 @@ CChannel::DestroyChannels()
{ {
if (bChannelsCreated) if (bChannelsCreated)
{ {
alDeleteSources(MAXCHANNELS + MAX2DCHANNELS, alSources); alDeleteSources(NUM_CHANNELS, alSources);
memset(alSources, 0, sizeof(alSources)); memset(alSources, 0, sizeof(alSources));
alDeleteBuffers(MAXCHANNELS + MAX2DCHANNELS, alBuffers); alDeleteBuffers(NUM_CHANNELS, alBuffers);
memset(alBuffers, 0, sizeof(alBuffers)); memset(alBuffers, 0, sizeof(alBuffers));
if (IsFXSupported()) if (IsFXSupported())
{ {
alDeleteFilters(MAXCHANNELS + MAX2DCHANNELS, alFilters); alDeleteFilters(NUM_CHANNELS, alFilters);
memset(alFilters, 0, sizeof(alFilters)); memset(alFilters, 0, sizeof(alFilters));
} }
bChannelsCreated = false; bChannelsCreated = false;

View file

@ -1,5 +1,6 @@
#pragma once #pragma once
#include "AudioSamples.h" #include "AudioSamples.h"
#include "audio_enums.h"
#define MAX_VOLUME 127 #define MAX_VOLUME 127
#define MAX_FREQ DIGITALRATE #define MAX_FREQ DIGITALRATE
@ -115,10 +116,9 @@ enum
#define MAXPROVIDERS 64 #define MAXPROVIDERS 64
#define MAXCHANNELS 28 #define MAXCHANNELS (NUM_CHANNELS_GENERIC+1)
#define MAXCHANNELS_SURROUND 24 #define MAXCHANNELS_SURROUND (MAXCHANNELS-4)
#define MAX2DCHANNELS 3 #define MAX2DCHANNELS 3
#define CHANNEL2D MAXCHANNELS
#define MAX_STREAMS 1 #define MAX_STREAMS 1
@ -126,7 +126,13 @@ enum
#define DIGITALBITS 16 #define DIGITALBITS 16
#define DIGITALCHANNELS 2 #define DIGITALCHANNELS 2
#define MAX_DIGITAL_MIXER_CHANNELS 34 #ifdef FIX_BUGS
#define MAX_DIGITAL_MIXER_CHANNELS (MAXCHANNELS+MAX_STREAMS*2+MAX2DCHANNELS)
#else
#define MAX_DIGITAL_MIXER_CHANNELS (MAXCHANNELS+MAX_STREAMS*2)
#endif
static_assert( NUM_CHANNELS == MAXCHANNELS + MAX2DCHANNELS, "The number of channels doesn't match with an enum" );
extern int gBankStartOffset[67]; extern int gBankStartOffset[67];

View file

@ -1785,7 +1785,7 @@ cSampleManager::SetChannelReverbFlag(uint32 nChannel, bool8 nReverbFlag)
switch ( nChannel ) switch ( nChannel )
{ {
case CHANNEL2D: case CHANNEL_POLICE_RADIO:
case CHANNEL2D+1: case CHANNEL2D+1:
case CHANNEL2D+2: case CHANNEL2D+2:
{ {
@ -1816,7 +1816,7 @@ cSampleManager::InitialiseChannel(uint32 nChannel, uint32 nSfx, uint8 nBank)
switch ( nChannel ) switch ( nChannel )
{ {
case CHANNEL2D: case CHANNEL_POLICE_RADIO:
case CHANNEL2D+1: case CHANNEL2D+1:
case CHANNEL2D+2: case CHANNEL2D+2:
{ {
@ -1918,7 +1918,7 @@ cSampleManager::SetChannelVolume(uint32 nChannel, uint32 nVolume)
switch ( nChannel ) switch ( nChannel )
{ {
case CHANNEL2D: case CHANNEL_POLICE_RADIO:
case CHANNEL2D+1: case CHANNEL2D+1:
case CHANNEL2D+2: case CHANNEL2D+2:
{ {
@ -1947,7 +1947,7 @@ cSampleManager::SetChannelPan(uint32 nChannel, uint32 nPan)
{ {
switch ( nChannel ) switch ( nChannel )
{ {
case CHANNEL2D: case CHANNEL_POLICE_RADIO:
case CHANNEL2D+1: case CHANNEL2D+1:
case CHANNEL2D+2: case CHANNEL2D+2:
{ {
@ -1970,7 +1970,7 @@ cSampleManager::SetChannelFrequency(uint32 nChannel, uint32 nFreq)
switch ( nChannel ) switch ( nChannel )
{ {
case CHANNEL2D: case CHANNEL_POLICE_RADIO:
case CHANNEL2D+1: case CHANNEL2D+1:
case CHANNEL2D+2: case CHANNEL2D+2:
{ {
@ -1998,7 +1998,7 @@ cSampleManager::SetChannelLoopPoints(uint32 nChannel, uint32 nLoopStart, int32 n
switch ( nChannel ) switch ( nChannel )
{ {
case CHANNEL2D: case CHANNEL_POLICE_RADIO:
case CHANNEL2D+1: case CHANNEL2D+1:
case CHANNEL2D+2: case CHANNEL2D+2:
{ {
@ -2026,7 +2026,7 @@ cSampleManager::SetChannelLoopCount(uint32 nChannel, uint32 nLoopCount)
switch ( nChannel ) switch ( nChannel )
{ {
case CHANNEL2D: case CHANNEL_POLICE_RADIO:
case CHANNEL2D+1: case CHANNEL2D+1:
case CHANNEL2D+2: case CHANNEL2D+2:
{ {
@ -2054,7 +2054,7 @@ cSampleManager::GetChannelUsedFlag(uint32 nChannel)
switch ( nChannel ) switch ( nChannel )
{ {
case CHANNEL2D: case CHANNEL_POLICE_RADIO:
case CHANNEL2D+1: case CHANNEL2D+1:
case CHANNEL2D+2: case CHANNEL2D+2:
{ {
@ -2087,7 +2087,7 @@ cSampleManager::StartChannel(uint32 nChannel)
switch ( nChannel ) switch ( nChannel )
{ {
case CHANNEL2D: case CHANNEL_POLICE_RADIO:
case CHANNEL2D+1: case CHANNEL2D+1:
case CHANNEL2D+2: case CHANNEL2D+2:
{ {
@ -2115,7 +2115,7 @@ cSampleManager::StopChannel(uint32 nChannel)
switch ( nChannel ) switch ( nChannel )
{ {
case CHANNEL2D: case CHANNEL_POLICE_RADIO:
case CHANNEL2D+1: case CHANNEL2D+1:
case CHANNEL2D+2: case CHANNEL2D+2:
{ {

View file

@ -94,8 +94,8 @@ int32 nPedSlotSfx [MAX_PEDSFX];
int32 nPedSlotSfxAddr[MAX_PEDSFX]; int32 nPedSlotSfxAddr[MAX_PEDSFX];
uint8 nCurrentPedSlot; uint8 nCurrentPedSlot;
CChannel aChannel[MAXCHANNELS+MAX2DCHANNELS]; CChannel aChannel[NUM_CHANNELS];
uint8 nChannelVolume[MAXCHANNELS+MAX2DCHANNELS]; uint8 nChannelVolume[NUM_CHANNELS];
uint32 nStreamLength[TOTAL_STREAMED_SOUNDS]; uint32 nStreamLength[TOTAL_STREAMED_SOUNDS];
ALuint ALStreamSources[MAX_STREAMS][2]; ALuint ALStreamSources[MAX_STREAMS][2];
@ -283,7 +283,8 @@ set_new_provider(int index)
_maxSamples = MAXCHANNELS; _maxSamples = MAXCHANNELS;
ALCint attr[] = {ALC_FREQUENCY,MAX_FREQ, ALCint attr[] = {ALC_FREQUENCY,MAX_FREQ,
ALC_MONO_SOURCES, MAX_STREAMS * 2 + MAXCHANNELS, ALC_MONO_SOURCES, MAX_DIGITAL_MIXER_CHANNELS - MAX2DCHANNELS,
ALC_STEREO_SOURCES, MAX2DCHANNELS,
0, 0,
}; };
@ -369,7 +370,7 @@ set_new_provider(int index)
CChannel::InitChannels(); CChannel::InitChannels();
for ( int32 i = 0; i < MAXCHANNELS; i++ ) for ( int32 i = 0; i < MAXCHANNELS; i++ )
aChannel[i].Init(i); aChannel[i].Init(i);
for ( int32 i = 0; i < MAX2DCHANNELS; i++ ) for ( int32 i = 0; i < MAX2DCHANNELS; i++ )
aChannel[CHANNEL2D+i].Init(CHANNEL2D+i, true); aChannel[CHANNEL2D+i].Init(CHANNEL2D+i, true);
@ -1052,7 +1053,7 @@ cSampleManager::Initialise(void)
} }
{ {
for ( int32 i = 0; i < MAXCHANNELS+MAX2DCHANNELS; i++ ) for ( int32 i = 0; i < NUM_CHANNELS; i++ )
nChannelVolume[i] = 0; nChannelVolume[i] = 0;
} }
@ -1276,7 +1277,7 @@ cSampleManager::UpdateEffectsVolume(void)
{ {
if ( _bSampmanInitialised ) if ( _bSampmanInitialised )
{ {
for ( int32 i = 0; i < MAXCHANNELS+MAX2DCHANNELS; i++ ) for ( int32 i = 0; i < NUM_CHANNELS; i++ )
{ {
if ( GetChannelUsedFlag(i) ) if ( GetChannelUsedFlag(i) )
{ {
@ -1584,7 +1585,7 @@ bool8 cSampleManager::UpdateReverb(void)
void void
cSampleManager::SetChannelReverbFlag(uint32 nChannel, bool8 nReverbFlag) cSampleManager::SetChannelReverbFlag(uint32 nChannel, bool8 nReverbFlag)
{ {
ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS ); ASSERT( nChannel < NUM_CHANNELS );
if ( usingEAX || _usingEFX ) if ( usingEAX || _usingEFX )
{ {
@ -1603,7 +1604,7 @@ cSampleManager::SetChannelReverbFlag(uint32 nChannel, bool8 nReverbFlag)
bool8 bool8
cSampleManager::InitialiseChannel(uint32 nChannel, uint32 nSfx, uint8 nBank) cSampleManager::InitialiseChannel(uint32 nChannel, uint32 nSfx, uint8 nBank)
{ {
ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS ); ASSERT( nChannel < NUM_CHANNELS );
uintptr addr; uintptr addr;
@ -1645,7 +1646,6 @@ void
cSampleManager::SetChannelEmittingVolume(uint32 nChannel, uint32 nVolume) cSampleManager::SetChannelEmittingVolume(uint32 nChannel, uint32 nVolume)
{ {
ASSERT( nChannel < CHANNEL2D ); ASSERT( nChannel < CHANNEL2D );
ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS );
uint32 vol = nVolume; uint32 vol = nVolume;
if ( vol > MAX_VOLUME ) vol = MAX_VOLUME; if ( vol > MAX_VOLUME ) vol = MAX_VOLUME;
@ -1667,7 +1667,6 @@ void
cSampleManager::SetChannel3DPosition(uint32 nChannel, float fX, float fY, float fZ) cSampleManager::SetChannel3DPosition(uint32 nChannel, float fX, float fY, float fZ)
{ {
ASSERT( nChannel < CHANNEL2D ); ASSERT( nChannel < CHANNEL2D );
ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS );
aChannel[nChannel].SetPosition(-fX, fY, fZ); aChannel[nChannel].SetPosition(-fX, fY, fZ);
} }
@ -1676,7 +1675,6 @@ void
cSampleManager::SetChannel3DDistances(uint32 nChannel, float fMax, float fMin) cSampleManager::SetChannel3DDistances(uint32 nChannel, float fMax, float fMin)
{ {
ASSERT( nChannel < CHANNEL2D ); ASSERT( nChannel < CHANNEL2D );
ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS );
aChannel[nChannel].SetDistances(fMax, fMin); aChannel[nChannel].SetDistances(fMax, fMin);
} }
@ -1684,7 +1682,7 @@ void
cSampleManager::SetChannelVolume(uint32 nChannel, uint32 nVolume) cSampleManager::SetChannelVolume(uint32 nChannel, uint32 nVolume)
{ {
ASSERT(nChannel >= CHANNEL2D ); ASSERT(nChannel >= CHANNEL2D );
ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS ); ASSERT( nChannel < NUM_CHANNELS );
if(nChannel >= CHANNEL2D) if(nChannel >= CHANNEL2D)
{ {
@ -1709,7 +1707,7 @@ void
cSampleManager::SetChannelPan(uint32 nChannel, uint32 nPan) cSampleManager::SetChannelPan(uint32 nChannel, uint32 nPan)
{ {
ASSERT(nChannel >= CHANNEL2D); ASSERT(nChannel >= CHANNEL2D);
ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS ); ASSERT( nChannel < NUM_CHANNELS );
if ( nChannel >= CHANNEL2D ) if ( nChannel >= CHANNEL2D )
{ {
@ -1720,7 +1718,7 @@ cSampleManager::SetChannelPan(uint32 nChannel, uint32 nPan)
void void
cSampleManager::SetChannelFrequency(uint32 nChannel, uint32 nFreq) cSampleManager::SetChannelFrequency(uint32 nChannel, uint32 nFreq)
{ {
ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS ); ASSERT( nChannel < NUM_CHANNELS );
aChannel[nChannel].SetCurrentFreq(nFreq); aChannel[nChannel].SetCurrentFreq(nFreq);
} }
@ -1728,7 +1726,7 @@ cSampleManager::SetChannelFrequency(uint32 nChannel, uint32 nFreq)
void void
cSampleManager::SetChannelLoopPoints(uint32 nChannel, uint32 nLoopStart, int32 nLoopEnd) cSampleManager::SetChannelLoopPoints(uint32 nChannel, uint32 nLoopStart, int32 nLoopEnd)
{ {
ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS ); ASSERT( nChannel < NUM_CHANNELS );
aChannel[nChannel].SetLoopPoints(nLoopStart / (DIGITALBITS / 8), nLoopEnd / (DIGITALBITS / 8)); aChannel[nChannel].SetLoopPoints(nLoopStart / (DIGITALBITS / 8), nLoopEnd / (DIGITALBITS / 8));
} }
@ -1736,7 +1734,7 @@ cSampleManager::SetChannelLoopPoints(uint32 nChannel, uint32 nLoopStart, int32 n
void void
cSampleManager::SetChannelLoopCount(uint32 nChannel, uint32 nLoopCount) cSampleManager::SetChannelLoopCount(uint32 nChannel, uint32 nLoopCount)
{ {
ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS ); ASSERT( nChannel < NUM_CHANNELS );
aChannel[nChannel].SetLoopCount(nLoopCount); aChannel[nChannel].SetLoopCount(nLoopCount);
} }
@ -1744,7 +1742,7 @@ cSampleManager::SetChannelLoopCount(uint32 nChannel, uint32 nLoopCount)
bool8 bool8
cSampleManager::GetChannelUsedFlag(uint32 nChannel) cSampleManager::GetChannelUsedFlag(uint32 nChannel)
{ {
ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS ); ASSERT( nChannel < NUM_CHANNELS );
return aChannel[nChannel].IsUsed(); return aChannel[nChannel].IsUsed();
} }
@ -1752,7 +1750,7 @@ cSampleManager::GetChannelUsedFlag(uint32 nChannel)
void void
cSampleManager::StartChannel(uint32 nChannel) cSampleManager::StartChannel(uint32 nChannel)
{ {
ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS ); ASSERT( nChannel < NUM_CHANNELS );
aChannel[nChannel].Start(); aChannel[nChannel].Start();
} }
@ -1760,7 +1758,7 @@ cSampleManager::StartChannel(uint32 nChannel)
void void
cSampleManager::StopChannel(uint32 nChannel) cSampleManager::StopChannel(uint32 nChannel)
{ {
ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS ); ASSERT( nChannel < NUM_CHANNELS );
aChannel[nChannel].Stop(); aChannel[nChannel].Stop();
} }
@ -2167,7 +2165,7 @@ cSampleManager::Service(void)
stream->Update(); stream->Update();
} }
int refCount = CChannel::channelsThatNeedService; int refCount = CChannel::channelsThatNeedService;
for ( int32 i = 0; refCount && i < MAXCHANNELS+MAX2DCHANNELS; i++ ) for ( int32 i = 0; refCount && i < NUM_CHANNELS; i++ )
{ {
if ( aChannel[i].Update() ) if ( aChannel[i].Update() )
refCount--; refCount--;

View file

@ -131,7 +131,6 @@ enum Config {
NUM_PED_COMMENTS_SLOTS = 20, NUM_PED_COMMENTS_SLOTS = 20,
NUM_SOUNDS_SAMPLES_BANKS = 2, NUM_SOUNDS_SAMPLES_BANKS = 2,
NUM_SOUNDS_SAMPLES_SLOTS = 27,
NUM_AUDIOENTITIES = 250, NUM_AUDIOENTITIES = 250,
NUM_AUDIO_REFLECTIONS = 8, NUM_AUDIO_REFLECTIONS = 8,
@ -400,6 +399,7 @@ static_assert(false, "SUPPORT_XBOX_SCRIPT and SUPPORT_MOBILE_SCRIPT are mutually
// Audio // Audio
#define RADIO_SCROLL_TO_PREV_STATION // Won't work without FIX_BUGS #define RADIO_SCROLL_TO_PREV_STATION // Won't work without FIX_BUGS
//#define AUDIO_CACHE // cache sound lengths to speed up the cold boot //#define AUDIO_CACHE // cache sound lengths to speed up the cold boot
#define PS2_AUDIO_CHANNELS // increases the maximum number of audio channels to PS2 value of 43 (PC has 28 originally)
//#define PS2_AUDIO_PATHS // changes audio paths for cutscenes and radio to PS2 paths (needs vbdec on MSS builds) //#define PS2_AUDIO_PATHS // changes audio paths for cutscenes and radio to PS2 paths (needs vbdec on MSS builds)
//#define AUDIO_OAL_USE_SNDFILE // use libsndfile to decode WAVs instead of our internal decoder //#define AUDIO_OAL_USE_SNDFILE // use libsndfile to decode WAVs instead of our internal decoder
#define AUDIO_OAL_USE_MPG123 // use mpg123 to support mp3 files #define AUDIO_OAL_USE_MPG123 // use mpg123 to support mp3 files