mirror of
https://github.com/love2d/love.git
synced 2026-08-17 19:23:38 +02:00
Automated formatting fix
This commit is contained in:
@@ -1,69 +1,69 @@
|
||||
/**
|
||||
* 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
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Decoder.h"
|
||||
|
||||
#include <common/Exception.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace sound
|
||||
{
|
||||
namespace lullaby
|
||||
{
|
||||
Decoder::Decoder(Data * data, const std::string & ext, int bufferSize)
|
||||
:data(data), ext(ext), bufferSize(bufferSize), sampleRate(DEFAULT_SAMPLE_RATE), buffer(0), eof(false)
|
||||
{
|
||||
data->retain();
|
||||
buffer = new char[bufferSize];
|
||||
}
|
||||
|
||||
Decoder::~Decoder()
|
||||
{
|
||||
if(buffer != 0)
|
||||
delete [] (char*) buffer;
|
||||
if(data != 0)
|
||||
data->release();
|
||||
}
|
||||
|
||||
void * Decoder::getBuffer() const
|
||||
{
|
||||
return buffer;
|
||||
}
|
||||
|
||||
int Decoder::getSize() const
|
||||
{
|
||||
return bufferSize;
|
||||
}
|
||||
|
||||
int Decoder::getSampleRate() const
|
||||
{
|
||||
return sampleRate;
|
||||
}
|
||||
|
||||
bool Decoder::isFinished()
|
||||
{
|
||||
return eof;
|
||||
}
|
||||
|
||||
|
||||
} // lullaby
|
||||
} // sound
|
||||
} // love
|
||||
/**
|
||||
* 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
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Decoder.h"
|
||||
|
||||
#include <common/Exception.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace sound
|
||||
{
|
||||
namespace lullaby
|
||||
{
|
||||
Decoder::Decoder(Data * data, const std::string & ext, int bufferSize)
|
||||
:data(data), ext(ext), bufferSize(bufferSize), sampleRate(DEFAULT_SAMPLE_RATE), buffer(0), eof(false)
|
||||
{
|
||||
data->retain();
|
||||
buffer = new char[bufferSize];
|
||||
}
|
||||
|
||||
Decoder::~Decoder()
|
||||
{
|
||||
if (buffer != 0)
|
||||
delete [] (char*) buffer;
|
||||
if (data != 0)
|
||||
data->release();
|
||||
}
|
||||
|
||||
void * Decoder::getBuffer() const
|
||||
{
|
||||
return buffer;
|
||||
}
|
||||
|
||||
int Decoder::getSize() const
|
||||
{
|
||||
return bufferSize;
|
||||
}
|
||||
|
||||
int Decoder::getSampleRate() const
|
||||
{
|
||||
return sampleRate;
|
||||
}
|
||||
|
||||
bool Decoder::isFinished()
|
||||
{
|
||||
return eof;
|
||||
}
|
||||
|
||||
|
||||
} // lullaby
|
||||
} // sound
|
||||
} // love
|
||||
|
||||
@@ -1,79 +1,79 @@
|
||||
/**
|
||||
* 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
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_SOUND_LULLABY_DECODER_H
|
||||
#define LOVE_SOUND_LULLABY_DECODER_H
|
||||
|
||||
// LOVE
|
||||
#include <sound/Decoder.h>
|
||||
#include <filesystem/File.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace sound
|
||||
{
|
||||
namespace lullaby
|
||||
{
|
||||
class Decoder : public love::sound::Decoder
|
||||
{
|
||||
protected:
|
||||
|
||||
// The encoded data. This should be replaced with buffered file
|
||||
// reads in the future.
|
||||
Data * data;
|
||||
|
||||
// File extension.
|
||||
std::string ext;
|
||||
|
||||
// When the decoder decodes data incrementally, it writes
|
||||
// this many bytes at a time (at most).
|
||||
int bufferSize;
|
||||
|
||||
// The desired frequency of the samples. 44100, 22050, or 11025.
|
||||
int sampleRate;
|
||||
|
||||
// Holds internal memory.
|
||||
void * buffer;
|
||||
|
||||
// Set this to true when eof has been reached.
|
||||
bool eof;
|
||||
|
||||
public:
|
||||
|
||||
Decoder(Data * data, const std::string & ext, int bufferSize);
|
||||
|
||||
virtual ~Decoder();
|
||||
|
||||
// Implement some of love::sound::Decoder, but allow subclasses
|
||||
// to override them.
|
||||
virtual void * getBuffer() const;
|
||||
virtual int getSize() const;
|
||||
virtual int getSampleRate() const;
|
||||
virtual bool isFinished();
|
||||
|
||||
}; // Decoder
|
||||
|
||||
} // lullaby
|
||||
} // sound
|
||||
} // love
|
||||
|
||||
#endif // LOVE_SOUND_LULLABY_DECODER_H
|
||||
/**
|
||||
* 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
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_SOUND_LULLABY_DECODER_H
|
||||
#define LOVE_SOUND_LULLABY_DECODER_H
|
||||
|
||||
// LOVE
|
||||
#include <sound/Decoder.h>
|
||||
#include <filesystem/File.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace sound
|
||||
{
|
||||
namespace lullaby
|
||||
{
|
||||
class Decoder : public love::sound::Decoder
|
||||
{
|
||||
protected:
|
||||
|
||||
// The encoded data. This should be replaced with buffered file
|
||||
// reads in the future.
|
||||
Data * data;
|
||||
|
||||
// File extension.
|
||||
std::string ext;
|
||||
|
||||
// When the decoder decodes data incrementally, it writes
|
||||
// this many bytes at a time (at most).
|
||||
int bufferSize;
|
||||
|
||||
// The desired frequency of the samples. 44100, 22050, or 11025.
|
||||
int sampleRate;
|
||||
|
||||
// Holds internal memory.
|
||||
void * buffer;
|
||||
|
||||
// Set this to true when eof has been reached.
|
||||
bool eof;
|
||||
|
||||
public:
|
||||
|
||||
Decoder(Data * data, const std::string & ext, int bufferSize);
|
||||
|
||||
virtual ~Decoder();
|
||||
|
||||
// Implement some of love::sound::Decoder, but allow subclasses
|
||||
// to override them.
|
||||
virtual void * getBuffer() const;
|
||||
virtual int getSize() const;
|
||||
virtual int getSampleRate() const;
|
||||
virtual bool isFinished();
|
||||
|
||||
}; // Decoder
|
||||
|
||||
} // lullaby
|
||||
} // sound
|
||||
} // love
|
||||
|
||||
#endif // LOVE_SOUND_LULLABY_DECODER_H
|
||||
|
||||
@@ -55,9 +55,9 @@ namespace lullaby
|
||||
"flac", ""
|
||||
};
|
||||
|
||||
for(int i = 0; !(supported[i].empty()); i++)
|
||||
for (int i = 0; !(supported[i].empty()); i++)
|
||||
{
|
||||
if(supported[i].compare(ext) == 0)
|
||||
if (supported[i].compare(ext) == 0)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -40,11 +40,11 @@ namespace lullaby
|
||||
{
|
||||
private:
|
||||
int pos;
|
||||
|
||||
|
||||
public:
|
||||
FLACDecoder(Data * data, const std::string & ext, int bufferSize);
|
||||
~FLACDecoder();
|
||||
|
||||
|
||||
static bool accepts(const std::string &ext);
|
||||
love::sound::Decoder *clone();
|
||||
int decode();
|
||||
@@ -54,7 +54,7 @@ namespace lullaby
|
||||
int getChannels() const;
|
||||
int getBits() const;
|
||||
int getSampleRate() const;
|
||||
|
||||
|
||||
//needed for FLAC
|
||||
FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], size_t *bytes);
|
||||
FLAC__StreamDecoderSeekStatus seek_callback(FLAC__uint64 offset);
|
||||
|
||||
@@ -1,140 +1,140 @@
|
||||
/**
|
||||
* 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
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
#include <common/config.h>
|
||||
#include "ModPlugDecoder.h"
|
||||
|
||||
#include <common/Exception.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace sound
|
||||
{
|
||||
namespace lullaby
|
||||
{
|
||||
ModPlugDecoder::ModPlugDecoder(Data * data, const std::string & ext, int bufferSize)
|
||||
: Decoder(data, ext, bufferSize), plug(0)
|
||||
{
|
||||
|
||||
// Set some ModPlug settings.
|
||||
settings.mFlags = MODPLUG_ENABLE_OVERSAMPLING | MODPLUG_ENABLE_NOISE_REDUCTION;
|
||||
settings.mChannels = 2;
|
||||
settings.mBits = 16;
|
||||
settings.mFrequency = sampleRate;
|
||||
settings.mResamplingMode = MODPLUG_RESAMPLE_LINEAR;
|
||||
|
||||
// fill with modplug defaults (modplug _memsets_, so we could get
|
||||
// garbage settings when the struct is only partially initialized)
|
||||
// This does not exist yet on Windows.
|
||||
settings.mStereoSeparation = 128;
|
||||
settings.mMaxMixChannels = 32;
|
||||
settings.mReverbDepth = 0;
|
||||
settings.mReverbDelay = 0;
|
||||
settings.mBassAmount = 0;
|
||||
settings.mBassRange = 0;
|
||||
settings.mSurroundDepth = 0;
|
||||
settings.mSurroundDelay = 0;
|
||||
settings.mLoopCount = 0;
|
||||
|
||||
ModPlug_SetSettings(&settings);
|
||||
|
||||
// Load the module.
|
||||
plug = ModPlug_Load(data->getData(), data->getSize());
|
||||
|
||||
if(plug == 0)
|
||||
throw love::Exception("Could not load file with ModPlug.");
|
||||
|
||||
// set master volume for delicate ears
|
||||
ModPlug_SetMasterVolume(plug, 128);
|
||||
}
|
||||
|
||||
ModPlugDecoder::~ModPlugDecoder()
|
||||
{
|
||||
if(plug != 0)
|
||||
ModPlug_Unload(plug);
|
||||
}
|
||||
|
||||
bool ModPlugDecoder::accepts(const std::string & ext)
|
||||
{
|
||||
static const std::string supported[] = {
|
||||
"699", "abc", "amf", "ams", "dbm", "dmf",
|
||||
"dsm", "far", "it", "j2b", "mdl", "med",
|
||||
"mid", "mod", "mt2", "mtm", "okt", "pat",
|
||||
"psm", "s3m", "stm", "ult", "umx", "wav",
|
||||
"xm", ""
|
||||
};
|
||||
|
||||
for(int i = 0; !(supported[i].empty()); i++)
|
||||
{
|
||||
if(supported[i].compare(ext) == 0)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
love::sound::Decoder * ModPlugDecoder::clone()
|
||||
{
|
||||
return new ModPlugDecoder(data, ext, bufferSize);
|
||||
}
|
||||
|
||||
int ModPlugDecoder::decode()
|
||||
{
|
||||
int r = ModPlug_Read(plug, buffer, bufferSize);
|
||||
|
||||
if(r == 0)
|
||||
eof = true;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
bool ModPlugDecoder::seek(float s)
|
||||
{
|
||||
ModPlug_Seek(plug, (int)(s*1000.0f));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ModPlugDecoder::rewind()
|
||||
{
|
||||
// Let's reload.
|
||||
ModPlug_Unload(plug);
|
||||
plug = ModPlug_Load(data->getData(), data->getSize());
|
||||
ModPlug_SetMasterVolume(plug, 128);
|
||||
eof = false;
|
||||
return (plug != 0);
|
||||
}
|
||||
|
||||
bool ModPlugDecoder::isSeekable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
int ModPlugDecoder::getChannels() const
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
int ModPlugDecoder::getBits() const
|
||||
{
|
||||
return 16;
|
||||
}
|
||||
|
||||
} // lullaby
|
||||
} // sound
|
||||
} // love
|
||||
/**
|
||||
* 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
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
#include <common/config.h>
|
||||
#include "ModPlugDecoder.h"
|
||||
|
||||
#include <common/Exception.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace sound
|
||||
{
|
||||
namespace lullaby
|
||||
{
|
||||
ModPlugDecoder::ModPlugDecoder(Data * data, const std::string & ext, int bufferSize)
|
||||
: Decoder(data, ext, bufferSize), plug(0)
|
||||
{
|
||||
|
||||
// Set some ModPlug settings.
|
||||
settings.mFlags = MODPLUG_ENABLE_OVERSAMPLING | MODPLUG_ENABLE_NOISE_REDUCTION;
|
||||
settings.mChannels = 2;
|
||||
settings.mBits = 16;
|
||||
settings.mFrequency = sampleRate;
|
||||
settings.mResamplingMode = MODPLUG_RESAMPLE_LINEAR;
|
||||
|
||||
// fill with modplug defaults (modplug _memsets_, so we could get
|
||||
// garbage settings when the struct is only partially initialized)
|
||||
// This does not exist yet on Windows.
|
||||
settings.mStereoSeparation = 128;
|
||||
settings.mMaxMixChannels = 32;
|
||||
settings.mReverbDepth = 0;
|
||||
settings.mReverbDelay = 0;
|
||||
settings.mBassAmount = 0;
|
||||
settings.mBassRange = 0;
|
||||
settings.mSurroundDepth = 0;
|
||||
settings.mSurroundDelay = 0;
|
||||
settings.mLoopCount = 0;
|
||||
|
||||
ModPlug_SetSettings(&settings);
|
||||
|
||||
// Load the module.
|
||||
plug = ModPlug_Load(data->getData(), data->getSize());
|
||||
|
||||
if (plug == 0)
|
||||
throw love::Exception("Could not load file with ModPlug.");
|
||||
|
||||
// set master volume for delicate ears
|
||||
ModPlug_SetMasterVolume(plug, 128);
|
||||
}
|
||||
|
||||
ModPlugDecoder::~ModPlugDecoder()
|
||||
{
|
||||
if (plug != 0)
|
||||
ModPlug_Unload(plug);
|
||||
}
|
||||
|
||||
bool ModPlugDecoder::accepts(const std::string & ext)
|
||||
{
|
||||
static const std::string supported[] = {
|
||||
"699", "abc", "amf", "ams", "dbm", "dmf",
|
||||
"dsm", "far", "it", "j2b", "mdl", "med",
|
||||
"mid", "mod", "mt2", "mtm", "okt", "pat",
|
||||
"psm", "s3m", "stm", "ult", "umx", "wav",
|
||||
"xm", ""
|
||||
};
|
||||
|
||||
for (int i = 0; !(supported[i].empty()); i++)
|
||||
{
|
||||
if (supported[i].compare(ext) == 0)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
love::sound::Decoder * ModPlugDecoder::clone()
|
||||
{
|
||||
return new ModPlugDecoder(data, ext, bufferSize);
|
||||
}
|
||||
|
||||
int ModPlugDecoder::decode()
|
||||
{
|
||||
int r = ModPlug_Read(plug, buffer, bufferSize);
|
||||
|
||||
if (r == 0)
|
||||
eof = true;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
bool ModPlugDecoder::seek(float s)
|
||||
{
|
||||
ModPlug_Seek(plug, (int)(s*1000.0f));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ModPlugDecoder::rewind()
|
||||
{
|
||||
// Let's reload.
|
||||
ModPlug_Unload(plug);
|
||||
plug = ModPlug_Load(data->getData(), data->getSize());
|
||||
ModPlug_SetMasterVolume(plug, 128);
|
||||
eof = false;
|
||||
return (plug != 0);
|
||||
}
|
||||
|
||||
bool ModPlugDecoder::isSeekable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
int ModPlugDecoder::getChannels() const
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
int ModPlugDecoder::getBits() const
|
||||
{
|
||||
return 16;
|
||||
}
|
||||
|
||||
} // lullaby
|
||||
} // sound
|
||||
} // love
|
||||
|
||||
@@ -1,65 +1,65 @@
|
||||
/**
|
||||
* 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
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_SOUND_LULLABY_MODPLUG_DECODER_H
|
||||
#define LOVE_SOUND_LULLABY_MODPLUG_DECODER_H
|
||||
|
||||
// LOVE
|
||||
#include <common/Data.h>
|
||||
#include "Decoder.h"
|
||||
|
||||
// SDL_sound
|
||||
#include <libmodplug/modplug.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace sound
|
||||
{
|
||||
namespace lullaby
|
||||
{
|
||||
class ModPlugDecoder : public Decoder
|
||||
{
|
||||
private:
|
||||
|
||||
ModPlugFile * plug;
|
||||
ModPlug_Settings settings;
|
||||
|
||||
public:
|
||||
|
||||
ModPlugDecoder(Data * data, const std::string & ext, int bufferSize);
|
||||
virtual ~ModPlugDecoder();
|
||||
|
||||
static bool accepts(const std::string & ext);
|
||||
|
||||
love::sound::Decoder * clone();
|
||||
int decode();
|
||||
bool seek(float s);
|
||||
bool rewind();
|
||||
bool isSeekable();
|
||||
int getChannels() const;
|
||||
int getBits() const;
|
||||
|
||||
}; // Decoder
|
||||
|
||||
} // lullaby
|
||||
} // sound
|
||||
} // love
|
||||
|
||||
#endif // LOVE_SOUND_LULLABY_MODPLUG_DECODER_H
|
||||
/**
|
||||
* 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
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_SOUND_LULLABY_MODPLUG_DECODER_H
|
||||
#define LOVE_SOUND_LULLABY_MODPLUG_DECODER_H
|
||||
|
||||
// LOVE
|
||||
#include <common/Data.h>
|
||||
#include "Decoder.h"
|
||||
|
||||
// SDL_sound
|
||||
#include <libmodplug/modplug.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace sound
|
||||
{
|
||||
namespace lullaby
|
||||
{
|
||||
class ModPlugDecoder : public Decoder
|
||||
{
|
||||
private:
|
||||
|
||||
ModPlugFile * plug;
|
||||
ModPlug_Settings settings;
|
||||
|
||||
public:
|
||||
|
||||
ModPlugDecoder(Data * data, const std::string & ext, int bufferSize);
|
||||
virtual ~ModPlugDecoder();
|
||||
|
||||
static bool accepts(const std::string & ext);
|
||||
|
||||
love::sound::Decoder * clone();
|
||||
int decode();
|
||||
bool seek(float s);
|
||||
bool rewind();
|
||||
bool isSeekable();
|
||||
int getChannels() const;
|
||||
int getBits() const;
|
||||
|
||||
}; // Decoder
|
||||
|
||||
} // lullaby
|
||||
} // sound
|
||||
} // love
|
||||
|
||||
#endif // LOVE_SOUND_LULLABY_MODPLUG_DECODER_H
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace lullaby
|
||||
|
||||
int ret;
|
||||
|
||||
if(!inited)
|
||||
if (!inited)
|
||||
{
|
||||
ret = mpg123_init();
|
||||
if (ret != MPG123_OK)
|
||||
@@ -76,9 +76,9 @@ namespace lullaby
|
||||
"mp3", ""
|
||||
};
|
||||
|
||||
for(int i = 0; !(supported[i].empty()); i++)
|
||||
for (int i = 0; !(supported[i].empty()); i++)
|
||||
{
|
||||
if(supported[i].compare(ext) == 0)
|
||||
if (supported[i].compare(ext) == 0)
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace lullaby
|
||||
|
||||
void Mpg123Decoder::quit()
|
||||
{
|
||||
if(inited)
|
||||
if (inited)
|
||||
mpg123_exit();
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ namespace lullaby
|
||||
int size = 0;
|
||||
bool done = false;
|
||||
|
||||
while(size < bufferSize && !done && !eof)
|
||||
while (size < bufferSize && !done && !eof)
|
||||
{
|
||||
size_t numbytes = 0;
|
||||
|
||||
@@ -137,7 +137,7 @@ namespace lullaby
|
||||
case MPG123_OK:
|
||||
continue;
|
||||
case MPG123_DONE:
|
||||
if(numbytes == 0)
|
||||
if (numbytes == 0)
|
||||
eof = true;
|
||||
break;
|
||||
default:
|
||||
@@ -166,10 +166,10 @@ namespace lullaby
|
||||
{
|
||||
off_t offset = static_cast<off_t>(s * static_cast<float>(sampleRate));
|
||||
|
||||
if(offset < 0)
|
||||
if (offset < 0)
|
||||
return false;
|
||||
|
||||
if(mpg123_feedseek(handle, offset, SEEK_SET, &offset) >= 0)
|
||||
if (mpg123_feedseek(handle, offset, SEEK_SET, &offset) >= 0)
|
||||
{
|
||||
data_offset = offset;
|
||||
eof = false;
|
||||
@@ -184,7 +184,7 @@ namespace lullaby
|
||||
eof = false;
|
||||
off_t offset;
|
||||
|
||||
if(mpg123_feedseek(handle, 0, SEEK_SET, &offset) >= 0)
|
||||
if (mpg123_feedseek(handle, 0, SEEK_SET, &offset) >= 0)
|
||||
{
|
||||
data_offset = offset;
|
||||
return true;
|
||||
@@ -212,14 +212,14 @@ namespace lullaby
|
||||
{
|
||||
int remaining = data_size - data_offset;
|
||||
|
||||
if(remaining <= 0)
|
||||
if (remaining <= 0)
|
||||
return MPG123_DONE;
|
||||
|
||||
int feed_bytes = remaining < bytes ? remaining : bytes;
|
||||
|
||||
int r = mpg123_feed(handle, (unsigned char*)data->getData() + data_offset, feed_bytes);
|
||||
|
||||
if(r == MPG123_OK || r == MPG123_DONE)
|
||||
if (r == MPG123_OK || r == MPG123_DONE)
|
||||
data_offset += feed_bytes;
|
||||
|
||||
return r;
|
||||
|
||||
@@ -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
|
||||
@@ -49,20 +49,20 @@ namespace lullaby
|
||||
{
|
||||
Data * data = file->read();
|
||||
std::string ext = file->getExtension();
|
||||
|
||||
|
||||
sound::Decoder * decoder = 0;
|
||||
|
||||
// Find a suitable decoder here, and return it.
|
||||
if(ModPlugDecoder::accepts(ext))
|
||||
if (ModPlugDecoder::accepts(ext))
|
||||
decoder = new ModPlugDecoder(data, ext, bufferSize);
|
||||
else if(Mpg123Decoder::accepts(ext))
|
||||
else if (Mpg123Decoder::accepts(ext))
|
||||
decoder = new Mpg123Decoder(data, ext, bufferSize);
|
||||
else if(VorbisDecoder::accepts(ext))
|
||||
else if (VorbisDecoder::accepts(ext))
|
||||
decoder = new VorbisDecoder(data, ext, bufferSize);
|
||||
/*else if (FLACDecoder::accepts(ext))
|
||||
decoder = new FLACDecoder(data, ext, bufferSize);*/
|
||||
|
||||
// else if(OtherDecoder::accept(ext))
|
||||
// else if (OtherDecoder::accept(ext))
|
||||
|
||||
data->release();
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -36,9 +36,9 @@ namespace lullaby
|
||||
/**
|
||||
* The love.sound.lullaby module is the custom sound decoder module for LOVE. Instead
|
||||
* of using an intermediate library like SDL_sound, it interfaces with relevant libraries
|
||||
* directly (libmpg123, libmodplug, libFLAC, etc).
|
||||
*
|
||||
* It was Mike that came up with the name Lullaby, which we both instantly recognized as awesome.
|
||||
* directly (libmpg123, libmodplug, libFLAC, etc).
|
||||
*
|
||||
* It was Mike that came up with the name Lullaby, which we both instantly recognized as awesome.
|
||||
**/
|
||||
class Sound : public love::sound::Sound
|
||||
{
|
||||
@@ -56,7 +56,7 @@ namespace lullaby
|
||||
|
||||
/// @copydoc love::Module::getName
|
||||
const char * getName() const;
|
||||
|
||||
|
||||
/// @copydoc love::sound::Sound::newDecoder
|
||||
sound::Decoder * newDecoder(love::filesystem::File * file, int bufferSize);
|
||||
|
||||
|
||||
@@ -147,7 +147,7 @@ namespace lullaby
|
||||
oggFile.dataRead = 0;
|
||||
|
||||
// Open Vorbis handle
|
||||
if(ov_open_callbacks(&oggFile, &handle, NULL, 0, vorbisCallbacks) < 0)
|
||||
if (ov_open_callbacks(&oggFile, &handle, NULL, 0, vorbisCallbacks) < 0)
|
||||
throw love::Exception("Could not read Ogg bitstream");
|
||||
|
||||
// Get info and comments
|
||||
@@ -166,9 +166,9 @@ namespace lullaby
|
||||
"ogg", "oga", ""
|
||||
};
|
||||
|
||||
for(int i = 0; !(supported[i].empty()); i++)
|
||||
for (int i = 0; !(supported[i].empty()); i++)
|
||||
{
|
||||
if(supported[i].compare(ext) == 0)
|
||||
if (supported[i].compare(ext) == 0)
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -184,20 +184,20 @@ namespace lullaby
|
||||
{
|
||||
int size = 0;
|
||||
|
||||
while(size < bufferSize)
|
||||
while (size < bufferSize)
|
||||
{
|
||||
int result = ov_read(&handle, (char*) buffer + size, bufferSize - size, endian, (getBits() == 16 ? 2 : 1), 1, 0);
|
||||
|
||||
if(result == OV_HOLE)
|
||||
if (result == OV_HOLE)
|
||||
continue;
|
||||
else if(result <= OV_EREAD)
|
||||
else if (result <= OV_EREAD)
|
||||
return -1;
|
||||
else if(result == 0)
|
||||
else if (result == 0)
|
||||
{
|
||||
eof = true;
|
||||
break;
|
||||
}
|
||||
else if(result > 0)
|
||||
else if (result > 0)
|
||||
size += result;
|
||||
}
|
||||
|
||||
@@ -208,7 +208,7 @@ namespace lullaby
|
||||
{
|
||||
int result = ov_time_seek(&handle, s);
|
||||
|
||||
if(result == 0)
|
||||
if (result == 0)
|
||||
{
|
||||
eof = false;
|
||||
return true;
|
||||
@@ -221,7 +221,7 @@ namespace lullaby
|
||||
{
|
||||
int result = ov_pcm_seek(&handle, 0);
|
||||
|
||||
if(result == 0)
|
||||
if (result == 0)
|
||||
{
|
||||
eof = false;
|
||||
return true;
|
||||
|
||||
@@ -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 lullaby
|
||||
|
||||
VorbisDecoder(Data * data, const std::string & ext, int bufferSize);
|
||||
virtual ~VorbisDecoder();
|
||||
|
||||
|
||||
static bool accepts(const std::string & ext);
|
||||
|
||||
love::sound::Decoder * clone();
|
||||
|
||||
Reference in New Issue
Block a user