Parcourir la source

audio: add a simple Stop() method to samples.

legacy
Sam Hocevar sam il y a 11 ans
Parent
révision
578ec1d413
3 fichiers modifiés avec 20 ajouts et 6 suppressions
  1. +2
    -0
      src/audio.cpp
  2. +17
    -6
      src/sample.cpp
  3. +1
    -0
      src/sample.h

+ 2
- 0
src/audio.cpp Voir le fichier

@@ -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
}



+ 17
- 6
src/sample.cpp Voir le fichier

@@ -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<String> 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
}



+ 1
- 0
src/sample.h Voir le fichier

@@ -40,6 +40,7 @@ protected:
public:
/* New methods */
void Play();
void Stop();

private:
SampleData *data;


Chargement…
Annuler
Enregistrer