Page MenuHomePhabricator (Chris)

No OneTemporary

Authored By
Unknown
Size
4 KB
Referenced Files
None
Subscribers
None
diff --git a/util/sdl/sound.cpp b/util/sdl/sound.cpp
index 1e52fcb8..12ee792c 100644
--- a/util/sdl/sound.cpp
+++ b/util/sdl/sound.cpp
@@ -1,84 +1,88 @@
#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):
own(NULL){
SDL_RWops * ops = SDL_RWFromConstMem(data, length);
this->data.chunk = Mix_LoadWAV_RW(ops, 1);
own = new int;
*own = 1;
}
/* load from path */
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);
}
+
+ /* use the frequency enforced by the audio system */
+ Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels);
+ FREQUENCY = audio_rate;
}
void Sound::play(){
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){
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;
if (data.chunk != NULL){
Mix_FreeChunk(data.chunk);
}
own = NULL;
}
}
}
void Sound::stop(){
if (data.channel != -1){
Mix_HaltChannel(data.channel);
}
}
diff --git a/util/sound.cpp b/util/sound.cpp
index 7b9631ea..ae2aa2fe 100644
--- a/util/sound.cpp
+++ b/util/sound.cpp
@@ -1,33 +1,35 @@
#ifdef USE_ALLEGRO
#include "allegro/sound.cpp"
#endif
#ifdef USE_SDL
#include "sdl/sound.cpp"
#endif
+
+int Sound::FREQUENCY = 22050;
Sound::Sound( const Sound & copy ):
own( NULL ){
own = copy.own;
if ( own ){
*own += 1;
}
data = copy.data;
}
Sound & Sound::operator=( const Sound & rhs ){
if ( own ){
destroy();
}
own = rhs.own;
if ( own ){
*own += 1;
}
data = rhs.data;
return *this;
}
Sound::~Sound(){
destroy();
}
diff --git a/util/sound.h b/util/sound.h
index 14ea08ba..10ab7d30 100644
--- a/util/sound.h
+++ b/util/sound.h
@@ -1,52 +1,53 @@
#ifndef _paintown_sound_h
#define _paintown_sound_h
#include <string>
#include "load_exception.h"
#ifdef USE_SDL
#include "sdl/sound.h"
#endif
#ifdef USE_ALLEGRO
#include "allegro/sound.h"
#endif
struct SAMPLE;
/* a sound! */
class Sound{
public:
Sound();
/* create from wav file (riff header + pcm) */
Sound(const char * data, int length);
/* load from path */
Sound(const std::string & path) throw (LoadException);
Sound(const Sound & copy);
/* do any global initialization necessary */
static void initialize();
Sound & operator=( const Sound & rhs );
void play();
void play(double volume, int pan);
void playLoop();
void stop();
virtual ~Sound();
/* global frequency to use */
- static const int FREQUENCY = 22050;
+ // static const int FREQUENCY = 22050;
+ static int FREQUENCY;
protected:
void destroy();
// SAMPLE * my_sound;
SoundData data;
/* reference counting */
int * own;
};
#endif

File Metadata

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

Event Timeline