diff options
Diffstat (limited to '')
-rw-r--r-- | src/audio/sampman_miles.cpp | 147 |
1 files changed, 138 insertions, 9 deletions
diff --git a/src/audio/sampman_miles.cpp b/src/audio/sampman_miles.cpp index 70ea942e..6a7850d8 100644 --- a/src/audio/sampman_miles.cpp +++ b/src/audio/sampman_miles.cpp @@ -61,6 +61,7 @@ char _mp3DirectoryPath[MAX_PATH]; HSTREAM mp3Stream [MAX_STREAMS]; int8 nStreamPan [MAX_STREAMS]; int8 nStreamVolume[MAX_STREAMS]; +uint8 nStreamLoopedFlag[MAX_STREAMS]; uint32 _CurMP3Index; int32 _CurMP3Pos; bool _bIsMp3Active; @@ -264,10 +265,63 @@ set_new_provider(S32 index) return false; } +U32 RadioHandlers[9]; + +U32 WINAPI vfs_open_callback(char const* Filename, U32* FileHandle) +{ + *FileHandle = (U32)fopen(Filename, "rb"); + + // couldn't they just use stricmp once? and strlen? this is very inefficient + if ((strcmp(Filename + strlen(Filename) - 4, ".adf") == 0) || (strcmp(Filename + strlen(Filename) - 4, ".ADF") == 0)) { + for (int i = 0; i < ARRAY_SIZE(RadioHandlers); i++) { + if (RadioHandlers[i] == NULL) { + RadioHandlers[i] = *FileHandle; + break; + } + } + strcpy((char*)Filename + strlen(Filename) - 4, ".mp3"); + } + return *FileHandle; +} + +void WINAPI vfs_close_callback(U32 FileHandle) +{ + for (int i = 0; i < ARRAY_SIZE(RadioHandlers); i++) { + if (RadioHandlers[i] == FileHandle) { + RadioHandlers[i] = NULL; + break; + } + } + fclose((FILE*)FileHandle); +} + +S32 WINAPI vfs_seek_callback(U32 FileHandle, S32 Offset, U32 Type) +{ + fseek((FILE*)FileHandle, Offset, Type); + return ftell((FILE*)FileHandle); +} + +U32 WINAPI vfs_read_callback(U32 FileHandle, void* Buffer, U32 Bytes) +{ + fread(Buffer, Bytes, 1, (FILE*)FileHandle); + uint8* _Buffer = (uint8*)Buffer; + + for (int i = 0; i < ARRAY_SIZE(RadioHandlers); i++) { + if (FileHandle == RadioHandlers[i]) { + for (U32 k = 0; k < Bytes; k++) + _Buffer[k] ^= 0x22; + break; + } + } + return Bytes; +} + cSampleManager::cSampleManager(void) : m_nNumberOfProviders(0) { ; + + AIL_set_file_callbacks(vfs_open_callback, vfs_close_callback, vfs_seek_callback, vfs_read_callback); } cSampleManager::~cSampleManager(void) @@ -354,6 +408,63 @@ cSampleManager::SetCurrent3DProvider(uint8 nProvider) return curprovider; } +int8 +cSampleManager::AutoDetect3DProviders() +{ + if (!AudioManager.IsAudioInitialised()) + return -1; + + int eax = -1, eax2 = -1, eax3 = -1, ds3dh = -1, ds3ds = -1; + + for (uint32 i = 0; i < GetNum3DProvidersAvailable(); i++) + { + char* providername = Get3DProviderName(i); + + if (!strcasecmp(providername, "CREATIVE LABS EAX (TM)")) { + AudioManager.SetCurrent3DProvider(i); + if (GetCurrent3DProviderIndex() == i) + eax = i; + } + + if (!strcasecmp(providername, "CREATIVE LABS EAX 2 (TM)")) { + AudioManager.SetCurrent3DProvider(i); + if (GetCurrent3DProviderIndex() == i) + eax2 = i; + } + + if (!strcasecmp(providername, "CREATIVE LABS EAX 3 (TM)")) { + AudioManager.SetCurrent3DProvider(i); + if (GetCurrent3DProviderIndex() == i) { + eax3 = i; + } + } + + if (!strcasecmp(providername, "DIRECTSOUND3D HARDWARE SUPPORT")) { + AudioManager.SetCurrent3DProvider(i); + if (GetCurrent3DProviderIndex() == i) + ds3dh = i; + } + + if (!strcasecmp(providername, "DIRECTSOUND3D SOFTWARE EMULATION")) { + AudioManager.SetCurrent3DProvider(i); + if (GetCurrent3DProviderIndex() == i) + ds3ds = i; + } + } + + if (eax3 != -1) + return eax3; + if (eax2 != -1) + return eax2; + if (eax != -1) + return eax; + if (ds3dh != -1) + return ds3dh; + if (ds3ds != -1) + return ds3ds; + return -1; +} + static bool _ResolveLink(char const *path, char *out) { @@ -1403,6 +1514,12 @@ cSampleManager::SetMusicMasterVolume(uint8 nVolume) } void +cSampleManager::SetMP3BoostVolume(uint8 nVolume) +{ + m_nMP3BoostVolume = nVolume; +} + +void cSampleManager::SetEffectsFadeVolume(uint8 nVolume) { m_nEffectsFadeVolume = nVolume; @@ -1515,7 +1632,7 @@ cSampleManager::LoadPedComment(uint32 nComment) case MUSICMODE_FRONTEND: { - if ( MusicManager.GetCurrentTrack() == STREAMED_SOUND_GAME_COMPLETED ) + if ( MusicManager.GetCurrentTrack() == STREAMED_SOUND_CUTSCENE_FINALE ) return false; break; @@ -1754,8 +1871,7 @@ 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.GetCurrentTrack() != STREAMED_SOUND_CUTSCENE_FINALE ) { nChannelVolume[nChannel] >>= 2; } @@ -1793,8 +1909,7 @@ 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.GetCurrentTrack() != STREAMED_SOUND_CUTSCENE_FINALE ) { nChannelVolume[nChannel] >>= 2; } @@ -1994,7 +2109,7 @@ cSampleManager::StopChannel(uint32 nChannel) } void -cSampleManager::PreloadStreamedFile(uint8 nFile, uint8 nStream) +cSampleManager::PreloadStreamedFile(uint32 nFile, uint8 nStream) { if ( m_bInitialised ) { @@ -2045,7 +2160,7 @@ cSampleManager::StartPreloadedStreamedFile(uint8 nStream) } bool -cSampleManager::StartStreamedFile(uint8 nFile, uint32 nPos, uint8 nStream) +cSampleManager::StartStreamedFile(uint32 nFile, uint32 nPos, uint8 nStream) { uint32 position = nPos; char filename[MAX_PATH]; @@ -2081,7 +2196,8 @@ cSampleManager::StartStreamedFile(uint8 nFile, uint32 nPos, uint8 nStream) AIL_open_stream(DIG, filename, 0); if(mp3Stream[nStream]) { AIL_set_stream_loop_count( - mp3Stream[nStream], 1); + mp3Stream[nStream], nStreamLoopedFlag[nStream] ? 0 : 1); + nStreamLoopedFlag[nStream] = true; AIL_set_stream_ms_position( mp3Stream[nStream], position); AIL_pause_stream(mp3Stream[nStream], @@ -2251,7 +2367,12 @@ cSampleManager::SetStreamedVolumeAndPan(uint8 nVolume, uint8 nPan, uint8 nEffect if ( mp3Stream[nStream] ) { if ( nEffectFlag ) - AIL_set_stream_volume(mp3Stream[nStream], m_nEffectsFadeVolume*vol*m_nEffectsVolume >> 14); + { + if ( nStream == 1 ) // TODO(MIAMI): || nStream == 2 when we have second mission channel? + AIL_set_stream_volume(mp3Stream[nStream], 128*vol*m_nEffectsVolume >> 14); + else + AIL_set_stream_volume(mp3Stream[nStream], m_nEffectsFadeVolume*vol*m_nEffectsVolume >> 14); + } else AIL_set_stream_volume(mp3Stream[nStream], m_nMusicFadeVolume*vol*m_nMusicVolume >> 14); @@ -2331,4 +2452,12 @@ cSampleManager::InitialiseSampleBanks(void) return true; } + +void +cSampleManager::SetStreamedFileLoopFlag(uint8 nLoopFlag, uint8 nChannel) +{ + if (m_bInitialised) + nStreamLoopedFlag[nChannel] = nLoopFlag; +} + #endif
\ No newline at end of file |