sound loops are now hard coded to channel 4

main
Martin Felis 2011-04-10 19:39:33 +02:00
parent 0236bed14b
commit b08a835bfb
3 changed files with 19 additions and 5 deletions

View File

@ -34,7 +34,7 @@ void SoundSample::Play() {
}
void SoundSample::Loop(int count) {
mChannel = Mix_PlayChannel(-1, mMixChunk, count);
mChannel = Mix_PlayChannel(4, mMixChunk, count);
}
void SoundSample::Stop() {
@ -48,13 +48,16 @@ int SoundBase::OnInit(int argc, char* argv[]) {
int audio_rate = 22050;
Uint16 audio_format = AUDIO_S16;
int audio_channels = 2;
int audio_buffers = 4096;
int audio_buffers = 512;
LogDebug("Sound Init");
if (Mix_OpenAudio (audio_rate, audio_format, audio_channels, audio_buffers)) {
LogError ("Unable to initialize the sound system! Error message: %s", SDL_GetError());
}
// Allocate a few channels
Mix_AllocateChannels(8);
Mix_QuerySpec (&audio_rate, &audio_format, &audio_channels);
LogDebug("Sound: rate: %d channels: %d format: %d", audio_rate, audio_channels, audio_format);
@ -97,7 +100,7 @@ void SoundBase::PlaySound (const std::string &sound_name) {
iter = mSamples.find(sound_name);
}
LogDebug ("Playing sound %s", sound_name.c_str());
LogDebug ("Playing sound %s at channel %d", sound_name.c_str(), iter->second->GetChannel());
iter->second->Play();
}
@ -118,7 +121,7 @@ void SoundBase::PlaySoundLoop (const std::string &sound_name, int count) {
iter = mSamples.find(sound_name);
}
LogDebug ("Playing sound loop %s", sound_name.c_str());
LogDebug ("Playing sound loop %s at channel %d", sound_name.c_str(), iter->second->GetChannel());
iter->second->Loop(count);
}
@ -136,7 +139,7 @@ void SoundBase::HaltSoundLoop (const std::string &sound_name) {
return;
}
LogDebug ("Halting sound loop %s", sound_name.c_str());
LogDebug ("Halting sound loop %s at channel %d", sound_name.c_str(), iter->second->GetChannel());
iter->second->Stop();
}

View File

@ -20,6 +20,7 @@ class SoundSample {
void Play();
void Loop(int count);
void Stop();
int GetChannel () { return mChannel; };
private:
int mChannel;
@ -34,6 +35,11 @@ typedef boost::shared_ptr<SoundSample> SoundSamplePtr;
class SoundBase : public Module {
public:
void PlaySound (const std::string &sound_name);
/** \brief Plays a sound chunk in a loop
*
* \note Loops are hard-coded played in channel 4, therefore playing
* two loops simultaneously is currently not supported.
*/
void PlaySoundLoop (const std::string &sound_name, int count);
void HaltSoundLoop (const std::string &sound_name);
void LoadSound (const std::string &sound_name);

View File

@ -4,6 +4,11 @@
namespace Engine {
void PlaySound (const std::string &sound_name);
/** \brief Plays a sound chunk in a loop
*
* \note Loops are hard-coded played in channel 4, therefore playing
* two loops simultaneously is currently not supported.
*/
void PlaySoundLoop (const std::string &sound_name, int count);
void HaltSoundLoop (const std::string &sound_name);
void PlayMusic (const std::string &music_name);