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.


Messages - tuanogus

Pages: [1]
1
Audio / I'm missing something fundamental RE threads and audio
« on: June 14, 2009, 03:21:46 pm »
Yes, of course. Thanks again for your attention! Off to build some rockets...

2
Audio / I'm missing something fundamental RE threads and audio
« on: June 14, 2009, 03:13:44 am »
In haste... So I created a sf::Sound pointer in my MainFrame class. My code, of course, looks more like the following now.
Code: [Select]

void MainFrame::OnFileListItemSelected( wxListEvent& WXUNUSED(event) )
{
std::string filename = this->wx2std(this->GetSelectedFile());

sf::SoundBuffer Buffer;

if (!Buffer.LoadFromFile(filename))  return;

this->Sound->SetBuffer(Buffer);
this->Sound->SetVolume(100.f);
this->Sound->Play();
}

There's a lot wrong with my code still, but at least the UI is free, audio is playing, and I'm starting to understanding SFML now. Thanks for your direction!

3
Audio / I'm missing something fundamental RE threads and audio
« on: June 14, 2009, 03:02:20 am »
Okee, I've got it figured out. Required a pointer (in my class) to a sf::Sound. Will follow up with my solution shortly.

4
Audio / I'm missing something fundamental RE threads and audio
« on: June 14, 2009, 02:52:42 am »
Regarding #1... you're saying I should be able to do this?

Code: [Select]

void MainFrame::OnFileListItemSelected( wxListEvent& WXUNUSED(event) )
{
std::string filename = this->wx2std(this->GetSelectedFile());

sf::SoundBuffer Buffer;

if (!Buffer.LoadFromFile(filename)) return;

sf::Sound Sound;
Sound.SetBuffer(Buffer);
Sound.SetVolume(100.f);
Sound.Play();
}


And this should play the sound without blocking the caller?

5
Audio / I'm missing something fundamental RE threads and audio
« on: June 13, 2009, 10:22:24 pm »
Ah, okay, that makes sense. I'll move some things up in scope and give it whirl.

Tx!

6
Audio / I'm missing something fundamental RE threads and audio
« on: June 13, 2009, 09:06:00 pm »
Yes, I tried that approach with the same results. Because of that I assumed that SFML was not threaded internally, and explains why I'm now trying the approach posted above.

Thanks for quick response!

Any other ideas?

7
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]