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

Author Topic: Sounds stop suddenly  (Read 3590 times)

0 Members and 1 Guest are viewing this topic.

WrathfulProgrammer

  • Newbie
  • *
  • Posts: 2
    • View Profile
Sounds stop suddenly
« on: March 21, 2010, 02:26:44 pm »
Hello, for some reason my sounds stop after a while, music continues playing as normal though.

I suspect it could have something to do with the frequency of the sound instance creation(Quite often), could it have something to do with that?

Init, called once on init.
Code: [Select]
if (!Music.OpenFromFile("DJYeoh0.ogg"))
{
MessageBox(hWnd,"Failed to load DJYeoh0.ogg.","Warning",MB_ICONEXCLAMATION | MB_OK);
return false;
}


if (!Buffer.LoadFromFile("laser0.ogg"))
{
MessageBox(hWnd,"Failure to load from file.","Warning",MB_ICONEXCLAMATION | MB_OK);
return false;
}


Create, this gets called each time a unit shoots/dies.
Code: [Select]
sf::Sound *temp_sound = new sf::Sound;
temp_sound->SetBuffer(ps->app->Buffer);
ps->sound_vec.push_back(temp_sound);
temp_sound->SetPitch(3);
temp_sound->Play();



Update called each frame
Code: [Select]
std::vector<sf::Sound*>::iterator sound_it = sound_vec.begin();
while(sound_it != sound_vec.end()){
int duration = (*sound_it)->GetBuffer()->GetDuration();
int elapsed = (*sound_it)->GetPlayingOffset();

if(elapsed >= duration){
sound_it = sound_vec.erase(sound_it);
}
else
sound_it++;
}


Thanks.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Sounds stop suddenly
« Reply #1 on: March 21, 2010, 02:31:38 pm »
You should keep track of the number of sounds that are alive, and tell me the maximum value that you get. You cannot create more than a given number of sound sources (this is a limitation of OpenAL), so this may explain your problem.
Laurent Gomila - SFML developer

WrathfulProgrammer

  • Newbie
  • *
  • Posts: 2
    • View Profile
Sounds stop suddenly
« Reply #2 on: March 21, 2010, 02:34:21 pm »
My apologies, found the problem, I wasn't deleting the instances.

CytraL

  • Jr. Member
  • **
  • Posts: 68
    • View Profile
    • GitHub
Sounds stop suddenly
« Reply #3 on: August 22, 2010, 06:32:08 pm »
Im using SFML v1.5

I have the same problem... and i try delete instace but.. SFML fail.. :\ (me fail but... xDDD)

I have this:
Code: [Select]

        std::deque<sf::Sound*>::iterator it = sounds.begin();
        while(it != sounds.end())
        {
            const sf::SoundBuffer *sbuffer = (*it)->GetBuffer();
            float duration = sbuffer->GetDuration();
            float pos = (*it)->GetPlayingOffset();

            if (pos == duration)
            {
                delete((*it));
                (*it) = 0x0;
                it = sounds.erase(it);
            }
            else
                ++it;
        }

In this code.... "pos" never is == to "duration" :S

Code: [Select]

        std::deque<sf::Sound*>::iterator it = sounds.begin();
        while(it != sounds.end())
        {
            if ((*it)->GetStatus() == sf::Sound::Stopped)
            {
                delete((*it));
                (*it) = 0x0;
                it = sounds.erase(it);
            }
            else
                ++it;
        }

This code delete the sound more fast... (NO LISTEN SOUND :S)

I add new sound with:
Code: [Select]

void CEngine::playSound(int sound_type)
{
    sf::Sound *sound;
    switch(sound_type)
    {
        case SOUND_FIRE:
        {
            sound = new sf::Sound(snd_fire01);
        } break;
        case SOUND_IMPACT:
        {
            sound = new sf::Sound(snd_impact01);
        } break;
        case SOUND_JUMP:
        {
            sound = new sf::Sound(snd_jump);
        } break;
        case SOUND_HURT:
        {
            sound = new sf::Sound(snd_hurt01);
        } break;
        case SOUND_FX1:
        {
            sound = new sf::Sound(snd_fx01);
        } break;

        default:
            return;
    }

    sound->Play();
    sounds.push_back(sound);
}



Help me pls!
dev@redneboa.es | WordPress | GitHub | YouTube

CytraL

  • Jr. Member
  • **
  • Posts: 68
    • View Profile
    • GitHub
Sounds stop suddenly
« Reply #4 on: August 24, 2010, 04:34:55 pm »
pls... anybody can help me??? ¿why? ¿dirty code? ¿tutorial solution? ¿...?
dev@redneboa.es | WordPress | GitHub | YouTube

Mindiell

  • Hero Member
  • *****
  • Posts: 1261
    • ICQ Messenger - 41484135
    • View Profile
Sounds stop suddenly
« Reply #5 on: August 24, 2010, 04:48:37 pm »
As always, a minimal code could be helpful.

And try to explain your problem clearly, I didn't understand if your sound is playing or not. And maybe you can count yur numbe of sounds in order to answer to Laurent ;)
Mindiell
----

 

anything