#include <sdlmixer.h>
Inheritance diagram for Wt::SDLMixer:
Public Types | |
typedef BaseFactory< Audio > | AudioBaseFactory |
Public Member Functions | |
virtual Audio::Chunk * | loadChunk (const std::string &filename) const |
virtual int | allocateChannels (int channels) |
virtual void | pause () |
pause all channels | |
virtual void | resume () |
resume all channels | |
virtual void | stop (int ms=0) |
stop all channels | |
virtual void | fadeOut (int ms) |
virtual int | playingChannels () const |
virtual int | pausedChannels () const |
virtual bool | isAvailable () const |
virtual Audio::Music * | loadMusic (const std::string &filename) |
virtual void | playMusic (Audio::Music &) |
it blocks until any previously music fading out is done | |
virtual void | fadeInMusic (Audio::Music &, int ms) |
virtual void | fadeOutMusic (int ms) |
virtual void | setMusicVolume (int volume) |
virtual void | pauseMusic () |
virtual void | rewindMusic () |
virtual bool | setMusicPosition (double start_sec) |
virtual void | stopMusic () |
virtual bool | playingMusic () const |
virtual bool | pausedMusic () const |
virtual int | musicFading () const |
int | numChannels () const |
Channel * | operator[] (int i) const |
Static Public Member Functions | |
static DERIVED * | instance () |
template<class GRANDCHILD> | |
static DERIVED * | instance () |
instantiates the pointer compatible child of DERIVED aka grandchild | |
static DERIVED * | existingInstance () |
static void | init () |
static void | quit () |
Public Attributes | |
Signal01< void, Channel * > | finished |
WVar< int > | musicLoops |
sigc::signal< void > | musicFinished |
Static Public Attributes | |
static Factory< Audio, SDLMixer > | factory |
Protected Member Functions | |
~SDLMixer () | |
SDLMixer () | |
virtual int | minHWVolume () const |
virtual int | maxHWVolume () const |
int | HWVolume (int volume) const |
template<typename CHILD> | |
void | adjustAllocatedChannels (int oldnum, int newnum) |
Static Protected Member Functions | |
static Audio * | load () |
try to load the instance | |
static void | onChannelFinish (int channel) |
callback called when a channel finishes | |
static void | onMusicFinish () |
static void | handleAudioEvent (const SDL_Event *event) |
SDLEvent::Audio handler. | |
Protected Attributes | |
std::vector< Channel * > | channels |
Static Protected Attributes | |
static const int | minVolume = 0 |
static const int | maxVolume = 1000 |
static DERIVED * | instance_ = 0 |
Static Private Attributes | |
static FlagMap | fadingTypeMap |
static FlagMap | musicTypeMap |
Friends | |
class | Singleton< Audio > |
Classes | |
class | Channel |
class | Chunk |
SDLMixer::Chunk implementation class. More... | |
class | Music |
Definition at line 37 of file sdlmixer.h.
typedef BaseFactory<Audio> Wt::Audio::AudioBaseFactory [inherited] |
Wt::SDLMixer::~SDLMixer | ( | ) | [protected] |
Definition at line 60 of file sdlmixer.cpp.
References allocateChannels(), and trace.
00060 { 00061 trace("sdlmixer", "Entering Destructor for SDLMixer\n"); 00062 allocateChannels(0); 00063 Mix_CloseAudio(); 00064 }
Here is the call graph for this function:
Wt::SDLMixer::SDLMixer | ( | ) | [protected] |
Definition at line 35 of file sdlmixer.cpp.
References fadingTypeMap, musicTypeMap, onChannelFinish(), and Wt::Audio::onMusicFinish().
Referenced by load().
00036 : Audio() { 00037 00038 // we can't reliably initialize staticly since we have to make 00039 // sure the enumeration is initialized first and this depends 00040 // from the linking order (static initialization fiasco) 00041 fadingTypeMap = boost::assign::map_list_of 00042 (MIX_NO_FADING, FadingType::None) 00043 (MIX_FADING_OUT, FadingType::Out) 00044 (MIX_FADING_IN, FadingType::In); 00045 00046 musicTypeMap = boost::assign::map_list_of 00047 (MUS_NONE, MusicType::None) 00048 (MUS_CMD, MusicType::Cmd) 00049 (MUS_WAV, MusicType::WAV) 00050 (MUS_MOD, MusicType::MOD) 00051 (MUS_MID, MusicType::MID) 00052 (MUS_OGG, MusicType::OGG) 00053 (MUS_MP3, MusicType::MP3); 00054 00055 adjustAllocatedChannels<SDLMixer>(0, Mix_AllocateChannels(-1)); 00056 Mix_ChannelFinished(onChannelFinish); 00057 Mix_HookMusicFinished(onMusicFinish); 00058 }
Here is the call graph for this function:
void Wt::Audio::adjustAllocatedChannels | ( | int | oldnum, | |
int | newnum | |||
) | [inline, protected, inherited] |
Definition at line 241 of file audio.h.
References Wt::Audio::Audio(), and Wt::Audio::channels.
00241 { 00242 if (oldnum < newnum) { 00243 for (int i = oldnum; i < newnum; i++) { 00244 channels.push_back(new typename CHILD::Channel(i)); 00245 } 00246 } else { // newnum < oldnum 00247 Audio& self = *this; 00248 for (int i = newnum; i < oldnum; i++) { 00249 delete self[i]; 00250 } 00251 self.channels.resize(newnum); 00252 } 00253 }
Here is the call graph for this function:
Reimplemented from Wt::Audio.
Definition at line 112 of file sdlmixer.cpp.
References Wt::Audio::numChannels().
Referenced by ~SDLMixer().
00112 { 00113 const int oldnum = numChannels(); 00114 assert(Mix_AllocateChannels(-1) == oldnum); 00115 00116 if (num_channels == oldnum || num_channels < 0) 00117 return oldnum; 00118 00119 adjustAllocatedChannels<SDLMixer>(oldnum, 00120 Mix_AllocateChannels(num_channels)); 00121 00122 return numChannels(); 00123 }
Here is the call graph for this function:
static DERIVED* Wt::Singleton< DERIVED >::existingInstance | ( | ) | [inline, static, inherited] |
Definition at line 36 of file singleton.h.
Referenced by Wt::Application::exit(), Wt::Application::postEvent(), Wt::Application::sendEvent(), and Wt::Application::sendPostedEvents().
00036 { 00037 return instance_; 00038 }
void Wt::SDLMixer::fadeInMusic | ( | Audio::Music & | , | |
int | ms | |||
) | [virtual] |
Reimplemented from Wt::Audio.
Definition at line 177 of file sdlmixer.cpp.
References Wt::Audio::musicLoops.
00177 { 00178 SDLMixer::Music& m = * static_cast<SDLMixer::Music *>(&music); 00179 Mix_FadeInMusic(m, musicLoops - 1, ms); 00180 }
void Wt::SDLMixer::fadeOut | ( | int | ms | ) | [virtual] |
void Wt::SDLMixer::fadeOutMusic | ( | int | ms | ) | [virtual] |
void Wt::Audio::handleAudioEvent | ( | const SDL_Event * | event | ) | [static, protected, inherited] |
SDLEvent::Audio handler.
it emits the required signal to all interested parties
Definition at line 213 of file audio.cpp.
References Wt::Audio::Event::channel(), Wt::Audio::Event::chunk(), Wt::Audio::Channel::finished, Wt::Singleton< DERIVED >::instance(), and trace.
Referenced by Wt::Audio::Audio().
00213 { 00214 trace("audio", "audio event delivered\n"); 00215 Event *sdl_audio_event = static_cast<Event *>(event->user.data1); 00216 Chunk *chunk = sdl_audio_event->chunk(); 00217 Channel *channel = sdl_audio_event->channel(); 00218 if (chunk && channel) { 00219 chunk->finished(chunk); 00220 channel->finished(channel); 00221 instance()->finished(channel); 00222 } else { 00223 instance()->musicFinished(); 00224 } 00225 delete sdl_audio_event; 00226 }
Here is the call graph for this function:
Definition at line 169 of file audio.cpp.
References Wt::Audio::maxHWVolume(), Wt::Audio::maxVolume, Wt::Audio::minHWVolume(), and Wt::Audio::minVolume.
00169 { 00170 return (maxHWVolume() - minHWVolume()) * volume / 00171 (maxVolume - minVolume); 00172 }
Here is the call graph for this function:
static void Wt::Singleton< DERIVED >::init | ( | ) | [inline, static, inherited] |
Reimplemented in Wt::Application.
Definition at line 49 of file singleton.h.
Referenced by Wt::Application::Application().
00049 { 00050 if (!instance()) { 00051 assert(0); 00052 } 00053 }
static DERIVED* Wt::Singleton< DERIVED >::instance | ( | ) | [inline, static, inherited] |
instantiates the pointer compatible child of DERIVED aka grandchild
it is handy in driver like situations
Definition at line 43 of file singleton.h.
static DERIVED* Wt::Singleton< DERIVED >::instance | ( | ) | [inline, static, inherited] |
Definition at line 32 of file singleton.h.
Referenced by Wt::Audio::Audio(), Wt::Sound::available(), Wt::SDLMixer::Chunk::channel(), Wt::NullAudio::Chunk::channel(), Wt::SDLSurface::defaultDepth(), Wt::SDLInput::EventInfo::EventInfo(), Wt::Dialog::exec(), Wt::Widget::grabKeyboard(), Wt::Widget::grabMouse(), Wt::Audio::handleAudioEvent(), Wt::SDLInput::handleKeyEvent(), Wt::Singleton< Wt::Audio >::init(), Wt::SDLTimer::init(), Wt::Sound::isAvailable(), Wt::Widget::keyboardGrabber(), Wt::Audio::load(), Wt::Widget::mouseGrabber(), onChannelFinish(), Wt::Audio::onChannelFinish(), Wt::Sound::play(), Wt::Singleton< Wt::Audio >::quit(), Wt::Widget::releaseKeyboard(), Wt::Widget::releaseMouse(), Wt::SDLInput::SDLInput(), setMusicVolume(), Wt::SDLMixer::Channel::setVolume(), and Wt::SDLMixer::Chunk::setVolume().
bool Wt::SDLMixer::isAvailable | ( | ) | const [virtual] |
Audio * Wt::SDLMixer::load | ( | ) | [static, protected] |
try to load the instance
if it fails return NULL if it succeeds must return the newly created object
Reimplemented from Wt::Audio.
Definition at line 66 of file sdlmixer.cpp.
References SDLMixer(), and trace.
00066 { 00067 trace("sdlmixer", "Initializing SDL audio...\n"); 00068 if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) { 00069 trace("sdlmixer", "Initialize SDL audio: %s\n", SDL_GetError()); 00070 goto fail; 00071 } 00072 00073 int audio_rate, audio_channels; 00074 Uint16 audio_format; 00075 int chunksize; 00076 00077 audio_format = MIX_DEFAULT_FORMAT; 00078 audio_channels = MIX_DEFAULT_CHANNELS; 00079 00080 //undef this (HIFI) to reduce CPU by a 5% 00081 audio_rate = MIX_DEFAULT_FREQUENCY; 00082 chunksize = 1024; 00083 //audio_rate = 44100; 00084 //chunksize = 2048; 00085 00086 /* Open the audio device */ 00087 if (Mix_OpenAudio(audio_rate, audio_format, 00088 audio_channels, chunksize) < 0) { 00089 trace("sdlmixer", "Initializing SDLMixer failed: %s\n", SDL_GetError()); 00090 SDL_QuitSubSystem(SDL_INIT_AUDIO); 00091 goto fail; 00092 } 00093 00094 Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels); 00095 trace("sdlmixer") << "Opened audio at "<< audio_rate << 00096 " Hz " << (audio_format & 0xFF) << "bit " << 00097 ((audio_channels > 1) ? "stereo" : "mono") << std::endl; 00098 00099 trace("audio", "SDLMixer initialization...ok\n"); 00100 return new SDLMixer(); 00101 00102 fail: 00103 trace("audio", "SDLMixer initialization...fail\n"); 00104 return 0; 00105 }
Here is the call graph for this function:
Audio::Chunk * Wt::SDLMixer::loadChunk | ( | const std::string & | filename | ) | const [virtual] |
Reimplemented from Wt::Audio.
Definition at line 107 of file sdlmixer.cpp.
00107 { 00108 Mix_Chunk *chunk = Mix_LoadWAV(filename.c_str()); 00109 return (chunk) ? new SDLMixer::Chunk(chunk) : 0; 00110 }
Audio::Music * Wt::SDLMixer::loadMusic | ( | const std::string & | filename | ) | [virtual] |
Reimplemented from Wt::Audio.
Definition at line 155 of file sdlmixer.cpp.
00155 { 00156 Mix_Music *m = Mix_LoadMUS(filename.c_str()); 00157 return (m) ? new Music(m) : 0; 00158 }
int Wt::SDLMixer::maxHWVolume | ( | ) | const [protected, virtual] |
int Wt::SDLMixer::minHWVolume | ( | ) | const [protected, virtual] |
int Wt::SDLMixer::musicFading | ( | ) | const [virtual] |
Reimplemented from Wt::Audio.
Definition at line 216 of file sdlmixer.cpp.
References fadingTypeMap.
00216 { 00217 return fadingTypeMap[Mix_FadingMusic()]; 00218 }
int Wt::Audio::numChannels | ( | ) | const [inherited] |
Definition at line 82 of file audio.cpp.
References Wt::Audio::channels.
Referenced by allocateChannels().
00082 { 00083 return channels.size(); 00084 }
void Wt::SDLMixer::onChannelFinish | ( | int | channel | ) | [static, protected] |
callback called when a channel finishes
Reimplemented from Wt::Audio.
Definition at line 232 of file sdlmixer.cpp.
References Wt::Singleton< DERIVED >::instance(), and Wt::Audio::onChannelFinish().
Referenced by SDLMixer().
00232 { 00233 Audio::onChannelFinish(channel_id); 00234 // if this function is called SDLMixer is running 00235 // so all static casts are safe 00236 SDLMixer& self = * static_cast<SDLMixer *>(instance()); 00237 SDLMixer::Channel *channel = 00238 static_cast<SDLMixer::Channel *>(self.channels[channel_id]); 00239 SDLMixer::Chunk *chunk = static_cast<SDLMixer::Chunk *>(channel->chunk()); 00240 channel->chunk_p = 0; 00241 chunk->channel_id = -1; 00242 }
Here is the call graph for this function:
void Wt::Audio::onMusicFinish | ( | ) | [static, protected, inherited] |
posts a SDL type event (SDLEvent::Audio) in the SDL event queue. By the time the event it is dispatched all SDL actions are allowed.
Definition at line 198 of file audio.cpp.
References Wt::SDLEvent::Audio, Wt::SDLEvent::push(), and trace.
Referenced by Wt::NullAudio::fadeInMusic(), Wt::NullAudio::playMusic(), and SDLMixer().
00198 { 00199 SDL_Event event; 00200 00201 event.type = SDLEvent::Audio; 00202 event.user.code = 0; 00203 event.user.data1 = new Event(0, 0); 00204 event.user.data2 = 0; 00205 00206 trace("audio", "musicFinished callback called\n"); 00207 00208 SDLEvent::push(&event); 00209 }
Here is the call graph for this function:
Audio::Channel * Wt::Audio::operator[] | ( | int | i | ) | const [inherited] |
Definition at line 86 of file audio.cpp.
References Wt::Audio::channels.
00086 { 00087 return channels[i]; 00088 }
void Wt::SDLMixer::pause | ( | ) | [virtual] |
int Wt::SDLMixer::pausedChannels | ( | ) | const [virtual] |
bool Wt::SDLMixer::pausedMusic | ( | ) | const [virtual] |
void Wt::SDLMixer::pauseMusic | ( | ) | [virtual] |
int Wt::SDLMixer::playingChannels | ( | ) | const [virtual] |
bool Wt::SDLMixer::playingMusic | ( | ) | const [virtual] |
void Wt::SDLMixer::playMusic | ( | Audio::Music & | ) | [virtual] |
it blocks until any previously music fading out is done
Reimplemented from Wt::Audio.
Definition at line 171 of file sdlmixer.cpp.
References Wt::Audio::musicLoops, and trace.
00171 { 00172 SDLMixer::Music& m = * static_cast<SDLMixer::Music *>(&music); 00173 trace("sdlmixer", "SDLMixer::playMusic() called\n"); 00174 Mix_PlayMusic(m, musicLoops - 1); 00175 }
static void Wt::Singleton< DERIVED >::quit | ( | ) | [inline, static, inherited] |
Reimplemented in Wt::Application.
Definition at line 55 of file singleton.h.
Referenced by Wt::Application::~Application().
00055 { 00056 delete instance(); 00057 }
void Wt::SDLMixer::resume | ( | ) | [virtual] |
void Wt::SDLMixer::rewindMusic | ( | ) | [virtual] |
bool Wt::SDLMixer::setMusicPosition | ( | double | start_sec | ) | [virtual] |
void Wt::SDLMixer::setMusicVolume | ( | int | volume | ) | [virtual] |
Reimplemented from Wt::Audio.
Definition at line 186 of file sdlmixer.cpp.
References Wt::Singleton< DERIVED >::instance().
00186 { 00187 SDLMixer& self = * static_cast<SDLMixer *>(instance()); 00188 int hwvol = self.HWVolume(volume); 00189 Mix_VolumeMusic(hwvol); 00190 }
Here is the call graph for this function:
void Wt::SDLMixer::stop | ( | int | ms = 0 |
) | [virtual] |
void Wt::SDLMixer::stopMusic | ( | ) | [virtual] |
std::vector<Channel *> Wt::Audio::channels [protected, inherited] |
Definition at line 260 of file audio.h.
Referenced by Wt::Audio::adjustAllocatedChannels(), Wt::Audio::allocateChannels(), Wt::Audio::numChannels(), and Wt::Audio::operator[]().
Factory< Audio, SDLMixer > Wt::SDLMixer::factory [static] |
FlagMap Wt::SDLMixer::fadingTypeMap [static, private] |
Definition at line 183 of file sdlmixer.h.
Referenced by Wt::SDLMixer::Channel::fading(), musicFading(), and SDLMixer().
Signal01<void, Channel *> Wt::Audio::finished [inherited] |
DERIVED * Wt::Singleton< DERIVED >::instance_ = 0 [static, protected, inherited] |
Definition at line 91 of file singleton.h.
Referenced by Wt::Singleton< Wt::Audio >::existingInstance(), Wt::Singleton< Wt::Audio >::instance(), Wt::Singleton< Wt::Audio >::load(), Wt::SDLDisplay::load(), Wt::Audio::load(), Wt::Singleton< Wt::Audio >::Singleton(), and Wt::Singleton< Wt::Audio >::~Singleton().
const int Wt::Audio::maxVolume = 1000 [static, protected, inherited] |
Definition at line 238 of file audio.h.
Referenced by Wt::SDLMixer::Chunk::Chunk(), and Wt::Audio::HWVolume().
const int Wt::Audio::minVolume = 0 [static, protected, inherited] |
sigc::signal<void> Wt::Audio::musicFinished [inherited] |
WVar<int> Wt::Audio::musicLoops [inherited] |
FlagMap Wt::SDLMixer::musicTypeMap [static, private] |
Definition at line 184 of file sdlmixer.h.
Referenced by SDLMixer(), and Wt::SDLMixer::Music::type().
This document is licensed under the terms of the GNU Free Documentation License and may be freely distributed under the conditions given by this license.