Page MenuHomePhabricator (Chris)

No OneTemporary

Authored By
Unknown
Size
4 KB
Referenced Files
None
Subscribers
None
diff --git a/util/music-player.h b/util/music-player.h
index ce5dcb95..44c6068f 100644
--- a/util/music-player.h
+++ b/util/music-player.h
@@ -1,86 +1,89 @@
#ifndef _paintown_music_player_h
#define _paintown_music_player_h
#ifdef USE_SDL
/* for Uint8 */
#include <SDL.h>
#endif
struct DUH;
struct DUH_SIGRENDERER;
#ifdef USE_ALLEGRO
struct AL_DUH_PLAYER;
struct AUDIOSTREAM;
#endif
class Music_Emu;
namespace Util{
class MusicPlayer{
public:
MusicPlayer();
virtual void play() = 0;
virtual void poll() = 0;
virtual void pause() = 0;
virtual void setVolume(double volume) = 0;
virtual ~MusicPlayer();
};
/* uses the GME library, plays nintendo music files and others */
class GMEPlayer: public MusicPlayer {
public:
GMEPlayer(const char * path);
virtual void play();
virtual void poll();
virtual void pause();
virtual void setVolume(double volume);
virtual ~GMEPlayer();
protected:
#ifdef USE_SDL
static void mixer(void * arg, Uint8 * stream, int length);
void render(Uint8 * stream, int length);
#endif
#ifdef USE_ALLEGRO
AUDIOSTREAM * stream;
#endif
double volume;
Music_Emu * emulator;
};
+#ifdef HAVE_OGG
+class OggPlayer: public MusicPlayer {
+};
+#endif
+
/* interface to DUMB, plays mod/s3m/xm/it */
class DumbPlayer: public MusicPlayer {
public:
DumbPlayer(const char * path);
virtual void play();
virtual void poll();
virtual void pause();
virtual void setVolume(double volume);
virtual ~DumbPlayer();
- static const int FREQUENCY = 22050;
-
protected:
DUH * loadDumbFile(const char * path);
#ifdef USE_SDL
static void mixer(void * player, Uint8 * stream, int length);
void render(Uint8 * stream, int length);
#endif
protected:
#ifdef USE_ALLEGRO
AL_DUH_PLAYER * player;
#endif
DUH * music_file;
#ifdef USE_SDL
DUH_SIGRENDERER * renderer;
#endif
double volume;
};
}
#endif
diff --git a/util/sdl/sound.cpp b/util/sdl/sound.cpp
index 10a2fe98..e85b92ac 100644
--- a/util/sdl/sound.cpp
+++ b/util/sdl/sound.cpp
@@ -1,73 +1,81 @@
#include "../sound.h"
#include <SDL.h>
#include "mixer/SDL_mixer.h"
Sound::Sound():
own(NULL){
}
/* create from wav file (riff header + pcm) */
-Sound::Sound(const char * data, int length){
+Sound::Sound(const char * data, int length):
+own(NULL){
/* TODO */
}
/* load from path */
-Sound::Sound(const std::string & path) throw (LoadException){
+Sound::Sound(const std::string & path) throw (LoadException):
+own(NULL){
data.chunk = Mix_LoadWAV(path.c_str());
if (!data.chunk){
printf("Can't load sound %s\n", path.c_str());
// throw LoadException("Could not load sound " + path);
} else {
own = new int;
*own = 1;
}
}
void Sound::initialize(){
// int audio_rate = 22050;
/* allegro uses 44100 by default with alsa9 */
int audio_rate = FREQUENCY;
// int audio_rate = 22050;
Uint16 audio_format = AUDIO_S16;
// Uint16 audio_format = MIX_DEFAULT_FORMAT;
int audio_channels = 2;
int audio_buffers = 4096;
// int audio_buffers = 44100;
if (Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers)) {
printf("Unable to open audio: %s!\n", Mix_GetError());
// exit(1);
}
}
void Sound::play(){
- /* FIXME: scale the volume based on the configuration sound setting */
- Mix_VolumeChunk(data.chunk, MIX_MAX_VOLUME);
- Mix_PlayChannel(-1, data.chunk, 0);
+ if (data.chunk != NULL){
+ /* FIXME: scale the volume based on the configuration sound setting */
+ Mix_VolumeChunk(data.chunk, MIX_MAX_VOLUME);
+ Mix_PlayChannel(-1, data.chunk, 0);
+ }
}
void Sound::play(double volume, int pan){
- /* FIXME: scale the volume based on the configuration sound setting */
- Mix_VolumeChunk(data.chunk, (int)(volume * MIX_MAX_VOLUME));
- Mix_PlayChannel(-1, data.chunk, 0);
+ if (data.chunk != NULL){
+ /* FIXME: scale the volume based on the configuration sound setting */
+ Mix_VolumeChunk(data.chunk, (int)(volume * MIX_MAX_VOLUME));
+ Mix_PlayChannel(-1, data.chunk, 0);
+ }
}
void Sound::playLoop(){
/* TODO */
}
void Sound::destroy(){
if ( own ){
*own -= 1;
if ( *own == 0 ){
delete own;
- Mix_FreeChunk(data.chunk);
+ if (data.chunk != NULL){
+ Mix_FreeChunk(data.chunk);
+ }
own = NULL;
}
}
}
void Sound::stop(){
if (data.channel != -1){
Mix_HaltChannel(data.channel);
}
}

File Metadata

Mime Type
text/x-diff
Expires
Thu, Jun 11, 12:41 PM (3 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
69078
Default Alt Text
(4 KB)

Event Timeline