summaryrefslogtreecommitdiffstats
path: root/src/audio
diff options
context:
space:
mode:
Diffstat (limited to 'src/audio')
-rw-r--r--src/audio/AudioLogic.cpp329
-rw-r--r--src/audio/AudioManager.cpp17
-rw-r--r--src/audio/AudioManager.h21
-rw-r--r--src/audio/AudioSamples.h2
-rw-r--r--src/audio/MusicManager.cpp354
-rw-r--r--src/audio/MusicManager.h10
-rw-r--r--src/audio/PoliceRadio.cpp9
-rw-r--r--src/audio/PoliceRadio.h2
-rw-r--r--src/audio/audio_enums.h7
-rw-r--r--src/audio/oal/channel.cpp56
-rw-r--r--src/audio/oal/channel.h6
-rw-r--r--src/audio/oal/oal_utils.cpp11
-rw-r--r--src/audio/oal/oal_utils.h7
-rw-r--r--src/audio/oal/stream.cpp856
-rw-r--r--src/audio/oal/stream.h13
-rw-r--r--src/audio/sampman.h7
-rw-r--r--src/audio/sampman_miles.cpp29
-rw-r--r--src/audio/sampman_oal.cpp186
-rw-r--r--src/audio/soundlist.h6
19 files changed, 1406 insertions, 522 deletions
diff --git a/src/audio/AudioLogic.cpp b/src/audio/AudioLogic.cpp
index 7340e73e..ec364c27 100644
--- a/src/audio/AudioLogic.cpp
+++ b/src/audio/AudioLogic.cpp
@@ -1,4 +1,4 @@
-#include "common.h"
+#include "common.h"
#include "AudioManager.h"
#include "audio_enums.h"
@@ -38,7 +38,7 @@
#include "ZoneCull.h"
#include "sampman.h"
-const int channels = ARRAY_SIZE(cAudioManager::m_asActiveSamples);
+const int channels = ARRAY_SIZE(AudioManager.m_asActiveSamples);
const int policeChannel = channels + 1;
const int allChannels = channels + 2;
@@ -52,8 +52,8 @@ uint32 gHomeNextTime;
uint32 gCellNextTime;
uint32 gNextCryTime;
-enum PLAY_STATUS : uint8 { PLAY_STATUS_STOPPED = 0, PLAY_STATUS_PLAYING, PLAY_STATUS_FINISHED };
-enum LOADING_STATUS : uint8 { LOADING_STATUS_NOT_LOADED = 0, LOADING_STATUS_LOADED, LOADING_STATUS_FAILED };
+enum PLAY_STATUS { PLAY_STATUS_STOPPED = 0, PLAY_STATUS_PLAYING, PLAY_STATUS_FINISHED };
+enum LOADING_STATUS { LOADING_STATUS_NOT_LOADED = 0, LOADING_STATUS_LOADED, LOADING_STATUS_FAILED };
void
cAudioManager::PreInitialiseGameSpecificSetup() const
@@ -128,31 +128,31 @@ cAudioManager::PostInitialiseGameSpecificSetup()
{
m_nFireAudioEntity = CreateEntity(AUDIOTYPE_FIRE, &gFireManager);
if (m_nFireAudioEntity >= 0)
- SetEntityStatus(m_nFireAudioEntity, 1);
+ SetEntityStatus(m_nFireAudioEntity, true);
m_nCollisionEntity = CreateEntity(AUDIOTYPE_COLLISION, (void *)1);
if (m_nCollisionEntity >= 0)
- SetEntityStatus(m_nCollisionEntity, 1);
+ SetEntityStatus(m_nCollisionEntity, true);
m_nFrontEndEntity = CreateEntity(AUDIOTYPE_FRONTEND, (void *)1);
if (m_nFrontEndEntity >= 0)
- SetEntityStatus(m_nFrontEndEntity, 1);
+ SetEntityStatus(m_nFrontEndEntity, true);
m_nProjectileEntity = CreateEntity(AUDIOTYPE_PROJECTILE, (void *)1);
if (m_nProjectileEntity >= 0)
- SetEntityStatus(m_nProjectileEntity, 1);
+ SetEntityStatus(m_nProjectileEntity, true);
m_nWaterCannonEntity = CreateEntity(AUDIOTYPE_WATERCANNON, (void *)1);
if (m_nWaterCannonEntity >= 0)
- SetEntityStatus(m_nWaterCannonEntity, 1);
+ SetEntityStatus(m_nWaterCannonEntity, true);
m_nPoliceChannelEntity = CreateEntity(AUDIOTYPE_POLICERADIO, (void *)1);
if (m_nPoliceChannelEntity >= 0)
- SetEntityStatus(m_nPoliceChannelEntity, 1);
+ SetEntityStatus(m_nPoliceChannelEntity, true);
m_nBridgeEntity = CreateEntity(AUDIOTYPE_BRIDGE, (void *)1);
if (m_nBridgeEntity >= 0)
- SetEntityStatus(m_nBridgeEntity, 1);
+ SetEntityStatus(m_nBridgeEntity, true);
m_sMissionAudio.m_nSampleIndex = NO_SAMPLE;
m_sMissionAudio.m_nLoadingStatus = LOADING_STATUS_NOT_LOADED;
@@ -240,7 +240,7 @@ cAudioManager::ProcessReverb() const
;
i++) {
if (m_asActiveSamples[i].m_bReverbFlag)
- SampleManager.SetChannelReverbFlag(i, 1);
+ SampleManager.SetChannelReverbFlag(i, true);
}
}
}
@@ -277,8 +277,7 @@ cAudioManager::ProcessSpecial()
}
CPlayerPed *playerPed = FindPlayerPed();
if (playerPed) {
- const PedState &state = playerPed->m_nPedState;
- if (state != PED_ENTER_CAR && state != PED_STEAL_CAR && !playerPed->bInVehicle)
+ if(playerPed->EnteringCar() && !playerPed->bInVehicle)
SampleManager.StopChannel(m_nActiveSamples);
}
}
@@ -287,7 +286,7 @@ cAudioManager::ProcessSpecial()
void
cAudioManager::ProcessEntity(int32 id)
{
- if (m_asAudioEntities[id].m_nStatus) {
+ if (m_asAudioEntities[id].m_bStatus) {
m_sQueueSample.m_nEntityIndex = id;
switch (m_asAudioEntities[id].m_nType) {
case AUDIOTYPE_PHYSICAL:
@@ -580,14 +579,13 @@ cAudioManager::ProcessVehicle(CVehicle *veh)
m_sQueueSample.m_vecPos = veh->GetPosition();
params.m_bDistanceCalculated = false;
- params.m_fDistance = GetDistanceSquared(m_sQueueSample.m_vecPos);
params.m_pVehicle = veh;
- params.m_pTransmission = nil;
- params.m_nIndex = 0;
- params.m_fVelocityChange = 0.0f;
+ params.m_fDistance = GetDistanceSquared(m_sQueueSample.m_vecPos);
if (handling != nil)
params.m_pTransmission = &handling->Transmission;
+ else
+ params.m_pTransmission = nil;
params.m_nIndex = veh->GetModelIndex() - MI_FIRST_VEHICLE;
if (params.m_pVehicle->GetStatus() == STATUS_SIMPLE)
@@ -1904,7 +1902,6 @@ cAudioManager::ProcessVehicleOneShots(cVehicleParams& params)
float vol;
bool noReflections;
float maxDist;
- cPedParams pedParams;
static uint8 WaveIndex = 41;
static uint8 GunIndex = 53;
@@ -2243,21 +2240,21 @@ cAudioManager::ProcessVehicleOneShots(cVehicleParams& params)
break;
}
case SOUND_PED_HELI_PLAYER_FOUND:
- pedParams.m_pPed = nil;
- pedParams.m_bDistanceCalculated = false;
- pedParams.m_fDistance = 0.0f;
+ {
+ cPedParams pedParams;
pedParams.m_bDistanceCalculated = params.m_bDistanceCalculated;
pedParams.m_fDistance = params.m_fDistance;
SetupPedComments(pedParams, SOUND_PED_HELI_PLAYER_FOUND);
continue;
+ }
case SOUND_PED_BODYCAST_HIT:
- pedParams.m_pPed = nil;
- pedParams.m_bDistanceCalculated = false;
- pedParams.m_fDistance = 0.0f;
+ {
+ cPedParams pedParams;
pedParams.m_bDistanceCalculated = params.m_bDistanceCalculated;
pedParams.m_fDistance = params.m_fDistance;
SetupPedComments(pedParams, SOUND_PED_BODYCAST_HIT);
continue;
+ }
case SOUND_WATER_FALL: {
const float SOUND_INTENSITY = 40.0f;
m_sQueueSample.m_nSampleIndex = SFX_SPLASH_1;
@@ -2402,20 +2399,20 @@ cAudioManager::ProcessBoatEngine(cVehicleParams& params)
CBoat *boat;
float padRelativeAccerate;
float gasPedal;
- int32 padAccelerate;
+ float padAccelerate;
uint8 emittingVol;
float oneShotVol;
static uint16 LastAccel = 0;
static uint8 LastVol = 0;
- static const int intensity = 50;
+ static const float intensity = 50.0f;
if (params.m_fDistance < SQR(intensity)) {
boat = (CBoat *)params.m_pVehicle;
if (params.m_nIndex == REEFER) {
CalculateDistance(params.m_bDistanceCalculated, params.m_fDistance);
- m_sQueueSample.m_nVolume = ComputeVolume(80, 50.f, m_sQueueSample.m_fDistance);
+ m_sQueueSample.m_nVolume = ComputeVolume(80, intensity, m_sQueueSample.m_fDistance);
if (m_sQueueSample.m_nVolume != 0) {
m_sQueueSample.m_nCounter = 39;
m_sQueueSample.m_nSampleIndex = SFX_FISHING_BOAT_IDLE;
@@ -2438,10 +2435,10 @@ cAudioManager::ProcessBoatEngine(cVehicleParams& params)
}
if (FindPlayerVehicle() == params.m_pVehicle) {
padAccelerate = Max(Pads[0].GetAccelerate(), Pads[0].GetBrake());
- padRelativeAccerate = padAccelerate / 255;
+ padRelativeAccerate = padAccelerate / 255.0f;
emittingVol = (100.f * padRelativeAccerate) + 15;
m_sQueueSample.m_nFrequency = (3000.f * padRelativeAccerate) + 6000;
- if (!boat->m_bIsAnchored)
+ if (!boat->bPropellerInWater)
m_sQueueSample.m_nFrequency = 11 * m_sQueueSample.m_nFrequency / 10;
} else {
gasPedal = Abs(boat->m_fGasPedal);
@@ -2451,11 +2448,11 @@ cAudioManager::ProcessBoatEngine(cVehicleParams& params)
} else {
emittingVol = (100.f * gasPedal) + 15;
m_sQueueSample.m_nFrequency = (3000.f * gasPedal) + 6000;
- if (!boat->m_bIsAnchored)
+ if (!boat->bPropellerInWater)
m_sQueueSample.m_nFrequency = 11 * m_sQueueSample.m_nFrequency / 10;
}
}
- m_sQueueSample.m_nVolume = ComputeVolume(emittingVol, 50.f, m_sQueueSample.m_fDistance);
+ m_sQueueSample.m_nVolume = ComputeVolume(emittingVol, intensity, m_sQueueSample.m_fDistance);
if (!m_sQueueSample.m_nVolume)
return true;
m_sQueueSample.m_nCounter = 40;
@@ -2513,7 +2510,7 @@ cAudioManager::ProcessBoatEngine(cVehicleParams& params)
}
}
CalculateDistance(params.m_bDistanceCalculated, params.m_fDistance);
- m_sQueueSample.m_nVolume = ComputeVolume(emittingVol, 50.f, m_sQueueSample.m_fDistance);
+ m_sQueueSample.m_nVolume = ComputeVolume(emittingVol, intensity, m_sQueueSample.m_fDistance);
if (!m_sQueueSample.m_nVolume)
return true;
m_sQueueSample.m_nFrequency += (m_sQueueSample.m_nEntityIndex * 65536) % 1000;
@@ -2955,13 +2952,9 @@ cAudioManager::ProcessPed(CPhysical *ped)
{
cPedParams params;
- params.m_pPed = nil;
- params.m_bDistanceCalculated = false;
- params.m_fDistance = 0.0f;
-
m_sQueueSample.m_vecPos = ped->GetPosition();
- // params.m_bDistanceCalculated = false;
+ params.m_bDistanceCalculated = false;
params.m_pPed = (CPed *)ped;
params.m_fDistance = GetDistanceSquared(m_sQueueSample.m_vecPos);
if (ped->GetModelIndex() == MI_FATMALE02)
@@ -3045,109 +3038,109 @@ cAudioManager::ProcessPedOneShots(cPedParams &params)
switch (sound) {
case SOUND_STEP_START:
case SOUND_STEP_END:
- if (!params.m_pPed->bIsLooking) {
- emittingVol = m_anRandomTable[3] % 15 + 45;
- if (FindPlayerPed() != m_asAudioEntities[m_sQueueSample.m_nEntityIndex].m_pEntity)
- emittingVol /= 2;
- maxDist = 400.f;
- switch (params.m_pPed->m_nSurfaceTouched) {
- case SURFACE_GRASS:
- sampleIndex = m_anRandomTable[1] % 5 + SFX_FOOTSTEP_GRASS_1;
- break;
- case SURFACE_GRAVEL:
- case SURFACE_MUD_DRY:
- sampleIndex = m_anRandomTable[4] % 5 + SFX_FOOTSTEP_GRAVEL_1;
- break;
- case SURFACE_CAR:
- case SURFACE_GARAGE_DOOR:
- case SURFACE_CAR_PANEL:
- case SURFACE_THICK_METAL_PLATE:
- case SURFACE_SCAFFOLD_POLE:
- case SURFACE_LAMP_POST:
- case SURFACE_FIRE_HYDRANT:
- case SURFACE_GIRDER:
- case SURFACE_METAL_CHAIN_FENCE:
- case SURFACE_CONTAINER:
- case SURFACE_NEWS_VENDOR:
- sampleIndex = m_anRandomTable[0] % 5 + SFX_FOOTSTEP_METAL_1;
- break;
- case SURFACE_SAND:
- sampleIndex = (m_anRandomTable[4] & 3) + SFX_FOOTSTEP_SAND_1;
- break;
- case SURFACE_WATER:
- sampleIndex = (m_anRandomTable[3] & 3) + SFX_FOOTSTEP_WATER_1;
- break;
- case SURFACE_WOOD_CRATES:
- case SURFACE_WOOD_BENCH:
- case SURFACE_WOOD_SOLID:
- sampleIndex = m_anRandomTable[2] % 5 + SFX_FOOTSTEP_WOOD_1;
- break;
- case SURFACE_HEDGE:
- sampleIndex = m_anRandomTable[2] % 5 + SFX_COL_VEG_1;
- break;
- default:
- sampleIndex = m_anRandomTable[2] % 5 + SFX_FOOTSTEP_CONCRETE_1;
- break;
- }
- m_sQueueSample.m_nSampleIndex = sampleIndex;
- m_sQueueSample.m_nBankIndex = SFX_BANK_0;
- m_sQueueSample.m_nCounter = m_asAudioEntities[m_sQueueSample.m_nEntityIndex].m_awAudioEvent[i] - 28;
- m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(m_sQueueSample.m_nSampleIndex);
- m_sQueueSample.m_nFrequency += RandomDisplacement(m_sQueueSample.m_nFrequency / 17);
- switch (params.m_pPed->m_nMoveState) {
- case PEDMOVE_WALK:
- emittingVol /= 4;
- m_sQueueSample.m_nFrequency = 9 * m_sQueueSample.m_nFrequency / 10;
- break;
- case PEDMOVE_RUN:
- emittingVol /= 2;
- m_sQueueSample.m_nFrequency = 11 * m_sQueueSample.m_nFrequency / 10;
- break;
- case PEDMOVE_SPRINT:
- m_sQueueSample.m_nFrequency = 12 * m_sQueueSample.m_nFrequency / 10;
- break;
- default:
- break;
- }
- m_sQueueSample.m_nReleasingVolumeModificator = 5;
- m_sQueueSample.m_fSpeedMultiplier = 0.0f;
- m_sQueueSample.m_fSoundIntensity = 20.0f;
- m_sQueueSample.m_nLoopCount = 1;
- m_sQueueSample.m_nLoopStart = 0;
- m_sQueueSample.m_nLoopEnd = -1;
- m_sQueueSample.m_nEmittingVolume = emittingVol;
- m_sQueueSample.m_bIs2D = false;
- m_sQueueSample.m_bReleasingSoundFlag = true;
- m_sQueueSample.m_bRequireReflection = true;
+ if (params.m_pPed->bIsInTheAir)
+ continue;
+ emittingVol = m_anRandomTable[3] % 15 + 45;
+ if (FindPlayerPed() != m_asAudioEntities[m_sQueueSample.m_nEntityIndex].m_pEntity)
+ emittingVol /= 2;
+ maxDist = 400.f;
+ switch (params.m_pPed->m_nSurfaceTouched) {
+ case SURFACE_GRASS:
+ sampleIndex = m_anRandomTable[1] % 5 + SFX_FOOTSTEP_GRASS_1;
+ break;
+ case SURFACE_GRAVEL:
+ case SURFACE_MUD_DRY:
+ sampleIndex = m_anRandomTable[4] % 5 + SFX_FOOTSTEP_GRAVEL_1;
+ break;
+ case SURFACE_CAR:
+ case SURFACE_GARAGE_DOOR:
+ case SURFACE_CAR_PANEL:
+ case SURFACE_THICK_METAL_PLATE:
+ case SURFACE_SCAFFOLD_POLE:
+ case SURFACE_LAMP_POST:
+ case SURFACE_FIRE_HYDRANT:
+ case SURFACE_GIRDER:
+ case SURFACE_METAL_CHAIN_FENCE:
+ case SURFACE_CONTAINER:
+ case SURFACE_NEWS_VENDOR:
+ sampleIndex = m_anRandomTable[0] % 5 + SFX_FOOTSTEP_METAL_1;
+ break;
+ case SURFACE_SAND:
+ sampleIndex = (m_anRandomTable[4] & 3) + SFX_FOOTSTEP_SAND_1;
+ break;
+ case SURFACE_WATER:
+ sampleIndex = (m_anRandomTable[3] & 3) + SFX_FOOTSTEP_WATER_1;
+ break;
+ case SURFACE_WOOD_CRATES:
+ case SURFACE_WOOD_BENCH:
+ case SURFACE_WOOD_SOLID:
+ sampleIndex = m_anRandomTable[2] % 5 + SFX_FOOTSTEP_WOOD_1;
+ break;
+ case SURFACE_HEDGE:
+ sampleIndex = m_anRandomTable[2] % 5 + SFX_COL_VEG_1;
+ break;
+ default:
+ sampleIndex = m_anRandomTable[2] % 5 + SFX_FOOTSTEP_CONCRETE_1;
+ break;
}
+ m_sQueueSample.m_nSampleIndex = sampleIndex;
+ m_sQueueSample.m_nBankIndex = SFX_BANK_0;
+ m_sQueueSample.m_nCounter = m_asAudioEntities[m_sQueueSample.m_nEntityIndex].m_awAudioEvent[i] - SOUND_STEP_START + 1;
+ m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(m_sQueueSample.m_nSampleIndex);
+ m_sQueueSample.m_nFrequency += RandomDisplacement(m_sQueueSample.m_nFrequency / 17);
+ switch (params.m_pPed->m_nMoveState) {
+ case PEDMOVE_WALK:
+ emittingVol /= 4;
+ m_sQueueSample.m_nFrequency = 9 * m_sQueueSample.m_nFrequency / 10;
+ break;
+ case PEDMOVE_RUN:
+ emittingVol /= 2;
+ m_sQueueSample.m_nFrequency = 11 * m_sQueueSample.m_nFrequency / 10;
+ break;
+ case PEDMOVE_SPRINT:
+ m_sQueueSample.m_nFrequency = 12 * m_sQueueSample.m_nFrequency / 10;
+ break;
+ default:
+ break;
+ }
+ m_sQueueSample.m_nReleasingVolumeModificator = 5;
+ m_sQueueSample.m_fSpeedMultiplier = 0.0f;
+ m_sQueueSample.m_fSoundIntensity = 20.0f;
+ m_sQueueSample.m_nLoopCount = 1;
+ m_sQueueSample.m_nLoopStart = 0;
+ m_sQueueSample.m_nLoopEnd = -1;
+ m_sQueueSample.m_nEmittingVolume = emittingVol;
+ m_sQueueSample.m_bIs2D = false;
+ m_sQueueSample.m_bReleasingSoundFlag = true;
+ m_sQueueSample.m_bRequireReflection = true;
break;
case SOUND_FALL_LAND:
case SOUND_FALL_COLLAPSE:
- if (!ped->bIsLooking) {
- maxDist = SQR(30);
- emittingVol = m_anRandomTable[3] % 20 + 80;
- if (ped->m_nSurfaceTouched == SURFACE_WATER) {
- m_sQueueSample.m_nSampleIndex = (m_anRandomTable[3] & 3) + SFX_FOOTSTEP_WATER_1;
- } else if (sound == SOUND_FALL_LAND) {
- m_sQueueSample.m_nSampleIndex = SFX_BODY_LAND;
- } else {
- m_sQueueSample.m_nSampleIndex = SFX_BODY_LAND_AND_FALL;
- }
- m_sQueueSample.m_nBankIndex = SFX_BANK_0;
- m_sQueueSample.m_nCounter = 1;
- m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(m_sQueueSample.m_nSampleIndex);
- m_sQueueSample.m_nFrequency += RandomDisplacement(m_sQueueSample.m_nFrequency / 17);
- m_sQueueSample.m_nReleasingVolumeModificator = 2;
- m_sQueueSample.m_fSpeedMultiplier = 0.0f;
- m_sQueueSample.m_fSoundIntensity = 30.0f;
- m_sQueueSample.m_nLoopCount = 1;
- m_sQueueSample.m_nLoopStart = 0;
- m_sQueueSample.m_nLoopEnd = -1;
- m_sQueueSample.m_nEmittingVolume = emittingVol;
- m_sQueueSample.m_bIs2D = false;
- m_sQueueSample.m_bReleasingSoundFlag = true;
- m_sQueueSample.m_bRequireReflection = true;
+ if (ped->bIsInTheAir)
+ continue;
+ maxDist = SQR(30);
+ emittingVol = m_anRandomTable[3] % 20 + 80;
+ if (ped->m_nSurfaceTouched == SURFACE_WATER) {
+ m_sQueueSample.m_nSampleIndex = (m_anRandomTable[3] & 3) + SFX_FOOTSTEP_WATER_1;
+ } else if (sound == SOUND_FALL_LAND) {
+ m_sQueueSample.m_nSampleIndex = SFX_BODY_LAND;
+ } else {
+ m_sQueueSample.m_nSampleIndex = SFX_BODY_LAND_AND_FALL;
}
+ m_sQueueSample.m_nBankIndex = SFX_BANK_0;
+ m_sQueueSample.m_nCounter = 1;
+ m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(m_sQueueSample.m_nSampleIndex);
+ m_sQueueSample.m_nFrequency += RandomDisplacement(m_sQueueSample.m_nFrequency / 17);
+ m_sQueueSample.m_nReleasingVolumeModificator = 2;
+ m_sQueueSample.m_fSpeedMultiplier = 0.0f;
+ m_sQueueSample.m_fSoundIntensity = 30.0f;
+ m_sQueueSample.m_nLoopCount = 1;
+ m_sQueueSample.m_nLoopStart = 0;
+ m_sQueueSample.m_nLoopEnd = -1;
+ m_sQueueSample.m_nEmittingVolume = emittingVol;
+ m_sQueueSample.m_bIs2D = false;
+ m_sQueueSample.m_bReleasingSoundFlag = true;
+ m_sQueueSample.m_bRequireReflection = true;
break;
case SOUND_FIGHT_PUNCH_33:
m_sQueueSample.m_nSampleIndex = SFX_FIGHT_1;
@@ -5795,7 +5788,7 @@ cAudioManager::GetCasualMaleOldTalkSfx(int16 sound)
uint32
cAudioManager::GetSpecialCharacterTalkSfx(int32 modelIndex, int32 sound)
{
- char *modelName = CModelInfo::GetModelInfo(modelIndex)->GetName();
+ char *modelName = CModelInfo::GetModelInfo(modelIndex)->GetModelName();
if (!CGeneral::faststricmp(modelName, "eight") || !CGeneral::faststricmp(modelName, "eight2")) {
return GetEightTalkSfx(sound);
}
@@ -6363,26 +6356,25 @@ cAudioManager::ProcessOneShotScriptObject(uint8 sound)
uint8 emittingVolume;
float distSquared;
- cPedParams male;
- cPedParams female;
-
static uint8 iSound = 0;
switch (sound) {
case SCRIPT_SOUND_INJURED_PED_MALE_OUCH_S:
case SCRIPT_SOUND_INJURED_PED_MALE_OUCH_L:
- male.m_pPed = nil;
- male.m_bDistanceCalculated = false;
- male.m_fDistance = GetDistanceSquared(m_sQueueSample.m_vecPos);
- SetupPedComments(male, SOUND_INJURED_PED_MALE_OUCH);
+ {
+ cPedParams pedParams;
+ pedParams.m_fDistance = GetDistanceSquared(m_sQueueSample.m_vecPos);
+ SetupPedComments(pedParams, SOUND_INJURED_PED_MALE_OUCH);
return;
+ }
case SCRIPT_SOUND_INJURED_PED_FEMALE_OUCH_S:
case SCRIPT_SOUND_INJURED_PED_FEMALE_OUCH_L:
- female.m_pPed = nil;
- female.m_bDistanceCalculated = false;
- female.m_fDistance = GetDistanceSquared(m_sQueueSample.m_vecPos);
- SetupPedComments(female, SOUND_INJURED_PED_FEMALE);
+ {
+ cPedParams pedParams;
+ pedParams.m_fDistance = GetDistanceSquared(m_sQueueSample.m_vecPos);
+ SetupPedComments(pedParams, SOUND_INJURED_PED_FEMALE);
return;
+ }
case SCRIPT_SOUND_GATE_START_CLUNK:
case SCRIPT_SOUND_GATE_STOP_CLUNK:
m_sQueueSample.m_fSoundIntensity = 40.0f;
@@ -6537,36 +6529,20 @@ cAudioManager::ProcessOneShotScriptObject(uint8 sound)
m_sQueueSample.m_nSampleIndex = SFX_BULLET_SHELL_HIT_GROUND_2;
m_sQueueSample.m_nFrequency = RandomDisplacement(500) + 11000;
m_sQueueSample.m_nReleasingVolumeModificator = 18;
- m_sQueueSample.m_fSoundIntensity = 20.0f;
- m_sQueueSample.m_nBankIndex = SFX_BANK_0;
- m_sQueueSample.m_fSpeedMultiplier = 0.0f;
- m_sQueueSample.m_bIs2D = false;
- emittingVolume = m_anRandomTable[2] % 20 + 30;
- distSquared = GetDistanceSquared(m_sQueueSample.m_vecPos);
- if (distSquared < SQR(m_sQueueSample.m_fSoundIntensity)) {
- m_sQueueSample.m_fDistance = Sqrt(distSquared);
- m_sQueueSample.m_nVolume = ComputeVolume(emittingVolume, m_sQueueSample.m_fSoundIntensity, m_sQueueSample.m_fDistance);
- if (m_sQueueSample.m_nVolume != 0) {
- m_sQueueSample.m_nCounter = iSound++;
- m_sQueueSample.m_nLoopCount = 1;
- m_sQueueSample.m_bReleasingSoundFlag = true;
- m_sQueueSample.m_nEmittingVolume = emittingVolume;
- m_sQueueSample.m_nLoopStart = 0;
- m_sQueueSample.m_nLoopEnd = -1;
- m_sQueueSample.m_bReverbFlag = true;
- AddSampleToRequestedQueue();
- }
- }
- return;
+ break;
case SURFACE_WATER:
return;
default:
+ m_sQueueSample.m_nSampleIndex = SFX_BULLET_SHELL_HIT_GROUND_1;
+ m_sQueueSample.m_nFrequency = RandomDisplacement(750) + 18000;
+ m_sQueueSample.m_nReleasingVolumeModificator = 15;
break;
}
+ } else {
+ m_sQueueSample.m_nSampleIndex = SFX_BULLET_SHELL_HIT_GROUND_1;
+ m_sQueueSample.m_nFrequency = RandomDisplacement(750) + 18000;
+ m_sQueueSample.m_nReleasingVolumeModificator = 15;
}
- m_sQueueSample.m_nSampleIndex = SFX_BULLET_SHELL_HIT_GROUND_1;
- m_sQueueSample.m_nFrequency = RandomDisplacement(750) + 18000;
- m_sQueueSample.m_nReleasingVolumeModificator = 15;
m_sQueueSample.m_fSoundIntensity = 20.0f;
m_sQueueSample.m_nBankIndex = SFX_BANK_0;
m_sQueueSample.m_fSpeedMultiplier = 0.0f;
@@ -7715,7 +7691,6 @@ cAudioManager::ProcessPoliceCellBeatingScriptObject(uint8 sound)
int32 sampleIndex;
uint8 emittingVol;
float distSquared;
- cPedParams params;
static uint8 iSound = 0;
@@ -7756,9 +7731,9 @@ cAudioManager::ProcessPoliceCellBeatingScriptObject(uint8 sound)
m_sQueueSample.m_bReverbFlag = true;
m_sQueueSample.m_bRequireReflection = false;
AddSampleToRequestedQueue();
+ cPedParams params;
params.m_bDistanceCalculated = true;
params.m_fDistance = distSquared;
- params.m_pPed = nil;
SetupPedComments(params, SOUND_INJURED_PED_MALE_PRISON);
}
gCellNextTime = time + 500 + m_anRandomTable[3] % 1500;
@@ -7952,7 +7927,7 @@ cAudioManager::ProcessFrontEnd()
frontendBank = true;
stereo = true;
break;
- case SOUND_FRONTEND_NO_RADIO:
+ case SOUND_FRONTEND_RADIO_TURN_OFF:
case SOUND_FRONTEND_RADIO_CHANGE:
m_sQueueSample.m_nSampleIndex = SFX_RADIO_CLICK;
break;
@@ -8121,7 +8096,7 @@ cAudioManager::ProcessGarages()
const float SOUND_INTENSITY = 80.0f;
CEntity *entity;
- eGarageState state;
+ uint8 state;
uint32 sampleIndex;
uint8 j;
float distSquared;
diff --git a/src/audio/AudioManager.cpp b/src/audio/AudioManager.cpp
index 947bda40..f61350fb 100644
--- a/src/audio/AudioManager.cpp
+++ b/src/audio/AudioManager.cpp
@@ -13,16 +13,19 @@
cAudioManager AudioManager;
-const int channels = ARRAY_SIZE(cAudioManager::m_asActiveSamples);
+const int channels = ARRAY_SIZE(AudioManager.m_asActiveSamples);
const int policeChannel = channels + 1;
const int allChannels = channels + 2;
+#define SPEED_OF_SOUND 343.f
+#define TIME_SPENT 50
+
cAudioManager::cAudioManager()
{
m_bIsInitialised = false;
- field_1 = 1;
- m_fSpeedOfSound = 6.86f;
- m_nTimeSpent = 50;
+ m_bReverb = true;
+ m_fSpeedOfSound = SPEED_OF_SOUND / TIME_SPENT;
+ m_nTimeSpent = TIME_SPENT;
m_nActiveSamples = NUM_SOUNDS_SAMPLES_SLOTS;
m_nActiveSampleQueue = 1;
ClearRequestedQueue();
@@ -128,7 +131,7 @@ cAudioManager::CreateEntity(eAudioType type, void *entity)
for (uint32 i = 0; i < ARRAY_SIZE(m_asAudioEntities); i++) {
if (!m_asAudioEntities[i].m_bIsUsed) {
m_asAudioEntities[i].m_bIsUsed = true;
- m_asAudioEntities[i].m_nStatus = 0;
+ m_asAudioEntities[i].m_bStatus = false;
m_asAudioEntities[i].m_nType = type;
m_asAudioEntities[i].m_pEntity = entity;
m_asAudioEntities[i].m_awAudioEvent[0] = SOUND_NO_SOUND;
@@ -163,7 +166,7 @@ void
cAudioManager::SetEntityStatus(int32 id, uint8 status)
{
if (m_bIsInitialised && id >= 0 && id < NUM_AUDIOENTITIES && m_asAudioEntities[id].m_bIsUsed)
- m_asAudioEntities[id].m_nStatus = status;
+ m_asAudioEntities[id].m_bStatus = status;
}
void
@@ -945,7 +948,7 @@ cAudioManager::ClearActiveSamples()
m_asActiveSamples[i].m_nCalculatedVolume = 0;
m_asActiveSamples[i].m_nReleasingVolumeDivider = 0;
m_asActiveSamples[i].m_nVolumeChange = -1;
- m_asActiveSamples[i].m_vecPos = {0.0f, 0.0f, 0.0f};
+ m_asActiveSamples[i].m_vecPos = CVector(0.0f, 0.0f, 0.0f);
m_asActiveSamples[i].m_bReverbFlag = false;
m_asActiveSamples[i].m_nLoopsRemaining = 0;
m_asActiveSamples[i].m_bRequireReflection = false;
diff --git a/src/audio/AudioManager.h b/src/audio/AudioManager.h
index d781ad71..2f86ee98 100644
--- a/src/audio/AudioManager.h
+++ b/src/audio/AudioManager.h
@@ -46,7 +46,7 @@ public:
eAudioType m_nType;
void *m_pEntity;
bool m_bIsUsed;
- uint8 m_nStatus;
+ uint8 m_bStatus;
int16 m_awAudioEvent[NUM_AUDIOENTITY_EVENTS];
float m_afVolume[NUM_AUDIOENTITY_EVENTS];
uint8 m_AudioEvents;
@@ -132,6 +132,13 @@ public:
bool m_bDistanceCalculated;
float m_fDistance;
CPed *m_pPed;
+
+ cPedParams()
+ {
+ m_bDistanceCalculated = false;
+ m_fDistance = 0.0f;
+ m_pPed = nil;
+ }
};
class cVehicleParams
@@ -143,6 +150,16 @@ public:
cTransmission *m_pTransmission;
int32 m_nIndex;
float m_fVelocityChange;
+
+ cVehicleParams()
+ {
+ m_bDistanceCalculated = false;
+ m_fDistance = 0.0f;
+ m_pVehicle = nil;
+ m_pTransmission = nil;
+ m_nIndex = 0;
+ m_fVelocityChange = 0.0f;
+ }
};
VALIDATE_SIZE(cVehicleParams, 0x18);
@@ -168,7 +185,7 @@ class cAudioManager
{
public:
bool m_bIsInitialised;
- uint8 field_1; // unused
+ bool m_bReverb; // unused
bool m_bFifthFrameFlag;
uint8 m_nActiveSamples;
uint8 field_4; // unused
diff --git a/src/audio/AudioSamples.h b/src/audio/AudioSamples.h
index e2721888..df64521c 100644
--- a/src/audio/AudioSamples.h
+++ b/src/audio/AudioSamples.h
@@ -2,7 +2,7 @@
#include "common.h"
-enum eSfxSample : uint32
+enum eSfxSample
{
SFX_CAR_HORN_JEEP = 0,
SFX_CAR_HORN_BMW328,
diff --git a/src/audio/MusicManager.cpp b/src/audio/MusicManager.cpp
index 5519d899..3e1a7384 100644
--- a/src/audio/MusicManager.cpp
+++ b/src/audio/MusicManager.cpp
@@ -15,6 +15,9 @@
#include "World.h"
#include "sampman.h"
+#if !defined FIX_BUGS && (defined RADIO_SCROLL_TO_PREV_STATION || defined RADIO_OFF_TEXT)
+static_assert(false, "RADIO_SCROLL_TO_PREV_STATION and RADIO_OFF_TEXT won't work correctly without FIX_BUGS");
+#endif
cMusicManager MusicManager;
int32 gNumRetunePresses;
@@ -26,8 +29,8 @@ cMusicManager::cMusicManager()
m_bIsInitialised = false;
m_bDisabled = false;
m_nMusicMode = MUSICMODE_DISABLED;
- m_nCurrentStreamedSound = NO_TRACK;
- m_nPreviousStreamedSound = NO_TRACK;
+ m_nNextTrack = NO_TRACK;
+ m_nPlayingTrack = NO_TRACK;
m_bFrontendTrackFinished = false;
m_bPlayInFrontend = false;
m_bSetNextStation = false;
@@ -35,7 +38,7 @@ cMusicManager::cMusicManager()
m_bPreviousPlayerInCar = false;
m_bPlayerInCar = false;
m_bAnnouncementInProgress = false;
- m_bDontServiceAmbienceTrack = false;
+ m_bVerifyAmbienceTrackStartedToPlay = false;
bHasStarted = false;
}
@@ -83,36 +86,64 @@ cMusicManager::DisplayRadioStationName()
if(m_bPlayerInCar && !m_bPreviousPlayerInCar)
pCurrentStation = nil;
- if(SampleManager.IsMP3RadioChannelAvailable()) {
- gStreamedSound = m_nCurrentStreamedSound;
+#ifdef FIX_BUGS
+ const int curRadio = GetCarTuning();
+#else
+ const int curRadio = m_nNextTrack;
+#endif
- if(gStreamedSound == STREAMED_SOUND_CITY_AMBIENT ||
- gStreamedSound == STREAMED_SOUND_WATER_AMBIENT) {
- gStreamedSound = STREAMED_SOUND_RADIO_POLICE;
- } else {
+#ifdef RADIO_SCROLL_TO_PREV_STATION
+ if(gNumRetunePresses < 0) {
+ gStreamedSound = curRadio;
+
+ gRetuneCounter = gNumRetunePresses;
+ pRetune = gStreamedSound;
- if(gStreamedSound >
- STREAMED_SOUND_RADIO_MP3_PLAYER)
- return;
+ while(gRetuneCounter < 0) {
+ if(pRetune == HEAD_RADIO) {
+ pRetune = RADIO_OFF;
+ } else if(pRetune == RADIO_OFF || pRetune == NUM_RADIOS) {
+ pRetune = SampleManager.IsMP3RadioChannelAvailable() ? USERTRACK : USERTRACK - 1;
+ } else
+ pRetune--;
+
+ ++gRetuneCounter;
}
+ } else
+#endif
+ if(SampleManager.IsMP3RadioChannelAvailable()) {
+ gStreamedSound = curRadio;
+
+ if(gStreamedSound == STREAMED_SOUND_CITY_AMBIENT ||
+ gStreamedSound == STREAMED_SOUND_WATER_AMBIENT) { // which means OFF
+ gStreamedSound = NUM_RADIOS;
+ } else if(gStreamedSound > STREAMED_SOUND_RADIO_MP3_PLAYER)
+ return;
pRetune = gNumRetunePresses + gStreamedSound;
- if(pRetune == POLICE_RADIO) {
+#ifdef FIX_BUGS
+ while(pRetune > NUM_RADIOS)
+ pRetune -= (NUM_RADIOS + 1);
+#endif
+ if(pRetune == NUM_RADIOS) {
pRetune = RADIO_OFF;
- } else if(pRetune > POLICE_RADIO) {
- pRetune = pRetune - RADIO_OFF;
}
+#ifndef FIX_BUGS
+ else if(pRetune > NUM_RADIOS) {
+ pRetune = pRetune - (NUM_RADIOS + 1);
+ }
+#endif
} else {
- gStreamedSound = m_nCurrentStreamedSound;
+ gStreamedSound = curRadio;
pRetune = gNumRetunePresses + gStreamedSound;
if(pRetune >= USERTRACK) {
gRetuneCounter = gNumRetunePresses;
- pRetune = m_nCurrentStreamedSound;
+ pRetune = curRadio;
if(gStreamedSound == STREAMED_SOUND_WATER_AMBIENT)
- pRetune = RADIO_OFF;
+ pRetune = STREAMED_SOUND_CITY_AMBIENT; // which is RADIO_OFF
while(gRetuneCounter) {
if(pRetune == RADIO_OFF) {
@@ -127,7 +158,7 @@ cMusicManager::DisplayRadioStationName()
}
}
- wchar *string = nil;
+ wchar *string;
switch(pRetune) {
case HEAD_RADIO: string = TheText.Get("FEA_FM0"); break;
@@ -139,15 +170,27 @@ cMusicManager::DisplayRadioStationName()
case MSX_FM: string = TheText.Get("FEA_FM6"); break;
case FLASHBACK: string = TheText.Get("FEA_FM7"); break;
case CHATTERBOX: string = TheText.Get("FEA_FM8"); break;
- case USERTRACK: string = TheText.Get("FEA_FM9"); break;
+ case USERTRACK:
+ if (!SampleManager.IsMP3RadioChannelAvailable())
+ return;
+ string = TheText.Get("FEA_FM9"); break;
+#ifdef RADIO_OFF_TEXT
+ case RADIO_OFF: {
+ extern wchar WideErrorString[];
+
+ string = TheText.Get("FEA_FMN");
+ if(string == WideErrorString) {
+ pCurrentStation = nil;
+ return;
+ }
+ break;
+ }
+#endif
default: return;
};
- if(pRetune > CHATTERBOX && !SampleManager.IsMP3RadioChannelAvailable()) { return; }
-
- if(string && pCurrentStation != string ||
- m_nCurrentStreamedSound == STREAMED_SOUND_RADIO_MP3_PLAYER &&
- m_nPreviousStreamedSound != STREAMED_SOUND_RADIO_MP3_PLAYER) {
+ if(pCurrentStation != string ||
+ m_nNextTrack == STREAMED_SOUND_RADIO_MP3_PLAYER && m_nPlayingTrack != STREAMED_SOUND_RADIO_MP3_PLAYER) {
pCurrentStation = string;
cDisplay = 60;
} else {
@@ -161,9 +204,15 @@ cMusicManager::DisplayRadioStationName()
CFont::SetPropOn();
CFont::SetFontStyle(FONT_HEADING);
CFont::SetCentreOn();
- CFont::SetCentreSize(SCREEN_STRETCH_X(DEFAULT_SCREEN_WIDTH));
+ // Reminder: Game doesn't have "scaling" at all, it just stretches, and it's team's decision here to not let centered text occupy all the screen.
+ // Disable ASPECT_RATIO_SCALE and it'll go back to default behaviour; stretching.
+ CFont::SetCentreSize(SCREEN_SCALE_X(DEFAULT_SCREEN_WIDTH));
CFont::SetColor(CRGBA(0, 0, 0, 255));
+#ifdef FIX_BUGS
CFont::PrintString(SCREEN_WIDTH / 2 + SCREEN_SCALE_X(2.0f), SCREEN_SCALE_Y(22.0f) + SCREEN_SCALE_Y(2.0f), pCurrentStation);
+#else
+ CFont::PrintString(SCREEN_WIDTH / 2 + 2.0f, SCREEN_SCALE_Y(22.0f) + 2.0f, pCurrentStation);
+#endif
if(gNumRetunePresses)
CFont::SetColor(CRGBA(102, 133, 143, 255));
@@ -222,7 +271,7 @@ cMusicManager::Initialise()
m_bDoTrackService = false;
m_bIgnoreTimeDelay = false;
m_bRadioSetByScript = false;
- m_nRadioStation = HEAD_RADIO;
+ m_nRadioStationScript = HEAD_RADIO;
m_nRadioPosition = -1;
m_nRadioInCar = NO_TRACK;
gNumRetunePresses = 0;
@@ -239,8 +288,8 @@ cMusicManager::Terminate()
if (SampleManager.IsStreamPlaying(0)) {
SampleManager.StopStreamedFile(0);
- m_nCurrentStreamedSound = NO_TRACK;
- m_nPreviousStreamedSound = NO_TRACK;
+ m_nNextTrack = NO_TRACK;
+ m_nPlayingTrack = NO_TRACK;
}
m_bIsInitialised = false;
}
@@ -268,14 +317,14 @@ cMusicManager::ChangeMusicMode(uint8 mode)
case MUSICMODE_CUTSCENE:
case MUSICMODE_DISABLED:
if (SampleManager.IsStreamPlaying(0)) {
- if (m_nCurrentStreamedSound < TOTAL_STREAMED_SOUNDS) {
- m_aTracks[m_nCurrentStreamedSound].m_nPosition = SampleManager.GetStreamedFilePosition(0);
- m_aTracks[m_nCurrentStreamedSound].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
+ if (m_nNextTrack < TOTAL_STREAMED_SOUNDS) {
+ m_aTracks[m_nNextTrack].m_nPosition = SampleManager.GetStreamedFilePosition(0);
+ m_aTracks[m_nNextTrack].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
}
SampleManager.StopStreamedFile(0);
}
- m_nCurrentStreamedSound = NO_TRACK;
- m_nPreviousStreamedSound = NO_TRACK;
+ m_nNextTrack = NO_TRACK;
+ m_nPlayingTrack = NO_TRACK;
m_bFrontendTrackFinished = false;
m_bPlayInFrontend = false;
m_bSetNextStation = false;
@@ -285,7 +334,7 @@ cMusicManager::ChangeMusicMode(uint8 mode)
m_nTimer = m_nLastTrackServiceTime = CTimer::GetTimeInMillisecondsPauseMode();
m_bDoTrackService = false;
m_bIgnoreTimeDelay = true;
- m_bDontServiceAmbienceTrack = false;
+ m_bVerifyAmbienceTrackStartedToPlay = false;
m_nMusicMode = mode2;
break;
default: return;
@@ -335,7 +384,7 @@ cMusicManager::SetRadioChannelByScript(uint8 station, int32 pos)
{
if (m_bIsInitialised && station < RADIO_OFF) {
m_bRadioSetByScript = true;
- m_nRadioStation = station;
+ m_nRadioStationScript = station;
m_nRadioPosition = pos == -1 ? -1 : pos % m_aTracks[station].m_nLength;
}
}
@@ -345,7 +394,7 @@ void
cMusicManager::ResetMusicAfterReload()
{
m_bRadioSetByScript = false;
- m_nRadioStation = 0;
+ m_nRadioStationScript = 0;
m_nRadioPosition = -1;
m_nAnnouncement = NO_TRACK;
m_bAnnouncementInProgress = false;
@@ -384,7 +433,7 @@ cMusicManager::Service()
m_nLastTrackServiceTime = m_nTimer;
} else m_bDoTrackService = false;
- if (m_nCurrentStreamedSound == NO_TRACK && SampleManager.IsStreamPlaying(0))
+ if (m_nNextTrack == NO_TRACK && SampleManager.IsStreamPlaying(0))
SampleManager.StopStreamedFile(0);
else switch (m_nMusicMode) {
case MUSICMODE_FRONTEND: ServiceFrontEndMode(); break;
@@ -395,10 +444,10 @@ cMusicManager::Service()
void
cMusicManager::ServiceFrontEndMode()
{
- if (m_nCurrentStreamedSound < TOTAL_STREAMED_SOUNDS) {
+ if (m_nNextTrack < TOTAL_STREAMED_SOUNDS) {
if (m_bFrontendTrackFinished) {
if (!SampleManager.IsStreamPlaying(0)) {
- switch (m_nCurrentStreamedSound)
+ switch (m_nNextTrack)
{
case STREAMED_SOUND_MISSION_COMPLETED:
if (!AudioManager.m_nUserPause)
@@ -410,15 +459,15 @@ cMusicManager::ServiceFrontEndMode()
default:
break;
}
- m_nCurrentStreamedSound = NO_TRACK;
- m_nPreviousStreamedSound = NO_TRACK;
+ m_nNextTrack = NO_TRACK;
+ m_nPlayingTrack = NO_TRACK;
}
} else if (bHasStarted) {
if (!SampleManager.IsStreamPlaying(0))
- SampleManager.StartStreamedFile(m_nCurrentStreamedSound, 0, 0);
+ SampleManager.StartStreamedFile(m_nNextTrack, 0, 0);
} else {
SampleManager.SetStreamedVolumeAndPan(0, 63, 0, 0);
- if (!SampleManager.StartStreamedFile(m_nCurrentStreamedSound, m_nCurrentStreamedSound < STREAMED_SOUND_RADIO_POLICE ? GetTrackStartPos(m_nCurrentStreamedSound) : 0, 0))
+ if (!SampleManager.StartStreamedFile(m_nNextTrack, m_nNextTrack < NUM_RADIOS ? GetTrackStartPos(m_nNextTrack) : 0, 0))
return;
SampleManager.SetStreamedVolumeAndPan(100, 63, 0, 0);
if (m_bPlayInFrontend) bHasStarted = true;
@@ -438,21 +487,38 @@ cMusicManager::ServiceGameMode()
m_bPreviousPlayerInCar = m_bPlayerInCar;
m_bPlayerInCar = PlayerInCar();
- m_nPreviousStreamedSound = m_nCurrentStreamedSound;
+ m_nPlayingTrack = m_nNextTrack;
if (m_bPlayerInCar) {
if (FindPlayerPed() != nil
&& !FindPlayerPed()->DyingOrDead()
- && CPad::GetPad(0)->ChangeStationJustDown()
&& !CReplay::IsPlayingBack()
&& FindPlayerVehicle() != nil
&& !UsesPoliceRadio(FindPlayerVehicle())) {
- gRetuneCounter = 30;
- gNumRetunePresses++;
- AudioManager.PlayOneShot(AudioManager.m_nFrontEndEntity, SOUND_FRONTEND_RADIO_CHANGE, 1.0f);
- if (SampleManager.IsMP3RadioChannelAvailable()) {
- if (gNumRetunePresses > RADIO_OFF)
- gNumRetunePresses -= RADIO_OFF;
+
+ if (CPad::GetPad(0)->ChangeStationJustDown()) {
+ gRetuneCounter = 30;
+ gNumRetunePresses++;
+ AudioManager.PlayOneShot(AudioManager.m_nFrontEndEntity, SOUND_FRONTEND_RADIO_CHANGE, 1.0f);
+ // This needs loop, and this is not the right place. Now done elsewhere.
+#ifndef FIX_BUGS
+ if (SampleManager.IsMP3RadioChannelAvailable()) {
+ if (gNumRetunePresses > RADIO_OFF)
+ gNumRetunePresses -= RADIO_OFF;
+ }
+#endif
+ }
+#ifdef RADIO_SCROLL_TO_PREV_STATION
+ else if(CPad::GetPad(0)->GetMouseWheelDownJustDown() || CPad::GetPad(0)->GetMouseWheelUpJustDown()) {
+ int scrollNext = ControlsManager.GetControllerKeyAssociatedWithAction(VEHICLE_CHANGE_RADIO_STATION, MOUSE);
+ int scrollPrev = scrollNext == rsMOUSEWHEELUPBUTTON ? rsMOUSEWHEELDOWNBUTTON : scrollNext == rsMOUSEWHEELDOWNBUTTON ? rsMOUSEWHEELUPBUTTON : -1;
+
+ if (scrollPrev != -1 && !ControlsManager.IsAnyVehicleActionAssignedToMouseKey(scrollPrev)) {
+ gRetuneCounter = 30;
+ gNumRetunePresses--;
+ AudioManager.PlayOneShot(AudioManager.m_nFrontEndEntity, SOUND_FRONTEND_RADIO_CHANGE, 1.0f);
+ }
}
+#endif
}
} else {
nFramesSinceCutsceneEnded = -1;
@@ -462,8 +528,8 @@ cMusicManager::ServiceGameMode()
m_bPreviousPlayerInCar = false;
if (!m_bPlayerInCar) {
if (m_bPreviousPlayerInCar) {
- if (m_nCurrentStreamedSound != STREAMED_SOUND_RADIO_POLICE)
- m_nRadioInCar = m_nCurrentStreamedSound;
+ if (m_nNextTrack != STREAMED_SOUND_RADIO_POLICE)
+ m_nRadioInCar = m_nNextTrack;
}
ServiceAmbience();
return;
@@ -471,22 +537,22 @@ cMusicManager::ServiceGameMode()
if (m_bPreviousPlayerInCar) {
if (m_nAnnouncement < TOTAL_STREAMED_SOUNDS
- && (m_nCurrentStreamedSound < STREAMED_SOUND_CITY_AMBIENT || m_bAnnouncementInProgress)
+ && (m_nNextTrack < RADIO_OFF || m_bAnnouncementInProgress)
&& ServiceAnnouncement())
{
if (m_bAnnouncementInProgress) {
m_bSetNextStation = false;
return;
}
- m_nPreviousStreamedSound = m_nCurrentStreamedSound;
- m_nCurrentStreamedSound = GetCarTuning();
+ m_nPlayingTrack = m_nNextTrack;
+ m_nNextTrack = GetCarTuning();
}
if (SampleManager.IsMP3RadioChannelAvailable()
- && m_nCurrentStreamedSound != STREAMED_SOUND_RADIO_MP3_PLAYER
+ && m_nNextTrack != STREAMED_SOUND_RADIO_MP3_PLAYER
&& ControlsManager.GetIsKeyboardKeyJustDown(rsF9))
{
- m_nPreviousStreamedSound = m_nCurrentStreamedSound;
- m_nCurrentStreamedSound = STREAMED_SOUND_RADIO_MP3_PLAYER;
+ m_nPlayingTrack = m_nNextTrack;
+ m_nNextTrack = STREAMED_SOUND_RADIO_MP3_PLAYER;
if (FindPlayerVehicle() != nil)
FindPlayerVehicle()->m_nRadioStation = STREAMED_SOUND_RADIO_MP3_PLAYER;
AudioManager.PlayOneShot(AudioManager.m_nFrontEndEntity, SOUND_FRONTEND_RADIO_CHANGE, 1.0f);
@@ -494,30 +560,42 @@ cMusicManager::ServiceGameMode()
gNumRetunePresses = 0;
m_bSetNextStation = false;
}
+ // Because when you switch radio back and forth, gNumRetunePresses will be 0 but gRetuneCounter won't.
+#ifdef RADIO_SCROLL_TO_PREV_STATION
+ if (gRetuneCounter != 0) {
+ if (gRetuneCounter > 1) gRetuneCounter--;
+ else if (gRetuneCounter == 1) gRetuneCounter = -1;
+ else if (gRetuneCounter == -1) {
+ m_bSetNextStation = true;
+ gRetuneCounter = 0;
+ }
+ }
+#else
if (gNumRetunePresses) {
if (gRetuneCounter != 0) gRetuneCounter--;
else m_bSetNextStation = true;
}
+#endif
if (gRetuneCounter)
AudioManager.DoPoliceRadioCrackle();
if (m_bSetNextStation) {
m_bSetNextStation = false;
- m_nPreviousStreamedSound = m_nCurrentStreamedSound;
- m_nCurrentStreamedSound = GetNextCarTuning();
- if (m_nCurrentStreamedSound == STREAMED_SOUND_CITY_AMBIENT || m_nCurrentStreamedSound == STREAMED_SOUND_WATER_AMBIENT)
+ m_nPlayingTrack = m_nNextTrack;
+ m_nNextTrack = GetNextCarTuning();
+ if (m_nNextTrack == STREAMED_SOUND_CITY_AMBIENT || m_nNextTrack == STREAMED_SOUND_WATER_AMBIENT)
bRadioOff = true;
- if (m_nPreviousStreamedSound == STREAMED_SOUND_CITY_AMBIENT || m_nPreviousStreamedSound == STREAMED_SOUND_WATER_AMBIENT)
+ if (m_nPlayingTrack == STREAMED_SOUND_CITY_AMBIENT || m_nPlayingTrack == STREAMED_SOUND_WATER_AMBIENT)
AudioManager.PlayOneShot(AudioManager.m_nFrontEndEntity, SOUND_FRONTEND_RADIO_CHANGE, 0.0f);
}
- if (m_nCurrentStreamedSound < STREAMED_SOUND_CITY_AMBIENT) {
+ if (m_nNextTrack < RADIO_OFF) {
if (ChangeRadioChannel()) {
ServiceTrack();
} else {
m_bPlayerInCar = false;
if (FindPlayerVehicle())
- FindPlayerVehicle()->m_nRadioStation = m_nCurrentStreamedSound;
- m_nCurrentStreamedSound = NO_TRACK;
+ FindPlayerVehicle()->m_nRadioStation = m_nNextTrack;
+ m_nNextTrack = NO_TRACK;
}
if (CTimer::GetIsSlowMotionActive()) {
if (TheCamera.pTargetEntity != nil) {
@@ -570,56 +648,56 @@ cMusicManager::ServiceGameMode()
return;
}
if (bRadioOff) {
- m_nCurrentStreamedSound = m_nPreviousStreamedSound;
+ m_nNextTrack = m_nPlayingTrack;
if (FindPlayerVehicle() != nil)
FindPlayerVehicle()->m_nRadioStation = RADIO_OFF;
- AudioManager.PlayOneShot(AudioManager.m_nFrontEndEntity, SOUND_FRONTEND_NO_RADIO, 0.0f);
+ AudioManager.PlayOneShot(AudioManager.m_nFrontEndEntity, SOUND_FRONTEND_RADIO_TURN_OFF, 0.0f);
}
ServiceAmbience();
return;
}
if (m_bRadioSetByScript) {
if (UsesPoliceRadio(FindPlayerVehicle())) {
- m_nCurrentStreamedSound = STREAMED_SOUND_RADIO_POLICE;
+ m_nNextTrack = STREAMED_SOUND_RADIO_POLICE;
} else {
- m_nCurrentStreamedSound = m_nRadioStation;
- if (FindPlayerVehicle()->m_nRadioStation == m_nCurrentStreamedSound) {
- m_nPreviousStreamedSound = NO_TRACK;
+ m_nNextTrack = m_nRadioStationScript;
+ if (FindPlayerVehicle()->m_nRadioStation == m_nNextTrack) {
+ m_nPlayingTrack = NO_TRACK;
SampleManager.SetStreamedVolumeAndPan(0, 63, 0, 0);
SampleManager.StopStreamedFile(0);
}
if (m_nRadioPosition != -1) {
- m_aTracks[m_nCurrentStreamedSound].m_nPosition = m_nRadioPosition;
- m_aTracks[m_nCurrentStreamedSound].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
+ m_aTracks[m_nNextTrack].m_nPosition = m_nRadioPosition;
+ m_aTracks[m_nNextTrack].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
}
}
} else {
- m_nCurrentStreamedSound = GetCarTuning();
+ m_nNextTrack = GetCarTuning();
}
- if (m_nCurrentStreamedSound >= RADIO_OFF) {
+ if (m_nNextTrack >= RADIO_OFF) {
ServiceAmbience();
return;
}
if (ChangeRadioChannel()) {
if (m_bRadioSetByScript) {
m_bRadioSetByScript = false;
- FindPlayerVehicle()->m_nRadioStation = m_nCurrentStreamedSound;
+ FindPlayerVehicle()->m_nRadioStation = m_nNextTrack;
}
} else {
m_bPlayerInCar = false;
- m_nCurrentStreamedSound = NO_TRACK;
+ m_nNextTrack = NO_TRACK;
}
}
void
cMusicManager::StopFrontEndTrack()
{
- if (IsInitialised() && !m_bDisabled && m_nMusicMode == MUSICMODE_FRONTEND && m_nCurrentStreamedSound != NO_TRACK) {
- m_aTracks[m_nCurrentStreamedSound].m_nPosition = SampleManager.GetStreamedFilePosition(0);
- m_aTracks[m_nCurrentStreamedSound].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
+ if (IsInitialised() && !m_bDisabled && m_nMusicMode == MUSICMODE_FRONTEND && m_nNextTrack != NO_TRACK) {
+ m_aTracks[m_nNextTrack].m_nPosition = SampleManager.GetStreamedFilePosition(0);
+ m_aTracks[m_nNextTrack].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
SampleManager.StopStreamedFile(0);
- m_nPreviousStreamedSound = NO_TRACK;
- m_nCurrentStreamedSound = NO_TRACK;
+ m_nPlayingTrack = NO_TRACK;
+ m_nNextTrack = NO_TRACK;
}
}
@@ -635,30 +713,30 @@ cMusicManager::PlayFrontEndTrack(uint8 track, uint8 bPlayInFrontend)
{
if (IsInitialised() && !m_bDisabled && track < TOTAL_STREAMED_SOUNDS) {
if (m_nMusicMode == MUSICMODE_GAME) {
- if (m_nCurrentStreamedSound != NO_TRACK) {
+ if (m_nNextTrack != NO_TRACK) {
if (m_bAnnouncementInProgress) {
m_nAnnouncement = NO_TRACK;
m_bAnnouncementInProgress = false;
}
- m_aTracks[m_nCurrentStreamedSound].m_nPosition = SampleManager.GetStreamedFilePosition(0);
- m_aTracks[m_nCurrentStreamedSound].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
+ m_aTracks[m_nNextTrack].m_nPosition = SampleManager.GetStreamedFilePosition(0);
+ m_aTracks[m_nNextTrack].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
}
SampleManager.StopStreamedFile(0);
} else if (m_nMusicMode == MUSICMODE_FRONTEND) {
- if (m_nCurrentStreamedSound != NO_TRACK) {
- m_aTracks[m_nCurrentStreamedSound].m_nPosition = SampleManager.GetStreamedFilePosition(0);
- m_aTracks[m_nCurrentStreamedSound].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
+ if (m_nNextTrack != NO_TRACK) {
+ m_aTracks[m_nNextTrack].m_nPosition = SampleManager.GetStreamedFilePosition(0);
+ m_aTracks[m_nNextTrack].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
}
SampleManager.StopStreamedFile(0);
}
- m_nPreviousStreamedSound = m_nCurrentStreamedSound;
- m_nCurrentStreamedSound = track;
+ m_nPlayingTrack = m_nNextTrack;
+ m_nNextTrack = track;
m_bPlayInFrontend = !!bPlayInFrontend;
m_bFrontendTrackFinished = false;
m_bDoTrackService = true;
bHasStarted = false;
- if (m_nCurrentStreamedSound < STREAMED_SOUND_RADIO_POLICE) {
+ if (m_nNextTrack < NUM_RADIOS) {
gRetuneCounter = 0;
gNumRetunePresses = 0;
}
@@ -674,7 +752,7 @@ cMusicManager::PreloadCutSceneMusic(uint8 track)
SampleManager.StopStreamedFile(0);
SampleManager.PreloadStreamedFile(track, 0);
SampleManager.SetStreamedVolumeAndPan(MAX_VOLUME, 63, 1, 0);
- m_nCurrentStreamedSound = track;
+ m_nNextTrack = track;
}
}
@@ -690,7 +768,7 @@ cMusicManager::StopCutSceneMusic(void)
{
if (IsInitialised() && !m_bDisabled && m_nMusicMode == MUSICMODE_CUTSCENE) {
SampleManager.StopStreamedFile(0);
- m_nCurrentStreamedSound = NO_TRACK;
+ m_nNextTrack = NO_TRACK;
}
}
@@ -734,45 +812,45 @@ cMusicManager::ServiceAmbience()
m_nAnnouncement = NO_TRACK;
m_bAnnouncementInProgress = false;
}
- if (m_nCurrentStreamedSound < STREAMED_SOUND_CITY_AMBIENT) {
+ if (m_nNextTrack < RADIO_OFF) {
if (SampleManager.IsStreamPlaying(0)) {
- m_aTracks[m_nCurrentStreamedSound].m_nPosition = SampleManager.GetStreamedFilePosition(0);
- m_aTracks[m_nCurrentStreamedSound].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
+ m_aTracks[m_nNextTrack].m_nPosition = SampleManager.GetStreamedFilePosition(0);
+ m_aTracks[m_nNextTrack].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
SampleManager.StopStreamedFile(0);
- m_nCurrentStreamedSound = NO_TRACK;
+ m_nNextTrack = NO_TRACK;
return;
}
- m_nCurrentStreamedSound = STREAMED_SOUND_CITY_AMBIENT;
+ m_nNextTrack = RADIO_OFF;
}
if (CWorld::Players[CWorld::PlayerInFocus].m_WBState != WBSTATE_PLAYING && !SampleManager.IsStreamPlaying(0)) {
- m_nCurrentStreamedSound = NO_TRACK;
+ m_nNextTrack = NO_TRACK;
return;
}
- m_nPreviousStreamedSound = m_nCurrentStreamedSound;
- m_nCurrentStreamedSound = TheCamera.DistanceToWater <= 45.0f ? STREAMED_SOUND_WATER_AMBIENT : STREAMED_SOUND_CITY_AMBIENT;
+ m_nPlayingTrack = m_nNextTrack;
+ m_nNextTrack = TheCamera.DistanceToWater <= 45.0f ? STREAMED_SOUND_WATER_AMBIENT : STREAMED_SOUND_CITY_AMBIENT;
- if (m_nCurrentStreamedSound == m_nPreviousStreamedSound) {
+ if (m_nNextTrack == m_nPlayingTrack) {
ComputeAmbienceVol(false, volume);
SampleManager.SetStreamedVolumeAndPan(volume, 63, 1, 0);
- if (m_bDontServiceAmbienceTrack) {
+ if (m_bVerifyAmbienceTrackStartedToPlay) {
if (SampleManager.IsStreamPlaying(0))
- m_bDontServiceAmbienceTrack = false;
+ m_bVerifyAmbienceTrackStartedToPlay = false;
} else ServiceTrack();
} else {
- if (m_nPreviousStreamedSound < TOTAL_STREAMED_SOUNDS) {
- m_aTracks[m_nPreviousStreamedSound].m_nPosition = SampleManager.GetStreamedFilePosition(0);
- m_aTracks[m_nPreviousStreamedSound].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
+ if (m_nPlayingTrack < TOTAL_STREAMED_SOUNDS) {
+ m_aTracks[m_nPlayingTrack].m_nPosition = SampleManager.GetStreamedFilePosition(0);
+ m_aTracks[m_nPlayingTrack].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
SampleManager.StopStreamedFile(0);
}
- uint32 pos = GetTrackStartPos(m_nCurrentStreamedSound);
+ uint32 pos = GetTrackStartPos(m_nNextTrack);
SampleManager.SetStreamedVolumeAndPan(0, 63, 1, 0);
- if (SampleManager.StartStreamedFile(m_nCurrentStreamedSound, pos, 0)) {
+ if (SampleManager.StartStreamedFile(m_nNextTrack, pos, 0)) {
ComputeAmbienceVol(true, volume);
SampleManager.SetStreamedVolumeAndPan(volume, 63, 1, 0);
- m_bDontServiceAmbienceTrack = true;
+ m_bVerifyAmbienceTrackStartedToPlay = true;
} else
- m_nCurrentStreamedSound = NO_TRACK;
+ m_nNextTrack = NO_TRACK;
}
}
@@ -801,7 +879,7 @@ cMusicManager::ServiceTrack()
{
if (m_bDoTrackService) {
if (!SampleManager.IsStreamPlaying(0))
- SampleManager.StartStreamedFile(m_nCurrentStreamedSound, 0, 0);
+ SampleManager.StartStreamedFile(m_nNextTrack, 0, 0);
}
}
@@ -821,9 +899,9 @@ cMusicManager::ServiceAnnouncement()
cCheck = 0;
int pos = SampleManager.GetStreamedFilePosition(0);
if (SampleManager.IsStreamPlaying(0)) {
- if (m_nCurrentStreamedSound != NO_TRACK) {
- m_aTracks[m_nCurrentStreamedSound].m_nPosition = pos;
- m_aTracks[m_nCurrentStreamedSound].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
+ if (m_nNextTrack != NO_TRACK) {
+ m_aTracks[m_nNextTrack].m_nPosition = pos;
+ m_aTracks[m_nNextTrack].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
SampleManager.StopStreamedFile(0);
}
}
@@ -832,8 +910,8 @@ cMusicManager::ServiceAnnouncement()
if (SampleManager.StartStreamedFile(m_nAnnouncement, 0, 0)) {
SampleManager.SetStreamedVolumeAndPan(AudioManager.ShouldDuckMissionAudio() ? 25 : 100, 63, 0, 0);
m_bAnnouncementInProgress = true;
- m_nPreviousStreamedSound = m_nCurrentStreamedSound;
- m_nCurrentStreamedSound = m_nAnnouncement;
+ m_nPlayingTrack = m_nNextTrack;
+ m_nNextTrack = m_nAnnouncement;
return true;
}
@@ -863,14 +941,34 @@ cMusicManager::GetNextCarTuning()
if (veh == nil) return RADIO_OFF;
if (UsesPoliceRadio(veh)) return POLICE_RADIO;
if (gNumRetunePresses != 0) {
+#ifdef RADIO_SCROLL_TO_PREV_STATION
+ if (gNumRetunePresses < 0) {
+ while (gNumRetunePresses < 0) {
+ if(veh->m_nRadioStation == HEAD_RADIO) {
+ veh->m_nRadioStation = RADIO_OFF;
+ } else if(veh->m_nRadioStation == RADIO_OFF || veh->m_nRadioStation == NUM_RADIOS) {
+ veh->m_nRadioStation = SampleManager.IsMP3RadioChannelAvailable() ? USERTRACK : USERTRACK - 1;
+ } else
+ veh->m_nRadioStation--;
+
+ ++gNumRetunePresses;
+ }
+ } else
+#endif
if (SampleManager.IsMP3RadioChannelAvailable()) {
if (veh->m_nRadioStation == RADIO_OFF)
- veh->m_nRadioStation = POLICE_RADIO;
+ veh->m_nRadioStation = NUM_RADIOS;
veh->m_nRadioStation += gNumRetunePresses;
- if (veh->m_nRadioStation == POLICE_RADIO)
+#ifdef FIX_BUGS
+ while (veh->m_nRadioStation > NUM_RADIOS)
+ veh->m_nRadioStation -= (NUM_RADIOS + 1);
+#endif
+ if (veh->m_nRadioStation == NUM_RADIOS)
veh->m_nRadioStation = RADIO_OFF;
- else if (veh->m_nRadioStation > POLICE_RADIO)
- veh->m_nRadioStation -= RADIO_OFF;
+#ifndef FIX_BUGS
+ else if (veh->m_nRadioStation > NUM_RADIOS)
+ veh->m_nRadioStation -= (NUM_RADIOS + 1);
+#endif
} else if (gNumRetunePresses + veh->m_nRadioStation >= USERTRACK) {
while (gNumRetunePresses) {
if (veh->m_nRadioStation == RADIO_OFF)
@@ -892,16 +990,16 @@ cMusicManager::GetNextCarTuning()
bool
cMusicManager::ChangeRadioChannel()
{
- if (m_nCurrentStreamedSound != m_nPreviousStreamedSound) {
- if (m_nPreviousStreamedSound < TOTAL_STREAMED_SOUNDS) {
- m_aTracks[m_nPreviousStreamedSound].m_nPosition = SampleManager.GetStreamedFilePosition(0);
- m_aTracks[m_nPreviousStreamedSound].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
+ if (m_nNextTrack != m_nPlayingTrack) {
+ if (m_nPlayingTrack < TOTAL_STREAMED_SOUNDS) {
+ m_aTracks[m_nPlayingTrack].m_nPosition = SampleManager.GetStreamedFilePosition(0);
+ m_aTracks[m_nPlayingTrack].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
SampleManager.SetStreamedVolumeAndPan(0, 63, 0, 0);
SampleManager.StopStreamedFile(0);
}
if (SampleManager.IsStreamPlaying(0))
return false;
- if (!SampleManager.StartStreamedFile(m_nCurrentStreamedSound, GetTrackStartPos(m_nCurrentStreamedSound), 0))
+ if (!SampleManager.StartStreamedFile(m_nNextTrack, GetTrackStartPos(m_nNextTrack), 0))
return false;
SampleManager.SetStreamedVolumeAndPan(AudioManager.ShouldDuckMissionAudio() ? 25 : 100, 63, 0, 0);
}
diff --git a/src/audio/MusicManager.h b/src/audio/MusicManager.h
index e8b94da6..5d277f0e 100644
--- a/src/audio/MusicManager.h
+++ b/src/audio/MusicManager.h
@@ -18,8 +18,8 @@ public:
bool m_bIsInitialised;
bool m_bDisabled;
uint8 m_nMusicMode;
- uint8 m_nCurrentStreamedSound;
- uint8 m_nPreviousStreamedSound;
+ uint8 m_nNextTrack;
+ uint8 m_nPlayingTrack;
bool m_bFrontendTrackFinished;
bool m_bPlayInFrontend;
bool m_bSetNextStation;
@@ -34,9 +34,9 @@ public:
uint32 m_nTimer;
bool m_bDoTrackService;
bool m_bIgnoreTimeDelay;
- bool m_bDontServiceAmbienceTrack;
+ bool m_bVerifyAmbienceTrackStartedToPlay;
bool m_bRadioSetByScript;
- uint8 m_nRadioStation;
+ uint8 m_nRadioStationScript;
int32 m_nRadioPosition;
uint8 m_nRadioInCar;
@@ -44,7 +44,7 @@ public:
cMusicManager();
bool IsInitialised() { return m_bIsInitialised; }
uint32 GetMusicMode() { return m_nMusicMode; }
- uint8 GetCurrentTrack() { return m_nCurrentStreamedSound; }
+ uint8 GetNextTrack() { return m_nNextTrack; }
bool Initialise();
void Terminate();
diff --git a/src/audio/PoliceRadio.cpp b/src/audio/PoliceRadio.cpp
index 665494a3..785dbf8f 100644
--- a/src/audio/PoliceRadio.cpp
+++ b/src/audio/PoliceRadio.cpp
@@ -13,8 +13,9 @@
#include "World.h"
#include "Zones.h"
#include "sampman.h"
+#include "Wanted.h"
-const int channels = ARRAY_SIZE(cAudioManager::m_asActiveSamples);
+const int channels = ARRAY_SIZE(AudioManager.m_asActiveSamples);
const int policeChannel = channels + 1;
struct tPoliceRadioZone {
@@ -93,7 +94,7 @@ cAudioManager::InitialisePoliceRadio()
for (int32 i = 0; i < ARRAY_SIZE(m_sPoliceRadioQueue.crimes); i++)
m_sPoliceRadioQueue.crimes[i].type = CRIME_NONE;
- SampleManager.SetChannelReverbFlag(policeChannel, 0);
+ SampleManager.SetChannelReverbFlag(policeChannel, false);
gSpecialSuspectLastSeenReport = false;
for (int32 i = 0; i < ARRAY_SIZE(gMinTimeToNextReport); i++)
gMinTimeToNextReport[i] = m_FrameCounter;
@@ -160,7 +161,7 @@ cAudioManager::ServicePoliceRadio()
if(CReplay::IsPlayingBack() || !FindPlayerPed() || !FindPlayerPed()->m_pWanted)
return;
#endif
- wantedLevel = FindPlayerPed()->m_pWanted->m_nWantedLevel;
+ wantedLevel = FindPlayerPed()->m_pWanted->GetWantedLevel();
if(!crimeReport) {
if(wantedLevel != 0) {
if(nLastSeen != 0) {
@@ -678,7 +679,7 @@ void
cAudioManager::ReportCrime(eCrimeType type, const CVector &pos)
{
int32 lastCrime = ARRAY_SIZE(m_sPoliceRadioQueue.crimes);
- if (m_bIsInitialised && MusicManager.m_nMusicMode != MUSICMODE_CUTSCENE && FindPlayerPed()->m_pWanted->m_nWantedLevel > 0 &&
+ if (m_bIsInitialised && MusicManager.m_nMusicMode != MUSICMODE_CUTSCENE && FindPlayerPed()->m_pWanted->GetWantedLevel() > 0 &&
(type > CRIME_NONE || type < NUM_CRIME_TYPES) && m_FrameCounter >= gMinTimeToNextReport[type]) {
for (int32 i = 0; i < ARRAY_SIZE(m_sPoliceRadioQueue.crimes); i++) {
if (m_sPoliceRadioQueue.crimes[i].type) {
diff --git a/src/audio/PoliceRadio.h b/src/audio/PoliceRadio.h
index c01f21ce..368708b6 100644
--- a/src/audio/PoliceRadio.h
+++ b/src/audio/PoliceRadio.h
@@ -1,6 +1,6 @@
#pragma once
-#include "Wanted.h"
+#include "Crime.h"
struct cAMCrime {
int32 type;
diff --git a/src/audio/audio_enums.h b/src/audio/audio_enums.h
index 20760859..027042cb 100644
--- a/src/audio/audio_enums.h
+++ b/src/audio/audio_enums.h
@@ -12,8 +12,9 @@ enum eRadioStation
FLASHBACK,
CHATTERBOX,
USERTRACK,
- POLICE_RADIO,
- RADIO_OFF,
+ POLICE_RADIO = 10,
+ NUM_RADIOS = 10,
+ RADIO_OFF = 11,
};
enum eMusicMode
@@ -235,7 +236,7 @@ enum AudioEntityHandle {
AEHANDLE_ERROR_BADAUDIOTYPE = -1,
};
-enum eAudioType : int32
+enum eAudioType
{
AUDIOTYPE_PHYSICAL = 0,
AUDIOTYPE_EXPLOSION,
diff --git a/src/audio/oal/channel.cpp b/src/audio/oal/channel.cpp
index 673a4aed..d1fd0aea 100644
--- a/src/audio/oal/channel.cpp
+++ b/src/audio/oal/channel.cpp
@@ -15,6 +15,8 @@ ALuint alFilters[MAXCHANNELS+MAX2DCHANNELS];
ALuint alBuffers[MAXCHANNELS+MAX2DCHANNELS];
bool bChannelsCreated = false;
+int32 CChannel::channelsThatNeedService = 0;
+
void
CChannel::InitChannels()
{
@@ -59,7 +61,9 @@ void CChannel::SetDefault()
Position[0] = 0.0f; Position[1] = 0.0f; Position[2] = 0.0f;
Distances[0] = 0.0f; Distances[1] = FLT_MAX;
- LoopCount = 1;
+
+ LoopCount = 1;
+ LastProcessedOffset = UINT32_MAX;
LoopPoints[0] = 0; LoopPoints[1] = -1;
Frequency = MAX_FREQ;
@@ -67,6 +71,10 @@ void CChannel::SetDefault()
void CChannel::Reset()
{
+ // Here is safe because ctor don't call this
+ if (LoopCount > 1)
+ channelsThatNeedService--;
+
ClearBuffer();
SetDefault();
}
@@ -165,10 +173,51 @@ void CChannel::SetCurrentFreq(uint32 freq)
SetPitch(ALfloat(freq) / Frequency);
}
-void CChannel::SetLoopCount(int32 loopCount) // fake. TODO:
+void CChannel::SetLoopCount(int32 count)
{
if ( !HasSource() ) return;
- alSourcei(alSources[id], AL_LOOPING, loopCount == 1 ? AL_FALSE : AL_TRUE);
+
+ // 0: loop indefinitely, 1: play one time, 2: play two times etc...
+ // only > 1 needs manual processing
+
+ if (LoopCount > 1 && count < 2)
+ channelsThatNeedService--;
+ else if (LoopCount < 2 && count > 1)
+ channelsThatNeedService++;
+
+ alSourcei(alSources[id], AL_LOOPING, count == 1 ? AL_FALSE : AL_TRUE);
+ LoopCount = count;
+}
+
+bool CChannel::Update()
+{
+ if (!HasSource()) return false;
+ if (LoopCount < 2) return false;
+
+ ALint state;
+ alGetSourcei(alSources[id], AL_SOURCE_STATE, &state);
+ if (state == AL_STOPPED) {
+ debug("Looping channels(%d in this case) shouldn't report AL_STOPPED, but nvm\n", id);
+ SetLoopCount(1);
+ return true;
+ }
+
+ assert(channelsThatNeedService > 0 && "Ref counting is broken");
+
+ ALint offset;
+ alGetSourcei(alSources[id], AL_SAMPLE_OFFSET, &offset);
+
+ // Rewound
+ if (offset < LastProcessedOffset) {
+ LoopCount--;
+ if (LoopCount == 1) {
+ // Playing last tune...
+ channelsThatNeedService--;
+ alSourcei(alSources[id], AL_LOOPING, AL_FALSE);
+ }
+ }
+ LastProcessedOffset = offset;
+ return true;
}
void CChannel::SetLoopPoints(ALint start, ALint end)
@@ -200,6 +249,7 @@ void CChannel::SetPan(int32 pan)
void CChannel::ClearBuffer()
{
if ( !HasSource() ) return;
+ alSourcei(alSources[id], AL_LOOPING, AL_FALSE);
alSourcei(alSources[id], AL_BUFFER, AL_NONE);
Data = nil;
DataSize = 0;
diff --git a/src/audio/oal/channel.h b/src/audio/oal/channel.h
index 81817a32..b081be25 100644
--- a/src/audio/oal/channel.h
+++ b/src/audio/oal/channel.h
@@ -19,7 +19,10 @@ class CChannel
float Distances[2];
int32 LoopCount;
ALint LoopPoints[2];
+ ALint LastProcessedOffset;
public:
+ static int32 channelsThatNeedService;
+
static void InitChannels();
static void DestroyChannels();
@@ -37,7 +40,7 @@ public:
void SetVolume(int32 vol);
void SetSampleData(void *_data, size_t _DataSize, int32 freq);
void SetCurrentFreq(uint32 freq);
- void SetLoopCount(int32 loopCount); // fake
+ void SetLoopCount(int32 count);
void SetLoopPoints(ALint start, ALint end);
void SetPosition(float x, float y, float z);
void SetDistances(float max, float min);
@@ -45,6 +48,7 @@ public:
void ClearBuffer();
void SetReverbMix(ALuint slot, float mix);
void UpdateReverb(ALuint slot);
+ bool Update();
};
#endif \ No newline at end of file
diff --git a/src/audio/oal/oal_utils.cpp b/src/audio/oal/oal_utils.cpp
index e16de572..e4cb0b77 100644
--- a/src/audio/oal/oal_utils.cpp
+++ b/src/audio/oal/oal_utils.cpp
@@ -3,6 +3,14 @@
#ifdef AUDIO_OAL
+/*
+ * When linking to a static openal-soft library,
+ * the extension function inside the openal library conflict with the variables here.
+ * Therefore declare these re3 owned symbols in a private namespace.
+ */
+
+namespace re3_openal {
+
LPALGENEFFECTS alGenEffects;
LPALDELETEEFFECTS alDeleteEffects;
LPALISEFFECT alIsEffect;
@@ -37,6 +45,9 @@ LPALGETFILTERIV alGetFilteriv;
LPALGETFILTERF alGetFilterf;
LPALGETFILTERFV alGetFilterfv;
+}
+
+using namespace re3_openal;
void EFXInit()
{
diff --git a/src/audio/oal/oal_utils.h b/src/audio/oal/oal_utils.h
index b89ccf36..f0fa090a 100644
--- a/src/audio/oal/oal_utils.h
+++ b/src/audio/oal/oal_utils.h
@@ -11,6 +11,8 @@ void EFX_Set(ALuint effect, const EAXLISTENERPROPERTIES *props);
void EAX3_SetReverbMix(ALuint filter, float mix);
void SetEffectsLevel(ALuint uiFilter, float level);
+namespace re3_openal {
+
extern LPALGENEFFECTS alGenEffects;
extern LPALDELETEEFFECTS alDeleteEffects;
extern LPALISEFFECT alIsEffect;
@@ -44,4 +46,9 @@ extern LPALGETFILTERI alGetFilteri;
extern LPALGETFILTERIV alGetFilteriv;
extern LPALGETFILTERF alGetFilterf;
extern LPALGETFILTERFV alGetFilterfv;
+
+}
+
+using namespace re3_openal;
+
#endif
diff --git a/src/audio/oal/stream.cpp b/src/audio/oal/stream.cpp
index 3adb702a..61cd243d 100644
--- a/src/audio/oal/stream.cpp
+++ b/src/audio/oal/stream.cpp
@@ -4,20 +4,395 @@
#include "stream.h"
#include "sampman.h"
-#ifdef AUDIO_OPUS
-#include <opusfile.h>
-#else
-#ifdef _WIN32
+#if defined _MSC_VER && !defined RE3_NO_AUTOLINK
+#ifdef AUDIO_OAL_USE_SNDFILE
#pragma comment( lib, "libsndfile-1.lib" )
+#endif
+#ifdef AUDIO_OAL_USE_MPG123
#pragma comment( lib, "libmpg123-0.lib" )
-#else
-#include "crossplatform.h"
#endif
+#endif
+#ifdef AUDIO_OAL_USE_SNDFILE
#include <sndfile.h>
+#endif
+#ifdef AUDIO_OAL_USE_MPG123
#include <mpg123.h>
#endif
+#ifdef AUDIO_OAL_USE_OPUS
+#include <opusfile.h>
+#endif
+
+#ifndef _WIN32
+#include "crossplatform.h"
+#endif
+
+/*
+As we ran onto an issue of having different volume levels for mono streams
+and stereo streams we are now handling all the stereo panning ourselves.
+Each stream now has two sources - one panned to the left and one to the right,
+and uses two separate buffers to store data for each individual channel.
+For that we also have to reshuffle all decoded PCM stereo data from LRLRLRLR to
+LLLLRRRR (handled by CSortStereoBuffer).
+*/
+
+class CSortStereoBuffer
+{
+ uint16* PcmBuf;
+ size_t BufSize;
+public:
+ CSortStereoBuffer() : PcmBuf(nil), BufSize(0) {}
+ ~CSortStereoBuffer()
+ {
+ if (PcmBuf)
+ free(PcmBuf);
+ }
+
+ uint16* GetBuffer(size_t size)
+ {
+ if (size == 0) return nil;
+ if (!PcmBuf)
+ {
+ BufSize = size;
+ PcmBuf = (uint16*)malloc(BufSize);
+ }
+ else if (BufSize < size)
+ {
+ BufSize = size;
+ PcmBuf = (uint16*)realloc(PcmBuf, size);
+ }
+ return PcmBuf;
+ }
+
+ void SortStereo(void* buf, size_t size)
+ {
+ uint16* InBuf = (uint16*)buf;
+ uint16* OutBuf = GetBuffer(size);
+
+ if (!OutBuf) return;
+
+ size_t rightStart = size / 4;
+ for (size_t i = 0; i < size / 4; i++)
+ {
+ OutBuf[i] = InBuf[i*2];
+ OutBuf[i+rightStart] = InBuf[i*2+1];
+ }
+
+ memcpy(InBuf, OutBuf, size);
+ }
+
+};
+
+CSortStereoBuffer SortStereoBuffer;
+
+class CImaADPCMDecoder
+{
+ const uint16 StepTable[89] = {
+ 7, 8, 9, 10, 11, 12, 13, 14,
+ 16, 17, 19, 21, 23, 25, 28, 31,
+ 34, 37, 41, 45, 50, 55, 60, 66,
+ 73, 80, 88, 97, 107, 118, 130, 143,
+ 157, 173, 190, 209, 230, 253, 279, 307,
+ 337, 371, 408, 449, 494, 544, 598, 658,
+ 724, 796, 876, 963, 1060, 1166, 1282, 1411,
+ 1552, 1707, 1878, 2066, 2272, 2499, 2749, 3024,
+ 3327, 3660, 4026, 4428, 4871, 5358, 5894, 6484,
+ 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899,
+ 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794,
+ 32767
+ };
-#ifndef AUDIO_OPUS
+ int16 Sample, StepIndex;
+
+public:
+ CImaADPCMDecoder()
+ {
+ Init(0, 0);
+ }
+
+ void Init(int16 _Sample, int16 _StepIndex)
+ {
+ Sample = _Sample;
+ StepIndex = _StepIndex;
+ }
+
+ void Decode(uint8 *inbuf, int16 *_outbuf, size_t size)
+ {
+ int16* outbuf = _outbuf;
+ for (size_t i = 0; i < size; i++)
+ {
+ *(outbuf++) = DecodeSample(inbuf[i] & 0xF);
+ *(outbuf++) = DecodeSample(inbuf[i] >> 4);
+ }
+ }
+
+ int16 DecodeSample(uint8 adpcm)
+ {
+ uint16 step = StepTable[StepIndex];
+
+ if (adpcm & 4)
+ StepIndex += ((adpcm & 3) + 1) * 2;
+ else
+ StepIndex--;
+
+ StepIndex = clamp(StepIndex, 0, 88);
+
+ int delta = step >> 3;
+ if (adpcm & 1) delta += step >> 2;
+ if (adpcm & 2) delta += step >> 1;
+ if (adpcm & 4) delta += step;
+ if (adpcm & 8) delta = -delta;
+
+ int newSample = Sample + delta;
+ Sample = clamp(newSample, -32768, 32767);
+ return Sample;
+ }
+};
+
+class CWavFile : public IDecoder
+{
+ enum
+ {
+ WAVEFMT_PCM = 1,
+ WAVEFMT_IMA_ADPCM = 0x11,
+ WAVEFMT_XBOX_ADPCM = 0x69,
+ };
+
+ struct tDataHeader
+ {
+ uint32 ID;
+ uint32 Size;
+ };
+
+ struct tFormatHeader
+ {
+ uint16 AudioFormat;
+ uint16 NumChannels;
+ uint32 SampleRate;
+ uint32 ByteRate;
+ uint16 BlockAlign;
+ uint16 BitsPerSample;
+ uint16 extra[2]; // adpcm only
+
+ tFormatHeader() { memset(this, 0, sizeof(*this)); }
+ };
+
+ FILE *m_pFile;
+ bool m_bIsOpen;
+
+ tFormatHeader m_FormatHeader;
+
+ uint32 m_DataStartOffset; // TODO: 64 bit?
+ uint32 m_nSampleCount;
+ uint32 m_nSamplesPerBlock;
+
+ // ADPCM things
+ uint8 *m_pAdpcmBuffer;
+ int16 **m_ppPcmBuffers;
+ CImaADPCMDecoder *m_pAdpcmDecoders;
+
+ void Close()
+ {
+ if (m_pFile) {
+ fclose(m_pFile);
+ m_pFile = nil;
+ }
+ delete[] m_pAdpcmBuffer;
+ delete[] m_ppPcmBuffers;
+ delete[] m_pAdpcmDecoders;
+ }
+
+ uint32 GetCurrentSample() const
+ {
+ // TODO: 64 bit?
+ uint32 FilePos = ftell(m_pFile);
+ if (FilePos <= m_DataStartOffset)
+ return 0;
+ return (FilePos - m_DataStartOffset) / m_FormatHeader.BlockAlign * m_nSamplesPerBlock;
+ }
+
+public:
+ CWavFile(const char* path) : m_bIsOpen(false), m_DataStartOffset(0), m_nSampleCount(0), m_nSamplesPerBlock(0), m_pAdpcmBuffer(nil), m_ppPcmBuffers(nil), m_pAdpcmDecoders(nil)
+ {
+ m_pFile = fopen(path, "rb");
+ if (!m_pFile) return;
+
+#define CLOSE_ON_ERROR(op)\
+ if (op) { \
+ Close(); \
+ return; \
+ }
+
+ tDataHeader DataHeader;
+
+ CLOSE_ON_ERROR(fread(&DataHeader, sizeof(DataHeader), 1, m_pFile) == 0);
+ CLOSE_ON_ERROR(DataHeader.ID != 'FFIR');
+
+ // TODO? validate filesizes
+
+ int WAVE;
+ CLOSE_ON_ERROR(fread(&WAVE, 4, 1, m_pFile) == 0);
+ CLOSE_ON_ERROR(WAVE != 'EVAW')
+ CLOSE_ON_ERROR(fread(&DataHeader, sizeof(DataHeader), 1, m_pFile) == 0);
+ CLOSE_ON_ERROR(DataHeader.ID != ' tmf');
+
+ CLOSE_ON_ERROR(fread(&m_FormatHeader, Min(DataHeader.Size, sizeof(tFormatHeader)), 1, m_pFile) == 0);
+ CLOSE_ON_ERROR(DataHeader.Size > sizeof(tFormatHeader));
+
+ switch (m_FormatHeader.AudioFormat)
+ {
+ case WAVEFMT_XBOX_ADPCM:
+ m_FormatHeader.AudioFormat = WAVEFMT_IMA_ADPCM;
+ case WAVEFMT_IMA_ADPCM:
+ m_nSamplesPerBlock = (m_FormatHeader.BlockAlign / m_FormatHeader.NumChannels - 4) * 2 + 1;
+ m_pAdpcmBuffer = new uint8[m_FormatHeader.BlockAlign];
+ m_ppPcmBuffers = new int16*[m_FormatHeader.NumChannels];
+ m_pAdpcmDecoders = new CImaADPCMDecoder[m_FormatHeader.NumChannels];
+ break;
+ case WAVEFMT_PCM:
+ m_nSamplesPerBlock = 1;
+ if (m_FormatHeader.BitsPerSample != 16)
+ {
+ debug("Unsupported PCM (%d bits), only signed 16-bit is supported (%s)\n", m_FormatHeader.BitsPerSample, path);
+ Close();
+ return;
+ }
+ break;
+ default:
+ debug("Unsupported wav format 0x%x (%s)\n", m_FormatHeader.AudioFormat, path);
+ Close();
+ return;
+ }
+
+ while (true) {
+ CLOSE_ON_ERROR(fread(&DataHeader, sizeof(DataHeader), 1, m_pFile) == 0);
+ if (DataHeader.ID == 'atad')
+ break;
+ fseek(m_pFile, DataHeader.Size, SEEK_CUR);
+ // TODO? validate data size
+ // maybe check if there no extreme custom headers that might break this
+ }
+
+ m_DataStartOffset = ftell(m_pFile);
+ m_nSampleCount = DataHeader.Size / m_FormatHeader.BlockAlign * m_nSamplesPerBlock;
+
+ m_bIsOpen = true;
+#undef CLOSE_ON_ERROR
+ }
+
+ ~CWavFile()
+ {
+ Close();
+ }
+
+ bool IsOpened()
+ {
+ return m_bIsOpen;
+ }
+
+ uint32 GetSampleSize()
+ {
+ return sizeof(uint16);
+ }
+
+ uint32 GetSampleCount()
+ {
+ return m_nSampleCount;
+ }
+
+ uint32 GetSampleRate()
+ {
+ return m_FormatHeader.SampleRate;
+ }
+
+ uint32 GetChannels()
+ {
+ return m_FormatHeader.NumChannels;
+ }
+
+ void Seek(uint32 milliseconds)
+ {
+ if (!IsOpened()) return;
+ fseek(m_pFile, m_DataStartOffset + ms2samples(milliseconds) / m_nSamplesPerBlock * m_FormatHeader.BlockAlign, SEEK_SET);
+ }
+
+ uint32 Tell()
+ {
+ if (!IsOpened()) return 0;
+ return samples2ms(GetCurrentSample());
+ }
+
+#define SAMPLES_IN_LINE (8)
+
+ uint32 Decode(void* buffer)
+ {
+ if (!IsOpened()) return 0;
+
+ if (m_FormatHeader.AudioFormat == WAVEFMT_PCM)
+ {
+ // just read the file and sort the samples
+ uint32 size = fread(buffer, 1, GetBufferSize(), m_pFile);
+ if (m_FormatHeader.NumChannels == 2)
+ SortStereoBuffer.SortStereo(buffer, size);
+ return size;
+ }
+ else if (m_FormatHeader.AudioFormat == WAVEFMT_IMA_ADPCM)
+ {
+ // trim the buffer size if we're at the end of our file
+ uint32 nMaxSamples = GetBufferSamples() / m_FormatHeader.NumChannels;
+ uint32 nSamplesLeft = m_nSampleCount - GetCurrentSample();
+ nMaxSamples = Min(nMaxSamples, nSamplesLeft);
+
+ // align sample count to our block
+ nMaxSamples = nMaxSamples / m_nSamplesPerBlock * m_nSamplesPerBlock;
+
+ // count the size of output buffer
+ uint32 OutBufSizePerChannel = nMaxSamples * GetSampleSize();
+ uint32 OutBufSize = OutBufSizePerChannel * m_FormatHeader.NumChannels;
+
+ // calculate the pointers to individual channel buffers
+ for (uint32 i = 0; i < m_FormatHeader.NumChannels; i++)
+ m_ppPcmBuffers[i] = (int16*)((int8*)buffer + OutBufSizePerChannel * i);
+
+ uint32 samplesRead = 0;
+ while (samplesRead < nMaxSamples)
+ {
+ // read the file
+ uint8 *pAdpcmBuf = m_pAdpcmBuffer;
+ if (fread(m_pAdpcmBuffer, 1, m_FormatHeader.BlockAlign, m_pFile) == 0)
+ return 0;
+
+ // get the first sample in adpcm block and initialise the decoder(s)
+ for (uint32 i = 0; i < m_FormatHeader.NumChannels; i++)
+ {
+ int16 Sample = *(int16*)pAdpcmBuf;
+ pAdpcmBuf += sizeof(int16);
+ int16 Step = *(int16*)pAdpcmBuf;
+ pAdpcmBuf += sizeof(int16);
+ m_pAdpcmDecoders[i].Init(Sample, Step);
+ *(m_ppPcmBuffers[i]) = Sample;
+ m_ppPcmBuffers[i]++;
+ }
+ samplesRead++;
+
+ // decode the rest of the block
+ for (uint32 s = 1; s < m_nSamplesPerBlock; s += SAMPLES_IN_LINE)
+ {
+ for (uint32 i = 0; i < m_FormatHeader.NumChannels; i++)
+ {
+ m_pAdpcmDecoders[i].Decode(pAdpcmBuf, m_ppPcmBuffers[i], SAMPLES_IN_LINE / 2);
+ pAdpcmBuf += SAMPLES_IN_LINE / 2;
+ m_ppPcmBuffers[i] += SAMPLES_IN_LINE;
+ }
+ samplesRead += SAMPLES_IN_LINE;
+ }
+ }
+ return OutBufSize;
+ }
+ return 0;
+ }
+};
+
+#ifdef AUDIO_OAL_USE_SNDFILE
class CSndFile : public IDecoder
{
SNDFILE *m_pfSound;
@@ -79,9 +454,18 @@ public:
uint32 Decode(void *buffer)
{
if ( !IsOpened() ) return 0;
- return sf_read_short(m_pfSound, (short *)buffer, GetBufferSamples()) * GetSampleSize();
+
+ size_t size = sf_read_short(m_pfSound, (short*)buffer, GetBufferSamples()) * GetSampleSize();
+ if (GetChannels()==2)
+ SortStereoBuffer.SortStereo(buffer, size);
+ return size;
}
};
+#endif
+
+#ifdef AUDIO_OAL_USE_MPG123
+// fuzzy seek eliminates stutter when playing ADF but spams errors a lot (nothing breaks though)
+#define MP3_USE_FUZZY_SEEK
class CMP3File : public IDecoder
{
@@ -99,12 +483,16 @@ public:
m_pMH = mpg123_new(nil, nil);
if ( m_pMH )
{
+#ifdef MP3_USE_FUZZY_SEEK
+ mpg123_param(m_pMH, MPG123_FLAGS, MPG123_FUZZY | MPG123_SEEKBUFFER | MPG123_GAPLESS | MPG123_QUIET, 0.0);
+#endif
long rate = 0;
int channels = 0;
int encoding = 0;
m_bOpened = mpg123_open(m_pMH, path) == MPG123_OK
&& mpg123_getformat(m_pMH, &rate, &channels, &encoding) == MPG123_OK;
+
m_nRate = rate;
m_nChannels = channels;
@@ -174,10 +562,251 @@ public:
assert("We can't handle audio files more then 2 GB yet :shrug:" && (size < UINT32_MAX));
#endif
if (err != MPG123_OK && err != MPG123_DONE) return 0;
+ if (GetChannels() == 2)
+ SortStereoBuffer.SortStereo(buffer, size);
return (uint32)size;
}
};
-#else
+
+#endif
+#define VAG_LINE_SIZE (0x10)
+#define VAG_SAMPLES_IN_LINE (28)
+
+class CVagDecoder
+{
+ const double f[5][2] = { { 0.0, 0.0 },
+ { 60.0 / 64.0, 0.0 },
+ { 115.0 / 64.0, -52.0 / 64.0 },
+ { 98.0 / 64.0, -55.0 / 64.0 },
+ { 122.0 / 64.0, -60.0 / 64.0 } };
+
+ double s_1;
+ double s_2;
+public:
+ CVagDecoder()
+ {
+ ResetState();
+ }
+
+ void ResetState()
+ {
+ s_1 = s_2 = 0.0;
+ }
+
+ static short quantize(double sample)
+ {
+ int a = int(sample + 0.5);
+ return short(clamp(a, -32768, 32767));
+ }
+
+ void Decode(void* _inbuf, int16* _outbuf, size_t size)
+ {
+ uint8* inbuf = (uint8*)_inbuf;
+ int16* outbuf = _outbuf;
+ size &= ~(VAG_LINE_SIZE - 1);
+
+ while (size > 0) {
+ double samples[VAG_SAMPLES_IN_LINE];
+
+ int predict_nr, shift_factor, flags;
+ predict_nr = *(inbuf++);
+ shift_factor = predict_nr & 0xf;
+ predict_nr >>= 4;
+ flags = *(inbuf++);
+ if (flags == 7) // TODO: ignore?
+ break;
+ for (int i = 0; i < VAG_SAMPLES_IN_LINE; i += 2) {
+ int d = *(inbuf++);
+ int16 s = int16((d & 0xf) << 12);
+ samples[i] = (double)(s >> shift_factor);
+ s = int16((d & 0xf0) << 8);
+ samples[i + 1] = (double)(s >> shift_factor);
+ }
+
+ for (int i = 0; i < VAG_SAMPLES_IN_LINE; i++) {
+ samples[i] = samples[i] + s_1 * f[predict_nr][0] + s_2 * f[predict_nr][1];
+ s_2 = s_1;
+ s_1 = samples[i];
+ *(outbuf++) = quantize(samples[i] + 0.5);
+ }
+ size -= VAG_LINE_SIZE;
+ }
+ }
+};
+
+#define VB_BLOCK_SIZE (0x2000)
+#define NUM_VAG_LINES_IN_BLOCK (VB_BLOCK_SIZE / VAG_LINE_SIZE)
+#define NUM_VAG_SAMPLES_IN_BLOCK (NUM_VAG_LINES_IN_BLOCK * VAG_SAMPLES_IN_LINE)
+
+class CVbFile : public IDecoder
+{
+ FILE *m_pFile;
+ CVagDecoder *m_pVagDecoders;
+
+ size_t m_FileSize;
+ size_t m_nNumberOfBlocks;
+
+ uint32 m_nSampleRate;
+ uint8 m_nChannels;
+ bool m_bBlockRead;
+ uint16 m_LineInBlock;
+ size_t m_CurrentBlock;
+
+ uint8 **m_ppVagBuffers; // buffers that cache actual ADPCM file data
+ int16 **m_ppPcmBuffers;
+
+ void ReadBlock(int32 block = -1)
+ {
+ // just read next block if -1
+ if (block != -1)
+ fseek(m_pFile, block * m_nChannels * VB_BLOCK_SIZE, SEEK_SET);
+
+ for (int i = 0; i < m_nChannels; i++)
+ fread(m_ppVagBuffers[i], VB_BLOCK_SIZE, 1, m_pFile);
+ m_bBlockRead = true;
+ }
+
+public:
+ CVbFile(const char* path, uint32 nSampleRate = 32000, uint8 nChannels = 2) : m_nSampleRate(nSampleRate), m_nChannels(nChannels), m_pVagDecoders(nil), m_ppVagBuffers(nil), m_ppPcmBuffers(nil),
+ m_FileSize(0), m_nNumberOfBlocks(0), m_bBlockRead(false), m_LineInBlock(0), m_CurrentBlock(0)
+ {
+ m_pFile = fopen(path, "rb");
+ if (!m_pFile) return;
+
+ fseek(m_pFile, 0, SEEK_END);
+ m_FileSize = ftell(m_pFile);
+ fseek(m_pFile, 0, SEEK_SET);
+
+ m_nNumberOfBlocks = m_FileSize / (nChannels * VB_BLOCK_SIZE);
+ m_pVagDecoders = new CVagDecoder[nChannels];
+ m_ppVagBuffers = new uint8*[nChannels];
+ m_ppPcmBuffers = new int16*[nChannels];
+ for (uint8 i = 0; i < nChannels; i++)
+ m_ppVagBuffers[i] = new uint8[VB_BLOCK_SIZE];
+ }
+
+ ~CVbFile()
+ {
+ if (m_pFile)
+ {
+ fclose(m_pFile);
+
+ delete[] m_pVagDecoders;
+ for (int i = 0; i < m_nChannels; i++)
+ delete[] m_ppVagBuffers[i];
+ delete[] m_ppVagBuffers;
+ delete[] m_ppPcmBuffers;
+ }
+ }
+
+ bool IsOpened()
+ {
+ return m_pFile != nil;
+ }
+
+ uint32 GetSampleSize()
+ {
+ return sizeof(uint16);
+ }
+
+ uint32 GetSampleCount()
+ {
+ if (!IsOpened()) return 0;
+ return m_nNumberOfBlocks * NUM_VAG_LINES_IN_BLOCK * VAG_SAMPLES_IN_LINE;
+ }
+
+ uint32 GetSampleRate()
+ {
+ return m_nSampleRate;
+ }
+
+ uint32 GetChannels()
+ {
+ return m_nChannels;
+ }
+
+ void Seek(uint32 milliseconds)
+ {
+ if (!IsOpened()) return;
+ uint32 samples = ms2samples(milliseconds);
+
+ // find the block of our sample
+ uint32 block = samples / NUM_VAG_SAMPLES_IN_BLOCK;
+ if (block > m_nNumberOfBlocks)
+ {
+ samples = 0;
+ block = 0;
+ }
+ if (block != m_CurrentBlock)
+ m_bBlockRead = false;
+
+ // find a line of our sample within our block
+ uint32 remainingSamples = samples - block * NUM_VAG_SAMPLES_IN_BLOCK;
+ uint32 newLine = remainingSamples / VAG_SAMPLES_IN_LINE / VAG_LINE_SIZE;
+
+ if (m_CurrentBlock != block || m_LineInBlock != newLine)
+ {
+ m_CurrentBlock = block;
+ m_LineInBlock = newLine;
+ for (uint32 i = 0; i < GetChannels(); i++)
+ m_pVagDecoders[i].ResetState();
+ }
+
+ }
+
+ uint32 Tell()
+ {
+ if (!IsOpened()) return 0;
+ uint32 pos = (m_CurrentBlock * NUM_VAG_LINES_IN_BLOCK + m_LineInBlock) * VAG_SAMPLES_IN_LINE;
+ return samples2ms(pos);
+ }
+
+ uint32 Decode(void* buffer)
+ {
+ if (!IsOpened()) return 0;
+
+ if (m_CurrentBlock >= m_nNumberOfBlocks) return 0;
+
+ // cache current ADPCM block
+ if (!m_bBlockRead)
+ ReadBlock(m_CurrentBlock);
+
+ // trim the buffer size if we're at the end of our file
+ int numberOfRequiredLines = GetBufferSamples() / m_nChannels / VAG_SAMPLES_IN_LINE;
+ int numberOfRemainingLines = (m_nNumberOfBlocks - m_CurrentBlock) * NUM_VAG_LINES_IN_BLOCK - m_LineInBlock;
+ int bufSizePerChannel = Min(numberOfRequiredLines, numberOfRemainingLines) * VAG_SAMPLES_IN_LINE * GetSampleSize();
+
+ // calculate the pointers to individual channel buffers
+ for (uint32 i = 0; i < m_nChannels; i++)
+ m_ppPcmBuffers[i] = (int16*)((int8*)buffer + bufSizePerChannel * i);
+
+ int size = 0;
+ while (size < bufSizePerChannel)
+ {
+ // decode the VAG lines
+ for (uint32 i = 0; i < m_nChannels; i++)
+ {
+ m_pVagDecoders[i].Decode(m_ppVagBuffers[i] + m_LineInBlock * VAG_LINE_SIZE, m_ppPcmBuffers[i], VAG_LINE_SIZE);
+ m_ppPcmBuffers[i] += VAG_SAMPLES_IN_LINE;
+ }
+ size += VAG_SAMPLES_IN_LINE * GetSampleSize();
+ m_LineInBlock++;
+
+ // block is over, read the next block
+ if (m_LineInBlock >= NUM_VAG_LINES_IN_BLOCK)
+ {
+ m_CurrentBlock++;
+ if (m_CurrentBlock >= m_nNumberOfBlocks) // end of file
+ break;
+ m_LineInBlock = 0;
+ ReadBlock();
+ }
+ }
+
+ return bufSizePerChannel * m_nChannels;
+ }
+};
+#ifdef AUDIO_OAL_USE_OPUS
class COpusFile : public IDecoder
{
OggOpusFile *m_FileH;
@@ -265,6 +894,9 @@ public:
if (size < 0)
return 0;
+ if (GetChannels() == 2)
+ SortStereoBuffer.SortStereo(buffer, size * m_nChannels * GetSampleSize());
+
return size * m_nChannels * GetSampleSize();
}
};
@@ -272,20 +904,20 @@ public:
void CStream::Initialise()
{
-#ifndef AUDIO_OPUS
+#ifdef AUDIO_OAL_USE_MPG123
mpg123_init();
#endif
}
void CStream::Terminate()
{
-#ifndef AUDIO_OPUS
+#ifdef AUDIO_OAL_USE_MPG123
mpg123_exit();
#endif
}
-CStream::CStream(char *filename, ALuint &source, ALuint (&buffers)[NUM_STREAMBUFFERS]) :
- m_alSource(source),
+CStream::CStream(char *filename, ALuint *sources, ALuint (&buffers)[NUM_STREAMBUFFERS], uint32 overrideSampleRate) :
+ m_pAlSources(sources),
m_alBuffers(buffers),
m_pBuffer(nil),
m_bPaused(false),
@@ -294,7 +926,8 @@ CStream::CStream(char *filename, ALuint &source, ALuint (&buffers)[NUM_STREAMBUF
m_bReset(false),
m_nVolume(0),
m_nPan(0),
- m_nPosBeforeReset(0)
+ m_nPosBeforeReset(0),
+ m_nLoopCount(1)
{
// Be case-insensitive on linux (from https://github.com/OneSadCookie/fcaseopen/)
@@ -312,13 +945,20 @@ CStream::CStream(char *filename, ALuint &source, ALuint (&buffers)[NUM_STREAMBUF
DEV("Stream %s\n", m_aFilename);
-#ifndef AUDIO_OPUS
- if (!strcasecmp(&m_aFilename[strlen(m_aFilename) - strlen(".mp3")], ".mp3"))
- m_pSoundFile = new CMP3File(m_aFilename);
- else if (!strcasecmp(&m_aFilename[strlen(m_aFilename) - strlen(".wav")], ".wav"))
+ if (!strcasecmp(&m_aFilename[strlen(m_aFilename) - strlen(".wav")], ".wav"))
+#ifdef AUDIO_OAL_USE_SNDFILE
m_pSoundFile = new CSndFile(m_aFilename);
#else
- if (!strcasecmp(&m_aFilename[strlen(m_aFilename) - strlen(".opus")], ".opus"))
+ m_pSoundFile = new CWavFile(m_aFilename);
+#endif
+#ifdef AUDIO_OAL_USE_MPG123
+ else if (!strcasecmp(&m_aFilename[strlen(m_aFilename) - strlen(".mp3")], ".mp3"))
+ m_pSoundFile = new CMP3File(m_aFilename);
+#endif
+ else if (!strcasecmp(&m_aFilename[strlen(m_aFilename) - strlen(".vb")], ".VB"))
+ m_pSoundFile = new CVbFile(m_aFilename, overrideSampleRate);
+#ifdef AUDIO_OAL_USE_OPUS
+ else if (!strcasecmp(&m_aFilename[strlen(m_aFilename) - strlen(".opus")], ".opus"))
m_pSoundFile = new COpusFile(m_aFilename);
#endif
else
@@ -366,7 +1006,7 @@ void CStream::Delete()
bool CStream::HasSource()
{
- return m_alSource != AL_NONE;
+ return (m_pAlSources[0] != AL_NONE) && (m_pAlSources[1] != AL_NONE);
}
bool CStream::IsOpened()
@@ -380,9 +1020,10 @@ bool CStream::IsPlaying()
if ( !m_bPaused )
{
- ALint sourceState;
- alGetSourcei(m_alSource, AL_SOURCE_STATE, &sourceState);
- if ( m_bActive || sourceState == AL_PLAYING )
+ ALint sourceState[2];
+ alGetSourcei(m_pAlSources[0], AL_SOURCE_STATE, &sourceState[0]);
+ alGetSourcei(m_pAlSources[1], AL_SOURCE_STATE, &sourceState[1]);
+ if (sourceState[0] == AL_PLAYING || sourceState[1] == AL_PLAYING)
return true;
}
@@ -393,9 +1034,12 @@ void CStream::Pause()
{
if ( !HasSource() ) return;
ALint sourceState = AL_PAUSED;
- alGetSourcei(m_alSource, AL_SOURCE_STATE, &sourceState);
- if (sourceState != AL_PAUSED )
- alSourcePause(m_alSource);
+ alGetSourcei(m_pAlSources[0], AL_SOURCE_STATE, &sourceState);
+ if (sourceState != AL_PAUSED)
+ alSourcePause(m_pAlSources[0]);
+ alGetSourcei(m_pAlSources[1], AL_SOURCE_STATE, &sourceState);
+ if (sourceState != AL_PAUSED)
+ alSourcePause(m_pAlSources[1]);
}
void CStream::SetPause(bool bPause)
@@ -417,19 +1061,21 @@ void CStream::SetPause(bool bPause)
void CStream::SetPitch(float pitch)
{
if ( !HasSource() ) return;
- alSourcef(m_alSource, AL_PITCH, pitch);
+ alSourcef(m_pAlSources[0], AL_PITCH, pitch);
+ alSourcef(m_pAlSources[1], AL_PITCH, pitch);
}
void CStream::SetGain(float gain)
{
if ( !HasSource() ) return;
- alSourcef(m_alSource, AL_GAIN, gain);
+ alSourcef(m_pAlSources[0], AL_GAIN, gain);
+ alSourcef(m_pAlSources[1], AL_GAIN, gain);
}
-void CStream::SetPosition(float x, float y, float z)
+void CStream::SetPosition(int i, float x, float y, float z)
{
if ( !HasSource() ) return;
- alSource3f(m_alSource, AL_POSITION, x, y, z);
+ alSource3f(m_pAlSources[i], AL_POSITION, x, y, z);
}
void CStream::SetVolume(uint32 nVol)
@@ -440,8 +1086,13 @@ void CStream::SetVolume(uint32 nVol)
void CStream::SetPan(uint8 nPan)
{
+ m_nPan = clamp((int8)nPan - 63, 0, 63);
+ SetPosition(0, (m_nPan - 63) / 64.0f, 0.0f, Sqrt(1.0f - SQR((m_nPan - 63) / 64.0f)));
+
+ m_nPan = clamp((int8)nPan + 64, 64, 127);
+ SetPosition(1, (m_nPan - 63) / 64.0f, 0.0f, Sqrt(1.0f - SQR((m_nPan - 63) / 64.0f)));
+
m_nPan = nPan;
- SetPosition((nPan - 63)/64.0f, 0.0f, Sqrt(1.0f-SQR((nPan-63)/64.0f)));
}
void CStream::SetPosMS(uint32 nPos)
@@ -458,10 +1109,10 @@ uint32 CStream::GetPosMS()
ALint offset;
//alGetSourcei(m_alSource, AL_SAMPLE_OFFSET, &offset);
- alGetSourcei(m_alSource, AL_BYTE_OFFSET, &offset);
+ alGetSourcei(m_pAlSources[0], AL_BYTE_OFFSET, &offset);
return m_pSoundFile->Tell()
- - m_pSoundFile->samples2ms(m_pSoundFile->GetBufferSamples() * (NUM_STREAMBUFFERS-1)) / m_pSoundFile->GetChannels()
+ - m_pSoundFile->samples2ms(m_pSoundFile->GetBufferSamples() * (NUM_STREAMBUFFERS/2-1)) / m_pSoundFile->GetChannels()
+ m_pSoundFile->samples2ms(offset/m_pSoundFile->GetSampleSize()) / m_pSoundFile->GetChannels();
}
@@ -471,33 +1122,41 @@ uint32 CStream::GetLengthMS()
return m_pSoundFile->GetLength();
}
-bool CStream::FillBuffer(ALuint alBuffer)
+bool CStream::FillBuffer(ALuint *alBuffer)
{
if ( !HasSource() )
return false;
if ( !IsOpened() )
return false;
- if ( !(alBuffer != AL_NONE && alIsBuffer(alBuffer)) )
+ if ( !(alBuffer[0] != AL_NONE && alIsBuffer(alBuffer[0])) )
+ return false;
+ if ( !(alBuffer[1] != AL_NONE && alIsBuffer(alBuffer[1])) )
return false;
uint32 size = m_pSoundFile->Decode(m_pBuffer);
if( size == 0 )
return false;
+
+ uint32 channelSize = size / m_pSoundFile->GetChannels();
- alBufferData(alBuffer, m_pSoundFile->GetChannels() == 1 ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16,
- m_pBuffer, size, m_pSoundFile->GetSampleRate());
-
+ alBufferData(alBuffer[0], AL_FORMAT_MONO16, m_pBuffer, channelSize, m_pSoundFile->GetSampleRate());
+ // TODO: use just one buffer if we play mono
+ if (m_pSoundFile->GetChannels() == 1)
+ alBufferData(alBuffer[1], AL_FORMAT_MONO16, m_pBuffer, channelSize, m_pSoundFile->GetSampleRate());
+ else
+ alBufferData(alBuffer[1], AL_FORMAT_MONO16, (uint8*)m_pBuffer + channelSize, channelSize, m_pSoundFile->GetSampleRate());
return true;
}
int32 CStream::FillBuffers()
{
int32 i = 0;
- for ( i = 0; i < NUM_STREAMBUFFERS; i++ )
+ for ( i = 0; i < NUM_STREAMBUFFERS/2; i++ )
{
- if ( !FillBuffer(m_alBuffers[i]) )
+ if ( !FillBuffer(&m_alBuffers[i*2]) )
break;
- alSourceQueueBuffers(m_alSource, 1, &m_alBuffers[i]);
+ alSourceQueueBuffers(m_pAlSources[0], 1, &m_alBuffers[i*2]);
+ alSourceQueueBuffers(m_pAlSources[1], 1, &m_alBuffers[i*2+1]);
}
return i;
@@ -506,21 +1165,25 @@ int32 CStream::FillBuffers()
void CStream::ClearBuffers()
{
if ( !HasSource() ) return;
-
- ALint buffersQueued;
- alGetSourcei(m_alSource, AL_BUFFERS_QUEUED, &buffersQueued);
+
+ ALint buffersQueued[2];
+ alGetSourcei(m_pAlSources[0], AL_BUFFERS_QUEUED, &buffersQueued[0]);
+ alGetSourcei(m_pAlSources[1], AL_BUFFERS_QUEUED, &buffersQueued[1]);
ALuint value;
- while (buffersQueued--)
- alSourceUnqueueBuffers(m_alSource, 1, &value);
+ while (buffersQueued[0]--)
+ alSourceUnqueueBuffers(m_pAlSources[0], 1, &value);
+ while (buffersQueued[1]--)
+ alSourceUnqueueBuffers(m_pAlSources[1], 1, &value);
}
bool CStream::Setup()
{
if ( IsOpened() )
{
+ alSourcei(m_pAlSources[0], AL_LOOPING, AL_FALSE);
+ alSourcei(m_pAlSources[1], AL_LOOPING, AL_FALSE);
m_pSoundFile->Seek(0);
- alSourcei(m_alSource, AL_SOURCE_RELATIVE, AL_TRUE);
//SetPosition(0.0f, 0.0f, 0.0f);
SetPitch(1.0f);
//SetPan(m_nPan);
@@ -530,23 +1193,42 @@ bool CStream::Setup()
return IsOpened();
}
+void CStream::SetLoopCount(int32 count)
+{
+ if ( !HasSource() ) return;
+
+ m_nLoopCount = count;
+}
+
void CStream::SetPlay(bool state)
{
if ( !HasSource() ) return;
if ( state )
{
ALint sourceState = AL_PLAYING;
- alGetSourcei(m_alSource, AL_SOURCE_STATE, &sourceState);
+ alGetSourcei(m_pAlSources[0], AL_SOURCE_STATE, &sourceState);
if (sourceState != AL_PLAYING )
- alSourcePlay(m_alSource);
+ alSourcePlay(m_pAlSources[0]);
+
+ sourceState = AL_PLAYING;
+ alGetSourcei(m_pAlSources[1], AL_SOURCE_STATE, &sourceState);
+ if (sourceState != AL_PLAYING)
+ alSourcePlay(m_pAlSources[1]);
+
m_bActive = true;
}
else
{
ALint sourceState = AL_STOPPED;
- alGetSourcei(m_alSource, AL_SOURCE_STATE, &sourceState);
- if (sourceState != AL_STOPPED )
- alSourceStop(m_alSource);
+ alGetSourcei(m_pAlSources[0], AL_SOURCE_STATE, &sourceState);
+ if (sourceState != AL_STOPPED)
+ alSourceStop(m_pAlSources[0]);
+
+ sourceState = AL_STOPPED;
+ alGetSourcei(m_pAlSources[1], AL_SOURCE_STATE, &sourceState);
+ if (sourceState != AL_STOPPED)
+ alSourceStop(m_pAlSources[1]);
+
m_bActive = false;
}
}
@@ -577,36 +1259,59 @@ void CStream::Update()
if ( !m_bPaused )
{
- ALint sourceState;
- ALint buffersProcessed = 0;
-
- alGetSourcei(m_alSource, AL_SOURCE_STATE, &sourceState);
- alGetSourcei(m_alSource, AL_BUFFERS_PROCESSED, &buffersProcessed);
+ ALint totalBuffers[2] = { 0, 0 };
+ ALint buffersProcessed[2] = { 0, 0 };
- ALint looping = AL_FALSE;
- alGetSourcei(m_alSource, AL_LOOPING, &looping);
-
- if ( looping == AL_TRUE )
+ // Relying a lot on left buffer states in here
+
+ do
{
- TRACE("stream set looping");
- alSourcei(m_alSource, AL_LOOPING, AL_TRUE);
- }
+ //alSourcef(m_pAlSources[0], AL_ROLLOFF_FACTOR, 0.0f);
+ alGetSourcei(m_pAlSources[0], AL_BUFFERS_QUEUED, &totalBuffers[0]);
+ alGetSourcei(m_pAlSources[0], AL_BUFFERS_PROCESSED, &buffersProcessed[0]);
+ //alSourcef(m_pAlSources[1], AL_ROLLOFF_FACTOR, 0.0f);
+ alGetSourcei(m_pAlSources[1], AL_BUFFERS_QUEUED, &totalBuffers[1]);
+ alGetSourcei(m_pAlSources[1], AL_BUFFERS_PROCESSED, &buffersProcessed[1]);
+ } while (buffersProcessed[0] != buffersProcessed[1]);
- while( buffersProcessed-- )
+ assert(buffersProcessed[0] == buffersProcessed[1]);
+
+ // Correcting OpenAL concepts here:
+ // AL_BUFFERS_QUEUED = Number of *all* buffers in queue, including processed, processing and pending
+ // AL_BUFFERS_PROCESSED = Index of the buffer being processing right now. Buffers coming after that(have greater index) are pending buffers.
+ // which means: totalBuffers[0] - buffersProcessed[0] = pending buffers
+
+ bool buffersRefilled = false;
+
+ // We should wait queue to be cleared to loop track, because position calculation relies on queue.
+ if (m_nLoopCount != 1 && m_bActive && totalBuffers[0] == 0)
{
- ALuint buffer;
-
- alSourceUnqueueBuffers(m_alSource, 1, &buffer);
-
- if ( m_bActive && FillBuffer(buffer) )
- alSourceQueueBuffers(m_alSource, 1, &buffer);
+ Setup();
+ buffersRefilled = FillBuffers() != 0;
+ if (m_nLoopCount != 0)
+ m_nLoopCount--;
}
-
- if ( sourceState != AL_PLAYING )
+ else
{
- alGetSourcei(m_alSource, AL_BUFFERS_PROCESSED, &buffersProcessed);
- SetPlay(buffersProcessed!=0);
+ while( buffersProcessed[0]-- )
+ {
+ ALuint buffer[2];
+
+ alSourceUnqueueBuffers(m_pAlSources[0], 1, &buffer[0]);
+ alSourceUnqueueBuffers(m_pAlSources[1], 1, &buffer[1]);
+
+ if (m_bActive && FillBuffer(buffer))
+ {
+ buffersRefilled = true;
+ alSourceQueueBuffers(m_pAlSources[0], 1, &buffer[0]);
+ alSourceQueueBuffers(m_pAlSources[1], 1, &buffer[1]);
+ }
+ }
}
+
+ // Two reasons: 1-Source may be starved to audio and stopped itself, 2- We're already waiting it to starve and die for looping track!
+ if (m_bActive && (buffersRefilled || (totalBuffers[1] - buffersProcessed[1] != 0)))
+ SetPlay(true);
}
}
@@ -618,6 +1323,7 @@ void CStream::ProviderInit()
{
SetPan(m_nPan);
SetVolume(m_nVolume);
+ SetLoopCount(m_nLoopCount);
SetPosMS(m_nPosBeforeReset);
if (m_bActive)
FillBuffers();
diff --git a/src/audio/oal/stream.h b/src/audio/oal/stream.h
index 2476abcc..b3e96809 100644
--- a/src/audio/oal/stream.h
+++ b/src/audio/oal/stream.h
@@ -3,7 +3,7 @@
#ifdef AUDIO_OAL
#include <AL/al.h>
-#define NUM_STREAMBUFFERS 4
+#define NUM_STREAMBUFFERS 8
class IDecoder
{
@@ -57,7 +57,7 @@ public:
class CStream
{
char m_aFilename[128];
- ALuint &m_alSource;
+ ALuint *m_pAlSources;
ALuint (&m_alBuffers)[NUM_STREAMBUFFERS];
bool m_bPaused;
@@ -69,24 +69,25 @@ class CStream
uint32 m_nVolume;
uint8 m_nPan;
uint32 m_nPosBeforeReset;
+ int32 m_nLoopCount;
IDecoder *m_pSoundFile;
bool HasSource();
- void SetPosition(float x, float y, float z);
+ void SetPosition(int i, float x, float y, float z);
void SetPitch(float pitch);
void SetGain(float gain);
void Pause();
void SetPlay(bool state);
- bool FillBuffer(ALuint alBuffer);
+ bool FillBuffer(ALuint *alBuffer);
int32 FillBuffers();
void ClearBuffers();
public:
static void Initialise();
static void Terminate();
- CStream(char *filename, ALuint &source, ALuint (&buffers)[NUM_STREAMBUFFERS]);
+ CStream(char *filename, ALuint *sources, ALuint (&buffers)[NUM_STREAMBUFFERS], uint32 overrideSampleRate = 32000);
~CStream();
void Delete();
@@ -103,6 +104,8 @@ public:
void Start();
void Stop();
void Update(void);
+ void SetLoopCount(int32);
+
void ProviderInit();
void ProviderTerm();
diff --git a/src/audio/sampman.h b/src/audio/sampman.h
index 2284d385..a5f6c7e2 100644
--- a/src/audio/sampman.h
+++ b/src/audio/sampman.h
@@ -1,5 +1,4 @@
#pragma once
-#include "common.h"
#include "AudioSamples.h"
#define MAX_VOLUME 127
@@ -218,7 +217,7 @@ extern uint32 BankStartOffset[MAX_SFX_BANKS];
extern int defaultProvider;
#endif
-#ifdef AUDIO_OPUS
+#if defined(OPUS_AUDIO_PATHS)
static char StreamedNameTable[][25] = {
"AUDIO\\HEAD.OPUS", "AUDIO\\CLASS.OPUS", "AUDIO\\KJAH.OPUS", "AUDIO\\RISE.OPUS", "AUDIO\\LIPS.OPUS", "AUDIO\\GAME.OPUS",
"AUDIO\\MSX.OPUS", "AUDIO\\FLASH.OPUS", "AUDIO\\CHAT.OPUS", "AUDIO\\HEAD.OPUS", "AUDIO\\POLICE.OPUS", "AUDIO\\CITY.OPUS",
@@ -254,9 +253,9 @@ static char StreamedNameTable[][25] = {
"AUDIO\\door_2.OPUS", "AUDIO\\door_3.OPUS", "AUDIO\\door_4.OPUS", "AUDIO\\door_5.OPUS", "AUDIO\\door_6.OPUS", "AUDIO\\t3_a.OPUS",
"AUDIO\\t3_b.OPUS", "AUDIO\\t3_c.OPUS", "AUDIO\\k1_b.OPUS", "AUDIO\\cat1.OPUS"};
#else
+#if defined(PS2_AUDIO_PATHS)
static char StreamedNameTable[][25]=
{
-#ifdef PS2_AUDIO
"AUDIO\\MUSIC\\HEAD.VB",
"AUDIO\\MUSIC\\CLASS.VB",
"AUDIO\\MUSIC\\KJAH.VB",
@@ -353,6 +352,8 @@ static char StreamedNameTable[][25]=
"AUDIO\\MUSIC\\MISCOM.VB",
"AUDIO\\MUSIC\\END.VB",
#else
+static char StreamedNameTable[][25] =
+{
"AUDIO\\HEAD.WAV",
"AUDIO\\CLASS.WAV",
"AUDIO\\KJAH.WAV",
diff --git a/src/audio/sampman_miles.cpp b/src/audio/sampman_miles.cpp
index 185e08d6..9b601d52 100644
--- a/src/audio/sampman_miles.cpp
+++ b/src/audio/sampman_miles.cpp
@@ -1,8 +1,7 @@
#include "common.h"
#ifdef AUDIO_MSS
-#include <windows.h>
-#include <shobjidl.h>
+#include <shlobj.h>
#include <shlguid.h>
#include <time.h>
@@ -65,7 +64,7 @@ uint32 _CurMP3Index;
int32 _CurMP3Pos;
bool _bIsMp3Active;
-#if defined(GTA3_1_1_PATCH) || defined(GTA3_STEAM_PATCH) || defined(NO_CDCHECK)
+#if GTA_VERSION >= GTA3_PC_11 || defined(NO_CDCHECK)
bool _bUseHDDAudio;
char _aHDDPath[MAX_PATH];
#endif
@@ -1043,7 +1042,7 @@ cSampleManager::Initialise(void)
if ( !m_bInitialised )
{
-#if !defined(GTA3_STEAM_PATCH) && !defined(NO_CDCHECK)
+#if GTA_VERSION < GTA3_PC_STEAM && !defined(NO_CDCHECK)
FrontEndMenuManager.WaitForUserCD();
if ( FrontEndMenuManager.m_bQuitGameNoCD )
{
@@ -1060,7 +1059,7 @@ cSampleManager::Initialise(void)
}
}
-#if defined(GTA3_1_1_PATCH) || defined(GTA3_STEAM_PATCH) || defined(NO_CDCHECK)
+#if GTA_VERSION >= GTA3_PC_11 || defined(NO_CDCHECK)
// hddaudio
/**
Option for user to play audio files directly from hard disk.
@@ -1297,17 +1296,17 @@ cSampleManager::Terminate(void)
bool
cSampleManager::CheckForAnAudioFileOnCD(void)
{
-#if !defined(GTA3_STEAM_PATCH) && !defined(NO_CDCHECK)
+#if GTA_VERSION < GTA3_PC_STEAM && !defined(NO_CDCHECK)
char filepath[MAX_PATH];
-#if defined(GTA3_1_1_PATCH)
+#if GTA_VERSION >= GTA3_PC_11
if (_bUseHDDAudio)
strcpy(filepath, _aHDDPath);
else
strcpy(filepath, m_szCDRomRootPath);
#else
strcpy(filepath, m_szCDRomRootPath);
-#endif // #if defined(GTA3_1_1_PATCH)
+#endif // #if GTA_VERSION >= GTA3_PC_11
strcat(filepath, StreamedNameTable[AudioManager.GetRandomNumber(1) % TOTAL_STREAMED_SOUNDS]);
@@ -1324,13 +1323,13 @@ cSampleManager::CheckForAnAudioFileOnCD(void)
#else
return true;
-#endif // #if !defined(GTA3_STEAM_PATCH) && !defined(NO_CDCHECK)
+#endif // #if GTA_VERSION < GTA3_PC_STEAM && !defined(NO_CDCHECK)
}
char
cSampleManager::GetCDAudioDriveLetter(void)
{
-#if defined(GTA3_1_1_PATCH) || defined(GTA3_STEAM_PATCH) || defined(NO_CDCHECK)
+#if GTA_VERSION >= GTA3_PC_11 || defined(NO_CDCHECK)
if (_bUseHDDAudio)
{
if ( strlen(_aHDDPath) != 0 )
@@ -1515,7 +1514,7 @@ cSampleManager::LoadPedComment(uint32 nComment)
case MUSICMODE_FRONTEND:
{
- if ( MusicManager.GetCurrentTrack() == STREAMED_SOUND_GAME_COMPLETED )
+ if ( MusicManager.GetNextTrack() == STREAMED_SOUND_GAME_COMPLETED )
return false;
break;
@@ -1754,8 +1753,8 @@ cSampleManager::SetChannelEmittingVolume(uint32 nChannel, uint32 nVolume)
// 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 )
+ && MusicManager.GetNextTrack() != STREAMED_SOUND_NEWS_INTRO
+ && MusicManager.GetNextTrack() != STREAMED_SOUND_CUTSCENE_SAL4_BDBD )
{
nChannelVolume[nChannel] >>= 2;
}
@@ -1793,8 +1792,8 @@ cSampleManager::SetChannelVolume(uint32 nChannel, uint32 nVolume)
// 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 )
+ && MusicManager.GetNextTrack() != STREAMED_SOUND_NEWS_INTRO
+ && MusicManager.GetNextTrack() != STREAMED_SOUND_CUTSCENE_SAL4_BDBD )
{
nChannelVolume[nChannel] >>= 2;
}
diff --git a/src/audio/sampman_oal.cpp b/src/audio/sampman_oal.cpp
index eec5ca5f..9365c7dd 100644
--- a/src/audio/sampman_oal.cpp
+++ b/src/audio/sampman_oal.cpp
@@ -1,17 +1,11 @@
//#define JUICY_OAL
#ifdef AUDIO_OAL
-#include "sampman.h"
-
#include <time.h>
#include "eax.h"
#include "eax-util.h"
-#define WITHWINDOWS
-#include "common.h"
-#include "crossplatform.h"
-
#ifdef _WIN32
#include <io.h>
#include <AL/al.h>
@@ -19,8 +13,22 @@
#include <AL/alext.h>
#include <AL/efx.h>
#include <AL/efx-presets.h>
+
+#pragma comment(lib, "OpenAL32.lib")
+
+// for user MP3s
+#include <direct.h>
+#include <shlobj.h>
+#include <shlguid.h>
+#else
+#define _getcwd getcwd
#endif
+#include "common.h"
+#include "crossplatform.h"
+
+#include "sampman.h"
+
#include "oal/oal_utils.h"
#include "oal/aldlist.h"
#include "oal/channel.h"
@@ -30,26 +38,12 @@
#include "MusicManager.h"
#include "Frontend.h"
#include "Timer.h"
-#ifdef AUDIO_OPUS
+#ifdef AUDIO_OAL_USE_OPUS
#include <opusfile.h>
#endif
//TODO: fix eax3 reverb
//TODO: max channels
-//TODO: loop count
-
-#ifdef _WIN32
-#pragma comment( lib, "OpenAL32.lib" )
-#endif
-
-// for user MP3s
-#ifdef _WIN32
-#include <direct.h>
-#include <shobjidl.h>
-#include <shlguid.h>
-#else
-#define _getcwd getcwd
-#endif
cSampleManager SampleManager;
bool _bSampmanInitialised = false;
@@ -83,7 +77,7 @@ char SampleBankDescFilename[] = "audio/sfx.SDT";
char SampleBankDataFilename[] = "audio/sfx.RAW";
FILE *fpSampleDescHandle;
-#ifdef AUDIO_OPUS
+#ifdef OPUS_SFX
OggOpusFile *fpSampleDataHandle;
#else
FILE *fpSampleDataHandle;
@@ -102,7 +96,7 @@ CChannel aChannel[MAXCHANNELS+MAX2DCHANNELS];
uint8 nChannelVolume[MAXCHANNELS+MAX2DCHANNELS];
uint32 nStreamLength[TOTAL_STREAMED_SOUNDS];
-ALuint ALStreamSources[MAX_STREAMS];
+ALuint ALStreamSources[MAX_STREAMS][2];
ALuint ALStreamBuffers[MAX_STREAMS][NUM_STREAMBUFFERS];
struct tMP3Entry
@@ -122,7 +116,6 @@ char _mp3DirectoryPath[MAX_PATH];
CStream *aStream[MAX_STREAMS];
uint8 nStreamPan [MAX_STREAMS];
uint8 nStreamVolume[MAX_STREAMS];
-uint8 nStreamLoopedFlag[MAX_STREAMS];
uint32 _CurMP3Index;
int32 _CurMP3Pos;
bool _bIsMp3Active;
@@ -245,9 +238,9 @@ release_existing()
if (stream)
stream->ProviderTerm();
- alDeleteSources(1, &ALStreamSources[i]);
alDeleteBuffers(NUM_STREAMBUFFERS, ALStreamBuffers[i]);
}
+ alDeleteSources(MAX_STREAMS*2, ALStreamSources[0]);
CChannel::DestroyChannels();
@@ -287,7 +280,10 @@ set_new_provider(int index)
//TODO:
_maxSamples = MAXCHANNELS;
- ALCint attr[] = {ALC_FREQUENCY,MAX_FREQ,0};
+ ALCint attr[] = {ALC_FREQUENCY,MAX_FREQ,
+ ALC_MONO_SOURCES, MAX_STREAMS * 2 + MAXCHANNELS,
+ 0,
+ };
ALDevice = alcOpenDevice(providers[index].id);
ASSERT(ALDevice != NULL);
@@ -319,11 +315,17 @@ set_new_provider(int index)
alGenAuxiliaryEffectSlots(1, &ALEffectSlot);
alGenEffects(1, &ALEffect);
}
-
+
+ alGenSources(MAX_STREAMS*2, ALStreamSources[0]);
for ( int32 i = 0; i < MAX_STREAMS; i++ )
{
- alGenSources(1, &ALStreamSources[i]);
- alGenBuffers(NUM_STREAMBUFFERS, ALStreamBuffers[i]);
+ alGenBuffers(NUM_STREAMBUFFERS, ALStreamBuffers[i]);
+ alSourcei(ALStreamSources[i][0], AL_SOURCE_RELATIVE, AL_TRUE);
+ alSource3f(ALStreamSources[i][0], AL_POSITION, 0.0f, 0.0f, 0.0f);
+ alSourcef(ALStreamSources[i][0], AL_GAIN, 1.0f);
+ alSourcei(ALStreamSources[i][1], AL_SOURCE_RELATIVE, AL_TRUE);
+ alSource3f(ALStreamSources[i][1], AL_POSITION, 0.0f, 0.0f, 0.0f);
+ alSourcef(ALStreamSources[i][1], AL_GAIN, 1.0f);
CStream *stream = aStream[i];
if (stream)
@@ -384,6 +386,12 @@ set_new_provider(int index)
return false;
}
+static bool
+IsThisTrackAt16KHz(uint32 track)
+{
+ return track == STREAMED_SOUND_RADIO_CHAT;
+}
+
cSampleManager::cSampleManager(void)
{
;
@@ -956,33 +964,37 @@ cSampleManager::Initialise(void)
#ifdef AUDIO_CACHE
FILE *cacheFile = fcaseopen("audio\\sound.cache", "rb");
if (cacheFile) {
+ debug("Loadind audio cache (If game crashes around here, then your cache is corrupted, remove audio/sound.cache)\n");
fread(nStreamLength, sizeof(uint32), TOTAL_STREAMED_SOUNDS, cacheFile);
fclose(cacheFile);
} else
-#endif
{
-
- for ( int32 i = 0; i < TOTAL_STREAMED_SOUNDS; i++ )
- {
- aStream[0] = new CStream(StreamedNameTable[i], ALStreamSources[0], ALStreamBuffers[0]);
-
- if ( aStream[0] && aStream[0]->IsOpened() )
- {
+ debug("Cannot load audio cache\n");
+#endif
+
+ for(int32 i = 0; i < TOTAL_STREAMED_SOUNDS; i++) {
+ aStream[0] = new CStream(StreamedNameTable[i], ALStreamSources[0], ALStreamBuffers[0], IsThisTrackAt16KHz(i) ? 16000 : 32000);
+
+ if(aStream[0] && aStream[0]->IsOpened()) {
uint32 tatalms = aStream[0]->GetLengthMS();
delete aStream[0];
aStream[0] = NULL;
-
+
nStreamLength[i] = tatalms;
- }
- else
+ } else
USERERROR("Can't open '%s'\n", StreamedNameTable[i]);
}
#ifdef AUDIO_CACHE
cacheFile = fcaseopen("audio\\sound.cache", "wb");
- fwrite(nStreamLength, sizeof(uint32), TOTAL_STREAMED_SOUNDS, cacheFile);
- fclose(cacheFile);
-#endif
+ if(cacheFile) {
+ debug("Saving audio cache\n");
+ fwrite(nStreamLength, sizeof(uint32), TOTAL_STREAMED_SOUNDS, cacheFile);
+ fclose(cacheFile);
+ } else {
+ debug("Cannot save audio cache\n");
+ }
}
+#endif
{
if ( !InitialiseSampleBanks() )
@@ -1199,7 +1211,7 @@ cSampleManager::LoadSampleBank(uint8 nBank)
return false;
}
-#ifdef AUDIO_OPUS
+#ifdef OPUS_SFX
int samplesRead = 0;
int samplesSize = nSampleBankSize[nBank] / 2;
op_pcm_seek(fpSampleDataHandle, 0);
@@ -1304,7 +1316,7 @@ cSampleManager::LoadPedComment(uint32 nComment)
case MUSICMODE_FRONTEND:
{
- if ( MusicManager.GetCurrentTrack() == STREAMED_SOUND_GAME_COMPLETED )
+ if ( MusicManager.GetNextTrack() == STREAMED_SOUND_GAME_COMPLETED )
return false;
break;
@@ -1312,7 +1324,7 @@ cSampleManager::LoadPedComment(uint32 nComment)
}
}
-#ifdef AUDIO_OPUS
+#ifdef OPUS_SFX
int samplesRead = 0;
int samplesSize = m_aSamples[nComment].nSize / 2;
op_pcm_seek(fpSampleDataHandle, m_aSamples[nComment].nOffset / 2);
@@ -1519,8 +1531,8 @@ cSampleManager::SetChannelEmittingVolume(uint32 nChannel, uint32 nVolume)
// reduce channel volume when JB.MP3 or S4_BDBD.MP3 playing
if ( MusicManager.GetMusicMode() == MUSICMODE_CUTSCENE
- && MusicManager.GetCurrentTrack() != STREAMED_SOUND_NEWS_INTRO
- && MusicManager.GetCurrentTrack() != STREAMED_SOUND_CUTSCENE_SAL4_BDBD )
+ && MusicManager.GetNextTrack() != STREAMED_SOUND_NEWS_INTRO
+ && MusicManager.GetNextTrack() != STREAMED_SOUND_CUTSCENE_SAL4_BDBD )
{
nChannelVolume[nChannel] = vol / 4;
}
@@ -1561,8 +1573,8 @@ cSampleManager::SetChannelVolume(uint32 nChannel, uint32 nVolume)
// 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 )
+ && MusicManager.GetNextTrack() != STREAMED_SOUND_NEWS_INTRO
+ && MusicManager.GetNextTrack() != STREAMED_SOUND_CUTSCENE_SAL4_BDBD )
{
nChannelVolume[nChannel] = vol / 4;
}
@@ -1648,11 +1660,11 @@ cSampleManager::PreloadStreamedFile(uint8 nFile, uint8 nStream)
strcpy(filename, StreamedNameTable[nFile]);
- CStream *stream = new CStream(filename, ALStreamSources[nStream], ALStreamBuffers[nStream]);
+ CStream *stream = new CStream(filename, ALStreamSources[nStream], ALStreamBuffers[nStream], IsThisTrackAt16KHz(nFile) ? 16000 : 32000);
ASSERT(stream != NULL);
aStream[nStream] = stream;
- if ( !stream->IsOpened() )
+ if ( !stream->Setup() )
{
delete stream;
aStream[nStream] = NULL;
@@ -1682,7 +1694,7 @@ cSampleManager::StartPreloadedStreamedFile(uint8 nStream)
if ( stream )
{
- if ( stream->Setup() )
+ if ( stream->IsOpened() )
{
stream->Start();
}
@@ -1723,18 +1735,16 @@ cSampleManager::StartStreamedFile(uint8 nFile, uint32 nPos, uint8 nStream)
nFile = 0;
strcat(filename, StreamedNameTable[nFile]);
- CStream* stream = new CStream(filename, ALStreamSources[nStream], ALStreamBuffers[nStream]);
+ CStream* stream = new CStream(filename, ALStreamSources[nStream], ALStreamBuffers[nStream], IsThisTrackAt16KHz(nFile) ? 16000 : 32000);
ASSERT(stream != NULL);
aStream[nStream] = stream;
- if (stream->IsOpened()) {
- if (stream->Setup()) {
- if (position != 0)
- stream->SetPosMS(position);
+ if (stream->Setup()) {
+ if (position != 0)
+ stream->SetPosMS(position);
- stream->Start();
- }
+ stream->Start();
return true;
} else {
@@ -1747,18 +1757,16 @@ cSampleManager::StartStreamedFile(uint8 nFile, uint32 nPos, uint8 nStream)
}
if (mp3->pLinkPath != NULL)
- aStream[nStream] = new CStream(mp3->pLinkPath, ALStreamSources[nStream], ALStreamBuffers[nStream]);
+ aStream[nStream] = new CStream(mp3->pLinkPath, ALStreamSources[nStream], ALStreamBuffers[nStream], IsThisTrackAt16KHz(nFile) ? 16000 : 32000);
else {
strcpy(filename, _mp3DirectoryPath);
strcat(filename, mp3->aFilename);
- aStream[nStream] = new CStream(filename, ALStreamSources[nStream], ALStreamBuffers[nStream]);
+ aStream[nStream] = new CStream(filename, ALStreamSources[nStream], ALStreamBuffers[nStream], IsThisTrackAt16KHz(nFile) ? 16000 : 32000);
}
- if (aStream[nStream]->IsOpened()) {
- if (aStream[nStream]->Setup()) {
- aStream[nStream]->Start();
- }
+ if (aStream[nStream]->Setup()) {
+ aStream[nStream]->Start();
return true;
} else {
@@ -1779,18 +1787,16 @@ cSampleManager::StartStreamedFile(uint8 nFile, uint32 nPos, uint8 nStream)
{
nFile = 0;
strcat(filename, StreamedNameTable[nFile]);
- CStream* stream = new CStream(filename, ALStreamSources[nStream], ALStreamBuffers[nStream]);
+ CStream* stream = new CStream(filename, ALStreamSources[nStream], ALStreamBuffers[nStream], IsThisTrackAt16KHz(nFile) ? 16000 : 32000);
ASSERT(stream != NULL);
aStream[nStream] = stream;
- if (stream->IsOpened()) {
- if (stream->Setup()) {
- if (position != 0)
- stream->SetPosMS(position);
+ if (stream->Setup()) {
+ if (position != 0)
+ stream->SetPosMS(position);
- stream->Start();
- }
+ stream->Start();
return true;
} else {
@@ -1803,7 +1809,7 @@ cSampleManager::StartStreamedFile(uint8 nFile, uint32 nPos, uint8 nStream)
}
if (e->pLinkPath != NULL)
- aStream[nStream] = new CStream(e->pLinkPath, ALStreamSources[nStream], ALStreamBuffers[nStream]);
+ aStream[nStream] = new CStream(e->pLinkPath, ALStreamSources[nStream], ALStreamBuffers[nStream], IsThisTrackAt16KHz(nFile) ? 16000 : 32000);
else {
strcpy(filename, _mp3DirectoryPath);
strcat(filename, e->aFilename);
@@ -1811,13 +1817,11 @@ cSampleManager::StartStreamedFile(uint8 nFile, uint32 nPos, uint8 nStream)
aStream[nStream] = new CStream(filename, ALStreamSources[nStream], ALStreamBuffers[nStream]);
}
- if (aStream[nStream]->IsOpened()) {
- if (aStream[nStream]->Setup()) {
- if (position != 0)
- aStream[nStream]->SetPosMS(position);
+ if (aStream[nStream]->Setup()) {
+ if (position != 0)
+ aStream[nStream]->SetPosMS(position);
- aStream[nStream]->Start();
- }
+ aStream[nStream]->Start();
_bIsMp3Active = true;
return true;
@@ -1836,18 +1840,16 @@ cSampleManager::StartStreamedFile(uint8 nFile, uint32 nPos, uint8 nStream)
strcpy(filename, StreamedNameTable[nFile]);
- CStream *stream = new CStream(filename, ALStreamSources[nStream], ALStreamBuffers[nStream]);
+ CStream *stream = new CStream(filename, ALStreamSources[nStream], ALStreamBuffers[nStream], IsThisTrackAt16KHz(nFile) ? 16000 : 32000);
ASSERT(stream != NULL);
aStream[nStream] = stream;
- if ( stream->IsOpened() ) {
- if ( stream->Setup() ) {
- if (position != 0)
- stream->SetPosMS(position);
+ if ( stream->Setup() ) {
+ if (position != 0)
+ stream->SetPosMS(position);
- stream->Start();
- }
+ stream->Start();
return true;
} else {
@@ -1949,6 +1951,12 @@ cSampleManager::Service(void)
if ( stream )
stream->Update();
}
+ int refCount = CChannel::channelsThatNeedService;
+ for ( int32 i = 0; refCount && i < MAXCHANNELS+MAX2DCHANNELS; i++ )
+ {
+ if ( aChannel[i].Update() )
+ refCount--;
+ }
}
bool
@@ -1959,7 +1967,7 @@ cSampleManager::InitialiseSampleBanks(void)
fpSampleDescHandle = fcaseopen(SampleBankDescFilename, "rb");
if ( fpSampleDescHandle == NULL )
return false;
-#ifndef AUDIO_OPUS
+#ifndef OPUS_SFX
fpSampleDataHandle = fcaseopen(SampleBankDataFilename, "rb");
if ( fpSampleDataHandle == NULL )
{
@@ -1977,7 +1985,7 @@ cSampleManager::InitialiseSampleBanks(void)
fpSampleDataHandle = op_open_file(SampleBankDataFilename, &e);
#endif
fread(m_aSamples, sizeof(tSample), TOTAL_AUDIO_SAMPLES, fpSampleDescHandle);
-#ifdef AUDIO_OPUS
+#ifdef OPUS_SFX
int32 _nSampleDataEndOffset = m_aSamples[TOTAL_AUDIO_SAMPLES - 1].nOffset + m_aSamples[TOTAL_AUDIO_SAMPLES - 1].nSize;
#endif
fclose(fpSampleDescHandle);
diff --git a/src/audio/soundlist.h b/src/audio/soundlist.h
index 225ed56e..4bbc3dde 100644
--- a/src/audio/soundlist.h
+++ b/src/audio/soundlist.h
@@ -1,6 +1,6 @@
#pragma once
-enum eSound : uint16
+enum eSound
{
SOUND_CAR_DOOR_CLOSE_BONNET = 0,
SOUND_CAR_DOOR_CLOSE_BUMPER,
@@ -160,7 +160,7 @@ enum eSound : uint16
SOUND_FRONTEND_MONO,
SOUND_FRONTEND_AUDIO_TEST,
SOUND_FRONTEND_FAIL,
- SOUND_FRONTEND_NO_RADIO,
+ SOUND_FRONTEND_RADIO_TURN_OFF,
SOUND_FRONTEND_RADIO_CHANGE,
SOUND_HUD,
SOUND_AMMUNATION_WELCOME_1,
@@ -173,7 +173,7 @@ enum eSound : uint16
};
-enum eScriptSounds : uint16 {
+enum eScriptSounds {
SCRIPT_SOUND_0 = 0,
SCRIPT_SOUND_1,
SCRIPT_SOUND_2,