X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fengine%2Fe_sound_al.inc;h=53ee47e63a9e351ffefbf73209d094305eddfdd3;hb=0e101bd452c40da601236aaa2dd4106be47ddce1;hp=312b701bed68abae6a4cc1c31cfffd0cd2fed1bb;hpb=1091a54dd9996ee2bc7620dfed900d64d066af88;p=d2df-sdl.git diff --git a/src/engine/e_sound_al.inc b/src/engine/e_sound_al.inc index 312b701..53ee47e 100644 --- a/src/engine/e_sound_al.inc +++ b/src/engine/e_sound_al.inc @@ -2,8 +2,7 @@ * * 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 - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * the Free Software Foundation, version 3 of the License ONLY. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -91,13 +90,15 @@ procedure e_SoundUpdate(); var e_SoundFormat: TSoundFormat; // desired sound format e_SoundsArray: array of TSoundRec = nil; - e_ZeroPosition: array [0..2] of ALfloat; + e_ZeroPosition: array [0..2] of ALfloat = (0, 0, 0); e_ALError: ALenum = 0; + e_SoundFont: string = ''; + e_MusicLerp: Boolean = True; implementation uses - g_window, g_options, utils; + g_options, utils; const NUM_SOURCES = 255; // + 1 stereo @@ -288,6 +289,8 @@ begin exit; end; + Loader.Looping := e_SoundsArray[find_id].Loops; + if not Loader.Load(FileName, e_SoundsArray[find_id].isMusic) then begin e_LogWritefln('Could not load sound `%s`', [FileName]); @@ -329,7 +332,6 @@ begin end else begin - Loader.Looping := e_SoundsArray[find_id].Loops; e_SoundsArray[find_id].alBuffer := 0; e_SoundsArray[find_id].Loader := Loader; end; @@ -362,6 +364,8 @@ begin exit; end; + Loader.Looping := e_SoundsArray[find_id].Loops; + if not Loader.Load(pData, LongWord(Length), e_SoundsArray[find_id].isMusic) then begin e_LogWritefln('Could not load sound `%p`', [pData]); @@ -403,11 +407,12 @@ begin end else begin - Loader.Looping := e_SoundsArray[find_id].Loops; e_SoundsArray[find_id].alBuffer := 0; e_SoundsArray[find_id].Loader := Loader; end; + // the calling side won't free this, the loader will get a copy, so fuck it + FreeMem(pData); ID := find_id; Result := True; end; @@ -449,6 +454,8 @@ begin end; procedure AssignSound(ID: DWORD; Src: ALuint); inline; +var + S: ALint; begin alGetError(); // reset error state @@ -457,8 +464,17 @@ begin // this is a stream // reset position e_SoundsArray[ID].Loader.SetPosition(0); - if CurStream <> ID then // changing streams, stop the thing just in case - alSourceStop(Src); + if CurStream <> ID then // changing streams + begin + alSourceStop(Src); // this should mark all buffers as processed + alGetSourcei(Src, AL_BUFFERS_PROCESSED, S); + // unqueue all buffers + if S > 0 then + begin + alSourceUnqueueBuffers(Src, S, @alStreamBufs[alStreamAvail]); + alStreamAvail := NUM_STREAM_BUFFERS; + end; + end; // this shit is playing now CurStream := ID; end @@ -496,6 +512,8 @@ begin if Result >= 0 then begin Pos[0] := Pan; + Pos[1] := 0; + Pos[2] := 0; AssignSound(ID, alSources[Result]); alSourcef(alSources[Result], AL_GAIN, 1); alSourcefv(alSources[Result], AL_POSITION, Pos); @@ -523,6 +541,8 @@ begin if Result >= 0 then begin Pos[0] := Pan; + Pos[1] := 0; + Pos[2] := 0; AssignSound(ID, alSources[Result]); alSourcefv(alSources[Result], AL_POSITION, Pos); alSourcef(alSources[Result], AL_GAIN, Volume); @@ -798,7 +818,7 @@ end; function TBasicSound.GetPan(): Single; var - Pos: array [0..2] of ALfloat; + Pos: array [0..2] of ALfloat = (0, 0, 0); begin Result := 0.0; if InvalidSource() then @@ -814,6 +834,8 @@ begin if InvalidSource() then Exit; Pos[0] := Pan; + Pos[1] := 0; + Pos[2] := 0; alSourcefv(alSources[FSource], AL_POSITION, Pos); end;