2009-06-21 05:24:30 +02:00
|
|
|
#include <iostream>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2009-08-26 03:16:40 +02:00
|
|
|
#include "../Headers/cAudio.h"
|
2009-11-20 04:39:56 +01:00
|
|
|
#include "../Headers/cLogger.h"
|
2009-06-21 05:24:30 +02:00
|
|
|
|
|
|
|
namespace cAudio
|
|
|
|
{
|
|
|
|
cAudio::cAudio(IAudioDecoder* decoder) : Decoder(decoder)
|
|
|
|
{
|
2009-08-29 13:24:31 +02:00
|
|
|
Mutex.lock();
|
2009-11-28 04:58:24 +01:00
|
|
|
Loop = false;
|
2009-06-21 05:24:30 +02:00
|
|
|
|
|
|
|
//Generates 3 buffers for the ogg file
|
2009-11-28 04:58:24 +01:00
|
|
|
alGenBuffers(NUM_BUFFERS, Buffers);
|
2009-06-21 05:24:30 +02:00
|
|
|
//Creates one source to be stored.
|
2009-11-28 04:58:24 +01:00
|
|
|
alGenSources(1, &Source);
|
2009-11-20 04:39:56 +01:00
|
|
|
checkError();
|
2009-08-29 13:24:31 +02:00
|
|
|
Mutex.unlock();
|
2009-06-21 05:24:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
cAudio::~cAudio()
|
|
|
|
{
|
2009-08-29 13:24:31 +02:00
|
|
|
Mutex.lock();
|
2009-06-21 05:24:30 +02:00
|
|
|
delete Decoder;
|
2009-08-29 13:24:31 +02:00
|
|
|
Mutex.unlock();
|
2009-06-21 05:24:30 +02:00
|
|
|
}
|
|
|
|
|
2009-11-28 04:58:24 +01:00
|
|
|
bool cAudio::play()
|
|
|
|
{
|
2009-08-29 13:24:31 +02:00
|
|
|
Mutex.lock();
|
2009-11-28 04:58:24 +01:00
|
|
|
if (!isPaused())
|
|
|
|
{
|
|
|
|
int queueSize = 0;
|
|
|
|
for(int u = 0; u < NUM_BUFFERS; u++)
|
|
|
|
{
|
|
|
|
int val = stream(Buffers[u]);
|
|
|
|
|
|
|
|
if(val < 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if(val > 0)
|
|
|
|
++queueSize;
|
|
|
|
}
|
|
|
|
//Stores the sources 3 buffers to be used in the queue
|
|
|
|
alSourceQueueBuffers(Source, queueSize, Buffers);
|
|
|
|
checkError();
|
|
|
|
}
|
|
|
|
alSourcePlay(Source);
|
2009-11-20 04:39:56 +01:00
|
|
|
checkError();
|
2009-08-29 13:24:31 +02:00
|
|
|
Mutex.unlock();
|
2009-11-28 04:58:24 +01:00
|
|
|
getLogger()->logDebug("Audio Source", "Source playing.");
|
|
|
|
return true;
|
2009-06-21 05:24:30 +02:00
|
|
|
}
|
|
|
|
|
2009-11-28 04:58:24 +01:00
|
|
|
bool cAudio::play2d(const bool& toLoop)
|
|
|
|
{
|
2009-08-29 13:24:31 +02:00
|
|
|
Mutex.lock();
|
2009-11-28 04:58:24 +01:00
|
|
|
alSourcei(Source, AL_SOURCE_RELATIVE, true);
|
|
|
|
loop(toLoop);
|
|
|
|
bool state = play();
|
|
|
|
checkError();
|
2009-08-29 13:24:31 +02:00
|
|
|
Mutex.unlock();
|
2009-11-28 04:58:24 +01:00
|
|
|
return state;
|
2009-06-21 05:24:30 +02:00
|
|
|
}
|
|
|
|
|
2009-11-28 04:58:24 +01:00
|
|
|
bool cAudio::play3d(const cVector3& position, const float& soundstr, const bool& toLoop)
|
|
|
|
{
|
2009-08-29 13:24:31 +02:00
|
|
|
Mutex.lock();
|
2009-11-28 04:58:24 +01:00
|
|
|
alSourcei(Source, AL_SOURCE_RELATIVE, false);
|
|
|
|
setPosition(position);
|
|
|
|
setStrength(soundstr);
|
|
|
|
loop(toLoop);
|
|
|
|
bool state = play();
|
|
|
|
checkError();
|
2009-08-29 13:24:31 +02:00
|
|
|
Mutex.unlock();
|
2009-11-28 04:58:24 +01:00
|
|
|
return state;
|
2009-06-21 05:24:30 +02:00
|
|
|
}
|
|
|
|
|
2009-11-28 04:58:24 +01:00
|
|
|
void cAudio::pause()
|
|
|
|
{
|
2009-08-29 13:24:31 +02:00
|
|
|
Mutex.lock();
|
2009-11-28 04:58:24 +01:00
|
|
|
alSourcePause(Source);
|
|
|
|
checkError();
|
|
|
|
Mutex.unlock();
|
|
|
|
getLogger()->logDebug("Audio Source", "Source paused.");
|
|
|
|
}
|
|
|
|
|
|
|
|
void cAudio::stop()
|
|
|
|
{
|
|
|
|
Mutex.lock();
|
|
|
|
alSourceStop(Source);
|
|
|
|
checkError();
|
|
|
|
Mutex.unlock();
|
|
|
|
getLogger()->logDebug("Audio Source", "Source stopped.");
|
|
|
|
}
|
2009-06-21 05:24:30 +02:00
|
|
|
|
2009-11-28 04:58:24 +01:00
|
|
|
void cAudio::loop(const bool& loop)
|
|
|
|
{
|
|
|
|
Mutex.lock();
|
|
|
|
Loop = loop;
|
2009-08-29 13:24:31 +02:00
|
|
|
Mutex.unlock();
|
2009-06-21 05:24:30 +02:00
|
|
|
}
|
|
|
|
|
2009-11-28 04:58:24 +01:00
|
|
|
bool cAudio::seek(const float& seconds)
|
|
|
|
{
|
|
|
|
bool state = false;
|
2009-08-29 13:24:31 +02:00
|
|
|
Mutex.lock();
|
2009-11-28 04:58:24 +01:00
|
|
|
if(Decoder->isSeekingSupported())
|
|
|
|
{
|
|
|
|
state = Decoder->seek(seconds, false);
|
|
|
|
}
|
|
|
|
Mutex.unlock();
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cAudio::update()
|
|
|
|
{
|
|
|
|
if(!isValid() || !isPlaying())
|
2009-08-29 13:24:31 +02:00
|
|
|
{
|
2009-06-21 05:24:30 +02:00
|
|
|
return false;
|
2009-08-29 13:24:31 +02:00
|
|
|
}
|
2009-06-21 05:24:30 +02:00
|
|
|
int processed = 0;
|
|
|
|
bool active = true;
|
2009-11-28 04:58:24 +01:00
|
|
|
|
|
|
|
Mutex.lock();
|
|
|
|
//gets the sound source processed buffers
|
|
|
|
alGetSourcei(Source, AL_BUFFERS_PROCESSED, &processed);
|
2009-08-11 19:57:20 +02:00
|
|
|
//while there is more data refill buffers with audio data.
|
|
|
|
while (processed--)
|
2009-06-21 05:24:30 +02:00
|
|
|
{
|
|
|
|
ALuint buffer;
|
2009-11-28 04:58:24 +01:00
|
|
|
alSourceUnqueueBuffers(Source, 1, &buffer);
|
2009-06-21 05:24:30 +02:00
|
|
|
active = stream(buffer);
|
|
|
|
|
2009-08-11 19:57:20 +02:00
|
|
|
//if more in stream continue playing.
|
2009-06-21 05:24:30 +02:00
|
|
|
if(active)
|
2009-11-28 04:58:24 +01:00
|
|
|
alSourceQueueBuffers(Source, 1, &buffer);
|
2009-11-20 04:39:56 +01:00
|
|
|
|
|
|
|
checkError();
|
2009-06-21 05:24:30 +02:00
|
|
|
}
|
2009-08-29 13:24:31 +02:00
|
|
|
Mutex.unlock();
|
2009-08-11 19:57:20 +02:00
|
|
|
return active;
|
2009-06-21 05:24:30 +02:00
|
|
|
}
|
|
|
|
|
2009-11-28 04:58:24 +01:00
|
|
|
void cAudio::release()
|
2009-06-21 05:24:30 +02:00
|
|
|
{
|
2009-11-28 04:58:24 +01:00
|
|
|
Mutex.lock();
|
|
|
|
//Stops the audio Source
|
|
|
|
alSourceStop(Source);
|
|
|
|
empty();
|
|
|
|
//Deletes the source
|
|
|
|
alDeleteSources(1, &Source);
|
|
|
|
//deletes the last filled buffer
|
|
|
|
alDeleteBuffers(NUM_BUFFERS, Buffers);
|
|
|
|
checkError();
|
|
|
|
Mutex.unlock();
|
|
|
|
getLogger()->logDebug("Audio Source", "Audio source released.");
|
2009-06-21 05:24:30 +02:00
|
|
|
}
|
|
|
|
|
2009-11-28 04:58:24 +01:00
|
|
|
const bool cAudio::isValid() const
|
|
|
|
{
|
|
|
|
bool state = (Decoder != 0);
|
|
|
|
return state;
|
|
|
|
}
|
2009-06-21 05:24:30 +02:00
|
|
|
|
2009-11-28 04:58:24 +01:00
|
|
|
const bool cAudio::isPlaying() const
|
|
|
|
{
|
|
|
|
ALenum state = 0;
|
|
|
|
alGetSourcei(Source, AL_SOURCE_STATE, &state);
|
|
|
|
return (state == AL_PLAYING);
|
2009-06-21 05:24:30 +02:00
|
|
|
}
|
|
|
|
|
2009-11-28 04:58:24 +01:00
|
|
|
const bool cAudio::isPaused() const
|
|
|
|
{
|
|
|
|
ALenum state = 0;
|
|
|
|
alGetSourcei(Source, AL_SOURCE_STATE, &state);
|
|
|
|
return (state == AL_PAUSED);
|
|
|
|
}
|
2009-06-21 05:24:30 +02:00
|
|
|
|
2009-11-28 04:58:24 +01:00
|
|
|
const bool cAudio::isStopped() const
|
|
|
|
{
|
|
|
|
ALenum state = 0;
|
|
|
|
alGetSourcei(Source, AL_SOURCE_STATE, &state);
|
|
|
|
return (state == AL_STOPPED);
|
2009-06-21 05:24:30 +02:00
|
|
|
}
|
|
|
|
|
2009-11-28 04:58:24 +01:00
|
|
|
const bool cAudio::isLooping() const
|
|
|
|
{
|
|
|
|
return Loop;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cAudio::setPosition(const cVector3& position)
|
|
|
|
{
|
2009-08-29 13:24:31 +02:00
|
|
|
Mutex.lock();
|
2009-11-28 04:58:24 +01:00
|
|
|
alSource3f(Source, AL_POSITION, position.x, position.y, position.z);
|
|
|
|
checkError();
|
2009-08-29 13:24:31 +02:00
|
|
|
Mutex.unlock();
|
2009-06-21 05:24:30 +02:00
|
|
|
}
|
|
|
|
|
2009-11-28 04:58:24 +01:00
|
|
|
void cAudio::setVelocity(const cVector3& velocity)
|
|
|
|
{
|
2009-08-29 13:24:31 +02:00
|
|
|
Mutex.lock();
|
2009-11-28 04:58:24 +01:00
|
|
|
alSource3f(Source, AL_VELOCITY, velocity.x, velocity.y, velocity.z);
|
2009-11-20 04:39:56 +01:00
|
|
|
checkError();
|
2009-08-29 13:24:31 +02:00
|
|
|
Mutex.unlock();
|
2009-06-21 05:24:30 +02:00
|
|
|
}
|
|
|
|
|
2009-11-28 04:58:24 +01:00
|
|
|
void cAudio::setDirection(const cVector3& direction)
|
|
|
|
{
|
2009-08-29 13:24:31 +02:00
|
|
|
Mutex.lock();
|
2009-11-28 04:58:24 +01:00
|
|
|
alSource3f(Source, AL_DIRECTION, direction.x, direction.y, direction.z);
|
2009-11-20 04:39:56 +01:00
|
|
|
checkError();
|
2009-08-29 13:24:31 +02:00
|
|
|
Mutex.unlock();
|
2009-06-21 05:24:30 +02:00
|
|
|
}
|
|
|
|
|
2009-11-28 04:58:24 +01:00
|
|
|
void cAudio::setRolloffFactor(const float& rolloff)
|
|
|
|
{
|
2009-08-29 13:24:31 +02:00
|
|
|
Mutex.lock();
|
2009-11-28 04:58:24 +01:00
|
|
|
alSourcef(Source, AL_ROLLOFF_FACTOR, rolloff);
|
|
|
|
checkError();
|
2009-08-29 13:24:31 +02:00
|
|
|
Mutex.unlock();
|
2009-06-21 05:24:30 +02:00
|
|
|
}
|
|
|
|
|
2009-11-28 04:58:24 +01:00
|
|
|
void cAudio::setStrength(const float& soundstrength)
|
|
|
|
{
|
|
|
|
float inverseStrength = 0.0f;
|
|
|
|
if(soundstrength > 0.0f)
|
|
|
|
inverseStrength = 1.0f / soundstrength;
|
|
|
|
|
2009-08-29 13:24:31 +02:00
|
|
|
Mutex.lock();
|
2009-11-28 04:58:24 +01:00
|
|
|
alSourcef(Source, AL_ROLLOFF_FACTOR, inverseStrength);
|
2009-11-20 04:39:56 +01:00
|
|
|
checkError();
|
2009-08-29 13:24:31 +02:00
|
|
|
Mutex.unlock();
|
2009-06-21 05:24:30 +02:00
|
|
|
}
|
|
|
|
|
2009-11-28 04:58:24 +01:00
|
|
|
void cAudio::setMinDistance(const float& minDistance)
|
|
|
|
{
|
2009-08-29 13:24:31 +02:00
|
|
|
Mutex.lock();
|
2009-11-28 04:58:24 +01:00
|
|
|
alSourcef(Source, AL_REFERENCE_DISTANCE, minDistance);
|
2009-11-20 04:39:56 +01:00
|
|
|
checkError();
|
2009-08-29 13:24:31 +02:00
|
|
|
Mutex.unlock();
|
2009-11-28 04:58:24 +01:00
|
|
|
}
|
2009-06-21 05:24:30 +02:00
|
|
|
|
2009-11-28 04:58:24 +01:00
|
|
|
void cAudio::setMaxDistance(const float& maxDistance)
|
|
|
|
{
|
2009-08-29 13:24:31 +02:00
|
|
|
Mutex.lock();
|
2009-11-28 04:58:24 +01:00
|
|
|
alSourcef(Source, AL_MAX_DISTANCE, maxDistance);
|
2009-11-20 04:39:56 +01:00
|
|
|
checkError();
|
2009-08-29 13:24:31 +02:00
|
|
|
Mutex.unlock();
|
2009-11-28 04:58:24 +01:00
|
|
|
}
|
2009-06-21 05:24:30 +02:00
|
|
|
|
2009-11-28 04:58:24 +01:00
|
|
|
void cAudio::setPitch(const float& pitch)
|
|
|
|
{
|
2009-08-29 13:24:31 +02:00
|
|
|
Mutex.lock();
|
2009-11-28 04:58:24 +01:00
|
|
|
alSourcef (Source, AL_PITCH, pitch);
|
2009-11-20 04:39:56 +01:00
|
|
|
checkError();
|
2009-08-29 13:24:31 +02:00
|
|
|
Mutex.unlock();
|
2009-06-21 05:24:30 +02:00
|
|
|
}
|
|
|
|
|
2009-11-28 04:58:24 +01:00
|
|
|
void cAudio::setVolume(const float& volume)
|
|
|
|
{
|
2009-08-29 13:24:31 +02:00
|
|
|
Mutex.lock();
|
2009-11-28 04:58:24 +01:00
|
|
|
alSourcef(Source, AL_GAIN, volume);
|
2009-11-20 04:39:56 +01:00
|
|
|
checkError();
|
2009-08-29 13:24:31 +02:00
|
|
|
Mutex.unlock();
|
2009-06-21 05:24:30 +02:00
|
|
|
}
|
|
|
|
|
2009-11-28 04:58:24 +01:00
|
|
|
void cAudio::setMinVolume(const float& minVolume)
|
|
|
|
{
|
2009-08-29 13:24:31 +02:00
|
|
|
Mutex.lock();
|
2009-11-28 04:58:24 +01:00
|
|
|
alSourcef(Source, AL_MIN_GAIN, minVolume);
|
2009-11-20 04:39:56 +01:00
|
|
|
checkError();
|
2009-08-29 13:24:31 +02:00
|
|
|
Mutex.unlock();
|
2009-11-28 04:58:24 +01:00
|
|
|
}
|
2009-06-21 05:24:30 +02:00
|
|
|
|
2009-11-28 04:58:24 +01:00
|
|
|
void cAudio::setMaxVolume(const float& maxVolume)
|
|
|
|
{
|
|
|
|
Mutex.lock();
|
|
|
|
alSourcef(Source, AL_MAX_GAIN, maxVolume);
|
|
|
|
checkError();
|
|
|
|
Mutex.unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void cAudio::setInnerConeAngle(const float& innerAngle)
|
|
|
|
{
|
2009-08-29 13:24:31 +02:00
|
|
|
Mutex.lock();
|
2009-11-28 04:58:24 +01:00
|
|
|
alSourcef(Source, AL_CONE_INNER_ANGLE, innerAngle);
|
|
|
|
checkError();
|
|
|
|
Mutex.unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void cAudio::setOuterConeAngle(const float& outerAngle)
|
|
|
|
{
|
|
|
|
Mutex.lock();
|
|
|
|
alSourcef(Source, AL_CONE_OUTER_ANGLE, outerAngle);
|
|
|
|
checkError();
|
|
|
|
Mutex.unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void cAudio::setOuterConeVolume(const float& outerVolume)
|
|
|
|
{
|
|
|
|
Mutex.lock();
|
|
|
|
alSourcef(Source, AL_CONE_OUTER_GAIN, outerVolume);
|
|
|
|
checkError();
|
|
|
|
Mutex.unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void cAudio::setDopplerStrength(const float& dstrength)
|
|
|
|
{
|
|
|
|
Mutex.lock();
|
|
|
|
alSourcef(Source, AL_DOPPLER_FACTOR, dstrength);
|
2009-11-20 04:39:56 +01:00
|
|
|
checkError();
|
2009-08-29 13:24:31 +02:00
|
|
|
Mutex.unlock();
|
2009-06-21 05:24:30 +02:00
|
|
|
}
|
|
|
|
|
2009-11-28 04:58:24 +01:00
|
|
|
void cAudio::setDopplerVelocity(const cVector3& dvelocity)
|
|
|
|
{
|
2009-08-29 13:24:31 +02:00
|
|
|
Mutex.lock();
|
2009-11-28 04:58:24 +01:00
|
|
|
alSource3f(Source, AL_DOPPLER_VELOCITY, dvelocity.x, dvelocity.y, dvelocity.z);
|
2009-11-20 04:39:56 +01:00
|
|
|
checkError();
|
2009-08-29 13:24:31 +02:00
|
|
|
Mutex.unlock();
|
2009-06-21 05:24:30 +02:00
|
|
|
}
|
|
|
|
|
2009-11-28 04:58:24 +01:00
|
|
|
const cVector3 cAudio::getPosition() const
|
|
|
|
{
|
|
|
|
cVector3 position;
|
|
|
|
alGetSourcefv(Source, AL_POSITION, &position.x);
|
|
|
|
return position;
|
|
|
|
}
|
|
|
|
|
|
|
|
const cVector3 cAudio::getVelocity() const
|
2009-08-26 04:19:58 +02:00
|
|
|
{
|
2009-11-28 04:58:24 +01:00
|
|
|
cVector3 velocity;
|
|
|
|
alGetSourcefv(Source, AL_VELOCITY, &velocity.x);
|
|
|
|
return velocity;
|
2009-08-26 04:19:58 +02:00
|
|
|
}
|
2009-11-28 04:58:24 +01:00
|
|
|
|
|
|
|
const cVector3 cAudio::getDirection() const
|
2009-08-26 05:06:36 +02:00
|
|
|
{
|
2009-11-28 04:58:24 +01:00
|
|
|
cVector3 direction;
|
|
|
|
alGetSourcefv(Source, AL_DIRECTION, &direction.x);
|
|
|
|
return direction;
|
2009-08-26 04:19:58 +02:00
|
|
|
}
|
2009-11-28 04:58:24 +01:00
|
|
|
|
|
|
|
const float cAudio::getRolloffFactor() const
|
2009-08-26 05:06:36 +02:00
|
|
|
{
|
2009-11-28 04:58:24 +01:00
|
|
|
float value = 0.0f;
|
|
|
|
alGetSourcef(Source, AL_ROLLOFF_FACTOR, &value);
|
|
|
|
return value;
|
2009-08-26 04:19:58 +02:00
|
|
|
}
|
2009-11-28 04:58:24 +01:00
|
|
|
|
|
|
|
const float cAudio::getStrength() const
|
2009-08-26 05:06:36 +02:00
|
|
|
{
|
2009-11-28 04:58:24 +01:00
|
|
|
float value = 0.0f;
|
|
|
|
alGetSourcef(Source, AL_ROLLOFF_FACTOR, &value);
|
|
|
|
|
|
|
|
float inverseStrength = 0.0f;
|
|
|
|
if(value > 0.0f)
|
|
|
|
inverseStrength = 1.0f / value;
|
|
|
|
|
|
|
|
return inverseStrength;
|
2009-08-26 04:19:58 +02:00
|
|
|
}
|
2009-11-28 04:58:24 +01:00
|
|
|
|
|
|
|
const float cAudio::getMinDistance() const
|
2009-08-26 05:06:36 +02:00
|
|
|
{
|
2009-11-28 04:58:24 +01:00
|
|
|
float value = 0.0f;
|
|
|
|
alGetSourcef(Source, AL_REFERENCE_DISTANCE, &value);
|
|
|
|
return value;
|
2009-08-26 04:19:58 +02:00
|
|
|
}
|
2009-11-28 04:58:24 +01:00
|
|
|
|
|
|
|
const float cAudio::getMaxDistance() const
|
2009-08-26 05:06:36 +02:00
|
|
|
{
|
2009-11-28 04:58:24 +01:00
|
|
|
float value = 0.0f;
|
|
|
|
alGetSourcef(Source, AL_MAX_DISTANCE, &value);
|
|
|
|
return value;
|
2009-08-26 04:19:58 +02:00
|
|
|
}
|
2009-11-28 04:58:24 +01:00
|
|
|
|
|
|
|
const float cAudio::getPitch() const
|
|
|
|
{
|
|
|
|
float value = 0.0f;
|
|
|
|
alGetSourcef(Source, AL_PITCH, &value);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
const float cAudio::getVolume() const
|
2009-08-26 05:06:36 +02:00
|
|
|
{
|
2009-11-28 04:58:24 +01:00
|
|
|
float value = 0.0f;
|
|
|
|
alGetSourcef(Source, AL_GAIN, &value);
|
|
|
|
return value;
|
2009-08-26 04:19:58 +02:00
|
|
|
}
|
2009-11-28 04:58:24 +01:00
|
|
|
|
|
|
|
const float cAudio::getMinVolume() const
|
|
|
|
{
|
|
|
|
float value = 0.0f;
|
|
|
|
alGetSourcef(Source, AL_MIN_GAIN, &value);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
const float cAudio::getMaxVolume() const
|
|
|
|
{
|
|
|
|
float value = 0.0f;
|
|
|
|
alGetSourcef(Source, AL_MAX_GAIN, &value);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
const float cAudio::getInnerConeAngle() const
|
|
|
|
{
|
|
|
|
float value = 0.0f;
|
|
|
|
alGetSourcef(Source, AL_CONE_INNER_ANGLE, &value);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
const float cAudio::getOuterConeAngle() const
|
2009-08-26 05:06:36 +02:00
|
|
|
{
|
2009-11-28 04:58:24 +01:00
|
|
|
float value = 0.0f;
|
|
|
|
alGetSourcef(Source, AL_CONE_OUTER_ANGLE, &value);
|
|
|
|
return value;
|
2009-08-26 04:19:58 +02:00
|
|
|
}
|
|
|
|
|
2009-11-28 04:58:24 +01:00
|
|
|
const float cAudio::getOuterConeVolume() const
|
|
|
|
{
|
|
|
|
float value = 0.0f;
|
|
|
|
alGetSourcef(Source, AL_CONE_OUTER_GAIN, &value);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
const float cAudio::getDopplerStrength() const
|
|
|
|
{
|
|
|
|
float value = 0.0f;
|
|
|
|
alGetSourcef(Source, AL_DOPPLER_FACTOR, &value);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
const cVector3 cAudio::getDopplerVelocity() const
|
|
|
|
{
|
|
|
|
cVector3 velocity;
|
|
|
|
alGetSourcefv(Source, AL_DOPPLER_VELOCITY, &velocity.x);
|
|
|
|
return velocity;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cAudio::empty()
|
2009-06-21 05:24:30 +02:00
|
|
|
{
|
2009-11-28 04:58:24 +01:00
|
|
|
int queued = 0;
|
|
|
|
alGetSourcei(Source, AL_BUFFERS_QUEUED, &queued);
|
|
|
|
|
|
|
|
while (queued--)
|
2009-06-21 05:24:30 +02:00
|
|
|
{
|
2009-11-28 04:58:24 +01:00
|
|
|
ALuint buffer;
|
|
|
|
alSourceUnqueueBuffers(Source, 1, &buffer);
|
|
|
|
checkError();
|
2009-06-21 05:24:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-28 04:58:24 +01:00
|
|
|
void cAudio::checkError()
|
2009-06-21 05:24:30 +02:00
|
|
|
{
|
2009-11-28 04:58:24 +01:00
|
|
|
int error = alGetError();
|
|
|
|
const char* errorString;
|
|
|
|
|
|
|
|
if (error != AL_NO_ERROR)
|
|
|
|
{
|
|
|
|
errorString = alGetString(error);
|
|
|
|
if(error == AL_OUT_OF_MEMORY)
|
|
|
|
getLogger()->logCritical("Audio Source", "OpenAL Error: %s.", errorString);
|
|
|
|
else
|
|
|
|
getLogger()->logError("Audio Source", "OpenAL Error: %s.", errorString);
|
2009-08-11 19:57:20 +02:00
|
|
|
}
|
2009-06-21 05:24:30 +02:00
|
|
|
}
|
|
|
|
|
2009-11-28 04:58:24 +01:00
|
|
|
bool cAudio::stream(ALuint buffer)
|
2009-06-21 05:24:30 +02:00
|
|
|
{
|
2009-11-28 04:58:24 +01:00
|
|
|
if(Decoder)
|
|
|
|
{
|
|
|
|
//stores the caculated data into buffer that is passed to output.
|
|
|
|
size_t totalread = 0;
|
|
|
|
unsigned int errorcount = 0;
|
|
|
|
char tempbuffer[BUFFER_SIZE];
|
|
|
|
while( totalread < BUFFER_SIZE )
|
|
|
|
{
|
|
|
|
char tempbuffer2[BUFFER_SIZE];
|
|
|
|
int actualread = Decoder->readAudioData(tempbuffer2, BUFFER_SIZE-totalread);
|
|
|
|
if(actualread > 0)
|
|
|
|
{
|
|
|
|
memcpy(tempbuffer+totalread,tempbuffer2,actualread);
|
|
|
|
totalread += actualread;
|
|
|
|
}
|
|
|
|
if(actualread < 0)
|
|
|
|
{
|
|
|
|
++errorcount;
|
|
|
|
getLogger()->logDebug("Audio Source", "Decoder returned an error: %i (%i of 3)", actualread, errorcount);
|
|
|
|
if(errorcount >= 3)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(actualread == 0)
|
|
|
|
{
|
|
|
|
if(isLooping())
|
|
|
|
{
|
|
|
|
//If we are to loop, set to the beginning and reload from the start
|
|
|
|
Decoder->setPosition(0, false);
|
|
|
|
getLogger()->logDebug("Audio Source", "Buffer looping.");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-06-21 05:24:30 +02:00
|
|
|
|
2009-11-28 04:58:24 +01:00
|
|
|
//Second check, in case looping is not enabled, we will return false for end of stream
|
|
|
|
if(totalread == 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
getLogger()->logDebug("Audio Source", "Buffered %i bytes of data into buffer %i at %i hz.", totalread, buffer, Decoder->getFrequency());
|
|
|
|
alBufferData(buffer, Decoder->getFormat(), tempbuffer, totalread, Decoder->getFrequency());
|
|
|
|
checkError();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2009-06-21 05:24:30 +02:00
|
|
|
}
|
|
|
|
}
|