Back to index

libsfml  1.6+dfsg2
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
sf::priv::AudioDevice Class Reference

AudioDevice is the high-level wrapper around the audio API, it manages creation and destruction of the audio device and context and stores the device capabilities /////////////////////////////////////////////////////////. More...

#include <AudioDevice.hpp>

Collaboration diagram for sf::priv::AudioDevice:
Collaboration graph
[legend]

List of all members.

Public Member Functions

ALCdevice * GetDevice () const
 Get the OpenAL audio device.
ALenum GetFormatFromChannelsCount (unsigned int ChannelsCount) const
 Get the OpenAL format that matches the given number of channels.

Static Public Member Functions

static AudioDeviceGetInstance ()
 Get the unique instance of the class.
static void AddReference ()
 Add a reference to the audio device.
static void RemoveReference ()
 Remove a reference to the audio device.

Private Member Functions

 AudioDevice ()
 Default constructor.
 ~AudioDevice ()
 Destructor.

Private Attributes

ALCdevice * myDevice
 Audio device.
ALCcontext * myContext
 Audio context.
unsigned int myRefCount
 References count.

Static Private Attributes

static AudioDeviceourInstance
 Unique instance of the audio device.

Detailed Description

AudioDevice is the high-level wrapper around the audio API, it manages creation and destruction of the audio device and context and stores the device capabilities /////////////////////////////////////////////////////////.

Definition at line 48 of file AudioDevice.hpp.


Constructor & Destructor Documentation

Default constructor.

Default constructor /////////////////////////////////////////////////////////.

/////////////////////////////////////////////////////////

Definition at line 48 of file AudioDevice.cpp.

                         :
myRefCount(0)
{
    // Create the device
    myDevice = alcOpenDevice(NULL);

    if (myDevice)
    {
        // Create the context
        myContext = alcCreateContext(myDevice, NULL);

        if (myContext)
        {
            // Set the context as the current one (we'll only need one)
            alcMakeContextCurrent(myContext);

            // Initialize the listener, located at the origin and looking along the Z axis
            Listener::SetPosition(0.f, 0.f, 0.f);
            Listener::SetTarget(0.f, 0.f, -1.f);
        }
        else
        {
            std::cerr << "Failed to create the audio context" << std::endl;
        }
    }
    else
    {
        std::cerr << "Failed to open the audio device" << std::endl;
    }
}

Here is the caller graph for this function:

Destructor.

Destructor /////////////////////////////////////////////////////////.

/////////////////////////////////////////////////////////

Definition at line 83 of file AudioDevice.cpp.

{
    // Destroy the context
    alcMakeContextCurrent(NULL);
    if (myContext)
        alcDestroyContext(myContext);
    
    // Destroy the device
    if (myDevice)
        alcCloseDevice(myDevice);
}

Member Function Documentation

Add a reference to the audio device.

Add a reference to the audio device /////////////////////////////////////////////////////////.

/////////////////////////////////////////////////////////

Definition at line 112 of file AudioDevice.cpp.

{
    // Create the audio device if it doesn't exist
    if (!ourInstance)
        ourInstance = new AudioDevice;

    // Increase the references count
    ourInstance->myRefCount++;
}

Here is the call graph for this function:

ALCdevice * sf::priv::AudioDevice::GetDevice ( ) const

Get the OpenAL audio device.

Get the OpenAL audio device /////////////////////////////////////////////////////////.

Returns:
OpenAL device (cannot be NULL)

/////////////////////////////////////////////////////////

Definition at line 143 of file AudioDevice.cpp.

{
    return myDevice;
}
ALenum sf::priv::AudioDevice::GetFormatFromChannelsCount ( unsigned int  ChannelsCount) const

Get the OpenAL format that matches the given number of channels.

Get the OpenAL format that matches the given number of channels /////////////////////////////////////////////////////////.

Parameters:
ChannelsCount: Number of channels
Returns:
OpenAL device (cannot be NULL)

/////////////////////////////////////////////////////////

Definition at line 152 of file AudioDevice.cpp.

{
    // Find the good format according to the number of channels
    switch (ChannelsCount)
    {
        case 1 : return AL_FORMAT_MONO16;
        case 2 : return AL_FORMAT_STEREO16;
        case 4 : return alGetEnumValue("AL_FORMAT_QUAD16");
        case 6 : return alGetEnumValue("AL_FORMAT_51CHN16");
        case 7 : return alGetEnumValue("AL_FORMAT_61CHN16");
        case 8 : return alGetEnumValue("AL_FORMAT_71CHN16");
    }

    return 0;
}

Get the unique instance of the class.

Get the unique instance of the class /////////////////////////////////////////////////////////.

Returns:
Unique instance of the class

/////////////////////////////////////////////////////////

Definition at line 99 of file AudioDevice.cpp.

{
    // Create the audio device if it doesn't exist
    if (!ourInstance)
        ourInstance = new AudioDevice;

    return *ourInstance;
}

Here is the call graph for this function:

Remove a reference to the audio device.

Remove a reference to the audio device /////////////////////////////////////////////////////////.

/////////////////////////////////////////////////////////

Definition at line 126 of file AudioDevice.cpp.

{
    // Decrease the references count
    ourInstance->myRefCount--;

    // Destroy the audio device if the references count reaches 0
    if (ourInstance->myRefCount == 0)
    {
        delete ourInstance;
        ourInstance = NULL;
    }
}

Member Data Documentation

ALCcontext* sf::priv::AudioDevice::myContext [private]

Audio context.

Definition at line 113 of file AudioDevice.hpp.

ALCdevice* sf::priv::AudioDevice::myDevice [private]

Audio device.

Definition at line 112 of file AudioDevice.hpp.

unsigned int sf::priv::AudioDevice::myRefCount [private]

References count.

Definition at line 114 of file AudioDevice.hpp.

Unique instance of the audio device.

Definition at line 107 of file AudioDevice.hpp.


The documentation for this class was generated from the following files: