X-Git-Url: http://deadsoftware.ru/gitweb?p=d2df-sdl.git;a=blobdiff_plain;f=src%2Fengine%2Fe_sound_sdl.inc;h=f71805ef50324de7d8d9b171871d7a783605753a;hp=4d9eaba5d983da5fc644b7255be1923dfcce928f;hb=59b0e5dfe65548c5fa24cc64136417c37b495573;hpb=0e101bd452c40da601236aaa2dd4106be47ddce1 diff --git a/src/engine/e_sound_sdl.inc b/src/engine/e_sound_sdl.inc index 4d9eaba..f71805e 100644 --- a/src/engine/e_sound_sdl.inc +++ b/src/engine/e_sound_sdl.inc @@ -16,8 +16,16 @@ interface uses {$IFDEF USE_MEMPOOL}mempool,{$ENDIF} - SDL2, SDL2_mixer, - e_log, SysUtils; + {$IFDEF USE_SDL} + SDL, SDL_mixer, + {$DEFINE SDL1MIXER} + {$UNDEF SDL2MIXER} + {$ELSE} + SDL2, SDL2_mixer, + {$UNDEF SDL1MIXER} + {$DEFINE SDL2MIXER} + {$ENDIF} + envvars, e_log, SysUtils; type TSoundRec = record @@ -90,6 +98,8 @@ procedure e_SoundUpdate(); var e_SoundsArray: array of TSoundRec = nil; + e_TimidityDecoder: Boolean; (* sdl_mixer special *) + implementation uses @@ -172,27 +182,39 @@ var rfreq: Integer; rformat: UInt16; rchans: Integer; + flags: Integer; begin if SoundInitialized then begin Result := true; Exit end; Result := False; SoundInitialized := False; + {$IFDEF HEADLESS} + // HACK: shit this into env and hope for the best + SetEnvVar('SDL_AUDIODRIVER', 'dummy'); + {$ENDIF} + if NoOutput then begin Result := true; Exit end; // wow, this is actually MIDI player! // we need module player - res := Mix_Init(MIX_INIT_FLAC or MIX_INIT_MOD or MIX_INIT_MODPLUG or MIX_INIT_MP3 or MIX_INIT_OGG or MIX_INIT_FLUIDSYNTH); + flags := MIX_INIT_FLAC or MIX_INIT_MOD or MIX_INIT_MP3 or MIX_INIT_OGG or MIX_INIT_FLUIDSYNTH; + {$IFDEF SDL2MIXER} + flags := flags or MIX_INIT_MODPLUG; + {$ENDIF} + res := Mix_Init(flags); e_WriteLog(Format('SDL: res=0x%x', [res]), TMsgType.Notify); if (res and MIX_INIT_FLAC) <> 0 then e_WriteLog('SDL: FLAC playback is active', TMsgType.Notify); if (res and MIX_INIT_MOD) <> 0 then e_WriteLog('SDL: MOD playback is active', TMsgType.Notify); - if (res and MIX_INIT_MODPLUG) <> 0 then e_WriteLog('SDL: MODPLUG playback is active', TMsgType.Notify); + {$IFDEF SDL2MIXER} + if (res and MIX_INIT_MODPLUG) <> 0 then e_WriteLog('SDL: MODPLUG playback is active', TMsgType.Notify); + {$ENDIF} if (res and MIX_INIT_MP3) <> 0 then e_WriteLog('SDL: MP3 playback is active', TMsgType.Notify); if (res and MIX_INIT_OGG) <> 0 then e_WriteLog('SDL: OGG playback is active', TMsgType.Notify); if (res and MIX_INIT_FLUIDSYNTH) <> 0 then e_WriteLog('SDL: FLUIDSYNTH playback is active', TMsgType.Notify); e_WriteLog(Format('SDL: initializing mixer at %d with buffer %d', [gsSDLSampleRate, gsSDLBufferSize]), TMsgType.Notify); - res := Mix_OpenAudio(gsSDLSampleRate, AUDIO_S16LSB, 2, gsSDLBufferSize); + res := Mix_OpenAudio(gsSDLSampleRate, MIX_DEFAULT_FORMAT, 2, gsSDLBufferSize); if res = -1 then begin e_WriteLog('Error initializing SDL mixer:', TMsgType.Fatal); @@ -209,8 +231,13 @@ begin begin e_WriteLog(Format('SDL: chunk decoder %s is avalable', [Mix_GetChunkDecoder(i)]), TMsgType.Notify); end; + + e_TimidityDecoder := false; for i := 0 to Mix_GetNumMusicDecoders()-1 do begin + case AnsiString(Mix_GetMusicDecoder(i)) of + 'TIMIDITY': e_TimidityDecoder := true; + end; e_WriteLog(Format('SDL: music decoder %s is avalable', [Mix_GetMusicDecoder(i)]), TMsgType.Notify); end; @@ -377,7 +404,11 @@ begin if isMusic then begin e_WriteLog(Format(' MUSIC SLOT: %u', [find_id]), TMsgType.Notify); - e_SoundsArray[find_id].Music := Mix_LoadMUS_RW(rw, 0); + {$IFDEF SDL1MIXER} + e_SoundsArray[find_id].Music := Mix_LoadMUS_RW(rw); + {$ELSE} + e_SoundsArray[find_id].Music := Mix_LoadMUS_RW(rw, 0); + {$ENDIF} if e_SoundsArray[find_id].Music = nil then begin e_WriteLog(Format('ERROR LOADING MUSIC:', [find_id]), TMsgType.Warning);