summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 89d242f)
raw | patch | inline | side by side (parent: 89d242f)
author | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Wed, 6 Apr 2016 23:14:57 +0000 (02:14 +0300) | ||
committer | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Wed, 6 Apr 2016 23:15:28 +0000 (02:15 +0300) |
src/engine/e_sound.pas | patch | blob | history | |
src/game/g_game.pas | patch | blob | history | |
src/game/g_sound.pas | patch | blob | history |
diff --git a/src/engine/e_sound.pas b/src/engine/e_sound.pas
index a173c883b65908ac1daeec908deca545b0a645af..deda06d56c59cb6efcc64fe90581e329a8a18f26 100644 (file)
--- a/src/engine/e_sound.pas
+++ b/src/engine/e_sound.pas
TSoundRec = record
Data: Pointer;
Sound: PMix_Chunk;
- Loop: Boolean;
+ Music: PMix_Music;
+ isMusic: Boolean;
end;
TBasicSound = class (TObject)
protected
FID: DWORD;
- FLoop: Boolean;
+ FMusic: Boolean;
FPosition: DWORD;
FPriority: Integer;
function e_InitSoundSystem(): 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): Boolean;
+function e_LoadSoundMem(pData: Pointer; Length: Integer; var ID: DWORD; isMusic: Boolean): Boolean;
// returns channel number or -1
function e_PlaySound(ID: DWORD): Integer;
const
N_CHANNELS = 512;
+ N_MUSCHAN = N_CHANNELS+42;
var
SoundMuted: Boolean = False;
Result := False;
SoundInitialized := False;
+{ // wow, this is actually MIDI player!
// we need module player
if (Mix_Init(MIX_INIT_MOD) and MIX_INIT_MOD) <> MIX_INIT_MOD then
begin
e_WriteLog(Mix_GetError(), MSG_FATALERROR);
//Exit;
end;
+}
res := Mix_OpenAudio(44100, AUDIO_S16LSB, 2, 512);
if res = -1 then
Result := True;
end;
+function e_isMusic (id: DWORD): Boolean;
+begin
+ Result := False;
+ if (e_SoundsArray <> nil) and (id <= High(e_SoundsArray)) then
+ begin
+ Result := (e_SoundsArray[id].Music <> nil);
+ end;
+end;
+
+function e_isSound (id: DWORD): Boolean;
+begin
+ Result := False;
+ if (e_SoundsArray <> nil) and (id <= High(e_SoundsArray)) then
+ begin
+ Result := (e_SoundsArray[id].Sound <> nil);
+ end;
+end;
+
function FindESound(): DWORD;
var
i: Integer;
-
begin
if e_SoundsArray <> nil then
for i := 0 to High(e_SoundsArray) do
- if e_SoundsArray[i].Sound = nil then
+ if (e_SoundsArray[i].Sound = nil) and (e_SoundsArray[i].Music = nil) then
begin
Result := i;
Exit;
end;
end;
-function e_LoadSound(FileName: String; var ID: DWORD; bLoop: Boolean): Boolean;
+function e_LoadSound(FileName: String; var ID: DWORD; isMusic: Boolean): Boolean;
var
find_id: DWORD;
begin
Result := False;
if not SoundInitialized then Exit;
- e_WriteLog('Loading sound '+FileName+'...', MSG_NOTIFY);
+ if isMusic then e_WriteLog('Loading music '+FileName+'...', MSG_NOTIFY)
+ else e_WriteLog('Loading sound '+FileName+'...', MSG_NOTIFY);
find_id := FindESound();
- e_SoundsArray[find_id].Sound := Mix_LoadWAV(PAnsiChar(FileName));
- if e_SoundsArray[find_id].Sound = nil then Exit;
-
e_SoundsArray[find_id].Data := nil;
- e_SoundsArray[find_id].Loop := bLoop;
+ e_SoundsArray[find_id].isMusic := isMusic;
+
+ if isMusic then
+ begin
+ e_SoundsArray[find_id].Music := Mix_LoadMUS(PAnsiChar(FileName));
+ if e_SoundsArray[find_id].Music = nil then Exit;
+ end
+ else
+ begin
+ e_SoundsArray[find_id].Sound := Mix_LoadWAV(PAnsiChar(FileName));
+ if e_SoundsArray[find_id].Sound = nil then Exit;
+ end;
ID := find_id;
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): Boolean;
var
find_id: DWORD;
rw: PSDL_RWops;
find_id := FindESound();
- e_SoundsArray[find_id].Sound := Mix_LoadWAV_RW(rw, 0);
- SDL_FreeRW(rw);
- if e_SoundsArray[find_id].Sound = nil then Exit;
-
e_SoundsArray[find_id].Data := pData;
- e_SoundsArray[find_id].Loop := bLoop;
+ e_SoundsArray[find_id].isMusic := isMusic;
+
+ if isMusic then
+ begin
+ e_SoundsArray[find_id].Music := Mix_LoadMUS_RW(rw, 0);
+ end
+ else
+ begin
+ e_SoundsArray[find_id].Sound := Mix_LoadWAV_RW(rw, 0);
+ end;
+ SDL_FreeRW(rw);
+ if (e_SoundsArray[find_id].Sound = nil) and (e_SoundsArray[find_id].Music = nil) then Exit;
ID := find_id;
function e_PlaySound (ID: DWORD): Integer;
var
- res: Integer;
+ res: Integer = -1;
begin
Result := -1;
if not SoundInitialized then Exit;
- if {(e_SoundsArray[ID].nRefs >= gMaxSimSounds) or} (e_SoundsArray[ID].Sound = nil) then Exit;
+ if {(e_SoundsArray[ID].nRefs >= gMaxSimSounds) or} (e_SoundsArray[ID].Sound = nil) and (e_SoundsArray[ID].Music = nil) then Exit;
+
+ if e_SoundsArray[ID].Music <> nil then
+ begin
+ res := Mix_PlayMusic(e_SoundsArray[ID].Music, -1);
+ if res >= 0 then res := N_MUSCHAN;
+ Result := res;
+ Exit;
+ end;
- if e_SoundsArray[ID].Loop then
+ if e_SoundsArray[ID].Sound <> nil then
+ res := Mix_PlayChannel(-1, e_SoundsArray[ID].Sound, 0);
+ {
+ if e_SoundsArray[ID].isMusic then
res := Mix_PlayChannel(-1, e_SoundsArray[ID].Sound, -1)
else
res := Mix_PlayChannel(-1, e_SoundsArray[ID].Sound, 0);
+ }
if SoundMuted and (res >= 0) then Mix_Volume(res, 0);
begin
Result := -1;
chan := e_PlaySound(ID);
- if chan < 0 then Exit;
-
- if not SoundMuted then
- if Pan < -1.0 then Pan := -1.0 else if Pan > 1.0 then Pan := 1.0;
- Pan := Pan+1.0; // 0..2
- l := trunc(127.0*(2.0-Pan));
- r := trunc(127.0*Pan);
- Mix_SetPanning(chan, l, r);
-
+ if (chan >= 0) and (chan <> N_MUSCHAN) then
+ begin
+ if Pan < -1.0 then Pan := -1.0 else if Pan > 1.0 then Pan := 1.0;
+ Pan := Pan+1.0; // 0..2
+ l := trunc(127.0*(2.0-Pan));
+ r := trunc(127.0*Pan);
+ Mix_SetPanning(chan, l, r);
+ end;
Result := chan;
end;
begin
Result := -1;
chan := e_PlaySound(ID);
- if chan < 0 then Exit;
-
- if Volume < 0 then Volume := 0 else if Volume > 1 then Volume := 1;
- if not SoundMuted then Mix_Volume(chan, trunc(Volume*MIX_MAX_VOLUME));
-
+ if (chan >= 0) and (chan <> N_MUSCHAN) then
+ begin
+ if Volume < 0 then Volume := 0 else if Volume > 1 then Volume := 1;
+ if not SoundMuted then Mix_Volume(chan, trunc(Volume*MIX_MAX_VOLUME));
+ end;
Result := chan;
end;
begin
Result := -1;
chan := e_PlaySound(ID);
- if chan < 0 then Exit;
-
- if Pan < -1.0 then Pan := -1.0 else if Pan > 1.0 then Pan := 1.0;
- Pan := Pan+1.0; // 0..2
- l := trunc(127.0*(2.0-Pan));
- r := trunc(127.0*Pan);
- Mix_SetPanning(chan, l, r);
-
- if Volume < 0 then Volume := 0 else if Volume > 1 then Volume := 1;
- if not SoundMuted then Mix_Volume(chan, trunc(Volume*MIX_MAX_VOLUME));
-
+ if (chan >= 0) and (chan <> N_MUSCHAN) then
+ begin
+ if Pan < -1.0 then Pan := -1.0 else if Pan > 1.0 then Pan := 1.0;
+ Pan := Pan+1.0; // 0..2
+ l := trunc(127.0*(2.0-Pan));
+ r := trunc(127.0*Pan);
+ Mix_SetPanning(chan, l, r);
+ if Volume < 0 then Volume := 0 else if Volume > 1 then Volume := 1;
+ if not SoundMuted then Mix_Volume(chan, trunc(Volume*MIX_MAX_VOLUME));
+ end;
Result := chan;
end;
procedure e_DeleteSound(ID: DWORD);
begin
- if e_SoundsArray[ID].Sound = nil then Exit;
+ if (e_SoundsArray[ID].Sound = nil) and (e_SoundsArray[ID].Music = nil) then Exit;
if e_SoundsArray[ID].Data <> nil then FreeMem(e_SoundsArray[ID].Data);
- Mix_FreeChunk(e_SoundsArray[ID].Sound);
+ if e_SoundsArray[ID].Sound <> nil then Mix_FreeChunk(e_SoundsArray[ID].Sound);
+ if e_SoundsArray[ID].Music <> nil then Mix_FreeMusic(e_SoundsArray[ID].Music);
e_SoundsArray[ID].Sound := nil;
+ e_SoundsArray[ID].Music := nil;
e_SoundsArray[ID].Data := nil;
end;
procedure e_StopChannels();
begin
Mix_HaltChannel(-1);
+ Mix_HaltMusic();
end;
procedure e_RemoveAllSounds();
constructor TBasicSound.Create();
begin
FID := NO_SOUND_ID;
- FLoop := False;
+ FMusic := False;
FChannel := -1;
FPosition := 0;
FPriority := 128;
if FID = NO_SOUND_ID then Exit;
Stop();
FID := NO_SOUND_ID;
- FLoop := False;
+ FMusic := False;
FPosition := 0;
end;
// aPos: msecs
function TBasicSound.RawPlay(Pan: Single; Volume: Single; aPos: DWORD): Boolean;
-var
- oldloop: Boolean;
begin
Result := False;
if (FID = NO_SOUND_ID) or not SoundInitialized then Exit;
- oldloop := e_SoundsArray[FID].Loop;
- e_SoundsArray[FID].Loop := FLoop;
Result := (e_PlaySoundPanVolume(FID, Pan, Volume) >= 0);
- e_SoundsArray[FID].Loop := oldloop;
//TODO: aPos
end;
begin
FreeSound();
FID := ID;
- FLoop := e_SoundsArray[ID].Loop;
+ FMusic := e_SoundsArray[ID].isMusic;
end;
function TBasicSound.IsPlaying(): Boolean;
begin
Result := False;
if FChannel < 0 then Exit;
- Result := (Mix_Playing(FChannel) > 0);
+ if e_isSound(FID) then Result := (Mix_Playing(FChannel) > 0)
+ else Result := (Mix_PlayingMusic() > 0);
end;
procedure TBasicSound.Stop();
begin
if FChannel < 0 then Exit;
//GetPosition();
- Mix_HaltChannel(FChannel);
+ if e_isSound(FID) then Mix_HaltChannel(FChannel) else Mix_HaltMusic();
FChannel := -1;
end;
begin
Result := False;
if FChannel < 0 then Exit;
- Result := (Mix_Paused(FChannel) > 0);
+ if e_isSound(FID) then Result := (Mix_Paused(FChannel) > 0) else Result := (Mix_PausedMusic() > 0);
end;
procedure TBasicSound.Pause(Enable: Boolean);
begin
if FChannel < 0 then Exit;
- if Mix_Paused(FChannel) > 0 then
+ if IsPaused() then
begin
- if Enable then Mix_Resume(FChannel);
+ if Enable then
+ begin
+ if e_isSound(FID) then Mix_Resume(FChannel) else Mix_ResumeMusic();
+ end;
end
else
begin
- if not Enable then Mix_Pause(FChannel);
+ if not Enable then
+ begin
+ if e_isSound(FID) then Mix_Pause(FChannel) else Mix_PauseMusic();
+ end;
end;
{
if Enable then
procedure TBasicSound.SetVolume(Volume: Single);
begin
if FChannel < 0 then Exit;
-
if Volume < 0 then Volume := 0 else if Volume > 1 then Volume := 1;
- Mix_Volume(FChannel, trunc(Volume*MIX_MAX_VOLUME));
+ if e_isSound(FID) then Mix_Volume(FChannel, trunc(Volume*MIX_MAX_VOLUME))
+ else Mix_VolumeMusic(trunc(Volume*MIX_MAX_VOLUME))
end;
//TODO
l, r: UInt8;
begin
if FChannel < 0 then Exit;
-
+ if not e_isSound(FID) then Exit;
if Pan < -1.0 then Pan := -1.0 else if Pan > 1.0 then Pan := 1.0;
Pan := Pan+1.0; // 0..2
l := trunc(127.0*(2.0-Pan));
diff --git a/src/game/g_game.pas b/src/game/g_game.pas
index 66d277443a50e8f511fd8d0f254685a493b25b80..9382a151881f02a2c7822c414b75abe3dce629d4 100644 (file)
--- a/src/game/g_game.pas
+++ b/src/game/g_game.pas
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');
+ g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD+':MUSIC\ROUNDMUS', 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 ebce17eb3da8bd509dc7c31ef2e4c850ccbee0e2..55098850892c9b9e40c9079296181f58d87fea12 100644 (file)
--- a/src/game/g_sound.pas
+++ b/src/game/g_sound.pas
function SetByName(SN: String): Boolean;
function SetCoords(X, Y: Integer; Volume: Single): Boolean;
- property Loop: Boolean read FLoop write FLoop;
+ property Loop: Boolean read FMusic write FMusic;
property Name: String read FName;
end;