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

Author Topic: Strange Open AL Errors  (Read 8497 times)

0 Members and 3 Guests are viewing this topic.

ComedicChimera

  • Newbie
  • *
  • Posts: 5
    • View Profile
Strange Open AL Errors
« on: September 19, 2018, 08:36:39 pm »
Hi, I was working recently on a project that required me to play variations of the same audio sample multiple times in rapid succession.  I have set up a Player class that will handle this for me. 

My Approach
My player class creates a single sf::SoundBuffer representing the source sample.  It then stores a queue for various sf::Sound objects that all use the same base sound buffer.  They all have pitches changes and volume adjustments applied and are pushed on the queue and played from the queue.  Before each play call, the player automatically pops all stopped sounds from the queue to save memory.

The Errors
In doing this I have come across a couple strange OpenAL errors.  Error Batch 1 happened at runtime and Error Batch 2 happened when the program was closing. (I am assuming they are caused be something gone awry in the destructor).  All of them seem to refer to invalid referencing or deleting of audio resources, but I am not sure.


Error Batch 1:
An internal OpenAL call failed in SoundSource.cpp(45).
Expression:
   alGenSources(1, &m_source)
Error description:
   AL_INVALID_VALUE
   A numeric argument is out of range.

An internal OpenAL call failed in SoundSource.cpp(46).
Expression:
   alSourcei(m_source, AL_BUFFER, 0)
Error description:
   AL_INVALID_NAME
   A bad name (ID) has been specified.

An internal OpenAL call failed in SoundSource.cpp(68).
Expression:
   alSourcef(m_source, AL_PITCH, pitch)
Error description:
   AL_INVALID_NAME
   A bad name (ID) has been specified.

An internal OpenAL call failed in SoundSource.cpp(75).
Expression:
   alSourcef(m_source, AL_GAIN, volume * 0.01f)
Error description:
   AL_INVALID_NAME
   A bad name (ID) has been specified.

An internal OpenAL call failed in SoundSource.cpp(82).
Expression:
   alSource3f(m_source, AL_POSITION, x, y, z)
Error description:
   AL_INVALID_NAME
   A bad name (ID) has been specified.

An internal OpenAL call failed in SoundSource.cpp(96).
Expression:
   alSourcei(m_source, AL_SOURCE_RELATIVE, relative)
Error description:
   AL_INVALID_NAME
   A bad name (ID) has been specified.

An internal OpenAL call failed in SoundSource.cpp(103).
Expression:
   alSourcef(m_source, AL_REFERENCE_DISTANCE, distance)
Error description:
   AL_INVALID_NAME
   A bad name (ID) has been specified.

An internal OpenAL call failed in SoundSource.cpp(110).
Expression:
   alSourcef(m_source, AL_ROLLOFF_FACTOR, attenuation)
Error description:
   AL_INVALID_NAME
   A bad name (ID) has been specified.

An internal OpenAL call failed in Sound.cpp(104).
Expression:
   alSourcei(m_source, AL_BUFFER, m_buffer->m_buffer)
Error description:
   AL_INVALID_NAME
   A bad name (ID) has been specified.

An internal OpenAL call failed in Sound.cpp(111).
Expression:
   alSourcei(m_source, AL_LOOPING, loop)
Error description:
   AL_INVALID_NAME
   A bad name (ID) has been specified.

An internal OpenAL call failed in Sound.cpp(73).
Expression:
   alSourcePlay(m_source)
Error description:
   AL_INVALID_NAME
   A bad name (ID) has been specified.

Error Batch 2:
An internal OpenAL call failed in SoundSource.cpp(60).
Expression:
   alSourcei(m_source, AL_BUFFER, 0)
Error description:
   AL_INVALID_NAME
   A bad name (ID) has been specified.

An internal OpenAL call failed in SoundSource.cpp(61).
Expression:
   alDeleteSources(1, &m_source)
Error description:
   AL_INVALID_OPERATION
   The specified operation is not allowed in the current state.

An internal OpenAL call failed in Sound.cpp(87).
Expression:
   alSourceStop(m_source)
