summaryrefslogtreecommitdiffstats
path: root/src/audio
diff options
context:
space:
mode:
authorSergeanur <s.anureev@yandex.ua>2021-05-23 15:47:16 +0200
committerSergeanur <s.anureev@yandex.ua>2021-06-24 20:34:33 +0200
commit02655313e9726a044dcecdeb143c261614d00f0f (patch)
treed019ad3353e749dc17dd3bfac885cd3d97558d5f /src/audio
parentFix MAX_DIGITAL_MIXER_CHANNELS (diff)
downloadre3-02655313e9726a044dcecdeb143c261614d00f0f.tar
re3-02655313e9726a044dcecdeb143c261614d00f0f.tar.gz
re3-02655313e9726a044dcecdeb143c261614d00f0f.tar.bz2
re3-02655313e9726a044dcecdeb143c261614d00f0f.tar.lz
re3-02655313e9726a044dcecdeb143c261614d00f0f.tar.xz
re3-02655313e9726a044dcecdeb143c261614d00f0f.tar.zst
re3-02655313e9726a044dcecdeb143c261614d00f0f.zip
Diffstat (limited to '')
-rw-r--r--src/audio/AudioLogic.cpp76
-rw-r--r--src/audio/AudioManager.cpp17
-rw-r--r--src/audio/AudioManager.h8
-rw-r--r--src/audio/PolRadio.cpp27
-rw-r--r--src/audio/audio_enums.h23
-rw-r--r--src/audio/oal/channel.cpp18
-rw-r--r--src/audio/sampman.h14
-rw-r--r--src/audio/sampman_miles.cpp20
-rw-r--r--src/audio/sampman_oal.cpp58
9 files changed, 144 insertions, 117 deletions
diff --git a/src/audio/AudioLogic.cpp b/src/audio/AudioLogic.cpp
index a3493e38..15454bfe 100644
--- a/src/audio/AudioLogic.cpp
+++ b/src/audio/AudioLogic.cpp
@@ -43,9 +43,9 @@
#include "Script.h"
#include "Wanted.h"
-const int channels = ARRAY_SIZE(AudioManager.m_asActiveSamples);
-const int policeChannel = channels + 1;
-const int allChannels = channels + 2;
+#ifndef GTA_PS2
+#define CHANNEL_PLAYER_VEHICLE_ENGINE m_nActiveSamples
+#endif
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 };
@@ -246,23 +246,25 @@ cAudioManager::ResetAudioLogicTimers(uint32 timer)
}
ClearMissionAudio(0);
ClearMissionAudio(1);
- SampleManager.StopChannel(policeChannel);
+ SampleManager.StopChannel(CHANNEL_POLICE_RADIO);
}
void
cAudioManager::ProcessReverb() const
{
#ifdef FIX_BUGS
- const uint32 numChannels = channels;
+ const uint32 numChannels = NUM_CHANNELS_GENERIC;
#else
- const uint32 numChannels = 28;
+ const uint32 numChannels = NUM_CHANNELS_GENERIC+1;
#endif
if (SampleManager.UpdateReverb() && m_bDynamicAcousticModelingStatus) {
+#ifndef GTA_PS2
for (uint32 i = 0; i < numChannels; i++) {
if (m_asActiveSamples[i].m_bReverbFlag)
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->EnteringCar()) {
if(!playerPed->bInVehicle && CWorld::Players[CWorld::PlayerInFocus].m_pRemoteVehicle == nil)
- SampleManager.StopChannel(m_nActiveSamples);
+ SampleManager.StopChannel(CHANNEL_PLAYER_VEHICLE_ENGINE);
}
}
}
@@ -1307,7 +1309,7 @@ cAudioManager::ProcessVehicleEngine(cVehicleParams& params)
playerVeh = FindPlayerVehicle();
veh = params.m_pVehicle;
if (playerVeh == veh && veh->GetStatus() == STATUS_WRECKED) {
- SampleManager.StopChannel(m_nActiveSamples);
+ SampleManager.StopChannel(CHANNEL_PLAYER_VEHICLE_ENGINE);
return;
}
if (!veh->bEngineOn)
@@ -1673,7 +1675,7 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams& params, CVehicle* veh
accelerateState = Pads[0].GetAccelerate();
brakeState = Pads[0].GetBrake();
}
- channelUsed = SampleManager.GetChannelUsedFlag(m_nActiveSamples);
+ channelUsed = SampleManager.GetChannelUsedFlag(CHANNEL_PLAYER_VEHICLE_ENGINE);
if (isMoped) {
CurrentPretendGear = params.m_pTransmission->nNumberOfGears;
currentGear = CurrentPretendGear;
@@ -1837,7 +1839,7 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams& params, CVehicle* veh
if (accelerateState <= 0) {
if (params.m_fVelocityChange < -0.001f) {
if (channelUsed) {
- SampleManager.StopChannel(m_nActiveSamples);
+ SampleManager.StopChannel(CHANNEL_PLAYER_VEHICLE_ENGINE);
bAccelSampleStopped = TRUE;
}
if (wheelsOnGround == 0 || params.m_pVehicle->bIsHandbrakeOn || lostTraction)
@@ -1849,7 +1851,7 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams& params, CVehicle* veh
*gasPedalAudioPtr = Max(0.0f, gasPedalAudio);
} else if (LastAccel > 0) {
if (channelUsed) {
- SampleManager.StopChannel(m_nActiveSamples);
+ SampleManager.StopChannel(CHANNEL_PLAYER_VEHICLE_ENGINE);
bAccelSampleStopped = TRUE;
}
nCruising = 0;
@@ -1910,7 +1912,7 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams& params, CVehicle* veh
if (engineSoundType == SFX_BANK_TRUCK)
freq /= 2;
if (channelUsed) {
- SampleManager.StopChannel(m_nActiveSamples);
+ SampleManager.StopChannel(CHANNEL_PLAYER_VEHICLE_ENGINE);
bAccelSampleStopped = TRUE;
}
if (params.m_pVehicle->bIsDrowning)
@@ -1925,55 +1927,55 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams& params, CVehicle* veh
bAccelSampleStopped = FALSE;
}
if (channelUsed) {
- SampleManager.SetChannelEmittingVolume(m_nActiveSamples, 120);
- SampleManager.SetChannel3DPosition(m_nActiveSamples, pos.x, pos.y, pos.z);
- SampleManager.SetChannel3DDistances(m_nActiveSamples, 50.0f, 12.5f);
+ SampleManager.SetChannelEmittingVolume(CHANNEL_PLAYER_VEHICLE_ENGINE, 120);
+ SampleManager.SetChannel3DPosition(CHANNEL_PLAYER_VEHICLE_ENGINE, pos.x, pos.y, pos.z);
+ SampleManager.SetChannel3DDistances(CHANNEL_PLAYER_VEHICLE_ENGINE, 50.0f, 12.5f);
freq = (GearFreqAdj[CurrentPretendGear] + freqModifier + 22050) ;
if (engineSoundType == SFX_BANK_TRUCK)
freq /= 2;
- SampleManager.SetChannelFrequency(m_nActiveSamples, freq);
+ SampleManager.SetChannelFrequency(CHANNEL_PLAYER_VEHICLE_ENGINE, freq);
if (!channelUsed) {
- SampleManager.SetChannelReverbFlag(m_nActiveSamples, m_bDynamicAcousticModelingStatus != FALSE);
- SampleManager.StartChannel(m_nActiveSamples);
+ SampleManager.SetChannelReverbFlag(CHANNEL_PLAYER_VEHICLE_ENGINE, m_bDynamicAcousticModelingStatus != FALSE);
+ SampleManager.StartChannel(CHANNEL_PLAYER_VEHICLE_ENGINE);
}
} else if (processedAccelSampleStopped) {
gearSoundStartTime = CTimer::GetTimeInMilliseconds();
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;
- SampleManager.SetChannelLoopCount(m_nActiveSamples, 1);
- SampleManager.SetChannelLoopPoints(m_nActiveSamples, 0, -1);
+ SampleManager.SetChannelLoopCount(CHANNEL_PLAYER_VEHICLE_ENGINE, 1);
+ SampleManager.SetChannelLoopPoints(CHANNEL_PLAYER_VEHICLE_ENGINE, 0, -1);
- SampleManager.SetChannelEmittingVolume(m_nActiveSamples, 120);
- SampleManager.SetChannel3DPosition(m_nActiveSamples, pos.x, pos.y, pos.z);
- SampleManager.SetChannel3DDistances(m_nActiveSamples, 50.0f, 12.5f);
+ SampleManager.SetChannelEmittingVolume(CHANNEL_PLAYER_VEHICLE_ENGINE, 120);
+ SampleManager.SetChannel3DPosition(CHANNEL_PLAYER_VEHICLE_ENGINE, pos.x, pos.y, pos.z);
+ SampleManager.SetChannel3DDistances(CHANNEL_PLAYER_VEHICLE_ENGINE, 50.0f, 12.5f);
freq = (GearFreqAdj[CurrentPretendGear] + freqModifier + 22050);
if (engineSoundType == SFX_BANK_TRUCK)
freq /= 2;
- SampleManager.SetChannelFrequency(m_nActiveSamples, freq);
+ SampleManager.SetChannelFrequency(CHANNEL_PLAYER_VEHICLE_ENGINE, freq);
if (!channelUsed) {
- SampleManager.SetChannelReverbFlag(m_nActiveSamples, m_bDynamicAcousticModelingStatus != FALSE);
- SampleManager.StartChannel(m_nActiveSamples);
+ SampleManager.SetChannelReverbFlag(CHANNEL_PLAYER_VEHICLE_ENGINE, m_bDynamicAcousticModelingStatus != FALSE);
+ SampleManager.StartChannel(CHANNEL_PLAYER_VEHICLE_ENGINE);
}
} else if (CurrentPretendGear < params.m_pTransmission->nNumberOfGears - 1) {
++CurrentPretendGear;
gearSoundStartTime = CTimer::GetTimeInMilliseconds();
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;
- SampleManager.SetChannelLoopCount(m_nActiveSamples, 1);
- SampleManager.SetChannelLoopPoints(m_nActiveSamples, 0, -1);
+ SampleManager.SetChannelLoopCount(CHANNEL_PLAYER_VEHICLE_ENGINE, 1);
+ SampleManager.SetChannelLoopPoints(CHANNEL_PLAYER_VEHICLE_ENGINE, 0, -1);
- SampleManager.SetChannelEmittingVolume(m_nActiveSamples, 120);
- SampleManager.SetChannel3DPosition(m_nActiveSamples, pos.x, pos.y, pos.z);
- SampleManager.SetChannel3DDistances(m_nActiveSamples, 50.0f, 12.5f);
+ SampleManager.SetChannelEmittingVolume(CHANNEL_PLAYER_VEHICLE_ENGINE, 120);
+ SampleManager.SetChannel3DPosition(CHANNEL_PLAYER_VEHICLE_ENGINE, pos.x, pos.y, pos.z);
+ SampleManager.SetChannel3DDistances(CHANNEL_PLAYER_VEHICLE_ENGINE, 50.0f, 12.5f);
freq = (GearFreqAdj[CurrentPretendGear] + freqModifier + 22050);
if (engineSoundType == SFX_BANK_TRUCK)
freq /= 2;
- SampleManager.SetChannelFrequency(m_nActiveSamples, freq);
+ SampleManager.SetChannelFrequency(CHANNEL_PLAYER_VEHICLE_ENGINE, freq);
if (!channelUsed) {
- SampleManager.SetChannelReverbFlag(m_nActiveSamples, m_bDynamicAcousticModelingStatus != FALSE);
- SampleManager.StartChannel(m_nActiveSamples);
+ SampleManager.SetChannelReverbFlag(CHANNEL_PLAYER_VEHICLE_ENGINE, m_bDynamicAcousticModelingStatus != FALSE);
+ SampleManager.StartChannel(CHANNEL_PLAYER_VEHICLE_ENGINE);
}
} else {
nCruising = 1;
@@ -1983,7 +1985,7 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams& params, CVehicle* veh
} else {
PlayCruising:
bAccelSampleStopped = TRUE;
- SampleManager.StopChannel(m_nActiveSamples);
+ SampleManager.StopChannel(CHANNEL_PLAYER_VEHICLE_ENGINE);
if (isMoped || accelerateState >= 150 && wheelsOnGround && brakeState <= 0 && !params.m_pVehicle->bIsHandbrakeOn
&& !lostTraction && currentGear >= params.m_pTransmission->nNumberOfGears - 1) {
if (accelerateState >= 220 && params.m_fVelocityChange + 0.001f >= velocityChangeForAudio) {
diff --git a/src/audio/AudioManager.cpp b/src/audio/AudioManager.cpp
index 3be053d2..e56d28e1 100644
--- a/src/audio/AudioManager.cpp
+++ b/src/audio/AudioManager.cpp
@@ -14,10 +14,6 @@
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 TIME_SPENT 40
@@ -28,7 +24,7 @@ cAudioManager::cAudioManager()
field_6 = 0;
m_fSpeedOfSound = SPEED_OF_SOUND / TIME_SPENT;
m_nTimeSpent = TIME_SPENT;
- m_nActiveSamples = NUM_SOUNDS_SAMPLES_SLOTS;
+ m_nActiveSamples = NUM_CHANNELS_GENERIC;
m_nActiveSampleQueue = 1;
ClearRequestedQueue();
m_nActiveSampleQueue = 0;
@@ -276,7 +272,7 @@ cAudioManager::ResetTimers(uint32 time)
ClearActiveSamples();
ClearMissionAudio(0);
ClearMissionAudio(1);
- SampleManager.StopChannel(policeChannel);
+ SampleManager.StopChannel(CHANNEL_POLICE_RADIO);
SampleManager.SetEffectsFadeVolume(0);
SampleManager.SetMusicFadeVolume(0);
MusicManager.ResetMusicAfterReload();
@@ -446,7 +442,7 @@ cAudioManager::ServiceSoundEffects()
{
m_bFifthFrameFlag = (m_FrameCounter++ % 5) == 0;
if (m_nUserPause && !m_nPreviousUserPause) {
- for (int32 i = 0; i < allChannels; i++)
+ for (int32 i = 0; i < NUM_CHANNELS; i++)
SampleManager.StopChannel(i);
ClearRequestedQueue();
@@ -773,7 +769,12 @@ cAudioManager::UpdateReflections()
void
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;
diff --git a/src/audio/AudioManager.h b/src/audio/AudioManager.h
index 49535252..d5b3ce15 100644
--- a/src/audio/AudioManager.h
+++ b/src/audio/AudioManager.h
@@ -205,10 +205,10 @@ public:
int32 m_nTimer;
tSound m_sQueueSample;
uint8 m_nActiveSampleQueue;
- tSound m_asSamples[NUM_SOUNDS_SAMPLES_BANKS][NUM_SOUNDS_SAMPLES_SLOTS];
- uint8 m_abSampleQueueIndexTable[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_CHANNELS_GENERIC];
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];
int32 m_anAudioEntityIndices[NUM_AUDIOENTITIES];
int32 m_nAudioEntitiesTotal;
@@ -544,7 +544,7 @@ public:
#endif
};
-#ifdef AUDIO_MSS
+#if defined(AUDIO_MSS) && !defined(PS2_AUDIO_CHANNELS)
static_assert(sizeof(cAudioManager) == 0x5558, "cAudioManager: error");
#endif
diff --git a/src/audio/PolRadio.cpp b/src/audio/PolRadio.cpp
index cf92bb95..82f44dee 100644
--- a/src/audio/PolRadio.cpp
+++ b/src/audio/PolRadio.cpp
@@ -15,9 +15,6 @@
#include "sampman.h"
#include "Wanted.h"
-const int channels = ARRAY_SIZE(AudioManager.m_asActiveSamples);
-const int policeChannel = channels + 1;
-
struct tPoliceRadioZone {
char m_aName[8];
uint32 m_nSampleIndex;
@@ -68,7 +65,7 @@ cAudioManager::InitialisePoliceRadio()
for (int32 i = 0; i < ARRAY_SIZE(m_sPoliceRadioQueue.crimes); i++)
m_sPoliceRadioQueue.crimes[i].type = CRIME_NONE;
- SampleManager.SetChannelReverbFlag(policeChannel, FALSE);
+ SampleManager.SetChannelReverbFlag(CHANNEL_POLICE_RADIO, FALSE);
gSpecialSuspectLastSeenReport = FALSE;
for (int32 i = 0; i < ARRAY_SIZE(gMinTimeToNextReport); i++)
gMinTimeToNextReport[i] = m_FrameCounter;
@@ -78,7 +75,7 @@ void
cAudioManager::ResetPoliceRadio()
{
if (!m_bIsInitialised) return;
- if (SampleManager.GetChannelUsedFlag(policeChannel)) SampleManager.StopChannel(policeChannel);
+ if (SampleManager.GetChannelUsedFlag(CHANNEL_POLICE_RADIO)) SampleManager.StopChannel(CHANNEL_POLICE_RADIO);
InitialisePoliceRadio();
}
@@ -168,7 +165,7 @@ cAudioManager::ServicePoliceRadioChannel(uint8 wantedLevel)
if (!m_bIsInitialised) return;
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 &&
SampleManager.IsStreamPlaying(1)) {
SampleManager.PauseStream(TRUE, 1);
@@ -200,7 +197,7 @@ cAudioManager::ServicePoliceRadioChannel(uint8 wantedLevel)
}
return;
}
- } else if (!SampleManager.GetChannelUsedFlag(policeChannel)) {
+ } else if (!SampleManager.GetChannelUsedFlag(CHANNEL_POLICE_RADIO)) {
SampleManager.PreloadStreamedFile(g_nMissionAudioSfx, 1);
SampleManager.SetStreamedVolumeAndPan(MAX_VOLUME, 63, TRUE, 1);
SampleManager.StartPreloadedStreamedFile(1);
@@ -211,7 +208,7 @@ cAudioManager::ServicePoliceRadioChannel(uint8 wantedLevel)
}
if (bChannelOpen) DoPoliceRadioCrackle();
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) {
sample = m_sPoliceRadioQueue.crimesSamples[m_sPoliceRadioQueue.policeChannelCounterSeconds];
m_sPoliceRadioQueue.policeChannelTimer--;
@@ -230,7 +227,7 @@ cAudioManager::ServicePoliceRadioChannel(uint8 wantedLevel)
if (sample == NO_SAMPLE) {
if (!processed) cWait = 30;
} else {
- SampleManager.InitialiseChannel(policeChannel, sample, 0);
+ SampleManager.InitialiseChannel(CHANNEL_POLICE_RADIO, sample, 0);
switch (sample) {
case SFX_POLICE_RADIO_MESSAGE_NOISE_1:
freq = m_anRandomTable[4] % 2000 + 10025;
@@ -239,12 +236,12 @@ cAudioManager::ServicePoliceRadioChannel(uint8 wantedLevel)
default: freq = SampleManager.GetSampleBaseFrequency(sample); break;
}
PoliceChannelFreq = freq;
- SampleManager.SetChannelFrequency(policeChannel, freq);
- SampleManager.SetChannelVolume(policeChannel, 100);
- SampleManager.SetChannelPan(policeChannel, 63);
- SampleManager.SetChannelLoopCount(policeChannel, 1);
- SampleManager.SetChannelLoopPoints(policeChannel, 0, -1);
- SampleManager.StartChannel(policeChannel);
+ SampleManager.SetChannelFrequency(CHANNEL_POLICE_RADIO, freq);
+ SampleManager.SetChannelVolume(CHANNEL_POLICE_RADIO, 100);
+ SampleManager.SetChannelPan(CHANNEL_POLICE_RADIO, 63);
+ SampleManager.SetChannelLoopCount(CHANNEL_POLICE_RADIO, 1);
+ SampleManager.SetChannelLoopPoints(CHANNEL_POLICE_RADIO, 0, -1);
+ SampleManager.StartChannel(CHANNEL_POLICE_RADIO);
}
if (processed) ResetPoliceRadio();
}
diff --git a/src/audio/audio_enums.h b/src/audio/audio_enums.h
index 990b2d73..5a14d312 100644
--- a/src/audio/audio_enums.h
+++ b/src/audio/audio_enums.h
@@ -1295,3 +1295,26 @@ enum eAudioType
AUDIOTYPE_POLICERADIO,
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
diff --git a/src/audio/oal/channel.cpp b/src/audio/oal/channel.cpp
index 1bb4c4a8..04e7e529 100644
--- a/src/audio/oal/channel.cpp
+++ b/src/audio/oal/channel.cpp
@@ -10,9 +10,9 @@
extern bool IsFXSupported();
-ALuint alSources[MAXCHANNELS+MAX2DCHANNELS];
-ALuint alFilters[MAXCHANNELS+MAX2DCHANNELS];
-ALuint alBuffers[MAXCHANNELS+MAX2DCHANNELS];
+ALuint alSources[NUM_CHANNELS];
+ALuint alFilters[NUM_CHANNELS];
+ALuint alBuffers[NUM_CHANNELS];
bool bChannelsCreated = false;
int32 CChannel::channelsThatNeedService = 0;
@@ -22,10 +22,10 @@ uint8 tempStereoBuffer[PED_BLOCKSIZE * 2];
void
CChannel::InitChannels()
{
- alGenSources(MAXCHANNELS+MAX2DCHANNELS, alSources);
- alGenBuffers(MAXCHANNELS+MAX2DCHANNELS, alBuffers);
+ alGenSources(NUM_CHANNELS, alSources);
+ alGenBuffers(NUM_CHANNELS, alBuffers);
if (IsFXSupported())
- alGenFilters(MAXCHANNELS + MAX2DCHANNELS, alFilters);
+ alGenFilters(NUM_CHANNELS, alFilters);
bChannelsCreated = true;
}
@@ -34,13 +34,13 @@ CChannel::DestroyChannels()
{
if (bChannelsCreated)
{
- alDeleteSources(MAXCHANNELS + MAX2DCHANNELS, alSources);
+ alDeleteSources(NUM_CHANNELS, alSources);
memset(alSources, 0, sizeof(alSources));
- alDeleteBuffers(MAXCHANNELS + MAX2DCHANNELS, alBuffers);
+ alDeleteBuffers(NUM_CHANNELS, alBuffers);
memset(alBuffers, 0, sizeof(alBuffers));
if (IsFXSupported())
{
- alDeleteFilters(MAXCHANNELS + MAX2DCHANNELS, alFilters);
+ alDeleteFilters(NUM_CHANNELS, alFilters);
memset(alFilters, 0, sizeof(alFilters));
}
bChannelsCreated = false;
diff --git a/src/audio/sampman.h b/src/audio/sampman.h
index 7c60080d..d6fc5cc0 100644
--- a/src/audio/sampman.h
+++ b/src/audio/sampman.h
@@ -1,5 +1,6 @@
#pragma once
#include "AudioSamples.h"
+#include "audio_enums.h"
#define MAX_VOLUME 127
#define MAX_FREQ DIGITALRATE
@@ -115,10 +116,9 @@ enum
#define MAXPROVIDERS 64
-#define MAXCHANNELS 28
-#define MAXCHANNELS_SURROUND 24
+#define MAXCHANNELS (NUM_CHANNELS_GENERIC+1)
+#define MAXCHANNELS_SURROUND (MAXCHANNELS-4)
#define MAX2DCHANNELS 1
-#define CHANNEL2D MAXCHANNELS
#define MAX_STREAMS 3
@@ -126,7 +126,13 @@ enum
#define DIGITALBITS 16
#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" );
class cSampleManager
{
diff --git a/src/audio/sampman_miles.cpp b/src/audio/sampman_miles.cpp
index a6f04775..558be334 100644
--- a/src/audio/sampman_miles.cpp
+++ b/src/audio/sampman_miles.cpp
@@ -1694,7 +1694,7 @@ cSampleManager::SetChannelReverbFlag(uint32 nChannel, bool8 nReverbFlag)
switch ( nChannel )
{
- case CHANNEL2D:
+ case CHANNEL_POLICE_RADIO:
{
b2d = TRUE;
break;
@@ -1723,7 +1723,7 @@ cSampleManager::InitialiseChannel(uint32 nChannel, uint32 nSfx, uint8 nBank)
switch ( nChannel )
{
- case CHANNEL2D:
+ case CHANNEL_POLICE_RADIO:
{
b2d = TRUE;
break;
@@ -1823,7 +1823,7 @@ cSampleManager::SetChannelVolume(uint32 nChannel, uint32 nVolume)
switch ( nChannel )
{
- case CHANNEL2D:
+ case CHANNEL_POLICE_RADIO:
{
nChannelVolume[nChannel] = vol;
@@ -1850,7 +1850,7 @@ cSampleManager::SetChannelPan(uint32 nChannel, uint32 nPan)
{
switch ( nChannel )
{
- case CHANNEL2D:
+ case CHANNEL_POLICE_RADIO:
{
#ifndef FIX_BUGS
if ( opened_samples[nChannel - MAXCHANNELS] ) // BUG
@@ -1871,7 +1871,7 @@ cSampleManager::SetChannelFrequency(uint32 nChannel, uint32 nFreq)
switch ( nChannel )
{
- case CHANNEL2D:
+ case CHANNEL_POLICE_RADIO:
{
b2d = TRUE;
break;
@@ -1897,7 +1897,7 @@ cSampleManager::SetChannelLoopPoints(uint32 nChannel, uint32 nLoopStart, int32 n
switch ( nChannel )
{
- case CHANNEL2D:
+ case CHANNEL_POLICE_RADIO:
{
b2d = TRUE;
break;
@@ -1923,7 +1923,7 @@ cSampleManager::SetChannelLoopCount(uint32 nChannel, uint32 nLoopCount)
switch ( nChannel )
{
- case CHANNEL2D:
+ case CHANNEL_POLICE_RADIO:
{
b2d = TRUE;
break;
@@ -1949,7 +1949,7 @@ cSampleManager::GetChannelUsedFlag(uint32 nChannel)
switch ( nChannel )
{
- case CHANNEL2D:
+ case CHANNEL_POLICE_RADIO:
{
b2d = TRUE;
break;
@@ -1980,7 +1980,7 @@ cSampleManager::StartChannel(uint32 nChannel)
switch ( nChannel )
{
- case CHANNEL2D:
+ case CHANNEL_POLICE_RADIO:
{
b2d = TRUE;
break;
@@ -2006,7 +2006,7 @@ cSampleManager::StopChannel(uint32 nChannel)
switch ( nChannel )
{
- case CHANNEL2D:
+ case CHANNEL_POLICE_RADIO:
{
b2d = TRUE;
break;
diff --git a/src/audio/sampman_oal.cpp b/src/audio/sampman_oal.cpp
index e74fac82..a4c92482 100644
--- a/src/audio/sampman_oal.cpp
+++ b/src/audio/sampman_oal.cpp
@@ -94,8 +94,8 @@ int32 nPedSlotSfx [MAX_PEDSFX];
int32 nPedSlotSfxAddr[MAX_PEDSFX];
uint8 nCurrentPedSlot;
-CChannel aChannel[MAXCHANNELS+MAX2DCHANNELS];
-uint8 nChannelVolume[MAXCHANNELS+MAX2DCHANNELS];
+CChannel aChannel[NUM_CHANNELS];
+uint8 nChannelVolume[NUM_CHANNELS];
uint32 nStreamLength[TOTAL_STREAMED_SOUNDS];
ALuint ALStreamSources[MAX_STREAMS][2];
@@ -213,9 +213,8 @@ add_providers()
static void
release_existing()
{
- for ( int32 i = 0; i < MAXCHANNELS; i++ )
+ for ( int32 i = 0; i < NUM_CHANNELS; i++ )
aChannel[i].Term();
- aChannel[CHANNEL2D].Term();
if ( IsFXSupported() )
{
@@ -284,7 +283,8 @@ set_new_provider(int index)
_maxSamples = MAXCHANNELS;
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,
};
@@ -370,8 +370,9 @@ set_new_provider(int index)
CChannel::InitChannels();
for ( int32 i = 0; i < MAXCHANNELS; i++ )
- aChannel[i].Init(i);
- aChannel[CHANNEL2D].Init(CHANNEL2D, true);
+ aChannel[i].Init(i);
+ for ( int32 i = 0; i < MAX2DCHANNELS; i++ )
+ aChannel[MAXCHANNELS+i].Init(MAXCHANNELS+i, true);
if ( IsFXSupported() )
{
@@ -978,7 +979,7 @@ cSampleManager::Initialise(void)
}
{
- for ( int32 i = 0; i < MAXCHANNELS+MAX2DCHANNELS; i++ )
+ for ( int32 i = 0; i < NUM_CHANNELS; i++ )
nChannelVolume[i] = 0;
}
@@ -1184,7 +1185,7 @@ cSampleManager::UpdateEffectsVolume(void)
{
if ( _bSampmanInitialised )
{
- for ( int32 i = 0; i < MAXCHANNELS+MAX2DCHANNELS; i++ )
+ for ( int32 i = 0; i < NUM_CHANNELS; i++ )
{
if ( GetChannelUsedFlag(i) )
{
@@ -1492,7 +1493,7 @@ bool8 cSampleManager::UpdateReverb(void)
void
cSampleManager::SetChannelReverbFlag(uint32 nChannel, bool8 nReverbFlag)
{
- ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS );
+ ASSERT( nChannel < NUM_CHANNELS );
if ( usingEAX || _usingEFX )
{
@@ -1511,7 +1512,7 @@ cSampleManager::SetChannelReverbFlag(uint32 nChannel, bool8 nReverbFlag)
bool8
cSampleManager::InitialiseChannel(uint32 nChannel, uint32 nSfx, uint8 nBank)
{
- ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS );
+ ASSERT( nChannel < NUM_CHANNELS );
uintptr addr;
@@ -1552,8 +1553,7 @@ cSampleManager::InitialiseChannel(uint32 nChannel, uint32 nSfx, uint8 nBank)
void
cSampleManager::SetChannelEmittingVolume(uint32 nChannel, uint32 nVolume)
{
- ASSERT( nChannel != CHANNEL2D );
- ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS );
+ ASSERT( nChannel < MAXCHANNELS );
uint32 vol = nVolume;
if ( vol > MAX_VOLUME ) vol = MAX_VOLUME;
@@ -1574,8 +1574,7 @@ cSampleManager::SetChannelEmittingVolume(uint32 nChannel, uint32 nVolume)
void
cSampleManager::SetChannel3DPosition(uint32 nChannel, float fX, float fY, float fZ)
{
- ASSERT( nChannel != CHANNEL2D );
- ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS );
+ ASSERT( nChannel < MAXCHANNELS );
aChannel[nChannel].SetPosition(-fX, fY, fZ);
}
@@ -1583,18 +1582,17 @@ cSampleManager::SetChannel3DPosition(uint32 nChannel, float fX, float fY, float
void
cSampleManager::SetChannel3DDistances(uint32 nChannel, float fMax, float fMin)
{
- ASSERT( nChannel != CHANNEL2D );
- ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS );
+ ASSERT( nChannel < MAXCHANNELS );
aChannel[nChannel].SetDistances(fMax, fMin);
}
void
cSampleManager::SetChannelVolume(uint32 nChannel, uint32 nVolume)
{
- ASSERT( nChannel == CHANNEL2D );
- ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS );
+ ASSERT( nChannel >= MAXCHANNELS );
+ ASSERT( nChannel < NUM_CHANNELS );
- if ( nChannel == CHANNEL2D )
+ if ( nChannel == CHANNEL_POLICE_RADIO )
{
uint32 vol = nVolume;
if ( vol > MAX_VOLUME ) vol = MAX_VOLUME;
@@ -1616,10 +1614,10 @@ cSampleManager::SetChannelVolume(uint32 nChannel, uint32 nVolume)
void
cSampleManager::SetChannelPan(uint32 nChannel, uint32 nPan)
{
- ASSERT(nChannel == CHANNEL2D);
- ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS );
+ ASSERT( nChannel >= MAXCHANNELS );
+ ASSERT( nChannel < NUM_CHANNELS );
- if ( nChannel == CHANNEL2D )
+ if ( nChannel == CHANNEL_POLICE_RADIO )
{
aChannel[nChannel].SetPan(nPan);
}
@@ -1628,7 +1626,7 @@ cSampleManager::SetChannelPan(uint32 nChannel, uint32 nPan)
void
cSampleManager::SetChannelFrequency(uint32 nChannel, uint32 nFreq)
{
- ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS );
+ ASSERT( nChannel < NUM_CHANNELS );
aChannel[nChannel].SetCurrentFreq(nFreq);
}
@@ -1636,7 +1634,7 @@ cSampleManager::SetChannelFrequency(uint32 nChannel, uint32 nFreq)
void
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));
}
@@ -1644,7 +1642,7 @@ cSampleManager::SetChannelLoopPoints(uint32 nChannel, uint32 nLoopStart, int32 n
void
cSampleManager::SetChannelLoopCount(uint32 nChannel, uint32 nLoopCount)
{
- ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS );
+ ASSERT( nChannel < NUM_CHANNELS );
aChannel[nChannel].SetLoopCount(nLoopCount);
}
@@ -1652,7 +1650,7 @@ cSampleManager::SetChannelLoopCount(uint32 nChannel, uint32 nLoopCount)
bool8
cSampleManager::GetChannelUsedFlag(uint32 nChannel)
{
- ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS );
+ ASSERT( nChannel < NUM_CHANNELS );
return aChannel[nChannel].IsUsed();
}
@@ -1660,7 +1658,7 @@ cSampleManager::GetChannelUsedFlag(uint32 nChannel)
void
cSampleManager::StartChannel(uint32 nChannel)
{
- ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS );
+ ASSERT( nChannel < NUM_CHANNELS );
aChannel[nChannel].Start();
}
@@ -1668,7 +1666,7 @@ cSampleManager::StartChannel(uint32 nChannel)
void
cSampleManager::StopChannel(uint32 nChannel)
{
- ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS );
+ ASSERT( nChannel < NUM_CHANNELS );
aChannel[nChannel].Stop();
}
@@ -2007,7 +2005,7 @@ cSampleManager::Service(void)
stream->Update();
}
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() )
refCount--;