X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fengine%2Fe_sound_fmod.inc;h=36d4932387d1f73e120a12368b460dc9079aba10;hb=5ec745243230db4b74820b894755e9f1eab0da4c;hp=430735c7c6ae56761d2fdd5713a0665f9eed31a7;hpb=5472594f32e33da0c66606ec9eebc8f798ef6b54;p=d2df-sdl.git diff --git a/src/engine/e_sound_fmod.inc b/src/engine/e_sound_fmod.inc index 430735c..36d4932 100644 --- a/src/engine/e_sound_fmod.inc +++ b/src/engine/e_sound_fmod.inc @@ -1,4 +1,4 @@ -(* Copyright (C) DooM 2D:Forever Developers +(* Copyright (C) Doom 2D: Forever Developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,6 +19,7 @@ uses fmod, fmodtypes, fmoderrors, + {$IFDEF USE_MEMPOOL}mempool,{$ENDIF} e_log, SysUtils; @@ -30,7 +31,7 @@ type nRefs: Integer; end; - TBasicSound = class (TObject) + TBasicSound = class{$IFDEF USE_MEMPOOL}(TPoolObject){$ENDIF} private FChannel: FMOD_CHANNEL; @@ -67,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; @@ -90,7 +91,7 @@ var implementation uses - g_window, g_options, BinEditor; + g_window, g_options, utils; const N_CHANNELS = 512; @@ -132,19 +133,19 @@ end; function TryInitWithOutput(Output: FMOD_OUTPUTTYPE; OutputName: String): FMOD_RESULT; begin - e_WriteLog('Trying with ' + OutputName + '...', MSG_WARNING); + e_WriteLog('Trying with ' + OutputName + '...', TMsgType.Warning); Result := FMOD_System_SetOutput(F_System, Output); if Result <> FMOD_OK then begin - e_WriteLog('Error setting FMOD output to ' + OutputName + '!', MSG_WARNING); - e_WriteLog(FMOD_ErrorString(Result), MSG_WARNING); + e_WriteLog('Error setting FMOD output to ' + OutputName + '!', TMsgType.Warning); + e_WriteLog(FMOD_ErrorString(Result), TMsgType.Warning); Exit; end; Result := FMOD_System_Init(F_System, N_CHANNELS, FMOD_INIT_NORMAL, nil); if Result <> FMOD_OK then begin - e_WriteLog('Error initializing FMOD system!', MSG_WARNING); - e_WriteLog(FMOD_ErrorString(Result), MSG_WARNING); + e_WriteLog('Error initializing FMOD system!', TMsgType.Warning); + e_WriteLog(FMOD_ErrorString(Result), TMsgType.Warning); Exit; end; end; @@ -158,35 +159,35 @@ var begin Result := False; - e_WriteLog(Format('Trying to initialize FMOD with %d', [Freq]), MSG_NOTIFY); + e_WriteLog(Format('Trying to initialize FMOD with %d', [Freq]), TMsgType.Notify); res := FMOD_System_Create(F_System); if res <> FMOD_OK then begin - e_WriteLog('Error creating FMOD system:', MSG_FATALERROR); - e_WriteLog(FMOD_ErrorString(res), MSG_FATALERROR); + e_WriteLog('Error creating FMOD system:', TMsgType.Fatal); + e_WriteLog(FMOD_ErrorString(res), TMsgType.Fatal); Exit; end; res := FMOD_System_GetVersion(F_System, ver); if res <> FMOD_OK then begin - e_WriteLog('Error getting FMOD version:', MSG_FATALERROR); - e_WriteLog(FMOD_ErrorString(res), MSG_FATALERROR); + e_WriteLog('Error getting FMOD version:', TMsgType.Fatal); + e_WriteLog(FMOD_ErrorString(res), TMsgType.Fatal); Exit; end; if ver < FMOD_VERSION then begin - e_WriteLog('FMOD library version is too old! Need '+IntToStr(FMOD_VERSION), MSG_FATALERROR); + e_WriteLog('FMOD library version is too old! Need '+IntToStr(FMOD_VERSION), TMsgType.Fatal); Exit; end; res := FMOD_System_SetSoftwareFormat(F_System, Freq, FMOD_SOUND_FORMAT_PCM16, 0, 0, FMOD_DSP_RESAMPLER_LINEAR); if res <> FMOD_OK then begin - e_WriteLog('Error setting FMOD software format!', MSG_FATALERROR); - e_WriteLog(FMOD_ErrorString(res), MSG_FATALERROR); + e_WriteLog('Error setting FMOD software format!', TMsgType.Fatal); + e_WriteLog(FMOD_ErrorString(res), TMsgType.Fatal); Exit; end; @@ -195,7 +196,7 @@ begin res := TryInitWithOutput(FMOD_OUTPUTTYPE_NOSOUND, 'OUTPUTTYPE_NOSOUND'); if res <> FMOD_OK then begin - e_WriteLog('FMOD: Giving up, can''t init with NOSOUND.', MSG_FATALERROR); + e_WriteLog('FMOD: Giving up, can''t init with NOSOUND.', TMsgType.Fatal); Exit; end; end @@ -204,8 +205,8 @@ begin res := FMOD_System_Init(F_System, N_CHANNELS, FMOD_INIT_NORMAL, nil); if res <> FMOD_OK then begin - e_WriteLog('Error initializing FMOD system!', MSG_WARNING); - e_WriteLog(FMOD_ErrorString(res), MSG_WARNING); + e_WriteLog('Error initializing FMOD system!', TMsgType.Warning); + e_WriteLog(FMOD_ErrorString(res), TMsgType.Warning); {$IFDEF LINUX} res := TryInitWithOutput(FMOD_OUTPUTTYPE_ALSA, 'OUTPUTTYPE_ALSA'); @@ -217,7 +218,7 @@ begin res := TryInitWithOutput(FMOD_OUTPUTTYPE_NOSOUND, 'OUTPUTTYPE_NOSOUND'); if res <> FMOD_OK then begin - e_WriteLog('FMOD: Giving up, can''t init any output.', MSG_FATALERROR); + e_WriteLog('FMOD: Giving up, can''t init any output.', TMsgType.Fatal); Exit; end; end; @@ -225,26 +226,26 @@ begin res := FMOD_System_GetOutput(F_System, output); if res <> FMOD_OK then - e_WriteLog('Error getting FMOD output!', MSG_WARNING) + e_WriteLog('Error getting FMOD output!', TMsgType.Warning) else case output of - FMOD_OUTPUTTYPE_NOSOUND: e_WriteLog('FMOD Output Method: NOSOUND', MSG_NOTIFY); - FMOD_OUTPUTTYPE_NOSOUND_NRT: e_WriteLog('FMOD Output Method: NOSOUND_NRT', MSG_NOTIFY); - FMOD_OUTPUTTYPE_DSOUND: e_WriteLog('FMOD Output Method: DSOUND', MSG_NOTIFY); - FMOD_OUTPUTTYPE_WINMM: e_WriteLog('FMOD Output Method: WINMM', MSG_NOTIFY); - FMOD_OUTPUTTYPE_OPENAL: e_WriteLog('FMOD Output Method: OPENAL', MSG_NOTIFY); - FMOD_OUTPUTTYPE_WASAPI: e_WriteLog('FMOD Output Method: WASAPI', MSG_NOTIFY); - FMOD_OUTPUTTYPE_ASIO: e_WriteLog('FMOD Output Method: ASIO', MSG_NOTIFY); - FMOD_OUTPUTTYPE_OSS: e_WriteLog('FMOD Output Method: OSS', MSG_NOTIFY); - FMOD_OUTPUTTYPE_ALSA: e_Writelog('FMOD Output Method: ALSA', MSG_NOTIFY); - else e_WriteLog('FMOD Output Method: Unknown', MSG_NOTIFY); + FMOD_OUTPUTTYPE_NOSOUND: e_WriteLog('FMOD Output Method: NOSOUND', TMsgType.Notify); + FMOD_OUTPUTTYPE_NOSOUND_NRT: e_WriteLog('FMOD Output Method: NOSOUND_NRT', TMsgType.Notify); + FMOD_OUTPUTTYPE_DSOUND: e_WriteLog('FMOD Output Method: DSOUND', TMsgType.Notify); + FMOD_OUTPUTTYPE_WINMM: e_WriteLog('FMOD Output Method: WINMM', TMsgType.Notify); + FMOD_OUTPUTTYPE_OPENAL: e_WriteLog('FMOD Output Method: OPENAL', TMsgType.Notify); + FMOD_OUTPUTTYPE_WASAPI: e_WriteLog('FMOD Output Method: WASAPI', TMsgType.Notify); + FMOD_OUTPUTTYPE_ASIO: e_WriteLog('FMOD Output Method: ASIO', TMsgType.Notify); + FMOD_OUTPUTTYPE_OSS: e_WriteLog('FMOD Output Method: OSS', TMsgType.Notify); + FMOD_OUTPUTTYPE_ALSA: e_Writelog('FMOD Output Method: ALSA', TMsgType.Notify); + else e_WriteLog('FMOD Output Method: Unknown', TMsgType.Notify); end; res := FMOD_System_GetDriver(F_System, drv); if res <> FMOD_OK then - e_WriteLog('Error getting FMOD driver!', MSG_WARNING) + e_WriteLog('Error getting FMOD driver!', TMsgType.Warning) else - e_WriteLog('FMOD driver id: '+IntToStr(drv), MSG_NOTIFY); + e_WriteLog('FMOD driver id: '+IntToStr(drv), TMsgType.Notify); Result := True; end; @@ -285,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; @@ -295,16 +296,16 @@ var begin Result := False; - e_WriteLog('Loading sound '+FileName+'...', MSG_NOTIFY); + e_WriteLog('Loading sound '+FileName+'...', TMsgType.Notify); 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) @@ -328,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; @@ -336,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; @@ -355,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) @@ -384,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; @@ -585,8 +586,8 @@ begin res := FMOD_Sound_Release(e_SoundsArray[ID].Sound); if res <> FMOD_OK then begin - e_WriteLog('Error releasing sound:', MSG_WARNING); - e_WriteLog(FMOD_ErrorString(res), MSG_WARNING); + e_WriteLog('Error releasing sound:', TMsgType.Warning); + e_WriteLog(FMOD_ErrorString(res), TMsgType.Warning); end; e_SoundsArray[ID].Sound := nil; @@ -701,16 +702,16 @@ begin res := FMOD_System_Close(F_System); if res <> FMOD_OK then begin - e_WriteLog('Error closing FMOD system!', MSG_FATALERROR); - e_WriteLog(FMOD_ErrorString(res), MSG_FATALERROR); + e_WriteLog('Error closing FMOD system!', TMsgType.Fatal); + e_WriteLog(FMOD_ErrorString(res), TMsgType.Fatal); Exit; end; res := FMOD_System_Release(F_System); if res <> FMOD_OK then begin - e_WriteLog('Error releasing FMOD system!', MSG_FATALERROR); - e_WriteLog(FMOD_ErrorString(res), MSG_FATALERROR); + e_WriteLog('Error releasing FMOD system!', TMsgType.Fatal); + e_WriteLog(FMOD_ErrorString(res), TMsgType.Fatal); end; end;