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

Author Topic: Sound is not working (error)  (Read 3038 times)

0 Members and 1 Guest are viewing this topic.

Bogdan

  • Jr. Member
  • **
  • Posts: 93
    • View Profile
Sound is not working (error)
« on: May 19, 2014, 06:04:53 pm »
I've been searching for and trying out many solutions for the whole day, but haven't been able to do anything about the problem so far. There seems to be a problem with the SoundBuffer, because when running this program, the consolole always is showing the same error:

"An internal OpenAL call failed in SoundBuffer.cpp (253) : AL_INVALID_VALVE, a numeric argument is out of range"

Chaning to static lib didnt help here and even putting the audio and libsndfile dlls didnt work either, but if I want to play the same file as "music", than in magically works. (see commented out code below ) I've even tried to replace the ole32.dll (inside Windows\SysWow64) with a newer one, but then visual studio did not start at all (instant crash). I'm using SMFL 2.1 (32 bit) with Visual Studio 2010 on a 64 bit Win 7 Machine. Any help appreciated!


main.cpp:



#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>

int main()
{
   sf::RenderWindow mMainWindow(sf::VideoMode(300,400,32), "Exitsoundcrash", sf::Style::Titlebar);
   sf::Event mMainEvent;

   sf::SoundBuffer soundBuffer;         //  <-----sound doesn't play (error in console window)            
   sf::Sound sound;                              
   sound.setBuffer(soundBuffer);
   if (!soundBuffer.loadFromFile("car.wav"))
      return -1;
   sound.play();

//   sf::Music music;               <----- this works
//   if (!music.openFromFile("car.wav"))
//      return -1;
//   music.play();
   


   while(mMainWindow.isOpen())
   {
      
      while(mMainWindow.pollEvent(mMainEvent))
      {

         if(mMainEvent.key.code == sf::Keyboard::Escape)
         mMainWindow.close();
      }
   
      mMainWindow.clear();
      mMainWindow.setFramerateLimit(30);
      mMainWindow.display();
   }

   return 0;
}

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Sound is not working (error)
« Reply #1 on: May 19, 2014, 09:53:17 pm »
...
   sf::SoundBuffer soundBuffer;         //  <-----sound doesn't play (error in console window)            
   sf::Sound sound;                              
   sound.setBuffer(soundBuffer);
   if (!soundBuffer.loadFromFile("car.wav"))
      return -1;
   sound.play();
...

Try this:
        sf::SoundBuffer soundBuffer;
        if (!soundBuffer.loadFromFile("car.wav"))
                return -1;
        sf::Sound sound;
        sound.setBuffer(soundBuffer);
        sound.play();
 
« Last Edit: May 20, 2014, 08:33:17 am by Jesper Juhl »

G.

  • Hero Member
  • *****
  • Posts: 1592
    • View Profile
Re: Sound is not working (error)
« Reply #2 on: May 19, 2014, 10:24:06 pm »
Didn't find a "more documented" source. :p
You should attach the sound buffer to the sound after loading it.

Admitedly, this behaviour is not very well documented.

PS @Jesper, I don't think there should be an & in your setBuffer
« Last Edit: May 19, 2014, 10:27:00 pm by G. »

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Sound is not working (error)
« Reply #3 on: May 20, 2014, 08:35:12 am »
@G. You are correct. That's what happens when you use your phone to reply and don't double check the documentation I guess. Thank's for the correction.

 

anything