+
+ SDL_LockAudio();
+
+ if (!m_evtHandler)
+ m_evtHandler = new wxSoundBackendSDLEvtHandler(this);
+
+ data->IncRef();
+
+ bool needsOpen = true;
+ if (m_audioOpen)
+ {
+ wxLogTrace(_T("sound"), _T("another sound playing, will be stopped"));
+ if (format == m_spec.format &&
+ m_spec.freq == (int)data->m_samplingRate &&
+ m_spec.channels == data->m_channels)
+ {
+ needsOpen = false;
+ }
+ else
+ {
+ SDL_CloseAudio();
+ m_audioOpen = false;
+ wxLogTrace(_T("sound"), _T("closed audio"));
+ }
+ m_data->DecRef();
+ }
+
+ m_playing = true;
+ m_data = data;
+ m_pos = 0;
+ m_loop = (flags & wxSOUND_LOOP);
+ wxLogTrace(_T("sound"), _T("prepared sound for playback"));
+
+ bool status = true;
+
+ if (needsOpen)
+ {
+ m_spec.format = format;
+ m_spec.freq = data->m_samplingRate;
+ m_spec.channels = data->m_channels;
+ m_spec.silence = 0;
+ m_spec.samples = 4096;
+ m_spec.size = 0;
+ m_spec.callback = wx_sdl_audio_callback;
+ m_spec.userdata = (void*)this;
+
+ wxLogTrace(_T("sound"), _T("opening SDL audio..."));
+ status = (SDL_OpenAudio(&m_spec, NULL) >= 0);
+ if (status)
+ {
+#if wxUSE_LOG_DEBUG
+ char driver[256];
+ SDL_AudioDriverName(driver, 256);
+ wxLogTrace(_T("sound"), _T("opened audio, driver '%s'"),
+ wxString(driver, wxConvLocal).c_str());
+#endif
+ m_audioOpen = true;
+ SDL_PauseAudio(0);
+ }
+ else
+ {
+ wxString err(SDL_GetError(), wxConvLocal);
+ wxLogError(_("Couldn't open audio: %s"), err.c_str());
+ }
+ }