diff --git a/src/audio.cpp b/src/audio.cpp index 3b701501..ff63a74b 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -38,6 +38,8 @@ void Audio::Setup(int channels) { #if defined USE_SDL_MIXER Mix_OpenAudio(22050, AUDIO_S16, channels, 1024); +#else + UNUSED(channels); #endif } diff --git a/src/sample.cpp b/src/sample.cpp index 2d5eed57..b49a5c4d 100644 --- a/src/sample.cpp +++ b/src/sample.cpp @@ -47,7 +47,8 @@ class SampleData private: char *name, *path; #if defined USE_SDL_MIXER - Mix_Chunk *chunk; + Mix_Chunk *m_chunk; + int m_channel; #endif }; @@ -66,11 +67,11 @@ Sample::Sample(char const *path) Array pathlist = System::GetPathList(path); for (int i = 0; i < pathlist.Count(); ++i) { - data->chunk = Mix_LoadWAV(pathlist[i].C()); - if (data->chunk) + data->m_chunk = Mix_LoadWAV(pathlist[i].C()); + if (data->m_chunk) break; } - if (!data->chunk) + if (!data->m_chunk) { #if !LOL_RELEASE Log::Error("could not load sample %s\n", path); @@ -78,13 +79,14 @@ Sample::Sample(char const *path) SDL_Quit(); exit(1); } + data->m_channel = -1; #endif } Sample::~Sample() { #if defined USE_SDL_MIXER - Mix_FreeChunk(data->chunk); + Mix_FreeChunk(data->m_chunk); #endif free(data->name); delete data; @@ -103,7 +105,16 @@ char const *Sample::GetName() void Sample::Play() { #if defined USE_SDL_MIXER - Mix_PlayChannel(-1, data->chunk, 0); + data->m_channel = Mix_PlayChannel(-1, data->m_chunk, 0); +#endif +} + +void Sample::Stop() +{ +#if defined USE_SDL_MIXER + if (data->m_channel >= 0) + Mix_HaltChannel(data->m_channel); + data->m_channel = -1; #endif } diff --git a/src/sample.h b/src/sample.h index 15fb1c25..4ba1a1d5 100644 --- a/src/sample.h +++ b/src/sample.h @@ -40,6 +40,7 @@ protected: public: /* New methods */ void Play(); + void Stop(); private: SampleData *data;