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

Author Topic: sf::SoundBuffer doesn't discard data on second loadFrom* call  (Read 10220 times)

0 Members and 1 Guest are viewing this topic.

Ancurio

  • Jr. Member
  • **
  • Posts: 66
    • View Profile
sf::SoundBuffer doesn't discard data on second loadFrom* call
« on: February 16, 2013, 07:05:41 am »
Hi!

It seems to me that when calling a load function on an sf::SoundBuffer that already has contents from a previous load, it will just keep the old data and not actually load any new samples. Is this intended behavior?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
AW: sf::SoundBuffer doesn't discard data on second loadFrom* call
« Reply #1 on: February 16, 2013, 07:14:19 am »
No, but are you sure you're doing things correctly?
Of you work with pointers, call new on the buffer without deleting the old one and without resetting the sound object, the sound object will still point to the old sound buffer.
Besides that you probably don't want to work with raw poonters.

Also in many cases it's not the best idea to use one buffer for different sounds.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::SoundBuffer doesn't discard data on second loadFrom* call
« Reply #2 on: February 16, 2013, 09:06:20 am »
You say that the sound buffer is not updated, but you probably mean that the sound that uses the buffer is not updated, right? Does it work if you call sound.setBuffer again after reloading the buffer?
Laurent Gomila - SFML developer

Ancurio

  • Jr. Member
  • **
  • Posts: 66
    • View Profile
Re: sf::SoundBuffer doesn't discard data on second loadFrom* call
« Reply #3 on: February 16, 2013, 10:07:32 am »
You say that the sound buffer is not updated, but you probably mean that the sound that uses the buffer is not updated, right? Does it work if you call sound.setBuffer again after reloading the buffer?

I've tried doing the setBuffer (although that shouldn't do anything I think, because an sf::Sound instance should only ever point to an sf::SoundBuffer object, not the raw sound samples themselves, no?). I also tried calling resetBuffer() before.

This is what I mean:
#include <SFML/Audio.hpp>
#include <SFML/System.hpp>

int main(int, char**)
{
        sf::SoundBuffer buffer;
        buffer.loadFromFile("sound1.ogg");

        sf::Sound sound(buffer);
        sound.play();

        sf::sleep(sf::seconds(5));

        buffer.loadFromFile("sound2.ogg");
        sound.setBuffer(buffer);
        sound.play();

        sf::sleep(sf::seconds(5));

        return 0;
}
 

"sound1.ogg" is played two times on my machine.
Currently I'm working around it by using an allocated sf::SoundBuffer object, which I delete and create again when another sound is to be loaded. I was writing a small and simple Qt app that plays back a user chosen sound on a certain action, so I tried to keep it as simple as possible and was hoping I could just load new samples into the buffer every time the user chose a new sound file.
« Last Edit: February 16, 2013, 10:10:17 am by Ancurio »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: sf::SoundBuffer doesn't discard data on second loadFrom* call
« Reply #4 on: February 16, 2013, 10:14:47 am »
Unfortunately I can confirm this issue.
When the second audio file should get loaded, the console spits the following out:
Quote
An internal OpenAL call failed in SoundBuffer.cpp (253) : AL_INVALID_VALUE, a numeric argument is out of range
And then it plays the same sound again.

Adding a .stop() after the pause doesn't help either.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Ancurio

  • Jr. Member
  • **
  • Posts: 66
    • View Profile
Re: sf::SoundBuffer doesn't discard data on second loadFrom* call
« Reply #5 on: February 16, 2013, 12:35:53 pm »
Unfortunately I can confirm this issue.
When the second audio file should get loaded, the console spits the following out:
Quote
An internal OpenAL call failed in SoundBuffer.cpp (253) : AL_INVALID_VALUE, a numeric argument is out of range
And then it plays the same sound again.

Adding a .stop() after the pause doesn't help either.

Ah damn, I should have used my debug build, then I would have gotten this message too I think and could have saved myself some fruitless debugging..

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::SoundBuffer doesn't discard data on second loadFrom* call
« Reply #6 on: February 16, 2013, 12:48:18 pm »
Ok, it really looks like a bug. Can you please open a new issue on the tracker so that I don't forget it?
Laurent Gomila - SFML developer

Ancurio

  • Jr. Member
  • **
  • Posts: 66
    • View Profile
Re: sf::SoundBuffer doesn't discard data on second loadFrom* call
« Reply #7 on: February 16, 2013, 12:48:40 pm »
Ok, it really looks like a bug. Can you please open a new issue on the tracker so that I don't forget it?

kk

deesse

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: sf::SoundBuffer doesn't discard data on second loadFrom* call
« Reply #8 on: March 12, 2013, 10:40:15 am »
I ran into something similar while playing with sound generation. I attempted to toggle my waveform between square and saw waves on the fly, but the playback never changed as if the buffer never updated. Pointing a unique_ptr to a new buffer seemed to get around this

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: sf::SoundBuffer doesn't discard data on second loadFrom* call
« Reply #9 on: May 11, 2013, 10:33:49 am »
This issue might have something to do with the buffer being "still in use". If you destroy all sources accessing it (i.e. all sf::Sound objects bound to it), reloading works just fine.

Given the example code above something like this:

#include <SFML/Audio.hpp>
#include <SFML/System.hpp>

int main(int, char**)
{
    sf::SoundBuffer buffer;
    buffer.loadFromFile("sound1.ogg");

    {
    sf::Sound sound(buffer);
    sound.play();

    sf::sleep(sf::seconds(5));
    }

    buffer.loadFromFile("sound2.ogg");
    {
    sf::Sound sound(buffer);
    sound.play();

    sf::sleep(sf::seconds(5));
    }

    return 0;
}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::SoundBuffer doesn't discard data on second loadFrom* call
« Reply #10 on: May 11, 2013, 11:53:43 am »
There are a lot more information on the bug tracker (#346) about this issue.
Laurent Gomila - SFML developer

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: sf::SoundBuffer doesn't discard data on second loadFrom* call
« Reply #11 on: May 11, 2013, 02:33:23 pm »
There are a lot more information on the bug tracker (#346) about this issue.

I think you mean #354, #346 is a bug on the linux window positioning.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::SoundBuffer doesn't discard data on second loadFrom* call
« Reply #12 on: May 11, 2013, 03:29:50 pm »
Oops...
Laurent Gomila - SFML developer

Ruckamongus

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
Re: sf::SoundBuffer doesn't discard data on second loadFrom* call
« Reply #13 on: June 28, 2013, 09:16:34 pm »
Is this issue fixed? If so, has the fix been added to the official SFML repository? I'm getting this error when calling loadFromSamples(), but my current version of SFML is a couple months old.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::SoundBuffer doesn't discard data on second loadFrom* call
« Reply #14 on: June 28, 2013, 10:11:46 pm »
Quote
Is this issue fixed?
Is it closed?
Laurent Gomila - SFML developer