summaryrefslogtreecommitdiffstats
path: root/src/audio
diff options
context:
space:
mode:
authorSergeanur <s.anureev@yandex.ua>2020-04-26 21:03:15 +0200
committerSergeanur <s.anureev@yandex.ua>2020-04-26 21:03:15 +0200
commitf0890b11122291a22d6a65f349281cf1aed49bd0 (patch)
tree3b418b522c5fd097abac916693e59808ea4f5b4f /src/audio
parentMore japanese (diff)
parentRemove little hack (diff)
downloadre3-f0890b11122291a22d6a65f349281cf1aed49bd0.tar
re3-f0890b11122291a22d6a65f349281cf1aed49bd0.tar.gz
re3-f0890b11122291a22d6a65f349281cf1aed49bd0.tar.bz2
re3-f0890b11122291a22d6a65f349281cf1aed49bd0.tar.lz
re3-f0890b11122291a22d6a65f349281cf1aed49bd0.tar.xz
re3-f0890b11122291a22d6a65f349281cf1aed49bd0.tar.zst
re3-f0890b11122291a22d6a65f349281cf1aed49bd0.zip
Diffstat (limited to 'src/audio')
-rw-r--r--src/audio/AudioCollision.cpp15
-rw-r--r--src/audio/AudioManager.cpp319
-rw-r--r--src/audio/AudioManager.h41
-rw-r--r--src/audio/AudioScriptObject.cpp9
-rw-r--r--src/audio/DMAudio.cpp58
-rw-r--r--src/audio/DMAudio.h4
-rw-r--r--src/audio/MusicManager.cpp49
-rw-r--r--src/audio/MusicManager.h2
-rw-r--r--src/audio/PoliceRadio.cpp44
-rw-r--r--src/audio/miles/sampman_mss.cpp2257
-rw-r--r--src/audio/miles/sampman_mss.h339
-rw-r--r--src/audio/openal/samp_oal.cpp1404
-rw-r--r--src/audio/openal/samp_oal.h340
-rw-r--r--src/audio/sampman.cpp2339
-rw-r--r--src/audio/sampman.h342
15 files changed, 4446 insertions, 3116 deletions
diff --git a/src/audio/AudioCollision.cpp b/src/audio/AudioCollision.cpp
index fecd079e..a963b293 100644
--- a/src/audio/AudioCollision.cpp
+++ b/src/audio/AudioCollision.cpp
@@ -1,5 +1,5 @@
#include "common.h"
-#include "patcher.h"
+
#include "DMAudio.h"
#include "Entity.h"
#include "AudioCollision.h"
@@ -226,7 +226,7 @@ cAudioManager::SetUpOneShotCollisionSound(cAudioCollision *col)
if(s1 == SURFACE_METAL6 && s2 == SURFACE_FLESH) ratio = 0.25f * ratio;
if(s1 == SURFACE_METAL6 && ratio < 0.6f) {
s1 = SURFACE_BILLBOARD;
- ratio = min(1.f, 2.f * ratio);
+ ratio = Min(1.f, 2.f * ratio);
}
emittingVol = 40.f * ratio;
if(emittingVol) {
@@ -406,14 +406,3 @@ cAudioManager::ReportCollision(CEntity *entity1, CEntity *entity2, uint8 surface
m_sCollisionManager.AddCollisionToRequestedQueue();
}
}
-
-STARTPATCHES
-InjectHook(0x5685E0, &cAudioCollisionManager::AddCollisionToRequestedQueue, PATCH_JUMP);
-InjectHook(0x569060, &cAudioManager::GetCollisionOneShotRatio, PATCH_JUMP);
-InjectHook(0x5693B0, &cAudioManager::GetCollisionRatio, PATCH_JUMP);
-InjectHook(0x568410, &cAudioManager::ReportCollision, PATCH_JUMP);
-InjectHook(0x5686D0, &cAudioManager::ServiceCollisions, PATCH_JUMP);
-InjectHook(0x568E20, &cAudioManager::SetLoopingCollisionRequestedSfxFreqAndGetVol, PATCH_JUMP);
-InjectHook(0x568D30, &cAudioManager::SetUpLoopingCollisionSound, PATCH_JUMP);
-InjectHook(0x5689D0, &cAudioManager::SetUpOneShotCollisionSound, PATCH_JUMP);
-ENDPATCHES
diff --git a/src/audio/AudioManager.cpp b/src/audio/AudioManager.cpp
index 1d2835cf..0c4b007f 100644
--- a/src/audio/AudioManager.cpp
+++ b/src/audio/AudioManager.cpp
@@ -1,5 +1,5 @@
-#include "common.h"
-#include "patcher.h"
+#include "common.h"
+
#include "audio_enums.h"
#include "AudioManager.h"
@@ -40,18 +40,18 @@
#include "sampman.h"
cAudioManager AudioManager;
-uint32 gPornNextTime; // = *(uint32*)0x6508A0;
-uint32 gSawMillNextTime; // = *(uint32*)0x6508A4;
-uint32 gShopNextTime; // = *(uint32*)0x6508A8;
-uint32 gAirportNextTime; // = *(uint32*)0x6508AC;
-uint32 gCinemaNextTime; //= *(uint32*)0x6508B0;
-uint32 gDocksNextTime; // = *(uint32*)0x6508B4;
-uint32 gHomeNextTime; // = *(uint32*)0x6508B8;
-uint32 gCellNextTime; // = *(uint32*)0x6508BC;
-uint32 gNextCryTime; // = *(uint32*)0x6508C0;
-uint8 gJumboVolOffsetPercentage; // = *(uint8 *)0x6508ED;
-bool bPlayerJustEnteredCar; // = *(bool *)0x6508C4;
-bool g_bMissionAudioLoadFailed; // = *(bool *)0x95CD8E;
+uint32 gPornNextTime;
+uint32 gSawMillNextTime;
+uint32 gShopNextTime;
+uint32 gAirportNextTime;
+uint32 gCinemaNextTime;
+uint32 gDocksNextTime;
+uint32 gHomeNextTime;
+uint32 gCellNextTime;
+uint32 gNextCryTime;
+uint8 gJumboVolOffsetPercentage;
+bool bPlayerJustEnteredCar;
+bool g_bMissionAudioLoadFailed;
const int channels = ARRAY_SIZE(cAudioManager::m_asActiveSamples);
const int policeChannel = channels + 1;
@@ -635,9 +635,9 @@ cAudioManager::ComputeDopplerEffectedFrequency(uint32 oldFreq, float position1,
float speedOfSource = (dist / m_bTimeSpent) * speedMultiplier;
if(m_fSpeedOfSound > Abs(speedOfSource)) {
if(speedOfSource < 0.0f) {
- speedOfSource = max(speedOfSource, -1.5f);
+ speedOfSource = Max(speedOfSource, -1.5f);
} else {
- speedOfSource = min(speedOfSource, 1.5f);
+ speedOfSource = Min(speedOfSource, 1.5f);
}
newFreq =
(oldFreq * m_fSpeedOfSound) / (speedOfSource + m_fSpeedOfSound);
@@ -650,10 +650,10 @@ cAudioManager::ComputeDopplerEffectedFrequency(uint32 oldFreq, float position1,
int32
cAudioManager::ComputePan(float dist, CVector *vec)
{
- int32 index = min(63, Abs(vec->x / (dist / 64.f)));
+ int32 index = Min(63, Abs(vec->x / (dist / 64.f)));
- if(vec->x > 0.f) return max(20, 63 - panTable[index]);
- return min(107, panTable[index] + 63);
+ if(vec->x > 0.f) return Max(20, 63 - panTable[index]);
+ return Min(107, panTable[index] + 63);
}
uint8
@@ -2894,7 +2894,7 @@ cAudioManager::GetVehicleDriveWheelSkidValue(uint8 wheel, CAutomobile *automobil
relativeVelChange = (gasPedalAudio - 0.4f) * 1.25f;
} else if(wheelState == WHEEL_STATE_SKIDDING) {
- relativeVelChange = min(1.0f, Abs(velocityChange) / transmission->fMaxVelocity);
+ relativeVelChange = Min(1.0f, Abs(velocityChange) / transmission->fMaxVelocity);
} else if(wheelState == WHEEL_STATE_FIXED) {
modificator = 0.4f;
relativeVelChange = gasPedalAudio;
@@ -2905,7 +2905,7 @@ cAudioManager::GetVehicleDriveWheelSkidValue(uint8 wheel, CAutomobile *automobil
velChange = Abs(velocityChange);
if(relativeVelChange > 0.4f) relativeVelChange = relativeVelChange * modificator;
if(velChange > 0.04f) {
- relativeVel = min(1.0f, velChange / transmission->fMaxVelocity);
+ relativeVel = Min(1.0f, velChange / transmission->fMaxVelocity);
} else {
relativeVel = 0.0f;
}
@@ -2914,7 +2914,7 @@ cAudioManager::GetVehicleDriveWheelSkidValue(uint8 wheel, CAutomobile *automobil
relativeVelChange = 0.0f;
}
- return max(relativeVelChange, min(1.0f, Abs(automobile->m_vecTurnSpeed.z) * 20.0f));
+ return Max(relativeVelChange, Min(1.0f, Abs(automobile->m_vecTurnSpeed.z) * 20.0f));
}
float
@@ -2924,12 +2924,12 @@ cAudioManager::GetVehicleNonDriveWheelSkidValue(uint8 wheel, CAutomobile *automo
float relativeVelChange;
if(automobile->m_aWheelState[wheel] == 2) {
- relativeVelChange = min(1.0f, Abs(velocityChange) / transmission->fMaxVelocity);
+ relativeVelChange = Min(1.0f, Abs(velocityChange) / transmission->fMaxVelocity);
} else {
relativeVelChange = 0.0f;
}
- return max(relativeVelChange, min(1.0f, Abs(automobile->m_vecTurnSpeed.z) * 20.0f));
+ return Max(relativeVelChange, Min(1.0f, Abs(automobile->m_vecTurnSpeed.z) * 20.0f));
}
bool
@@ -3326,7 +3326,7 @@ cAudioManager::ProcessActiveQueues()
if(field_4) {
emittingVol =
2 *
- min(63,
+ Min(63,
sample.m_bEmittingVolume);
} else {
emittingVol =
@@ -3353,13 +3353,13 @@ cAudioManager::ProcessActiveQueues()
if(sample.m_nFrequency <=
m_asActiveSamples[j]
.m_nFrequency) {
- freq = max(
+ freq = Max(
sample.m_nFrequency,
m_asActiveSamples[j]
.m_nFrequency -
6000);
} else {
- freq = min(
+ freq = Min(
sample.m_nFrequency,
m_asActiveSamples[j]
.m_nFrequency +
@@ -3376,14 +3376,14 @@ cAudioManager::ProcessActiveQueues()
if(sample.m_bEmittingVolume <=
m_asActiveSamples[j]
.m_bEmittingVolume) {
- vol = max(
+ vol = Max(
m_asActiveSamples[j]
.m_bEmittingVolume -
10,
sample
.m_bEmittingVolume);
} else {
- vol = min(
+ vol = Min(
m_asActiveSamples[j]
.m_bEmittingVolume +
10,
@@ -3394,7 +3394,7 @@ cAudioManager::ProcessActiveQueues()
uint8 emittingVol;
if(field_4) {
emittingVol =
- 2 * min(63, vol);
+ 2 * Min(63, vol);
} else {
emittingVol = vol;
}
@@ -3461,7 +3461,7 @@ cAudioManager::ProcessActiveQueues()
&position);
if(field_4) {
emittingVol =
- 2 * min(63, m_asActiveSamples[j]
+ 2 * Min(63, m_asActiveSamples[j]
.m_bEmittingVolume);
} else {
emittingVol =
@@ -3783,7 +3783,7 @@ cAudioManager::ProcessBoatMovingOverWater(cVehicleParams *params)
velocityChange = Abs(params->m_fVelocityChange);
if(velocityChange <= 0.0005f && params->m_pVehicle->GetPosition().y) return true;
- velocityChange = min(0.75f, velocityChange);
+ velocityChange = Min(0.75f, velocityChange);
multiplier = (velocityChange - 0.0005f) * 1.3342f;
CalculateDistance(params->m_bDistanceCalculated, params->m_fDistance);
vol = (30.f * multiplier);
@@ -5044,7 +5044,7 @@ void
cAudioManager::ProcessJumboDecel(CPlane *plane)
{
if(SetupJumboFlySound(20) && SetupJumboTaxiSound(75)) {
- const float modificator = min(1.f, (plane->m_fSpeed - 0.10334f) * 1.676f);
+ const float modificator = Min(1.f, (plane->m_fSpeed - 0.10334f) * 1.676f);
SetupJumboEngineSound(maxVolume * modificator, 6050.f * modificator + 16000);
SetupJumboWhineSound(18, 29500);
}
@@ -6269,7 +6269,7 @@ cAudioManager::ProcessPedHeadphones(cPedParams *params)
emittingVol = 10;
veh = (CAutomobile *)ped->m_pMyVehicle;
if(veh && veh->IsCar()) {
- for(int32 i = 2; i < ARRAYSIZE(veh->Doors); i++) {
+ for(int32 i = 2; i < ARRAY_SIZE(veh->Doors); i++) {
if(!veh->IsDoorClosed((eDoors)i) ||
veh->IsDoorMissing((eDoors)i)) {
emittingVol = 42;
@@ -7259,7 +7259,7 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams *params, CAutomobile *
CurrentPretendGear = 1;
}
if(CReplay::IsPlayingBack()) {
- accelerateState = 255.f * max(0.0f, min(1.0f, automobile->m_fGasPedal));
+ accelerateState = 255.f * Max(0.0f, Min(1.0f, automobile->m_fGasPedal));
} else {
accelerateState = Pads->GetAccelerate();
}
@@ -7268,7 +7268,7 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams *params, CAutomobile *
velocityChange = params->m_fVelocityChange;
relativeVelocityChange = 2.0f * velocityChange / transmission->fMaxVelocity;
- accelerationMultipler = min(min(1.f, relativeVelocityChange), 0.f);
+ accelerationMultipler = Min(Min(1.f, relativeVelocityChange), 0.f);
gasPedalAudio = accelerationMultipler;
currentGear = params->m_pVehicle->m_nCurrentGear;
@@ -7290,9 +7290,9 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams *params, CAutomobile *
if(0.0f != velocityChange) {
time = params->m_pVehicle->m_vecMoveSpeed.z / velocityChange;
if(time <= 0.0f) {
- freqModifier = max(-0.2f, time) * -15000.f;
+ freqModifier = Max(-0.2f, time) * -15000.f;
} else {
- freqModifier = -(min(0.2f, time) * 15000.f);
+ freqModifier = -(Min(0.2f, time) * 15000.f);
}
if(params->m_fVelocityChange < -0.001f) freqModifier = -freqModifier;
} else {
@@ -7311,10 +7311,10 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams *params, CAutomobile *
gasPedalAudio = automobile->m_fGasPedalAudio;
} else {
gasPedalAudio =
- min(1.0f, params->m_fVelocityChange /
+ Min(1.0f, params->m_fVelocityChange /
params->m_pTransmission->fMaxReverseVelocity);
}
- gasPedalAudio = max(0.0f, gasPedalAudio);
+ gasPedalAudio = Max(0.0f, gasPedalAudio);
automobile->m_fGasPedalAudio = gasPedalAudio;
} else if(LastAccel > 0) {
if(channelUsed) {
@@ -7343,7 +7343,7 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams *params, CAutomobile *
AddPlayerCarSample(110 - (40.f * gasPedalAudio), freq,
(engineSoundType + SFX_CAR_REV_10), 0, 52, 1);
- CurrentPretendGear = max(1, currentGear);
+ CurrentPretendGear = Max(1, currentGear);
LastAccel = accelerateState;
bHandbrakeOnLastFrame = automobile->bIsHandbrakeOn;
@@ -8005,7 +8005,7 @@ cAudioManager::ProcessTrainNoise(cVehicleParams *params)
if(params->m_fVelocityChange > 0.0f) {
CalculateDistance(params->m_bDistanceCalculated, params->m_fDistance);
train = (CTrain *)params->m_pVehicle;
- speedMultipler = min(1.0f, train->m_fSpeed * 250.f / 51.f);
+ speedMultipler = Min(1.0f, train->m_fSpeed * 250.f / 51.f);
emittingVol = (75.f * speedMultipler);
if(train->m_fWagonPosition == 0.0f) {
m_sQueueSample.m_bVolume =
@@ -8176,7 +8176,7 @@ cAudioManager::ProcessVehicleDoors(cVehicleParams *params)
if(automobile->Damage.GetDoorStatus(i) == 2) {
doorState = automobile->Doors[i].m_nDoorState;
if(doorState == 1 || doorState == 2) {
- velocity = min(0.3f, Abs(automobile->Doors[i].m_fAngVel));
+ velocity = Min(0.3f, Abs(automobile->Doors[i].m_fAngVel));
if(velocity > 0.0035f) {
emittingVol = (100.f * velocity * 10.f / 3.f);
m_sQueueSample.m_bVolume = ComputeVolume(
@@ -8599,7 +8599,7 @@ cAudioManager::ProcessVehicleOneShots(cVehicleParams *params)
m_sQueueSample.m_fSoundIntensity = 30.0f;
break;
case SOUND_CAR_JUMP:
- emittingVol = max(
+ emittingVol = Max(
80.f,
2 * (100.f *
m_asAudioEntities[m_sQueueSample.m_nEntityIndex].m_afVolume[i]));
@@ -9081,7 +9081,7 @@ cAudioManager::ProcessVehicleRoadNoise(cVehicleParams *params)
params->m_fDistance);
emittingVol =
30.f *
- min(1.f,
+ Min(1.f,
velocity / (0.5f * params->m_pTransmission->fMaxVelocity));
m_sQueueSample.m_bVolume =
ComputeVolume(emittingVol, 95.f, m_sQueueSample.m_fDistance);
@@ -9132,6 +9132,9 @@ cAudioManager::ProcessVehicleSirenOrAlarm(cVehicleParams *params)
CVehicle *veh = params->m_pVehicle;
if(veh->m_bSirenOrAlarm == 0 && veh->m_nAlarmState <= 0) return;
+#ifdef FIX_BUGS
+ if (params->m_pVehicle->m_status == STATUS_WRECKED) return;
+#endif
CalculateDistance(params->m_bDistanceCalculated, params->m_fDistance);
m_sQueueSample.m_bVolume = ComputeVolume(80, 110.f, m_sQueueSample.m_fDistance);
if(m_sQueueSample.m_bVolume) {
@@ -9394,7 +9397,7 @@ cAudioManager::ProcessWetRoadNoise(cVehicleParams *params)
CalculateDistance(params->m_bDistanceCalculated,
params->m_fDistance);
relativeVelocity =
- min(1.0f,
+ Min(1.0f,
velChange / (0.5f * params->m_pTransmission->fMaxVelocity));
emittingVol = 23.0f * relativeVelocity * CWeather::WetRoads;
m_sQueueSample.m_bVolume =
@@ -9545,6 +9548,9 @@ cAudioManager::ResetTimers(uint32 time)
SampleManager.SetEffectsFadeVolume(0);
SampleManager.SetMusicFadeVolume(0);
MusicManager.ResetMusicAfterReload();
+#ifdef OPENAL
+ SampleManager.Service();
+#endif
}
}
@@ -9600,6 +9606,9 @@ cAudioManager::ServiceSoundEffects()
ProcessMissionAudio();
AdjustSamplesVolume();
ProcessActiveQueues();
+#ifdef OPENAL
+ SampleManager.Service();
+#endif
for(int32 i = 0; i < m_sAudioScriptObjectManager.m_nScriptObjectEntityTotal; ++i) {
cAudioScriptObject *object =
(cAudioScriptObject *)m_asAudioEntities[m_sAudioScriptObjectManager.m_anScriptObjectEntityIndices[i]]
@@ -9980,7 +9989,7 @@ cAudioManager::Terminate()
m_sAudioScriptObjectManager.m_nScriptObjectEntityTotal = 0;
PreTerminateGameSpecificShutdown();
- for(uint32 i = 0; i < DIGITALCHANNELS; i++) {
+ for(uint32 i = 0; i < MAX_SAMPLEBANKS; i++) {
if(SampleManager.IsSampleBankLoaded(i)) SampleManager.UnloadSampleBank(i);
}
@@ -10032,7 +10041,7 @@ cAudioManager::UpdateReflections()
if(CWorld::ProcessVerticalLine(
camPos, m_avecReflectionsPos[4].z, colpoint,
ent, true, false, false, false, true, false,
- false)) {
+ nil)) {
m_afReflectionsDistances[4] =
colpoint.point.z - camPos.z;
} else {
@@ -10144,217 +10153,3 @@ cAudioManager::ComputeEmittingVolume(uint8 emittingVolume, float intensity, floa
quatIntensity;
return emittingVolume;
}
-
-// STARTPATCHES
-// InjectHook(0x57B210, &cAudioManager::AddDetailsToRequestedOrderList, PATCH_JUMP);
-// InjectHook(0x56AD30, &cAudioManager::AddPlayerCarSample, PATCH_JUMP);
-// InjectHook(0x57B300, &cAudioManager::AddReflectionsToRequestedQueue, PATCH_JUMP);
-// InjectHook(0x57B8D0, &cAudioManager::AddReleasingSounds, PATCH_JUMP);
-// InjectHook(0x57B070, &cAudioManager::AddSampleToRequestedQueue, PATCH_JUMP);
-// InjectHook(0x5697A0, &cAudioManager::CalculateDistance, PATCH_JUMP);
-// InjectHook(0x57AA10, &cAudioManager::CheckForAnAudioFileOnCD, PATCH_JUMP);
-// InjectHook(0x57C160, &cAudioManager::ClearActiveSamples, PATCH_JUMP);
-// InjectHook(0x5796A0, &cAudioManager::ClearMissionAudio, PATCH_JUMP);
-// InjectHook(0x57C120, &cAudioManager::ClearRequestedQueue, PATCH_JUMP);
-// InjectHook(0x57AE00, &cAudioManager::ComputeDopplerEffectedFrequency, PATCH_JUMP);
-// InjectHook(0x57AD20, &cAudioManager::ComputePan, PATCH_JUMP);
-// InjectHook(0x57ABB0, &cAudioManager::ComputeVolume, PATCH_JUMP);
-// InjectHook(0x57A310, &cAudioManager::CreateEntity, PATCH_JUMP);
-// InjectHook(0x57A830, &cAudioManager::DestroyAllGameCreatedEntities, PATCH_JUMP);
-// InjectHook(0x57A400, &cAudioManager::DestroyEntity, PATCH_JUMP);
-// InjectHook(0x57C290, &cAudioManager::GenerateIntegerRandomNumberTable, PATCH_JUMP);
-// InjectHook(0x57A8C0, &cAudioManager::Get3DProviderName, PATCH_JUMP);
-// InjectHook(0x571110, &cAudioManager::GetArmyTalkSfx, PATCH_JUMP);
-// InjectHook(0x573AB0, &cAudioManager::GetBlackBusinessFemaleTalkSfx, PATCH_JUMP);
-// InjectHook(0x572050, &cAudioManager::GetBlackCasualFemaleTalkSfx, PATCH_JUMP);
-// InjectHook(0x574380, &cAudioManager::GetBlackConstructionWorkerTalkSfx, PATCH_JUMP);
-// InjectHook(0x571D80, &cAudioManager::GetBlackCriminalTalkSfx, PATCH_JUMP);
-// InjectHook(0x5735E0, &cAudioManager::GetBlackDockerMaleTalkSfx, PATCH_JUMP);
-// InjectHook(0x5724D0, &cAudioManager::GetBlackFatFemaleTalkSfx, PATCH_JUMP);
-// InjectHook(0x5726C0, &cAudioManager::GetBlackFatMaleTalkSfx, PATCH_JUMP);
-// InjectHook(0x5728B0, &cAudioManager::GetBlackFemaleProstituteTalkSfx, PATCH_JUMP);
-// InjectHook(0x572C20, &cAudioManager::GetBlackProjectFemaleOldTalkSfx, PATCH_JUMP);
-// InjectHook(0x572D20, &cAudioManager::GetBlackProjectFemaleYoungTalkSfx, PATCH_JUMP);
-// InjectHook(0x572AF0, &cAudioManager::GetBlackProjectMaleTalkSfx, PATCH_JUMP);
-// InjectHook(0x5739C0, &cAudioManager::GetBlackWorkerMaleTalkSfx, PATCH_JUMP);
-// InjectHook(0x574FF0, &cAudioManager::GetBomberTalkSfx, PATCH_JUMP);
-// InjectHook(0x5712C0, &cAudioManager::GetBusinessMaleOldTalkSfx, PATCH_JUMP);
-// InjectHook(0x5713E0, &cAudioManager::GetBusinessMaleYoungTalkSfx, PATCH_JUMP);
-// InjectHook(0x572040, &cAudioManager::GetCasualMaleOldTalkSfx, PATCH_JUMP);
-// InjectHook(0x574FE0, &cAudioManager::GetCatatalinaTalkSfx, PATCH_JUMP);
-// InjectHook(0x57AA30, &cAudioManager::GetCDAudioDriveLetter, PATCH_JUMP);
-// InjectHook(0x573010, &cAudioManager::GetChinatownFemaleOldTalkSfx, PATCH_JUMP);
-// InjectHook(0x5730F0, &cAudioManager::GetChinatownFemaleYoungTalkSfx, PATCH_JUMP);
-// InjectHook(0x572E10, &cAudioManager::GetChinatownMaleOldTalkSfx, PATCH_JUMP);
-// InjectHook(0x572F10, &cAudioManager::GetChinatownMaleYoungTalkSfx, PATCH_JUMP);
-// InjectHook(0x575120, &cAudioManager::GetChunkyTalkSfx, PATCH_JUMP);
-// InjectHook(0x571B00, &cAudioManager::GetColumbianTalkSfx, PATCH_JUMP);
-// InjectHook(0x570EA0, &cAudioManager::GetCopTalkSfx, PATCH_JUMP);
-// InjectHook(0x57A8F0, &cAudioManager::GetCurrent3DProviderIndex, PATCH_JUMP);
-// InjectHook(0x571770, &cAudioManager::GetDiabloTalkSfx, PATCH_JUMP);
-// InjectHook(0x569750, &cAudioManager::GetDistanceSquared, PATCH_JUMP);
-// InjectHook(0x574DA0, &cAudioManager::GetEightTalkSfx, PATCH_JUMP);
-// InjectHook(0x574040, &cAudioManager::GetFanFemaleTalkSfx, PATCH_JUMP);
-// InjectHook(0x573F60, &cAudioManager::GetFanMaleTalkSfx, PATCH_JUMP);
-// InjectHook(0x571040, &cAudioManager::GetFBITalkSfx, PATCH_JUMP);
-// InjectHook(0x572280, &cAudioManager::GetFemaleNo3TalkSfx, PATCH_JUMP);
-// InjectHook(0x5712B0, &cAudioManager::GetFiremanTalkSfx, PATCH_JUMP);
-// InjectHook(0x574E50, &cAudioManager::GetFrankieTalkSfx, PATCH_JUMP);
-// InjectHook(0x575510, &cAudioManager::GetGenericFemaleTalkSfx, PATCH_JUMP);
-// InjectHook(0x575460, &cAudioManager::GetGenericMaleTalkSfx, PATCH_JUMP);
-// InjectHook(0x571C30, &cAudioManager::GetHoodTalkSfx, PATCH_JUMP);
-// InjectHook(0x5741F0, &cAudioManager::GetHospitalFemaleTalkSfx, PATCH_JUMP);
-// InjectHook(0x574120, &cAudioManager::GetHospitalMaleTalkSfx, PATCH_JUMP);
-// InjectHook(0x56F410, &cAudioManager::GetJumboTaxiFreq, PATCH_JUMP);
-// InjectHook(0x573310, &cAudioManager::GetLittleItalyFemaleOldTalkSfx, PATCH_JUMP);
-// InjectHook(0x573400, &cAudioManager::GetLittleItalyFemaleYoungTalkSfx, PATCH_JUMP);
-// InjectHook(0x5731E0, &cAudioManager::GetLittleItalyMaleTalkSfx, PATCH_JUMP);
-// InjectHook(0x571510, &cAudioManager::GetMafiaTalkSfx, PATCH_JUMP);
-// InjectHook(0x571F40, &cAudioManager::GetMaleNo2TalkSfx, PATCH_JUMP);
-// InjectHook(0x5711C0, &cAudioManager::GetMedicTalkSfx, PATCH_JUMP);
-// InjectHook(0x5795D0, &cAudioManager::GetMissionAudioLoadingStatus, PATCH_JUMP);
-// InjectHook(0x574F00, &cAudioManager::GetMistyTalkSfx, PATCH_JUMP);
-// InjectHook(0x575340, &cAudioManager::GetNormalMaleTalkSfx, PATCH_JUMP);
-// InjectHook(0x57A8A0, &cAudioManager::GetNum3DProvidersAvailable, PATCH_JUMP);
-// InjectHook(0x574FD0, &cAudioManager::GetOJGTalkSfx, PATCH_JUMP);
-// InjectHook(0x570960, &cAudioManager::GetPedCommentSfx, PATCH_JUMP);
-// InjectHook(0x570DB0, &cAudioManager::GetPhrase, PATCH_JUMP);
-// InjectHook(0x56BF80, &cAudioManager::GetVehicleDriveWheelSkidValue, PATCH_JUMP);
-// InjectHook(0x56C120, &cAudioManager::GetVehicleNonDriveWheelSkidValue, PATCH_JUMP);
-// InjectHook(0x575240, &cAudioManager::GetPimpTalkSfx, PATCH_JUMP);
-// InjectHook(0x570E00, &cAudioManager::GetPlayerTalkSfx, PATCH_JUMP);
-// InjectHook(0x5737E0, &cAudioManager::GetScumFemaleTalkSfx, PATCH_JUMP);
-// InjectHook(0x5736D0, &cAudioManager::GetScumMaleTalkSfx, PATCH_JUMP);
-// InjectHook(0x575060, &cAudioManager::GetSecurityGuardTalkSfx, PATCH_JUMP);
-// InjectHook(0x574480, &cAudioManager::GetShopperFemaleTalkSfx, PATCH_JUMP);
-// InjectHook(0x574790, &cAudioManager::GetSpecialCharacterTalkSfx, PATCH_JUMP);
-// InjectHook(0x573E90, &cAudioManager::GetStewardFemaleTalkSfx, PATCH_JUMP);
-// InjectHook(0x573DC0, &cAudioManager::GetStewardMaleTalkSfx, PATCH_JUMP);
-// InjectHook(0x574690, &cAudioManager::GetStudentFemaleTalkSfx, PATCH_JUMP);
-// InjectHook(0x574590, &cAudioManager::GetStudentMaleTalkSfx, PATCH_JUMP);
-// InjectHook(0x573CD0, &cAudioManager::GetSupermodelFemaleTalkSfx, PATCH_JUMP);
-// InjectHook(0x573BD0, &cAudioManager::GetSupermodelMaleTalkSfx, PATCH_JUMP);
-// InjectHook(0x570F80, &cAudioManager::GetSwatTalkSfx, PATCH_JUMP);
-// InjectHook(0x575190, &cAudioManager::GetTaxiDriverTalkSfx, PATCH_JUMP);
-// InjectHook(0x571650, &cAudioManager::GetTriadTalkSfx, PATCH_JUMP);
-// InjectHook(0x5723A0, &cAudioManager::GetWhiteBusinessFemaleTalkSfx, PATCH_JUMP);
-// InjectHook(0x572170, &cAudioManager::GetWhiteCasualFemaleTalkSfx, PATCH_JUMP);
-// InjectHook(0x574290, &cAudioManager::GetWhiteConstructionWorkerTalkSfx, PATCH_JUMP);
-// InjectHook(0x571E60, &cAudioManager::GetWhiteCriminalTalkSfx, PATCH_JUMP);
-// InjectHook(0x5734F0, &cAudioManager::GetWhiteDockerMaleTalkSfx, PATCH_JUMP);
-// InjectHook(0x5727B0, &cAudioManager::GetWhiteFatFemaleTalkSfx, PATCH_JUMP);
-// InjectHook(0x5725D0, &cAudioManager::GetWhiteFatMaleTalkSfx, PATCH_JUMP);
-// InjectHook(0x5729D0, &cAudioManager::GetWhiteFemaleProstituteTalkSfx, PATCH_JUMP);
-// InjectHook(0x5738D0, &cAudioManager::GetWhiteWorkerMaleTalkSfx, PATCH_JUMP);
-// InjectHook(0x5718D0, &cAudioManager::GetYakuzaTalkSfx, PATCH_JUMP);
-// InjectHook(0x5719E0, &cAudioManager::GetYardieTalkSfx, PATCH_JUMP);
-// InjectHook(0x56CAB0, &cAudioManager::HasAirBrakes, PATCH_JUMP);
-// InjectHook(0x57A0E0, &cAudioManager::Initialise, PATCH_JUMP);
-// InjectHook(0x57B030, &cAudioManager::InterrogateAudioEntities, PATCH_JUMP);
-// InjectHook(0x57AA50, &cAudioManager::IsAudioInitialised, PATCH_JUMP);
-// InjectHook(0x579650, &cAudioManager::IsMissionAudioSampleFinished, PATCH_JUMP);
-// InjectHook(0x57A9C0, &cAudioManager::IsMP3RadioChannelAvailable, PATCH_JUMP);
-// InjectHook(0x579520, &cAudioManager::MissionScriptAudioUsesPoliceChannel, PATCH_JUMP);
-// InjectHook(0x56AD10, &cAudioManager::PlayerJustGotInCar, PATCH_JUMP);
-// InjectHook(0x56AD20, &cAudioManager::PlayerJustLeftCar, PATCH_JUMP);
-// InjectHook(0x579620, &cAudioManager::PlayLoadedMissionAudio, PATCH_JUMP);
-// InjectHook(0x57A500, &cAudioManager::PlayOneShot, PATCH_JUMP);
-// InjectHook(0x569420, &cAudioManager::PostInitialiseGameSpecificSetup, PATCH_JUMP);
-// InjectHook(0x569640, &cAudioManager::PostTerminateGameSpecificShutdown, PATCH_JUMP);
-// InjectHook(0x569400, &cAudioManager::PreInitialiseGameSpecificSetup, PATCH_JUMP);
-// InjectHook(0x579550, &cAudioManager::PreloadMissionAudio, PATCH_JUMP);
-// InjectHook(0x569570, &cAudioManager::PreTerminateGameSpecificShutdown, PATCH_JUMP);
-// InjectHook(0x57BA60, &cAudioManager::ProcessActiveQueues, PATCH_JUMP);
-// InjectHook(0x56C940, &cAudioManager::ProcessAirBrakes, PATCH_JUMP);
-// InjectHook(0x577B30, &cAudioManager::ProcessAirportScriptObject, PATCH_JUMP);
-// InjectHook(0x56DE80, &cAudioManager::ProcessBoatEngine, PATCH_JUMP);
-// InjectHook(0x56E500, &cAudioManager::ProcessBoatMovingOverWater, PATCH_JUMP);
-// InjectHook(0x5790D0, &cAudioManager::ProcessBridge, PATCH_JUMP);
-// InjectHook(0x579250, &cAudioManager::ProcessBridgeMotor, PATCH_JUMP);
-// InjectHook(0x579310, &cAudioManager::ProcessBridgeOneShots, PATCH_JUMP);
-// InjectHook(0x579170, &cAudioManager::ProcessBridgeWarning, PATCH_JUMP);
-// InjectHook(0x56CC20, &cAudioManager::ProcessCarBombTick, PATCH_JUMP);
-// InjectHook(0x577CA0, &cAudioManager::ProcessCinemaScriptObject, PATCH_JUMP);
-// InjectHook(0x577E50, &cAudioManager::ProcessDocksScriptObject, PATCH_JUMP);
-// InjectHook(0x56CAF0, &cAudioManager::ProcessEngineDamage, PATCH_JUMP);
-// InjectHook(0x569870, &cAudioManager::ProcessEntity, PATCH_JUMP);
-// InjectHook(0x575AC0, &cAudioManager::ProcessExplosions, PATCH_JUMP);
-// InjectHook(0x578FD0, &cAudioManager::ProcessFireHydrant, PATCH_JUMP);
-// InjectHook(0x5785E0, &cAudioManager::ProcessFrontEnd, PATCH_JUMP);
-// InjectHook(0x56E6A0, &cAudioManager::ProcessHelicopter, PATCH_JUMP);
-// InjectHook(0x577FE0, &cAudioManager::ProcessHomeScriptObject, PATCH_JUMP);
-// InjectHook(0x56E8F0, &cAudioManager::ProcessJumbo, PATCH_JUMP);
-// InjectHook(0x56EA40, &cAudioManager::ProcessJumboAccel, PATCH_JUMP);
-// InjectHook(0x56EE40, &cAudioManager::ProcessJumboDecel, PATCH_JUMP);
-// InjectHook(0x56ECF0, &cAudioManager::ProcessJumboFlying, PATCH_JUMP);
-// InjectHook(0x56ED10, &cAudioManager::ProcessJumboLanding, PATCH_JUMP);
-// InjectHook(0x56EC00, &cAudioManager::ProcessJumboTakeOff, PATCH_JUMP);
-// InjectHook(0x56EA10, &cAudioManager::ProcessJumboTaxi, PATCH_JUMP);
-// InjectHook(0x5777E0, &cAudioManager::ProcessLaunderetteScriptObject, PATCH_JUMP);
-// InjectHook(0x576770, &cAudioManager::ProcessLoopingScriptObject, PATCH_JUMP);
-// InjectHook(0x5796E0, &cAudioManager::ProcessMissionAudio, PATCH_JUMP);
-// InjectHook(0x56A050, &cAudioManager::ProcessModelCarEngine, PATCH_JUMP);
-// InjectHook(0x5760C0, &cAudioManager::ProcessOneShotScriptObject, PATCH_JUMP);
-// InjectHook(0x56F450, &cAudioManager::ProcessPed, PATCH_JUMP);
-// InjectHook(0x56F4D0, &cAudioManager::ProcessPedHeadphones, PATCH_JUMP);
-// InjectHook(0x56F650, &cAudioManager::ProcessPedOneShots, PATCH_JUMP);
-// InjectHook(0x5699C0, &cAudioManager::ProcessPhysical, PATCH_JUMP);
-// InjectHook(0x56E860, &cAudioManager::ProcessPlane, PATCH_JUMP);
-// InjectHook(0x56B0D0, &cAudioManager::ProcessPlayersVehicleEngine, PATCH_JUMP);
-// InjectHook(0x578190, &cAudioManager::ProcessPoliceCellBeatingScriptObject, PATCH_JUMP);
-// InjectHook(0x577280, &cAudioManager::ProcessPornCinema, PATCH_JUMP);
-// InjectHook(0x578A80, &cAudioManager::ProcessProjectiles, PATCH_JUMP);
-// InjectHook(0x569CC0, &cAudioManager::ProcessRainOnVehicle, PATCH_JUMP);
-// InjectHook(0x569700, &cAudioManager::ProcessReverb, PATCH_JUMP);
-// InjectHook(0x569E50, &cAudioManager::ProcessReverseGear, PATCH_JUMP);
-// InjectHook(0x577630, &cAudioManager::ProcessSawMillScriptObject, PATCH_JUMP);
-// InjectHook(0x576070, &cAudioManager::ProcessScriptObject, PATCH_JUMP);
-// InjectHook(0x577970, &cAudioManager::ProcessShopScriptObject, PATCH_JUMP);
-// InjectHook(0x5697D0, &cAudioManager::ProcessSpecial, PATCH_JUMP);
-// InjectHook(0x56DBF0, &cAudioManager::ProcessTrainNoise, PATCH_JUMP);
-// InjectHook(0x569A00, &cAudioManager::ProcessVehicle, PATCH_JUMP);
-// InjectHook(0x56C770, &cAudioManager::ProcessVehicleDoors, PATCH_JUMP);
-// InjectHook(0x56C200, &cAudioManager::ProcessVehicleHorn, PATCH_JUMP);
-// InjectHook(0x56C640, &cAudioManager::ProcessVehicleReverseWarning, PATCH_JUMP);
-// InjectHook(0x56A230, &cAudioManager::ProcessVehicleRoadNoise, PATCH_JUMP);
-// InjectHook(0x56C420, &cAudioManager::ProcessVehicleSirenOrAlarm, PATCH_JUMP);
-// InjectHook(0x56BCB0, &cAudioManager::ProcessVehicleSkidding, PATCH_JUMP);
-// InjectHook(0x575F30, &cAudioManager::ProcessWaterCannon, PATCH_JUMP);
-// InjectHook(0x578370, &cAudioManager::ProcessWeather, PATCH_JUMP);
-// InjectHook(0x56A440, &cAudioManager::ProcessWetRoadNoise, PATCH_JUMP);
-// InjectHook(0x577530, &cAudioManager::ProcessWorkShopScriptObject, PATCH_JUMP);
-// InjectHook(0x57AF90, &cAudioManager::RandomDisplacement, PATCH_JUMP);
-// InjectHook(0x57A9F0, &cAudioManager::ReacquireDigitalHandle, PATCH_JUMP);
-// InjectHook(0x57A9E0, &cAudioManager::ReleaseDigitalHandle, PATCH_JUMP);
-// InjectHook(0x569650, &cAudioManager::ResetAudioLogicTimers, PATCH_JUMP);
-// InjectHook(0x57A7B0, &cAudioManager::ResetTimers, PATCH_JUMP);
-// InjectHook(0x57A2A0, &cAudioManager::Service, PATCH_JUMP);
-// InjectHook(0x57AA60, &cAudioManager::ServiceSoundEffects, PATCH_JUMP);
-// InjectHook(0x57A910, &cAudioManager::SetCurrent3DProvider, PATCH_JUMP);
-// InjectHook(0x57AA00, &cAudioManager::SetDynamicAcousticModelingStatus, PATCH_JUMP);
-// InjectHook(0x57A770, &cAudioManager::SetEffectsFadeVolume, PATCH_JUMP);
-// InjectHook(0x57A730, &cAudioManager::SetEffectsMasterVolume, PATCH_JUMP);
-// InjectHook(0x57A4C0, &cAudioManager::SetEntityStatus, PATCH_JUMP);
-// InjectHook(0x5795F0, &cAudioManager::SetMissionAudioLocation, PATCH_JUMP);
-// InjectHook(0x57A790, &cAudioManager::SetMusicFadeVolume, PATCH_JUMP);
-// InjectHook(0x57A750, &cAudioManager::SetMusicMasterVolume, PATCH_JUMP);
-// InjectHook(0x57A9A0, &cAudioManager::SetSpeakerConfig, PATCH_JUMP);
-// InjectHook(0x56F230, &cAudioManager::SetupJumboFlySound, PATCH_JUMP);
-// InjectHook(0x56F310, &cAudioManager::SetupJumboRumbleSound, PATCH_JUMP);
-// InjectHook(0x56EF20, &cAudioManager::SetupJumboTaxiSound, PATCH_JUMP);
-// InjectHook(0x56F070, &cAudioManager::SetupJumboWhineSound, PATCH_JUMP);
-// InjectHook(0x570690, &cAudioManager::SetupPedComments, PATCH_JUMP);
-// InjectHook(0x57A150, &cAudioManager::Terminate, PATCH_JUMP);
-// InjectHook(0x57AC60, &cAudioManager::TranslateEntity, PATCH_JUMP);
-// InjectHook(0x56AC80, &cAudioManager::UpdateGasPedalAudio, PATCH_JUMP);
-// InjectHook(0x57B470, &cAudioManager::UpdateReflections, PATCH_JUMP);
-// InjectHook(0x56C600, &cAudioManager::UsesReverseWarning, PATCH_JUMP);
-// InjectHook(0x56C3C0, &cAudioManager::UsesSiren, PATCH_JUMP);
-// InjectHook(0x56C3F0, &cAudioManager::UsesSirenSwitching, PATCH_JUMP);
-
-// InjectHook(0x57C2B0, &cAudioManager::AdjustSamplesVolume, PATCH_JUMP);
-// InjectHook(0x57C320, &cAudioManager::ComputeEmittingVolume, PATCH_JUMP);
-
-// InjectHook(0x5755C0, &cPedComments::Add, PATCH_JUMP);
-// InjectHook(0x575730, &cPedComments::Process, PATCH_JUMP);
-// ENDPATCHES
diff --git a/src/audio/AudioManager.h b/src/audio/AudioManager.h
index 31a07f9b..72d8ba41 100644
--- a/src/audio/AudioManager.h
+++ b/src/audio/AudioManager.h
@@ -118,7 +118,7 @@ enum eScriptSounds : int16 {
SCRIPT_SOUND_BULLET_HIT_GROUND_1 = 106,
SCRIPT_SOUND_BULLET_HIT_GROUND_2 = 107,
SCRIPT_SOUND_BULLET_HIT_GROUND_3 = 108,
- SCRIPT_SOUND_109 = 109,
+ SCRIPT_SOUND_BULLET_HIT_WATER = 109, //no sound
SCRIPT_SOUND_110 = 110,
SCRIPT_SOUND_111 = 111,
SCRIPT_SOUND_PAYPHONE_RINGING = 112,
@@ -143,28 +143,17 @@ public:
int32 m_nSampleIndex;
uint8 m_bBankIndex;
bool m_bIs2D;
- uint8 field_14; // unused
- uint8 field_15; // unused
int32 m_nReleasingVolumeModificator;
int32 m_nFrequency;
uint8 m_bVolume;
- uint8 field_25; // unused
- uint8 field_26; // unused
- uint8 field_27; // unused
float m_fDistance;
int32 m_nLoopCount;
int32 m_nLoopStart;
int32 m_nLoopEnd;
uint8 m_bEmittingVolume;
- uint8 field_45; // unused
- uint8 field_46; // unused
- uint8 field_47; // unused
float m_fSpeedMultiplier;
float m_fSoundIntensity;
bool m_bReleasingSoundFlag;
- uint8 field_57; // unused
- uint8 field_58; // unused
- uint8 field_59; // unused
CVector m_vecPos;
bool m_bReverbFlag;
uint8 m_bLoopsRemaining;
@@ -173,15 +162,8 @@ public:
int32 m_nReleasingVolumeDivider;
bool m_bIsProcessed;
bool m_bLoopEnded;
- uint8 field_82; // unused
- uint8 field_83; // unused
int32 m_nCalculatedVolume;
int8 m_nVolumeChange;
- uint8 field_89; // unused
- uint8 field_90; // unused
- uint8 field_91; // unused
-
- // no methods
};
static_assert(sizeof(tSound) == 92, "tSound: error");
@@ -197,12 +179,8 @@ public:
bool m_bIsUsed;
uint8 m_bStatus;
int16 m_awAudioEvent[NUM_AUDIOENTITY_EVENTS];
- //uint8 gap_18[2];
float m_afVolume[NUM_AUDIOENTITY_EVENTS];
uint8 m_AudioEvents;
- uint8 field_25[3];
-
- // no methods
};
static_assert(sizeof(tAudioEntity) == 40, "tAudioEntity: error");
@@ -216,8 +194,6 @@ public:
float m_fDistance;
uint8 m_bVolume;
int8 m_nProcess;
-
- // no methods
};
static_assert(sizeof(tPedComment) == 28, "tPedComment: error");
@@ -244,18 +220,12 @@ class cMissionAudio
public:
CVector m_vecPos;
bool m_bPredefinedProperties;
- //uint8 gap_13[3];
int m_nSampleIndex;
uint8 m_bLoadingStatus;
uint8 m_bPlayStatus;
uint8 field_22; // todo find a name
- uint8 field_23; // unused
int32 m_nMissionAudioCounter;
bool m_bIsPlayed;
- uint8 field_29; // unused
- uint8 field_30; // unused
- uint8 field_31; // unused
- // no methods
};
static_assert(sizeof(cMissionAudio) == 32, "cMissionAudio: error");
@@ -305,17 +275,11 @@ public:
uint8 m_bActiveSamples;
uint8 field_4; // unused
bool m_bDynamicAcousticModelingStatus;
- uint8 field_6; // unused
- uint8 field_7; // unused
float m_fSpeedOfSound;
bool m_bTimerJustReset;
- uint8 field_13; // unused
- uint8 field_14; // unused
- uint8 field_15; // unused
int32 m_nTimer;
tSound m_sQueueSample;
bool m_bActiveSampleQueue;
- uint8 gap_109[3]; // unused
tSound m_asSamples[NUM_SOUNDS_SAMPLES_BANKS][NUM_SOUNDS_SAMPLES_SLOTS];
uint8 m_abSampleQueueIndexTable[NUM_SOUNDS_SAMPLES_BANKS][NUM_SOUNDS_SAMPLES_SLOTS];
uint8 m_bSampleRequestQueuesStatus[NUM_SOUNDS_SAMPLES_BANKS];
@@ -341,7 +305,6 @@ public:
uint8 m_bTimeSpent;
uint8 m_bUserPause;
uint8 m_bPreviousUserPause;
- uint8 field_19195; // unused
uint32 m_FrameCounter;
cAudioManager();
@@ -618,6 +581,6 @@ public:
uint8 ComputeEmittingVolume(uint8 emittingVolume, float intensity, float dist);
};
-static_assert(sizeof(cAudioManager) == 19220, "cAudioManager: error");
+//dstatic_assert(sizeof(cAudioManager) == 19220, "cAudioManager: error");
extern cAudioManager AudioManager;
diff --git a/src/audio/AudioScriptObject.cpp b/src/audio/AudioScriptObject.cpp
index da9e1d2e..3d84006d 100644
--- a/src/audio/AudioScriptObject.cpp
+++ b/src/audio/AudioScriptObject.cpp
@@ -1,5 +1,5 @@
#include "common.h"
-#include "patcher.h"
+
#include "AudioScriptObject.h"
#include "Pools.h"
#include "DMAudio.h"
@@ -86,10 +86,3 @@ PlayOneShotScriptObject(uint8 id, CVector const &pos)
audioScriptObject->AudioEntity = AEHANDLE_NONE;
DMAudio.CreateOneShotScriptObject(audioScriptObject);
}
-
-STARTPATCHES
-InjectHook(0x57C430, &cAudioScriptObject::Reset, PATCH_JUMP);
-InjectHook(0x57C5F0, &PlayOneShotScriptObject, PATCH_JUMP);
-InjectHook(0x57C560, &cAudioScriptObject::LoadAllAudioScriptObjects, PATCH_JUMP);
-InjectHook(0x57c460, &cAudioScriptObject::SaveAllAudioScriptObjects, PATCH_JUMP);
-ENDPATCHES \ No newline at end of file
diff --git a/src/audio/DMAudio.cpp b/src/audio/DMAudio.cpp
index a01c85ae..11c85dbd 100644
--- a/src/audio/DMAudio.cpp
+++ b/src/audio/DMAudio.cpp
@@ -1,12 +1,12 @@
#include "common.h"
-#include "patcher.h"
+
#include "DMAudio.h"
#include "MusicManager.h"
#include "AudioManager.h"
#include "AudioScriptObject.h"
#include "sampman.h"
-cDMAudio &DMAudio = *(cDMAudio*)0x95CDBE;
+cDMAudio DMAudio;
void
cDMAudio::Initialise(void)
@@ -318,57 +318,3 @@ cDMAudio::SetRadioChannel(int8 radio, int32 pos)
{
MusicManager.SetRadioChannelByScript(radio, pos);
}
-
-STARTPATCHES
- InjectHook(0x57C760, &cDMAudio::Initialise, PATCH_JUMP);
- InjectHook(0x57C780, &cDMAudio::Terminate, PATCH_JUMP);
- InjectHook(0x57C7A0, &cDMAudio::Service, PATCH_JUMP);
- InjectHook(0x57C7C0, &cDMAudio::CreateEntity, PATCH_JUMP);
- InjectHook(0x57C7F0, &cDMAudio::DestroyEntity, PATCH_JUMP);
- InjectHook(0x57C810, &cDMAudio::SetEntityStatus, PATCH_JUMP);
- InjectHook(0x57C840, &cDMAudio::PlayOneShot, PATCH_JUMP);
- InjectHook(0x57C870, &cDMAudio::DestroyAllGameCreatedEntities, PATCH_JUMP);
- InjectHook(0x57C890, &cDMAudio::SetEffectsMasterVolume, PATCH_JUMP);
- InjectHook(0x57C8C0, &cDMAudio::SetMusicMasterVolume, PATCH_JUMP);
- InjectHook(0x57C8F0, &cDMAudio::SetEffectsFadeVol, PATCH_JUMP);
- InjectHook(0x57C920, &cDMAudio::SetMusicFadeVol, PATCH_JUMP);
- InjectHook(0x57C950, &cDMAudio::GetNum3DProvidersAvailable, PATCH_JUMP);
- InjectHook(0x57C970, &cDMAudio::Get3DProviderName, PATCH_JUMP);
- InjectHook(0x57C990, &cDMAudio::GetCurrent3DProviderIndex, PATCH_JUMP);
- InjectHook(0x57C9B0, &cDMAudio::SetCurrent3DProvider, PATCH_JUMP);
- InjectHook(0x57C9D0, &cDMAudio::SetSpeakerConfig, PATCH_JUMP);
- InjectHook(0x57C9F0, &cDMAudio::IsMP3RadioChannelAvailable, PATCH_JUMP);
- InjectHook(0x57CA10, &cDMAudio::ReleaseDigitalHandle, PATCH_JUMP);
- InjectHook(0x57CA30, &cDMAudio::ReacquireDigitalHandle, PATCH_JUMP);
- InjectHook(0x57CA50, &cDMAudio::SetDynamicAcousticModelingStatus, PATCH_JUMP);
- InjectHook(0x57CA70, &cDMAudio::CheckForAnAudioFileOnCD, PATCH_JUMP);
- InjectHook(0x57CA90, &cDMAudio::GetCDAudioDriveLetter, PATCH_JUMP);
- InjectHook(0x57CAB0, &cDMAudio::IsAudioInitialised, PATCH_JUMP);
- InjectHook(0x57CAD0, &cDMAudio::ReportCrime, PATCH_JUMP);
- InjectHook(0x57CB00, &cDMAudio::CreateLoopingScriptObject, PATCH_JUMP);
- InjectHook(0x57CB40, &cDMAudio::DestroyLoopingScriptObject, PATCH_JUMP);
- InjectHook(0x57CB60, &cDMAudio::CreateOneShotScriptObject, PATCH_JUMP);
- InjectHook(0x57CBB0, &cDMAudio::PlaySuspectLastSeen, PATCH_JUMP);
- InjectHook(0x57CBE0, &cDMAudio::ReportCollision, PATCH_JUMP);
- InjectHook(0x57CC20, &cDMAudio::PlayFrontEndSound, PATCH_JUMP);
- InjectHook(0x57CC60, &cDMAudio::PlayRadioAnnouncement, PATCH_JUMP);
- InjectHook(0x57CC80, &cDMAudio::PlayFrontEndTrack, PATCH_JUMP);
- InjectHook(0x57CCB0, &cDMAudio::StopFrontEndTrack, PATCH_JUMP);
- InjectHook(0x57CCD0, &cDMAudio::ResetTimers, PATCH_JUMP);
- InjectHook(0x57CCF0, &cDMAudio::ChangeMusicMode, PATCH_JUMP);
- InjectHook(0x57CD10, &cDMAudio::PreloadCutSceneMusic, PATCH_JUMP);
- InjectHook(0x57CD30, &cDMAudio::PlayPreloadedCutSceneMusic, PATCH_JUMP);
- InjectHook(0x57CD50, &cDMAudio::StopCutSceneMusic, PATCH_JUMP);
- InjectHook(0x57CD70, &cDMAudio::PreloadMissionAudio, PATCH_JUMP);
- InjectHook(0x57CD90, &cDMAudio::GetMissionAudioLoadingStatus, PATCH_JUMP);
- InjectHook(0x57CDB0, &cDMAudio::SetMissionAudioLocation, PATCH_JUMP);
- InjectHook(0x57CDE0, &cDMAudio::PlayLoadedMissionAudio, PATCH_JUMP);
- InjectHook(0x57CE00, &cDMAudio::IsMissionAudioSampleFinished, PATCH_JUMP);
- InjectHook(0x57CE20, &cDMAudio::ClearMissionAudio, PATCH_JUMP);
- InjectHook(0x57CE40, &cDMAudio::GetRadioInCar, PATCH_JUMP);
- InjectHook(0x57CE60, &cDMAudio::SetRadioInCar, PATCH_JUMP);
- InjectHook(0x57CE80, &cDMAudio::SetRadioChannel, PATCH_JUMP);
-
- //InjectHook(0x57CEB0, `global constructor keyed to'dmaudio.cpp, PATCH_JUMP);
- //InjectHook(0x57CED0, cDMAudio::~cDMAudio, PATCH_JUMP);
-ENDPATCHES
diff --git a/src/audio/DMAudio.h b/src/audio/DMAudio.h
index d2cdf466..42688fa6 100644
--- a/src/audio/DMAudio.h
+++ b/src/audio/DMAudio.h
@@ -1,6 +1,7 @@
#pragma once
#include "audio_enums.h"
+#include "Crime.h"
enum eSound : int16
{
@@ -179,7 +180,6 @@ enum eSound : int16
class cAudioScriptObject;
class CEntity;
-enum eCrimeType;
class cDMAudio
{
@@ -256,4 +256,4 @@ public:
void SetRadioInCar(uint32 radio);
void SetRadioChannel(int8 radio, int32 pos);
};
-extern cDMAudio &DMAudio;
+extern cDMAudio DMAudio;
diff --git a/src/audio/MusicManager.cpp b/src/audio/MusicManager.cpp
index d840c57b..efea6e45 100644
--- a/src/audio/MusicManager.cpp
+++ b/src/audio/MusicManager.cpp
@@ -13,12 +13,12 @@
#include "Timer.h"
#include "World.h"
#include "sampman.h"
-#include "patcher.h"
-cMusicManager &MusicManager = *(cMusicManager *)0x8F3964;
-int32 &gNumRetunePresses = *(int32 *)0x650B80;
-int32 &gRetuneCounter = *(int32*)0x650B84;
-bool& bHasStarted = *(bool*)0x650B7C;
+
+cMusicManager MusicManager;
+int32 gNumRetunePresses;
+int32 gRetuneCounter;
+bool bHasStarted;
const int maxVolume = 127;
@@ -51,6 +51,12 @@ cMusicManager::PlayerInCar()
if(State == PED_DRAG_FROM_CAR || State == PED_EXIT_CAR || State == PED_ARRESTED)
return false;
+ if (!FindPlayerVehicle())
+ return true;
+
+ if (FindPlayerVehicle()->m_status == STATUS_WRECKED)
+ return false;
+
switch(FindPlayerVehicle()->m_modelIndex) {
case MI_FIRETRUCK:
case MI_AMBULAN:
@@ -699,7 +705,7 @@ cMusicManager::GetTrackStartPos(uint8 track)
result = m_aTracks[track].m_nPosition;
m_aTracks[track].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
} else
- result = min(CTimer::GetTimeInMillisecondsPauseMode() - timer, 90000) + m_aTracks[track].m_nPosition;
+ result = Min(CTimer::GetTimeInMillisecondsPauseMode() - timer, 90000) + m_aTracks[track].m_nPosition;
if (result > m_aTracks[track].m_nLength) result %= m_aTracks[track].m_nLength;
return result;
@@ -904,34 +910,3 @@ cMusicManager::ChangeRadioChannel()
}
return true;
}
-
-STARTPATCHES
-InjectHook(0x57E4B0, &cMusicManager::PlayerInCar, PATCH_JUMP);
-InjectHook(0x57E6D0, &cMusicManager::DisplayRadioStationName, PATCH_JUMP);
-InjectHook(0x57CF70, &cMusicManager::Initialise, PATCH_JUMP);
-InjectHook(0x57D140, &cMusicManager::Terminate, PATCH_JUMP);
-InjectHook(0x57D1D0, &cMusicManager::GetRadioInCar, PATCH_JUMP);
-InjectHook(0x57D2C0, &cMusicManager::SetRadioInCar, PATCH_JUMP);
-InjectHook(0x57D180, &cMusicManager::SetRadioChannelByScript, PATCH_JUMP);
-InjectHook(0x57CF30, &cMusicManager::ResetMusicAfterReload, PATCH_JUMP);
-InjectHook(0x57E6A0, &cMusicManager::UsesPoliceRadio, PATCH_JUMP);
-InjectHook(0x57D310, &cMusicManager::ChangeMusicMode, PATCH_JUMP);
-InjectHook(0x57D420, &cMusicManager::ResetTimers, PATCH_JUMP);
-InjectHook(0x57D440, &cMusicManager::Service, PATCH_JUMP);
-InjectHook(0x57D530, &cMusicManager::ServiceFrontEndMode, PATCH_JUMP);
-InjectHook(0x57E3D0, &cMusicManager::StopFrontEndTrack, PATCH_JUMP);
-InjectHook(0x57E430, &cMusicManager::PlayAnnouncement, PATCH_JUMP);
-InjectHook(0x57E2E0, &cMusicManager::PlayFrontEndTrack, PATCH_JUMP);
-InjectHook(0x57E210, &cMusicManager::PreloadCutSceneMusic, PATCH_JUMP);
-InjectHook(0x57E290, &cMusicManager::PlayPreloadedCutSceneMusic, PATCH_JUMP);
-InjectHook(0x57E2B0, &cMusicManager::StopCutSceneMusic, PATCH_JUMP);
-InjectHook(0x57E450, &cMusicManager::GetTrackStartPos, PATCH_JUMP);
-InjectHook(0x57D690, &cMusicManager::ServiceGameMode, PATCH_JUMP);
-InjectHook(0x57DCB0, &cMusicManager::ServiceAmbience, PATCH_JUMP);
-InjectHook(0x57DEA0, &cMusicManager::ComputeAmbienceVol, PATCH_JUMP);
-InjectHook(0x57E100, &cMusicManager::ServiceTrack, PATCH_JUMP);
-InjectHook(0x57DFC0, &cMusicManager::ServiceAnnouncement, PATCH_JUMP);
-InjectHook(0x57E530, &cMusicManager::GetCarTuning, PATCH_JUMP);
-InjectHook(0x57E5A0, &cMusicManager::GetNextCarTuning, PATCH_JUMP);
-InjectHook(0x57E130, &cMusicManager::ChangeRadioChannel, PATCH_JUMP);
-ENDPATCHES \ No newline at end of file
diff --git a/src/audio/MusicManager.h b/src/audio/MusicManager.h
index 5c255069..5d6f41cf 100644
--- a/src/audio/MusicManager.h
+++ b/src/audio/MusicManager.h
@@ -86,4 +86,4 @@ public:
static_assert(sizeof(cMusicManager) == 0x95C, "cMusicManager: error");
-extern cMusicManager &MusicManager;
+extern cMusicManager MusicManager;
diff --git a/src/audio/PoliceRadio.cpp b/src/audio/PoliceRadio.cpp
index 255d7026..c4946da6 100644
--- a/src/audio/PoliceRadio.cpp
+++ b/src/audio/PoliceRadio.cpp
@@ -1,15 +1,18 @@
#include "common.h"
-#include "patcher.h"
+
#include "DMAudio.h"
+
#include "AudioManager.h"
+
#include "AudioSamples.h"
#include "MusicManager.h"
-#include "PoliceRadio.h"
#include "PlayerPed.h"
-#include "sampman.h"
-#include "Zones.h"
+#include "PoliceRadio.h"
+#include "Replay.h"
#include "Vehicle.h"
#include "World.h"
+#include "Zones.h"
+#include "sampman.h"
const int maxVolume = 127;
const int channels = ARRAY_SIZE(cAudioManager::m_asActiveSamples);
@@ -21,14 +24,14 @@ struct tPoliceRadioZone {
int32 field_12;
};
-tPoliceRadioZone (&ZoneSfx)[NUMAUDIOZONES] = *(tPoliceRadioZone(*)[NUMAUDIOZONES])*(uintptr*)0x880240;
-char *SubZo2Label = (char*)0x6E9918;
-char *SubZo3Label = (char*)0x6E9870;
+tPoliceRadioZone ZoneSfx[NUMAUDIOZONES];
+char SubZo2Label[8];
+char SubZo3Label[8];
-int32 &g_nMissionAudioSfx = *(int32*)0x60ED84;
-int8 &g_nMissionAudioPlayingStatus = *(int8*)0x60ED88;
-uint8 &gSpecialSuspectLastSeenReport = *(uint8*)0x95CD4D;
-uint32 (&gMinTimeToNextReport)[NUM_CRIME_TYPES] = *(uint32(*)[NUM_CRIME_TYPES])*(uintptr*)0x8E2828;
+int32 g_nMissionAudioSfx = TOTAL_AUDIO_SAMPLES;
+int8 g_nMissionAudioPlayingStatus = 2;
+uint8 gSpecialSuspectLastSeenReport;
+uint32 gMinTimeToNextReport[NUM_CRIME_TYPES];
void
cAudioManager::InitialisePoliceRadioZones()
@@ -155,7 +158,8 @@ cAudioManager::ServicePoliceRadio()
if(!m_bUserPause) {
bool crimeReport = SetupCrimeReport();
#ifdef FIX_BUGS // Crash at 0x5fe6ef
- if(!FindPlayerPed() || !FindPlayerPed()->m_pWanted) return;
+ if(CReplay::IsPlayingBack() || !FindPlayerPed() || !FindPlayerPed()->m_pWanted)
+ return;
#endif
wantedLevel = FindPlayerPed()->m_pWanted->m_nWantedLevel;
if(!crimeReport) {
@@ -774,19 +778,3 @@ cAudioManager::AgeCrimes()
}
}
}
-
-STARTPATCHES
-InjectHook(0x580AF0, &cAudioManager::AgeCrimes, PATCH_JUMP);
-InjectHook(0x57F060, &cAudioManager::DoPoliceRadioCrackle, PATCH_JUMP);
-InjectHook(0x57F050, &cAudioManager::GetMissionScriptPoliceAudioPlayingStatus, PATCH_JUMP);
-InjectHook(0x57EEC0, &cAudioManager::InitialisePoliceRadio, PATCH_JUMP);
-InjectHook(0x57EAC0, &cAudioManager::InitialisePoliceRadioZones, PATCH_JUMP);
-InjectHook(0x580500, &cAudioManager::PlaySuspectLastSeen, PATCH_JUMP);
-InjectHook(0x5803D0, &cAudioManager::ReportCrime, PATCH_JUMP);
-InjectHook(0x57EFF0, &cAudioManager::ResetPoliceRadio, PATCH_JUMP);
-InjectHook(0x57F110, &cAudioManager::ServicePoliceRadio, PATCH_JUMP);
-InjectHook(0x57F1B0, &cAudioManager::ServicePoliceRadioChannel, PATCH_JUMP);
-InjectHook(0x57F020, &cAudioManager::SetMissionScriptPoliceAudio, PATCH_JUMP);
-InjectHook(0x57F5B0, &cAudioManager::SetupCrimeReport, PATCH_JUMP);
-InjectHook(0x57FCC0, &cAudioManager::SetupSuspectLastSeenReport, PATCH_JUMP);
-ENDPATCHES
diff --git a/src/audio/miles/sampman_mss.cpp b/src/audio/miles/sampman_mss.cpp
new file mode 100644
index 00000000..f3a6ba80
--- /dev/null
+++ b/src/audio/miles/sampman_mss.cpp
@@ -0,0 +1,2257 @@
+#include <windows.h>
+#include <shobjidl.h>
+#include <shlguid.h>
+
+#include <time.h>
+
+#include "eax.h"
+#include "eax-util.h"
+#include "mss.h"
+
+#include "sampman_mss.h"
+#include "AudioManager.h"
+#include "MusicManager.h"
+#include "Frontend.h"
+#include "Timer.h"
+
+
+#pragma comment( lib, "mss32.lib" )
+
+cSampleManager SampleManager;
+int32 BankStartOffset[MAX_SAMPLEBANKS];
+///////////////////////////////////////////////////////////////
+
+char SampleBankDescFilename[] = "AUDIO\\SFX.SDT";
+char SampleBankDataFilename[] = "AUDIO\\SFX.RAW";
+
+FILE *fpSampleDescHandle;
+FILE *fpSampleDataHandle;
+bool bSampleBankLoaded [MAX_SAMPLEBANKS];
+int32 nSampleBankDiscStartOffset [MAX_SAMPLEBANKS];
+int32 nSampleBankSize [MAX_SAMPLEBANKS];
+int32 nSampleBankMemoryStartAddress[MAX_SAMPLEBANKS];
+int32 _nSampleDataEndOffset;
+
+int32 nPedSlotSfx [MAX_PEDSFX];
+int32 nPedSlotSfxAddr[MAX_PEDSFX];
+uint8 nCurrentPedSlot;
+
+uint8 nChannelVolume[MAXCHANNELS+MAX2DCHANNELS];
+
+uint32 nStreamLength[TOTAL_STREAMED_SOUNDS];
+
+///////////////////////////////////////////////////////////////
+struct tMP3Entry
+{
+ char aFilename[MAX_PATH];
+
+ uint32 nTrackLength;
+ uint32 nTrackStreamPos;
+
+ tMP3Entry *pNext;
+ char *pLinkPath;
+};
+
+uint32 nNumMP3s;
+tMP3Entry *_pMP3List;
+char _mp3DirectoryPath[MAX_PATH];
+HSTREAM mp3Stream [MAX_MP3STREAMS];
+int8 nStreamPan [MAX_MP3STREAMS];
+int8 nStreamVolume[MAX_MP3STREAMS];
+uint32 _CurMP3Index;
+int32 _CurMP3Pos;
+bool _bIsMp3Active;
+
+#if defined(GTA3_1_1_PATCH) || defined(GTA3_STEAM_PATCH) || defined(NO_CDCHECK)
+bool _bUseHDDAudio;
+char _aHDDPath[MAX_PATH];
+#endif
+///////////////////////////////////////////////////////////////
+
+
+bool _bSampmanInitialised = false;
+
+//
+// Miscellaneous globals / defines
+
+// Env Size Diffus Room RoomHF RoomLF DecTm DcHF DcLF Refl RefDel Ref Pan Revb RevDel Rev Pan EchTm EchDp ModTm ModDp AirAbs HFRef LFRef RRlOff FLAGS
+
+EAXLISTENERPROPERTIES StartEAX3 =
+ {26, 1.7f, 0.8f, -1000, -1000, -100, 4.42f, 0.14f, 1.00f, 429, 0.014f, 0.00f,0.00f,0.00f, 1023, 0.021f, 0.00f,0.00f,0.00f, 0.250f, 0.000f, 0.250f, 0.000f, -5.0f, 2727.1f, 250.0f, 0.00f, 0x3f };
+
+EAXLISTENERPROPERTIES FinishEAX3 =
+ {26, 100.0f, 1.0f, 0, -1000, -2200, 20.0f, 1.39f, 1.00f, 1000, 0.069f, 0.00f,0.00f,0.00f, 400, 0.100f, 0.00f,0.00f,0.00f, 0.250f, 1.000f, 3.982f, 0.000f, -18.0f, 3530.8f, 417.9f, 6.70f, 0x3f };
+
+EAXLISTENERPROPERTIES EAX3Params;
+
+S32 prevprovider=-1;
+S32 curprovider=-1;
+S32 usingEAX=0;
+S32 usingEAX3=0;
+HPROVIDER opened_provider=0;
+H3DSAMPLE opened_samples[MAXCHANNELS] = {0};
+HSAMPLE opened_2dsamples[MAX2DCHANNELS] = {0};
+HDIGDRIVER DIG;
+S32 speaker_type=0;
+
+U32 _maxSamples;
+float _fPrevEaxRatioDestination;
+bool _usingMilesFast2D;
+float _fEffectsLevel;
+
+
+struct
+{
+ HPROVIDER id;
+ char name[80];
+}providers[MAXPROVIDERS];
+
+typedef struct provider_stuff
+{
+ char* name;
+ HPROVIDER id;
+} provider_stuff;
+
+
+static int __cdecl comp(const provider_stuff*s1,const provider_stuff*s2)
+{
+ return( _stricmp(s1->name,s2->name) );
+}
+
+static void
+add_providers()
+{
+ provider_stuff pi[MAXPROVIDERS];
+ U32 n,i,j;
+
+ SampleManager.SetNum3DProvidersAvailable(0);
+
+ HPROENUM next = HPROENUM_FIRST;
+
+ n=0;
+ while (AIL_enumerate_3D_providers(&next, &pi[n].id, &pi[n].name) && (n<MAXPROVIDERS))
+ {
+ ++n;
+ }
+
+ qsort(pi,n,sizeof(pi[0]), (int(__cdecl*)(void const*, void const*))comp);
+
+ for(i=0;i<n;i++)
+ {
+ providers[i].id=pi[i].id;
+ strcpy(providers[i].name, pi[i].name);
+ SampleManager.Set3DProviderName(i, providers[i].name);
+ }
+
+ SampleManager.SetNum3DProvidersAvailable(n);
+
+ for(j=n;j<MAXPROVIDERS;j++)
+ SampleManager.Set3DProviderName(j, NULL);
+}
+
+static void
+release_existing()
+{
+ for ( U32 i = 0; i < _maxSamples; i++ )
+ {
+ if ( opened_samples[i] )
+ {
+ AIL_release_3D_sample_handle(opened_samples[i]);
+ opened_samples[i] = NULL;
+ }
+ }
+
+ if ( opened_provider )
+ {
+ AIL_close_3D_provider(opened_provider);
+ opened_provider = NULL;
+ }
+
+ _fPrevEaxRatioDestination = 0.0f;
+ _usingMilesFast2D = false;
+ _fEffectsLevel = 0.0f;
+}
+
+static bool
+set_new_provider(S32 index)
+{
+ DWORD result;
+
+ if ( curprovider == index )
+ return true;
+
+ //close the already opened provider
+ curprovider = index;
+
+ release_existing();
+
+ if ( curprovider != -1 )
+ {
+ if ( !strcmp(providers[index].name, "Dolby Surround") )
+ _maxSamples = MAXCHANNELS_SURROUND;
+ else
+ _maxSamples = MAXCHANNELS;
+
+ AIL_set_3D_provider_preference(providers[index].id, "Maximum supported samples", &_maxSamples);
+
+ //load the new provider
+ result = AIL_open_3D_provider(providers[index].id);
+
+ if (result != M3D_NOERR)
+ {
+ curprovider=-1;
+
+ OutputDebugStringA(AIL_last_error());
+
+ release_existing();
+
+ return false;
+ }
+ else
+ {
+ opened_provider=providers[index].id;
+
+ //see if we're running under an EAX compatible provider
+
+ if ( !strcmp(providers[index].name, "Creative Labs EAX 3 (TM)") )
+ {
+ usingEAX = 1;
+ usingEAX3 = 1;
+ }
+ else
+ {
+ usingEAX3 = 0;
+
+ result=AIL_3D_room_type(opened_provider);
+ usingEAX=(((S32)result)!=-1)?1:0; // will be something other than -1 on EAX
+ }
+
+ if ( usingEAX3 )
+ {
+ OutputDebugString("DOING SPECIAL EAX 3 STUFF!");
+ AIL_set_3D_provider_preference(opened_provider, "EAX all parameters", &FinishEAX3);
+ }
+ else if ( usingEAX )
+ {
+ AIL_set_3D_room_type(opened_provider, ENVIRONMENT_CAVE);
+
+ if ( !strcmp(providers[index].name, "Miles Fast 2D Positional Audio") )
+ _usingMilesFast2D = true;
+ }
+
+ AIL_3D_provider_attribute(opened_provider, "Maximum supported samples", &_maxSamples);
+
+ if ( _maxSamples > MAXCHANNELS )
+ _maxSamples = MAXCHANNELS;
+
+ SampleManager.SetSpeakerConfig(speaker_type);
+
+ //obtain a 3D sample handles
+ for ( U32 i = 0; i < _maxSamples; ++i )
+ {
+ opened_samples[i] = AIL_allocate_3D_sample_handle(opened_provider);
+ if ( opened_samples[i] != NULL )
+ AIL_set_3D_sample_effects_level(opened_samples[i], 0.0f);
+ }
+
+ return true;
+ }
+ }
+
+ return false;
+}
+
+void
+cSampleManager::SetSpeakerConfig(int32 which)
+{
+ switch ( which )
+ {
+ case 1:
+ speaker_type=AIL_3D_2_SPEAKER;
+ break;
+
+ case 2:
+ speaker_type=AIL_3D_HEADPHONE;
+ break;
+
+ case 3:
+ speaker_type=AIL_3D_4_SPEAKER;
+ break;
+
+ default:
+ return;
+ break;
+ }
+
+ if (opened_provider)
+ AIL_set_3D_speaker_type(opened_provider, speaker_type);
+}
+
+uint32
+cSampleManager::GetMaximumSupportedChannels(void)
+{
+ if ( _maxSamples > MAXCHANNELS )
+ return MAXCHANNELS;
+
+ return _maxSamples;
+}
+
+int8
+cSampleManager::GetCurrent3DProviderIndex(void)
+{
+ return curprovider;
+}
+
+int8
+cSampleManager::SetCurrent3DProvider(uint8 nProvider)
+{
+ S32 savedprovider = curprovider;
+
+ if ( nProvider < m_nNumberOfProviders )
+ {
+ if ( set_new_provider(nProvider) )
+ return curprovider;
+ else if ( savedprovider != -1 && savedprovider < m_nNumberOfProviders && set_new_provider(savedprovider) )
+ return curprovider;
+ else
+ return -1;
+ }
+ else
+ return curprovider;
+}
+
+static bool
+_ResolveLink(char const *path, char *out)
+{
+ IShellLink* psl;
+ WIN32_FIND_DATA fd;
+ char filepath[MAX_PATH];
+
+ CoInitialize(NULL);
+
+ if (SUCCEEDED( CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&psl ) ))
+ {
+ IPersistFile *ppf;
+
+ if (SUCCEEDED(psl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf)))
+ {
+ WCHAR wpath[MAX_PATH];
+
+ MultiByteToWideChar(CP_ACP, 0, path, -1, wpath, MAX_PATH);
+
+ if (SUCCEEDED(ppf->Load(wpath, STGM_READ)))
+ {
+ /* Resolve the link */
+ if (SUCCEEDED(psl->Resolve(NULL, SLR_ANY_MATCH|SLR_NO_UI|SLR_NOSEARCH)))
+ {
+ strcpy(filepath, path);
+
+ if (SUCCEEDED(psl->GetPath(filepath, MAX_PATH, &fd, SLGP_UNCPRIORITY)))
+ {
+ OutputDebugString(fd.cFileName);
+
+ strcpy(out, filepath);
+ // FIX: Release the objects. Taken from SA.
+#ifdef FIX_BUGS
+ ppf->Release();
+ psl->Release();
+#endif
+ return true;
+ }
+ }
+ }
+
+ ppf->Release();
+ }
+ psl->Release();
+ }
+
+ return false;
+}
+
+static void
+_FindMP3s(void)
+{
+ tMP3Entry *pList;
+ bool bShortcut;
+ bool bInitFirstEntry;
+ HANDLE hFind;
+ char path[MAX_PATH];
+ char filepath[MAX_PATH*2];
+ S32 total_ms;
+ WIN32_FIND_DATA fd;
+
+
+ if ( GetCurrentDirectory(MAX_PATH, _mp3DirectoryPath) == 0 )
+ {
+ GetLastError();
+ return;
+ }
+
+ OutputDebugString("Finding MP3s...");
+ strcpy(path, _mp3DirectoryPath);
+ strcat(path, "\\MP3\\");
+
+ strcpy(_mp3DirectoryPath, path);
+ OutputDebugString(_mp3DirectoryPath);
+
+ strcat(path, "*");
+
+ hFind = FindFirstFile(path, &fd);
+
+ if ( hFind == INVALID_HANDLE_VALUE )
+ {
+ GetLastError();
+ return;
+ }
+
+ strcpy(filepath, _mp3DirectoryPath);
+ strcat(filepath, fd.cFileName);
+
+ int32 filepathlen = strlen(filepath);
+
+ if ( filepathlen <= 0)
+ {
+ FindClose(hFind);
+ return;
+ }
+
+ FILE *f = fopen("MP3\\MP3Report.txt", "w");
+
+ if ( f )
+ {
+ fprintf(f, "MP3 Report File\n\n");
+ fprintf(f, "\"%s\"", fd.cFileName);
+ }
+
+
+ if ( filepathlen > 4 )
+ {
+ if ( !strcmp(&filepath[filepathlen - 4], ".lnk") )
+ {
+ if ( _ResolveLink(filepath, filepath) )
+ {
+ OutputDebugString("Resolving Link");
+ OutputDebugString(filepath);
+
+ if ( f ) fprintf(f, " - shortcut to \"%s\"", filepath);
+ }
+ else
+ {
+ if ( f ) fprintf(f, " - couldn't resolve shortcut");
+ }
+
+ bShortcut = true;
+ }
+ else
+ bShortcut = false;
+ }
+
+ mp3Stream[0] = AIL_open_stream(DIG, filepath, 0);
+ if ( mp3Stream[0] )
+ {
+ AIL_stream_ms_position(mp3Stream[0], &total_ms, NULL);
+
+ AIL_close_stream(mp3Stream[0]);
+ mp3Stream[0] = NULL;
+
+ OutputDebugString(fd.cFileName);
+
+ _pMP3List = new tMP3Entry;
+
+ if ( _pMP3List == NULL )
+ {
+ FindClose(hFind);
+
+ if ( f )
+ fclose(f);
+
+ return;
+ }
+
+ nNumMP3s = 1;
+
+ strcpy(_pMP3List->aFilename, fd.cFileName);
+
+ _pMP3List->nTrackLength = total_ms;
+
+ _pMP3List->pNext = NULL;
+
+ pList = _pMP3List;
+
+ if ( bShortcut )
+ {
+ _pMP3List->pLinkPath = new char[MAX_PATH*2];
+ strcpy(_pMP3List->pLinkPath, filepath);
+ }
+ else
+ {
+ _pMP3List->pLinkPath = NULL;
+ }
+
+ if ( f ) fprintf(f, " - OK\n");
+
+ bInitFirstEntry = false;
+ }
+ else
+ {
+ strcat(filepath, " - NOT A VALID MP3");
+
+ OutputDebugString(filepath);
+
+ if ( f ) fprintf(f, " - not an MP3 or supported MP3 type\n");
+
+ bInitFirstEntry = true;
+ }
+
+ while ( true )
+ {
+ if ( !FindNextFile(hFind, &fd) )
+ break;
+
+ if ( bInitFirstEntry )
+ {
+ strcpy(filepath, _mp3DirectoryPath);
+ strcat(filepath, fd.cFileName);
+
+ int32 filepathlen = strlen(filepath);
+
+ if ( f ) fprintf(f, "\"%s\"", fd.cFileName);
+
+ if ( filepathlen > 0 )
+ {
+ if ( filepathlen > 4 )
+ {
+ if ( !strcmp(&filepath[filepathlen - 4], ".lnk") )
+ {
+ if ( _ResolveLink(filepath, filepath) )
+ {
+ OutputDebugString("Resolving Link");
+ OutputDebugString(filepath);
+
+ if ( f ) fprintf(f, " - shortcut to \"%s\"", filepath);
+ }
+ else
+ {
+ if ( f ) fprintf(f, " - couldn't resolve shortcut");
+ }
+
+ bShortcut = true;
+ }
+ else
+ {
+ bShortcut = false;
+
+ if ( filepathlen > MAX_PATH )
+ {
+ if ( f ) fprintf(f, " - Filename and path too long - %s - IGNORED)\n", filepath);
+
+ continue;
+ }
+ }
+ }
+
+ mp3Stream[0] = AIL_open_stream(DIG, filepath, 0);
+ if ( mp3Stream[0] )
+ {
+ AIL_stream_ms_position(mp3Stream[0], &total_ms, NULL);
+
+ AIL_close_stream(mp3Stream[0]);
+ mp3Stream[0] = NULL;
+
+ OutputDebugString(fd.cFileName);
+
+ _pMP3List = new tMP3Entry;
+
+ if ( _pMP3List == NULL)
+ break;
+
+ nNumMP3s = 1;
+
+ strcpy(_pMP3List->aFilename, fd.cFileName);
+
+ _pMP3List->nTrackLength = total_ms;
+ _pMP3List->pNext = NULL;
+
+ if ( bShortcut )
+ {
+ _pMP3List->pLinkPath = new char [MAX_PATH*2];
+ strcpy(_pMP3List->pLinkPath, filepath);
+ }
+ else
+ {
+ _pMP3List->pLinkPath = NULL;
+ }
+
+ pList = _pMP3List;
+
+ if ( f ) fprintf(f, " - OK\n");
+
+ bInitFirstEntry = false;
+ }
+ else
+ {
+ strcat(filepath, " - NOT A VALID MP3");
+ OutputDebugString(filepath);
+
+ if ( f ) fprintf(f, " - not an MP3 or supported MP3 type\n");
+ }
+ }
+ }
+ else
+ {
+ strcpy(filepath, _mp3DirectoryPath);
+ strcat(filepath, fd.cFileName);
+
+ int32 filepathlen = strlen(filepath);
+
+ if ( filepathlen > 0 )
+ {
+ if ( f ) fprintf(f, "\"%s\"", fd.cFileName);
+
+ if ( filepathlen > 4 )
+ {
+ if ( !strcmp(&filepath[filepathlen - 4], ".lnk") )
+ {
+ if ( _ResolveLink(filepath, filepath) )
+ {
+ OutputDebugString("Resolving Link");
+ OutputDebugString(filepath);
+
+ if ( f ) fprintf(f, " - shortcut to \"%s\"", filepath);
+ }
+ else
+ {
+ if ( f ) fprintf(f, " - couldn't resolve shortcut");
+ }
+
+ bShortcut = true;
+ }
+ else
+ {
+ bShortcut = false;
+ }
+ }
+
+ mp3Stream[0] = AIL_open_stream(DIG, filepath, 0);
+ if ( mp3Stream[0] )
+ {
+ AIL_stream_ms_position(mp3Stream[0], &total_ms, NULL);
+
+ AIL_close_stream(mp3Stream[0]);
+ mp3Stream[0] = NULL;
+
+ pList->pNext = new tMP3Entry;
+
+ tMP3Entry *e = pList->pNext;
+
+ if ( e == NULL )
+ break;
+
+ pList = pList->pNext;
+
+ strcpy(e->aFilename, fd.cFileName);
+ e->nTrackLength = total_ms;
+ e->pNext = NULL;
+
+ if ( bShortcut )
+ {
+ e->pLinkPath = new char [MAX_PATH*2];
+ strcpy(e->pLinkPath, filepath);
+ }
+ else
+ {
+ e->pLinkPath = NULL;
+ }
+
+ nNumMP3s++;
+
+ OutputDebugString(fd.cFileName);
+
+ if ( f ) fprintf(f, " - OK\n");
+ }
+ else
+ {
+ strcat(filepath, " - NOT A VALID MP3");
+ OutputDebugString(filepath);
+
+ if ( f ) fprintf(f, " - not an MP3 or supported MP3 type\n");
+ }
+ }
+ }
+ }
+
+ if ( f )
+ {
+ fprintf(f, "\nTOTAL SUPPORTED MP3s: %d\n", nNumMP3s);
+ fclose(f);
+ }
+
+ FindClose(hFind);
+}
+
+static void
+_DeleteMP3Entries(void)
+{
+ tMP3Entry *e = _pMP3List;
+
+ while ( e != NULL )
+ {
+ tMP3Entry *next = e->pNext;
+
+ if ( next == NULL )
+ next = NULL;
+
+ if ( e->pLinkPath != NULL )
+ {
+#ifndef FIX_BUGS
+ delete e->pLinkPath; // BUG: should be delete []
+#else
+ delete[] e->pLinkPath;
+#endif
+ e->pLinkPath = NULL;
+ }
+
+ delete e;
+
+ if ( next )
+ e = next;
+ else
+ e = NULL;
+
+ nNumMP3s--;
+ }
+
+
+ if ( nNumMP3s != 0 )
+ {
+ OutputDebugString("Not all MP3 entries were deleted");
+ nNumMP3s = 0;
+ }
+
+ _pMP3List = NULL;
+}
+
+static tMP3Entry *
+_GetMP3EntryByIndex(uint32 idx)
+{
+ uint32 n = ( idx < nNumMP3s ) ? idx : 0;
+
+ if ( _pMP3List != NULL )
+ {
+ tMP3Entry *e = _pMP3List;
+
+ for ( uint32 i = 0; i < n; i++ )
+ e = e->pNext;
+
+ return e;
+
+ }
+
+ return NULL;
+}
+
+static inline bool
+_GetMP3PosFromStreamPos(uint32 *pPosition, tMP3Entry **pEntry)
+{
+ _CurMP3Index = 0;
+
+ for ( *pEntry = _pMP3List; *pEntry != NULL; *pEntry = (*pEntry)->pNext )
+ {
+ if ( *pPosition >= (*pEntry)->nTrackStreamPos
+ && *pPosition < (*pEntry)->nTrackLength + (*pEntry)->nTrackStreamPos )
+ {
+ *pPosition -= (*pEntry)->nTrackStreamPos;
+ _CurMP3Pos = *pPosition;
+
+ return true;
+ }
+
+ _CurMP3Index++;
+ }
+
+ *pPosition = 0;
+ *pEntry = _pMP3List;
+ _CurMP3Pos = 0;
+ _CurMP3Index = 0;
+
+ return false;
+}
+
+bool
+cSampleManager::IsMP3RadioChannelAvailable(void)
+{
+ return nNumMP3s != 0;
+}
+
+void
+cSampleManager::ReleaseDigitalHandle(void)
+{
+ if ( DIG )
+ {
+ prevprovider = curprovider;
+ release_existing();
+ curprovider = -1;
+ AIL_digital_handle_release(DIG);
+ }
+}
+
+void
+cSampleManager::ReacquireDigitalHandle(void)
+{
+ if ( DIG )
+ {
+ AIL_digital_handle_reacquire(DIG);
+ if ( prevprovider != -1 )
+ set_new_provider(prevprovider);
+ }
+}
+
+bool
+cSampleManager::Initialise(void)
+{
+ TRACE("start");
+
+ if ( _bSampmanInitialised )
+ return true;
+
+ {
+ for ( int32 i = 0; i < TOTAL_AUDIO_SAMPLES; i++ )
+ {
+ m_aSamples[i].nOffset = 0;
+ m_aSamples[i].nSize = 0;
+ m_aSamples[i].nFrequency = 22050;
+ m_aSamples[i].nLoopStart = 0;
+ m_aSamples[i].nLoopEnd = -1;
+ }
+
+ m_nEffectsVolume = MAX_VOLUME;
+ m_nMusicVolume = MAX_VOLUME;
+ m_nEffectsFadeVolume = MAX_VOLUME;
+ m_nMusicFadeVolume = MAX_VOLUME;
+
+ m_nMonoMode = 0;
+ }
+
+ // miles
+ TRACE("MILES");
+ {
+ curprovider = -1;
+ prevprovider = -1;
+
+ _usingMilesFast2D = false;
+ usingEAX=0;
+ usingEAX3=0;
+
+ _fEffectsLevel = 0.0f;
+
+ _maxSamples = 0;
+
+ opened_provider = NULL;
+ DIG = NULL;
+
+ for ( int32 i = 0; i < MAXCHANNELS; i++ )
+ opened_samples[i] = NULL;
+ }
+
+ // banks
+ TRACE("banks");
+ {
+ fpSampleDescHandle = NULL;
+ fpSampleDataHandle = NULL;
+
+ _nSampleDataEndOffset = 0;
+
+ for ( int32 i = 0; i < MAX_SAMPLEBANKS; i++ )
+ {
+ bSampleBankLoaded[i] = false;
+ nSampleBankDiscStartOffset[i] = 0;
+ nSampleBankSize[i] = 0;
+ nSampleBankMemoryStartAddress[i] = 0;
+ }
+ }
+
+ // pedsfx
+ TRACE("pedsfx");
+ {
+ for ( int32 i = 0; i < MAX_PEDSFX; i++ )
+ {
+ nPedSlotSfx[i] = NO_SAMPLE;
+ nPedSlotSfxAddr[i] = 0;
+ }
+
+ nCurrentPedSlot = 0;
+ }
+
+ // channel volume
+ TRACE("vol");
+ {
+ for ( int32 i = 0; i < MAXCHANNELS+MAX2DCHANNELS; i++ )
+ nChannelVolume[i] = 0;
+ }
+
+ TRACE("mss");
+ {
+ AIL_set_redist_directory( "mss" );
+
+ AIL_startup();
+
+ AIL_set_preference(DIG_MIXER_CHANNELS, MAX_DIGITAL_MIXER_CHANNELS);
+
+ DIG = AIL_open_digital_driver(DIGITALRATE, DIGITALBITS, DIGITALCHANNELS, 0);
+ if ( DIG == NULL )
+ {
+ OutputDebugString(AIL_last_error());
+ Terminate();
+ return false;
+ }
+
+ add_providers();
+
+ if ( !InitialiseSampleBanks() )
+ {
+ Terminate();
+ return false;
+ }
+
+ nSampleBankMemoryStartAddress[SAMPLEBANK_MAIN] = (int32)AIL_mem_alloc_lock(nSampleBankSize[SAMPLEBANK_MAIN]);
+ if ( !nSampleBankMemoryStartAddress[SAMPLEBANK_MAIN] )
+ {
+ Terminate();
+ return false;
+ }
+
+ nSampleBankMemoryStartAddress[SAMPLEBANK_PED] = (int32)AIL_mem_alloc_lock(PED_BLOCKSIZE*MAX_PEDSFX);
+
+ }
+
+ TRACE("cdrom");
+
+ S32 tatalms;
+ char filepath[MAX_PATH];
+
+ {
+ m_bInitialised = false;
+
+ while (true)
+ {
+ int32 drive = 'C';
+
+ do
+ {
+ char latter[2];
+
+ latter[0] = drive;
+ latter[1] = '\0';
+
+ strcpy(m_szCDRomRootPath, latter);
+ strcat(m_szCDRomRootPath, ":\\");
+
+ if ( GetDriveType(m_szCDRomRootPath) == DRIVE_CDROM )
+ {
+ strcpy(filepath, m_szCDRomRootPath);
+ strcat(filepath, StreamedNameTable[0]);
+
+ FILE *f = fopen(filepath, "rb");
+
+ if ( f )
+ {
+ fclose(f);
+
+ bool bFileNotFound = false;
+
+ for ( int32 i = 0; i < TOTAL_STREAMED_SOUNDS; i++ )
+ {
+ strcpy(filepath, m_szCDRomRootPath);
+ strcat(filepath, StreamedNameTable[i]);
+
+ mp3Stream[0] = AIL_open_stream(DIG, filepath, 0);
+
+ if ( mp3Stream[0] )
+ {
+ AIL_stream_ms_position(mp3Stream[0], &tatalms, NULL);
+
+ AIL_close_stream(mp3Stream[0]);
+ mp3Stream[0] = NULL;
+
+ nStreamLength[i] = tatalms;
+ }
+ else
+ {
+ bFileNotFound = true;
+ break;
+ }
+ }
+
+ if ( !bFileNotFound )
+ {
+ m_bInitialised = true;
+ break;
+ }
+ else
+ {
+ m_bInitialised = false;
+ continue;
+ }
+ }
+ }
+
+ } while ( ++drive <= 'Z' );
+
+ if ( !m_bInitialised )
+ {
+#if !defined(GTA3_STEAM_PATCH) && !defined(NO_CDCHECK)
+ FrontEndMenuManager.WaitForUserCD();
+ if ( FrontEndMenuManager.m_bQuitGameNoCD )
+ {
+ Terminate();
+ return false;
+ }
+ continue;
+#else
+ m_bInitialised = true;
+#endif
+ }
+
+ break;
+ }
+ }
+
+#if defined(GTA3_1_1_PATCH) || defined(GTA3_STEAM_PATCH) || defined(NO_CDCHECK)
+ // hddaudio
+ /**
+ Option for user to play audio files directly from hard disk.
+ Copy the contents of the PLAY discs Audio directory into your installed Grand Theft Auto III Audio directory.
+ Grand Theft Auto III still requires the presence of the PLAY disc when started.
+ This may give better performance on some machines (though worse on others).
+ **/
+ TRACE("hddaudio 1.1 patch");
+ {
+ int32 streamLength[TOTAL_STREAMED_SOUNDS];
+
+ bool bFileNotFound = false;
+ char rootpath[MAX_PATH];
+
+ strcpy(_aHDDPath, m_szCDRomRootPath);
+ rootpath[0] = '\0';
+
+ FILE *f = fopen(StreamedNameTable[0], "rb");
+
+ if ( f )
+ {
+ fclose(f);
+
+ for ( int32 i = 0; i < TOTAL_STREAMED_SOUNDS; i++ )
+ {
+ strcpy(filepath, rootpath);
+ strcat(filepath, StreamedNameTable[i]);
+
+ mp3Stream[0] = AIL_open_stream(DIG, filepath, 0);
+
+ if ( mp3Stream[0] )
+ {
+ AIL_stream_ms_position(mp3Stream[0], &tatalms, NULL);
+
+ AIL_close_stream(mp3Stream[0]);
+ mp3Stream[0] = NULL;
+
+ streamLength[i] = tatalms;
+ }
+ else
+ {
+ bFileNotFound = true;
+ break;
+ }
+ }
+
+ }
+ else
+ bFileNotFound = true;
+
+ if ( !bFileNotFound )
+ {
+ strcpy(m_szCDRomRootPath, rootpath);
+
+ for ( int32 i = 0; i < TOTAL_STREAMED_SOUNDS; i++ )
+ nStreamLength[i] = streamLength[i];
+
+ _bUseHDDAudio = true;
+ }
+ else
+ _bUseHDDAudio = false;
+ }
+#endif
+
+ TRACE("stream");
+ {
+ for ( int32 i = 0; i < MAX_MP3STREAMS; i++ )
+ {
+ mp3Stream [i] = NULL;
+ nStreamPan [i] = 63;
+ nStreamVolume[i] = 100;
+ }
+ }
+
+ for ( int32 i = 0; i < MAX2DCHANNELS; i++ )
+ {
+ opened_2dsamples[i] = AIL_allocate_sample_handle(DIG);
+ if ( opened_2dsamples[i] )
+ {
+ AIL_init_sample(opened_2dsamples[i]);
+ AIL_set_sample_type(opened_2dsamples[i], DIG_F_MONO_16, DIG_PCM_SIGN);
+ }
+ }
+
+ TRACE("providerset");
+ {
+ _bSampmanInitialised = true;
+
+ U32 n = 0;
+
+ while ( n < m_nNumberOfProviders )
+ {
+ if ( !strcmp(providers[n].name, "Miles Fast 2D Positional Audio") )
+ {
+ set_new_provider(n);
+ break;
+ }
+ n++;
+ }
+
+ if ( n == m_nNumberOfProviders )
+ {
+ Terminate();
+ return false;
+ }
+ }
+
+ TRACE("bank");
+
+ LoadSampleBank(SAMPLEBANK_MAIN);
+
+ // mp3
+ TRACE("mp3");
+ {
+ nNumMP3s = 0;
+
+ _pMP3List = NULL;
+
+ _FindMP3s();
+
+ if ( nNumMP3s != 0 )
+ {
+ nStreamLength[STREAMED_SOUND_RADIO_MP3_PLAYER] = 0;
+
+ for ( tMP3Entry *e = _pMP3List; e != NULL; e = e->pNext )
+ {
+ e->nTrackStreamPos = nStreamLength[STREAMED_SOUND_RADIO_MP3_PLAYER];
+ nStreamLength[STREAMED_SOUND_RADIO_MP3_PLAYER] += e->nTrackLength;
+ }
+
+ time_t t = time(NULL);
+ tm *localtm;
+ bool bUseRandomTable;
+
+ if ( t == -1 )
+ bUseRandomTable = true;
+ else
+ {
+ bUseRandomTable = false;
+ localtm = localtime(&t);
+ }
+
+ int32 randval;
+ if ( bUseRandomTable )
+ randval = AudioManager.GetRandomNumber(1);
+ else
+ randval = localtm->tm_sec * localtm->tm_min;
+
+ _CurMP3Index = randval % nNumMP3s;
+
+ tMP3Entry *randmp3 = _pMP3List;
+ for ( int32 i = randval % nNumMP3s; i > 0; --i)
+ randmp3 = randmp3->pNext;
+
+ if ( bUseRandomTable )
+ _CurMP3Pos = AudioManager.GetRandomNumber(0) % randmp3->nTrackLength;
+ else
+ {
+ if ( localtm->tm_sec > 0 )
+ {
+ int32 s = localtm->tm_sec;
+ _CurMP3Pos = s*s*s*s*s*s*s*s % randmp3->nTrackLength;
+ }
+ else
+ _CurMP3Pos = AudioManager.GetRandomNumber(0) % randmp3->nTrackLength;
+ }
+ }
+ else
+ _CurMP3Pos = 0;
+
+ _bIsMp3Active = false;
+ }
+
+ TRACE("end");
+
+ return true;
+}
+
+void
+cSampleManager::Terminate(void)
+{
+ for ( int32 i = 0; i < MAX_MP3STREAMS; i++ )
+ {
+ if ( mp3Stream[i] )
+ {
+ AIL_pause_stream(mp3Stream[i], 1);
+ AIL_close_stream(mp3Stream[i]);
+ mp3Stream[i] = NULL;
+ }
+ }
+
+ for ( int32 i = 0; i < MAX2DCHANNELS; i++ )
+ {
+ if ( opened_2dsamples[i] )
+ {
+ AIL_release_sample_handle(opened_2dsamples[i]);
+ opened_2dsamples[i] = NULL;
+ }
+ }
+
+ release_existing();
+
+ _DeleteMP3Entries();
+
+ if ( nSampleBankMemoryStartAddress[SAMPLEBANK_MAIN] != 0 )
+ {
+ AIL_mem_free_lock((void *)nSampleBankMemoryStartAddress[SAMPLEBANK_MAIN]);
+ nSampleBankMemoryStartAddress[SAMPLEBANK_MAIN] = 0;
+ }
+
+ if ( nSampleBankMemoryStartAddress[SAMPLEBANK_PED] != 0 )
+ {
+ AIL_mem_free_lock((void *)nSampleBankMemoryStartAddress[SAMPLEBANK_PED]);
+ nSampleBankMemoryStartAddress[SAMPLEBANK_PED] = 0;
+ }
+
+ if ( DIG )
+ {
+ AIL_close_digital_driver(DIG);
+ DIG = NULL;
+ }
+
+ AIL_shutdown();
+
+ _bSampmanInitialised = false;
+}
+
+bool
+cSampleManager::CheckForAnAudioFileOnCD(void)
+{
+#if !defined(GTA3_STEAM_PATCH) && !defined(NO_CDCHECK)
+ char filepath[MAX_PATH];
+
+#if defined(GTA3_1_1_PATCH)
+ if (_bUseHDDAudio)
+ strcpy(filepath, _aHDDPath);
+ else
+ strcpy(filepath, m_szCDRomRootPath);
+#else
+ strcpy(filepath, m_szCDRomRootPath);
+#endif // #if defined(GTA3_1_1_PATCH)
+
+ strcat(filepath, StreamedNameTable[AudioManager.GetRandomNumber(1) % TOTAL_STREAMED_SOUNDS]);
+
+ FILE *f = fopen(filepath, "rb");
+
+ if ( f )
+ {
+ fclose(f);
+
+ return true;
+ }
+
+ return false;
+
+#else
+ return true;
+#endif // #if !defined(GTA3_STEAM_PATCH) && !defined(NO_CDCHECK)
+}
+
+char
+cSampleManager::GetCDAudioDriveLetter(void)
+{
+#if defined(GTA3_1_1_PATCH) || defined(GTA3_STEAM_PATCH) || defined(NO_CDCHECK)
+ if (_bUseHDDAudio)
+ {
+ if ( strlen(_aHDDPath) != 0 )
+ return _aHDDPath[0];
+ else
+ return '\0';
+ }
+ else
+ {
+ if ( strlen(m_szCDRomRootPath) != 0 )
+ return m_szCDRomRootPath[0];
+ else
+ return '\0';
+ }
+#else
+ if ( strlen(m_szCDRomRootPath) != 0 )
+ return m_szCDRomRootPath[0];
+ else
+ return '\0';
+#endif
+}
+
+void
+cSampleManager::UpdateEffectsVolume(void) //[Y], cSampleManager::UpdateSoundBuffers ?
+{
+ if ( _bSampmanInitialised )
+ {
+ for ( int32 i = 0; i < MAXCHANNELS+MAX2DCHANNELS; i++ )
+ {
+ if ( i < MAXCHANNELS )
+ {
+ if ( opened_samples[i] && GetChannelUsedFlag(i) )
+ {
+ if ( nChannelVolume[i] )
+ {
+ AIL_set_3D_sample_volume(opened_samples[i],
+ m_nEffectsFadeVolume * nChannelVolume[i] * m_nEffectsVolume >> 14);
+ }
+ }
+ }
+ else
+ {
+ if ( opened_2dsamples[i - MAXCHANNELS] )
+ {
+ if ( GetChannelUsedFlag(i - MAXCHANNELS) )
+ {
+ if ( nChannelVolume[i - MAXCHANNELS] )
+ {
+ AIL_set_sample_volume(opened_2dsamples[i - MAXCHANNELS],
+ m_nEffectsFadeVolume * nChannelVolume[i - MAXCHANNELS] * m_nEffectsVolume >> 14);
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+void
+cSampleManager::SetEffectsMasterVolume(uint8 nVolume)
+{
+ m_nEffectsVolume = nVolume;
+ UpdateEffectsVolume();
+}
+
+void
+cSampleManager::SetMusicMasterVolume(uint8 nVolume)
+{
+ m_nMusicVolume = nVolume;
+}
+
+void
+cSampleManager::SetEffectsFadeVolume(uint8 nVolume)
+{
+ m_nEffectsFadeVolume = nVolume;
+ UpdateEffectsVolume();
+}
+
+void
+cSampleManager::SetMusicFadeVolume(uint8 nVolume)
+{
+ m_nMusicFadeVolume = nVolume;
+}
+
+bool
+cSampleManager::LoadSampleBank(uint8 nBank)
+{
+ if ( CTimer::GetIsCodePaused() )
+ return false;
+
+ if ( MusicManager.IsInitialised()
+ && MusicManager.GetMusicMode() == MUSICMODE_CUTSCENE
+ && nBank != SAMPLEBANK_MAIN )
+ {
+ return false;
+ }
+
+ if ( fseek(fpSampleDataHandle, nSampleBankDiscStartOffset[nBank], SEEK_SET) != 0 )
+ return false;
+
+ if ( fread((void *)nSampleBankMemoryStartAddress[nBank], 1, nSampleBankSize[nBank],fpSampleDataHandle) != nSampleBankSize[nBank] )
+ return false;
+
+ bSampleBankLoaded[nBank] = true;
+
+ return true;
+}
+
+void
+cSampleManager::UnloadSampleBank(uint8 nBank)
+{
+ bSampleBankLoaded[nBank] = false;
+}
+
+bool
+cSampleManager::IsSampleBankLoaded(uint8 nBank)
+{
+ return bSampleBankLoaded[nBank];
+}
+
+bool
+cSampleManager::IsPedCommentLoaded(uint32 nComment)
+{
+ uint8 slot;
+
+ for ( int32 i = 0; i < _TODOCONST(3); i++ )
+ {
+ slot = nCurrentPedSlot - i - 1;
+ if ( nComment == nPedSlotSfx[slot] )
+ return true;
+ }
+
+ return false;
+}
+
+int32
+cSampleManager::_GetPedCommentSlot(uint32 nComment)
+{
+ uint8 slot;
+
+ for ( int32 i = 0; i < _TODOCONST(3); i++ )
+ {
+ slot = nCurrentPedSlot - i - 1;
+ if ( nComment == nPedSlotSfx[slot] )
+ return slot;
+ }
+
+ return -1;
+}
+
+bool
+cSampleManager::LoadPedComment(uint32 nComment)
+{
+ if ( CTimer::GetIsCodePaused() )
+ return false;
+
+ // no talking peds during cutsenes or the game end
+ if ( MusicManager.IsInitialised() )
+ {
+ switch ( MusicManager.GetMusicMode() )
+ {
+ case MUSICMODE_CUTSCENE:
+ {
+ return false;
+
+ break;
+ }
+
+ case MUSICMODE_FRONTEND:
+ {
+ if ( MusicManager.GetCurrentTrack() == STREAMED_SOUND_GAME_COMPLETED )
+ return false;
+
+ break;
+ }
+ }
+ }
+
+ if ( fseek(fpSampleDataHandle, m_aSamples[nComment].nOffset, SEEK_SET) != 0 )
+ return false;
+
+ if ( fread((void *)(nSampleBankMemoryStartAddress[SAMPLEBANK_PED] + PED_BLOCKSIZE*nCurrentPedSlot), 1, m_aSamples[nComment].nSize, fpSampleDataHandle) != m_aSamples[nComment].nSize )
+ return false;
+
+ nPedSlotSfxAddr[nCurrentPedSlot] = nSampleBankMemoryStartAddress[SAMPLEBANK_PED] + PED_BLOCKSIZE*nCurrentPedSlot;
+ nPedSlotSfx [nCurrentPedSlot] = nComment;
+
+ if ( ++nCurrentPedSlot >= MAX_PEDSFX )
+ nCurrentPedSlot = 0;
+
+ return true;
+}
+
+int32
+cSampleManager::GetSampleBaseFrequency(uint32 nSample)
+{
+ return m_aSamples[nSample].nFrequency;
+}
+
+int32
+cSampleManager::GetSampleLoopStartOffset(uint32 nSample)
+{
+ return m_aSamples[nSample].nLoopStart;
+}
+
+int32
+cSampleManager::GetSampleLoopEndOffset(uint32 nSample)
+{
+ return m_aSamples[nSample].nLoopEnd;
+}
+
+uint32
+cSampleManager::GetSampleLength(uint32 nSample)
+{
+ return m_aSamples[nSample].nSize >> 1;
+}
+
+bool
+cSampleManager::UpdateReverb(void)
+{
+ if ( !usingEAX )
+ return false;
+
+ if ( AudioManager.GetFrameCounter() & 15 )
+ return false;
+
+ float y = AudioManager.GetReflectionsDistance(REFLECTION_TOP) + AudioManager.GetReflectionsDistance(REFLECTION_BOTTOM);
+ float x = AudioManager.GetReflectionsDistance(REFLECTION_LEFT) + AudioManager.GetReflectionsDistance(REFLECTION_RIGHT);
+ float z = AudioManager.GetReflectionsDistance(REFLECTION_UP);
+
+ float normy = norm(y, 5.0f, 40.0f);
+ float normx = norm(x, 5.0f, 40.0f);
+ float normz = norm(z, 5.0f, 40.0f);
+
+ float fRatio;
+
+ if ( normy == 0.0f )
+ {
+ if ( normx == 0.0f )
+ {
+ if ( normz == 0.0f )
+ fRatio = 0.3f;
+ else
+ fRatio = 0.5f;
+ }
+ else
+ {
+ fRatio = 0.3f;
+ }
+ }
+ else
+ {
+ if ( normx == 0.0f )
+ {
+ if ( normz == 0.0f )
+ fRatio = 0.3f;
+ else
+ fRatio = 0.5f;
+ }
+ else
+ {
+ if ( normz == 0.0f )
+ fRatio = 0.3f;
+ else
+ fRatio = (normy+normx+normz) / 3.0f;
+ }
+ }
+
+ fRatio = clamp(fRatio, usingEAX3==1 ? 0.0f : 0.30f, 1.0f);
+
+ if ( fRatio == _fPrevEaxRatioDestination )
+ return false;
+
+ if ( usingEAX3 )
+ {
+ if ( EAX3ListenerInterpolate(&StartEAX3, &FinishEAX3, fRatio, &EAX3Params, false) )
+ {
+ AIL_set_3D_provider_preference(opened_provider, "EAX all parameters", &EAX3Params);
+ _fEffectsLevel = 1.0f - fRatio * 0.5f;
+ }
+ }
+ else
+ {
+ if ( _usingMilesFast2D )
+ _fEffectsLevel = (1.0f - fRatio) * 0.4f;
+ else
+ _fEffectsLevel = (1.0f - fRatio) * 0.7f;
+ }
+
+ _fPrevEaxRatioDestination = fRatio;
+
+ return true;
+}
+
+void
+cSampleManager::SetChannelReverbFlag(uint32 nChannel, uint8 nReverbFlag)
+{
+ bool b2d = false;
+
+ switch ( nChannel )
+ {
+ case CHANNEL2D:
+ {
+ b2d = true;
+ break;
+ }
+ }
+
+ if ( usingEAX )
+ {
+ if ( nReverbFlag != 0 )
+ {
+ if ( !b2d )
+ AIL_set_3D_sample_effects_level(opened_samples[nChannel], _fEffectsLevel);
+ }
+ else
+ {
+ if ( !b2d )
+ AIL_set_3D_sample_effects_level(opened_samples[nChannel], 0.0f);
+ }
+ }
+}
+
+bool
+cSampleManager::InitialiseChannel(uint32 nChannel, uint32 nSfx, uint8 nBank)
+{
+ bool b2d = false;
+
+ switch ( nChannel )
+ {
+ case CHANNEL2D:
+ {
+ b2d = true;
+ break;
+ }
+ }
+
+ int32 addr;
+
+ if ( nSfx < SAMPLEBANK_MAX )
+ {
+ if ( !IsSampleBankLoaded(nBank) )
+ return false;
+
+ addr = nSampleBankMemoryStartAddress[nBank] + m_aSamples[nSfx].nOffset - m_aSamples[BankStartOffset[nBank]].nOffset;
+ }
+ else
+ {
+ if ( !IsPedCommentLoaded(nSfx) )
+ return false;
+
+ int32 slot = _GetPedCommentSlot(nSfx);
+
+ addr = nPedSlotSfxAddr[slot];
+ }
+
+ if ( b2d )
+ {
+ if ( opened_2dsamples[nChannel - MAXCHANNELS] )
+ {
+ AIL_set_sample_address(opened_2dsamples[nChannel - MAXCHANNELS], (void *)addr, m_aSamples[nSfx].nSize);
+ return true;
+ }
+ else
+ return false;
+ }
+ else
+ {
+ AILSOUNDINFO info;
+
+ info.format = WAVE_FORMAT_PCM;
+ info.data_ptr = (void *)addr;
+ info.channels = 1;
+ info.data_len = m_aSamples[nSfx].nSize;
+ info.rate = m_aSamples[nSfx].nFrequency;
+ info.bits = 16;
+
+ if ( AIL_set_3D_sample_info(opened_samples[nChannel], &info) == 0 )
+ {
+ OutputDebugString(AIL_last_error());
+ return false;
+ }
+
+ return true;
+ }
+}
+
+void
+cSampleManager::SetChannelEmittingVolume(uint32 nChannel, uint32 nVolume)
+{
+ uint32 vol = nVolume;
+ if ( vol > MAX_VOLUME ) vol = MAX_VOLUME;
+
+ nChannelVolume[nChannel] = vol;
+
+ // increase the volume for JB.MP3 and S4_BDBD.MP3
+ if ( MusicManager.GetMusicMode() == MUSICMODE_CUTSCENE
+ && MusicManager.GetCurrentTrack() != STREAMED_SOUND_NEWS_INTRO
+ && MusicManager.GetCurrentTrack() != STREAMED_SOUND_CUTSCENE_SAL4_BDBD )
+ {
+ nChannelVolume[nChannel] >>= 2;
+ }
+
+ if ( opened_samples[nChannel] )
+ AIL_set_3D_sample_volume(opened_samples[nChannel], m_nEffectsFadeVolume*nChannelVolume[nChannel]*m_nEffectsVolume >> 14);
+
+}
+
+void
+cSampleManager::SetChannel3DPosition(uint32 nChannel, float fX, float fY, float fZ)
+{
+ if ( opened_samples[nChannel] )
+ AIL_set_3D_position(opened_samples[nChannel], -fX, fY, fZ);
+}
+
+void
+cSampleManager::SetChannel3DDistances(uint32 nChannel, float fMax, float fMin)
+{
+ if ( opened_samples[nChannel] )
+ AIL_set_3D_sample_distances(opened_samples[nChannel], fMax, fMin);
+}
+
+void
+cSampleManager::SetChannelVolume(uint32 nChannel, uint32 nVolume)
+{
+ uint32 vol = nVolume;
+ if ( vol > MAX_VOLUME ) vol = MAX_VOLUME;
+
+ switch ( nChannel )
+ {
+ case CHANNEL2D:
+ {
+ nChannelVolume[nChannel] = vol;
+
+ // increase the volume for JB.MP3 and S4_BDBD.MP3
+ if ( MusicManager.GetMusicMode() == MUSICMODE_CUTSCENE
+ && MusicManager.GetCurrentTrack() != STREAMED_SOUND_NEWS_INTRO
+ && MusicManager.GetCurrentTrack() != STREAMED_SOUND_CUTSCENE_SAL4_BDBD )
+ {
+ nChannelVolume[nChannel] >>= 2;
+ }
+
+ if ( opened_2dsamples[nChannel - MAXCHANNELS] )
+ {
+ AIL_set_sample_volume(opened_2dsamples[nChannel - MAXCHANNELS],
+ m_nEffectsFadeVolume*vol*m_nEffectsVolume >> 14);
+ }
+
+ break;
+ }
+ }
+}
+
+void
+cSampleManager::SetChannelPan(uint32 nChannel, uint32 nPan)
+{
+ switch ( nChannel )
+ {
+ case CHANNEL2D:
+ {
+#ifndef FIX_BUGS
+ if ( opened_samples[nChannel - MAXCHANNELS] ) // BUG
+#else
+ if ( opened_2dsamples[nChannel - MAXCHANNELS] )
+#endif
+ AIL_set_sample_pan(opened_2dsamples[nChannel - MAXCHANNELS], nPan);
+
+ break;
+ }
+ }
+}
+
+void
+cSampleManager::SetChannelFrequency(uint32 nChannel, uint32 nFreq)
+{
+ bool b2d = false;
+
+ switch ( nChannel )
+ {
+ case CHANNEL2D:
+ {
+ b2d = true;
+ break;
+ }
+ }
+
+ if ( b2d )
+ {
+ if ( opened_2dsamples[nChannel - MAXCHANNELS] )
+ AIL_set_sample_playback_rate(opened_2dsamples[nChannel - MAXCHANNELS], nFreq);
+ }
+ else
+ {
+ if ( opened_samples[nChannel] )
+ AIL_set_3D_sample_playback_rate(opened_samples[nChannel], nFreq);
+ }
+}
+
+void
+cSampleManager::SetChannelLoopPoints(uint32 nChannel, uint32 nLoopStart, int32 nLoopEnd)
+{
+ bool b2d = false;
+
+ switch ( nChannel )
+ {
+ case CHANNEL2D:
+ {
+ b2d = true;
+ break;
+ }
+ }
+
+ if ( b2d )
+ {
+ if ( opened_2dsamples[nChannel - MAXCHANNELS] )
+ AIL_set_sample_loop_block(opened_2dsamples[nChannel - MAXCHANNELS], nLoopStart, nLoopEnd);
+ }
+ else
+ {
+ if ( opened_samples[nChannel] )
+ AIL_set_3D_sample_loop_block(opened_samples[nChannel], nLoopStart, nLoopEnd);
+ }
+}
+
+void
+cSampleManager::SetChannelLoopCount(uint32 nChannel, uint32 nLoopCount)
+{
+ bool b2d = false;
+
+ switch ( nChannel )
+ {
+ case CHANNEL2D:
+ {
+ b2d = true;
+ break;
+ }
+ }
+
+ if ( b2d )
+ {
+ if ( opened_2dsamples[nChannel - MAXCHANNELS] )
+ AIL_set_sample_loop_count(opened_2dsamples[nChannel - MAXCHANNELS], nLoopCount);
+ }
+ else
+ {
+ if ( opened_samples[nChannel] )
+ AIL_set_3D_sample_loop_count(opened_samples[nChannel], nLoopCount);
+ }
+}
+
+bool
+cSampleManager::GetChannelUsedFlag(uint32 nChannel)
+{
+ bool b2d = false;
+
+ switch ( nChannel )
+ {
+ case CHANNEL2D:
+ {
+ b2d = true;
+ break;
+ }
+ }
+
+ if ( b2d )
+ {
+ if ( opened_2dsamples[nChannel - MAXCHANNELS] )
+ return AIL_sample_status(opened_2dsamples[nChannel - MAXCHANNELS]) == SMP_PLAYING;
+ else
+ return false;
+ }
+ else
+ {
+ if ( opened_samples[nChannel] )
+ return AIL_3D_sample_status(opened_samples[nChannel]) == SMP_PLAYING;
+ else
+ return false;
+ }
+
+}
+
+void
+cSampleManager::StartChannel(uint32 nChannel)
+{
+ bool b2d = false;
+
+ switch ( nChannel )
+ {
+ case CHANNEL2D:
+ {
+ b2d = true;
+ break;
+ }
+ }
+
+ if ( b2d )
+ {
+ if ( opened_2dsamples[nChannel - MAXCHANNELS] )
+ AIL_start_sample(opened_2dsamples[nChannel - MAXCHANNELS]);
+ }
+ else
+ {
+ if ( opened_samples[nChannel] )
+ AIL_start_3D_sample(opened_samples[nChannel]);
+ }
+}
+
+void
+cSampleManager::StopChannel(uint32 nChannel)
+{
+ bool b2d = false;
+
+ switch ( nChannel )
+ {
+ case CHANNEL2D:
+ {
+ b2d = true;
+ break;
+ }
+ }
+
+ if ( b2d )
+ {
+ if ( opened_2dsamples[nChannel - MAXCHANNELS] )
+ AIL_end_sample(opened_2dsamples[nChannel - MAXCHANNELS]);
+ }
+ else
+ {
+ if ( opened_samples[nChannel] )
+ {
+ if ( AIL_3D_sample_status(opened_samples[nChannel]) == SMP_PLAYING )
+ AIL_end_3D_sample(opened_samples[nChannel]);
+ }
+ }
+}
+
+void
+cSampleManager::PreloadStreamedFile(uint8 nFile, uint8 nStream)
+{
+ if ( m_bInitialised )
+ {
+ if ( nFile < TOTAL_STREAMED_SOUNDS )
+ {
+ if ( mp3Stream[nStream] )
+ {
+ AIL_pause_stream(mp3Stream[nStream], 1);
+ AIL_close_stream(mp3Stream[nStream]);
+ }
+
+ char filepath[MAX_PATH];
+
+ strcpy(filepath, m_szCDRomRootPath);
+ strcat(filepath, StreamedNameTable[nFile]);
+
+ mp3Stream[nStream] = AIL_open_stream(DIG, filepath, 0);
+
+ if ( mp3Stream[nStream] )
+ {
+ AIL_set_stream_loop_count(mp3Stream[nStream], 1);
+ AIL_service_stream(mp3Stream[nStream], 1);
+ }
+ else
+ OutputDebugString(AIL_last_error());
+ }
+ }
+}
+
+void
+cSampleManager::PauseStream(uint8 nPauseFlag, uint8 nStream)
+{
+ if ( m_bInitialised )
+ {
+ if ( mp3Stream[nStream] )
+ AIL_pause_stream(mp3Stream[nStream], nPauseFlag != 0);
+ }
+}
+
+void
+cSampleManager::StartPreloadedStreamedFile(uint8 nStream)
+{
+ if ( m_bInitialised )
+ {
+ if ( mp3Stream[nStream] )
+ AIL_start_stream(mp3Stream[nStream]);
+ }
+}
+
+bool
+cSampleManager::StartStreamedFile(uint8 nFile, uint32 nPos, uint8 nStream)
+{
+ uint32 position = nPos;
+ char filename[MAX_PATH];
+
+ if ( m_bInitialised && nFile < TOTAL_STREAMED_SOUNDS )
+ {
+ if ( mp3Stream[nStream] )
+ {
+ AIL_pause_stream(mp3Stream[nStream], 1);
+ AIL_close_stream(mp3Stream[nStream]);
+ }
+
+ if ( nFile == STREAMED_SOUND_RADIO_MP3_PLAYER )
+ {
+ uint32 i = 0;
+ do {
+ if(i != 0 || _bIsMp3Active) {
+ if(++_CurMP3Index >= nNumMP3s) _CurMP3Index = 0;
+
+ _CurMP3Pos = 0;
+
+ tMP3Entry *mp3 = _GetMP3EntryByIndex(_CurMP3Index);
+
+ if(mp3) {
+ mp3 = _pMP3List;
+ if(mp3 == NULL) {
+ _bIsMp3Active = false;
+ nFile = 0;
+ strcpy(filename, m_szCDRomRootPath);
+ strcat(filename, StreamedNameTable[nFile]);
+
+ mp3Stream[nStream] =
+ AIL_open_stream(DIG, filename, 0);
+ if(mp3Stream[nStream]) {
+ AIL_set_stream_loop_count(
+ mp3Stream[nStream], 1);
+ AIL_set_stream_ms_position(
+ mp3Stream[nStream], position);
+ AIL_pause_stream(mp3Stream[nStream],
+ 0);
+ return true;
+ }
+
+ return false;
+ }
+ }
+
+ if(mp3->pLinkPath != NULL)
+ mp3Stream[nStream] =
+ AIL_open_stream(DIG, mp3->pLinkPath, 0);
+ else {
+ strcpy(filename, _mp3DirectoryPath);
+ strcat(filename, mp3->aFilename);
+
+ mp3Stream[nStream] =
+ AIL_open_stream(DIG, filename, 0);
+ }
+
+ if(mp3Stream[nStream]) {
+ AIL_set_stream_loop_count(mp3Stream[nStream], 1);
+ AIL_set_stream_ms_position(mp3Stream[nStream], 0);
+ AIL_pause_stream(mp3Stream[nStream], 0);
+ return true;
+ }
+
+ _bIsMp3Active = false;
+ continue;
+ }
+ if ( nPos > nStreamLength[STREAMED_SOUND_RADIO_MP3_PLAYER] )
+ position = 0;
+
+ tMP3Entry *e;
+ if ( !_GetMP3PosFromStreamPos(&position, &e) )
+ {
+ if ( e == NULL )
+ {
+ nFile = 0;
+ strcpy(filename, m_szCDRomRootPath);
+ strcat(filename, StreamedNameTable[nFile]);
+ mp3Stream[nStream] =
+ AIL_open_stream(DIG, filename, 0);
+ if(mp3Stream[nStream]) {
+ AIL_set_stream_loop_count(
+ mp3Stream[nStream], 1);
+ AIL_set_stream_ms_position(
+ mp3Stream[nStream], position);
+ AIL_pause_stream(mp3Stream[nStream], 0);
+ return true;
+ }
+
+ return false;
+ }
+ }
+
+ if ( e->pLinkPath != NULL )
+ mp3Stream[nStream] = AIL_open_stream(DIG, e->pLinkPath, 0);
+ else
+ {
+ strcpy(filename, _mp3DirectoryPath);
+ strcat(filename, e->aFilename);
+
+ mp3Stream[nStream] = AIL_open_stream(DIG, filename, 0);
+ }
+
+ if ( mp3Stream[nStream] )
+ {
+ AIL_set_stream_loop_count(mp3Stream[nStream], 1);
+ AIL_set_stream_ms_position(mp3Stream[nStream], position);
+ AIL_pause_stream(mp3Stream[nStream], 0);
+
+ _bIsMp3Active = true;
+
+ return true;
+ }
+
+ _bIsMp3Active = false;
+
+ } while(++i < nNumMP3s);
+
+ position = 0;
+ nFile = 0;
+ }
+
+ strcpy(filename, m_szCDRomRootPath);
+ strcat(filename, StreamedNameTable[nFile]);
+
+ mp3Stream[nStream] = AIL_open_stream(DIG, filename, 0);
+ if ( mp3Stream[nStream] )
+ {
+ AIL_set_stream_loop_count(mp3Stream[nStream], 1);
+ AIL_set_stream_ms_position(mp3Stream[nStream], position);
+ AIL_pause_stream(mp3Stream[nStream], 0);
+ return true;
+ }
+ }
+
+ return false;
+}
+
+void
+cSampleManager::StopStreamedFile(uint8 nStream)
+{
+ if ( m_bInitialised )
+ {
+ if ( mp3Stream[nStream] )
+ {
+ AIL_pause_stream(mp3Stream[nStream], 1);
+
+ AIL_close_stream(mp3Stream[nStream]);
+ mp3Stream[nStream] = NULL;
+
+ if ( nStream == 0 )
+ _bIsMp3Active = false;
+ }
+ }
+}
+
+int32
+cSampleManager::GetStreamedFilePosition(uint8 nStream)
+{
+ S32 currentms;
+
+ if ( m_bInitialised )
+ {
+ if ( mp3Stream[nStream] )
+ {
+ if ( _bIsMp3Active )
+ {
+ tMP3Entry *mp3 = _GetMP3EntryByIndex(_CurMP3Index);
+
+ if ( mp3 != NULL )
+ {
+ AIL_stream_ms_position(mp3Stream[nStream], NULL, &currentms);
+ return currentms + mp3->nTrackStreamPos;
+ }
+ else
+ return 0;
+ }
+ else
+ {
+ AIL_stream_ms_position(mp3Stream[nStream], NULL, &currentms);
+ return currentms;
+ }
+ }
+ }
+
+ return 0;
+}
+
+void
+cSampleManager::SetStreamedVolumeAndPan(uint8 nVolume, uint8 nPan, uint8 nEffectFlag, uint8 nStream)
+{
+ uint8 vol = nVolume;
+
+ if ( m_bInitialised )
+ {
+ if ( vol > MAX_VOLUME ) vol = MAX_VOLUME;
+ if ( vol > MAX_VOLUME ) vol = MAX_VOLUME;
+
+ nStreamVolume[nStream] = vol;
+ nStreamPan[nStream] = nPan;
+
+ if ( mp3Stream[nStream] )
+ {
+ if ( nEffectFlag )
+ AIL_set_stream_volume(mp3Stream[nStream], m_nEffectsFadeVolume*vol*m_nEffectsVolume >> 14);
+ else
+ AIL_set_stream_volume(mp3Stream[nStream], m_nMusicFadeVolume*vol*m_nMusicVolume >> 14);
+
+ AIL_set_stream_pan(mp3Stream[nStream], nPan);
+ }
+ }
+}
+
+int32
+cSampleManager::GetStreamedFileLength(uint8 nStream)
+{
+ if ( m_bInitialised )
+ return nStreamLength[nStream];
+
+ return 0;
+}
+
+bool
+cSampleManager::IsStreamPlaying(uint8 nStream)
+{
+ if ( m_bInitialised )
+ {
+ if ( mp3Stream[nStream] )
+ {
+ if ( AIL_stream_status(mp3Stream[nStream]) == SMP_PLAYING )
+ return true;
+ else
+ return false;
+ }
+ }
+
+ return false;
+}
+
+bool
+cSampleManager::InitialiseSampleBanks(void)
+{
+ int32 nBank = SAMPLEBANK_MAIN;
+
+ fpSampleDescHandle = fopen(SampleBankDescFilename, "rb");
+ if ( fpSampleDescHandle == NULL )
+ return false;
+
+ fpSampleDataHandle = fopen(SampleBankDataFilename, "rb");
+ if ( fpSampleDataHandle == NULL )
+ {
+ fclose(fpSampleDescHandle);
+ fpSampleDescHandle = NULL;
+
+ return false;
+ }
+
+ fseek(fpSampleDataHandle, 0, SEEK_END);
+ _nSampleDataEndOffset = ftell(fpSampleDataHandle);
+ rewind(fpSampleDataHandle);
+
+ fread(m_aSamples, sizeof(tSample), TOTAL_AUDIO_SAMPLES, fpSampleDescHandle);
+
+ fclose(fpSampleDescHandle);
+ fpSampleDescHandle = NULL;
+
+ for ( int32 i = 0; i < TOTAL_AUDIO_SAMPLES; i++ )
+ {
+#ifdef FIX_BUGS
+ if (nBank >= MAX_SAMPLEBANKS) break;
+#endif
+ if ( BankStartOffset[nBank] == BankStartOffset[SAMPLEBANK_MAIN] + i )
+ {
+ nSampleBankDiscStartOffset[nBank] = m_aSamples[i].nOffset;
+ nBank++;
+ }
+ }
+
+ nSampleBankSize[SAMPLEBANK_MAIN] = nSampleBankDiscStartOffset[SAMPLEBANK_PED] - nSampleBankDiscStartOffset[SAMPLEBANK_MAIN];
+ nSampleBankSize[SAMPLEBANK_PED] = _nSampleDataEndOffset - nSampleBankDiscStartOffset[SAMPLEBANK_PED];
+
+ return true;
+}
diff --git a/src/audio/miles/sampman_mss.h b/src/audio/miles/sampman_mss.h
new file mode 100644
index 00000000..ebedfb63
--- /dev/null
+++ b/src/audio/miles/sampman_mss.h
@@ -0,0 +1,339 @@
+#pragma once
+#include "common.h"
+#include "AudioSamples.h"
+
+#define MAX_VOLUME 127
+
+struct tSample {
+ int32 nOffset;
+ uint32 nSize;
+ int32 nFrequency;
+ int32 nLoopStart;
+ int32 nLoopEnd;
+};
+
+enum
+{
+ SAMPLEBANK_MAIN,
+ SAMPLEBANK_PED,
+ MAX_SAMPLEBANKS,
+ SAMPLEBANK_INVALID
+};
+
+#define MAX_PEDSFX 7
+#define PED_BLOCKSIZE 79000
+
+#define MAXPROVIDERS 64
+
+#define MAXCHANNELS 28
+#define MAXCHANNELS_SURROUND 24
+#define MAX2DCHANNELS 1
+#define CHANNEL2D MAXCHANNELS
+
+#define MAX_MP3STREAMS 2
+
+#define DIGITALRATE 32000
+#define DIGITALBITS 16
+#define DIGITALCHANNELS 2
+
+#define MAX_DIGITAL_MIXER_CHANNELS 32
+
+class cSampleManager
+{
+ uint8 m_nEffectsVolume;
+ uint8 m_nMusicVolume;
+ uint8 m_nEffectsFadeVolume;
+ uint8 m_nMusicFadeVolume;
+ uint8 m_nMonoMode;
+ char unk;
+ char m_szCDRomRootPath[80];
+ bool m_bInitialised;
+ uint8 m_nNumberOfProviders;
+ char *m_aAudioProviders[MAXPROVIDERS];
+ tSample m_aSamples[TOTAL_AUDIO_SAMPLES];
+
+public:
+
+
+
+ cSampleManager(void) :
+ m_nNumberOfProviders(0)
+ { }
+
+ ~cSampleManager(void)
+ { }
+
+ void SetSpeakerConfig(int32 nConfig);
+ uint32 GetMaximumSupportedChannels(void);
+
+ uint32 GetNum3DProvidersAvailable() { return m_nNumberOfProviders; }
+ void SetNum3DProvidersAvailable(uint32 num) { m_nNumberOfProviders = num; }
+
+ char *Get3DProviderName(uint8 id) { return m_aAudioProviders[id]; }
+ void Set3DProviderName(uint8 id, char *name) { m_aAudioProviders[id] = name; }
+
+ int8 GetCurrent3DProviderIndex(void);
+ int8 SetCurrent3DProvider(uint8 which);
+
+ bool IsMP3RadioChannelAvailable(void);
+
+ void ReleaseDigitalHandle (void);
+ void ReacquireDigitalHandle(void);
+
+ bool Initialise(void);
+ void Terminate (void);
+
+ bool CheckForAnAudioFileOnCD(void);
+ char GetCDAudioDriveLetter (void);
+
+ void UpdateEffectsVolume(void);
+
+ void SetEffectsMasterVolume(uint8 nVolume);
+ void SetMusicMasterVolume (uint8 nVolume);
+ void SetEffectsFadeVolume (uint8 nVolume);
+ void SetMusicFadeVolume (uint8 nVolume);
+
+ bool LoadSampleBank (uint8 nBank);
+ void UnloadSampleBank (uint8 nBank);
+ bool IsSampleBankLoaded(uint8 nBank);
+
+ bool IsPedCommentLoaded(uint32 nComment);
+ bool LoadPedComment (uint32 nComment);
+
+ int32 _GetPedCommentSlot(uint32 nComment);
+
+ int32 GetSampleBaseFrequency (uint32 nSample);
+ int32 GetSampleLoopStartOffset(uint32 nSample);
+ int32 GetSampleLoopEndOffset (uint32 nSample);
+ uint32 GetSampleLength (uint32 nSample);
+
+ bool UpdateReverb(void);
+
+ void SetChannelReverbFlag (uint32 nChannel, uint8 nReverbFlag);
+ bool InitialiseChannel (uint32 nChannel, uint32 nSfx, uint8 nBank);
+ void SetChannelEmittingVolume(uint32 nChannel, uint32 nVolume);
+ void SetChannel3DPosition (uint32 nChannel, float fX, float fY, float fZ);
+ void SetChannel3DDistances (uint32 nChannel, float fMax, float fMin);
+ void SetChannelVolume (uint32 nChannel, uint32 nVolume);
+ void SetChannelPan (uint32 nChannel, uint32 nPan);
+ void SetChannelFrequency (uint32 nChannel, uint32 nFreq);
+ void SetChannelLoopPoints (uint32 nChannel, uint32 nLoopStart, int32 nLoopEnd);
+ void SetChannelLoopCount (uint32 nChannel, uint32 nLoopCount);
+ bool GetChannelUsedFlag (uint32 nChannel);
+ void StartChannel (uint32 nChannel);
+ void StopChannel (uint32 nChannel);
+
+ void PreloadStreamedFile (uint8 nFile, uint8 nStream);
+ void PauseStream (uint8 nPauseFlag, uint8 nStream);
+ void StartPreloadedStreamedFile (uint8 nStream);
+ bool StartStreamedFile (uint8 nFile, uint32 nPos, uint8 nStream);
+ void StopStreamedFile (uint8 nStream);
+ int32 GetStreamedFilePosition (uint8 nStream);
+ void SetStreamedVolumeAndPan(uint8 nVolume, uint8 nPan, uint8 nEffectFlag, uint8 nStream);
+ int32 GetStreamedFileLength (uint8 nStream);
+ bool IsStreamPlaying (uint8 nStream);
+ bool InitialiseSampleBanks(void);
+};
+
+extern cSampleManager SampleManager;
+extern int32 BankStartOffset[MAX_SAMPLEBANKS];
+
+static char StreamedNameTable[][25]=
+{
+ "AUDIO\\HEAD.WAV",
+ "AUDIO\\CLASS.WAV",
+ "AUDIO\\KJAH.WAV",
+ "AUDIO\\RISE.WAV",
+ "AUDIO\\LIPS.WAV",
+ "AUDIO\\GAME.WAV",
+ "AUDIO\\MSX.WAV",
+ "AUDIO\\FLASH.WAV",
+ "AUDIO\\CHAT.WAV",
+ "AUDIO\\HEAD.WAV",
+ "AUDIO\\POLICE.WAV",
+ "AUDIO\\CITY.WAV",
+ "AUDIO\\WATER.WAV",
+ "AUDIO\\COMOPEN.WAV",
+ "AUDIO\\SUBOPEN.WAV",
+ "AUDIO\\JB.MP3",
+ "AUDIO\\BET.MP3",
+ "AUDIO\\L1_LG.MP3",
+ "AUDIO\\L2_DSB.MP3",
+ "AUDIO\\L3_DM.MP3",
+ "AUDIO\\L4_PAP.MP3",
+ "AUDIO\\L5_TFB.MP3",
+ "AUDIO\\J0_DM2.MP3",
+ "AUDIO\\J1_LFL.MP3",
+ "AUDIO\\J2_KCL.MP3",
+ "AUDIO\\J3_VH.MP3",
+ "AUDIO\\J4_ETH.MP3",
+ "AUDIO\\J5_DST.MP3",
+ "AUDIO\\J6_TBJ.MP3",
+ "AUDIO\\T1_TOL.MP3",
+ "AUDIO\\T2_TPU.MP3",
+ "AUDIO\\T3_MAS.MP3",
+ "AUDIO\\T4_TAT.MP3",
+ "AUDIO\\T5_BF.MP3",
+ "AUDIO\\S0_MAS.MP3",
+ "AUDIO\\S1_PF.MP3",
+ "AUDIO\\S2_CTG.MP3",
+ "AUDIO\\S3_RTC.MP3",
+ "AUDIO\\S5_LRQ.MP3",
+ "AUDIO\\S4_BDBA.MP3",
+ "AUDIO\\S4_BDBB.MP3",
+ "AUDIO\\S2_CTG2.MP3",
+ "AUDIO\\S4_BDBD.MP3",
+ "AUDIO\\S5_LRQB.MP3",
+ "AUDIO\\S5_LRQC.MP3",
+ "AUDIO\\A1_SSO.WAV",
+ "AUDIO\\A2_PP.WAV",
+ "AUDIO\\A3_SS.WAV",
+ "AUDIO\\A4_PDR.WAV",
+ "AUDIO\\A5_K2FT.WAV",
+ "AUDIO\\K1_KBO.MP3",
+ "AUDIO\\K2_GIS.MP3",
+ "AUDIO\\K3_DS.MP3",
+ "AUDIO\\K4_SHI.MP3",
+ "AUDIO\\K5_SD.MP3",
+ "AUDIO\\R0_PDR2.MP3",
+ "AUDIO\\R1_SW.MP3",
+ "AUDIO\\R2_AP.MP3",
+ "AUDIO\\R3_ED.MP3",
+ "AUDIO\\R4_GF.MP3",
+ "AUDIO\\R5_PB.MP3",
+ "AUDIO\\R6_MM.MP3",
+ "AUDIO\\D1_STOG.MP3",
+ "AUDIO\\D2_KK.MP3",
+ "AUDIO\\D3_ADO.MP3",
+ "AUDIO\\D5_ES.MP3",
+ "AUDIO\\D7_MLD.MP3",
+ "AUDIO\\D4_GTA.MP3",
+ "AUDIO\\D4_GTA2.MP3",
+ "AUDIO\\D6_STS.MP3",
+ "AUDIO\\A6_BAIT.WAV",
+ "AUDIO\\A7_ETG.WAV",
+ "AUDIO\\A8_PS.WAV",
+ "AUDIO\\A9_ASD.WAV",
+ "AUDIO\\K4_SHI2.MP3",
+ "AUDIO\\C1_TEX.MP3",
+ "AUDIO\\EL_PH1.MP3",
+ "AUDIO\\EL_PH2.MP3",
+ "AUDIO\\EL_PH3.MP3",
+ "AUDIO\\EL_PH4.MP3",
+ "AUDIO\\YD_PH1.MP3",
+ "AUDIO\\YD_PH2.MP3",
+ "AUDIO\\YD_PH3.MP3",
+ "AUDIO\\YD_PH4.MP3",
+ "AUDIO\\HD_PH1.MP3",
+ "AUDIO\\HD_PH2.MP3",
+ "AUDIO\\HD_PH3.MP3",
+ "AUDIO\\HD_PH4.MP3",
+ "AUDIO\\HD_PH5.MP3",
+ "AUDIO\\MT_PH1.MP3",
+ "AUDIO\\MT_PH2.MP3",
+ "AUDIO\\MT_PH3.MP3",
+ "AUDIO\\MT_PH4.MP3",
+ "AUDIO\\MISCOM.WAV",
+ "AUDIO\\END.MP3",
+ "AUDIO\\lib_a1.WAV",
+ "AUDIO\\lib_a2.WAV",
+ "AUDIO\\lib_a.WAV",
+ "AUDIO\\lib_b.WAV",
+ "AUDIO\\lib_c.WAV",
+ "AUDIO\\lib_d.WAV",
+ "AUDIO\\l2_a.WAV",
+ "AUDIO\\j4t_1.WAV",
+ "AUDIO\\j4t_2.WAV",
+ "AUDIO\\j4t_3.WAV",
+ "AUDIO\\j4t_4.WAV",
+ "AUDIO\\j4_a.WAV",
+ "AUDIO\\j4_b.WAV",
+ "AUDIO\\j4_c.WAV",
+ "AUDIO\\j4_d.WAV",
+ "AUDIO\\j4_e.WAV",
+ "AUDIO\\j4_f.WAV",
+ "AUDIO\\j6_1.WAV",
+ "AUDIO\\j6_a.WAV",
+ "AUDIO\\j6_b.WAV",
+ "AUDIO\\j6_c.WAV",
+ "AUDIO\\j6_d.WAV",
+ "AUDIO\\t4_a.WAV",
+ "AUDIO\\s1_a.WAV",
+ "AUDIO\\s1_a1.WAV",
+ "AUDIO\\s1_b.WAV",
+ "AUDIO\\s1_c.WAV",
+ "AUDIO\\s1_c1.WAV",
+ "AUDIO\\s1_d.WAV",
+ "AUDIO\\s1_e.WAV",
+ "AUDIO\\s1_f.WAV",
+ "AUDIO\\s1_g.WAV",
+ "AUDIO\\s1_h.WAV",
+ "AUDIO\\s1_i.WAV",
+ "AUDIO\\s1_j.WAV",
+ "AUDIO\\s1_k.WAV",
+ "AUDIO\\s1_l.WAV",
+ "AUDIO\\s3_a.WAV",
+ "AUDIO\\s3_b.WAV",
+ "AUDIO\\el3_a.WAV",
+ "AUDIO\\mf1_a.WAV",
+ "AUDIO\\mf2_a.WAV",
+ "AUDIO\\mf3_a.WAV",
+ "AUDIO\\mf3_b.WAV",
+ "AUDIO\\mf3_b1.WAV",
+ "AUDIO\\mf3_c.WAV",
+ "AUDIO\\mf4_a.WAV",
+ "AUDIO\\mf4_b.WAV",
+ "AUDIO\\mf4_c.WAV",
+ "AUDIO\\a1_a.WAV",
+ "AUDIO\\a3_a.WAV",
+ "AUDIO\\a5_a.WAV",
+ "AUDIO\\a4_a.WAV",
+ "AUDIO\\a4_b.WAV",
+ "AUDIO\\a4_c.WAV",
+ "AUDIO\\a4_d.WAV",
+ "AUDIO\\k1_a.WAV",
+ "AUDIO\\k3_a.WAV",
+ "AUDIO\\r1_a.WAV",
+ "AUDIO\\r2_a.WAV",
+ "AUDIO\\r2_b.WAV",
+ "AUDIO\\r2_c.WAV",
+ "AUDIO\\r2_d.WAV",
+ "AUDIO\\r2_e.WAV",
+ "AUDIO\\r2_f.WAV",
+ "AUDIO\\r2_g.WAV",
+ "AUDIO\\r2_h.WAV",
+ "AUDIO\\r5_a.WAV",
+ "AUDIO\\r6_a.WAV",
+ "AUDIO\\r6_a1.WAV",
+ "AUDIO\\r6_b.WAV",
+ "AUDIO\\lo2_a.WAV",
+ "AUDIO\\lo6_a.WAV",
+ "AUDIO\\yd2_a.WAV",
+ "AUDIO\\yd2_b.WAV",
+ "AUDIO\\yd2_c.WAV",
+ "AUDIO\\yd2_c1.WAV",
+ "AUDIO\\yd2_d.WAV",
+ "AUDIO\\yd2_e.WAV",
+ "AUDIO\\yd2_f.WAV",
+ "AUDIO\\yd2_g.WAV",
+ "AUDIO\\yd2_h.WAV",
+ "AUDIO\\yd2_ass.WAV",
+ "AUDIO\\yd2_ok.WAV",
+ "AUDIO\\h5_a.WAV",
+ "AUDIO\\h5_b.WAV",
+ "AUDIO\\h5_c.WAV",
+ "AUDIO\\ammu_a.WAV",
+ "AUDIO\\ammu_b.WAV",
+ "AUDIO\\ammu_c.WAV",
+ "AUDIO\\door_1.WAV",
+ "AUDIO\\door_2.WAV",
+ "AUDIO\\door_3.WAV",
+ "AUDIO\\door_4.WAV",
+ "AUDIO\\door_5.WAV",
+ "AUDIO\\door_6.WAV",
+ "AUDIO\\t3_a.WAV",
+ "AUDIO\\t3_b.WAV",
+ "AUDIO\\t3_c.WAV",
+ "AUDIO\\k1_b.WAV",
+ "AUDIO\\cat1.WAV"
+};
diff --git a/src/audio/openal/samp_oal.cpp b/src/audio/openal/samp_oal.cpp
new file mode 100644
index 00000000..e8213cd9
--- /dev/null
+++ b/src/audio/openal/samp_oal.cpp
@@ -0,0 +1,1404 @@
+#include <al.h>
+#include <alc.h>
+#include <mpg123_pre.h>
+//#include <mpg123.h>
+#include <time.h>
+#include <io.h>
+#include "samp_oal.h"
+#include "AudioManager.h"
+#include "MusicManager.h"
+#include "Frontend.h"
+#include "Timer.h"
+
+#pragma comment( lib, "libmpg123.lib" )
+#pragma comment( lib, "OpenAL32.lib" )
+
+cSampleManager SampleManager;
+int32 BankStartOffset[MAX_SAMPLEBANKS];
+
+
+///////////////////////////////////////////////////////////////
+class MP3Stream
+{
+public:
+ mpg123_handle *m_pMPG;
+ FILE *m_fpFile;
+ unsigned char *m_pBuf;
+ char m_aFilename[128];
+ size_t m_nBufSize;
+ size_t m_nLengthInBytes;
+ long m_nRate;
+ int m_nBitRate;
+ int m_nChannels;
+ int m_nEncoding;
+ int m_nLength;
+ int m_nBlockSize;
+ int m_nNumBlocks;
+ ALuint m_alSource;
+ ALuint m_alBuffers[5];
+ unsigned char *m_pBlocks;
+ bool m_bIsFree;
+ bool m_bIsOpened;
+ bool m_bIsPaused;
+ int m_nVolume;
+
+ void Initialize(void);
+ bool FillBuffer(ALuint alBuffer);
+ void Update(void);
+ void SetPos(uint32 nPos);
+ int32 FillBuffers();
+ MP3Stream(char *filename, ALuint source, ALuint *buffers);
+ ~MP3Stream() { Delete(); }
+ void Delete();
+
+};
+///////////////////////////////////////////////////////////////
+
+char SampleBankDescFilename[] = "AUDIO\\SFX.SDT";
+char SampleBankDataFilename[] = "AUDIO\\SFX.RAW";
+
+FILE *fpSampleDescHandle;
+FILE *fpSampleDataHandle;
+bool bSampleBankLoaded [MAX_SAMPLEBANKS];
+int32 nSampleBankDiscStartOffset [MAX_SAMPLEBANKS];
+int32 nSampleBankSize [MAX_SAMPLEBANKS];
+int32 nSampleBankMemoryStartAddress[MAX_SAMPLEBANKS];
+int32 _nSampleDataEndOffset;
+
+int32 nPedSlotSfx [MAX_PEDSFX];
+int32 nPedSlotSfxAddr[MAX_PEDSFX];
+uint8 nCurrentPedSlot;
+
+
+
+uint32 nStreamLength[TOTAL_STREAMED_SOUNDS];
+
+///////////////////////////////////////////////////////////////
+ALuint alChannel[MAXCHANNELS+MAX2DCHANNELS];
+ALuint ALStreamSources[MAX_STREAMS];
+ALuint ALStreamBuffers[MAX_STREAMS][5];
+struct
+{
+ ALuint buffer;
+ ALuint timer;
+}ALBuffers[SAMPLEBANK_MAX];
+
+ALuint pedBuffers[MAX_PEDSFX];
+//bank0Buffers
+
+uint32 nNumMP3s;
+
+MP3Stream *mp3Stream[MAX_STREAMS];
+int8 nStreamPan [MAX_STREAMS];
+int8 nStreamVolume[MAX_STREAMS];
+
+float ChannelPitch[MAXCHANNELS+MAX2DCHANNELS];
+uint8 nChannelVolume[MAXCHANNELS+MAX2DCHANNELS];
+uint32 ChannelSample[MAXCHANNELS+MAX2DCHANNELS];
+int32 currentChannelMaxFrontDistance[MAXCHANNELS+MAX2DCHANNELS];
+int32 currentChannelFrequency[MAXCHANNELS+MAX2DCHANNELS];
+int32 currentChannelVolume[MAXCHANNELS+MAX2DCHANNELS];
+
+
+cSampleManager::cSampleManager(void)
+{
+ ;
+}
+
+cSampleManager::~cSampleManager(void)
+{
+ ASSERT((void *)nSampleBankMemoryStartAddress[SAMPLEBANK_PED] == NULL);
+ free((void *)nSampleBankMemoryStartAddress[SAMPLEBANK_PED]);
+
+ if ( fpSampleDescHandle != NULL )
+ {
+ fclose(fpSampleDescHandle);
+ fpSampleDescHandle = NULL;
+ }
+
+ if ( fpSampleDataHandle != NULL )
+ {
+ fclose(fpSampleDataHandle);
+ fpSampleDataHandle = NULL;
+ }
+}
+
+void cSampleManager::SetSpeakerConfig(int32 nConfig)
+{
+
+}
+
+uint32 cSampleManager::GetMaximumSupportedChannels(void)
+{
+ return 20;
+}
+
+uint32 cSampleManager::GetNum3DProvidersAvailable()
+{
+ return 1;
+}
+
+void cSampleManager::SetNum3DProvidersAvailable(uint32 num)
+{
+ ;
+}
+
+char *cSampleManager::Get3DProviderName(uint8 id)
+{
+ static char PROVIDER[256] = "OpenAL";
+ return PROVIDER;
+}
+
+void cSampleManager::Set3DProviderName(uint8 id, char *name)
+{
+ ;
+}
+
+int8 cSampleManager::GetCurrent3DProviderIndex(void)
+{
+ return 0;
+}
+
+int8 cSampleManager::SetCurrent3DProvider(uint8 which)
+{
+ return 0;
+}
+
+bool
+cSampleManager::IsMP3RadioChannelAvailable(void)
+{
+ return nNumMP3s != 0;
+}
+
+
+void cSampleManager::ReleaseDigitalHandle(void)
+{
+
+}
+
+void cSampleManager::ReacquireDigitalHandle(void)
+{
+
+}
+
+bool
+cSampleManager::Initialise(void)
+{
+ ALCint attr[] = {ALC_FREQUENCY,MAX_FREQ,0};
+
+ m_pDevice = alcOpenDevice(NULL);
+ ASSERT(m_pDevice != NULL);
+
+ m_pContext = alcCreateContext(m_pDevice, attr);
+ ASSERT(m_pContext != NULL);
+
+ alcMakeContextCurrent(m_pContext);
+
+ mpg123_init();
+
+
+
+ for ( int32 i = 0; i < TOTAL_AUDIO_SAMPLES; i++ )
+ {
+ m_aSamples[i].nOffset = 0;
+ m_aSamples[i].nSize = 0;
+ m_aSamples[i].nFrequency = MAX_FREQ;
+ m_aSamples[i].nLoopStart = 0;
+ m_aSamples[i].nLoopEnd = -1;
+ }
+
+ for ( int32 i = 0; i < TOTAL_STREAMED_SOUNDS; i++ )
+ nStreamLength[i] = 3600000;
+
+ for ( int32 i = 0; i < MAX_STREAMS; i++ )
+ {
+ mp3Stream[i] = NULL;
+ nStreamVolume[i] = 100;
+ nStreamPan[i] = 63;
+ }
+
+ alGenSources(MAX_STREAMS, (ALuint *)ALStreamSources);
+ alGenBuffers(MAX_STREAMS*5, (ALuint *)ALStreamBuffers);
+
+ m_nMonoMode = 0;
+
+ m_nEffectsVolume = MAX_VOLUME;
+ m_nMusicVolume = MAX_VOLUME;
+ m_nEffectsFadeVolume = MAX_VOLUME;
+ m_nMusicFadeVolume = MAX_VOLUME;
+
+
+ memset(alChannel, 0, sizeof(alChannel));
+ memset(nChannelVolume, 0, sizeof(nChannelVolume));
+ memset(ChannelSample, 0, sizeof(ChannelSample));
+
+ for ( int32 i = 0; i < ARRAY_SIZE(ChannelPitch); i++ )
+ ChannelPitch[i] = 1.0f;
+
+
+ fpSampleDescHandle = NULL;
+ fpSampleDataHandle = NULL;
+
+ for ( int32 i = 0; i < MAX_SAMPLEBANKS; i++ )
+ {
+ bSampleBankLoaded[i] = false;
+ nSampleBankDiscStartOffset[i] = 0;
+ nSampleBankSize[i] = 0;
+ nSampleBankMemoryStartAddress[i] = 0;
+ }
+
+ alGenBuffers(MAX_PEDSFX, pedBuffers);
+
+ for ( int32 i = 0; i < MAX_PEDSFX; i++ )
+ {
+ nPedSlotSfx[i] = NO_SAMPLE;
+ nPedSlotSfxAddr[i] = 0;
+ }
+
+ nCurrentPedSlot = 0;
+
+ for ( int32 i = 0; i < SAMPLEBANK_MAX; i++ )
+ {
+ ALBuffers[i].buffer = 0;
+ ALBuffers[i].timer = 0;
+ }
+
+ alListenerf (AL_GAIN, 1.0f);
+ alListener3f(AL_POSITION, 0.0f, 0.0f, 0.0f);
+ alListener3f(AL_VELOCITY, 0.0f, 0.0f, 0.0f);
+ ALfloat orientation[6] = { 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f };
+ alListenerfv(AL_ORIENTATION, orientation);
+
+ if ( !InitialiseSampleBanks() )
+ {
+ Terminate();
+ return false;
+ }
+
+ nSampleBankMemoryStartAddress[SAMPLEBANK_MAIN] = (int32)malloc(nSampleBankSize[SAMPLEBANK_MAIN]);
+ ASSERT(nSampleBankMemoryStartAddress[SAMPLEBANK_MAIN] != NULL);
+
+ if ( nSampleBankMemoryStartAddress[SAMPLEBANK_MAIN] == NULL )
+ {
+ Terminate();
+ return false;
+ }
+
+ nSampleBankMemoryStartAddress[SAMPLEBANK_PED] = (int32)malloc(PED_BLOCKSIZE*MAX_PEDSFX);
+ ASSERT(nSampleBankMemoryStartAddress[SAMPLEBANK_PED] != NULL);
+
+ alGenSources(MAXCHANNELS, alChannel);
+ for ( int32 i = 0; i < MAXCHANNELS; i++ )
+ {
+ if ( alChannel[i] )
+ alSourcei(alChannel[i], AL_SOURCE_RELATIVE, AL_TRUE);
+ }
+
+ alGenSources(MAX2DCHANNELS, &alChannel[CHANNEL2D]);
+ if ( alChannel[CHANNEL2D] )
+ {
+ alSourcei (alChannel[CHANNEL2D], AL_SOURCE_RELATIVE, AL_TRUE);
+ alSource3f(alChannel[CHANNEL2D], AL_POSITION, 0.0f, 0.0f, 0.0f);
+ alSourcef (alChannel[CHANNEL2D], AL_GAIN, 1.0f);
+ }
+
+ LoadSampleBank(SAMPLEBANK_MAIN);
+
+ return true;
+}
+
+void
+cSampleManager::Terminate(void)
+{
+ mpg123_exit();
+ alcMakeContextCurrent(NULL);
+ alcDestroyContext(m_pContext);
+ alcCloseDevice(m_pDevice);
+}
+
+void
+cSampleManager::UpdateSoundBuffers(void)
+{
+ for ( int32 i = 0; i < SAMPLEBANK_MAX; i++ )
+ {
+ if ( ALBuffers[i].timer > 0 )
+ {
+ ALBuffers[i].timer -= ALuint(CTimer::GetTimeStep() * 20.0f);
+
+ if ( ALBuffers[i].timer <= 0 )
+ {
+ if ( ALBuffers[i].buffer != 0 && alIsBuffer(ALBuffers[i].buffer) )
+ {
+ alDeleteBuffers(1, &ALBuffers[i].buffer);
+
+ if ( alGetError() == AL_NO_ERROR )
+ ALBuffers[i].buffer = 0;
+ else
+ ALBuffers[i].buffer = 120000;
+ }
+ }
+ }
+ }
+}
+
+bool cSampleManager::CheckForAnAudioFileOnCD(void)
+{
+ return true;
+}
+
+char cSampleManager::GetCDAudioDriveLetter(void)
+{
+ return '\0';
+}
+
+void
+cSampleManager::SetEffectsMasterVolume(uint8 nVolume)
+{
+ m_nEffectsVolume = nVolume;
+}
+
+void
+cSampleManager::SetMusicMasterVolume(uint8 nVolume)
+{
+ m_nMusicVolume = nVolume;
+}
+
+void
+cSampleManager::SetEffectsFadeVolume(uint8 nVolume)
+{
+ m_nEffectsFadeVolume = nVolume;
+}
+
+void
+cSampleManager::SetMusicFadeVolume(uint8 nVolume)
+{
+ m_nMusicFadeVolume = nVolume;
+}
+
+void
+cSampleManager::SetMonoMode(uint8 nMode)
+{
+ m_nMonoMode = nMode;
+}
+
+bool
+cSampleManager::LoadSampleBank(uint8 nBank)
+{
+ ASSERT( nBank < MAX_SAMPLEBANKS );
+
+ if ( CTimer::GetIsCodePaused() )
+ return false;
+
+ if ( MusicManager.IsInitialised()
+ && MusicManager.GetMusicMode() == MUSICMODE_CUTSCENE
+ && nBank != SAMPLEBANK_MAIN )
+ {
+ return false;
+ }
+
+ if ( fseek(fpSampleDataHandle, nSampleBankDiscStartOffset[nBank], SEEK_SET) != 0 )
+ return false;
+
+ if ( fread((void *)nSampleBankMemoryStartAddress[nBank], 1, nSampleBankSize[nBank], fpSampleDataHandle) != nSampleBankSize[nBank] )
+ return false;
+
+ bSampleBankLoaded[nBank] = true;
+
+ return true;
+}
+
+void
+cSampleManager::UnloadSampleBank(uint8 nBank)
+{
+ ASSERT( nBank < MAX_SAMPLEBANKS );
+
+ ; // NOIMP
+}
+
+bool
+cSampleManager::IsSampleBankLoaded(uint8 nBank)
+{
+ ASSERT( nBank < MAX_SAMPLEBANKS );
+ return true;
+}
+
+bool
+cSampleManager::IsPedCommentLoaded(uint32 nComment)
+{
+ ASSERT( nComment < TOTAL_AUDIO_SAMPLES );
+
+ uint8 slot;
+
+ for ( int32 i = 0; i < _TODOCONST(3); i++ )
+ {
+ slot = nCurrentPedSlot - i - 1;
+ if ( nComment == nPedSlotSfx[slot] )
+ return true;
+ }
+
+ return false;
+}
+
+
+int32
+cSampleManager::_GetPedCommentSlot(uint32 nComment)
+{
+ uint8 slot;
+
+ for (int32 i = 0; i < _TODOCONST(3); i++)
+ {
+ slot = nCurrentPedSlot - i - 1;
+ if (nComment == nPedSlotSfx[slot])
+ return slot;
+ }
+
+ return -1;
+}
+
+bool
+cSampleManager::LoadPedComment(uint32 nComment)
+{
+ ASSERT( nComment < TOTAL_AUDIO_SAMPLES );
+
+ if ( CTimer::GetIsCodePaused() )
+ return false;
+
+ // no talking peds during cutsenes or the game end
+ if ( MusicManager.IsInitialised() )
+ {
+ switch ( MusicManager.GetMusicMode() )
+ {
+ case MUSICMODE_CUTSCENE:
+ {
+ return false;
+
+ break;
+ }
+
+ case MUSICMODE_FRONTEND:
+ {
+ if ( MusicManager.GetCurrentTrack() == STREAMED_SOUND_GAME_COMPLETED )
+ return false;
+
+ break;
+ }
+ }
+ }
+
+ if ( fseek(fpSampleDataHandle, m_aSamples[nComment].nOffset, SEEK_SET) != 0 )
+ return false;
+
+ if ( fread((void *)(nSampleBankMemoryStartAddress[SAMPLEBANK_PED] + PED_BLOCKSIZE*nCurrentPedSlot), 1, m_aSamples[nComment].nSize, fpSampleDataHandle) != m_aSamples[nComment].nSize )
+ return false;
+
+ nPedSlotSfx[nCurrentPedSlot] = nComment;
+
+ alBufferData(pedBuffers[nCurrentPedSlot],
+ AL_FORMAT_MONO16,
+ (void *)(nSampleBankMemoryStartAddress[SAMPLEBANK_PED] + PED_BLOCKSIZE*nCurrentPedSlot),
+ m_aSamples[nComment].nSize,
+ MAX_FREQ);
+
+ if ( ++nCurrentPedSlot >= MAX_PEDSFX )
+ nCurrentPedSlot = 0;
+
+ return true;
+}
+
+int32
+cSampleManager::GetBankContainingSound(uint32 offset)
+{
+ if ( offset >= BankStartOffset[SAMPLEBANK_PED] )
+ return SAMPLEBANK_PED;
+
+ if ( offset >= BankStartOffset[SAMPLEBANK_MAIN] )
+ return SAMPLEBANK_MAIN;
+
+ return SAMPLEBANK_INVALID;
+}
+
+int32
+cSampleManager::GetSampleBaseFrequency(uint32 nSample)
+{
+ ASSERT( nSample < TOTAL_AUDIO_SAMPLES );
+ return m_aSamples[nSample].nFrequency;
+}
+
+int32
+cSampleManager::GetSampleLoopStartOffset(uint32 nSample)
+{
+ ASSERT( nSample < TOTAL_AUDIO_SAMPLES );
+ return m_aSamples[nSample].nLoopStart;
+}
+
+int32
+cSampleManager::GetSampleLoopEndOffset(uint32 nSample)
+{
+ ASSERT( nSample < TOTAL_AUDIO_SAMPLES );
+ return m_aSamples[nSample].nLoopEnd;
+}
+
+uint32
+cSampleManager::GetSampleLength(uint32 nSample)
+{
+ ASSERT( nSample < TOTAL_AUDIO_SAMPLES );
+ return m_aSamples[nSample].nSize >> 1;
+}
+
+bool cSampleManager::UpdateReverb(void)
+{
+ return false;
+}
+
+void
+cSampleManager::SetChannelReverbFlag(uint32 nChannel, uint8 nReverbFlag)
+{
+ ; // NOIMP
+}
+
+bool
+cSampleManager::InitialiseChannel(uint32 nChannel, uint32 nSfx, uint8 nBank)
+{
+ ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS );
+
+ ALuint buffer;
+
+ if ( nSfx < SAMPLEBANK_MAX )
+ {
+ int32 offset = (m_aSamples[nSfx].nLoopStart > 0) ? (m_aSamples[nSfx].nOffset - m_aSamples[nSfx].nLoopStart) : m_aSamples[nSfx].nOffset;
+ int32 size = (m_aSamples[nSfx].nLoopStart > 0) ? (m_aSamples[nSfx].nLoopEnd - m_aSamples[nSfx].nLoopStart) : m_aSamples[nSfx].nSize;
+
+ void *data = malloc(size);
+ ASSERT(data != NULL);
+
+ if ( fseek(fpSampleDataHandle, offset + nSampleBankDiscStartOffset[nBank], SEEK_SET) != 0 )
+ {
+ free(data);
+ return false;
+ }
+
+ if ( fread(data, 1, size, fpSampleDataHandle) != size )
+ {
+ free(data);
+ return false;
+ }
+
+ ALuint buf;
+ alGenBuffers(1, &buf);
+ alBufferData(buf, AL_FORMAT_MONO16, data, size, MAX_FREQ);
+ free(data);
+
+ if ( !IsSampleBankLoaded(nBank) )
+ return false;
+
+ ALBuffers[nSfx].buffer = buf;
+ ALBuffers[nSfx].timer = 120000;
+
+ buffer = ALBuffers[nSfx].buffer;
+
+ ChannelSample[nChannel] = nSfx;
+ }
+ else
+ {
+ if ( !IsPedCommentLoaded(nSfx) )
+ return false;
+
+ int32 slot = _GetPedCommentSlot(nSfx);
+
+ buffer = pedBuffers[slot];
+ }
+
+ if ( buffer == 0 )
+ {
+ TRACE("No buffer to play id %d", nSfx);
+ return false;
+ }
+
+ if ( GetChannelUsedFlag(nChannel) )
+ {
+ TRACE("Stopping channel %d - really!!!", nChannel);
+ StopChannel(nChannel);
+ }
+
+ alSourcei(alChannel[nChannel], AL_BUFFER, 0);
+ currentChannelVolume [nChannel] = -1;
+ currentChannelFrequency [nChannel] = -1;
+ currentChannelMaxFrontDistance[nChannel] = -1;
+
+ if ( alChannel[nChannel] )
+ {
+ alSourcei(alChannel[nChannel], AL_BUFFER, buffer);
+ alSourcef(alChannel[nChannel], AL_PITCH, 1.0f);
+ ChannelPitch[nChannel] = 1.0f;
+ return true;
+ }
+
+ return false;
+}
+
+void
+cSampleManager::SetChannelEmittingVolume(uint32 nChannel, uint32 nVolume)
+{
+ ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS );
+
+ uint32 vol = nVolume;
+ if ( vol > MAX_VOLUME ) vol = MAX_VOLUME;
+
+ nChannelVolume[nChannel] = vol;
+
+ // reduce the volume for JB.MP3 and S4_BDBD.MP3
+ if ( MusicManager.GetMusicMode() == MUSICMODE_CUTSCENE
+ && MusicManager.GetCurrentTrack() != STREAMED_SOUND_NEWS_INTRO
+ && MusicManager.GetCurrentTrack() != STREAMED_SOUND_CUTSCENE_SAL4_BDBD )
+ {
+ nChannelVolume[nChannel] >>= 2;
+ }
+
+ uint32 channelVol = m_nEffectsFadeVolume*nChannelVolume[nChannel]*m_nEffectsVolume >> 14;
+ if ( ChannelSample[nChannel] >= SFX_CAR_REV_1 && SFX_CAR_REV_10 >= ChannelSample[nChannel] ) // nice hack
+ channelVol >>= 1;
+
+ if ( alChannel[nChannel] )
+ {
+ if ( currentChannelVolume[nChannel] != channelVol )
+ {
+ ALfloat gain = ALfloat(channelVol) / MAX_VOLUME;
+ alSourcef(alChannel[nChannel], AL_GAIN, gain);
+ currentChannelVolume[nChannel] = channelVol;
+ }
+ }
+}
+
+void
+cSampleManager::SetChannel3DPosition(uint32 nChannel, float fX, float fY, float fZ)
+{
+ ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS );
+
+ if ( alChannel[nChannel] )
+ {
+ alSource3f(alChannel[nChannel], AL_POSITION, -fX, fY, fZ);
+ }
+}
+
+void
+cSampleManager::SetChannel3DDistances(uint32 nChannel, float fMax, float fMin)
+{
+ ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS );
+
+ if ( alChannel[nChannel] )
+ {
+ if ( float(currentChannelMaxFrontDistance[nChannel]) != fMax )
+ {
+ alSourcef(alChannel[nChannel], AL_MAX_DISTANCE, fMax);
+ alSourcef(alChannel[nChannel], AL_REFERENCE_DISTANCE, 5.0f);
+ alSourcef(alChannel[nChannel], AL_MAX_GAIN, 1.0f);
+ currentChannelMaxFrontDistance[nChannel] = int32(fMax);
+ }
+ }
+}
+
+void
+cSampleManager::SetChannelVolume(uint32 nChannel, uint32 nVolume)
+{
+ ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS );
+
+ if ( nChannel == CHANNEL2D )
+ {
+ uint32 vol = nVolume;
+ if ( vol > MAX_VOLUME ) vol = MAX_VOLUME;
+
+ nChannelVolume[nChannel] = vol;
+
+ // increase the volume for JB.MP3 and S4_BDBD.MP3
+ if ( MusicManager.GetMusicMode() == MUSICMODE_CUTSCENE
+ && MusicManager.GetCurrentTrack() != STREAMED_SOUND_NEWS_INTRO
+ && MusicManager.GetCurrentTrack() != STREAMED_SOUND_CUTSCENE_SAL4_BDBD )
+ {
+ nChannelVolume[nChannel] >>= 2;
+ }
+
+ uint32 channelVol = m_nEffectsFadeVolume*nChannelVolume[nChannel]*m_nEffectsVolume >> 14;
+ if ( ChannelSample[nChannel] >= SFX_CAR_REV_1 && SFX_CAR_IDLE_10 >= ChannelSample[nChannel] ) // nice hack
+ channelVol >>= 1;
+
+ if ( alChannel[nChannel] )
+ {
+ if ( currentChannelVolume[nChannel] != channelVol )
+ {
+ ALfloat gain = ALfloat(channelVol) / MAX_VOLUME;
+ alSourcef(alChannel[nChannel], AL_GAIN, gain);
+ currentChannelVolume[nChannel] = channelVol;
+ }
+ }
+ }
+}
+
+void
+cSampleManager::SetChannelPan(uint32 nChannel, uint32 nPan)
+{
+ ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS );
+ ; // NOIMP
+}
+
+void
+cSampleManager::SetChannelFrequency(uint32 nChannel, uint32 nFreq)
+{
+ ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS );
+
+ if ( alChannel[nChannel] )
+ {
+ if ( currentChannelFrequency[nChannel] != nFreq )
+ {
+ ALfloat pitch = ALfloat(nFreq) / MAX_FREQ;
+ alSourcef(alChannel[nChannel], AL_PITCH, pitch);
+ currentChannelFrequency[nChannel] = nFreq;
+
+ if ( Abs(1.0f - pitch) < 0.01f )
+ ChannelPitch[nChannel] = 1.0f;
+ else
+ ChannelPitch[nChannel] = pitch;
+ }
+ }
+}
+
+void
+cSampleManager::SetChannelLoopPoints(uint32 nChannel, uint32 nLoopStart, int32 nLoopEnd)
+{
+ ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS );
+
+ ; // NOIMP
+}
+
+void
+cSampleManager::SetChannelLoopCount(uint32 nChannel, uint32 nLoopCount)
+{
+ ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS );
+
+ if ( nLoopCount != 0 )
+ alSourcei(alChannel[nChannel], AL_LOOPING, AL_FALSE);
+ else
+ alSourcei(alChannel[nChannel], AL_LOOPING, AL_TRUE);
+}
+
+bool
+cSampleManager::GetChannelUsedFlag(uint32 nChannel)
+{
+ ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS );
+
+ if ( alChannel[nChannel] )
+ {
+ ALint sourceState;
+ alGetSourcei(alChannel[nChannel], AL_SOURCE_STATE, &sourceState);
+ return sourceState == AL_PLAYING;
+ }
+
+ return false;
+}
+
+void
+cSampleManager::StartChannel(uint32 nChannel)
+{
+ ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS );
+
+ if ( alChannel[nChannel] )
+ {
+ if ( ChannelSample[nChannel] > SAMPLEBANK_END ) // PED's Bank
+ {
+ if ( ChannelPitch[nChannel] != 1.0f )
+ ChannelPitch[nChannel] = 1.0f;
+ }
+
+ alSourcef (alChannel[nChannel], AL_PITCH, ChannelPitch[nChannel]);
+ alSourcePlay(alChannel[nChannel]);
+ }
+}
+
+void
+cSampleManager::StopChannel(uint32 nChannel)
+{
+ ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS );
+
+ if ( alChannel[nChannel] )
+ {
+ alSourceStop(alChannel[nChannel]);
+
+ currentChannelVolume [nChannel] = -1;
+ currentChannelFrequency [nChannel] = -1;
+ currentChannelMaxFrontDistance[nChannel] = -1;
+ ChannelPitch [nChannel] = 1.0f;
+ }
+}
+
+void
+cSampleManager::PreloadStreamedFile(uint8 nFile, uint8 nStream)
+{
+ char filename[256];
+
+ ASSERT( nStream < MAX_STREAMS );
+
+ if ( nFile < TOTAL_STREAMED_SOUNDS )
+ {
+ if ( mp3Stream[nStream] )
+ {
+ delete mp3Stream[nStream];
+ mp3Stream[nStream] = NULL;
+ }
+
+ strcpy(filename, StreamedNameTable[nFile]);
+
+ MP3Stream *stream = new MP3Stream(filename, ALStreamSources[nStream], ALStreamBuffers[nStream]);
+ ASSERT(stream != NULL);
+
+ mp3Stream[nStream] = stream;
+
+ if ( stream->m_bIsOpened )
+ {
+ ;
+ }
+ else
+ {
+ delete stream;
+ mp3Stream[nStream] = NULL;
+ }
+ }
+}
+
+void
+cSampleManager::PauseStream(uint8 nPauseFlag, uint8 nStream)
+{
+ ASSERT( nStream < MAX_STREAMS );
+
+ MP3Stream *stream = mp3Stream[nStream];
+
+ if ( stream )
+ {
+ if ( nPauseFlag != 0 )
+ {
+ if ( !stream->m_bIsPaused )
+ {
+ alSourcePause(stream->m_alSource);
+ stream->m_bIsPaused = true;
+ }
+ }
+ else
+ {
+ if ( stream->m_bIsPaused )
+ {
+ alSourcef(stream->m_alSource, AL_PITCH, 1.0f);
+ alSourcePlay(stream->m_alSource);
+ stream->m_bIsPaused = false;
+ }
+ }
+ }
+}
+
+void
+cSampleManager::StartPreloadedStreamedFile(uint8 nStream)
+{
+ ASSERT( nStream < MAX_STREAMS );
+
+ MP3Stream *stream = mp3Stream[nStream];
+
+ if ( stream )
+ {
+ stream->Initialize();
+ if ( stream->m_bIsOpened )
+ {
+ //NOTE: set pos here on mobile
+
+ if ( stream->FillBuffers() != 0 )
+ {
+ alSourcef(stream->m_alSource, AL_PITCH, 1.0f);
+ alSourcePlay(stream->m_alSource);
+ stream->m_bIsFree = false;
+ }
+ }
+ }
+}
+
+bool
+cSampleManager::StartStreamedFile(uint8 nFile, uint32 nPos, uint8 nStream)
+{
+ char filename[256];
+
+ ASSERT( nStream < MAX_STREAMS );
+
+ if ( nFile < TOTAL_STREAMED_SOUNDS )
+ {
+ if ( mp3Stream[nStream] )
+ {
+ delete mp3Stream[nStream];
+ mp3Stream[nStream] = NULL;
+ }
+
+ strcpy(filename, StreamedNameTable[nFile]);
+
+ MP3Stream *stream = new MP3Stream(filename, ALStreamSources[nStream], ALStreamBuffers[nStream]);
+ ASSERT(stream != NULL);
+
+ mp3Stream[nStream] = stream;
+
+ if ( stream->m_bIsOpened )
+ {
+ stream->Initialize();
+ nStreamLength[nFile] = stream->m_nLength;
+ //MusicManager.SetTrackInfoLength(nFile, stream->m_nLength);
+
+ if ( stream->m_bIsOpened )
+ {
+ if ( nPos != 0 )
+ {
+ stream->SetPos(nPos);
+ }
+
+ if ( stream->FillBuffers() != 0 )
+ {
+ alSourcef(stream->m_alSource, AL_PITCH, 1.0f);
+ alSourcePlay(stream->m_alSource);
+ stream->m_bIsFree = false;
+ }
+ }
+
+ return true;
+ }
+ else
+ {
+ delete stream;
+ mp3Stream[nStream] = NULL;
+ }
+ }
+
+ return false;
+}
+
+void
+cSampleManager::StopStreamedFile(uint8 nStream)
+{
+ ASSERT( nStream < MAX_STREAMS );
+
+ MP3Stream *stream = mp3Stream[nStream];
+
+ if ( stream )
+ {
+ delete stream;
+ mp3Stream[nStream] = NULL;
+ }
+}
+
+int32
+cSampleManager::GetStreamedFilePosition(uint8 nStream)
+{
+ ASSERT( nStream < MAX_STREAMS );
+
+ MP3Stream *stream = mp3Stream[nStream];
+
+ if ( stream )
+ {
+ return (ftell(stream->m_fpFile) * 8) / stream->m_nBitRate;
+ }
+
+ return 0;
+}
+
+void
+cSampleManager::SetStreamedVolumeAndPan(uint8 nVolume, uint8 nPan, uint8 nEffectFlag, uint8 nStream)
+{
+ ASSERT( nStream < MAX_STREAMS );
+
+ if ( nVolume > MAX_VOLUME )
+ nVolume = MAX_VOLUME;
+
+ if ( nPan > MAX_VOLUME )
+ nPan = MAX_VOLUME;
+
+ nStreamVolume[nStream] = m_nMusicFadeVolume * nVolume;
+ nStreamPan [nStream] = nPan;
+
+ MP3Stream *stream = mp3Stream[nStream];
+
+ if ( stream )
+ {
+ uint32 vol;
+ if ( nEffectFlag )
+ vol = m_nEffectsFadeVolume*nVolume*m_nEffectsVolume >> 14;
+ else
+ vol = m_nMusicFadeVolume*nVolume*m_nMusicVolume >> 14;
+
+ if ( stream->m_nVolume != vol )
+ {
+ if ( stream->m_bIsOpened )
+ {
+ ALuint source = stream->m_alSource;
+ if ( source )
+ {
+ ALfloat gain = ALfloat(vol) / MAX_VOLUME;
+ alSourcef(source, AL_GAIN, gain);
+ stream = mp3Stream[nStream];
+ }
+ }
+
+ stream->m_nVolume = vol;
+ }
+ }
+}
+
+int32
+cSampleManager::GetStreamedFileLength(uint8 nStream)
+{
+ ASSERT( nStream < TOTAL_STREAMED_SOUNDS );
+
+ return nStreamLength[nStream];
+}
+
+bool
+cSampleManager::IsStreamPlaying(uint8 nStream)
+{
+ ASSERT( nStream < MAX_STREAMS );
+
+ MP3Stream *stream = mp3Stream[nStream];
+
+ if ( stream && stream->m_bIsOpened && !stream->m_bIsPaused )
+ {
+ ALint sourceState;
+ alGetSourcei(stream->m_alSource, AL_SOURCE_STATE, &sourceState);
+ if ( !stream->m_bIsFree || sourceState == AL_PLAYING )
+ return true;
+ }
+
+ return false;
+}
+
+void
+cSampleManager::Service(void)
+{
+ for ( int32 i = 0; i < MAX_STREAMS; i++ )
+ {
+ if ( mp3Stream[i] )
+ mp3Stream[i]->Update();
+ }
+
+ UpdateSoundBuffers();
+}
+
+bool
+cSampleManager::InitialiseSampleBanks(void)
+{
+ int32 nBank = SAMPLEBANK_MAIN;
+
+ fpSampleDescHandle = fopen(SampleBankDescFilename, "rb");
+ if ( fpSampleDescHandle == NULL )
+ return false;
+
+ fpSampleDataHandle = fopen(SampleBankDataFilename, "rb");
+ if ( fpSampleDataHandle == NULL )
+ {
+ fclose(fpSampleDescHandle);
+ fpSampleDescHandle = NULL;
+
+ return false;
+ }
+
+ fseek(fpSampleDataHandle, 0, SEEK_END);
+ int32 _nSampleDataEndOffset = ftell(fpSampleDataHandle);
+ rewind(fpSampleDataHandle);
+
+ fread(m_aSamples, sizeof(tSample), TOTAL_AUDIO_SAMPLES, fpSampleDescHandle);
+
+ fclose(fpSampleDescHandle);
+ fpSampleDescHandle = NULL;
+
+ for ( int32 i = 0; i < TOTAL_AUDIO_SAMPLES; i++ )
+ {
+ if ( BankStartOffset[nBank] == BankStartOffset[SAMPLEBANK_MAIN] + i )
+ {
+ nSampleBankDiscStartOffset[nBank] = m_aSamples[i].nOffset;
+ nBank++;
+ }
+ }
+
+ nSampleBankSize[SAMPLEBANK_MAIN] = nSampleBankDiscStartOffset[SAMPLEBANK_PED] - nSampleBankDiscStartOffset[SAMPLEBANK_MAIN];
+ nSampleBankSize[SAMPLEBANK_PED] = _nSampleDataEndOffset - nSampleBankDiscStartOffset[SAMPLEBANK_PED];
+
+ return true;
+}
+
+/*
+sub_1D8D40
+PreloadSoundBank(tSample *,uchar)
+CheckOpenALChannels(void)
+*/
+
+void MP3Stream::Initialize(void)
+{
+ if ( !m_bIsOpened )
+ return;
+
+ mpg123_format_none(m_pMPG);
+
+ mpg123_format(m_pMPG, 11000, MPG123_MONO|MPG123_STEREO, MPG123_ENC_SIGNED_16);
+ mpg123_format(m_pMPG, 24000, MPG123_MONO|MPG123_STEREO, MPG123_ENC_SIGNED_16);
+ mpg123_format(m_pMPG, 32000, MPG123_MONO|MPG123_STEREO, MPG123_ENC_SIGNED_16);
+ mpg123_format(m_pMPG, 44100, MPG123_MONO|MPG123_STEREO, MPG123_ENC_SIGNED_16);
+
+ if ( mpg123_open_feed(m_pMPG) != MPG123_OK )
+ return;
+
+ const uint32 CHUNK_SIZE = 1024*5;
+
+ if ( fread(m_pBuf, 1, CHUNK_SIZE, m_fpFile) != CHUNK_SIZE )
+ {
+ Delete();
+ return;
+ }
+
+ m_nBufSize -= CHUNK_SIZE;
+
+ mpg123_feed(m_pMPG, m_pBuf, CHUNK_SIZE);
+
+ if ( mpg123_getformat(m_pMPG, &m_nRate, &m_nChannels, &m_nEncoding) != MPG123_OK )
+ {
+ Delete();
+ return;
+ }
+
+ mpg123_frameinfo info;
+ if ( mpg123_info(m_pMPG, &info) != MPG123_OK )
+ {
+ Delete();
+ return;
+ }
+
+ m_nBitRate = info.bitrate;
+ m_nLength = 8 * m_nLengthInBytes / info.bitrate;
+ m_nBlockSize = mpg123_outblock(m_pMPG);
+ m_nNumBlocks = 5;
+ m_pBlocks = (unsigned char *)malloc(m_nNumBlocks * m_nBlockSize);
+}
+
+bool MP3Stream::FillBuffer(ALuint alBuffer)
+{
+ size_t done;
+
+ uint8 *pBlockBuff = (uint8 *)m_pBlocks;
+
+ bool fail = !(m_nBufSize > 1);
+
+ int err = mpg123_read(m_pMPG, m_pBlocks, m_nBlockSize, &done);
+ if ( alBuffer == 0 )
+ {
+ if ( err == MPG123_OK )
+ {
+ while ( mpg123_read(m_pMPG, pBlockBuff, m_nBlockSize, &done) == MPG123_OK )
+ ;
+ }
+
+ return true;
+ }
+
+ int32 blocks = 0;
+ for ( blocks = 0; blocks < m_nNumBlocks; blocks++ )
+ {
+ if ( err == MPG123_NEED_MORE )
+ {
+ if ( fail )
+ break;
+
+ size_t readSize = m_nBufSize;
+ if ( readSize > 0x4000 )
+ {
+ if ( fread(m_pBuf, 1, 0x4000, m_fpFile) != 0x4000 )
+ {
+ fail = true;
+ TRACE("MP3 ************* : MP3 read unsuccessful mid file, stopping queuing");
+ break;
+ }
+
+ m_nBufSize -= 0x4000;
+ mpg123_feed(m_pMPG, m_pBuf, 0x4000);
+ }
+ else
+ {
+ if ( fread(m_pBuf, 1, readSize, m_fpFile) != readSize )
+ {
+ fail = true;
+ break;
+ }
+
+ m_nBufSize -= readSize;
+ mpg123_feed(m_pMPG, m_pBuf, readSize);
+ }
+ }
+ else if ( err == MPG123_OK )
+ {
+ pBlockBuff += m_nBlockSize;
+ }
+ else
+ {
+ fail = true;
+ break;
+ }
+
+ err = mpg123_read(m_pMPG, pBlockBuff, m_nBlockSize, &done);
+ }
+
+ if ( blocks != 0 )
+ {
+ if ( m_nChannels == 1 )
+ alBufferData(alBuffer, AL_FORMAT_MONO16, m_pBlocks, m_nBlockSize*blocks, m_nRate);
+ else
+ alBufferData(alBuffer, AL_FORMAT_STEREO16, m_pBlocks, m_nBlockSize*blocks, m_nRate);
+ }
+
+ if ( fail && blocks < m_nNumBlocks )
+ m_bIsFree = true;
+
+ return blocks != 0;
+}
+
+void MP3Stream::Update(void)
+{
+ if ( !m_bIsOpened )
+ return;
+
+ if ( m_bIsFree )
+ return;
+
+ if ( !m_bIsPaused )
+ {
+ ALint sourceState;
+ ALint buffersProcessed = 0;
+
+ alGetSourcei(m_alSource, AL_SOURCE_STATE, &sourceState);
+ alGetSourcei(m_alSource, AL_BUFFERS_PROCESSED, &buffersProcessed);
+
+ ALint looping = AL_FALSE;
+ alGetSourcei(m_alSource, AL_LOOPING, &looping);
+
+ if ( looping == AL_TRUE )
+ {
+ TRACE("stream set looping");
+ alSourcei(m_alSource, AL_LOOPING, AL_TRUE);
+ }
+
+ while( buffersProcessed-- )
+ {
+ ALuint buffer;
+
+ alSourceUnqueueBuffers(m_alSource, 1, &buffer);
+
+ if ( !m_bIsFree && FillBuffer(buffer) )
+ alSourceQueueBuffers(m_alSource, 1, &buffer);
+ }
+
+ if ( sourceState != AL_PLAYING )
+ {
+ alSourcef(m_alSource, AL_PITCH, 1.0f);
+ alSourcePlay(m_alSource);
+ }
+ }
+}
+
+void MP3Stream::SetPos(uint32 nPos)
+{
+ uint32 pos = nPos;
+ if ( nPos > m_nLength )
+ pos %= m_nLength;
+
+ uint32 blockPos = m_nBitRate * pos / 8;
+ if ( blockPos > m_nLengthInBytes )
+ blockPos %= m_nLengthInBytes;
+
+ fseek(m_fpFile, blockPos, SEEK_SET);
+
+ size_t done;
+ while ( mpg123_read(m_pMPG, m_pBlocks, m_nBlockSize, &done) == MPG123_OK )
+ ;
+}
+
+int32 MP3Stream::FillBuffers()
+{
+ int32 i = 0;
+ for ( i = 0; i < ARRAY_SIZE(m_alBuffers); i++ )
+ {
+ if ( !FillBuffer(m_alBuffers[i]) )
+ break;
+ alSourceQueueBuffers(m_alSource, 1, &m_alBuffers[i]);
+ }
+
+ return i;
+}
+
+MP3Stream::MP3Stream(char *filename, ALuint source, ALuint *buffers)
+{
+ strcpy(m_aFilename, filename);
+ memset(m_alBuffers, 0, sizeof(m_alBuffers));
+ m_alSource = source;
+ memcpy(m_alBuffers, buffers, sizeof(m_alBuffers));
+ m_nVolume = -1;
+ m_pBlocks = NULL;
+ m_pBuf = NULL;
+ m_pMPG = NULL;
+ m_bIsPaused = false;
+ m_bIsOpened = true;
+ m_bIsFree = true;
+ m_fpFile = fopen(m_aFilename, "rb");
+
+ if ( m_fpFile )
+ {
+ m_nBufSize = filelength(fileno(m_fpFile));
+ m_nLengthInBytes = m_nBufSize;
+ m_pMPG = mpg123_new(NULL, NULL);
+ m_pBuf = (unsigned char *)malloc(0x4000);
+ }
+ else
+ {
+ m_bIsOpened = false;
+ Delete();
+ }
+}
+
+void MP3Stream::Delete()
+{
+ if ( m_pMPG )
+ {
+ mpg123_delete(m_pMPG);
+ m_pMPG = NULL;
+ }
+
+ if ( m_fpFile )
+ {
+ fclose(m_fpFile);
+ m_fpFile = NULL;
+ }
+
+ if ( m_alSource )
+ {
+ ALint sourceState = AL_STOPPED;
+ alGetSourcei(m_alSource, AL_SOURCE_STATE, &sourceState);
+ if (sourceState != AL_STOPPED )
+ alSourceStop(m_alSource);
+
+ ALint buffersQueued;
+ alGetSourcei(m_alSource, AL_BUFFERS_QUEUED, &buffersQueued);
+
+ ALuint value;
+ while (buffersQueued--)
+ alSourceUnqueueBuffers(m_alSource, 1, &value);
+
+ m_alSource = 0;
+ }
+
+ if ( m_pBlocks )
+ {
+ free(m_pBlocks);
+ m_pBlocks = NULL;
+ }
+
+ if ( m_pBuf )
+ {
+ free(m_pBuf);
+ m_pBuf = NULL;
+ }
+
+ m_bIsOpened = false;
+} \ No newline at end of file
diff --git a/src/audio/openal/samp_oal.h b/src/audio/openal/samp_oal.h
new file mode 100644
index 00000000..8bbdbcc9
--- /dev/null
+++ b/src/audio/openal/samp_oal.h
@@ -0,0 +1,340 @@
+#pragma once
+#include "common.h"
+#include "AudioSamples.h"
+
+#define MAX_VOLUME 127
+//#define MAX_FREQ 22050
+#define MAX_FREQ 32000
+
+struct tSample {
+ int32 nOffset;
+ uint32 nSize;
+ int32 nFrequency;
+ int32 nLoopStart;
+ int32 nLoopEnd;
+};
+
+enum
+{
+ SAMPLEBANK_MAIN,
+ SAMPLEBANK_PED,
+ MAX_SAMPLEBANKS,
+ SAMPLEBANK_INVALID
+};
+
+#define MAX_PEDSFX 7
+#define PED_BLOCKSIZE 79000
+
+
+//#define MAXCHANNELS 21 android
+#define MAXCHANNELS 28
+#define MAX2DCHANNELS 1
+#define CHANNEL2D MAXCHANNELS
+
+#define MAX_STREAMS 2
+
+struct ALCdevice_struct;
+struct ALCcontext_struct;
+typedef struct ALCdevice_struct ALCdevice;
+typedef struct ALCcontext_struct ALCcontext;
+
+class cSampleManager
+{
+ int field_0;
+ ALCdevice *m_pDevice;
+ ALCcontext *m_pContext;
+
+ uint8 m_nEffectsVolume;
+ uint8 m_nMusicVolume;
+ uint8 m_nEffectsFadeVolume;
+ uint8 m_nMusicFadeVolume;
+ uint8 m_nMonoMode;
+ char _pad0[3];
+ tSample m_aSamples[TOTAL_AUDIO_SAMPLES];
+
+public:
+
+
+
+ cSampleManager(void);
+ ~cSampleManager(void);
+
+ void SetSpeakerConfig(int32 nConfig);
+ uint32 GetMaximumSupportedChannels(void);
+
+ uint32 GetNum3DProvidersAvailable();
+ void SetNum3DProvidersAvailable(uint32 num);
+
+ char *Get3DProviderName(uint8 id);
+ void Set3DProviderName(uint8 id, char *name);
+
+ int8 GetCurrent3DProviderIndex(void);
+ int8 SetCurrent3DProvider(uint8 which);
+
+ bool IsMP3RadioChannelAvailable(void);
+
+ void ReleaseDigitalHandle (void);
+ void ReacquireDigitalHandle(void);
+
+ bool Initialise(void);
+ void Terminate (void);
+
+ void UpdateSoundBuffers(void);
+
+ bool CheckForAnAudioFileOnCD(void);
+ char GetCDAudioDriveLetter (void);
+
+ void UpdateEffectsVolume(void);
+
+ void SetEffectsMasterVolume(uint8 nVolume);
+ void SetMusicMasterVolume (uint8 nVolume);
+ void SetEffectsFadeVolume (uint8 nVolume);
+ void SetMusicFadeVolume (uint8 nVolume);
+ void SetMonoMode (uint8 nMode);
+
+ bool LoadSampleBank (uint8 nBank);
+ void UnloadSampleBank (uint8 nBank);
+ bool IsSampleBankLoaded(uint8 nBank);
+
+ bool IsPedCommentLoaded(uint32 nComment);
+ bool LoadPedComment (uint32 nComment);
+ int32 GetBankContainingSound(uint32 offset);
+
+ int32 _GetPedCommentSlot(uint32 nComment);
+
+ int32 GetSampleBaseFrequency (uint32 nSample);
+ int32 GetSampleLoopStartOffset(uint32 nSample);
+ int32 GetSampleLoopEndOffset (uint32 nSample);
+ uint32 GetSampleLength (uint32 nSample);
+
+ bool UpdateReverb(void);
+
+ void SetChannelReverbFlag (uint32 nChannel, uint8 nReverbFlag);
+ bool InitialiseChannel (uint32 nChannel, uint32 nSfx, uint8 nBank);
+ void SetChannelEmittingVolume(uint32 nChannel, uint32 nVolume);
+ void SetChannel3DPosition (uint32 nChannel, float fX, float fY, float fZ);
+ void SetChannel3DDistances (uint32 nChannel, float fMax, float fMin);
+ void SetChannelVolume (uint32 nChannel, uint32 nVolume);
+ void SetChannelPan (uint32 nChannel, uint32 nPan);
+ void SetChannelFrequency (uint32 nChannel, uint32 nFreq);
+ void SetChannelLoopPoints (uint32 nChannel, uint32 nLoopStart, int32 nLoopEnd);
+ void SetChannelLoopCount (uint32 nChannel, uint32 nLoopCount);
+ bool GetChannelUsedFlag (uint32 nChannel);
+ void StartChannel (uint32 nChannel);
+ void StopChannel (uint32 nChannel);
+
+ void PreloadStreamedFile (uint8 nFile, uint8 nStream);
+ void PauseStream (uint8 nPauseFlag, uint8 nStream);
+ void StartPreloadedStreamedFile (uint8 nStream);
+ bool StartStreamedFile (uint8 nFile, uint32 nPos, uint8 nStream);
+ void StopStreamedFile (uint8 nStream);
+ int32 GetStreamedFilePosition (uint8 nStream);
+ void SetStreamedVolumeAndPan(uint8 nVolume, uint8 nPan, uint8 nEffectFlag, uint8 nStream);
+ int32 GetStreamedFileLength (uint8 nStream);
+ bool IsStreamPlaying (uint8 nStream);
+ void Service(void);
+ bool InitialiseSampleBanks(void);
+};
+
+extern cSampleManager SampleManager;
+extern int32 BankStartOffset[MAX_SAMPLEBANKS];
+
+static char StreamedNameTable[][25]=
+{
+ "AUDIO\\HEAD.MP3",
+ "AUDIO\\CLASS.MP3",
+ "AUDIO\\KJAH.MP3",
+ "AUDIO\\RISE.MP3",
+ "AUDIO\\LIPS.MP3",
+ "AUDIO\\GAME.MP3",
+ "AUDIO\\MSX.MP3",
+ "AUDIO\\FLASH.MP3",
+ "AUDIO\\CHAT.MP3",
+ "AUDIO\\HEAD.MP3",
+ "AUDIO\\POLICE.MP3",
+ "AUDIO\\CITY.MP3",
+ "AUDIO\\WATER.MP3",
+ "AUDIO\\COMOPEN.MP3",
+ "AUDIO\\SUBOPEN.MP3",
+ "AUDIO\\JB.MP3",
+ "AUDIO\\BET.MP3",
+ "AUDIO\\L1_LG.MP3",
+ "AUDIO\\L2_DSB.MP3",
+ "AUDIO\\L3_DM.MP3",
+ "AUDIO\\L4_PAP.MP3",
+ "AUDIO\\L5_TFB.MP3",
+ "AUDIO\\J0_DM2.MP3",
+ "AUDIO\\J1_LFL.MP3",
+ "AUDIO\\J2_KCL.MP3",
+ "AUDIO\\J3_VH.MP3",
+ "AUDIO\\J4_ETH.MP3",
+ "AUDIO\\J5_DST.MP3",
+ "AUDIO\\J6_TBJ.MP3",
+ "AUDIO\\T1_TOL.MP3",
+ "AUDIO\\T2_TPU.MP3",
+ "AUDIO\\T3_MAS.MP3",
+ "AUDIO\\T4_TAT.MP3",
+ "AUDIO\\T5_BF.MP3",
+ "AUDIO\\S0_MAS.MP3",
+ "AUDIO\\S1_PF.MP3",
+ "AUDIO\\S2_CTG.MP3",
+ "AUDIO\\S3_RTC.MP3",
+ "AUDIO\\S5_LRQ.MP3",
+ "AUDIO\\S4_BDBA.MP3",
+ "AUDIO\\S4_BDBB.MP3",
+ "AUDIO\\S2_CTG2.MP3",
+ "AUDIO\\S4_BDBD.MP3",
+ "AUDIO\\S5_LRQB.MP3",
+ "AUDIO\\S5_LRQC.MP3",
+ "AUDIO\\A1_SSO.MP3",
+ "AUDIO\\A2_PP.MP3",
+ "AUDIO\\A3_SS.MP3",
+ "AUDIO\\A4_PDR.MP3",
+ "AUDIO\\A5_K2FT.MP3",
+ "AUDIO\\K1_KBO.MP3",
+ "AUDIO\\K2_GIS.MP3",
+ "AUDIO\\K3_DS.MP3",
+ "AUDIO\\K4_SHI.MP3",
+ "AUDIO\\K5_SD.MP3",
+ "AUDIO\\R0_PDR2.MP3",
+ "AUDIO\\R1_SW.MP3",
+ "AUDIO\\R2_AP.MP3",
+ "AUDIO\\R3_ED.MP3",
+ "AUDIO\\R4_GF.MP3",
+ "AUDIO\\R5_PB.MP3",
+ "AUDIO\\R6_MM.MP3",
+ "AUDIO\\D1_STOG.MP3",
+ "AUDIO\\D2_KK.MP3",
+ "AUDIO\\D3_ADO.MP3",
+ "AUDIO\\D5_ES.MP3",
+ "AUDIO\\D7_MLD.MP3",
+ "AUDIO\\D4_GTA.MP3",
+ "AUDIO\\D4_GTA2.MP3",
+ "AUDIO\\D6_STS.MP3",
+ "AUDIO\\A6_BAIT.MP3",
+ "AUDIO\\A7_ETG.MP3",
+ "AUDIO\\A8_PS.MP3",
+ "AUDIO\\A9_ASD.MP3",
+ "AUDIO\\K4_SHI2.MP3",
+ "AUDIO\\C1_TEX.MP3",
+ "AUDIO\\EL_PH1.MP3",
+ "AUDIO\\EL_PH2.MP3",
+ "AUDIO\\EL_PH3.MP3",
+ "AUDIO\\EL_PH4.MP3",
+ "AUDIO\\YD_PH1.MP3",
+ "AUDIO\\YD_PH2.MP3",
+ "AUDIO\\YD_PH3.MP3",
+ "AUDIO\\YD_PH4.MP3",
+ "AUDIO\\HD_PH1.MP3",
+ "AUDIO\\HD_PH2.MP3",
+ "AUDIO\\HD_PH3.MP3",
+ "AUDIO\\HD_PH4.MP3",
+ "AUDIO\\HD_PH5.MP3",
+ "AUDIO\\MT_PH1.MP3",
+ "AUDIO\\MT_PH2.MP3",
+ "AUDIO\\MT_PH3.MP3",
+ "AUDIO\\MT_PH4.MP3",
+ "AUDIO\\MISCOM.MP3",
+ "AUDIO\\END.MP3",
+ "AUDIO\\lib_a1.MP3",
+ "AUDIO\\lib_a2.MP3",
+ "AUDIO\\lib_a.MP3",
+ "AUDIO\\lib_b.MP3",
+ "AUDIO\\lib_c.MP3",
+ "AUDIO\\lib_d.MP3",
+ "AUDIO\\l2_a.MP3",
+ "AUDIO\\j4t_1.MP3",
+ "AUDIO\\j4t_2.MP3",
+ "AUDIO\\j4t_3.MP3",
+ "AUDIO\\j4t_4.MP3",
+ "AUDIO\\j4_a.MP3",
+ "AUDIO\\j4_b.MP3",
+ "AUDIO\\j4_c.MP3",
+ "AUDIO\\j4_d.MP3",
+ "AUDIO\\j4_e.MP3",
+ "AUDIO\\j4_f.MP3",
+ "AUDIO\\j6_1.MP3",
+ "AUDIO\\j6_a.MP3",
+ "AUDIO\\j6_b.MP3",
+ "AUDIO\\j6_c.MP3",
+ "AUDIO\\j6_d.MP3",
+ "AUDIO\\t4_a.MP3",
+ "AUDIO\\s1_a.MP3",
+ "AUDIO\\s1_a1.MP3",
+ "AUDIO\\s1_b.MP3",
+ "AUDIO\\s1_c.MP3",
+ "AUDIO\\s1_c1.MP3",
+ "AUDIO\\s1_d.MP3",
+ "AUDIO\\s1_e.MP3",
+ "AUDIO\\s1_f.MP3",
+ "AUDIO\\s1_g.MP3",
+ "AUDIO\\s1_h.MP3",
+ "AUDIO\\s1_i.MP3",
+ "AUDIO\\s1_j.MP3",
+ "AUDIO\\s1_k.MP3",
+ "AUDIO\\s1_l.MP3",
+ "AUDIO\\s3_a.MP3",
+ "AUDIO\\s3_b.MP3",
+ "AUDIO\\el3_a.MP3",
+ "AUDIO\\mf1_a.MP3",
+ "AUDIO\\mf2_a.MP3",
+ "AUDIO\\mf3_a.MP3",
+ "AUDIO\\mf3_b.MP3",
+ "AUDIO\\mf3_b1.MP3",
+ "AUDIO\\mf3_c.MP3",
+ "AUDIO\\mf4_a.MP3",
+ "AUDIO\\mf4_b.MP3",
+ "AUDIO\\mf4_c.MP3",
+ "AUDIO\\a1_a.MP3",
+ "AUDIO\\a3_a.MP3",
+ "AUDIO\\a5_a.MP3",
+ "AUDIO\\a4_a.MP3",
+ "AUDIO\\a4_b.MP3",
+ "AUDIO\\a4_c.MP3",
+ "AUDIO\\a4_d.MP3",
+ "AUDIO\\k1_a.MP3",
+ "AUDIO\\k3_a.MP3",
+ "AUDIO\\r1_a.MP3",
+ "AUDIO\\r2_a.MP3",
+ "AUDIO\\r2_b.MP3",
+ "AUDIO\\r2_c.MP3",
+ "AUDIO\\r2_d.MP3",
+ "AUDIO\\r2_e.MP3",
+ "AUDIO\\r2_f.MP3",
+ "AUDIO\\r2_g.MP3",
+ "AUDIO\\r2_h.MP3",
+ "AUDIO\\r5_a.MP3",
+ "AUDIO\\r6_a.MP3",
+ "AUDIO\\r6_a1.MP3",
+ "AUDIO\\r6_b.MP3",
+ "AUDIO\\lo2_a.MP3",
+ "AUDIO\\lo6_a.MP3",
+ "AUDIO\\yd2_a.MP3",
+ "AUDIO\\yd2_b.MP3",
+ "AUDIO\\yd2_c.MP3",
+ "AUDIO\\yd2_c1.MP3",
+ "AUDIO\\yd2_d.MP3",
+ "AUDIO\\yd2_e.MP3",
+ "AUDIO\\yd2_f.MP3",
+ "AUDIO\\yd2_g.MP3",
+ "AUDIO\\yd2_h.MP3",
+ "AUDIO\\yd2_ass.MP3",
+ "AUDIO\\yd2_ok.MP3",
+ "AUDIO\\h5_a.MP3",
+ "AUDIO\\h5_b.MP3",
+ "AUDIO\\h5_c.MP3",
+ "AUDIO\\ammu_a.MP3",
+ "AUDIO\\ammu_b.MP3",
+ "AUDIO\\ammu_c.MP3",
+ "AUDIO\\door_1.MP3",
+ "AUDIO\\door_2.MP3",
+ "AUDIO\\door_3.MP3",
+ "AUDIO\\door_4.MP3",
+ "AUDIO\\door_5.MP3",
+ "AUDIO\\door_6.MP3",
+ "AUDIO\\t3_a.MP3",
+ "AUDIO\\t3_b.MP3",
+ "AUDIO\\t3_c.MP3",
+ "AUDIO\\k1_b.MP3",
+ "AUDIO\\cat1.MP3"
+};
diff --git a/src/audio/sampman.cpp b/src/audio/sampman.cpp
index 6edb6028..aa6b67dc 100644
--- a/src/audio/sampman.cpp
+++ b/src/audio/sampman.cpp
@@ -1,2334 +1,7 @@
-#include <windows.h>
-#include <shobjidl.h>
-#include <shlguid.h>
-
-#include <time.h>
-
-#include "eax.h"
-#include "eax-util.h"
-#include "mss.h"
-
-#include "sampman.h"
-#include "AudioManager.h"
-#include "MusicManager.h"
-#include "Frontend.h"
-#include "Timer.h"
-#include "patcher.h"
-
-#pragma comment( lib, "mss32.lib" )
-
-cSampleManager &SampleManager = *(cSampleManager *)0x7341E0;
-extern int32 (&BankStartOffset)[MAX_SAMPLEBANKS] = *(int32 (*)[MAX_SAMPLEBANKS])*(int *)0x6FAB70;
-
-///////////////////////////////////////////////////////////////
-
-char SampleBankDescFilename[] = "AUDIO\\SFX.SDT";
-char SampleBankDataFilename[] = "AUDIO\\SFX.RAW";
-
-FILE *fpSampleDescHandle;
-FILE *fpSampleDataHandle;
-bool bSampleBankLoaded [MAX_SAMPLEBANKS];
-int32 nSampleBankDiscStartOffset [MAX_SAMPLEBANKS];
-int32 nSampleBankSize [MAX_SAMPLEBANKS];
-int32 nSampleBankMemoryStartAddress[MAX_SAMPLEBANKS];
-int32 _nSampleDataEndOffset;
-
-int32 nPedSlotSfx [MAX_PEDSFX];
-int32 nPedSlotSfxAddr[MAX_PEDSFX];
-uint8 nCurrentPedSlot;
-
-uint8 nChannelVolume[MAXCHANNELS+MAX2DCHANNELS];
-
-uint32 nStreamLength[TOTAL_STREAMED_SOUNDS];
-
-///////////////////////////////////////////////////////////////
-struct tMP3Entry
-{
- char aFilename[MAX_PATH];
-
- uint32 nTrackLength;
- uint32 nTrackStreamPos;
-
- tMP3Entry *pNext;
- char *pLinkPath;
-};
-
-uint32 nNumMP3s;
-tMP3Entry *_pMP3List;
-char _mp3DirectoryPath[MAX_PATH];
-HSTREAM mp3Stream [MAX_MP3STREAMS];
-int8 nStreamPan [MAX_MP3STREAMS];
-int8 nStreamVolume[MAX_MP3STREAMS];
-uint32 _CurMP3Index;
-int32 _CurMP3Pos;
-bool _bIsMp3Active;
-
-#if defined(GTA3_1_1_PATCH) || defined(GTA3_STEAM_PATCH) || defined(NO_CDCHECK)
-bool _bUseHDDAudio;
-char _aHDDPath[MAX_PATH];
-#endif
-///////////////////////////////////////////////////////////////
-
-
-bool _bSampmanInitialised = false;
-
-//
-// Miscellaneous globals / defines
-
-// Env Size Diffus Room RoomHF RoomLF DecTm DcHF DcLF Refl RefDel Ref Pan Revb RevDel Rev Pan EchTm EchDp ModTm ModDp AirAbs HFRef LFRef RRlOff FLAGS
-
-EAXLISTENERPROPERTIES StartEAX3 =
- {26, 1.7f, 0.8f, -1000, -1000, -100, 4.42f, 0.14f, 1.00f, 429, 0.014f, 0.00f,0.00f,0.00f, 1023, 0.021f, 0.00f,0.00f,0.00f, 0.250f, 0.000f, 0.250f, 0.000f, -5.0f, 2727.1f, 250.0f, 0.00f, 0x3f };
-
-EAXLISTENERPROPERTIES FinishEAX3 =
- {26, 100.0f, 1.0f, 0, -1000, -2200, 20.0f, 1.39f, 1.00f, 1000, 0.069f, 0.00f,0.00f,0.00f, 400, 0.100f, 0.00f,0.00f,0.00f, 0.250f, 1.000f, 3.982f, 0.000f, -18.0f, 3530.8f, 417.9f, 6.70f, 0x3f };
-
-EAXLISTENERPROPERTIES EAX3Params;
-
-S32 prevprovider=-1;
-S32 curprovider=-1;
-S32 usingEAX=0;
-S32 usingEAX3=0;
-HPROVIDER opened_provider=0;
-H3DSAMPLE opened_samples[MAXCHANNELS] = {0};
-HSAMPLE opened_2dsamples[MAX2DCHANNELS] = {0};
-HDIGDRIVER DIG;
-S32 speaker_type=0;
-
-U32 _maxSamples;
-float _fPrevEaxRatioDestination;
-bool _usingMilesFast2D;
-float _fEffectsLevel;
-
-
-struct
-{
- HPROVIDER id;
- char name[80];
-}providers[MAXPROVIDERS];
-
-typedef struct provider_stuff
-{
- char* name;
- HPROVIDER id;
-} provider_stuff;
-
-
-static int __cdecl comp(const provider_stuff*s1,const provider_stuff*s2)
-{
- return(strcasecmp(s1->name, s2->name));
-}
-
-static void
-add_providers()
-{
- provider_stuff pi[MAXPROVIDERS];
- U32 n,i,j;
-
- SampleManager.SetNum3DProvidersAvailable(0);
-
- HPROENUM next = HPROENUM_FIRST;
-
- n=0;
- while (AIL_enumerate_3D_providers(&next, &pi[n].id, &pi[n].name) && (n<MAXPROVIDERS))
- {
- ++n;
- }
-
- qsort(pi,n,sizeof(pi[0]), (int(__cdecl*)(void const*, void const*))comp);
-
- for(i=0;i<n;i++)
- {
- providers[i].id=pi[i].id;
- strcpy(providers[i].name, pi[i].name);
- SampleManager.Set3DProviderName(i, providers[i].name);
- }
-
- SampleManager.SetNum3DProvidersAvailable(n);
-
- for(j=n;j<MAXPROVIDERS;j++)
- SampleManager.Set3DProviderName(j, NULL);
-}
-
-static void
-release_existing()
-{
- for ( U32 i = 0; i < _maxSamples; i++ )
- {
- if ( opened_samples[i] )
- {
- AIL_release_3D_sample_handle(opened_samples[i]);
- opened_samples[i] = NULL;
- }
- }
-
- if ( opened_provider )
- {
- AIL_close_3D_provider(opened_provider);
- opened_provider = NULL;
- }
-
- _fPrevEaxRatioDestination = 0.0f;
- _usingMilesFast2D = false;
- _fEffectsLevel = 0.0f;
-}
-
-static bool
-set_new_provider(S32 index)
-{
- DWORD result;
-
- if ( curprovider == index )
- return true;
-
- //close the already opened provider
- curprovider = index;
-
- release_existing();
-
- if ( curprovider != -1 )
- {
- if ( !strcmp(providers[index].name, "Dolby Surround") )
- _maxSamples = MAXCHANNELS_SURROUND;
- else
- _maxSamples = MAXCHANNELS;
-
- AIL_set_3D_provider_preference(providers[index].id, "Maximum supported samples", &_maxSamples);
-
- //load the new provider
- result = AIL_open_3D_provider(providers[index].id);
-
- if (result != M3D_NOERR)
- {
- curprovider=-1;
-
- OutputDebugStringA(AIL_last_error());
-
- release_existing();
-
- return false;
- }
- else
- {
- opened_provider=providers[index].id;
-
- //see if we're running under an EAX compatible provider
-
- if ( !strcmp(providers[index].name, "Creative Labs EAX 3 (TM)") )
- {
- usingEAX = 1;
- usingEAX3 = 1;
- }
- else
- {
- usingEAX3 = 0;
-
- result=AIL_3D_room_type(opened_provider);
- usingEAX=(((S32)result)!=-1)?1:0; // will be something other than -1 on EAX
- }
-
- if ( usingEAX3 )
- {
- OutputDebugString("DOING SPECIAL EAX 3 STUFF!");
- AIL_set_3D_provider_preference(opened_provider, "EAX all parameters", &FinishEAX3);
- }
- else if ( usingEAX )
- {
- AIL_set_3D_room_type(opened_provider, ENVIRONMENT_CAVE);
-
- if ( !strcmp(providers[index].name, "Miles Fast 2D Positional Audio") )
- _usingMilesFast2D = true;
- }
-
- AIL_3D_provider_attribute(opened_provider, "Maximum supported samples", &_maxSamples);
-
- if ( _maxSamples > MAXCHANNELS )
- _maxSamples = MAXCHANNELS;
-
- SampleManager.SetSpeakerConfig(speaker_type);
-
- //obtain a 3D sample handles
- for ( U32 i = 0; i < _maxSamples; ++i )
- {
- opened_samples[i] = AIL_allocate_3D_sample_handle(opened_provider);
- if ( opened_samples[i] != NULL )
- AIL_set_3D_sample_effects_level(opened_samples[i], 0.0f);
- }
-
- return true;
- }
- }
-
- return false;
-}
-
-void
-cSampleManager::SetSpeakerConfig(int32 which)
-{
- switch ( which )
- {
- case 1:
- speaker_type=AIL_3D_2_SPEAKER;
- break;
-
- case 2:
- speaker_type=AIL_3D_HEADPHONE;
- break;
-
- case 3:
- speaker_type=AIL_3D_4_SPEAKER;
- break;
-
- default:
- return;
- break;
- }
-
- if (opened_provider)
- AIL_set_3D_speaker_type(opened_provider, speaker_type);
-}
-
-uint32
-cSampleManager::GetMaximumSupportedChannels(void)
-{
- if ( _maxSamples > MAXCHANNELS )
- return MAXCHANNELS;
-
- return _maxSamples;
-}
-
-int8
-cSampleManager::GetCurrent3DProviderIndex(void)
-{
- return curprovider;
-}
-
-int8
-cSampleManager::SetCurrent3DProvider(uint8 nProvider)
-{
- S32 savedprovider = curprovider;
-
- if ( nProvider < m_nNumberOfProviders )
- {
- if ( set_new_provider(nProvider) )
- return curprovider;
- else if ( savedprovider != -1 && savedprovider < m_nNumberOfProviders && set_new_provider(savedprovider) )
- return curprovider;
- else
- return -1;
- }
- else
- return curprovider;
-}
-
-static bool
-_ResolveLink(char const *path, char *out)
-{
- IShellLink* psl;
- WIN32_FIND_DATA fd;
- char filepath[MAX_PATH];
-
- CoInitialize(NULL);
-
- if (SUCCEEDED( CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&psl ) ))
- {
- IPersistFile *ppf;
-
- if (SUCCEEDED(psl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf)))
- {
- WCHAR wpath[MAX_PATH];
-
- MultiByteToWideChar(CP_ACP, 0, path, -1, wpath, MAX_PATH);
-
- if (SUCCEEDED(ppf->Load(wpath, STGM_READ)))
- {
- /* Resolve the link */
- if (SUCCEEDED(psl->Resolve(NULL, SLR_ANY_MATCH|SLR_NO_UI|SLR_NOSEARCH)))
- {
- strcpy(filepath, path);
-
- if (SUCCEEDED(psl->GetPath(filepath, MAX_PATH, &fd, SLGP_UNCPRIORITY)))
- {
- OutputDebugString(fd.cFileName);
-
- strcpy(out, filepath);
- // FIX: Release the objects. Taken from SA.
-#ifdef FIX_BUGS
- ppf->Release();
- psl->Release();
-#endif
- return true;
- }
- }
- }
-
- ppf->Release();
- }
- psl->Release();
- }
-
- return false;
-}
-
-static void
-_FindMP3s(void)
-{
- tMP3Entry *pList;
- bool bShortcut;
- bool bInitFirstEntry;
- HANDLE hFind;
- char path[MAX_PATH];
- char filepath[MAX_PATH*2];
- S32 total_ms;
- WIN32_FIND_DATA fd;
-
-
- if ( GetCurrentDirectory(MAX_PATH, _mp3DirectoryPath) == 0 )
- {
- GetLastError();
- return;
- }
-
- OutputDebugString("Finding MP3s...");
- strcpy(path, _mp3DirectoryPath);
- strcat(path, "\\MP3\\");
-
- strcpy(_mp3DirectoryPath, path);
- OutputDebugString(_mp3DirectoryPath);
-
- strcat(path, "*");
-
- hFind = FindFirstFile(path, &fd);
-
- if ( hFind == INVALID_HANDLE_VALUE )
- {
- GetLastError();
- return;
- }
-
- strcpy(filepath, _mp3DirectoryPath);
- strcat(filepath, fd.cFileName);
-
- int32 filepathlen = strlen(filepath);
-
- if ( filepathlen <= 0)
- {
- FindClose(hFind);
- return;
- }
-
- FILE *f = fopen("MP3\\MP3Report.txt", "w");
-
- if ( f )
- {
- fprintf(f, "MP3 Report File\n\n");
- fprintf(f, "\"%s\"", fd.cFileName);
- }
-
-
- if ( filepathlen > 4 )
- {
- if ( !strcmp(&filepath[filepathlen - 4], ".lnk") )
- {
- if ( _ResolveLink(filepath, filepath) )
- {
- OutputDebugString("Resolving Link");
- OutputDebugString(filepath);
-
- if ( f )
- fprintf(f, " - shortcut to \"%s\"", filepath);
- }
- else
- {
- if ( f )
- fprintf(f, " - couldn't resolve shortcut");
- }
-
- bShortcut = true;
- }
- else
- {
- bShortcut = false;
- }
- }
-
- mp3Stream[0] = AIL_open_stream(DIG, filepath, 0);
- if ( mp3Stream[0] )
- {
- AIL_stream_ms_position(mp3Stream[0], &total_ms, NULL);
-
- AIL_close_stream(mp3Stream[0]);
- mp3Stream[0] = NULL;
-
- OutputDebugString(fd.cFileName);
-
- _pMP3List = new tMP3Entry;
-
- if ( _pMP3List == NULL )
- {
- FindClose(hFind);
-
- if ( f )
- fclose(f);
-
- return;
- }
-
- nNumMP3s = 1;
-
- strcpy(_pMP3List->aFilename, fd.cFileName);
-
- _pMP3List->nTrackLength = total_ms;
-
- _pMP3List->pNext = NULL;
-
- pList = _pMP3List;
-
- if ( bShortcut )
- {
- _pMP3List->pLinkPath = new char[MAX_PATH*2];
- strcpy(_pMP3List->pLinkPath, filepath);
- }
- else
- {
- _pMP3List->pLinkPath = NULL;
- }
-
- if ( f )
- fprintf(f, " - OK\n");
-
- bInitFirstEntry = false;
- }
- else
- {
- strcat(filepath, " - NOT A VALID MP3");
-
- OutputDebugString(filepath);
-
- if ( f )
- fprintf(f, " - not an MP3 or supported MP3 type\n");
-
- bInitFirstEntry = true;
- }
-
- while ( true )
- {
- if ( !FindNextFile(hFind, &fd) )
- {
- if ( f )
- {
- fprintf(f, "\nTOTAL SUPPORTED MP3s: %d\n", nNumMP3s);
- fclose(f);
- }
-
- FindClose(hFind);
-
- return;
- }
-
- if ( bInitFirstEntry )
- {
- strcpy(filepath, _mp3DirectoryPath);
- strcat(filepath, fd.cFileName);
-
- int32 filepathlen = strlen(filepath);
-
- if ( f )
- fprintf(f, "\"%s\"", fd.cFileName);
-
- if ( filepathlen > 0 )
- {
- if ( filepathlen > 4 )
- {
- if ( !strcmp(&filepath[filepathlen - 4], ".lnk") )
- {
- if ( _ResolveLink(filepath, filepath) )
- {
- OutputDebugString("Resolving Link");
- OutputDebugString(filepath);
-
- if ( f )
- fprintf(f, " - shortcut to \"%s\"", filepath);
- }
- else
- {
- if ( f )
- fprintf(f, " - couldn't resolve shortcut");
- }
-
- bShortcut = true;
- }
- else
- {
- bShortcut = false;
-
- if ( filepathlen > MAX_PATH )
- {
- if ( f )
- fprintf(f, " - Filename and path too long - %s - IGNORED)\n", filepath);
-
- continue;
- }
- }
- }
-
- mp3Stream[0] = AIL_open_stream(DIG, filepath, 0);
- if ( mp3Stream[0] )
- {
- AIL_stream_ms_position(mp3Stream[0], &total_ms, NULL);
-
- AIL_close_stream(mp3Stream[0]);
- mp3Stream[0] = NULL;
-
- OutputDebugString(fd.cFileName);
-
- _pMP3List = new tMP3Entry;
-
- if ( _pMP3List == NULL)
- {
- if ( f )
- {
- fprintf(f, "\nTOTAL SUPPORTED MP3s: %d\n", nNumMP3s);
- fclose(f);
- }
- FindClose(hFind);
- return;
- }
-
- nNumMP3s = 1;
-
- strcpy(_pMP3List->aFilename, fd.cFileName);
-
- _pMP3List->nTrackLength = total_ms;
- _pMP3List->pNext = NULL;
-
- if ( bShortcut )
- {
- _pMP3List->pLinkPath = new char [MAX_PATH*2];
- strcpy(_pMP3List->pLinkPath, filepath);
- }
- else
- {
- _pMP3List->pLinkPath = NULL;
- }
-
- pList = _pMP3List;
-
- if ( f )
- fprintf(f, " - OK\n");
-
- bInitFirstEntry = false;
- }
- else
- {
- strcat(filepath, " - NOT A VALID MP3");
- OutputDebugString(filepath);
-
- if ( f )
- fprintf(f, " - not an MP3 or supported MP3 type\n");
- }
- }
- }
- else
- {
- strcpy(filepath, _mp3DirectoryPath);
- strcat(filepath, fd.cFileName);
-
- int32 filepathlen = strlen(filepath);
-
- if ( filepathlen > 0 )
- {
- if ( f )
- fprintf(f, "\"%s\"", fd.cFileName);
-
- if ( filepathlen > 4 )
- {
- if ( !strcmp(&filepath[filepathlen - 4], ".lnk") )
- {
- if ( _ResolveLink(filepath, filepath) )
- {
- OutputDebugString("Resolving Link");
- OutputDebugString(filepath);
-
- if ( f )
- fprintf(f, " - shortcut to \"%s\"", filepath);
- }
- else
- {
- if ( f )
- fprintf(f, " - couldn't resolve shortcut");
- }
-
- bShortcut = true;
- }
- else
- {
- bShortcut = false;
- }
- }
-
- mp3Stream[0] = AIL_open_stream(DIG, filepath, 0);
- if ( mp3Stream[0] )
- {
- AIL_stream_ms_position(mp3Stream[0], &total_ms, NULL);
-
- AIL_close_stream(mp3Stream[0]);
- mp3Stream[0] = NULL;
-
- pList->pNext = new tMP3Entry;
-
- tMP3Entry *e = pList->pNext;
-
- if ( e == NULL)
- {
- if ( f )
- {
- fprintf(f, "\nTOTAL SUPPORTED MP3s: %d\n", nNumMP3s);
- fclose(f);
- }
- FindClose(hFind);
- return;
- }
-
- pList = pList->pNext;
-
- strcpy(e->aFilename, fd.cFileName);
- e->nTrackLength = total_ms;
- e->pNext = NULL;
-
- if ( bShortcut )
- {
- e->pLinkPath = new char [MAX_PATH*2];
- strcpy(e->pLinkPath, filepath);
- }
- else
- {
- e->pLinkPath = NULL;
- }
-
- nNumMP3s++;
-
- OutputDebugString(fd.cFileName);
-
- if ( f )
- fprintf(f, " - OK\n");
- }
- else
- {
- strcat(filepath, " - NOT A VALID MP3");
- OutputDebugString(filepath);
-
- if ( f )
- fprintf(f, " - not an MP3 or supported MP3 type\n");
- }
- }
- }
- }
-}
-
-static void
-_DeleteMP3Entries(void)
-{
- tMP3Entry *e = _pMP3List;
-
- while ( e != NULL )
- {
- tMP3Entry *next = e->pNext;
-
- if ( next == NULL )
- next = NULL;
-
- if ( e->pLinkPath != NULL )
- {
-#ifndef FIX_BUGS
- delete e->pLinkPath; // BUG: should be delete []
+#pragma once
+#include "common.h"
+#ifndef OPENAL
+#include "miles\sampman_mss.cpp"
#else
- delete[] e->pLinkPath;
-#endif
- e->pLinkPath = NULL;
- }
-
- delete e;
-
- if ( next )
- e = next;
- else
- e = NULL;
-
- nNumMP3s--;
- }
-
-
- if ( nNumMP3s != 0 )
- {
- OutputDebugString("Not all MP3 entries were deleted");
- nNumMP3s = 0;
- }
-
- _pMP3List = NULL;
-}
-
-static tMP3Entry *
-_GetMP3EntryByIndex(uint32 idx)
-{
- uint32 n = ( idx < nNumMP3s ) ? idx : 0;
-
- if ( _pMP3List != NULL )
- {
- tMP3Entry *e = _pMP3List;
-
- for ( uint32 i = 0; i < n; i++ )
- e = e->pNext;
-
- return e;
-
- }
-
- return NULL;
-}
-
-static inline bool
-_GetMP3PosFromStreamPos(uint32 *pPosition, tMP3Entry **pEntry)
-{
- _CurMP3Index = 0;
-
- for ( *pEntry = _pMP3List; *pEntry != NULL; *pEntry = (*pEntry)->pNext )
- {
- if ( *pPosition >= (*pEntry)->nTrackStreamPos
- && *pPosition < (*pEntry)->nTrackLength + (*pEntry)->nTrackStreamPos )
- {
- *pPosition -= (*pEntry)->nTrackStreamPos;
- _CurMP3Pos = *pPosition;
-
- return true;
- }
-
- _CurMP3Index++;
- }
-
- *pPosition = 0;
- *pEntry = _pMP3List;
- _CurMP3Pos = 0;
- _CurMP3Index = 0;
-
- return false;
-}
-
-bool
-cSampleManager::IsMP3RadioChannelAvailable(void)
-{
- return nNumMP3s != 0;
-}
-
-void
-cSampleManager::ReleaseDigitalHandle(void)
-{
- if ( DIG )
- {
- prevprovider = curprovider;
- release_existing();
- curprovider = -1;
- AIL_digital_handle_release(DIG);
- }
-}
-
-void
-cSampleManager::ReacquireDigitalHandle(void)
-{
- if ( DIG )
- {
- AIL_digital_handle_reacquire(DIG);
- if ( prevprovider != -1 )
- set_new_provider(prevprovider);
- }
-}
-
-bool
-cSampleManager::Initialise(void)
-{
- TRACE("start");
-
- if ( _bSampmanInitialised )
- return true;
-
- {
- for ( int32 i = 0; i < TOTAL_AUDIO_SAMPLES; i++ )
- {
- m_aSamples[i].nOffset = 0;
- m_aSamples[i].nSize = 0;
- m_aSamples[i].nFrequency = 22050;
- m_aSamples[i].nLoopStart = 0;
- m_aSamples[i].nLoopEnd = -1;
- }
-
- m_nEffectsVolume = MAX_VOLUME;
- m_nMusicVolume = MAX_VOLUME;
- m_nEffectsFadeVolume = MAX_VOLUME;
- m_nMusicFadeVolume = MAX_VOLUME;
-
- m_nMonoMode = 0;
- }
-
- // miles
- TRACE("MILES");
- {
- curprovider = -1;
- prevprovider = -1;
-
- _usingMilesFast2D = false;
- usingEAX=0;
- usingEAX3=0;
-
- _fEffectsLevel = 0.0f;
-
- _maxSamples = 0;
-
- opened_provider = NULL;
- DIG = NULL;
-
- for ( int32 i = 0; i < MAXCHANNELS; i++ )
- opened_samples[i] = NULL;
- }
-
- // banks
- TRACE("banks");
- {
- fpSampleDescHandle = NULL;
- fpSampleDataHandle = NULL;
-
- _nSampleDataEndOffset = 0;
-
- for ( int32 i = 0; i < MAX_SAMPLEBANKS; i++ )
- {
- bSampleBankLoaded[i] = false;
- nSampleBankDiscStartOffset[i] = 0;
- nSampleBankSize[i] = 0;
- nSampleBankMemoryStartAddress[i] = 0;
- }
- }
-
- // pedsfx
- TRACE("pedsfx");
- {
- for ( int32 i = 0; i < MAX_PEDSFX; i++ )
- {
- nPedSlotSfx[i] = NO_SAMPLE;
- nPedSlotSfxAddr[i] = 0;
- }
-
- nCurrentPedSlot = 0;
- }
-
- // channel volume
- TRACE("vol");
- {
- for ( int32 i = 0; i < MAXCHANNELS+MAX2DCHANNELS; i++ )
- nChannelVolume[i] = 0;
- }
-
- TRACE("mss");
- {
- AIL_set_redist_directory( "mss" );
-
- AIL_startup();
-
- AIL_set_preference(DIG_MIXER_CHANNELS, MAX_DIGITAL_MIXER_CHANNELS);
-
- DIG = AIL_open_digital_driver(DIGITALRATE, DIGITALBITS, DIGITALCHANNELS, 0);
- if ( DIG == NULL )
- {
- OutputDebugString(AIL_last_error());
- Terminate();
- return false;
- }
-
- add_providers();
-
- if ( !InitialiseSampleBanks() )
- {
- Terminate();
- return false;
- }
-
- nSampleBankMemoryStartAddress[SAMPLEBANK_MAIN] = (int32)AIL_mem_alloc_lock(nSampleBankSize[SAMPLEBANK_MAIN]);
- if ( !nSampleBankMemoryStartAddress[SAMPLEBANK_MAIN] )
- {
- Terminate();
- return false;
- }
-
- nSampleBankMemoryStartAddress[SAMPLEBANK_PED] = (int32)AIL_mem_alloc_lock(PED_BLOCKSIZE*MAX_PEDSFX);
-
- }
-
- TRACE("cdrom");
-
- S32 tatalms;
- char filepath[MAX_PATH];
-
- {
- m_bInitialised = false;
-
- while (true)
- {
- int32 drive = 'C';
-
- do
- {
- char latter[2];
-
- latter[0] = drive;
- latter[1] = '\0';
-
- strcpy(m_szCDRomRootPath, latter);
- strcat(m_szCDRomRootPath, ":\\");
-
- if ( GetDriveType(m_szCDRomRootPath) == DRIVE_CDROM )
- {
- strcpy(filepath, m_szCDRomRootPath);
- strcat(filepath, StreamedNameTable[0]);
-
- FILE *f = fopen(filepath, "rb");
-
- if ( f )
- {
- fclose(f);
-
- bool bFileNotFound = false;
-
- for ( int32 i = 0; i < TOTAL_STREAMED_SOUNDS; i++ )
- {
- strcpy(filepath, m_szCDRomRootPath);
- strcat(filepath, StreamedNameTable[i]);
-
- mp3Stream[0] = AIL_open_stream(DIG, filepath, 0);
-
- if ( mp3Stream[0] )
- {
- AIL_stream_ms_position(mp3Stream[0], &tatalms, NULL);
-
- AIL_close_stream(mp3Stream[0]);
- mp3Stream[0] = NULL;
-
- nStreamLength[i] = tatalms;
- }
- else
- {
- bFileNotFound = true;
- break;
- }
- }
-
- if ( !bFileNotFound )
- {
- m_bInitialised = true;
- break;
- }
- else
- {
- m_bInitialised = false;
- continue;
- }
- }
- }
-
- } while ( ++drive <= 'Z' );
-
- if ( !m_bInitialised )
- {
-#if !defined(GTA3_STEAM_PATCH) && !defined(NO_CDCHECK)
- FrontEndMenuManager.WaitForUserCD();
- if ( FrontEndMenuManager.m_bQuitGameNoCD )
- {
- Terminate();
- return false;
- }
- continue;
-#else
- m_bInitialised = true;
-#endif
- }
-
- break;
- }
- }
-
-#if defined(GTA3_1_1_PATCH) || defined(GTA3_STEAM_PATCH) || defined(NO_CDCHECK)
- // hddaudio
- /**
- Option for user to play audio files directly from hard disk.
- Copy the contents of the PLAY discs Audio directory into your installed Grand Theft Auto III Audio directory.
- Grand Theft Auto III still requires the presence of the PLAY disc when started.
- This may give better performance on some machines (though worse on others).
- **/
- TRACE("hddaudio 1.1 patch");
- {
- int32 streamLength[TOTAL_STREAMED_SOUNDS];
-
- bool bFileNotFound = false;
- char rootpath[MAX_PATH];
-
- strcpy(_aHDDPath, m_szCDRomRootPath);
- rootpath[0] = '\0';
-
- FILE *f = fopen(StreamedNameTable[0], "rb");
-
- if ( f )
- {
- fclose(f);
-
- for ( int32 i = 0; i < TOTAL_STREAMED_SOUNDS; i++ )
- {
- strcpy(filepath, rootpath);
- strcat(filepath, StreamedNameTable[i]);
-
- mp3Stream[0] = AIL_open_stream(DIG, filepath, 0);
-
- if ( mp3Stream[0] )
- {
- AIL_stream_ms_position(mp3Stream[0], &tatalms, NULL);
-
- AIL_close_stream(mp3Stream[0]);
- mp3Stream[0] = NULL;
-
- streamLength[i] = tatalms;
- }
- else
- {
- bFileNotFound = true;
- break;
- }
- }
-
- }
- else
- bFileNotFound = true;
-
- if ( !bFileNotFound )
- {
- strcpy(m_szCDRomRootPath, rootpath);
-
- for ( int32 i = 0; i < TOTAL_STREAMED_SOUNDS; i++ )
- nStreamLength[i] = streamLength[i];
-
- _bUseHDDAudio = true;
- }
- else
- _bUseHDDAudio = false;
- }
-#endif
-
- TRACE("stream");
- {
- for ( int32 i = 0; i < MAX_MP3STREAMS; i++ )
- {
- mp3Stream [i] = NULL;
- nStreamPan [i] = 63;
- nStreamVolume[i] = 100;
- }
- }
-
- for ( int32 i = 0; i < MAX2DCHANNELS; i++ )
- {
- opened_2dsamples[i] = AIL_allocate_sample_handle(DIG);
- if ( opened_2dsamples[i] )
- {
- AIL_init_sample(opened_2dsamples[i]);
- AIL_set_sample_type(opened_2dsamples[i], DIG_F_MONO_16, DIG_PCM_SIGN);
- }
- }
-
- TRACE("providerset");
- {
- _bSampmanInitialised = true;
-
- U32 n = 0;
-
- while ( n < m_nNumberOfProviders )
- {
- if ( !strcmp(providers[n].name, "Miles Fast 2D Positional Audio") )
- {
- set_new_provider(n);
- break;
- }
- n++;
- }
-
- if ( n == m_nNumberOfProviders )
- {
- Terminate();
- return false;
- }
- }
-
- TRACE("bank");
-
- LoadSampleBank(SAMPLEBANK_MAIN);
-
- // mp3
- TRACE("mp3");
- {
- nNumMP3s = 0;
-
- _pMP3List = NULL;
-
- _FindMP3s();
-
- if ( nNumMP3s != 0 )
- {
- nStreamLength[STREAMED_SOUND_RADIO_MP3_PLAYER] = 0;
-
- for ( tMP3Entry *e = _pMP3List; e != NULL; e = e->pNext )
- {
- e->nTrackStreamPos = nStreamLength[STREAMED_SOUND_RADIO_MP3_PLAYER];
- nStreamLength[STREAMED_SOUND_RADIO_MP3_PLAYER] += e->nTrackLength;
- }
-
- time_t t = time(NULL);
- tm *localtm;
- bool bUseRandomTable;
-
- if ( t == -1 )
- bUseRandomTable = true;
- else
- {
- bUseRandomTable = false;
- localtm = localtime(&t);
- }
-
- int32 randval;
- if ( bUseRandomTable )
- randval = AudioManager.GetRandomNumber(1);
- else
- randval = localtm->tm_sec * localtm->tm_min;
-
- _CurMP3Index = randval % nNumMP3s;
-
- tMP3Entry *randmp3 = _pMP3List;
- for ( int32 i = randval % nNumMP3s; i > 0; --i)
- randmp3 = randmp3->pNext;
-
- if ( bUseRandomTable )
- _CurMP3Pos = AudioManager.GetRandomNumber(0) % randmp3->nTrackLength;
- else
- {
- if ( localtm->tm_sec > 0 )
- {
- int32 s = localtm->tm_sec;
- _CurMP3Pos = s*s*s*s*s*s*s*s % randmp3->nTrackLength;
- }
- else
- _CurMP3Pos = AudioManager.GetRandomNumber(0) % randmp3->nTrackLength;
- }
- }
- else
- _CurMP3Pos = 0;
-
- _bIsMp3Active = false;
- }
-
- TRACE("end");
-
- return true;
-}
-
-void
-cSampleManager::Terminate(void)
-{
- for ( int32 i = 0; i < MAX_MP3STREAMS; i++ )
- {
- if ( mp3Stream[i] )
- {
- AIL_pause_stream(mp3Stream[i], 1);
- AIL_close_stream(mp3Stream[i]);
- mp3Stream[i] = NULL;
- }
- }
-
- for ( int32 i = 0; i < MAX2DCHANNELS; i++ )
- {
- if ( opened_2dsamples[i] )
- {
- AIL_release_sample_handle(opened_2dsamples[i]);
- opened_2dsamples[i] = NULL;
- }
- }
-
- release_existing();
-
- _DeleteMP3Entries();
-
- if ( nSampleBankMemoryStartAddress[SAMPLEBANK_MAIN] != 0 )
- {
- AIL_mem_free_lock((void *)nSampleBankMemoryStartAddress[SAMPLEBANK_MAIN]);
- nSampleBankMemoryStartAddress[SAMPLEBANK_MAIN] = 0;
- }
-
- if ( nSampleBankMemoryStartAddress[SAMPLEBANK_PED] != 0 )
- {
- AIL_mem_free_lock((void *)nSampleBankMemoryStartAddress[SAMPLEBANK_PED]);
- nSampleBankMemoryStartAddress[SAMPLEBANK_PED] = 0;
- }
-
- if ( DIG )
- {
- AIL_close_digital_driver(DIG);
- DIG = NULL;
- }
-
- AIL_shutdown();
-
- _bSampmanInitialised = false;
-}
-
-bool
-cSampleManager::CheckForAnAudioFileOnCD(void)
-{
-#if !defined(GTA3_STEAM_PATCH) && !defined(NO_CDCHECK)
- char filepath[MAX_PATH];
-
-#if defined(GTA3_1_1_PATCH)
- if (_bUseHDDAudio)
- strcpy(filepath, _aHDDPath);
- else
- strcpy(filepath, m_szCDRomRootPath);
-#else
- strcpy(filepath, m_szCDRomRootPath);
-#endif // #if defined(GTA3_1_1_PATCH)
-
- strcat(filepath, StreamedNameTable[AudioManager.GetRandomNumber(1) % TOTAL_STREAMED_SOUNDS]);
-
- FILE *f = fopen(filepath, "rb");
-
- if ( f )
- {
- fclose(f);
-
- return true;
- }
-
- return false;
-
-#else
- return true;
-#endif // #if !defined(GTA3_STEAM_PATCH) && !defined(NO_CDCHECK)
-}
-
-char
-cSampleManager::GetCDAudioDriveLetter(void)
-{
-#if defined(GTA3_1_1_PATCH) || defined(GTA3_STEAM_PATCH) || defined(NO_CDCHECK)
- if (_bUseHDDAudio)
- {
- if ( strlen(_aHDDPath) != 0 )
- return _aHDDPath[0];
- else
- return '\0';
- }
- else
- {
- if ( strlen(m_szCDRomRootPath) != 0 )
- return m_szCDRomRootPath[0];
- else
- return '\0';
- }
-#else
- if ( strlen(m_szCDRomRootPath) != 0 )
- return m_szCDRomRootPath[0];
- else
- return '\0';
-#endif
-}
-
-void
-cSampleManager::UpdateEffectsVolume(void) //[Y], cSampleManager::UpdateSoundBuffers ?
-{
- if ( _bSampmanInitialised )
- {
- for ( int32 i = 0; i < MAXCHANNELS+MAX2DCHANNELS; i++ )
- {
- if ( i < MAXCHANNELS )
- {
- if ( opened_samples[i] && GetChannelUsedFlag(i) )
- {
- if ( nChannelVolume[i] )
- {
- AIL_set_3D_sample_volume(opened_samples[i],
- m_nEffectsFadeVolume * nChannelVolume[i] * m_nEffectsVolume >> 14);
- }
- }
- }
- else
- {
- if ( opened_2dsamples[i - MAXCHANNELS] )
- {
- if ( GetChannelUsedFlag(i - MAXCHANNELS) )
- {
- if ( nChannelVolume[i - MAXCHANNELS] )
- {
- AIL_set_sample_volume(opened_2dsamples[i - MAXCHANNELS],
- m_nEffectsFadeVolume * nChannelVolume[i - MAXCHANNELS] * m_nEffectsVolume >> 14);
- }
- }
- }
- }
- }
- }
-}
-
-void
-cSampleManager::SetEffectsMasterVolume(uint8 nVolume)
-{
- m_nEffectsVolume = nVolume;
- UpdateEffectsVolume();
-}
-
-void
-cSampleManager::SetMusicMasterVolume(uint8 nVolume)
-{
- m_nMusicVolume = nVolume;
-}
-
-void
-cSampleManager::SetEffectsFadeVolume(uint8 nVolume)
-{
- m_nEffectsFadeVolume = nVolume;
- UpdateEffectsVolume();
-}
-
-void
-cSampleManager::SetMusicFadeVolume(uint8 nVolume)
-{
- m_nMusicFadeVolume = nVolume;
-}
-
-bool
-cSampleManager::LoadSampleBank(uint8 nBank)
-{
- if ( CTimer::GetIsCodePaused() )
- return false;
-
- if ( MusicManager.IsInitialised()
- && MusicManager.GetMusicMode() == MUSICMODE_CUTSCENE
- && nBank != SAMPLEBANK_MAIN )
- {
- return false;
- }
-
- if ( fseek(fpSampleDataHandle, nSampleBankDiscStartOffset[nBank], SEEK_SET) != 0 )
- return false;
-
- if ( fread((void *)nSampleBankMemoryStartAddress[nBank], 1, nSampleBankSize[nBank],fpSampleDataHandle) != nSampleBankSize[nBank] )
- return false;
-
- bSampleBankLoaded[nBank] = true;
-
- return true;
-}
-
-void
-cSampleManager::UnloadSampleBank(uint8 nBank)
-{
- bSampleBankLoaded[nBank] = false;
-}
-
-bool
-cSampleManager::IsSampleBankLoaded(uint8 nBank)
-{
- return bSampleBankLoaded[nBank];
-}
-
-bool
-cSampleManager::IsPedCommentLoaded(uint32 nComment)
-{
- uint8 slot;
-
- for ( int32 i = 0; i < _TODOCONST(3); i++ )
- {
- slot = nCurrentPedSlot - i - 1;
- if ( nComment == nPedSlotSfx[slot] )
- return true;
- }
-
- return false;
-}
-
-int32
-cSampleManager::_GetPedCommentSlot(uint32 nComment)
-{
- uint8 slot;
-
- for ( int32 i = 0; i < _TODOCONST(3); i++ )
- {
- slot = nCurrentPedSlot - i - 1;
- if ( nComment == nPedSlotSfx[slot] )
- return slot;
- }
-
- return -1;
-}
-
-bool
-cSampleManager::LoadPedComment(uint32 nComment)
-{
- if ( CTimer::GetIsCodePaused() )
- return false;
-
- // no talking peds during cutsenes or the game end
- if ( MusicManager.IsInitialised() )
- {
- switch ( MusicManager.GetMusicMode() )
- {
- case MUSICMODE_CUTSCENE:
- {
- return false;
-
- break;
- }
-
- case MUSICMODE_FRONTEND:
- {
- if ( MusicManager.GetCurrentTrack() == STREAMED_SOUND_GAME_COMPLETED )
- return false;
-
- break;
- }
- }
- }
-
- if ( fseek(fpSampleDataHandle, m_aSamples[nComment].nOffset, SEEK_SET) != 0 )
- return false;
-
- if ( fread((void *)(nSampleBankMemoryStartAddress[SAMPLEBANK_PED] + PED_BLOCKSIZE*nCurrentPedSlot), 1, m_aSamples[nComment].nSize, fpSampleDataHandle) != m_aSamples[nComment].nSize )
- return false;
-
- nPedSlotSfxAddr[nCurrentPedSlot] = nSampleBankMemoryStartAddress[SAMPLEBANK_PED] + PED_BLOCKSIZE*nCurrentPedSlot;
- nPedSlotSfx [nCurrentPedSlot] = nComment;
-
- if ( ++nCurrentPedSlot >= MAX_PEDSFX )
- nCurrentPedSlot = 0;
-
- return true;
-}
-
-int32
-cSampleManager::GetSampleBaseFrequency(uint32 nSample)
-{
- return m_aSamples[nSample].nFrequency;
-}
-
-int32
-cSampleManager::GetSampleLoopStartOffset(uint32 nSample)
-{
- return m_aSamples[nSample].nLoopStart;
-}
-
-int32
-cSampleManager::GetSampleLoopEndOffset(uint32 nSample)
-{
- return m_aSamples[nSample].nLoopEnd;
-}
-
-uint32
-cSampleManager::GetSampleLength(uint32 nSample)
-{
- return m_aSamples[nSample].nSize >> 1;
-}
-
-bool
-cSampleManager::UpdateReverb(void)
-{
- if ( !usingEAX )
- return false;
-
- if ( AudioManager.GetFrameCounter() & 15 )
- return false;
-
- float y = AudioManager.GetReflectionsDistance(REFLECTION_TOP) + AudioManager.GetReflectionsDistance(REFLECTION_BOTTOM);
- float x = AudioManager.GetReflectionsDistance(REFLECTION_LEFT) + AudioManager.GetReflectionsDistance(REFLECTION_RIGHT);
- float z = AudioManager.GetReflectionsDistance(REFLECTION_UP);
-
- float normy = norm(y, 5.0f, 40.0f);
- float normx = norm(x, 5.0f, 40.0f);
- float normz = norm(z, 5.0f, 40.0f);
-
- float fRatio;
-
- if ( normy == 0.0f )
- {
- if ( normx == 0.0f )
- {
- if ( normz == 0.0f )
- fRatio = 0.3f;
- else
- fRatio = 0.5f;
- }
- else
- {
- fRatio = 0.3f;
- }
- }
- else
- {
- if ( normx == 0.0f )
- {
- if ( normz == 0.0f )
- fRatio = 0.3f;
- else
- fRatio = 0.5f;
- }
- else
- {
- if ( normz == 0.0f )
- fRatio = 0.3f;
- else
- fRatio = (normy+normx+normz) / 3.0f;
- }
- }
-
- fRatio = clamp(fRatio, usingEAX3==1 ? 0.0f : 0.30f, 1.0f);
-
- if ( fRatio == _fPrevEaxRatioDestination )
- return false;
-
- if ( usingEAX3 )
- {
- if ( EAX3ListenerInterpolate(&StartEAX3, &FinishEAX3, fRatio, &EAX3Params, false) )
- {
- AIL_set_3D_provider_preference(opened_provider, "EAX all parameters", &EAX3Params);
- _fEffectsLevel = 1.0f - fRatio * 0.5f;
- }
- }
- else
- {
- if ( _usingMilesFast2D )
- _fEffectsLevel = (1.0f - fRatio) * 0.4f;
- else
- _fEffectsLevel = (1.0f - fRatio) * 0.7f;
- }
-
- _fPrevEaxRatioDestination = fRatio;
-
- return true;
-}
-
-void
-cSampleManager::SetChannelReverbFlag(uint32 nChannel, uint8 nReverbFlag)
-{
- bool b2d = false;
-
- switch ( nChannel )
- {
- case CHANNEL2D:
- {
- b2d = true;
- break;
- }
- }
-
- if ( usingEAX )
- {
- if ( nReverbFlag != 0 )
- {
- if ( !b2d )
- AIL_set_3D_sample_effects_level(opened_samples[nChannel], _fEffectsLevel);
- }
- else
- {
- if ( !b2d )
- AIL_set_3D_sample_effects_level(opened_samples[nChannel], 0.0f);
- }
- }
-}
-
-bool
-cSampleManager::InitialiseChannel(uint32 nChannel, uint32 nSfx, uint8 nBank)
-{
- bool b2d = false;
-
- switch ( nChannel )
- {
- case CHANNEL2D:
- {
- b2d = true;
- break;
- }
- }
-
- int32 addr;
-
- if ( nSfx < SAMPLEBANK_MAX )
- {
- if ( !IsSampleBankLoaded(nBank) )
- return false;
-
- addr = nSampleBankMemoryStartAddress[nBank] + m_aSamples[nSfx].nOffset - m_aSamples[BankStartOffset[nBank]].nOffset;
- }
- else
- {
- if ( !IsPedCommentLoaded(nSfx) )
- return false;
-
- int32 slot = _GetPedCommentSlot(nSfx);
-
- addr = nPedSlotSfxAddr[slot];
- }
-
- if ( b2d )
- {
- if ( opened_2dsamples[nChannel - MAXCHANNELS] )
- {
- AIL_set_sample_address(opened_2dsamples[nChannel - MAXCHANNELS], (void *)addr, m_aSamples[nSfx].nSize);
- return true;
- }
- else
- return false;
- }
- else
- {
- AILSOUNDINFO info;
-
- info.format = WAVE_FORMAT_PCM;
- info.data_ptr = (void *)addr;
- info.channels = 1;
- info.data_len = m_aSamples[nSfx].nSize;
- info.rate = m_aSamples[nSfx].nFrequency;
- info.bits = 16;
-
- if ( AIL_set_3D_sample_info(opened_samples[nChannel], &info) == 0 )
- {
- OutputDebugString(AIL_last_error());
- return false;
- }
-
- return true;
- }
-}
-
-void
-cSampleManager::SetChannelEmittingVolume(uint32 nChannel, uint32 nVolume)
-{
- uint32 vol = nVolume;
- if ( vol > MAX_VOLUME ) vol = MAX_VOLUME;
-
- nChannelVolume[nChannel] = vol;
-
- // increase the volume for JB.MP3 and S4_BDBD.MP3
- if ( MusicManager.GetMusicMode() == MUSICMODE_CUTSCENE
- && MusicManager.GetCurrentTrack() != STREAMED_SOUND_NEWS_INTRO
- && MusicManager.GetCurrentTrack() != STREAMED_SOUND_CUTSCENE_SAL4_BDBD )
- {
- nChannelVolume[nChannel] >>= 2;
- }
-
- if ( opened_samples[nChannel] )
- AIL_set_3D_sample_volume(opened_samples[nChannel], m_nEffectsFadeVolume*nChannelVolume[nChannel]*m_nEffectsVolume >> 14);
-
-}
-
-void
-cSampleManager::SetChannel3DPosition(uint32 nChannel, float fX, float fY, float fZ)
-{
- if ( opened_samples[nChannel] )
- AIL_set_3D_position(opened_samples[nChannel], -fX, fY, fZ);
-}
-
-void
-cSampleManager::SetChannel3DDistances(uint32 nChannel, float fMax, float fMin)
-{
- if ( opened_samples[nChannel] )
- AIL_set_3D_sample_distances(opened_samples[nChannel], fMax, fMin);
-}
-
-void
-cSampleManager::SetChannelVolume(uint32 nChannel, uint32 nVolume)
-{
- uint32 vol = nVolume;
- if ( vol > MAX_VOLUME ) vol = MAX_VOLUME;
-
- switch ( nChannel )
- {
- case CHANNEL2D:
- {
- nChannelVolume[nChannel] = vol;
-
- // increase the volume for JB.MP3 and S4_BDBD.MP3
- if ( MusicManager.GetMusicMode() == MUSICMODE_CUTSCENE
- && MusicManager.GetCurrentTrack() != STREAMED_SOUND_NEWS_INTRO
- && MusicManager.GetCurrentTrack() != STREAMED_SOUND_CUTSCENE_SAL4_BDBD )
- {
- nChannelVolume[nChannel] >>= 2;
- }
-
- if ( opened_2dsamples[nChannel - MAXCHANNELS] )
- {
- AIL_set_sample_volume(opened_2dsamples[nChannel - MAXCHANNELS],
- m_nEffectsFadeVolume*vol*m_nEffectsVolume >> 14);
- }
-
- break;
- }
- }
-}
-
-void
-cSampleManager::SetChannelPan(uint32 nChannel, uint32 nPan)
-{
- switch ( nChannel )
- {
- case CHANNEL2D:
- {
-#ifndef FIX_BUGS
- if ( opened_samples[nChannel - MAXCHANNELS] ) // BUG
-#else
- if ( opened_2dsamples[nChannel - MAXCHANNELS] )
-#endif
- AIL_set_sample_pan(opened_2dsamples[nChannel - MAXCHANNELS], nPan);
-
- break;
- }
- }
-}
-
-void
-cSampleManager::SetChannelFrequency(uint32 nChannel, uint32 nFreq)
-{
- bool b2d = false;
-
- switch ( nChannel )
- {
- case CHANNEL2D:
- {
- b2d = true;
- break;
- }
- }
-
- if ( b2d )
- {
- if ( opened_2dsamples[nChannel - MAXCHANNELS] )
- AIL_set_sample_playback_rate(opened_2dsamples[nChannel - MAXCHANNELS], nFreq);
- }
- else
- {
- if ( opened_samples[nChannel] )
- AIL_set_3D_sample_playback_rate(opened_samples[nChannel], nFreq);
- }
-}
-
-void
-cSampleManager::SetChannelLoopPoints(uint32 nChannel, uint32 nLoopStart, int32 nLoopEnd)
-{
- bool b2d = false;
-
- switch ( nChannel )
- {
- case CHANNEL2D:
- {
- b2d = true;
- break;
- }
- }
-
- if ( b2d )
- {
- if ( opened_2dsamples[nChannel - MAXCHANNELS] )
- AIL_set_sample_loop_block(opened_2dsamples[nChannel - MAXCHANNELS], nLoopStart, nLoopEnd);
- }
- else
- {
- if ( opened_samples[nChannel] )
- AIL_set_3D_sample_loop_block(opened_samples[nChannel], nLoopStart, nLoopEnd);
- }
-}
-
-void
-cSampleManager::SetChannelLoopCount(uint32 nChannel, uint32 nLoopCount)
-{
- bool b2d = false;
-
- switch ( nChannel )
- {
- case CHANNEL2D:
- {
- b2d = true;
- break;
- }
- }
-
- if ( b2d )
- {
- if ( opened_2dsamples[nChannel - MAXCHANNELS] )
- AIL_set_sample_loop_count(opened_2dsamples[nChannel - MAXCHANNELS], nLoopCount);
- }
- else
- {
- if ( opened_samples[nChannel] )
- AIL_set_3D_sample_loop_count(opened_samples[nChannel], nLoopCount);
- }
-}
-
-bool
-cSampleManager::GetChannelUsedFlag(uint32 nChannel)
-{
- bool b2d = false;
-
- switch ( nChannel )
- {
- case CHANNEL2D:
- {
- b2d = true;
- break;
- }
- }
-
- if ( b2d )
- {
- if ( opened_2dsamples[nChannel - MAXCHANNELS] )
- return AIL_sample_status(opened_2dsamples[nChannel - MAXCHANNELS]) == SMP_PLAYING;
- else
- return false;
- }
- else
- {
- if ( opened_samples[nChannel] )
- return AIL_3D_sample_status(opened_samples[nChannel]) == SMP_PLAYING;
- else
- return false;
- }
-
-}
-
-void
-cSampleManager::StartChannel(uint32 nChannel)
-{
- bool b2d = false;
-
- switch ( nChannel )
- {
- case CHANNEL2D:
- {
- b2d = true;
- break;
- }
- }
-
- if ( b2d )
- {
- if ( opened_2dsamples[nChannel - MAXCHANNELS] )
- AIL_start_sample(opened_2dsamples[nChannel - MAXCHANNELS]);
- }
- else
- {
- if ( opened_samples[nChannel] )
- AIL_start_3D_sample(opened_samples[nChannel]);
- }
-}
-
-void
-cSampleManager::StopChannel(uint32 nChannel)
-{
- bool b2d = false;
-
- switch ( nChannel )
- {
- case CHANNEL2D:
- {
- b2d = true;
- break;
- }
- }
-
- if ( b2d )
- {
- if ( opened_2dsamples[nChannel - MAXCHANNELS] )
- AIL_end_sample(opened_2dsamples[nChannel - MAXCHANNELS]);
- }
- else
- {
- if ( opened_samples[nChannel] )
- {
- if ( AIL_3D_sample_status(opened_samples[nChannel]) == SMP_PLAYING )
- AIL_end_3D_sample(opened_samples[nChannel]);
- }
- }
-}
-
-void
-cSampleManager::PreloadStreamedFile(uint8 nFile, uint8 nStream)
-{
- if ( m_bInitialised )
- {
- if ( nFile < TOTAL_STREAMED_SOUNDS )
- {
- if ( mp3Stream[nStream] )
- {
- AIL_pause_stream(mp3Stream[nStream], 1);
- AIL_close_stream(mp3Stream[nStream]);
- }
-
- char filepath[MAX_PATH];
-
- strcpy(filepath, m_szCDRomRootPath);
- strcat(filepath, StreamedNameTable[nFile]);
-
- mp3Stream[nStream] = AIL_open_stream(DIG, filepath, 0);
-
- if ( mp3Stream[nStream] )
- {
- AIL_set_stream_loop_count(mp3Stream[nStream], 1);
- AIL_service_stream(mp3Stream[nStream], 1);
- }
- else
- OutputDebugString(AIL_last_error());
- }
- }
-}
-
-void
-cSampleManager::PauseStream(uint8 nPauseFlag, uint8 nStream)
-{
- if ( m_bInitialised )
- {
- if ( mp3Stream[nStream] )
- AIL_pause_stream(mp3Stream[nStream], nPauseFlag != 0);
- }
-}
-
-void
-cSampleManager::StartPreloadedStreamedFile(uint8 nStream)
-{
- if ( m_bInitialised )
- {
- if ( mp3Stream[nStream] )
- AIL_start_stream(mp3Stream[nStream]);
- }
-}
-
-bool
-cSampleManager::StartStreamedFile(uint8 nFile, uint32 nPos, uint8 nStream)
-{
- uint32 position = nPos;
- char filename[MAX_PATH];
-
- if ( m_bInitialised && nFile < TOTAL_STREAMED_SOUNDS )
- {
- if ( mp3Stream[nStream] )
- {
- AIL_pause_stream(mp3Stream[nStream], 1);
- AIL_close_stream(mp3Stream[nStream]);
- }
-
- if ( nFile == STREAMED_SOUND_RADIO_MP3_PLAYER )
- {
- uint32 i = 0;
-
- if ( !_bIsMp3Active ) goto FIND_MP3TRACK;
-
- do
- {
- if ( ++_CurMP3Index >= nNumMP3s )
- _CurMP3Index = 0;
-
- _CurMP3Pos = 0;
-
- tMP3Entry *mp3 = _GetMP3EntryByIndex(_CurMP3Index);
-
- if ( mp3 )
- {
- mp3 = _pMP3List;
- if ( mp3 == NULL )
- {
- _bIsMp3Active = false;
- nFile = 0;
- goto PLAY_STREAMEDTRACK;
- }
- }
-
- if ( mp3->pLinkPath != NULL )
- mp3Stream[nStream] = AIL_open_stream(DIG, mp3->pLinkPath, 0);
- else
- {
- strcpy(filename, _mp3DirectoryPath);
- strcat(filename, mp3->aFilename);
-
- mp3Stream[nStream] = AIL_open_stream(DIG, filename, 0);
- }
-
- if ( mp3Stream[nStream] )
- {
- AIL_set_stream_loop_count(mp3Stream[nStream], 1);
- AIL_set_stream_ms_position(mp3Stream[nStream], 0);
- AIL_pause_stream(mp3Stream[nStream], 0);
- return true;
- }
-
- goto NEXT_MP3TRACK;
-
-FIND_MP3TRACK:
- if ( nPos > nStreamLength[STREAMED_SOUND_RADIO_MP3_PLAYER] )
- position = 0;
-
- tMP3Entry *e;
- if ( !_GetMP3PosFromStreamPos(&position, &e) )
- {
- if ( e == NULL )
- {
- nFile = 0;
- goto PLAY_STREAMEDTRACK;
- }
- }
-
- if ( e->pLinkPath != NULL )
- mp3Stream[nStream] = AIL_open_stream(DIG, e->pLinkPath, 0);
- else
- {
- strcpy(filename, _mp3DirectoryPath);
- strcat(filename, e->aFilename);
-
- mp3Stream[nStream] = AIL_open_stream(DIG, filename, 0);
- }
-
- if ( mp3Stream[nStream] )
- {
- AIL_set_stream_loop_count(mp3Stream[nStream], 1);
- AIL_set_stream_ms_position(mp3Stream[nStream], position);
- AIL_pause_stream(mp3Stream[nStream], 0);
-
- _bIsMp3Active = true;
-
- return true;
- }
-
-NEXT_MP3TRACK:
- _bIsMp3Active = false;
-
- } while ( ++i < nNumMP3s );
-
- position = 0;
- nFile = 0;
- goto PLAY_STREAMEDTRACK;
- }
-
-PLAY_STREAMEDTRACK:
- strcpy(filename, m_szCDRomRootPath);
- strcat(filename, StreamedNameTable[nFile]);
-
- mp3Stream[nStream] = AIL_open_stream(DIG, filename, 0);
- if ( mp3Stream[nStream] )
- {
- AIL_set_stream_loop_count(mp3Stream[nStream], 1);
- AIL_set_stream_ms_position(mp3Stream[nStream], position);
- AIL_pause_stream(mp3Stream[nStream], 0);
- return true;
- }
- }
-
- return false;
-}
-
-void
-cSampleManager::StopStreamedFile(uint8 nStream)
-{
- if ( m_bInitialised )
- {
- if ( mp3Stream[nStream] )
- {
- AIL_pause_stream(mp3Stream[nStream], 1);
-
- AIL_close_stream(mp3Stream[nStream]);
- mp3Stream[nStream] = NULL;
-
- if ( nStream == 0 )
- _bIsMp3Active = false;
- }
- }
-}
-
-int32
-cSampleManager::GetStreamedFilePosition(uint8 nStream)
-{
- S32 currentms;
-
- if ( m_bInitialised )
- {
- if ( mp3Stream[nStream] )
- {
- if ( _bIsMp3Active )
- {
- tMP3Entry *mp3 = _GetMP3EntryByIndex(_CurMP3Index);
-
- if ( mp3 != NULL )
- {
- AIL_stream_ms_position(mp3Stream[nStream], NULL, &currentms);
- return currentms + mp3->nTrackStreamPos;
- }
- else
- return 0;
- }
- else
- {
- AIL_stream_ms_position(mp3Stream[nStream], NULL, &currentms);
- return currentms;
- }
- }
- }
-
- return 0;
-}
-
-void
-cSampleManager::SetStreamedVolumeAndPan(uint8 nVolume, uint8 nPan, uint8 nEffectFlag, uint8 nStream)
-{
- uint8 vol = nVolume;
-
- if ( m_bInitialised )
- {
- if ( vol > MAX_VOLUME ) vol = MAX_VOLUME;
- if ( vol > MAX_VOLUME ) vol = MAX_VOLUME;
-
- nStreamVolume[nStream] = vol;
- nStreamPan[nStream] = nPan;
-
- if ( mp3Stream[nStream] )
- {
- if ( nEffectFlag )
- AIL_set_stream_volume(mp3Stream[nStream], m_nEffectsFadeVolume*vol*m_nEffectsVolume >> 14);
- else
- AIL_set_stream_volume(mp3Stream[nStream], m_nMusicFadeVolume*vol*m_nMusicVolume >> 14);
-
- AIL_set_stream_pan(mp3Stream[nStream], nPan);
- }
- }
-}
-
-int32
-cSampleManager::GetStreamedFileLength(uint8 nStream)
-{
- if ( m_bInitialised )
- return nStreamLength[nStream];
-
- return 0;
-}
-
-bool
-cSampleManager::IsStreamPlaying(uint8 nStream)
-{
- if ( m_bInitialised )
- {
- if ( mp3Stream[nStream] )
- {
- if ( AIL_stream_status(mp3Stream[nStream]) == SMP_PLAYING )
- return true;
- else
- return false;
- }
- }
-
- return false;
-}
-
-bool
-cSampleManager::InitialiseSampleBanks(void)
-{
- int32 nBank = SAMPLEBANK_MAIN;
-
- fpSampleDescHandle = fopen(SampleBankDescFilename, "rb");
- if ( fpSampleDescHandle == NULL )
- return false;
-
- fpSampleDataHandle = fopen(SampleBankDataFilename, "rb");
- if ( fpSampleDataHandle == NULL )
- {
- fclose(fpSampleDescHandle);
- fpSampleDescHandle = NULL;
-
- return false;
- }
-
- fseek(fpSampleDataHandle, 0, SEEK_END);
- _nSampleDataEndOffset = ftell(fpSampleDataHandle);
- rewind(fpSampleDataHandle);
-
- fread(m_aSamples, sizeof(tSample), TOTAL_AUDIO_SAMPLES, fpSampleDescHandle);
-
- fclose(fpSampleDescHandle);
- fpSampleDescHandle = NULL;
-
- for ( int32 i = 0; i < TOTAL_AUDIO_SAMPLES; i++ )
- {
- if ( BankStartOffset[nBank] == BankStartOffset[0] + i )
- {
- nSampleBankDiscStartOffset[nBank] = m_aSamples[i].nOffset;
- nBank++;
- }
- }
-
- nSampleBankSize[SAMPLEBANK_MAIN] = nSampleBankDiscStartOffset[SAMPLEBANK_PED] - nSampleBankDiscStartOffset[SAMPLEBANK_MAIN];
- nSampleBankSize[SAMPLEBANK_PED] = _nSampleDataEndOffset - nSampleBankDiscStartOffset[SAMPLEBANK_PED];
-
- return true;
-}
-
-STARTPATCHES
- //InjectHook(0x565500, cSampleManager::cSampleManager, PATCH_JUMP);
- //InjectHook(0x565510, cSampleManager::~cSampleManager, PATCH_JUMP);
- InjectHook(0x565520, comp, PATCH_JUMP);
- InjectHook(0x565540, add_providers, PATCH_JUMP);
- InjectHook(0x565680, release_existing, PATCH_JUMP);
- InjectHook(0x5656F0, set_new_provider, PATCH_JUMP);
- InjectHook(0x565900, &cSampleManager::SetSpeakerConfig, PATCH_JUMP);
- InjectHook(0x565970, &cSampleManager::GetMaximumSupportedChannels, PATCH_JUMP);
- InjectHook(0x565990, &cSampleManager::GetCurrent3DProviderIndex, PATCH_JUMP);
- InjectHook(0x5659A0, &cSampleManager::SetCurrent3DProvider, PATCH_JUMP);
- InjectHook(0x565A10, _ResolveLink, PATCH_JUMP);
- InjectHook(0x565B40, _FindMP3s, PATCH_JUMP);
- InjectHook(0x566380, _DeleteMP3Entries, PATCH_JUMP);
- InjectHook(0x566400, _GetMP3EntryByIndex, PATCH_JUMP);
- InjectHook(0x566490, &cSampleManager::IsMP3RadioChannelAvailable, PATCH_JUMP);
- InjectHook(0x5664B0, &cSampleManager::ReleaseDigitalHandle, PATCH_JUMP);
- InjectHook(0x5664F0, &cSampleManager::ReacquireDigitalHandle, PATCH_JUMP);
- InjectHook(0x566530, &cSampleManager::Initialise, PATCH_JUMP);
- InjectHook(0x566DC0, &cSampleManager::Terminate, PATCH_JUMP);
- InjectHook(0x566EA0, &cSampleManager::CheckForAnAudioFileOnCD, PATCH_JUMP);
- InjectHook(0x566F20, &cSampleManager::GetCDAudioDriveLetter, PATCH_JUMP);
- InjectHook(0x566F50, &cSampleManager::UpdateEffectsVolume, PATCH_JUMP);
- InjectHook(0x567010, &cSampleManager::SetEffectsMasterVolume, PATCH_JUMP);
- InjectHook(0x567020, &cSampleManager::SetMusicMasterVolume, PATCH_JUMP);
- InjectHook(0x567030, &cSampleManager::SetEffectsFadeVolume, PATCH_JUMP);
- InjectHook(0x567040, &cSampleManager::SetMusicFadeVolume, PATCH_JUMP);
- InjectHook(0x567050, &cSampleManager::LoadSampleBank, PATCH_JUMP);
- InjectHook(0x567110, &cSampleManager::UnloadSampleBank, PATCH_JUMP);
- InjectHook(0x567130, &cSampleManager::IsSampleBankLoaded, PATCH_JUMP);
- InjectHook(0x567150, &cSampleManager::IsPedCommentLoaded, PATCH_JUMP);
- InjectHook(0x5671A0, &cSampleManager::LoadPedComment, PATCH_JUMP);
- InjectHook(0x5672A0, &cSampleManager::GetSampleBaseFrequency, PATCH_JUMP);
- InjectHook(0x5672C0, &cSampleManager::GetSampleLoopStartOffset, PATCH_JUMP);
- InjectHook(0x5672E0, &cSampleManager::GetSampleLoopEndOffset, PATCH_JUMP);
- InjectHook(0x567300, &cSampleManager::GetSampleLength, PATCH_JUMP);
- InjectHook(0x567320, &cSampleManager::UpdateReverb, PATCH_JUMP);
- InjectHook(0x567630, &cSampleManager::SetChannelReverbFlag, PATCH_JUMP);
- InjectHook(0x5676A0, &cSampleManager::InitialiseChannel, PATCH_JUMP);
- InjectHook(0x567820, &cSampleManager::SetChannelEmittingVolume, PATCH_JUMP);
- InjectHook(0x567890, &cSampleManager::SetChannel3DPosition, PATCH_JUMP);
- InjectHook(0x5678D0, &cSampleManager::SetChannel3DDistances, PATCH_JUMP);
- InjectHook(0x567900, &cSampleManager::SetChannelVolume, PATCH_JUMP);
- InjectHook(0x567980, &cSampleManager::SetChannelPan, PATCH_JUMP);
- InjectHook(0x5679D0, &cSampleManager::SetChannelFrequency, PATCH_JUMP);
- InjectHook(0x567A30, &cSampleManager::SetChannelLoopPoints, PATCH_JUMP);
- InjectHook(0x567AA0, &cSampleManager::SetChannelLoopCount, PATCH_JUMP);
- InjectHook(0x567B00, &cSampleManager::GetChannelUsedFlag, PATCH_JUMP);
- InjectHook(0x567B80, &cSampleManager::StartChannel, PATCH_JUMP);
- InjectHook(0x567BE0, &cSampleManager::StopChannel, PATCH_JUMP);
- InjectHook(0x567C50, &cSampleManager::PreloadStreamedFile, PATCH_JUMP);
- InjectHook(0x567D30, &cSampleManager::PauseStream, PATCH_JUMP);
- InjectHook(0x567D60, &cSampleManager::StartPreloadedStreamedFile, PATCH_JUMP);
- InjectHook(0x567D80, &cSampleManager::StartStreamedFile, PATCH_JUMP);
- InjectHook(0x5680E0, &cSampleManager::StopStreamedFile, PATCH_JUMP);
- InjectHook(0x568130, &cSampleManager::GetStreamedFilePosition, PATCH_JUMP);
- InjectHook(0x5681D0, &cSampleManager::SetStreamedVolumeAndPan, PATCH_JUMP);
- InjectHook(0x568270, &cSampleManager::GetStreamedFileLength, PATCH_JUMP);
- InjectHook(0x568290, &cSampleManager::IsStreamPlaying, PATCH_JUMP);
- InjectHook(0x5682D0, &cSampleManager::InitialiseSampleBanks, PATCH_JUMP);
- //InjectHook(0x5683F0, `global constructor keyed to'sampman.cpp, PATCH_JUMP);
-ENDPATCHES
+#include "openal\samp_oal.cpp"
+#endif \ No newline at end of file
diff --git a/src/audio/sampman.h b/src/audio/sampman.h
index 4b546911..f454d236 100644
--- a/src/audio/sampman.h
+++ b/src/audio/sampman.h
@@ -1,339 +1,7 @@
#pragma once
#include "common.h"
-#include "AudioSamples.h"
-
-#define MAX_VOLUME 127
-
-struct tSample {
- int32 nOffset;
- uint32 nSize;
- int32 nFrequency;
- int32 nLoopStart;
- int32 nLoopEnd;
-};
-
-enum
-{
- SAMPLEBANK_MAIN,
- SAMPLEBANK_PED,
- MAX_SAMPLEBANKS,
- SAMPLEBANK_INVALID
-};
-
-#define MAX_PEDSFX 7
-#define PED_BLOCKSIZE 79000
-
-#define MAXPROVIDERS 64
-
-#define MAXCHANNELS 28
-#define MAXCHANNELS_SURROUND 24
-#define MAX2DCHANNELS 1
-#define CHANNEL2D MAXCHANNELS
-
-#define MAX_MP3STREAMS 2
-
-#define DIGITALRATE 32000
-#define DIGITALBITS 16
-#define DIGITALCHANNELS 2
-
-#define MAX_DIGITAL_MIXER_CHANNELS 32
-
-class cSampleManager
-{
- uint8 m_nEffectsVolume;
- uint8 m_nMusicVolume;
- uint8 m_nEffectsFadeVolume;
- uint8 m_nMusicFadeVolume;
- uint8 m_nMonoMode;
- char _pad0[1];
- char m_szCDRomRootPath[80];
- bool m_bInitialised;
- uint8 m_nNumberOfProviders;
- char *m_aAudioProviders[MAXPROVIDERS];
- tSample m_aSamples[TOTAL_AUDIO_SAMPLES];
-
-public:
-
-
-
- cSampleManager(void) :
- m_nNumberOfProviders(0)
- { }
-
- ~cSampleManager(void)
- { }
-
- void SetSpeakerConfig(int32 nConfig);
- uint32 GetMaximumSupportedChannels(void);
-
- uint32 GetNum3DProvidersAvailable() { return m_nNumberOfProviders; }
- void SetNum3DProvidersAvailable(uint32 num) { m_nNumberOfProviders = num; }
-
- char *Get3DProviderName(uint8 id) { return m_aAudioProviders[id]; }
- void Set3DProviderName(uint8 id, char *name) { m_aAudioProviders[id] = name; }
-
- int8 GetCurrent3DProviderIndex(void);
- int8 SetCurrent3DProvider(uint8 which);
-
- bool IsMP3RadioChannelAvailable(void);
-
- void ReleaseDigitalHandle (void);
- void ReacquireDigitalHandle(void);
-
- bool Initialise(void);
- void Terminate (void);
-
- bool CheckForAnAudioFileOnCD(void);
- char GetCDAudioDriveLetter (void);
-
- void UpdateEffectsVolume(void);
-
- void SetEffectsMasterVolume(uint8 nVolume);
- void SetMusicMasterVolume (uint8 nVolume);
- void SetEffectsFadeVolume (uint8 nVolume);
- void SetMusicFadeVolume (uint8 nVolume);
-
- bool LoadSampleBank (uint8 nBank);
- void UnloadSampleBank (uint8 nBank);
- bool IsSampleBankLoaded(uint8 nBank);
-
- bool IsPedCommentLoaded(uint32 nComment);
- bool LoadPedComment (uint32 nComment);
-
- int32 _GetPedCommentSlot(uint32 nComment);
-
- int32 GetSampleBaseFrequency (uint32 nSample);
- int32 GetSampleLoopStartOffset(uint32 nSample);
- int32 GetSampleLoopEndOffset (uint32 nSample);
- uint32 GetSampleLength (uint32 nSample);
-
- bool UpdateReverb(void);
-
- void SetChannelReverbFlag (uint32 nChannel, uint8 nReverbFlag);
- bool InitialiseChannel (uint32 nChannel, uint32 nSfx, uint8 nBank);
- void SetChannelEmittingVolume(uint32 nChannel, uint32 nVolume);
- void SetChannel3DPosition (uint32 nChannel, float fX, float fY, float fZ);
- void SetChannel3DDistances (uint32 nChannel, float fMax, float fMin);
- void SetChannelVolume (uint32 nChannel, uint32 nVolume);
- void SetChannelPan (uint32 nChannel, uint32 nPan);
- void SetChannelFrequency (uint32 nChannel, uint32 nFreq);
- void SetChannelLoopPoints (uint32 nChannel, uint32 nLoopStart, int32 nLoopEnd);
- void SetChannelLoopCount (uint32 nChannel, uint32 nLoopCount);
- bool GetChannelUsedFlag (uint32 nChannel);
- void StartChannel (uint32 nChannel);
- void StopChannel (uint32 nChannel);
-
- void PreloadStreamedFile (uint8 nFile, uint8 nStream);
- void PauseStream (uint8 nPauseFlag, uint8 nStream);
- void StartPreloadedStreamedFile (uint8 nStream);
- bool StartStreamedFile (uint8 nFile, uint32 nPos, uint8 nStream);
- void StopStreamedFile (uint8 nStream);
- int32 GetStreamedFilePosition (uint8 nStream);
- void SetStreamedVolumeAndPan(uint8 nVolume, uint8 nPan, uint8 nEffectFlag, uint8 nStream);
- int32 GetStreamedFileLength (uint8 nStream);
- bool IsStreamPlaying (uint8 nStream);
- bool InitialiseSampleBanks(void);
-};
-
-extern cSampleManager &SampleManager;
-extern int32 (&BankStartOffset)[MAX_SAMPLEBANKS];
-
-static char StreamedNameTable[][25]=
-{
- "AUDIO\\HEAD.WAV",
- "AUDIO\\CLASS.WAV",
- "AUDIO\\KJAH.WAV",
- "AUDIO\\RISE.WAV",
- "AUDIO\\LIPS.WAV",
- "AUDIO\\GAME.WAV",
- "AUDIO\\MSX.WAV",
- "AUDIO\\FLASH.WAV",
- "AUDIO\\CHAT.WAV",
- "AUDIO\\HEAD.WAV",
- "AUDIO\\POLICE.WAV",
- "AUDIO\\CITY.WAV",
- "AUDIO\\WATER.WAV",
- "AUDIO\\COMOPEN.WAV",
- "AUDIO\\SUBOPEN.WAV",
- "AUDIO\\JB.MP3",
- "AUDIO\\BET.MP3",
- "AUDIO\\L1_LG.MP3",
- "AUDIO\\L2_DSB.MP3",
- "AUDIO\\L3_DM.MP3",
- "AUDIO\\L4_PAP.MP3",
- "AUDIO\\L5_TFB.MP3",
- "AUDIO\\J0_DM2.MP3",
- "AUDIO\\J1_LFL.MP3",
- "AUDIO\\J2_KCL.MP3",
- "AUDIO\\J3_VH.MP3",
- "AUDIO\\J4_ETH.MP3",
- "AUDIO\\J5_DST.MP3",
- "AUDIO\\J6_TBJ.MP3",
- "AUDIO\\T1_TOL.MP3",
- "AUDIO\\T2_TPU.MP3",
- "AUDIO\\T3_MAS.MP3",
- "AUDIO\\T4_TAT.MP3",
- "AUDIO\\T5_BF.MP3",
- "AUDIO\\S0_MAS.MP3",
- "AUDIO\\S1_PF.MP3",
- "AUDIO\\S2_CTG.MP3",
- "AUDIO\\S3_RTC.MP3",
- "AUDIO\\S5_LRQ.MP3",
- "AUDIO\\S4_BDBA.MP3",
- "AUDIO\\S4_BDBB.MP3",
- "AUDIO\\S2_CTG2.MP3",
- "AUDIO\\S4_BDBD.MP3",
- "AUDIO\\S5_LRQB.MP3",
- "AUDIO\\S5_LRQC.MP3",
- "AUDIO\\A1_SSO.WAV",
- "AUDIO\\A2_PP.WAV",
- "AUDIO\\A3_SS.WAV",
- "AUDIO\\A4_PDR.WAV",
- "AUDIO\\A5_K2FT.WAV",
- "AUDIO\\K1_KBO.MP3",
- "AUDIO\\K2_GIS.MP3",
- "AUDIO\\K3_DS.MP3",
- "AUDIO\\K4_SHI.MP3",
- "AUDIO\\K5_SD.MP3",
- "AUDIO\\R0_PDR2.MP3",
- "AUDIO\\R1_SW.MP3",
- "AUDIO\\R2_AP.MP3",
- "AUDIO\\R3_ED.MP3",
- "AUDIO\\R4_GF.MP3",
- "AUDIO\\R5_PB.MP3",
- "AUDIO\\R6_MM.MP3",
- "AUDIO\\D1_STOG.MP3",
- "AUDIO\\D2_KK.MP3",
- "AUDIO\\D3_ADO.MP3",
- "AUDIO\\D5_ES.MP3",
- "AUDIO\\D7_MLD.MP3",
- "AUDIO\\D4_GTA.MP3",
- "AUDIO\\D4_GTA2.MP3",
- "AUDIO\\D6_STS.MP3",
- "AUDIO\\A6_BAIT.WAV",
- "AUDIO\\A7_ETG.WAV",
- "AUDIO\\A8_PS.WAV",
- "AUDIO\\A9_ASD.WAV",
- "AUDIO\\K4_SHI2.MP3",
- "AUDIO\\C1_TEX.MP3",
- "AUDIO\\EL_PH1.MP3",
- "AUDIO\\EL_PH2.MP3",
- "AUDIO\\EL_PH3.MP3",
- "AUDIO\\EL_PH4.MP3",
- "AUDIO\\YD_PH1.MP3",
- "AUDIO\\YD_PH2.MP3",
- "AUDIO\\YD_PH3.MP3",
- "AUDIO\\YD_PH4.MP3",
- "AUDIO\\HD_PH1.MP3",
- "AUDIO\\HD_PH2.MP3",
- "AUDIO\\HD_PH3.MP3",
- "AUDIO\\HD_PH4.MP3",
- "AUDIO\\HD_PH5.MP3",
- "AUDIO\\MT_PH1.MP3",
- "AUDIO\\MT_PH2.MP3",
- "AUDIO\\MT_PH3.MP3",
- "AUDIO\\MT_PH4.MP3",
- "AUDIO\\MISCOM.WAV",
- "AUDIO\\END.MP3",
- "AUDIO\\lib_a1.WAV",
- "AUDIO\\lib_a2.WAV",
- "AUDIO\\lib_a.WAV",
- "AUDIO\\lib_b.WAV",
- "AUDIO\\lib_c.WAV",
- "AUDIO\\lib_d.WAV",
- "AUDIO\\l2_a.WAV",
- "AUDIO\\j4t_1.WAV",
- "AUDIO\\j4t_2.WAV",
- "AUDIO\\j4t_3.WAV",
- "AUDIO\\j4t_4.WAV",
- "AUDIO\\j4_a.WAV",
- "AUDIO\\j4_b.WAV",
- "AUDIO\\j4_c.WAV",
- "AUDIO\\j4_d.WAV",
- "AUDIO\\j4_e.WAV",
- "AUDIO\\j4_f.WAV",
- "AUDIO\\j6_1.WAV",
- "AUDIO\\j6_a.WAV",
- "AUDIO\\j6_b.WAV",
- "AUDIO\\j6_c.WAV",
- "AUDIO\\j6_d.WAV",
- "AUDIO\\t4_a.WAV",
- "AUDIO\\s1_a.WAV",
- "AUDIO\\s1_a1.WAV",
- "AUDIO\\s1_b.WAV",
- "AUDIO\\s1_c.WAV",
- "AUDIO\\s1_c1.WAV",
- "AUDIO\\s1_d.WAV",
- "AUDIO\\s1_e.WAV",
- "AUDIO\\s1_f.WAV",
- "AUDIO\\s1_g.WAV",
- "AUDIO\\s1_h.WAV",
- "AUDIO\\s1_i.WAV",
- "AUDIO\\s1_j.WAV",
- "AUDIO\\s1_k.WAV",
- "AUDIO\\s1_l.WAV",
- "AUDIO\\s3_a.WAV",
- "AUDIO\\s3_b.WAV",
- "AUDIO\\el3_a.WAV",
- "AUDIO\\mf1_a.WAV",
- "AUDIO\\mf2_a.WAV",
- "AUDIO\\mf3_a.WAV",
- "AUDIO\\mf3_b.WAV",
- "AUDIO\\mf3_b1.WAV",
- "AUDIO\\mf3_c.WAV",
- "AUDIO\\mf4_a.WAV",
- "AUDIO\\mf4_b.WAV",
- "AUDIO\\mf4_c.WAV",
- "AUDIO\\a1_a.WAV",
- "AUDIO\\a3_a.WAV",
- "AUDIO\\a5_a.WAV",
- "AUDIO\\a4_a.WAV",
- "AUDIO\\a4_b.WAV",
- "AUDIO\\a4_c.WAV",
- "AUDIO\\a4_d.WAV",
- "AUDIO\\k1_a.WAV",
- "AUDIO\\k3_a.WAV",
- "AUDIO\\r1_a.WAV",
- "AUDIO\\r2_a.WAV",
- "AUDIO\\r2_b.WAV",
- "AUDIO\\r2_c.WAV",
- "AUDIO\\r2_d.WAV",
- "AUDIO\\r2_e.WAV",
- "AUDIO\\r2_f.WAV",
- "AUDIO\\r2_g.WAV",
- "AUDIO\\r2_h.WAV",
- "AUDIO\\r5_a.WAV",
- "AUDIO\\r6_a.WAV",
- "AUDIO\\r6_a1.WAV",
- "AUDIO\\r6_b.WAV",
- "AUDIO\\lo2_a.WAV",
- "AUDIO\\lo6_a.WAV",
- "AUDIO\\yd2_a.WAV",
- "AUDIO\\yd2_b.WAV",
- "AUDIO\\yd2_c.WAV",
- "AUDIO\\yd2_c1.WAV",
- "AUDIO\\yd2_d.WAV",
- "AUDIO\\yd2_e.WAV",
- "AUDIO\\yd2_f.WAV",
- "AUDIO\\yd2_g.WAV",
- "AUDIO\\yd2_h.WAV",
- "AUDIO\\yd2_ass.WAV",
- "AUDIO\\yd2_ok.WAV",
- "AUDIO\\h5_a.WAV",
- "AUDIO\\h5_b.WAV",
- "AUDIO\\h5_c.WAV",
- "AUDIO\\ammu_a.WAV",
- "AUDIO\\ammu_b.WAV",
- "AUDIO\\ammu_c.WAV",
- "AUDIO\\door_1.WAV",
- "AUDIO\\door_2.WAV",
- "AUDIO\\door_3.WAV",
- "AUDIO\\door_4.WAV",
- "AUDIO\\door_5.WAV",
- "AUDIO\\door_6.WAV",
- "AUDIO\\t3_a.WAV",
- "AUDIO\\t3_b.WAV",
- "AUDIO\\t3_c.WAV",
- "AUDIO\\k1_b.WAV",
- "AUDIO\\cat1.WAV"
-};
+#ifndef OPENAL
+#include "miles\sampman_mss.h"
+#else
+#include "openal\samp_oal.h"
+#endif \ No newline at end of file