Automated formatting fix

This commit is contained in:
Bart van Strien
2011-11-16 11:32:41 +01:00
parent fafe472595
commit 0aae9684b3
262 changed files with 16705 additions and 16503 deletions
+33 -25
View File
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 LOVE Development Team
*
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
@@ -30,16 +30,18 @@ namespace audio
namespace openal
{
Audio::PoolThread::PoolThread(Pool* pool)
: pool(pool), finish(false) {
: pool(pool), finish(false)
{
}
void Audio::PoolThread::main()
{
while(true) {
while (true)
{
{
thread::Lock lock(mutex);
if (finish) {
if (finish)
{
return;
}
}
@@ -61,32 +63,35 @@ namespace openal
// Passing zero for default device.
device = alcOpenDevice(0);
if(device == 0)
if (device == 0)
throw love::Exception("Could not open device.");
context = alcCreateContext(device, 0);
if(context == 0)
if (context == 0)
throw love::Exception("Could not create context.");
alcMakeContextCurrent(context);
if(alcGetError(device) != ALC_NO_ERROR)
if (alcGetError(device) != ALC_NO_ERROR)
throw love::Exception("Could not make context current.");
/*std::string captureName(alcGetString(NULL, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER));
const ALCchar * devices = alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER);
while (*devices) {
while (*devices)
{
std::string device(devices);
devices += device.size() + 1;
if (device.find("Mic") != std::string::npos || device.find("mic") != std::string::npos) {
if (device.find("Mic") != std::string::npos || device.find("mic") != std::string::npos)
{
captureName = device;
}
}
capture = alcCaptureOpenDevice(captureName.c_str(), 8000, AL_FORMAT_MONO16, 262144); // about 32 seconds
if (!capture) {
if (!capture)
{
// We're not going to prevent LOVE from running without a microphone, but we should warn, at least
std::cerr << "Warning, couldn't open capture device! No audio input!" << std::endl;
}*/
@@ -105,7 +110,7 @@ namespace openal
delete poolThread;
delete pool;
alcMakeContextCurrent(0);
alcDestroyContext(context);
//if (capture) alcCaptureCloseDevice(capture);
@@ -167,7 +172,7 @@ namespace openal
{
source->resume();
}
void Audio::resume()
{
pool->resume();
@@ -224,16 +229,17 @@ namespace openal
{
alListenerfv(AL_VELOCITY, v);
}
void Audio::record()
{
if (!canRecord()) return;
alcCaptureStart(capture);
}
love::sound::SoundData * Audio::getRecordedData()
{
if (!canRecord()) return NULL;
if (!canRecord())
return NULL;
int samplerate = 8000;
ALCint samples;
alcGetIntegerv(capture, ALC_CAPTURE_SAMPLES, 4, &samples);
@@ -243,18 +249,20 @@ namespace openal
free(data);
return sd;
}
love::sound::SoundData * Audio::stopRecording(bool returnData)
{
if (!canRecord()) return NULL;
if (!canRecord())
return NULL;
love::sound::SoundData * sd = NULL;
if (returnData) {
if (returnData)
{
sd = getRecordedData();
}
alcCaptureStop(capture);
return sd;
}
bool Audio::canRecord()
{
return (capture != NULL);
+5 -5
View File
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 LOVE Development Team
*
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
@@ -57,7 +57,7 @@ namespace openal
// The OpenAL device.
ALCdevice * device;
// The OpenAL capture device (microphone).
ALCdevice * capture;
@@ -121,7 +121,7 @@ namespace openal
void setOrientation(float * v);
void getVelocity(float * v) const;
void setVelocity(float * v);
void record();
love::sound::SoundData * getRecordedData();
love::sound::SoundData * stopRecording(bool returnData);
+18 -18
View File
@@ -36,11 +36,11 @@ namespace openal
// Create the mutex.
mutex = new thread::Mutex();
if(alGetError() != AL_NO_ERROR)
if (alGetError() != AL_NO_ERROR)
throw love::Exception("Could not generate sources.");
// Make all sources available initially.
for(int i = 0; i < NUM_SOURCES; i++)
for (int i = 0; i < NUM_SOURCES; i++)
available.push(sources[i]);
}
@@ -69,9 +69,9 @@ namespace openal
bool p = false;
{
thread::Lock lock(mutex);
for(std::map<Source *, ALuint>::iterator i = playing.begin(); i != playing.end(); i++)
for (std::map<Source *, ALuint>::iterator i = playing.begin(); i != playing.end(); i++)
{
if(i->first == s)
if (i->first == s)
p = true;
}
}
@@ -84,9 +84,9 @@ namespace openal
std::map<Source *, ALuint>::iterator i = playing.begin();
while(i != playing.end())
while (i != playing.end())
{
if(!i->first->update())
if (!i->first->update())
{
i->first->stopAtomic();
i->first->rewindAtomic();
@@ -118,10 +118,10 @@ namespace openal
bool alreadyPlaying = findSource(source, out);
if(!alreadyPlaying)
if (!alreadyPlaying)
{
// Try to play.
if(!available.empty())
if (!available.empty())
{
// Get the first available source.
out = available.front();
@@ -154,7 +154,7 @@ namespace openal
void Pool::stop()
{
thread::Lock lock(mutex);
for(std::map<Source *, ALuint>::iterator i = playing.begin(); i != playing.end(); i++)
for (std::map<Source *, ALuint>::iterator i = playing.begin(); i != playing.end(); i++)
{
i->first->stopAtomic();
i->first->release();
@@ -173,7 +173,7 @@ namespace openal
void Pool::pause()
{
thread::Lock lock(mutex);
for(std::map<Source *, ALuint>::iterator i = playing.begin(); i != playing.end(); i++)
for (std::map<Source *, ALuint>::iterator i = playing.begin(); i != playing.end(); i++)
i->first->pauseAtomic();
}
@@ -181,14 +181,14 @@ namespace openal
{
thread::Lock lock(mutex);
ALuint out;
if(findSource(source, out))
if (findSource(source, out))
source->pauseAtomic();
}
void Pool::resume()
{
thread::Lock lock(mutex);
for(std::map<Source *, ALuint>::iterator i = playing.begin(); i != playing.end(); i++)
for (std::map<Source *, ALuint>::iterator i = playing.begin(); i != playing.end(); i++)
i->first->resumeAtomic();
}
@@ -196,14 +196,14 @@ namespace openal
{
thread::Lock lock(mutex);
ALuint out;
if(findSource(source, out))
if (findSource(source, out))
source->resumeAtomic();
}
void Pool::rewind()
{
thread::Lock lock(mutex);
for(std::map<Source *, ALuint>::iterator i = playing.begin(); i != playing.end(); i++)
for (std::map<Source *, ALuint>::iterator i = playing.begin(); i != playing.end(); i++)
i->first->rewindAtomic();
}
@@ -224,7 +224,7 @@ namespace openal
{
ALuint s = findi(source);
if(s != 0)
if (s != 0)
{
available.push(s);
playing.erase(source);
@@ -247,7 +247,7 @@ namespace openal
{
std::map<Source *, ALuint>::const_iterator i = playing.find((Source *)source);
if(i != playing.end())
if (i != playing.end())
return i->second;
return 0;
@@ -259,7 +259,7 @@ namespace openal
bool found = i != playing.end();
if(found)
if (found)
out = i->second;
return found;
@@ -269,7 +269,7 @@ namespace openal
{
std::map<Source *, ALuint>::iterator i = playing.find((Source *)source);
if(i != playing.end())
if (i != playing.end())
{
source->stopAtomic();
available.push(i->second);
+3 -3
View File
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 LOVE Development Team
*
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
+47 -40
View File
@@ -87,7 +87,7 @@ namespace openal
valid = pool->play(this, source);
if(valid)
if (valid)
reset(source);
}
@@ -117,7 +117,7 @@ namespace openal
bool Source::isStopped() const
{
if(valid)
if (valid)
{
ALenum state;
alGetSourcei(source, AL_SOURCE_STATE, &state);
@@ -129,7 +129,7 @@ namespace openal
bool Source::isPaused() const
{
if(valid)
if (valid)
{
ALenum state;
alGetSourcei(source, AL_SOURCE_STATE, &state);
@@ -161,7 +161,7 @@ namespace openal
alGetSourcei(source, AL_BUFFERS_PROCESSED, &processed);
while(processed--)
while (processed--)
{
ALuint buffer;
@@ -196,7 +196,7 @@ namespace openal
void Source::setPitch(float pitch)
{
if(valid)
if (valid)
alSourcef(source, AL_PITCH, pitch);
this->pitch = pitch;
@@ -204,7 +204,7 @@ namespace openal
float Source::getPitch() const
{
if(valid)
if (valid)
{
ALfloat f;
alGetSourcef(source, AL_PITCH, &f);
@@ -217,7 +217,7 @@ namespace openal
void Source::setVolume(float volume)
{
if(valid)
if (valid)
{
alSourcef(source, AL_GAIN, volume);
}
@@ -227,7 +227,7 @@ namespace openal
float Source::getVolume() const
{
if(valid)
if (valid)
{
ALfloat f;
alGetSourcef(source, AL_GAIN, &f);
@@ -237,14 +237,15 @@ namespace openal
// In case the Source isn't playing.
return volume;
}
void Source::seekAtomic(float offset, void * unit)
{
if (valid)
{
switch (*((Source::Unit*) unit)) {
case Source::UNIT_SAMPLES:
if (type == TYPE_STREAM) {
if (type == TYPE_STREAM)
{
offsetSamples = offset;
ALint buffer;
alGetSourcei(source, AL_BUFFER, &buffer);
@@ -253,13 +254,16 @@ namespace openal
offset /= freq;
offsetSeconds = offset;
decoder->seek(offset);
} else {
}
else
{
alSourcef(source, AL_SAMPLE_OFFSET, offset);
}
break;
case Source::UNIT_SECONDS:
case Source::UNIT_SECONDS:
default:
if (type == TYPE_STREAM) {
if (type == TYPE_STREAM)
{
offsetSeconds = offset;
decoder->seek(offset);
ALint buffer;
@@ -267,7 +271,9 @@ namespace openal
int freq;
alGetBufferi(buffer, AL_FREQUENCY, &freq);
offsetSamples = offset*freq;
} else {
}
else
{
alSourcef(source, AL_SEC_OFFSET, offset);
}
break;
@@ -290,7 +296,7 @@ namespace openal
{
return pool->seek(this, offset, &unit);
}
float Source::tellAtomic(void * unit) const
{
if (valid)
@@ -324,7 +330,7 @@ namespace openal
void Source::setPosition(float * v)
{
if(valid)
if (valid)
alSourcefv(source, AL_POSITION, v);
setFloatv(position, v);
@@ -332,7 +338,7 @@ namespace openal
void Source::getPosition(float * v) const
{
if(valid)
if (valid)
alGetSourcefv(source, AL_POSITION, v);
else
setFloatv(v, position);
@@ -340,7 +346,7 @@ namespace openal
void Source::setVelocity(float * v)
{
if(valid)
if (valid)
alSourcefv(source, AL_VELOCITY, v);
setFloatv(velocity, v);
@@ -348,7 +354,7 @@ namespace openal
void Source::getVelocity(float * v) const
{
if(valid)
if (valid)
alGetSourcefv(source, AL_VELOCITY, v);
else
setFloatv(v, velocity);
@@ -356,7 +362,7 @@ namespace openal
void Source::setDirection(float * v)
{
if(valid)
if (valid)
alSourcefv(source, AL_DIRECTION, v);
else
setFloatv(direction, v);
@@ -364,7 +370,7 @@ namespace openal
void Source::getDirection(float * v) const
{
if(valid)
if (valid)
alGetSourcefv(source, AL_DIRECTION, v);
else
setFloatv(v, direction);
@@ -372,7 +378,7 @@ namespace openal
void Source::setLooping(bool looping)
{
if(valid && type == TYPE_STATIC)
if (valid && type == TYPE_STATIC)
alSourcei(source, AL_LOOPING, looping ? AL_TRUE : AL_FALSE);
this->looping = looping;
@@ -385,23 +391,23 @@ namespace openal
void Source::playAtomic()
{
if(type == TYPE_STATIC)
if (type == TYPE_STATIC)
{
alSourcei(source, AL_BUFFER, buffers[0]);
}
else if(type == TYPE_STREAM)
else if (type == TYPE_STREAM)
{
int usedBuffers = 0;
for(unsigned int i = 0; i < MAX_BUFFERS; i++)
for (unsigned int i = 0; i < MAX_BUFFERS; i++)
{
streamAtomic(buffers[i], decoder);
++usedBuffers;
if(decoder->isFinished())
if (decoder->isFinished())
break;
}
if(usedBuffers > 0)
if (usedBuffers > 0)
alSourceQueueBuffers(source, usedBuffers, buffers);
}
@@ -418,13 +424,13 @@ namespace openal
void Source::stopAtomic()
{
if(valid)
if (valid)
{
if(type == TYPE_STATIC)
if (type == TYPE_STATIC)
{
alSourceStop(source);
}
else if(type == TYPE_STREAM)
else if (type == TYPE_STREAM)
{
alSourceStop(source);
int queued = 0;
@@ -444,7 +450,7 @@ namespace openal
void Source::pauseAtomic()
{
if(valid)
if (valid)
{
alSourcePause(source);
paused = true;
@@ -453,7 +459,7 @@ namespace openal
void Source::resumeAtomic()
{
if(valid && paused)
if (valid && paused)
{
alSourcePlay(source);
paused = false;
@@ -462,13 +468,13 @@ namespace openal
void Source::rewindAtomic()
{
if(valid && type == TYPE_STATIC)
if (valid && type == TYPE_STATIC)
{
alSourceRewind(source);
if (!paused)
alSourcePlay(source);
}
else if(valid && type == TYPE_STREAM)
else if (valid && type == TYPE_STREAM)
{
bool waspaused = paused;
decoder->rewind();
@@ -508,13 +514,13 @@ namespace openal
ALenum Source::getFormat(int channels, int bits) const
{
if(channels == 1 && bits == 8)
if (channels == 1 && bits == 8)
return AL_FORMAT_MONO8;
else if(channels == 1 && bits == 16)
else if (channels == 1 && bits == 16)
return AL_FORMAT_MONO16;
else if(channels == 2 && bits == 8)
else if (channels == 2 && bits == 8)
return AL_FORMAT_STEREO8;
else if(channels == 2 && bits == 16)
else if (channels == 2 && bits == 16)
return AL_FORMAT_STEREO16;
else
return 0;
@@ -527,10 +533,11 @@ namespace openal
int fmt = getFormat(d->getChannels(), d->getBits());
if(fmt != 0)
if (fmt != 0)
alBufferData(buffer, fmt, d->getBuffer(), decoded, d->getSampleRate());
if(decoder->isFinished() && isLooping()) {
if (decoder->isFinished() && isLooping())
{
int queued, processed;
alGetSourcei(source, AL_BUFFERS_QUEUED, &queued);
alGetSourcei(source, AL_BUFFERS_PROCESSED, &processed);
+1 -1
View File
@@ -63,7 +63,7 @@ namespace openal
float direction[3];
bool looping;
bool paused;
float offsetSamples;
float offsetSeconds;