summaryrefslogtreecommitdiffstats
path: root/src/audio
diff options
context:
space:
mode:
authorerorcun <erorcunerorcun@hotmail.com.tr>2021-02-08 11:23:19 +0100
committererorcun <erorcunerorcun@hotmail.com.tr>2021-02-08 11:23:19 +0100
commitb464bb7fd43a86264e816e950ccac1d6845b0230 (patch)
tree1070200f94f1f7adf4ae26950011884e1956576d /src/audio
parentUse our synonyms for attack anims again (diff)
parentreorganize shaders; use modulate flag; update librw (diff)
downloadre3-b464bb7fd43a86264e816e950ccac1d6845b0230.tar
re3-b464bb7fd43a86264e816e950ccac1d6845b0230.tar.gz
re3-b464bb7fd43a86264e816e950ccac1d6845b0230.tar.bz2
re3-b464bb7fd43a86264e816e950ccac1d6845b0230.tar.lz
re3-b464bb7fd43a86264e816e950ccac1d6845b0230.tar.xz
re3-b464bb7fd43a86264e816e950ccac1d6845b0230.tar.zst
re3-b464bb7fd43a86264e816e950ccac1d6845b0230.zip
Diffstat (limited to 'src/audio')
-rw-r--r--src/audio/AudioLogic.cpp12
-rw-r--r--src/audio/MusicManager.cpp515
-rw-r--r--src/audio/MusicManager.h26
-rw-r--r--src/audio/audio_enums.h2
-rw-r--r--src/audio/oal/channel.cpp56
-rw-r--r--src/audio/oal/channel.h6
-rw-r--r--src/audio/oal/stream.cpp79
-rw-r--r--src/audio/oal/stream.h3
-rw-r--r--src/audio/sampman_oal.cpp82
-rw-r--r--src/audio/soundlist.h14
10 files changed, 484 insertions, 311 deletions
diff --git a/src/audio/AudioLogic.cpp b/src/audio/AudioLogic.cpp
index ce543f33..c7b26711 100644
--- a/src/audio/AudioLogic.cpp
+++ b/src/audio/AudioLogic.cpp
@@ -8846,7 +8846,7 @@ cAudioManager::ProcessFrontEnd()
break;
case SOUND_PICKUP_BONUS:
case SOUND_FRONTEND_MENU_STARTING:
- case SOUND_HUD_SOUND:
+ case SOUND_HUD:
stereo = true;
m_sQueueSample.m_nSampleIndex = SFX_INFO_LEFT;
center = true;
@@ -8882,11 +8882,11 @@ cAudioManager::ProcessFrontEnd()
case SOUND_CLOCK_TICK:
m_sQueueSample.m_nSampleIndex = SFX_TIMER;
break;
- case SOUND_FRONTEND_NO_RADIO:
- case SOUND_FRONTEND_RADIO_CHANGE:
+ case SOUND_FRONTEND_RADIO_TURN_OFF:
+ case SOUND_FRONTEND_RADIO_TURN_ON:
m_sQueueSample.m_nSampleIndex = SFX_RADIO_CLICK;
break;
- case SOUND_FRONTEND_RADIO_CHANGE_2:
+ case SOUND_FRONTEND_HURRICANE:
m_sQueueSample.m_nSampleIndex = SFX_HURRICANE_MA;
break;
case SOUND_BULLETTRACE_1:
@@ -8937,9 +8937,9 @@ cAudioManager::ProcessFrontEnd()
sample = m_asAudioEntities[m_sQueueSample.m_nEntityIndex].m_awAudioEvent[i];
- if (sample == SOUND_FRONTEND_NO_RADIO)
+ if (sample == SOUND_FRONTEND_RADIO_TURN_OFF)
m_sQueueSample.m_nFrequency = 28509;
- else if (sample == SOUND_FRONTEND_RADIO_CHANGE)
+ else if (sample == SOUND_FRONTEND_RADIO_TURN_ON)
m_sQueueSample.m_nFrequency = 32000;
else if (sample == SOUND_BULLETTRACE_1 || sample == SOUND_BULLETTRACE_2) {
m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(m_sQueueSample.m_nSampleIndex);
diff --git a/src/audio/MusicManager.cpp b/src/audio/MusicManager.cpp
index acfe09c3..d229ef8d 100644
--- a/src/audio/MusicManager.cpp
+++ b/src/audio/MusicManager.cpp
@@ -21,6 +21,10 @@
#include "DMAudio.h"
#include "GenericGameStorage.h"
+#if !defined FIX_BUGS && (defined RADIO_SCROLL_TO_PREV_STATION || defined RADIO_OFF_TEXT)
+static_assert(false, "R*'s radio implementation is quite buggy, RADIO_SCROLL_TO_PREV_STATION and RADIO_OFF_TEXT won't work without FIX_BUGS");
+#endif
+
cMusicManager MusicManager;
int32 gNumRetunePresses;
int32 gRetuneCounter;
@@ -52,7 +56,7 @@ cMusicManager::cMusicManager()
m_nPlayingTrack = NO_TRACK;
m_nUpcomingMusicMode = MUSICMODE_DISABLED;
m_nMusicMode = MUSICMODE_DISABLED;
- field_2 = false;
+ m_bSetNextStation = false;
for (int i = 0; i < NUM_RADIOS; i++)
aListenTimeArray[i] = 0.0f;
@@ -71,27 +75,27 @@ cMusicManager::ResetMusicAfterReload()
float afRadioTime[NUM_RADIOS];
m_bRadioSetByScript = false;
- m_nRadioStation = WILDSTYLE;
+ m_nRadioStationScript = WILDSTYLE;
m_nRadioPosition = -1;
m_nAnnouncement = NO_TRACK;
m_bAnnouncementInProgress = false;
- field_2 = false;
+ m_bSetNextStation = false;
RadioStaticTimer = 0;
gNumRetunePresses = 0;
gRetuneCounter = 0;
m_nFrontendTrack = NO_TRACK;
m_nPlayingTrack = NO_TRACK;
- field_398E = false;
- field_398F = false;
- m_nStreamedTrack = NO_TRACK;
- field_3994 = false;
- field_3995 = false;
- field_3996 = false;
- field_3997 = false;
+ m_FrontendLoopFlag = false;
+ m_bTrackChangeStarted = false;
+ m_nNextTrack = NO_TRACK;
+ m_nNextLoopFlag = false;
+ m_bVerifyNextTrackStartedToPlay = false;
+ m_bGameplayAllowsRadio = false;
+ m_bRadioStreamReady = false;
nFramesSinceCutsceneEnded = -1;
- field_3999 = false;
- field_399A = false;
- field_399C = false;
+ m_bUserResumedGame = false;
+ m_bMusicModeChangeStarted = false;
+ m_bEarlyFrontendTrack = false;
m_nVolumeLatency = 0;
m_nCurrentVolume = 0;
m_nMaxVolume = 0;
@@ -108,7 +112,7 @@ cMusicManager::ResetMusicAfterReload()
for (int i = 0; i < NUM_RADIOS; i++) {
aListenTimeArray[i] = afRadioTime[i];
- uint32 trackPos = GetSavedRadioStationPosition(i);
+ int32 trackPos = GetSavedRadioStationPosition(i);
if (trackPos != -1) {
if (trackPos > m_aTracks[i].m_nLength) {
debug("Radio Track %d saved position is %d, Length is only %d\n", i, trackPos, m_aTracks[i].m_nLength);
@@ -179,7 +183,7 @@ cMusicManager::Initialise()
m_bResetTimers = false;
m_nResetTime = 0;
m_bRadioSetByScript = false;
- m_nRadioStation = WILDSTYLE;
+ m_nRadioStationScript = WILDSTYLE;
m_nRadioPosition = -1;
m_nRadioInCar = NO_TRACK;
gRetuneCounter = 0;
@@ -188,18 +192,18 @@ cMusicManager::Initialise()
m_nPlayingTrack = NO_TRACK;
m_nUpcomingMusicMode = MUSICMODE_DISABLED;
m_nMusicMode = MUSICMODE_DISABLED;
- field_398E = false;
- field_398F = false;
- m_nStreamedTrack = NO_TRACK;
- field_3994 = false;
- field_3995 = false;
- field_3996 = false;
- field_3997 = false;
+ m_FrontendLoopFlag = false;
+ m_bTrackChangeStarted = false;
+ m_nNextTrack = NO_TRACK;
+ m_nNextLoopFlag = false;
+ m_bVerifyNextTrackStartedToPlay = false;
+ m_bGameplayAllowsRadio = false;
+ m_bRadioStreamReady = false;
nFramesSinceCutsceneEnded = -1;
- field_3999 = false;
- field_399A = false;
+ m_bUserResumedGame = false;
+ m_bMusicModeChangeStarted = false;
m_nMusicModeToBeSet = MUSICMODE_DISABLED;
- field_399C = false;
+ m_bEarlyFrontendTrack = false;
m_nVolumeLatency = 0;
m_nCurrentVolume = 0;
m_nMaxVolume = 0;
@@ -227,7 +231,7 @@ cMusicManager::SetRadioChannelByScript(uint32 station, int32 pos)
station = STREAMED_SOUND_CITY_AMBIENT;
if (station <= STREAMED_SOUND_RADIO_POLICE) {
m_bRadioSetByScript = true;
- m_nRadioStation = station;
+ m_nRadioStationScript = station;
m_nRadioPosition = pos == -1 ? -1 : pos % m_aTracks[station].m_nLength;
}
}
@@ -292,7 +296,7 @@ cMusicManager::SetRadioInCar(uint32 station)
void
cMusicManager::RecordRadioStats()
{
- if (m_nPlayingTrack < STREAMED_SOUND_CITY_AMBIENT) {
+ if (m_nPlayingTrack < NUM_RADIOS) {
double time /*Rusty*/ = CTimer::GetTimeInMillisecondsPauseMode();
if (time > m_nLastTrackServiceTime)
aListenTimeArray[m_nPlayingTrack] += time - m_nLastTrackServiceTime;
@@ -321,11 +325,11 @@ cMusicManager::ChangeMusicMode(uint8 mode)
while (SampleManager.IsStreamPlaying(0))
SampleManager.StopStreamedFile(0);
m_nMusicMode = m_nUpcomingMusicMode;
- field_399A = false;
- field_398F = false;
- m_nStreamedTrack = NO_TRACK;
- field_3994 = false;
- field_3995 = false;
+ m_bMusicModeChangeStarted = false;
+ m_bTrackChangeStarted = false;
+ m_nNextTrack = NO_TRACK;
+ m_nNextLoopFlag = false;
+ m_bVerifyNextTrackStartedToPlay = false;
m_nPlayingTrack = NO_TRACK;
m_nFrontendTrack = NO_TRACK;
m_bAnnouncementInProgress = false;
@@ -356,7 +360,7 @@ cMusicManager::Service()
if (!m_bIsInitialised || m_bDisabled) return;
- if (!field_399A)
+ if (!m_bMusicModeChangeStarted)
m_nMusicModeToBeSet = m_nUpcomingMusicMode;
if (m_nMusicModeToBeSet == m_nMusicMode) {
if (!AudioManager.m_nUserPause || AudioManager.m_nPreviousUserPause || m_nMusicMode != MUSICMODE_FRONTEND)
@@ -371,13 +375,13 @@ cMusicManager::Service()
else
m_nMusicMode = MUSICMODE_DISABLED;
} else {
- field_399A = true;
- if (!field_3999 && !AudioManager.m_nUserPause && AudioManager.m_nPreviousUserPause)
- field_3999 = true;
+ m_bMusicModeChangeStarted = true;
+ if (!m_bUserResumedGame && !AudioManager.m_nUserPause && AudioManager.m_nPreviousUserPause)
+ m_bUserResumedGame = true;
if (AudioManager.m_FrameCounter % 4 == 0) {
gNumRetunePresses = 0;
gRetuneCounter = 0;
- field_2 = false;
+ m_bSetNextStation = false;
if (SampleManager.IsStreamPlaying(0)) {
if (m_nPlayingTrack != NO_TRACK && !bRadioStatsRecorded)
{
@@ -390,14 +394,14 @@ cMusicManager::Service()
} else {
bRadioStatsRecorded = false;
m_nMusicMode = m_nMusicModeToBeSet;
- field_399A = false;
- field_398F = false;
- m_nStreamedTrack = NO_TRACK;
- field_3994 = false;
- field_3995 = false;
+ m_bMusicModeChangeStarted = false;
+ m_bTrackChangeStarted = false;
+ m_nNextTrack = NO_TRACK;
+ m_nNextLoopFlag = false;
+ m_bVerifyNextTrackStartedToPlay = false;
m_nPlayingTrack = NO_TRACK;
- if (field_399C)
- field_399C = false;
+ if (m_bEarlyFrontendTrack)
+ m_bEarlyFrontendTrack = false;
else
m_nFrontendTrack = NO_TRACK;
}
@@ -417,19 +421,19 @@ cMusicManager::ServiceFrontEndMode()
g_bAnnouncementReadPosAlready = false;
m_nAnnouncement = NO_TRACK;
m_bAnnouncementInProgress = false;
- m_nStreamedTrack = NO_TRACK;
+ m_nNextTrack = NO_TRACK;
m_nFrontendTrack = NO_TRACK;
m_nPlayingTrack = NO_TRACK;
}
if (AudioManager.m_FrameCounter % 4 != 0) return;
- if (!field_398F && !field_3995) {
- m_nStreamedTrack = m_nFrontendTrack;
- field_3994 = field_398E;
+ if (!m_bTrackChangeStarted && !m_bVerifyNextTrackStartedToPlay) {
+ m_nNextTrack = m_nFrontendTrack;
+ m_nNextLoopFlag = m_FrontendLoopFlag;
}
- if (m_nStreamedTrack == m_nPlayingTrack) {
+ if (m_nNextTrack == m_nPlayingTrack) {
if (SampleManager.IsStreamPlaying(0)) {
if (m_nVolumeLatency > 0) m_nVolumeLatency--;
else {
@@ -444,25 +448,25 @@ cMusicManager::ServiceFrontEndMode()
ChangeMusicMode(MUSICMODE_GAME);
}
} else {
- field_398F = true;
- if (field_3995 || !SampleManager.IsStreamPlaying(0)) {
+ m_bTrackChangeStarted = true;
+ if (m_bVerifyNextTrackStartedToPlay || !SampleManager.IsStreamPlaying(0)) {
bRadioStatsRecorded = false;
- if (SampleManager.IsStreamPlaying(0) || m_nStreamedTrack == NO_TRACK) {
- m_nPlayingTrack = m_nStreamedTrack;
- field_3995 = false;
- field_398F = false;
+ if (SampleManager.IsStreamPlaying(0) || m_nNextTrack == NO_TRACK) {
+ m_nPlayingTrack = m_nNextTrack;
+ m_bVerifyNextTrackStartedToPlay = false;
+ m_bTrackChangeStarted = false;
} else {
- uint32 trackStartPos = (m_nStreamedTrack > STREAMED_SOUND_RADIO_POLICE) ? 0 : GetTrackStartPos(m_nStreamedTrack);
- if (m_nStreamedTrack != NO_TRACK) {
- SampleManager.SetStreamedFileLoopFlag(field_3994, 0);
- SampleManager.StartStreamedFile(m_nStreamedTrack, trackStartPos, 0);
+ uint32 trackStartPos = (m_nNextTrack > STREAMED_SOUND_RADIO_POLICE) ? 0 : GetTrackStartPos(m_nNextTrack);
+ if (m_nNextTrack != NO_TRACK) {
+ SampleManager.SetStreamedFileLoopFlag(m_nNextLoopFlag, 0);
+ SampleManager.StartStreamedFile(m_nNextTrack, trackStartPos, 0);
m_nVolumeLatency = 3;
m_nCurrentVolume = 0;
m_nMaxVolume = 100;
SampleManager.SetStreamedVolumeAndPan(m_nCurrentVolume, 63, 0, 0);
- if (m_nStreamedTrack < STREAMED_SOUND_CITY_AMBIENT)
+ if (m_nNextTrack < STREAMED_SOUND_CITY_AMBIENT)
m_nLastTrackServiceTime = CTimer::GetTimeInMillisecondsPauseMode();
- field_3995 = true;
+ m_bVerifyNextTrackStartedToPlay = true;
}
}
} else {
@@ -483,8 +487,8 @@ cMusicManager::ServiceGameMode()
{
CPed *ped = FindPlayerPed();
CVehicle *vehicle = AudioManager.FindVehicleOfPlayer();
- field_3997 = field_3996;
- field_3996 = false;
+ m_bRadioStreamReady = m_bGameplayAllowsRadio;
+ m_bGameplayAllowsRadio = false;
switch (CGame::currArea)
{
@@ -495,29 +499,28 @@ cMusicManager::ServiceGameMode()
case AREA_BLOOD:
case AREA_OVALRING:
case AREA_MALIBU_CLUB:
- field_3996 = false;
+ m_bGameplayAllowsRadio = false;
break;
default:
if (SampleManager.GetMusicVolume()) {
if (PlayerInCar())
- field_3996 = true;
+ m_bGameplayAllowsRadio = true;
} else
- field_3996 = false;
+ m_bGameplayAllowsRadio = false;
break;
}
- if (!field_3996) {
+ if (!m_bGameplayAllowsRadio) {
nFramesSinceCutsceneEnded = -1;
gNumRetunePresses = 0;
gRetuneCounter = 0;
- field_2 = false;
+ m_bSetNextStation = false;
} else if (ped) {
- if(!ped->DyingOrDead()) {
+ if(!ped->DyingOrDead() && vehicle) {
#ifdef GTA_PC
if (SampleManager.IsMP3RadioChannelAvailable()
&& vehicle->m_nRadioStation < USERTRACK
- && ControlsManager.GetIsKeyboardKeyJustDown(rsF9)
- && vehicle)
+ && ControlsManager.GetIsKeyboardKeyJustDown(rsF9))
{
if (!UsesPoliceRadio(vehicle) && !UsesTaxiRadio(vehicle)) {
gNumRetunePresses = 0;
@@ -532,7 +535,7 @@ cMusicManager::ServiceGameMode()
}
}
#endif
- if (CPad::GetPad(0)->ChangeStationJustDown() && vehicle)
+ if (CPad::GetPad(0)->ChangeStationJustDown())
{
if (!UsesPoliceRadio(vehicle) && !UsesTaxiRadio(vehicle)) {
gNumRetunePresses++;
@@ -540,147 +543,183 @@ cMusicManager::ServiceGameMode()
RadioStaticCounter = 0;
}
}
-
+#ifdef RADIO_SCROLL_TO_PREV_STATION
+ else if(CPad::GetPad(0)->GetMouseWheelDownJustDown() || CPad::GetPad(0)->GetMouseWheelUpJustDown()) {
+ if(!UsesPoliceRadio(vehicle) && !UsesTaxiRadio(vehicle)) {
+ int scrollNext = ControlsManager.GetControllerKeyAssociatedWithAction(VEHICLE_CHANGE_RADIO_STATION, MOUSE);
+ int scrollPrev = scrollNext == rsMOUSEWHEELUPBUTTON ? rsMOUSEWHEELDOWNBUTTON
+ : scrollNext == rsMOUSEWHEELDOWNBUTTON ? rsMOUSEWHEELUPBUTTON : -1;
+
+ if(scrollPrev != -1 && !ControlsManager.IsAnyVehicleActionAssignedToMouseKey(scrollPrev)) {
+ gNumRetunePresses--;
+ gRetuneCounter = 20;
+ RadioStaticCounter = 0;
+ int track = gNumRetunePresses + vehicle->m_nRadioStation;
+ while(track < 0) track += NUM_RADIOS + 1;
+ while(track >= NUM_RADIOS + 1) track -= NUM_RADIOS + 1;
+ if(!DMAudio.IsMP3RadioChannelAvailable() && track == USERTRACK) gNumRetunePresses--;
+ }
+ }
+ }
+#endif
}
}
- if (field_3999)
+ if (m_bUserResumedGame)
{
- field_3997 = false;
- field_3999 = false;
+ m_bRadioStreamReady = false;
+ m_bUserResumedGame = false;
}
if (m_nPlayingTrack == NO_TRACK && m_nFrontendTrack == NO_TRACK)
- field_3997 = false;
+ m_bRadioStreamReady = false;
- if (field_3996)
+ if (m_bGameplayAllowsRadio)
{
- if (field_3997)
+ if (!m_bRadioStreamReady)
{
- if (m_nAnnouncement < NO_TRACK) {
- if ((m_bAnnouncementInProgress || m_nFrontendTrack == m_nPlayingTrack) && ServiceAnnouncement()) {
- if (m_bAnnouncementInProgress) {
- field_2 = false;
- gNumRetunePresses = 0;
- gRetuneCounter = 0;
- return;
- }
- if(m_nAnnouncement == NO_TRACK) {
- m_nStreamedTrack = NO_TRACK;
- m_nFrontendTrack = GetCarTuning();
- field_2 = false;
- gRetuneCounter = 0;
- gNumRetunePresses = 0;
- }
+ if(vehicle == nil) {
+ m_nFrontendTrack = STREAMED_SOUND_RADIO_WAVE; // huh?
+ return;
+ }
+ if(m_bRadioSetByScript) {
+ if(UsesPoliceRadio(vehicle))
+ m_nFrontendTrack = STREAMED_SOUND_RADIO_POLICE;
+ else if(UsesTaxiRadio(vehicle))
+ m_nFrontendTrack = STREAMED_SOUND_RADIO_TAXI;
+ else {
+ m_nFrontendTrack = m_nRadioStationScript;
+ vehicle->m_nRadioStation = m_nRadioStationScript;
}
+ if(m_nRadioPosition != -1) {
+ m_aTracks[m_nFrontendTrack].m_nPosition = m_nRadioPosition;
+ m_aTracks[m_nFrontendTrack].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
+ }
+ m_bRadioSetByScript = false;
+ return;
}
- if (!m_bAnnouncementInProgress
- && m_nAnnouncement == NO_TRACK
- && m_nPlayingTrack == STREAMED_SOUND_RADIO_MP3_PLAYER
- && !SampleManager.IsStreamPlaying(0))
- {
- SampleManager.StartStreamedFile(STREAMED_SOUND_RADIO_MP3_PLAYER, 0, 0);
+
+ // This starts the radio when you enter the car.
+ m_nFrontendTrack = GetCarTuning();
+ return;
+ }
+ if (m_nAnnouncement < NO_TRACK) {
+ if ((m_bAnnouncementInProgress || m_nFrontendTrack == m_nPlayingTrack) && ServiceAnnouncement()) {
+ if (m_bAnnouncementInProgress) {
+ m_bSetNextStation = false;
+ gNumRetunePresses = 0;
+ gRetuneCounter = 0;
+ return;
+ }
+ if(m_nAnnouncement == NO_TRACK) {
+ m_nNextTrack = NO_TRACK;
+ m_nFrontendTrack = GetCarTuning();
+ m_bSetNextStation = false;
+ gRetuneCounter = 0;
+ gNumRetunePresses = 0;
+ }
}
+ }
+ if (!m_bAnnouncementInProgress
+ && m_nAnnouncement == NO_TRACK
+ && m_nPlayingTrack == STREAMED_SOUND_RADIO_MP3_PLAYER
+ && !SampleManager.IsStreamPlaying(0))
+ {
+ SampleManager.StartStreamedFile(STREAMED_SOUND_RADIO_MP3_PLAYER, 0, 0);
+ }
- if (!m_bRadioSetByScript)
+ if (!m_bRadioSetByScript)
+ {
+ // 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) {
+ m_bSetNextStation = true;
+ gRetuneCounter = 0;
+ }
+ }
+#else
+ if (gNumRetunePresses != 0)
{
- if (gNumRetunePresses != 0)
+ if (--gRetuneCounter == 0)
{
- if (--gRetuneCounter == 0)
- {
- field_2 = true;
- gRetuneCounter = 0;
- }
+ m_bSetNextStation = true;
+ gRetuneCounter = 0;
}
- if (gRetuneCounter)
- {
- int32 station = gNumRetunePresses + vehicle->m_nRadioStation;
- while (station >= RADIO_OFF) station -= RADIO_OFF;
+ }
+#endif
+ if (gRetuneCounter)
+ {
+ int32 station = gNumRetunePresses + vehicle->m_nRadioStation;
+#ifdef RADIO_SCROLL_TO_PREV_STATION
+ while (station < 0) station += NUM_RADIOS + 1;
+#endif
+ while (station >= NUM_RADIOS + 1) station -= NUM_RADIOS + 1;
- if (!DMAudio.IsMP3RadioChannelAvailable() && station == USERTRACK)
- {
- ++gNumRetunePresses;
- station = NUM_RADIOS;
- }
- if (station == NUM_RADIOS)
- {
- if (gRetuneCounter == NUM_RADIOS + 9)
- {
- AudioManager.PlayOneShot(AudioManager.m_nFrontEndEntity, SOUND_FRONTEND_NO_RADIO, 0.0f);
- RadioStaticCounter = 5;
- }
- }
- else
+ // Scrolling back won't hit here, so increasing isn't problem
+ if (!DMAudio.IsMP3RadioChannelAvailable() && station == USERTRACK)
+ {
+ ++gNumRetunePresses;
+ station = RADIO_OFF;
+ }
+ if (station == RADIO_OFF)
+ {
+ if (gRetuneCounter == 19) // One less then what switching radio sets, so runs right after turning off radio
{
- if (station == WILDSTYLE && gRetuneCounter == NUM_RADIOS + 9)
- AudioManager.PlayOneShot(AudioManager.m_nFrontEndEntity, SOUND_FRONTEND_RADIO_CHANGE, 0.0f);
- AudioManager.DoPoliceRadioCrackle();
+ AudioManager.PlayOneShot(AudioManager.m_nFrontEndEntity, SOUND_FRONTEND_RADIO_TURN_OFF, 0.0f);
+ RadioStaticCounter = 5;
}
}
- if (RadioStaticCounter < 2 && CTimer::GetTimeInMilliseconds() > RadioStaticTimer + 800)
+ else
{
- AudioManager.PlayOneShot(AudioManager.m_nFrontEndEntity, SOUND_RADIO_CHANGE, 0.0f);
- RadioStaticCounter++;
- RadioStaticTimer = CTimer::GetTimeInMilliseconds();
+#ifdef RADIO_SCROLL_TO_PREV_STATION
+ if (vehicle->m_nRadioStation == RADIO_OFF && gRetuneCounter == 19) // Right after turning on the radio
+#else
+ if (station == 0 && gRetuneCounter == 19) // Right after turning on the radio
+#endif
+ AudioManager.PlayOneShot(AudioManager.m_nFrontEndEntity, SOUND_FRONTEND_RADIO_TURN_ON, 0.0f);
+ AudioManager.DoPoliceRadioCrackle();
}
- if (field_2)
- m_nFrontendTrack = GetNextCarTuning();
- if (m_nFrontendTrack >= STREAMED_SOUND_CITY_AMBIENT && m_nFrontendTrack <= STREAMED_SOUND_AMBSIL_AMBIENT)
- SetUpCorrectAmbienceTrack();
- ServiceTrack(vehicle, ped);
- if (field_2)
- field_2 = false;
- return;
}
- if (UsesPoliceRadio(vehicle))
- m_nFrontendTrack = STREAMED_SOUND_RADIO_POLICE;
- else if (UsesTaxiRadio(vehicle))
- m_nFrontendTrack = STREAMED_SOUND_RADIO_TAXI;
- else {
- m_nFrontendTrack = m_nRadioStation;
- vehicle->m_nRadioStation = m_nRadioStation;
- }
-
- if (m_nRadioPosition != -1) {
- m_aTracks[m_nFrontendTrack].m_nPosition = m_nRadioPosition;
- m_aTracks[m_nFrontendTrack].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
+ if (RadioStaticCounter < 2 && CTimer::GetTimeInMilliseconds() > RadioStaticTimer + 800)
+ {
+ AudioManager.PlayOneShot(AudioManager.m_nFrontEndEntity, SOUND_RADIO_CHANGE, 0.0f);
+ RadioStaticCounter++;
+ RadioStaticTimer = CTimer::GetTimeInMilliseconds();
}
-
- gRetuneCounter = 0;
- gNumRetunePresses = 0;
- field_2 = false;
- m_bRadioSetByScript = false;
+ if (m_bSetNextStation)
+ m_nFrontendTrack = GetNextCarTuning();
if (m_nFrontendTrack >= STREAMED_SOUND_CITY_AMBIENT && m_nFrontendTrack <= STREAMED_SOUND_AMBSIL_AMBIENT)
SetUpCorrectAmbienceTrack();
ServiceTrack(vehicle, ped);
- if (field_2)
- field_2 = false;
+ if (m_bSetNextStation)
+ m_bSetNextStation = false;
return;
}
- if (vehicle == nil)
- {
- m_nFrontendTrack = STREAMED_SOUND_RADIO_WAVE; // huh?
- return;
+ if (UsesPoliceRadio(vehicle))
+ m_nFrontendTrack = STREAMED_SOUND_RADIO_POLICE;
+ else if (UsesTaxiRadio(vehicle))
+ m_nFrontendTrack = STREAMED_SOUND_RADIO_TAXI;
+ else {
+ m_nFrontendTrack = m_nRadioStationScript;
+ vehicle->m_nRadioStation = m_nRadioStationScript;
}
- if (m_bRadioSetByScript)
- {
- if (UsesPoliceRadio(vehicle))
- m_nFrontendTrack = STREAMED_SOUND_RADIO_POLICE;
- else if (UsesTaxiRadio(vehicle))
- m_nFrontendTrack = STREAMED_SOUND_RADIO_TAXI;
- else {
- m_nFrontendTrack = m_nRadioStation;
- vehicle->m_nRadioStation = m_nRadioStation;
- }
- if (m_nRadioPosition != -1)
- {
- m_aTracks[m_nFrontendTrack].m_nPosition = m_nRadioPosition;
- m_aTracks[m_nFrontendTrack].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
- }
- m_bRadioSetByScript = false;
- return;
+
+ if (m_nRadioPosition != -1) {
+ m_aTracks[m_nFrontendTrack].m_nPosition = m_nRadioPosition;
+ m_aTracks[m_nFrontendTrack].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode();
}
- m_nFrontendTrack = GetCarTuning();
+ gRetuneCounter = 0;
+ gNumRetunePresses = 0;
+ m_bSetNextStation = false;
+ m_bRadioSetByScript = false;
+ if (m_nFrontendTrack >= STREAMED_SOUND_CITY_AMBIENT && m_nFrontendTrack <= STREAMED_SOUND_AMBSIL_AMBIENT)
+ SetUpCorrectAmbienceTrack();
+ ServiceTrack(vehicle, ped);
+ if (m_bSetNextStation)
+ m_bSetNextStation = false;
return;
}
@@ -692,7 +731,7 @@ cMusicManager::ServiceGameMode()
g_bAnnouncementReadPosAlready = false;
m_nAnnouncement = NO_TRACK;
m_bAnnouncementInProgress = false;
- m_nStreamedTrack = NO_TRACK;
+ m_nNextTrack = NO_TRACK;
m_nFrontendTrack = NO_TRACK;
m_nPlayingTrack = NO_TRACK;
}
@@ -834,7 +873,7 @@ cMusicManager::ServiceAnnouncement()
{
if (m_bAnnouncementInProgress) {
if (SampleManager.IsStreamPlaying(0))
- m_nPlayingTrack = m_nStreamedTrack;
+ m_nPlayingTrack = m_nNextTrack;
else if (m_nPlayingTrack != NO_TRACK) {
m_nAnnouncement = NO_TRACK;
m_bAnnouncementInProgress = false;
@@ -852,9 +891,9 @@ cMusicManager::ServiceAnnouncement()
} else {
g_bAnnouncementReadPosAlready = false;
m_nPlayingTrack = NO_TRACK;
- m_nStreamedTrack = m_nAnnouncement;
- SampleManager.SetStreamedFileLoopFlag(0, false);
- SampleManager.StartStreamedFile(m_nStreamedTrack, 0, 0);
+ m_nNextTrack = m_nAnnouncement;
+ SampleManager.SetStreamedFileLoopFlag(0, 0);
+ SampleManager.StartStreamedFile(m_nNextTrack, 0, 0);
SampleManager.SetStreamedVolumeAndPan(MAX_VOLUME, 63, 0, 0);
m_bAnnouncementInProgress = true;
}
@@ -868,9 +907,9 @@ cMusicManager::ServiceTrack(CVehicle *veh, CPed *ped)
static bool bRadioStatsRecorded = false;
static bool bRadioStatsRecorded2 = false;
uint8 volume;
- if (!field_398F)
- m_nStreamedTrack = m_nFrontendTrack;
- if (gRetuneCounter != 0 || field_2) {
+ if (!m_bTrackChangeStarted)
+ m_nNextTrack = m_nFrontendTrack;
+ if (gRetuneCounter != 0 || m_bSetNextStation) {
if (SampleManager.IsStreamPlaying(0)) {
if (m_nPlayingTrack != NO_TRACK && !bRadioStatsRecorded) {
m_aTracks[m_nPlayingTrack].m_nPosition = SampleManager.GetStreamedFilePosition(0);
@@ -889,28 +928,35 @@ cMusicManager::ServiceTrack(CVehicle *veh, CPed *ped)
m_nPlayingTrack = NO_TRACK;
}
- if (m_nStreamedTrack != m_nPlayingTrack)
+ if (m_nNextTrack != m_nPlayingTrack)
{
- field_398F = true;
+ m_bTrackChangeStarted = true;
SampleManager.SetStreamedVolumeAndPan(0, 63, 0, 0);
if (!(AudioManager.m_FrameCounter & 1)) {
- if (field_3995 || !SampleManager.IsStreamPlaying(0)) {
+ if (m_bVerifyNextTrackStartedToPlay || !SampleManager.IsStreamPlaying(0)) {
bRadioStatsRecorded2 = false;
if (SampleManager.IsStreamPlaying(0)) {
- m_nPlayingTrack = m_nStreamedTrack;
- field_3995 = false;
- field_398F = false;
+ m_nPlayingTrack = m_nNextTrack;
+ m_bVerifyNextTrackStartedToPlay = false;
+ m_bTrackChangeStarted = false;
if (veh) {
- if (veh->m_nRadioStation < STREAMED_SOUND_CITY_AMBIENT || veh->m_nRadioStation > STREAMED_SOUND_AMBSIL_AMBIENT)
+#ifdef FIX_BUGS
+ if (m_nPlayingTrack >= STREAMED_SOUND_CITY_AMBIENT && m_nPlayingTrack <= STREAMED_SOUND_AMBSIL_AMBIENT)
+ veh->m_nRadioStation = RADIO_OFF;
+ else if (m_nPlayingTrack < STREAMED_SOUND_CITY_AMBIENT)
veh->m_nRadioStation = m_nPlayingTrack;
+#else
+ if (veh->m_nRadioStation >= STREAMED_SOUND_CITY_AMBIENT && veh->m_nRadioStation <= STREAMED_SOUND_AMBSIL_AMBIENT)
+ veh->m_nRadioStation = RADIO_OFF;
else
- veh->m_nRadioStation = STREAMED_SOUND_CITY_AMBIENT;
+ veh->m_nRadioStation = m_nPlayingTrack;
+#endif
}
} else {
- uint32 pos = GetTrackStartPos(m_nStreamedTrack);
- if (m_nStreamedTrack != NO_TRACK) {
+ uint32 pos = GetTrackStartPos(m_nNextTrack);
+ if (m_nNextTrack != NO_TRACK) {
SampleManager.SetStreamedFileLoopFlag(1, 0);
- SampleManager.StartStreamedFile(m_nStreamedTrack, pos, 0);
+ SampleManager.StartStreamedFile(m_nNextTrack, pos, 0);
if (m_nFrontendTrack < STREAMED_SOUND_CITY_AMBIENT || m_nFrontendTrack > STREAMED_SOUND_AMBSIL_AMBIENT)
{
m_nVolumeLatency = 10;
@@ -923,9 +969,9 @@ cMusicManager::ServiceTrack(CVehicle *veh, CPed *ped)
ComputeAmbienceVol(true, volume);
SampleManager.SetStreamedVolumeAndPan(volume, 63, 1, 0);
}
- if (m_nStreamedTrack < STREAMED_SOUND_CITY_AMBIENT)
+ if (m_nNextTrack < STREAMED_SOUND_CITY_AMBIENT)
m_nLastTrackServiceTime = CTimer::GetTimeInMillisecondsPauseMode();
- field_3995 = true;
+ m_bVerifyNextTrackStartedToPlay = true;
}
}
} else {
@@ -939,8 +985,8 @@ cMusicManager::ServiceTrack(CVehicle *veh, CPed *ped)
RecordRadioStats();
if (m_nPlayingTrack >= STREAMED_SOUND_HAVANA_CITY_AMBIENT && m_nPlayingTrack <= STREAMED_SOUND_HAVANA_BEACH_AMBIENT)
{
- if (m_nStreamedTrack >= STREAMED_SOUND_HAVANA_CITY_AMBIENT && m_nStreamedTrack <= STREAMED_SOUND_HAVANA_BEACH_AMBIENT)
- AudioManager.PlayOneShot(AudioManager.m_nFrontEndEntity, SOUND_FRONTEND_RADIO_CHANGE_2, 0.0);
+ if (m_nNextTrack >= STREAMED_SOUND_HAVANA_CITY_AMBIENT && m_nNextTrack <= STREAMED_SOUND_HAVANA_BEACH_AMBIENT)
+ AudioManager.PlayOneShot(AudioManager.m_nFrontEndEntity, SOUND_FRONTEND_HURRICANE, 0.0);
}
}
SampleManager.SetStreamedVolumeAndPan(0, 63, 0, 0);
@@ -1050,14 +1096,14 @@ cMusicManager::StopCutSceneMusic(void)
}
void
-cMusicManager::PlayFrontEndTrack(uint32 track, uint8 bPlayInFrontend)
+cMusicManager::PlayFrontEndTrack(uint32 track, uint8 loopFlag)
{
if (IsInitialised() && !m_bDisabled && track < TOTAL_STREAMED_SOUNDS && (m_nUpcomingMusicMode == MUSICMODE_FRONTEND || m_nMusicMode == MUSICMODE_FRONTEND))
{
m_nFrontendTrack = track;
- field_398E = bPlayInFrontend;
+ m_FrontendLoopFlag = loopFlag;
if (m_nMusicMode != MUSICMODE_FRONTEND)
- field_399C = true;
+ m_bEarlyFrontendTrack = true;
}
}
@@ -1083,10 +1129,18 @@ cMusicManager::GetNextCarTuning()
if (UsesPoliceRadio(veh)) return STREAMED_SOUND_RADIO_POLICE;
if (UsesTaxiRadio(veh)) return STREAMED_SOUND_RADIO_TAXI;
if (gNumRetunePresses != 0) {
+#ifdef RADIO_SCROLL_TO_PREV_STATION
+ // m_nRadioStation is unsigned, so...
+ int station = veh->m_nRadioStation + gNumRetunePresses;
+ while(station < 0) station += NUM_RADIOS + 1;
+ while(station >= NUM_RADIOS + 1) station -= NUM_RADIOS + 1;
+ veh->m_nRadioStation = station;
+#else
veh->m_nRadioStation += gNumRetunePresses;
- while (veh->m_nRadioStation >= RADIO_OFF)
- veh->m_nRadioStation -= RADIO_OFF;
- DMAudio.IsMP3RadioChannelAvailable(); // woof, just call and do nothing =P
+ while(veh->m_nRadioStation >= NUM_RADIOS + 1)
+ veh->m_nRadioStation -= NUM_RADIOS + 1;
+#endif
+ DMAudio.IsMP3RadioChannelAvailable(); // woof, just call and do nothing =P they manipulate gNumRetunePresses on DisplayRadioStationName in this case
gNumRetunePresses = 0;
}
return veh->m_nRadioStation;
@@ -1129,7 +1183,7 @@ cMusicManager::GetTrackStartPos(uint32 track)
uint32
cMusicManager::GetRadioPosition(uint32 station)
{
- if (station < STREAMED_SOUND_CITY_AMBIENT)
+ if (station < NUM_RADIOS)
return GetTrackStartPos(station);
return 0;
}
@@ -1158,7 +1212,7 @@ cMusicManager::SetMalibuClubTrackPos(uint8 scriptObject)
{
if (!IsInitialised())
m_aTracks[STREAMED_SOUND_MALIBU_AMBIENT].m_nPosition = 8640;
- if (m_nStreamedTrack != STREAMED_SOUND_MALIBU_AMBIENT && m_nPlayingTrack != STREAMED_SOUND_MALIBU_AMBIENT) {
+ if (m_nNextTrack != STREAMED_SOUND_MALIBU_AMBIENT && m_nPlayingTrack != STREAMED_SOUND_MALIBU_AMBIENT) {
switch (scriptObject)
{
case SCRIPT_SOUND_NEW_BUILDING_MALIBU_1:
@@ -1180,7 +1234,7 @@ cMusicManager::SetStripClubTrackPos(uint8 scriptObject)
{
if (!IsInitialised())
m_aTracks[STREAMED_SOUND_STRIPCLUB_AMBIENT].m_nPosition = 0;
- if (m_nStreamedTrack != STREAMED_SOUND_STRIPCLUB_AMBIENT && m_nPlayingTrack != STREAMED_SOUND_STRIPCLUB_AMBIENT)
+ if (m_nNextTrack != STREAMED_SOUND_STRIPCLUB_AMBIENT && m_nPlayingTrack != STREAMED_SOUND_STRIPCLUB_AMBIENT)
{
switch (scriptObject)
{
@@ -1201,7 +1255,7 @@ cMusicManager::SetStripClubTrackPos(uint8 scriptObject)
void
cMusicManager::DisplayRadioStationName()
{
- int8 gStreamedSound;
+ uint8 gStreamedSound;
static wchar *pCurrentStation = nil;
static uint8 cDisplay = 0;
@@ -1211,20 +1265,28 @@ cMusicManager::DisplayRadioStationName()
if (vehicle)
{
- uint8 track;
+ int8 track;
gStreamedSound = vehicle->m_nRadioStation;
if (gStreamedSound >= STREAMED_SOUND_CITY_AMBIENT && gStreamedSound <= STREAMED_SOUND_AMBSIL_AMBIENT)
- gStreamedSound = STREAMED_SOUND_CITY_AMBIENT;
+ gStreamedSound = RADIO_OFF;
if (gNumRetunePresses != 0)
{
track = gNumRetunePresses + gStreamedSound;
- while (track >= RADIO_OFF) track -= RADIO_OFF;
+#ifdef RADIO_SCROLL_TO_PREV_STATION
+ while (track < 0) track += NUM_RADIOS + 1;
+#endif
+ while (track >= NUM_RADIOS + 1) track -= NUM_RADIOS + 1;
+
+ // We already handle this condition while scrolling back, on key press. No need to change this.
if (!DMAudio.IsMP3RadioChannelAvailable() && track == USERTRACK)
gNumRetunePresses++;
}
else
+#ifdef FIX_BUGS
+ track = GetCarTuning(); // gStreamedSound or veh->m_nRadioStation would also work, but these don't cover police/taxi radios
+#else
track = m_nFrontendTrack;
-
+#endif
wchar* string = nil;
switch (track) {
@@ -1241,6 +1303,18 @@ cMusicManager::DisplayRadioStationName()
if (!SampleManager.IsMP3RadioChannelAvailable())
return;
string = TheText.Get("FEA_MP3"); 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;
};
@@ -1272,6 +1346,11 @@ cMusicManager::DisplayRadioStationName()
CFont::DrawFonts();
}
}
+ // Always show station text after entering car. Same behaviour as III and SA.
+#ifdef FIX_BUGS
+ else
+ pCurrentStation = nil;
+#endif
}
bool
diff --git a/src/audio/MusicManager.h b/src/audio/MusicManager.h
index f103e84e..27456d79 100644
--- a/src/audio/MusicManager.h
+++ b/src/audio/MusicManager.h
@@ -18,7 +18,7 @@ class cMusicManager
public:
bool m_bIsInitialised;
bool m_bDisabled;
- bool field_2;
+ bool m_bSetNextStation;
uint8 m_nVolumeLatency;
uint8 m_nCurrentVolume;
uint8 m_nMaxVolume;
@@ -28,25 +28,25 @@ public:
bool m_bResetTimers;
uint32 m_nResetTime;
bool m_bRadioSetByScript;
- uint8 m_nRadioStation;
- uint32 m_nRadioPosition;
+ uint8 m_nRadioStationScript;
+ int32 m_nRadioPosition;
uint32 m_nRadioInCar;
uint32 m_nFrontendTrack;
uint32 m_nPlayingTrack;
uint8 m_nUpcomingMusicMode;
uint8 m_nMusicMode;
- bool field_398E;
- bool field_398F;
- uint32 m_nStreamedTrack;
- bool field_3994;
- bool field_3995;
- bool field_3996;
- bool field_3997;
+ bool m_FrontendLoopFlag;
+ bool m_bTrackChangeStarted;
+ uint32 m_nNextTrack;
+ bool m_nNextLoopFlag;
+ bool m_bVerifyNextTrackStartedToPlay;
+ bool m_bGameplayAllowsRadio;
+ bool m_bRadioStreamReady;
int8 nFramesSinceCutsceneEnded;
- bool field_3999;
- bool field_399A;
+ bool m_bUserResumedGame;
+ bool m_bMusicModeChangeStarted;
uint8 m_nMusicModeToBeSet;
- bool field_399C;
+ bool m_bEarlyFrontendTrack;
float aListenTimeArray[NUM_RADIOS];
float m_nLastTrackServiceTime;
diff --git a/src/audio/audio_enums.h b/src/audio/audio_enums.h
index 91fcec49..990b2d73 100644
--- a/src/audio/audio_enums.h
+++ b/src/audio/audio_enums.h
@@ -14,8 +14,8 @@ enum eRadioStation
USERTRACK,
NUM_RADIOS = 10,
POLICE_RADIO = 10,
+ RADIO_OFF = 10,
//TAXI_RADIO,
- RADIO_OFF,
};
enum eMusicMode
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/stream.cpp b/src/audio/oal/stream.cpp
index 19fa4ec4..4817d6d5 100644
--- a/src/audio/oal/stream.cpp
+++ b/src/audio/oal/stream.cpp
@@ -499,6 +499,7 @@ public:
m_bOpened = mpg123_open(m_pMH, path) == MPG123_OK
&& mpg123_getformat(m_pMH, &rate, &channels, &encoding) == MPG123_OK;
+
m_nRate = rate;
m_nChannels = channels;
@@ -980,7 +981,8 @@ CStream::CStream(char *filename, ALuint *sources, ALuint (&buffers)[NUM_STREAMBU
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/)
@@ -1078,7 +1080,7 @@ bool CStream::IsPlaying()
ALint sourceState[2];
alGetSourcei(m_pAlSources[0], AL_SOURCE_STATE, &sourceState[0]);
alGetSourcei(m_pAlSources[1], AL_SOURCE_STATE, &sourceState[1]);
- if ( m_bActive || sourceState[0] == AL_PLAYING || sourceState[1] == AL_PLAYING)
+ if (sourceState[0] == AL_PLAYING || sourceState[1] == AL_PLAYING)
return true;
}
@@ -1236,6 +1238,8 @@ 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);
//SetPosition(0.0f, 0.0f, 0.0f);
SetPitch(1.0f);
@@ -1246,6 +1250,13 @@ bool CStream::Setup()
return IsOpened();
}
+void CStream::SetLoopCount(int32 count)
+{
+ if ( !HasSource() ) return;
+
+ m_nLoopCount = count;
+}
+
void CStream::SetPlay(bool state)
{
if ( !HasSource() ) return;
@@ -1305,7 +1316,7 @@ void CStream::Update()
if ( !m_bPaused )
{
- ALint sourceState[2];
+ ALint totalBuffers[2] = { 0, 0 };
ALint buffersProcessed[2] = { 0, 0 };
// Relying a lot on left buffer states in here
@@ -1313,44 +1324,51 @@ void CStream::Update()
do
{
//alSourcef(m_pAlSources[0], AL_ROLLOFF_FACTOR, 0.0f);
- alGetSourcei(m_pAlSources[0], AL_SOURCE_STATE, &sourceState[0]);
+ 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_SOURCE_STATE, &sourceState[1]);
+ alGetSourcei(m_pAlSources[1], AL_BUFFERS_QUEUED, &totalBuffers[1]);
alGetSourcei(m_pAlSources[1], AL_BUFFERS_PROCESSED, &buffersProcessed[1]);
} while (buffersProcessed[0] != buffersProcessed[1]);
- ALint looping = AL_FALSE;
- alGetSourcei(m_pAlSources[0], AL_LOOPING, &looping);
-
- if ( looping == AL_TRUE )
- {
- TRACE("stream set looping");
- alSourcei(m_pAlSources[0], AL_LOOPING, AL_TRUE);
- alSourcei(m_pAlSources[1], AL_LOOPING, AL_TRUE);
- }
-
assert(buffersProcessed[0] == buffersProcessed[1]);
- while( buffersProcessed[0]-- )
+ // 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[2];
-
- alSourceUnqueueBuffers(m_pAlSources[0], 1, &buffer[0]);
- alSourceUnqueueBuffers(m_pAlSources[1], 1, &buffer[1]);
-
- if (m_bActive && FillBuffer(buffer))
- {
- alSourceQueueBuffers(m_pAlSources[0], 1, &buffer[0]);
- alSourceQueueBuffers(m_pAlSources[1], 1, &buffer[1]);
- }
+ Setup();
+ buffersRefilled = FillBuffers() != 0;
+ if (m_nLoopCount != 0)
+ m_nLoopCount--;
}
-
- if ( sourceState[0] != AL_PLAYING )
+ else
{
- alGetSourcei(m_pAlSources[0], AL_BUFFERS_PROCESSED, &buffersProcessed[0]);
- SetPlay(buffersProcessed[0]!=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);
}
}
@@ -1362,6 +1380,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 bcbc5e54..b3e96809 100644
--- a/src/audio/oal/stream.h
+++ b/src/audio/oal/stream.h
@@ -69,6 +69,7 @@ class CStream
uint32 m_nVolume;
uint8 m_nPan;
uint32 m_nPosBeforeReset;
+ int32 m_nLoopCount;
IDecoder *m_pSoundFile;
@@ -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_oal.cpp b/src/audio/sampman_oal.cpp
index 0d06098d..ae4b1cbb 100644
--- a/src/audio/sampman_oal.cpp
+++ b/src/audio/sampman_oal.cpp
@@ -46,7 +46,6 @@
//TODO: fix eax3 reverb
//TODO: max channels
-//TODO: loop count
cSampleManager SampleManager;
bool _bSampmanInitialised = false;
@@ -1695,7 +1694,7 @@ cSampleManager::PreloadStreamedFile(uint32 nFile, uint8 nStream)
ASSERT(stream != NULL);
aStream[nStream] = stream;
- if ( !stream->IsOpened() )
+ if ( !stream->Setup() )
{
delete stream;
aStream[nStream] = NULL;
@@ -1725,7 +1724,7 @@ cSampleManager::StartPreloadedStreamedFile(uint8 nStream)
if ( stream )
{
- if ( stream->Setup() )
+ if ( stream->IsOpened() )
{
stream->Start();
}
@@ -1771,13 +1770,13 @@ cSampleManager::StartStreamedFile(uint32 nFile, uint32 nPos, uint8 nStream)
aStream[nStream] = stream;
- if (stream->IsOpened()) {
- if (stream->Setup()) {
- if (position != 0)
- stream->SetPosMS(position);
+ if (stream->Setup()) {
+ stream->SetLoopCount(nStreamLoopedFlag[nStream] ? 0 : 1);
+ nStreamLoopedFlag[nStream] = true;
+ if (position != 0)
+ stream->SetPosMS(position);
- stream->Start();
- }
+ stream->Start();
return true;
} else {
@@ -1798,10 +1797,8 @@ cSampleManager::StartStreamedFile(uint32 nFile, uint32 nPos, uint8 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 {
@@ -1827,13 +1824,13 @@ cSampleManager::StartStreamedFile(uint32 nFile, uint32 nPos, uint8 nStream)
aStream[nStream] = stream;
- if (stream->IsOpened()) {
- if (stream->Setup()) {
- if (position != 0)
- stream->SetPosMS(position);
+ if (stream->Setup()) {
+ stream->SetLoopCount(nStreamLoopedFlag[nStream] ? 0 : 1);
+ nStreamLoopedFlag[nStream] = true;
+ if (position != 0)
+ stream->SetPosMS(position);
- stream->Start();
- }
+ stream->Start();
return true;
} else {
@@ -1854,13 +1851,11 @@ cSampleManager::StartStreamedFile(uint32 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;
@@ -1884,13 +1879,13 @@ cSampleManager::StartStreamedFile(uint32 nFile, uint32 nPos, uint8 nStream)
aStream[nStream] = stream;
- if ( stream->IsOpened() ) {
- if ( stream->Setup() ) {
- if (position != 0)
- stream->SetPosMS(position);
+ if ( stream->Setup() ) {
+ stream->SetLoopCount(nStreamLoopedFlag[nStream] ? 0 : 1);
+ nStreamLoopedFlag[nStream] = true;
+ if (position != 0)
+ stream->SetPosMS(position);
- stream->Start();
- }
+ stream->Start();
return true;
} else {
@@ -1913,6 +1908,9 @@ cSampleManager::StopStreamedFile(uint8 nStream)
{
delete stream;
aStream[nStream] = NULL;
+
+ if ( nStream == 0 )
+ _bIsMp3Active = false;
}
}
@@ -1925,7 +1923,21 @@ cSampleManager::GetStreamedFilePosition(uint8 nStream)
if ( stream )
{
- return stream->GetPosMS();
+ if ( _bIsMp3Active )
+ {
+ tMP3Entry *mp3 = _GetMP3EntryByIndex(_CurMP3Index);
+
+ if ( mp3 != NULL )
+ {
+ return stream->GetPosMS() + mp3->nTrackStreamPos;
+ }
+ else
+ return 0;
+ }
+ else
+ {
+ return stream->GetPosMS();
+ }
}
return 0;
@@ -2001,6 +2013,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
diff --git a/src/audio/soundlist.h b/src/audio/soundlist.h
index 4d88590e..e86b13ee 100644
--- a/src/audio/soundlist.h
+++ b/src/audio/soundlist.h
@@ -171,22 +171,22 @@ enum eSound
SOUND_CAR_PED_COLLISION,
SOUND_CLOCK_TICK,
SOUND_PART_MISSION_COMPLETE,
- SOUND_FRONTEND_MENU_STARTING, // same with SOUND_HUD_SOUND
+ SOUND_FRONTEND_MENU_STARTING, // same sound as SOUND_HUD
// TODO(Miami): What are 170-175??
- SOUND_FRONTEND_NO_RADIO = 176, // those 3 are all same sound
- SOUND_FRONTEND_RADIO_CHANGE,
- SOUND_FRONTEND_RADIO_CHANGE_2,
- SOUND_HUD_SOUND,
+ SOUND_FRONTEND_RADIO_TURN_OFF = 176, // those 2 are same sound
+ SOUND_FRONTEND_RADIO_TURN_ON,
+ SOUND_FRONTEND_HURRICANE, // yes, frontend
+ SOUND_HUD,
SOUND_180,
SOUND_181,
SOUND_182,
SOUND_LIGHTNING,
SOUND_BULLETTRACE_1,
SOUND_BULLETTRACE_2,
- SOUND_186, // makes same sound with 40
- SOUND_187, // makes same sound with 46
+ SOUND_186, // makes same sound as 40
+ SOUND_187, // makes same sound as 46
SOUND_MELEE_ATTACK_START,
SOUND_SKATING,
SOUND_WEAPON_MINIGUN_ATTACK,