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

Author Topic: Problems with sf::SoundBuffer  (Read 10294 times)

0 Members and 1 Guest are viewing this topic.

CBenni::O

  • Newbie
  • *
  • Posts: 48
    • View Profile
Problems with sf::SoundBuffer
« on: March 05, 2010, 08:36:06 pm »
Hy,

Why doesn't this code work:

Code: [Select]
int main()
{
sf::SoundBuffer MSB;
MSB.LoadFromFile("nice_music.ogg");
sf::Sound MySound2(MSB);
MySound2.Play();
if(MySound2.GetStatus() != sf::Sound::Playing)
{
// Debugging shows that this spot is executed...
}
sf::Sleep(10.0f);
return 0;
};

I am using the SFML 2.0 from the trunk...

Is it because I dont create a Window, or why else?

bye, CBenni::O
42!
Metal will never die!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Problems with sf::SoundBuffer
« Reply #1 on: March 05, 2010, 08:41:32 pm »
Does LoadFromFile("nice_music.ogg") succeed?
Laurent Gomila - SFML developer

CBenni::O

  • Newbie
  • *
  • Posts: 48
    • View Profile
Problems with sf::SoundBuffer
« Reply #2 on: March 05, 2010, 08:44:04 pm »
Now it does... And the status is set correctly, too...

But still, I don't hear the sound...

EDIT: I put this piece of code into a working piece of code, which creates a window, and still, it didn't play!
EDIT2: Sry, i am an idiot :D It wasn't a soft- but a hardwareproblem :roll:

:? another Problem... in a bigger program, it loads the SoundBuffer all right, but when i call it using my ResourceManager, it can't play the soundbuffer anymore... I haven't found a place where a soundbuffer is copied, only sf::SoundBuffer* pointers are passed to the user... What ist the problem here?

bye, CBenni::O
42!
Metal will never die!

CBenni::O

  • Newbie
  • *
  • Posts: 48
    • View Profile
Problems with sf::SoundBuffer
« Reply #3 on: March 06, 2010, 01:11:32 pm »
see EDIT above...

sry for confusing posts...

bye, CBenni::O
42!
Metal will never die!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Problems with sf::SoundBuffer
« Reply #4 on: March 06, 2010, 01:15:47 pm »
Show your code ;)
Laurent Gomila - SFML developer

CBenni::O

  • Newbie
  • *
  • Posts: 48
    • View Profile
Problems with sf::SoundBuffer
« Reply #5 on: March 06, 2010, 01:24:47 pm »
I'll try to make it as small as possible...
42!
Metal will never die!

CBenni::O

  • Newbie
  • *
  • Posts: 48
    • View Profile
Problems with sf::SoundBuffer
« Reply #6 on: March 06, 2010, 02:02:20 pm »
So, these are the important parts:

Creating the Resource:
Code: [Select]
SoundBuffer_Resource* NewSoundBuffer = new SoundBuffer_Resource(TopJob.filename);
ResourcePair = std::make_pair(TopJob.filename,NewSoundBuffer);
MyResources.insert(ResourcePair);

(topjob is a job out of the loading queue...)
Loading the Buffer:
Code: [Select]
SoundBuffer_Resource::SoundBuffer_Resource(const std::string filename)
{
MySoundBuffer = new sf::SoundBuffer();
MySoundBuffer->LoadFromFile(filename);
}


Aquiring the Resource:
Code: [Select]
template<typename T>
T* BBB::ResourceManager::Acquire(std::string name, DWORD maxloadingtime, DWORD sleeptime)
{
DWORD StartTime = timeGetTime();
while(MyResources.find(name) == MyResources.end() || MyResources.find(name)->second == NULL)
{
DWORD eltime = timeGetTime()-StartTime;
if(eltime < maxloadingtime)
{
Sleep(sleeptime);
}
else
{
return NULL;
}
}

}

return static_cast<T*>(MyResources.find(name)->second);
};


Using the SoundBuffer:
Code: [Select]
BBB::SoundBuffer_Resource* MyRes2 = MyResMgr.Acquire<BBB::SoundBuffer_Resource>("../Data/nice_music.ogg",1000000,10);
if(MyRes2 != NULL)
{
MySoundIsLoaded = true;
sf::SoundBuffer test = *MyRes2->Get();
MySound.SetBuffer(*MyRes2->Get());
MySound.Play();
}


