Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - tuanogus

Pages: [1]
1
Audio / I'm missing something fundamental RE threads and audio
« on: June 13, 2009, 06:31:10 pm »
Hi,

I'm developing an audio sample manager and am prototyping it with wxWidgets and SFML. I am having trouble with sf::Thread...well...threading. I am spankin' new to SFML and have read as much as I can on this subject, and I am probably misunderstanding something fundamental.

I am using wxWidgets for the UI (the main thread) and am trying to spawn a thread to play a sound. For example, inside my wxFrame...
Code: [Select]

// Event handler for a wxListCtrl selection event...
void MainFrame::OnFileListItemSelected( wxListEvent& WXUNUSED(event) )
{
       std::string filename = this->wx2std(this->GetSelectedFile());
sf::Thread Thread(&ThreadFunction, &filename);
Thread.Launch();
}

void ThreadFunction(void* UserData)
{
std::string* str = (std::string*)UserData;

sf::SoundBuffer Buffer;

if (!Buffer.LoadFromFile(*str)) return;

sf::Sound Sound;
Sound.SetBuffer(Buffer); // Buffer is a sf::SoundBuffer
Sound.SetVolume(100.f);
Sound.Play();

while(Sound.GetStatus() == sf::Sound::Playing) {
sf::Sleep(0.1f);
}
}

While this actually plays the audio as I expected, my UI is blocked until the Sound has finished playing. Any feedback is appreciated. I'm looking at a lot of different libraries and want to have a decent understanding of SFML before proceeding in my evaluation.

Also, I don't know why I need the last while loop in order for the Sound to play. I expected to be able to just call Sound.Play and have the entire sound play.

Cheers! And, very nice work. I love the API design.

Pages: [1]
anything