From: fgsfds Date: Wed, 1 May 2019 17:07:15 +0000 (+0300) Subject: can load non-looping music; fixed looping ROUNDMUS X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=5ec745243230db4b74820b894755e9f1eab0da4c;p=d2df-sdl.git can load non-looping music; fixed looping ROUNDMUS --- diff --git a/src/engine/e_sound_fmod.inc b/src/engine/e_sound_fmod.inc index d0db4fe..36d4932 100644 --- a/src/engine/e_sound_fmod.inc +++ b/src/engine/e_sound_fmod.inc @@ -68,8 +68,8 @@ const function e_InitSoundSystem(NoOutput: Boolean = False): Boolean; -function e_LoadSound(FileName: string; var ID: DWORD; bLoop: Boolean): Boolean; -function e_LoadSoundMem(pData: Pointer; Length: Integer; var ID: DWORD; bLoop: Boolean): Boolean; +function e_LoadSound(FileName: string; var ID: DWORD; isMusic: Boolean; ForceNoLoop: Boolean = False): Boolean; +function e_LoadSoundMem(pData: Pointer; Length: Integer; var ID: DWORD; isMusic: Boolean; ForceNoLoop: Boolean = False): Boolean; function e_PlaySound(ID: DWORD): Integer; function e_PlaySoundPan(ID: DWORD; Pan: Single): Integer; @@ -286,7 +286,7 @@ begin end; end; -function e_LoadSound(FileName: String; var ID: DWORD; bLoop: Boolean): Boolean; +function e_LoadSound(FileName: String; var ID: DWORD; isMusic: Boolean; ForceNoLoop: Boolean = False): Boolean; var find_id: DWORD; res: FMOD_RESULT; @@ -300,12 +300,12 @@ begin find_id := FindESound(); - if bLoop then + if isMusic and not ForceNoLoop then bt := FMOD_LOOP_NORMAL else bt := FMOD_LOOP_OFF; - if not bLoop then + if not isMusic then res := FMOD_System_CreateSound(F_System, PAnsiChar(FileName), bt + FMOD_2D + FMOD_HARDWARE, nil, e_SoundsArray[find_id].Sound) @@ -329,7 +329,7 @@ begin end; e_SoundsArray[find_id].Data := nil; - e_SoundsArray[find_id].isMusic := bLoop; + e_SoundsArray[find_id].isMusic := isMusic; e_SoundsArray[find_id].nRefs := 0; ID := find_id; @@ -337,7 +337,7 @@ begin Result := True; end; -function e_LoadSoundMem(pData: Pointer; Length: Integer; var ID: DWORD; bLoop: Boolean): Boolean; +function e_LoadSoundMem(pData: Pointer; Length: Integer; var ID: DWORD; isMusic: Boolean; ForceNoLoop: Boolean = False): Boolean; var find_id: DWORD; res: FMOD_RESULT; @@ -356,12 +356,12 @@ begin soundExInfo.cbsize := sz; soundExInfo.length := Length; - if bLoop then + if isMusic and not ForceNoLoop then bt := FMOD_LOOP_NORMAL else bt := FMOD_LOOP_OFF; - if not bLoop then + if not isMusic then res := FMOD_System_CreateSound(F_System, pData, bt + FMOD_2D + FMOD_HARDWARE + FMOD_OPENMEMORY, @soundExInfo, e_SoundsArray[find_id].Sound) @@ -385,7 +385,7 @@ begin end; e_SoundsArray[find_id].Data := pData; - e_SoundsArray[find_id].isMusic := bLoop; + e_SoundsArray[find_id].isMusic := isMusic; e_SoundsArray[find_id].nRefs := 0; ID := find_id; diff --git a/src/engine/e_sound_sdl.inc b/src/engine/e_sound_sdl.inc index ade8262..eb42c8b 100644 --- a/src/engine/e_sound_sdl.inc +++ b/src/engine/e_sound_sdl.inc @@ -28,6 +28,7 @@ type Sound: PMix_Chunk; Music: PMix_Music; isMusic: Boolean; + Loops: Boolean; nRefs: Integer; end; @@ -71,8 +72,8 @@ const function e_InitSoundSystem(NoOutput: Boolean = False): Boolean; -function e_LoadSound(FileName: string; var ID: DWORD; isMusic: Boolean): Boolean; -function e_LoadSoundMem(pData: Pointer; Length: Integer; var ID: DWORD; isMusic: Boolean): Boolean; +function e_LoadSound(FileName: string; var ID: DWORD; isMusic: Boolean; ForceNoLoop: Boolean = False): Boolean; +function e_LoadSoundMem(pData: Pointer; Length: Integer; var ID: DWORD; isMusic: Boolean; ForceNoLoop: Boolean = False): Boolean; // returns channel number or -1 function e_PlaySound(ID: DWORD): Integer; @@ -283,7 +284,7 @@ begin end; end; -function e_LoadSound(FileName: String; var ID: DWORD; isMusic: Boolean): Boolean; +function e_LoadSound(FileName: String; var ID: DWORD; isMusic: Boolean; ForceNoLoop: Boolean = False): Boolean; var find_id: DWORD; begin @@ -306,6 +307,7 @@ begin e_SoundsArray[find_id].Data := nil; e_SoundsArray[find_id].isMusic := isMusic; + e_SoundsArray[find_id].Loops := isMusic and not ForceNoLoop; e_SoundsArray[find_id].nRefs := 0; if isMusic then @@ -331,7 +333,7 @@ begin Result := True; end; -function e_LoadSoundMem(pData: Pointer; Length: Integer; var ID: DWORD; isMusic: Boolean): Boolean; +function e_LoadSoundMem(pData: Pointer; Length: Integer; var ID: DWORD; isMusic: Boolean; ForceNoLoop: Boolean = False): Boolean; var find_id: DWORD; rw: PSDL_RWops; @@ -372,6 +374,7 @@ begin e_SoundsArray[find_id].Data := pData; if isid3 then e_SoundsArray[find_id].Data := nil; e_SoundsArray[find_id].isMusic := isMusic; + e_SoundsArray[find_id].Loops := isMusic and not ForceNoLoop; e_SoundsArray[find_id].nRefs := 0; if isMusic then @@ -416,6 +419,7 @@ end; function e_PlaySound (ID: DWORD): Integer; var res: Integer = -1; + loops: Integer = 0; begin Result := -1; if not SoundInitialized then Exit; @@ -424,7 +428,8 @@ begin begin if e_SoundsArray[ID].nRefs >= gMaxSimSounds then Exit; Inc(e_SoundsArray[ID].nRefs); - res := Mix_PlayChannel(-1, e_SoundsArray[ID].Sound, 0); + if e_SoundsArray[ID].Loops then loops := -1; + res := Mix_PlayChannel(-1, e_SoundsArray[ID].Sound, loops); if res >= 0 then begin ChanSIds[res].id := ID; @@ -442,7 +447,8 @@ begin begin if not e_isMusic(ID) then Exit; Mix_HaltMusic(); - res := Mix_PlayMusic(e_SoundsArray[ID].Music, -1); + if e_SoundsArray[ID].Loops then loops := -1; + res := Mix_PlayMusic(e_SoundsArray[ID].Music, loops); if res >= 0 then res := N_MUSCHAN; if SoundMuted then Mix_VolumeMusic(0) else Mix_VolumeMusic(MusVolume); Result := res; diff --git a/src/game/g_game.pas b/src/game/g_game.pas index d8aab5c..081d97e 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -1324,7 +1324,7 @@ begin g_Game_SetLoadingText(_lc[I_LOAD_MUSIC], 0, False); g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD+':MUSIC\INTERMUS', True); g_Sound_CreateWADEx('MUSIC_MENU', GameWAD+':MUSIC\MENU', True); - g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD+':MUSIC\ROUNDMUS', True); + g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD+':MUSIC\ROUNDMUS', True, True); g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD+':MUSIC\ENDMUS', True); g_Game_SetLoadingText(_lc[I_LOAD_MENUS], 0, False); diff --git a/src/game/g_sound.pas b/src/game/g_sound.pas index ad514c1..094df0f 100644 --- a/src/game/g_sound.pas +++ b/src/game/g_sound.pas @@ -71,9 +71,9 @@ function g_Sound_PlayAt(ID: DWORD; X, Y: Integer): Boolean; function g_Sound_PlayExAt(SoundName: ShortString; X, Y: Integer): Boolean; function g_Sound_CreateWAD(var ID: DWORD; Resource: string; isMusic: Boolean = False): Boolean; -function g_Sound_CreateWADEx(SoundName: ShortString; Resource: string; isMusic: Boolean = False): Boolean; +function g_Sound_CreateWADEx(SoundName: ShortString; Resource: string; isMusic: Boolean = False; ForceNoLoop: Boolean = False): Boolean; function g_Sound_CreateFile(var ID: DWORD; FileName: string; isMusic: Boolean = False): Boolean; -function g_Sound_CreateFileEx(SoundName: ShortString; FileName: string; isMusic: Boolean = False): Boolean; +function g_Sound_CreateFileEx(SoundName: ShortString; FileName: string; isMusic: Boolean = False; ForceNoLoop: Boolean = False): Boolean; procedure g_Sound_Delete(SoundName: ShortString); function g_Sound_Exists(SoundName: string): Boolean; @@ -276,7 +276,7 @@ begin Result := e_LoadSound(FileName, ID, isMusic); end; -function g_Sound_CreateFileEx(SoundName: ShortString; FileName: string; isMusic: Boolean = False): Boolean; +function g_Sound_CreateFileEx(SoundName: ShortString; FileName: string; isMusic: Boolean = False; ForceNoLoop: Boolean = False): Boolean; var find_id: DWORD; begin @@ -284,7 +284,7 @@ begin find_id := FindSound(); - if not e_LoadSound(FileName, SoundArray[find_id].ID, isMusic) then + if not e_LoadSound(FileName, SoundArray[find_id].ID, isMusic, ForceNoLoop) then Exit; SoundArray[find_id].Name := SoundName; @@ -336,7 +336,7 @@ begin Result := True; end; -function g_Sound_CreateWADEx(SoundName: ShortString; Resource: string; isMusic: Boolean = False): Boolean; +function g_Sound_CreateWADEx(SoundName: ShortString; Resource: string; isMusic: Boolean = False; ForceNoLoop: Boolean = False): Boolean; var WAD: TWADFile; FileName: string; @@ -358,7 +358,7 @@ begin if WAD.GetResource(g_ExtractFilePathName(Resource), SoundData, ResLength) then begin - if e_LoadSoundMem(SoundData, ResLength, SoundArray[find_id].ID, isMusic) then + if e_LoadSoundMem(SoundData, ResLength, SoundArray[find_id].ID, isMusic, ForceNoLoop) then begin SoundArray[find_id].Name := SoundName; SoundArray[find_id].IsMusic := isMusic;