I don't see a single copy in there...

The Buffer returned by Aquire ist not NULL, but it isn't played either...

bye, CBenni::O
42!
Metal will never die!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Problems with sf::SoundBuffer
« Reply #7 on: March 06, 2010, 02:58:30 pm »
You still don't check whether LoadFromFile succeeds or not.
Laurent Gomila - SFML developer

CBenni::O

  • Newbie
  • *
  • Posts: 48
    • View Profile
Problems with sf::SoundBuffer
« Reply #8 on: March 06, 2010, 03:16:04 pm »
I test it, i just put that out, because it is quite a lot of testing etc.

I have added this into the constructor of SoundBuffer_Resource:

Code: [Select]
sf::Sound test(*MySoundBuffer);
test.play();
Sleep(10000);


And it played the sound! (only for 10 seconds, of course ;))

bye, CBenni::O
42!
Metal will never die!

CBenni::O

  • Newbie
  • *
  • Posts: 48
    • View Profile
Problems with sf::SoundBuffer
« Reply #9 on: March 06, 2010, 07:36:07 pm »
Sorry for multiple Post,
but I have tested some more and found out that inside of SoundBuffer_Resource::Get(), the buffer is okay... So the problem is somewhere in the way from Get() to the usage uf my Buffer...

does anyone see the error I'm making?

Or is it (eventually) a bug in the copy semantics? But actually, I don't pass Instances, only pointers...

bye, CBenni::O
42!
Metal will never die!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Problems with sf::SoundBuffer
« Reply #10 on: March 06, 2010, 08:13:04 pm »
If I were you, I'd write a minimal example that reproduces this problem. Your code is too complex and contains too many lines unrelated to the problem, you'll waste more time trying to debug it directly than writing a simpler similar code.
Laurent Gomila - SFML developer

CBenni::O

  • Newbie
  • *
  • Posts: 48
    • View Profile
Problems with sf::SoundBuffer
« Reply #11 on: March 06, 2010, 09:07:57 pm »
I've been trying that, but I never achieved to build a code that reproduces my Problem... I am not able to isolate the Problem...

I'll try again, or else I upload the complete source, if that helps...

bye, CBenni::O
42!
Metal will never die!

CBenni::O

  • Newbie
  • *
  • Posts: 48
    • View Profile
Problems with sf::SoundBuffer
« Reply #12 on: March 07, 2010, 06:44:37 pm »
It works now...

I didn't get what was wrong, but this worked:

Code: [Select]
sf::Sound* MySound;

if(!MySoundIsLoaded)
{
BBB::SoundBuffer_Resource* MyRes2 = MyResMgr.Acquire<BBB::SoundBuffer_Resource>("../Data/nice_music.ogg",false,BBB::Res_None,0,0);
if(MyRes2 != NULL)
{
MySound = new sf::Sound(*MyRes2->Get()));
MySound->Play();
MySoundIsLoaded = true;
}
}


But this didn't:

Code: [Select]
sf::Sound* MySound = new sf::Sound();

if(!MySoundIsLoaded)
{
BBB::SoundBuffer_Resource* MyRes2 = MyResMgr.Acquire<BBB::SoundBuffer_Resource>("../Data/nice_music.ogg",false,BBB::Res_None,0,0);
if(MyRes2 != NULL)
{
MySound->SetBuffer(*MyRes2->Get()));
MySound->Play();
MySoundIsLoaded = true;
}

Any mistakes left? ;)

I would check the semantics of SetBuffer...

bye, CBenni::O
42!
Metal will never die!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Problems with sf::SoundBuffer
« Reply #13 on: March 07, 2010, 07:22:20 pm »
Your second piece of code is totally wrong, can you show the actual code? ;)
Laurent Gomila - SFML developer

CBenni::O

  • Newbie
  • *
  • Posts: 48
    • View Profile
Problems with sf::SoundBuffer
« Reply #14 on: March 07, 2010, 09:31:03 pm »
I'm sorry... did a few mistakes -.-

Correcting them rightaway...

bye, CBenni::O
42!
Metal will never die!

 

anything