[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] r2703 - in branches/pingus_sdl/src: . sound
From: |
jsalmon3 |
Subject: |
[Pingus-CVS] r2703 - in branches/pingus_sdl/src: . sound |
Date: |
Mon, 9 Jul 2007 08:51:28 +0200 |
Author: jsalmon3
Date: 2007-07-09 08:51:20 +0200 (Mon, 09 Jul 2007)
New Revision: 2703
Modified:
branches/pingus_sdl/src/SConscript
branches/pingus_sdl/src/sound/sound.cpp
branches/pingus_sdl/src/sound/sound_real.cpp
branches/pingus_sdl/src/sound/sound_real.hpp
branches/pingus_sdl/src/sound/sound_res_mgr.cpp
branches/pingus_sdl/src/sound/sound_res_mgr.hpp
Log:
Converted sound to use SDL_mixer
Modified: branches/pingus_sdl/src/SConscript
===================================================================
--- branches/pingus_sdl/src/SConscript 2007-07-09 05:57:20 UTC (rev 2702)
+++ branches/pingus_sdl/src/SConscript 2007-07-09 06:51:20 UTC (rev 2703)
@@ -43,7 +43,7 @@
# clanMikMod-0.8 ">=" 0.8.0')
env.ParseConfig('sdl-config --cflags --libs')
-env['LIBS'] += ['SDL_image', 'physfs']
+env['LIBS'] += ['SDL_image', 'SDL_mixer', 'physfs']
# sdl_env.ParseConfig('sdl-config --cflags --libs')
# sdl_env['LIBS'] += ['SDL_image']
@@ -237,7 +237,7 @@
'smallmap_image.cpp',
'sound/sound.cpp',
'sound/sound_dummy.cpp',
-# 'sound/sound_real.cpp',
+'sound/sound_real.cpp',
'sound/sound_res_mgr.cpp',
'ground_map.cpp',
'start_screen.cpp',
Modified: branches/pingus_sdl/src/sound/sound.cpp
===================================================================
--- branches/pingus_sdl/src/sound/sound.cpp 2007-07-09 05:57:20 UTC (rev
2702)
+++ branches/pingus_sdl/src/sound/sound.cpp 2007-07-09 06:51:20 UTC (rev
2703)
@@ -22,6 +22,7 @@
#include "../path_manager.hpp"
#include "../globals.hpp"
#include "sound_dummy.hpp"
+#include "sound_real.hpp"
#include "sound.hpp"
namespace Sound {
@@ -33,8 +34,6 @@
{
if (s == 0)
{
- PingusSound::init(new PingusSoundDummy());
-#if 0
if (sound_enabled || music_enabled)
{
if (verbose)
@@ -42,8 +41,8 @@
try {
PingusSound::init (new PingusSoundReal ());
- } catch (CL_Error& err) {
- std::cout << "CL_Error: " << err.message << std::endl;
+ } catch (const std::string& err) {
+ std::cout << "Sound Error: " << err << std::endl;
std::cout << "Sound will be disabled" << std::endl;
PingusSound::init (new PingusSoundDummy ());
}
@@ -54,7 +53,6 @@
std::cout << "Sound disabled" << std::endl;
PingusSound::init (new PingusSoundDummy ());
}
-#endif
}
else
{
@@ -114,7 +112,7 @@
PingusSound::play_music(const std::string & name, float volume)
{
assert (sound);
- sound->real_play_music(path_manager.complete ("music/" + name), volume);
+ sound->real_play_music(path_manager.complete ("data/music/" + name), volume);
}
void
Modified: branches/pingus_sdl/src/sound/sound_real.cpp
===================================================================
--- branches/pingus_sdl/src/sound/sound_real.cpp 2007-07-09 05:57:20 UTC
(rev 2702)
+++ branches/pingus_sdl/src/sound/sound_real.cpp 2007-07-09 06:51:20 UTC
(rev 2703)
@@ -17,6 +17,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#include "SDL.h"
+#include "SDL_mixer.h"
#include "../globals.hpp"
#include "../debug.hpp"
#include "sound_res_mgr.hpp"
@@ -25,22 +27,23 @@
namespace Sound {
PingusSoundReal::PingusSoundReal ()
- : music_sample (0), music_session(0)
+ : music_sample(0)
{
- pout(PINGUS_DEBUG_SOUND) << "Initializing ClanLib-Sound" << std::endl;
+ pout(PINGUS_DEBUG_SOUND) << "Initializing SDL audio" << std::endl;
- sound_output = new CL_SoundOutput(44100);
- CL_SetupSound::init();
+ if (SDL_Init(SDL_INIT_AUDIO) == -1)
+ {
+ std::cout << "Unable to initialize SDL: " << SDL_GetError() << std::endl;
+ throw SDL_GetError();
+ }
- pout(PINGUS_DEBUG_SOUND) << "Initializing ClanLib-MikMod" << std::endl;
+ pout(PINGUS_DEBUG_SOUND) << "Initializing SDL_Mixer" << std::endl;
-#ifdef HAVE_LIBCLANVORBIS
- CL_SetupVorbis::init();
-#endif
-
-#ifdef HAVE_LIBCLANMIKMOD
- CL_SetupMikMod::init();
-#endif
+ if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 4096) == -1)
+ {
+ std::cout << "Unable to initialize SDL_Mixer: " << Mix_GetError() <<
std::endl;
+ throw Mix_GetError();
+ }
}
PingusSoundReal::~PingusSoundReal()
@@ -48,65 +51,47 @@
real_stop_music();
SoundResMgr::free_sound_map();
-#ifdef HAVE_LIBCLANMIKMOD
- CL_SetupMikMod::deinit();
-#endif
-
-#ifdef HAVE_LIBCLANVORBIS
- CL_SetupVorbis::deinit();
-#endif
-
- CL_SetupSound::deinit();
- sound_output->stop_all();
- delete sound_output;
+ Mix_CloseAudio();
}
-struct sound_is_finished
-{
- bool operator()(CL_SoundBuffer_Session& sess) {
- return !sess.is_playing();
- }
-};
-
void
PingusSoundReal::real_play_sound(const std::string& name, float volume, float
panning)
{
if (!sound_enabled)
return;
- SoundHandle buffer;
- CL_SoundBuffer_Session sess;
+ SoundHandle chunk;
- try {
- buffer = SoundResMgr::load(name);
- sess = buffer->prepare();
- } catch (const CL_Error & e) {
- perr(PINGUS_DEBUG_SOUND) << "Can't open sound '" << name << "' --
skipping\n"
- << " CL_Error: " << e.message << std::endl;
- return;
- }
+ chunk = SoundResMgr::load(name);
+ if (!chunk)
+ {
+ perr(PINGUS_DEBUG_SOUND) << "Can't open sound '" << name << "' --
skipping\n"
+ << " Mix_Error: " << Mix_GetError() <<
std::endl;
+ return;
+ }
- sess.set_volume(volume);
- sess.set_pan(panning);
- sess.set_looping(false);
- sess.play();
+ int channel = Mix_PlayChannel(-1, chunk, 0);
+ if (channel != -1)
+ {
+ Mix_Volume(channel, (int)(volume * MIX_MAX_VOLUME));
+ if (panning != 0.0f)
+ {
+ Uint8 left = (panning < 0.0f) ? 255 : (Uint8)((panning - 1.0f) *
-255);
+ Uint8 right = (panning > 0.0f) ? 255 : (Uint8)((panning + 1.0f) *
255);
+ Mix_SetPanning(channel, left, right);
+ }
+ }
}
void
PingusSoundReal::real_stop_music ()
{
- if (music_session)
- {
- music_session->stop();
- delete music_session;
- music_session = 0;
-
- if (music_sample)
+ if (music_sample)
{
- delete music_sample;
- music_sample = NULL;
+ Mix_HaltMusic();
+ Mix_FreeMusic(music_sample);
+ music_sample = 0;
}
- }
}
void
@@ -123,32 +108,16 @@
real_stop_music();
- music_sample = 0;
-
- if (filename.substr(filename.size()-4, 4) == ".ogg")
+ music_sample = Mix_LoadMUS(filename.c_str());
+ if (!music_sample)
{
- #ifdef HAVE_LIBCLANVORBIS
- music_sample = new CL_SoundBuffer (filename.c_str());
- #endif
+ perr(PINGUS_DEBUG_SOUND) << "Can't load music: " << filename << "' --
skipping\n"
+ << " Mix_Error: " << Mix_GetError() <<
std::endl;
+ return;
}
- else if (filename.substr(filename.size()-4, 4) == ".wav")
- {
- music_sample = new CL_SoundBuffer (filename.c_str());
- }
- else
- { // MikMod should support the rest...
- #ifdef HAVE_LIBCLANMIKMOD
- music_sample = new CL_SoundBuffer (filename.c_str());
- #endif
- }
- if (music_sample)
- {
- music_session = new CL_SoundBuffer_Session(music_sample->prepare());
- music_session->set_volume(volume * 0.5f); // FIXME: music_volume
- music_session->set_looping(true);
- music_session->play();
- }
+ Mix_VolumeMusic((int)(volume * 0.5f * MIX_MAX_VOLUME)); // FIXME:
music_volume
+ Mix_PlayMusic(music_sample, -1);
}
} // namespace Sound
Modified: branches/pingus_sdl/src/sound/sound_real.hpp
===================================================================
--- branches/pingus_sdl/src/sound/sound_real.hpp 2007-07-09 05:57:20 UTC
(rev 2702)
+++ branches/pingus_sdl/src/sound/sound_real.hpp 2007-07-09 06:51:20 UTC
(rev 2703)
@@ -20,14 +20,12 @@
#ifndef HEADER_PINGUS_SOUND_REAL_HXX
#define HEADER_PINGUS_SOUND_REAL_HXX
+#include "SDL_mixer.h"
#include <config.h>
#include <vector>
#include "sound_impl.hpp"
#include "sound.hpp"
-class CL_SoundBuffer;
-class CL_SoundBuffer_Session;
-
namespace Sound {
/** A simple wrapper class around SDL_Mixer, it will init itself
@@ -36,14 +34,8 @@
{
private:
/** The current music file */
- CL_SoundBuffer * music_sample;
+ Mix_Music* music_sample;
- /** Music Controller Session */
- CL_SoundBuffer_Session* music_session;
-
- /** Sound Output object */
- CL_SoundOutput* sound_output;
-
public:
PingusSoundReal ();
virtual ~PingusSoundReal ();
Modified: branches/pingus_sdl/src/sound/sound_res_mgr.cpp
===================================================================
--- branches/pingus_sdl/src/sound/sound_res_mgr.cpp 2007-07-09 05:57:20 UTC
(rev 2702)
+++ branches/pingus_sdl/src/sound/sound_res_mgr.cpp 2007-07-09 06:51:20 UTC
(rev 2703)
@@ -28,36 +28,35 @@
SoundHandle
SoundResMgr::load(const std::string& name)
{
-#if 0
SoundMap::iterator i = sound_map.find(name);
if (i == sound_map.end())
{
- std::string filename = path_manager.complete("sounds/" + name + ".wav");
- CL_SoundBuffer* buffer = new CL_SoundBuffer (filename, true);
+ std::string filename = path_manager.complete("data/sounds/" + name +
".wav");
+ Mix_Chunk* chunk = Mix_LoadWAV(filename.c_str());
pout(PINGUS_DEBUG_LOADING) << "SoundResMgr: Loading sound from disk: "
<< name << " -> " << filename << std::endl;
+ if (!chunk)
+ pout(PINGUS_DEBUG_LOADING) << "Error: " << Mix_GetError() << std::endl;
- sound_map[name] = buffer;
- return buffer;
+ sound_map[name] = chunk;
+ return chunk;
}
else
{
pout(PINGUS_DEBUG_LOADING) << "SoundResMgr: Loading sound from cache: "
<< name << std::endl;
return i->second;
}
-#endif
+
return 0;
}
void SoundResMgr::free_sound_map()
{
-#if 0
for (SoundMap::iterator i = sound_map.begin(); i != sound_map.end(); ++i)
{
- delete i->second;
+ Mix_FreeChunk(i->second);
}
-#endif
}
Modified: branches/pingus_sdl/src/sound/sound_res_mgr.hpp
===================================================================
--- branches/pingus_sdl/src/sound/sound_res_mgr.hpp 2007-07-09 05:57:20 UTC
(rev 2702)
+++ branches/pingus_sdl/src/sound/sound_res_mgr.hpp 2007-07-09 06:51:20 UTC
(rev 2703)
@@ -21,17 +21,16 @@
#define HEADER_PINGUS_SOUND_RES_MGR_HXX
#include <map>
+#include "SDL_mixer.h"
-class CL_SoundBuffer;
+typedef Mix_Chunk* SoundHandle;
-typedef CL_SoundBuffer* SoundHandle;
-
/** */
class SoundResMgr
{
private:
- typedef std::map<std::string, CL_SoundBuffer*> SoundMap;
+ typedef std::map<std::string, Mix_Chunk*> SoundMap;
static SoundMap sound_map;
public:
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] r2703 - in branches/pingus_sdl/src: . sound,
jsalmon3 <=