Changeset 2492


Ignore:
Timestamp:
Feb 25, 2013, 2:05:00 PM (6 years ago)
Author:
sam
Message:

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

Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/audio.cpp

    r2183 r2492  
    3939#if defined USE_SDL_MIXER
    4040    Mix_OpenAudio(22050, AUDIO_S16, channels, 1024);
     41#else
     42    UNUSED(channels);
    4143#endif
    4244}
  • trunk/src/sample.cpp

    r2440 r2492  
    4848    char *name, *path;
    4949#if defined USE_SDL_MIXER
    50     Mix_Chunk *chunk;
     50    Mix_Chunk *m_chunk;
     51    int m_channel;
    5152#endif
    5253};
     
    6768    for (int i = 0; i < pathlist.Count(); ++i)
    6869    {
    69         data->chunk = Mix_LoadWAV(pathlist[i].C());
    70         if (data->chunk)
     70        data->m_chunk = Mix_LoadWAV(pathlist[i].C());
     71        if (data->m_chunk)
    7172            break;
    7273    }
    73     if (!data->chunk)
     74    if (!data->m_chunk)
    7475    {
    7576#if !LOL_RELEASE
     
    7980        exit(1);
    8081    }
     82    data->m_channel = -1;
    8183#endif
    8284}
     
    8587{
    8688#if defined USE_SDL_MIXER
    87     Mix_FreeChunk(data->chunk);
     89    Mix_FreeChunk(data->m_chunk);
    8890#endif
    8991    free(data->name);
     
    104106{
    105107#if defined USE_SDL_MIXER
    106     Mix_PlayChannel(-1, data->chunk, 0);
     108    data->m_channel = Mix_PlayChannel(-1, data->m_chunk, 0);
     109#endif
     110}
     111
     112void Sample::Stop()
     113{
     114#if defined USE_SDL_MIXER
     115    if (data->m_channel >= 0)
     116        Mix_HaltChannel(data->m_channel);
     117    data->m_channel = -1;
    107118#endif
    108119}
  • trunk/src/sample.h

    r2216 r2492  
    4141    /* New methods */
    4242    void Play();
     43    void Stop();
    4344
    4445private:
Note: See TracChangeset for help on using the changeset viewer.