Commit 1b87ae0d authored by Gerhard Stein's avatar Gerhard Stein

Removed obsolete Audio code

parent a6abde34
......@@ -176,22 +176,9 @@ IF (OPENGL)
ADD_DEFINITIONS(-DUSE_OPENGL)
ENDIF (OPENGL)
IF(WIN32)
find_package(SDL_Mixer)
else(WIN32)
INCLUDE(FindPkgConfig)
if(USE_SDL2)
PKG_CHECK_MODULES(SDL_MIXER SDL2_mixer>=2.0.0)
else()
PKG_CHECK_MODULES(SDL_MIXER SDL_mixer>=1.0.0)
endif()
endif(WIN32)
find_package(SDL_mixer REQUIRED)
if(${SDL_MIXER_FOUND})
ADD_DEFINITIONS(-DUSE_SDLMIXER)
if(SDL_MIXER_FOUND)
INCLUDE_DIRECTORIES(${SDL_MIXER_INCLUDE_DIRS})
endif()
......
......@@ -12,9 +12,7 @@
#include <base/utils/FindFile.h>
#include "sdl/audio/music/CMusic.h"
#if defined(USE_SDLMIXER)
#include <SDL_mixer.h>
#endif
#include <fstream>
......@@ -87,7 +85,6 @@ bool Audio::init()
mAudioSpec.userdata = nullptr;
// Initialize audio system
#if defined(USE_SDLMIXER)
if( Mix_OpenAudio(mAudioSpec.freq,
mAudioSpec.format,
mAudioSpec.channels,
......@@ -150,54 +147,6 @@ bool Audio::init()
//SDL_PauseAudio(0);
#else
if( SDL_OpenAudio(&mAudioSpec, &obtained) < 0 )
{
gLogging.ftextOut("SoundDrv_Start(): Couldn't open audio: %s<br>", SDL_GetError());
gLogging.ftextOut("Sound will be disabled.<br>");
mAudioSpec.channels = 0;
mAudioSpec.format = 0;
mAudioSpec.freq = 0;
return false;
}
mAudioSpec = obtained;
mMixedForm.resize(mAudioSpec.size);
gLogging.ftextOut("SDL_AudioSpec:<br>");
gLogging.ftextOut(" freq: %d<br>", mAudioSpec.freq);
gLogging.ftextOut(" channels: %d<br>", mAudioSpec.channels);
gLogging.ftextOut(" audio buffer size: %d<br>", mAudioSpec.size);
switch( mAudioSpec.format )
{
case AUDIO_U8:
gLogging.ftextOut(" format: AUDIO_U8<br>" );
break;
case AUDIO_S16:
gLogging.ftextOut(" format: AUDIO_S16<br>" );
break;
default:
gLogging.ftextOut(" format: UNKNOWN %d<br>", mAudioSpec.format );
break;
}
#if SDL_VERSION_ATLEAST(2, 0, 0)
gLogging << "Using audio driver: " << SDL_GetCurrentAudioDriver() << " <br>";
#else
//gLogging << "Using audio driver: " << SDL_AudioDriverName(name, 32) << " <br>";
#endif
const unsigned int channels = 32;
mSndChnlVec.clear();
mSndChnlVec.assign(channels, CSoundChannel(mAudioSpec));
SDL_PauseAudio(0);
#endif
gLogging << "Sound System: SDL sound system initialized.<br>";
// Let's initialize the OPL Emulator here!
......@@ -236,17 +185,6 @@ void Audio::destroy()
{
stopAllSounds();
#if !defined(USE_SDLMIXER)
SDL_LockAudio();
SDL_CloseAudio();
if(!mMixedForm.empty())
mMixedForm.clear();
#endif
if(!mSndChnlVec.empty())
{
mSndChnlVec.clear();
......@@ -257,9 +195,7 @@ void Audio::destroy()
m_OPL_Player.shutdown();
#if defined(USE_SDLMIXER)
Mix_CloseAudio();
#endif
}
// stops all currently playing sounds
......@@ -274,21 +210,13 @@ void Audio::stopAllSounds()
// pauses any currently playing sounds
void Audio::pauseAudio()
{
#if !defined(USE_SDLMIXER)
SDL_PauseAudio(1);
#else
Mix_Pause(-1);
#endif
}
// resumes playing a previously paused sound
void Audio::resumeAudio()
{
#if !defined(USE_SDLMIXER)
SDL_PauseAudio(0);
#else
Mix_Resume(-1);
#endif
}
// returns true if sound snd is currently playing
......@@ -326,23 +254,19 @@ void Audio::setSoundVolume(const Uint8 volume, const bool immediately)
{
m_SoundVolume = volume;
#if defined(USE_SDLMIXER)
if(immediately)
{
Mix_Volume(-1, volume);
}
#endif
}
void Audio::setMusicVolume(const Uint8 volume, const bool immediately)
{
m_MusicVolume = volume;
#if defined(USE_SDLMIXER)
if(immediately)
{
Mix_VolumeMusic(volume);
}
#endif
}
......@@ -373,39 +297,6 @@ void Audio::callback(void *unused,
return;
}
#if defined(USE_SDLMIXER)
#else
mMixedForm.resize(len);
Uint8* buffer = mMixedForm.data();
if (gMusicPlayer.playing())
{
gMusicPlayer.readWaveform(buffer, len);
mixAudio(stream, buffer, len, m_MusicVolume);
}
bool any_sound_playing = false;
std::vector<CSoundChannel>::iterator snd_chnl = mSndChnlVec.begin();
for( ; snd_chnl != mSndChnlVec.end() ; snd_chnl++)
{
if(snd_chnl->isPlaying())
{
any_sound_playing |= true;
snd_chnl->readWaveform( buffer, len );
mixAudio(stream, buffer, len, m_SoundVolume);
}
}
if(!any_sound_playing)
{
// means no sound is playing
mPauseGameplay = false;
}
#endif
mCallbackRunning = false;
}
......@@ -518,16 +409,8 @@ void Audio::setupSoundData(const std::map<GameSound, int> &slotMap,
{
assert(audioResPtr);
#if !defined(USE_SDLMIXER)
SDL_LockAudio();
#endif
sndSlotMap = slotMap;
mpAudioRessources.reset(audioResPtr);
#if !defined(USE_SDLMIXER)
SDL_UnlockAudio();
#endif
}
void Audio::unloadSoundData()
......@@ -535,16 +418,7 @@ void Audio::unloadSoundData()
// Wait for callback to finish running...
while(mCallbackRunning);
#if !defined(USE_SDLMIXER)
SDL_LockAudio();
#endif
mpAudioRessources.release();
#if !defined(USE_SDLMIXER)
mMixedForm.clear();
SDL_UnlockAudio();
#endif
}
......
......@@ -145,10 +145,6 @@ private:
// Boolean that holds if the Soundblaster is to be used. If set false it will use the PC Speaker emulation
bool mUseSoundBlaster = false;
#if !defined(USE_SDLMIXER)
std::vector<Uint8> mMixedForm; // Mainly used by the callback function. Declared once and allocated // for the whole runtime
#endif
std::map<GameSound, int> sndSlotMap;
COPLEmulator m_OPL_Player;
......
......@@ -17,10 +17,8 @@ target_link_libraries(sdl_extensions_audio
sdl_extensions_audio_base)
if(${SDL_MIXER_FOUND})
LINK_DIRECTORIES(${SDL_MIXER_LIBRARY_DIRS})
target_link_libraries(sdl_extensions_audio
${SDL_MIXER_LIBRARY})
endif()
......@@ -17,9 +17,7 @@
#include <string>
#include <cassert>
#if defined (USE_SDLMIXER)
#include <SDL_mixer.h>
#endif
CIMFPlayer::CIMFPlayer( COPLEmulator& opl_emulator ) :
......@@ -56,10 +54,6 @@ bool CIMFPlayer::loadMusicFromFile(const std::string& filename)
fseek(fp, 0, SEEK_SET);
}
#if !defined(USE_SDLMIXER)
SDL_LockAudio();
#endif
if(!m_IMF_Data.empty())
m_IMF_Data.clear();
......@@ -76,10 +70,6 @@ bool CIMFPlayer::loadMusicFromFile(const std::string& filename)
}
fclose(fp);
#if !defined(USE_SDLMIXER)
SDL_UnlockAudio();
#endif
return ok;
}
......@@ -87,25 +77,14 @@ bool CIMFPlayer::loadMusicFromFile(const std::string& filename)
bool CIMFPlayer::loadMusicTrack(const int track)
{
#if !defined(USE_SDLMIXER)
SDL_LockAudio();
#endif
if( m_IMF_Data.empty() )
m_IMF_Data.clear();
if(!gKeenFiles.exeFile.loadMusicTrack(m_IMF_Data, track))
{
#if !defined(USE_SDLMIXER)
SDL_UnlockAudio();
#endif
return false;
}
#if !defined(USE_SDLMIXER)
SDL_UnlockAudio();
#endif
return true;
}
......@@ -113,38 +92,22 @@ bool CIMFPlayer::loadMusicTrack(const int track)
bool CIMFPlayer::open(const bool lock)
{
#if !defined(USE_SDLMIXER)
if(lock) SDL_LockAudio();
#endif
m_numreadysamples = m_IMFDelay = 0;
m_samplesPerMusicTick = gSound.getAudioSpec().freq / m_opl_emulator.getIMFClockRate();
m_opl_emulator.setup();
#if !defined(USE_SDLMIXER)
if(lock) SDL_UnlockAudio();
#endif
return !m_IMF_Data.empty();
}
void CIMFPlayer::close(const bool lock)
{
#if !defined(USE_SDLMIXER)
if(lock) SDL_LockAudio();
#endif
play(false);
m_IMF_Data.gotoStart();
m_numreadysamples = m_IMFDelay = 0;
m_opl_emulator.ShutAL();
m_opl_emulator.shutdown();
#if !defined(USE_SDLMIXER)
if(lock) SDL_UnlockAudio();
#endif
return;
}
......@@ -250,7 +213,6 @@ void CIMFPlayer::readBuffer(Uint8* buffer, Uint32 length)
#if defined(USE_SDLMIXER)
////// Hooks for SDL_Mixer Only ///////
// We still a local to file declared object from the IMFPlayer class.
......@@ -320,7 +282,5 @@ void unhookAll()
}
#endif
......@@ -15,9 +15,7 @@
#include <SDL.h>
#include <string>
#if defined(USE_SDLMIXER)
#include <SDL_mixer.h>
#endif
struct IMFChunkType
{
......@@ -66,7 +64,6 @@ private:
};
#if defined(USE_SDLMIXER)
// External Music hooks for the imf player
/**
......@@ -105,7 +102,6 @@ void musicFinished();
*/
void unhookAll();
#endif
#endif /* CIMFPLAYER_H_ */
......@@ -21,8 +21,6 @@ IF(TREMOR)
TARGET_LINK_LIBRARIES(sdl_extensions_audio_music vorbisidec)
ENDIF(TREMOR)
if(${SDL_MIXER_FOUND})
LINK_DIRECTORIES(${SDL_MIXER_LIBRARY_DIRS})
target_link_libraries(sdl_extensions_audio_music
${SDL_MIXER_LIBRARIES})
endif()
......@@ -25,33 +25,12 @@ bool CMusic::loadTrack(const int track)
gLogging.textOut("Load track number " + itoa(track) + "");
#if defined(USE_SDLMIXER)
if(loadIMFTrack(track))
{
gSound.resumeAudio();
return true;
}
#else
#if defined(OGG) || defined(TREMOR)
mpPlayer.reset( new COGGPlayer );
if(mpPlayer->loadMusicTrack(track))
{
gSound.resumeAudio();
return true;
}
#endif
mpPlayer.reset( new CIMFPlayer );
if(!mpPlayer->loadMusicTrack(track))
{
gLogging.textOut("No music to be loaded for Track" + itoa(track) + ".");
}
#endif
gSound.resumeAudio();
......@@ -61,9 +40,6 @@ bool CMusic::loadTrack(const int track)
bool CMusic::load(const std::string &musicfile)
{
#if !defined(USE_SDLMIXER)
mpPlayer.reset();
#else
if(mpMixMusic)
{
......@@ -73,8 +49,6 @@ bool CMusic::load(const std::string &musicfile)
unhookAll();
#endif
if(musicfile == "") return false;
const SDL_AudioSpec &audioSpec = gSound.getAudioSpec();
......@@ -89,28 +63,16 @@ bool CMusic::load(const std::string &musicfile)
if( extension == "imf" )
{
#if defined(USE_SDLMIXER)
if(!loadIMFFile(musicfile))
{
return false;
}
#else
mpPlayer.reset( new CIMFPlayer );
if(!mpPlayer->loadMusicFromFile(musicfile))
{
return false;
}
#endif
}
else if( extension == "ogg" )
{
#if defined(USE_SDLMIXER)
const auto fullFname = GetFullFileName(musicfile);
mpMixMusic = Mix_LoadMUS(fullFname.c_str());
if(!mpMixMusic)
......@@ -122,29 +84,7 @@ bool CMusic::load(const std::string &musicfile)
}
}
#else
#if defined(OGG) || defined(TREMOR)
mpPlayer.reset( new COGGPlayer );
mpPlayer->loadMusicFromFile(musicfile);
#else
gLogging.ftextOut("Music Manager: Neither OGG nor TREMOR-Support are enabled! Please use another build<br>");
gSound.resumeAudio();
return false;
#endif
}
if(!mpPlayer->open(true))
{
mpPlayer.reset();
gLogging.textOut(FONTCOLORS::PURPLE,"Music Manager: File could not be opened: \"%s\". File is damaged or something is wrong with your soundcard!<br>", musicfile.c_str());
gSound.resumeAudio();
return false;
}
#endif
return true;
......@@ -163,24 +103,13 @@ void CMusic::reload()
{
//gSound.pauseAudio();
#if defined(USE_SDLMIXER)
Mix_RewindMusic();
#else
if(!mpPlayer)
{
return;
}
mpPlayer->reload();
#endif
//gSound.resumeAudio();
}
void CMusic::play()
{
#if defined(USE_SDLMIXER)
if(Mix_PausedMusic())
{
Mix_ResumeMusic();
......@@ -204,38 +133,20 @@ void CMusic::play()
}
//Mix_VolumeMusic(SDL_MIX_MAXVOLUME);
#else
if(!mpPlayer)
{
return;
}
mpPlayer->play(true);
#endif
}
void CMusic::pause()
{
#if defined(USE_SDLMIXER)
if(!Mix_PausedMusic())
{
Mix_PauseMusic();
}
#else
if(!mpPlayer)
return;
mpPlayer->play(false);
#endif
}
void CMusic::stop()
{
#if defined(USE_SDLMIXER)
if(Mix_PlayingMusic())
{
Mix_HaltMusic();
......@@ -249,29 +160,12 @@ void CMusic::stop()
unhookAll();
#else
if(!mpPlayer)
return;
gSound.pauseAudio();
mpPlayer->close(true);
mpPlayer.reset();
gSound.resumeAudio();
#endif
}
// length only refers to the part(buffer) that has to be played
void CMusic::readWaveform(Uint8* buffer, size_t length)
{
#if !defined(USE_SDLMIXER)
if( !mpPlayer )
return;
mpPlayer->readBuffer(buffer, length);
#endif
return;
}
bool CMusic::LoadfromSonglist(const std::string &gamepath, const int &level)
......
......@@ -22,9 +22,7 @@
#include <base/Singleton.h>
#if defined(USE_SDLMIXER)
#include <SDL_mixer.h>
#endif
#define gMusicPlayer CMusic::get()
......@@ -63,11 +61,7 @@ public:
return false;
}
#if defined(USE_SDLMIXER)
return Mix_PausedMusic();
#else
return mpPlayer->playing();
#endif
}
bool playing()
......@@ -77,36 +71,18 @@ public:
return false;
}
#if defined(USE_SDLMIXER)
return Mix_PlayingMusic();
#else
return mpPlayer->playing();
#endif
}
bool active()
{
#if defined(USE_SDLMIXER)
return Mix_PlayingMusic();
#else
if(mpPlayer)
return true;
else
return false;
#endif
}
private:
#if !defined(USE_SDLMIXER)
std::unique_ptr<CMusicPlayer> mpPlayer;
#endif
#if defined(USE_SDLMIXER)
Mix_Music *mpMixMusic = nullptr;
#endif
};
......
......@@ -14,9 +14,7 @@
#include <base/GsLogging.h>
#if defined(USE_SDLMIXER)
#include <SDL_mixer.h>
#endif
int CSoundChannel::mTotNumChannels = 0;
......@@ -52,28 +50,18 @@ void
CSoundChannel::
stopSound()
{
#if !defined(USE_SDLMIXER)
SDL_LockAudio();
#endif
mpCurrentSndSlot = nullptr;
mBalance = 0;
mSoundPtr = 0;
mSoundPaused = true;
mSoundPlaying = false;
#if defined(USE_SDLMIXER)
Mix_HaltChannel(mId);
#else
SDL_UnlockAudio();
#endif
}
void CSoundChannel::setupSound( CSoundSlot &SndSlottoPlay,
const bool sound_forced )
{
#if defined(USE_SDLMIXER)
mpCurrentSndSlot = &SndSlottoPlay;
mSoundPlaying = true;
mSoundPtr = 0;
......@@ -87,18 +75,6 @@ void CSoundChannel::setupSound( CSoundSlot &SndSlottoPlay,
{
gLogging.ftextOut("Mix_PlayChannel: %s\n", Mix_GetError());
}
#else
SDL_LockAudio();
mpCurrentSndSlot = &SndSlottoPlay;
mSoundPlaying = true;
mSoundPtr = 0;
mSoundForced = sound_forced;
SDL_UnlockAudio();
#endif
}
/** \brief This program reads the balance information and balances the stereo sound
......
......@@ -103,15 +103,11 @@ void CSoundSlot::setupWaveForm( Uint8 *buf, Uint32 len )
mSounddata.resize(m_soundlength);
memcpy(mSounddata.data(), buf, m_soundlength);
#if defined(USE_SDLMIXER)
if(!(mpWaveChunk=Mix_QuickLoad_RAW(mSounddata.data(), mSounddata.size())))
{
gLogging.ftextOut("Mix_QuickLoad_WAV: %s\n", Mix_GetError());
// handle error
}
#endif
}
void CSoundSlot::setupWaveForm( const std::vector<Uint8>& waveform )
......@@ -123,11 +119,6 @@ void CSoundSlot::setupWaveForm( const std::vector<Uint8>& waveform )
bool CSoundSlot::HQSndLoad(const std::string& gamepath,
const std::string& soundname)
{
#if defined(USE_SDLMIXER)
// m_soundlength = len;
// load sample.wav in to sample
std::string buf;
......@@ -151,120 +142,6 @@ bool CSoundSlot::HQSndLoad(const std::string& gamepath,
}
return true;
#else
SDL_AudioSpec AudioFileSpec;