X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/342dc9287c824d32f191f7d0b56f3128fd62e018..3dd4386160b8f6d28ecc4ad2ca308c437721a41f:/src/unix/sound_sdl.cpp diff --git a/src/unix/sound_sdl.cpp b/src/unix/sound_sdl.cpp index b8c77fa006..12edf71953 100644 --- a/src/unix/sound_sdl.cpp +++ b/src/unix/sound_sdl.cpp @@ -5,7 +5,7 @@ // Modified by: // Created: 2004/01/31 // RCS-ID: $Id$ -// Copyright: (c) 2004, Vaclav Slavik +// Copyright: (c) 2004, Open Source Applications Foundation // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -18,7 +18,7 @@ #pragma hdrstop #endif -#if wxUSE_WAVE && wxUSE_LIBSDL +#if wxUSE_SOUND && wxUSE_LIBSDL #include @@ -56,8 +56,7 @@ END_DECLARE_EVENT_TYPES() DECLARE_EVENT_TABLE_ENTRY(wxEVT_SOUND_BACKEND_SDL_NOTIFICATION, \ -1, \ -1, \ - (wxObjectEventFunction) \ - (wxSoundBackendSDLNotificationFunction)& func, \ + (wxObjectEventFunction) wxStaticCastEvent( wxSoundBackendSDLNotificationFunction, & func ), \ (wxObject *) NULL ), IMPLEMENT_DYNAMIC_CLASS(wxSoundBackendSDLNotification, wxEvtHandler) @@ -82,9 +81,12 @@ public: int GetPriority() const { return 9; } bool IsAvailable() const; bool HasNativeAsyncPlayback() const { return true; } - bool Play(wxSoundData *data, unsigned flags); + bool Play(wxSoundData *data, unsigned flags, + volatile wxSoundPlaybackStatus *status); void FillAudioBuffer(Uint8 *stream, int len); + void FinishedPlayback(); + void Stop(); bool IsPlaying() const { return m_playing; } @@ -113,7 +115,7 @@ private: { wxLogTrace(_T("sound"), _T("received playback status change notification")); - m_backend->Stop(); + m_backend->FinishedPlayback(); } wxSoundBackendSDL *m_backend; @@ -191,6 +193,12 @@ void wxSoundBackendSDL::FillAudioBuffer(Uint8 *stream, int len) } } +void wxSoundBackendSDL::FinishedPlayback() +{ + if (!m_playing) + Stop(); +} + bool wxSoundBackendSDL::OpenAudio() { if (!m_audioOpen) @@ -236,8 +244,11 @@ void wxSoundBackendSDL::CloseAudio() } } -bool wxSoundBackendSDL::Play(wxSoundData *data, unsigned flags) +bool wxSoundBackendSDL::Play(wxSoundData *data, unsigned flags, + volatile wxSoundPlaybackStatus *WXUNUSED(status)) { + Stop(); + int format; if (data->m_bitsPerSample == 8) format = AUDIO_U8; @@ -245,8 +256,6 @@ bool wxSoundBackendSDL::Play(wxSoundData *data, unsigned flags) format = AUDIO_S16LSB; else return false; - - SDL_LockAudio(); bool needsOpen = true; if (m_audioOpen) @@ -263,34 +272,31 @@ bool wxSoundBackendSDL::Play(wxSoundData *data, unsigned flags) } } - Stop(); - if (needsOpen) { m_spec.format = format; m_spec.freq = data->m_samplingRate; m_spec.channels = data->m_channels; if (!OpenAudio()) - { - SDL_UnlockAudio(); return false; - } } - + + SDL_LockAudio(); + wxLogTrace(_T("sound"), _T("playing new sound")); m_playing = true; m_pos = 0; m_loop = (flags & wxSOUND_LOOP); m_data = data; data->IncRef(); + SDL_UnlockAudio(); SDL_PauseAudio(0); - SDL_UnlockAudio(); // wait until playback finishes if called in sync mode: if (!(flags & wxSOUND_ASYNC)) { wxLogTrace(_T("sound"), _T("waiting for sample to finish")); - while (m_playing) + while (m_playing && m_data == data) { #if wxUSE_THREADS // give the playback thread a chance to add event to pending @@ -298,7 +304,7 @@ bool wxSoundBackendSDL::Play(wxSoundData *data, unsigned flags) if (wxThread::IsMain()) wxMutexGuiLeave(); #endif - wxUsleep(10); + wxMilliSleep(10); #if wxUSE_THREADS if (wxThread::IsMain()) wxMutexGuiEnter(); @@ -314,6 +320,7 @@ void wxSoundBackendSDL::Stop() { SDL_LockAudio(); SDL_PauseAudio(1); + m_playing = false; if (m_data) { m_data->DecRef(); @@ -327,4 +334,4 @@ extern "C" wxSoundBackend *wxCreateSoundBackendSDL() return new wxSoundBackendSDL(); } -#endif // wxUSE_WAVE && wxUSE_LIBSDL +#endif // wxUSE_SOUND && wxUSE_LIBSDL