diff options
Diffstat (limited to 'src/audio')
-rw-r--r-- | src/audio/AudioLogic.cpp | 2 | ||||
-rw-r--r-- | src/audio/MusicManager.cpp | 281 | ||||
-rw-r--r-- | src/audio/MusicManager.h | 10 | ||||
-rw-r--r-- | src/audio/audio_enums.h | 5 | ||||
-rw-r--r-- | src/audio/oal/channel.cpp | 56 | ||||
-rw-r--r-- | src/audio/oal/channel.h | 6 | ||||
-rw-r--r-- | src/audio/oal/stream.cpp | 88 | ||||
-rw-r--r-- | src/audio/oal/stream.h | 5 | ||||
-rw-r--r-- | src/audio/sampman_miles.cpp | 10 | ||||
-rw-r--r-- | src/audio/sampman_oal.cpp | 93 | ||||
-rw-r--r-- | src/audio/soundlist.h | 2 |
11 files changed, 338 insertions, 220 deletions
diff --git a/src/audio/AudioLogic.cpp b/src/audio/AudioLogic.cpp index eab14ce6..ec364c27 100644 --- a/src/audio/AudioLogic.cpp +++ b/src/audio/AudioLogic.cpp @@ -7927,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; diff --git a/src/audio/MusicManager.cpp b/src/audio/MusicManager.cpp index 54c1b0bc..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,16 +86,15 @@ cMusicManager::DisplayRadioStationName() if(m_bPlayerInCar && !m_bPreviousPlayerInCar) pCurrentStation = nil; +#ifdef FIX_BUGS + const int curRadio = GetCarTuning(); +#else + const int curRadio = m_nNextTrack; +#endif + #ifdef RADIO_SCROLL_TO_PREV_STATION if(gNumRetunePresses < 0) { - gStreamedSound = m_nCurrentStreamedSound; - - if(gStreamedSound == STREAMED_SOUND_CITY_AMBIENT || - gStreamedSound == STREAMED_SOUND_WATER_AMBIENT) { - gStreamedSound = POLICE_RADIO; // which means OFF - - } else if(gStreamedSound > STREAMED_SOUND_RADIO_MP3_PLAYER) - return; + gStreamedSound = curRadio; gRetuneCounter = gNumRetunePresses; pRetune = gStreamedSound; @@ -100,7 +102,7 @@ cMusicManager::DisplayRadioStationName() while(gRetuneCounter < 0) { if(pRetune == HEAD_RADIO) { pRetune = RADIO_OFF; - } else if(pRetune == RADIO_OFF || pRetune == POLICE_RADIO) { + } else if(pRetune == RADIO_OFF || pRetune == NUM_RADIOS) { pRetune = SampleManager.IsMP3RadioChannelAvailable() ? USERTRACK : USERTRACK - 1; } else pRetune--; @@ -110,31 +112,38 @@ cMusicManager::DisplayRadioStationName() } else #endif if(SampleManager.IsMP3RadioChannelAvailable()) { - gStreamedSound = m_nCurrentStreamedSound; + gStreamedSound = curRadio; if(gStreamedSound == STREAMED_SOUND_CITY_AMBIENT || - gStreamedSound == STREAMED_SOUND_WATER_AMBIENT) { - gStreamedSound = POLICE_RADIO; // which means OFF + 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) { @@ -149,7 +158,7 @@ cMusicManager::DisplayRadioStationName() } } - wchar *string = nil; + wchar *string; switch(pRetune) { case HEAD_RADIO: string = TheText.Get("FEA_FM0"); break; @@ -161,22 +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: case POLICE_RADIO: string = TheText.Get("FEM_OFF"); break; + case RADIO_OFF: { + extern wchar WideErrorString[]; + + string = TheText.Get("FEA_FMN"); + if(string == WideErrorString) { + pCurrentStation = nil; + return; + } + break; + } #endif default: return; }; -#ifdef RADIO_OFF_TEXT - if(pRetune == USERTRACK && !SampleManager.IsMP3RadioChannelAvailable()) { string = TheText.Get("FEM_OFF"); } -#else - if(pRetune > CHATTERBOX && !SampleManager.IsMP3RadioChannelAvailable()) { return; } -#endif - - 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 { @@ -257,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; @@ -274,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; } @@ -303,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; @@ -320,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; @@ -370,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; } } @@ -380,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; @@ -419,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; @@ -430,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) @@ -445,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; @@ -473,7 +487,7 @@ 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() @@ -485,10 +499,13 @@ cMusicManager::ServiceGameMode() 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()) { @@ -511,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; @@ -520,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); @@ -563,22 +580,22 @@ cMusicManager::ServiceGameMode() 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) { @@ -631,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; } } @@ -696,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; } @@ -735,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; } } @@ -751,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; } } @@ -795,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; } } @@ -862,7 +879,7 @@ cMusicManager::ServiceTrack() { if (m_bDoTrackService) { if (!SampleManager.IsStreamPlaying(0)) - SampleManager.StartStreamedFile(m_nCurrentStreamedSound, 0, 0); + SampleManager.StartStreamedFile(m_nNextTrack, 0, 0); } } @@ -882,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); } } @@ -893,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; } @@ -929,7 +946,7 @@ cMusicManager::GetNextCarTuning() while (gNumRetunePresses < 0) { if(veh->m_nRadioStation == HEAD_RADIO) { veh->m_nRadioStation = RADIO_OFF; - } else if(veh->m_nRadioStation == RADIO_OFF || veh->m_nRadioStation == POLICE_RADIO) { + } else if(veh->m_nRadioStation == RADIO_OFF || veh->m_nRadioStation == NUM_RADIOS) { veh->m_nRadioStation = SampleManager.IsMP3RadioChannelAvailable() ? USERTRACK : USERTRACK - 1; } else veh->m_nRadioStation--; @@ -940,12 +957,18 @@ cMusicManager::GetNextCarTuning() #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) @@ -967,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/audio_enums.h b/src/audio/audio_enums.h index 8c6d35aa..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 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 74ed86f4..44cc1c93 100644 --- a/src/audio/oal/stream.cpp +++ b/src/audio/oal/stream.cpp @@ -492,6 +492,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; @@ -925,7 +926,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/) @@ -1021,7 +1023,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; } @@ -1093,6 +1095,7 @@ void CStream::SetPan(uint8 nPan) m_nPan = nPan; } +// Should only be called if source is stopped void CStream::SetPosMS(uint32 nPos) { if ( !IsOpened() ) return; @@ -1175,10 +1178,16 @@ void CStream::ClearBuffers() alSourceUnqueueBuffers(m_pAlSources[1], 1, &value); } -bool CStream::Setup() +bool CStream::Setup(bool imSureQueueIsEmpty) { if ( IsOpened() ) { + alSourcei(m_pAlSources[0], AL_LOOPING, AL_FALSE); + alSourcei(m_pAlSources[1], AL_LOOPING, AL_FALSE); + if (!imSureQueueIsEmpty) { + SetPlay(false); + ClearBuffers(); + } m_pSoundFile->Seek(0); //SetPosition(0.0f, 0.0f, 0.0f); SetPitch(1.0f); @@ -1189,6 +1198,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; @@ -1248,7 +1264,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 @@ -1256,44 +1272,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 ) + 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) { - TRACE("stream set looping"); - alSourcei(m_pAlSources[0], AL_LOOPING, AL_TRUE); - alSourcei(m_pAlSources[1], AL_LOOPING, AL_TRUE); + Setup(true); + buffersRefilled = FillBuffers() != 0; + if (m_nLoopCount != 0) + m_nLoopCount--; } - - assert(buffersProcessed[0] == buffersProcessed[1]); - - while( buffersProcessed[0]-- ) + else { - ALuint buffer[2]; - - alSourceUnqueueBuffers(m_pAlSources[0], 1, &buffer[0]); - alSourceUnqueueBuffers(m_pAlSources[1], 1, &buffer[1]); - - if (m_bActive && FillBuffer(buffer)) + while( buffersProcessed[0]-- ) { - alSourceQueueBuffers(m_pAlSources[0], 1, &buffer[0]); - alSourceQueueBuffers(m_pAlSources[1], 1, &buffer[1]); + 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]); + } } } - - if ( sourceState[0] != AL_PLAYING ) - { - alGetSourcei(m_pAlSources[0], AL_BUFFERS_PROCESSED, &buffersProcessed[0]); - SetPlay(buffersProcessed[0]!=0); - } + + // 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); } } @@ -1301,10 +1324,11 @@ void CStream::ProviderInit() { if ( m_bReset ) { - if ( Setup() ) + if ( Setup(true) ) { 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..9a2a2fbe 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; @@ -99,10 +100,12 @@ public: uint32 GetPosMS(); uint32 GetLengthMS(); - bool Setup(); + bool Setup(bool imSureQueueIsEmpty = false); void Start(); void Stop(); void Update(void); + void SetLoopCount(int32); + void ProviderInit(); void ProviderTerm(); diff --git a/src/audio/sampman_miles.cpp b/src/audio/sampman_miles.cpp index 11e2b0ff..9b601d52 100644 --- a/src/audio/sampman_miles.cpp +++ b/src/audio/sampman_miles.cpp @@ -1514,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; @@ -1753,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; } @@ -1792,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 798ea287..d9adef5b 100644 --- a/src/audio/sampman_oal.cpp +++ b/src/audio/sampman_oal.cpp @@ -14,8 +14,6 @@ #include <AL/efx.h> #include <AL/efx-presets.h> -#pragma comment(lib, "OpenAL32.lib") - // for user MP3s #include <direct.h> #include <shlobj.h> @@ -24,6 +22,10 @@ #define _getcwd getcwd #endif +#if defined _MSC_VER && !defined CMAKE_NO_AUTOLINK +#pragma comment( lib, "OpenAL32.lib" ) +#endif + #include "common.h" #include "crossplatform.h" @@ -44,7 +46,6 @@ //TODO: fix eax3 reverb //TODO: max channels -//TODO: loop count cSampleManager SampleManager; bool _bSampmanInitialised = false; @@ -117,7 +118,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; @@ -1318,7 +1318,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; @@ -1533,8 +1533,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; } @@ -1575,8 +1575,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; } @@ -1666,7 +1666,7 @@ cSampleManager::PreloadStreamedFile(uint8 nFile, uint8 nStream) ASSERT(stream != NULL); aStream[nStream] = stream; - if ( !stream->IsOpened() ) + if ( !stream->Setup() ) { delete stream; aStream[nStream] = NULL; @@ -1696,7 +1696,7 @@ cSampleManager::StartPreloadedStreamedFile(uint8 nStream) if ( stream ) { - if ( stream->Setup() ) + if ( stream->IsOpened() ) { stream->Start(); } @@ -1742,13 +1742,11 @@ cSampleManager::StartStreamedFile(uint8 nFile, uint32 nPos, uint8 nStream) 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 { @@ -1769,10 +1767,8 @@ cSampleManager::StartStreamedFile(uint8 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 { @@ -1798,13 +1794,11 @@ cSampleManager::StartStreamedFile(uint8 nFile, uint32 nPos, uint8 nStream) 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 { @@ -1825,13 +1819,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; @@ -1855,13 +1847,11 @@ cSampleManager::StartStreamedFile(uint8 nFile, uint32 nPos, uint8 nStream) 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 { @@ -1884,6 +1874,9 @@ cSampleManager::StopStreamedFile(uint8 nStream) { delete stream; aStream[nStream] = NULL; + + if ( nStream == 0 ) + _bIsMp3Active = false; } } @@ -1896,7 +1889,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; @@ -1963,6 +1970,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 7c3b30a7..4bbc3dde 100644 --- a/src/audio/soundlist.h +++ b/src/audio/soundlist.h @@ -160,7 +160,7 @@ enum eSound 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, |