Error description:
   AL_INVALID_NAME
   A bad name (ID) has been specified.

An internal OpenAL call failed in Sound.cpp(87).
Expression:
   alSourceStop(m_source)
Error description:
   AL_INVALID_NAME
   A bad name (ID) has been specified.

My Code
Below is the full implementation of my player class.  There is nothing more to it.

Player.h:
#pragma once

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

class Player {
        sf::SoundBuffer m_Sample;
        std::queue<sf::Sound> m_Sounds;

        int m_Max;

        float convertToPitch(int);

public:
        Player(int);
        ~Player();

        void playValue(int);
};
 

Player.cpp:
#include "player.h"

Player::Player(int max)
        : m_Max(max + 1)
{
        m_Sample.loadFromFile("data/sample.wav");
}

Player::~Player() {
        while (m_Sounds.size() > 0) {
                m_Sounds.front().stop();
                m_Sounds.pop();
        }
               
}

float Player::convertToPitch(int value) {
        return 2.0 * (value / (float)m_Max) + 0.01;
}

void Player::playValue(int value) {
        while (m_Sounds.size() > 0 && m_Sounds.front().getStatus() == sf::Sound::Stopped)
                m_Sounds.pop();

        float pitch = convertToPitch(value);
       
        sf::Sound sound;
        sound.setBuffer(m_Sample);
        sound.setPitch(pitch);
        sound.setVolume(20);

        m_Sounds.push(sound);
        m_Sounds.back().play();
}

Please get back to me as soon as possible and don't hesitate to let me know of anything else you need to see.
Thanks again!

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Strange Open AL Errors
« Reply #1 on: September 19, 2018, 10:07:38 pm »
How do you instance this Player class?
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

ComedicChimera

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Strange Open AL Errors
« Reply #2 on: September 20, 2018, 01:43:25 am »
It is a member of another class that is instantiated once in the program.  The Player class itself is only initialized once in the constructor of that other class.

dabbertorres

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • website/blog
Re: Strange Open AL Errors
« Reply #3 on: September 20, 2018, 04:59:25 am »
And how is "that other" class instantiated? Is it statically initialized?

ComedicChimera

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Strange Open AL Errors
« Reply #4 on: September 20, 2018, 05:39:50 am »
The other class is created in the body of a function that is only called once.  It creates a single instance of the player and is itself a single instance.  It is passed by reference a couple times, but it is never copied.  If need be, I can post a link the Github repo so you can see the entire project or the parent class as well.

The values of the holder class may change, but other than a variable used to calculate the pitch, the Player class es values are constant.

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Strange Open AL Errors
« Reply #5 on: September 20, 2018, 05:46:54 am »
I'm pretty sure there is an upper limit on the amount of OpenAL sound sources which you could have hit.
Back to C++ gamedev with SFML in May 2023

ComedicChimera

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Strange Open AL Errors
« Reply #6 on: September 20, 2018, 06:46:02 am »
That is kind of what I figured was happening.  If this is the case, is there anything I can do that will still allow me to play the sounds rapidly?  I think I big issue is that the pitch change also lengthens the already relatively long base sample.  Is it possible to set a maximum duration for sf::Sound or some other class?
I am open to any solution if it is reasonably possible.

ComedicChimera

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Strange Open AL Errors
« Reply #7 on: September 20, 2018, 07:13:45 am »
Ok, so I think I fixed it by switching to a list and removing based on both the time played and whether or not it is done.  Now, I just have to remove the sine wave buzzing on ending...

Thanks, guys!

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Strange Open AL Errors
« Reply #8 on: September 22, 2018, 09:23:01 pm »
Using a list is a good direction to go; it's my default when working with sounds.
Why, though, does using a queue causes OpenAL to complain?

As you probably know, a sine wave stopping instantly makes the sound have to jump from its current position to zero. Fading it out will smooth out the transition and will make zero the expected value. You can do this pretty quickly if you want it to sound like it's stopping 'instantly' or more slowly if you want a more natural 'tail'.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*