CRLF to LF

This commit is contained in:
Bart van Strien
2012-07-04 14:40:24 +02:00
parent a970f1df97
commit 7793e7f02f
414 changed files with 94042 additions and 94042 deletions
+142 -142
View File
@@ -1,142 +1,142 @@
/**
* Copyright (c) 2006-2012 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_DECODER_H
#define LOVE_SOUND_DECODER_H
// LOVE
#include "common/Object.h"
namespace love
{
namespace sound
{
/**
* Decoder objects are responsible for decoding audio files. They maintain
* an interal buffer into which they write raw decoded audio data.
**/
class Decoder : public Object
{
public:
/**
* Indicates how many bytes of raw data should be generated at each
* call to Decode.
**/
static const int DEFAULT_BUFFER_SIZE = 2048;
/**
* Indicates the quality of the sound.
**/
static const int DEFAULT_SAMPLE_RATE = 44100;
/**
* Default is stereo.
**/
static const int DEFAULT_CHANNELS = 2;
/**
* 16 bit audio is the default.
**/
static const int DEFAULT_BITS = 16;
/**
* Creates a deep of itself. The sound stream can (and should) be
* rewound, and does not have to be at the same place.
* @return A new Decoder object.
**/
virtual Decoder *clone() = 0;
/**
* Destructor. Should free internal buffer.
**/
virtual ~Decoder() {};
/**
* Decodes the next chunk of the music stream, this will usually be
* bufferSize amount of bytes, unless EOF occurs. Zero or negative values
* indicate EOF or errors.
* @return The number of bytes actually decoded.
**/
virtual int decode() = 0;
/**
* Gets the size of the buffer (NOT the size of the entire stream).
* @return The size of the buffer.
**/
virtual int getSize() const = 0;
/**
* Gets a pointer to the actual data. The contents of this buffer will
* change with each call to decode, so the client must copy the data.
* @return A buffer to raw sound data.
**/
virtual void *getBuffer() const = 0;
/**
* Seeks to the specified position, if possible.
* @param s The position in the stream in seconds.
* @return True if success, false on fail/unsupported.
**/
virtual bool seek(float s) = 0;
/**
* Rewinds the stream to the start.
* @return True if success, false on fail/unsupported.
**/
virtual bool rewind() = 0;
/**
* Checks whether a stream is seekable.
* @return True if seekable, false otherwise.
**/
virtual bool isSeekable() = 0;
/**
* Checks whether a stream has more data to decode or not. Use
* rewind to start the stream again.
* @return False if there is more data, true on EOF.
**/
virtual bool isFinished() = 0;
/**
* Gets the number of channels in a stream. Supported values are 1 (mono) or 2 (stereo).
* @return Either 1 for mono, 2 for stereo, or 0 on errors.
**/
virtual int getChannels() const = 0;
/**
* Gets the number of bits per sample. Supported values are 8 or 16.
* @return Either 8, 16, or 0 if unsupported.
**/
virtual int getBits() const = 0;
/**
* Gets the sample rate for the Decoder, that is, samples per second.
* @return The sample rate, eg. 44100.
**/
virtual int getSampleRate() const = 0;
}; // Decoder
} // sound
} // love
#endif // LOVE_SOUND_DECODER_H
/**
* Copyright (c) 2006-2012 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_DECODER_H
#define LOVE_SOUND_DECODER_H
// LOVE
#include "common/Object.h"
namespace love
{
namespace sound
{
/**
* Decoder objects are responsible for decoding audio files. They maintain
* an interal buffer into which they write raw decoded audio data.
**/
class Decoder : public Object
{
public:
/**
* Indicates how many bytes of raw data should be generated at each
* call to Decode.
**/
static const int DEFAULT_BUFFER_SIZE = 2048;
/**
* Indicates the quality of the sound.
**/
static const int DEFAULT_SAMPLE_RATE = 44100;
/**
* Default is stereo.
**/
static const int DEFAULT_CHANNELS = 2;
/**
* 16 bit audio is the default.
**/
static const int DEFAULT_BITS = 16;
/**
* Creates a deep of itself. The sound stream can (and should) be
* rewound, and does not have to be at the same place.
* @return A new Decoder object.
**/
virtual Decoder *clone() = 0;
/**
* Destructor. Should free internal buffer.
**/
virtual ~Decoder() {};
/**
* Decodes the next chunk of the music stream, this will usually be
* bufferSize amount of bytes, unless EOF occurs. Zero or negative values
* indicate EOF or errors.
* @return The number of bytes actually decoded.
**/
virtual int decode() = 0;
/**
* Gets the size of the buffer (NOT the size of the entire stream).
* @return The size of the buffer.
**/
virtual int getSize() const = 0;
/**
* Gets a pointer to the actual data. The contents of this buffer will
* change with each call to decode, so the client must copy the data.
* @return A buffer to raw sound data.
**/
virtual void *getBuffer() const = 0;
/**
* Seeks to the specified position, if possible.
* @param s The position in the stream in seconds.
* @return True if success, false on fail/unsupported.
**/
virtual bool seek(float s) = 0;
/**
* Rewinds the stream to the start.
* @return True if success, false on fail/unsupported.
**/
virtual bool rewind() = 0;
/**
* Checks whether a stream is seekable.
* @return True if seekable, false otherwise.
**/
virtual bool isSeekable() = 0;
/**
* Checks whether a stream has more data to decode or not. Use
* rewind to start the stream again.
* @return False if there is more data, true on EOF.
**/
virtual bool isFinished() = 0;
/**
* Gets the number of channels in a stream. Supported values are 1 (mono) or 2 (stereo).
* @return Either 1 for mono, 2 for stereo, or 0 on errors.
**/
virtual int getChannels() const = 0;
/**
* Gets the number of bits per sample. Supported values are 8 or 16.
* @return Either 8, 16, or 0 if unsupported.
**/
virtual int getBits() const = 0;
/**
* Gets the sample rate for the Decoder, that is, samples per second.
* @return The sample rate, eg. 44100.
**/
virtual int getSampleRate() const = 0;
}; // Decoder
} // sound
} // love
#endif // LOVE_SOUND_DECODER_H
+44 -44
View File
@@ -1,44 +1,44 @@
/**
* Copyright (c) 2006-2012 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 "Sound.h"
namespace love
{
namespace sound
{
Sound::~Sound()
{
}
SoundData *Sound::newSoundData(Decoder *decoder)
{
return new SoundData(decoder);
}
SoundData *Sound::newSoundData(int samples, int sampleRate, int bits, int channels)
{
return new SoundData(samples, sampleRate, bits, channels);
}
} // sound
} // love
/**
* Copyright (c) 2006-2012 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 "Sound.h"
namespace love
{
namespace sound
{
Sound::~Sound()
{
}
SoundData *Sound::newSoundData(Decoder *decoder)
{
return new SoundData(decoder);
}
SoundData *Sound::newSoundData(int samples, int sampleRate, int bits, int channels)
{
return new SoundData(samples, sampleRate, bits, channels);
}
} // sound
} // love
+83 -83
View File
@@ -1,84 +1,84 @@
/**
* Copyright (c) 2006-2012 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_SOUND_H
#define LOVE_SOUND_SOUND_H
// LOVE
#include "common/Module.h"
#include "filesystem/File.h"
#include "SoundData.h"
#include "Decoder.h"
namespace love
{
namespace sound
{
/**
* The Sound module is responsible for decoding sound data. It is
* not responsible for playing it.
**/
class Sound : public Module
{
public:
/**
* Destructor.
**/
virtual ~Sound();
/**
* Creates new SoundData from a decoder. Fully expands the
* encoded sound data into raw sound data. Not recommended
* on large (long-duration) files.
* @param decoder The file to decode the data from.
* @return A SoundData object, or zero if the file type couldn't be handled.
**/
SoundData *newSoundData(Decoder *decoder);
/**
* Creates a new SoundData with the specified number of samples and format.
* @param duration In seconds.
* @param sampleRate Number of samples per second.
* @param bits Bits per sample (8 or 16).
* @param channels Either 1 for mono, or 2 for stereo.
* @return A new SoundData object, or zero in case of errors.
**/
SoundData *newSoundData(int samples, int sampleRate, int bits, int channels);
/**
* Attempts to find a decoder for the encoded sound data in the
* specified file.
* @param file The file with encoded sound data.
* @param bufferSize The size of each decoded chunk.
* @param sampleRate Samples per second, or quality of the audio. 44100 is a good value.
* @return A Decoder object on success, or zero if no decoder could be found.
**/
virtual Decoder *newDecoder(filesystem::File *file, int bufferSize) = 0;
}; // Sound
} // sound
} // love
/**
* Copyright (c) 2006-2012 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_SOUND_H
#define LOVE_SOUND_SOUND_H
// LOVE
#include "common/Module.h"
#include "filesystem/File.h"
#include "SoundData.h"
#include "Decoder.h"
namespace love
{
namespace sound
{
/**
* The Sound module is responsible for decoding sound data. It is
* not responsible for playing it.
**/
class Sound : public Module
{
public:
/**
* Destructor.
**/
virtual ~Sound();
/**
* Creates new SoundData from a decoder. Fully expands the
* encoded sound data into raw sound data. Not recommended
* on large (long-duration) files.
* @param decoder The file to decode the data from.
* @return A SoundData object, or zero if the file type couldn't be handled.
**/
SoundData *newSoundData(Decoder *decoder);
/**
* Creates a new SoundData with the specified number of samples and format.
* @param duration In seconds.
* @param sampleRate Number of samples per second.
* @param bits Bits per sample (8 or 16).
* @param channels Either 1 for mono, or 2 for stereo.
* @return A new SoundData object, or zero in case of errors.
**/
SoundData *newSoundData(int samples, int sampleRate, int bits, int channels);
/**
* Attempts to find a decoder for the encoded sound data in the
* specified file.
* @param file The file with encoded sound data.
* @param bufferSize The size of each decoded chunk.
* @param sampleRate Samples per second, or quality of the audio. 44100 is a good value.
* @return A Decoder object on success, or zero if no decoder could be found.
**/
virtual Decoder *newDecoder(filesystem::File *file, int bufferSize) = 0;
}; // Sound
} // sound
} // love
#endif // LOVE_SOUND_SOUND_H
+187 -187
View File
@@ -1,187 +1,187 @@
/**
* Copyright (c) 2006-2012 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 "SoundData.h"
// C
#include <climits>
#include <cstdlib>
#include <cstring>
// STL
#include <iostream>
#include <vector>
namespace love
{
namespace sound
{
SoundData::SoundData(Decoder *decoder)
: data(0)
, size(0)
, sampleRate(Decoder::DEFAULT_SAMPLE_RATE)
, bits(0)
, channels(0)
{
size_t bufferSize = 524288;
int decoded = decoder->decode();
while (decoded > 0)
{
// Expand or allocate buffer. Note that realloc may move
// memory to other locations.
if (!data || bufferSize < (size_t) size + decoded)
{
while (bufferSize < (size_t) size + decoded)
bufferSize <<= 1;
data = (char *)realloc(data, bufferSize);
}
if (!data)
throw love::Exception("Not enough memory.");
// Copy memory into new part of memory.
memcpy(data + size, decoder->getBuffer(), decoded);
// Keep this up to date.
size += decoded;
// Overflow check.
if (size < 0)
{
free(data);
throw love::Exception("Not enough memory.");
}
decoded = decoder->decode();
}
// Shrink buffer if necessary.
if (data && bufferSize > (size_t) size)
data = (char *) realloc(data, size);
channels = decoder->getChannels();
bits = decoder->getBits();
sampleRate = decoder->getSampleRate();
}
SoundData::SoundData(int samples, int sampleRate, int bits, int channels)
: data(0)
, size(samples*(bits/8)*channels)
, sampleRate(sampleRate)
, bits(bits)
, channels(channels)
{
double realsize = samples;
realsize *= (bits/8)*channels;
if (realsize > INT_MAX)
throw love::Exception("Data is too big!");
data = (char *)malloc(size);
if (!data)
throw love::Exception("Not enough memory.");
}
SoundData::SoundData(void *d, int samples, int sampleRate, int bits, int channels)
: data(0)
, size(samples*(bits/8)*channels)
, sampleRate(sampleRate)
, bits(bits)
, channels(channels)
{
double realsize = samples;
realsize *= (bits/8)*channels;
if (realsize > INT_MAX)
throw love::Exception("Data is too big!");
data = (char *)malloc(size);
if (!data)
throw love::Exception("Not enough memory.");
memcpy(data, d, size);
}
SoundData::~SoundData()
{
if (data != 0)
free(data);
}
void *SoundData::getData() const
{
return (void *)data;
}
int SoundData::getSize() const
{
return (int)size;
}
int SoundData::getChannels() const
{
return channels;
}
int SoundData::getBits() const
{
return bits;
}
int SoundData::getSampleRate() const
{
return sampleRate;
}
void SoundData::setSample(int i, float sample)
{
// Check range.
if (i < 0 || i >= size/(bits/8))
return;
if (bits == 16)
{
short *s = (short *)data;
s[i] = (short)(sample*(float)SHRT_MAX);
return;
}
else
{
data[i] = (char)(sample*(float)CHAR_MAX);
return;
}
}
float SoundData::getSample(int i) const
{
// Check range.
if (i < 0 || i >= size/(bits/8))
return 0;
if (bits == 16)
{
short *s = (short *)data;
return (float)s[i]/(float)SHRT_MAX;
}
else
{
return (float)data[i]/(float)CHAR_MAX;
}
}
} // sound
} // love
/**
* Copyright (c) 2006-2012 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 "SoundData.h"
// C
#include <climits>
#include <cstdlib>
#include <cstring>
// STL
#include <iostream>
#include <vector>
namespace love
{
namespace sound
{
SoundData::SoundData(Decoder *decoder)
: data(0)
, size(0)
, sampleRate(Decoder::DEFAULT_SAMPLE_RATE)
, bits(0)
, channels(0)
{
size_t bufferSize = 524288;
int decoded = decoder->decode();
while (decoded > 0)
{
// Expand or allocate buffer. Note that realloc may move
// memory to other locations.
if (!data || bufferSize < (size_t) size + decoded)
{
while (bufferSize < (size_t) size + decoded)
bufferSize <<= 1;
data = (char *)realloc(data, bufferSize);
}
if (!data)
throw love::Exception("Not enough memory.");
// Copy memory into new part of memory.
memcpy(data + size, decoder->getBuffer(), decoded);
// Keep this up to date.
size += decoded;
// Overflow check.
if (size < 0)
{
free(data);
throw love::Exception("Not enough memory.");
}
decoded = decoder->decode();
}
// Shrink buffer if necessary.
if (data && bufferSize > (size_t) size)
data = (char *) realloc(data, size);
channels = decoder->getChannels();
bits = decoder->getBits();
sampleRate = decoder->getSampleRate();
}
SoundData::SoundData(int samples, int sampleRate, int bits, int channels)
: data(0)
, size(samples*(bits/8)*channels)
, sampleRate(sampleRate)
, bits(bits)
, channels(channels)
{
double realsize = samples;
realsize *= (bits/8)*channels;
if (realsize > INT_MAX)
throw love::Exception("Data is too big!");
data = (char *)malloc(size);
if (!data)
throw love::Exception("Not enough memory.");
}
SoundData::SoundData(void *d, int samples, int sampleRate, int bits, int channels)
: data(0)
, size(samples*(bits/8)*channels)
, sampleRate(sampleRate)
, bits(bits)
, channels(channels)
{
double realsize = samples;
realsize *= (bits/8)*channels;
if (realsize > INT_MAX)
throw love::Exception("Data is too big!");
data = (char *)malloc(size);
if (!data)
throw love::Exception("Not enough memory.");
memcpy(data, d, size);
}
SoundData::~SoundData()
{
if (data != 0)
free(data);
}
void *SoundData::getData() const
{
return (void *)data;
}
int SoundData::getSize() const
{
return (int)size;
}
int SoundData::getChannels() const
{
return channels;
}
int SoundData::getBits() const
{
return bits;
}
int SoundData::getSampleRate() const
{
return sampleRate;
}
void SoundData::setSample(int i, float sample)
{
// Check range.
if (i < 0 || i >= size/(bits/8))
return;
if (bits == 16)
{
short *s = (short *)data;
s[i] = (short)(sample*(float)SHRT_MAX);
return;
}
else
{
data[i] = (char)(sample*(float)CHAR_MAX);
return;
}
}
float SoundData::getSample(int i) const
{
// Check range.
if (i < 0 || i >= size/(bits/8))
return 0;
if (bits == 16)
{
short *s = (short *)data;
return (float)s[i]/(float)SHRT_MAX;
}
else
{
return (float)data[i]/(float)CHAR_MAX;
}
}
} // sound
} // love
+68 -68
View File
@@ -1,68 +1,68 @@
/**
* Copyright (c) 2006-2012 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_SOUND_DATA_H
#define LOVE_SOUND_SOUND_DATA_H
// LOVE
#include "filesystem/File.h"
#include "Decoder.h"
namespace love
{
namespace sound
{
class SoundData : public love::Data
{
public:
SoundData(Decoder *decoder);
SoundData(int samples, int sampleRate, int bits, int channels);
SoundData(void *d, int samples, int sampleRate, int bits, int channels);
virtual ~SoundData();
// Implements Data.
void *getData() const;
int getSize() const;
virtual int getChannels() const;
virtual int getBits() const;
virtual int getSampleRate() const;
void setSample(int i, float sample);
float getSample(int i) const;
private:
char *data;
int size;
int sampleRate;
int bits;
int channels;
}; // SoundData
} // sound
} // love
#endif // LOVE_SOUND_SOUND_DATA_H
/**
* Copyright (c) 2006-2012 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_SOUND_DATA_H
#define LOVE_SOUND_SOUND_DATA_H
// LOVE
#include "filesystem/File.h"
#include "Decoder.h"
namespace love
{
namespace sound
{
class SoundData : public love::Data
{
public:
SoundData(Decoder *decoder);
SoundData(int samples, int sampleRate, int bits, int channels);
SoundData(void *d, int samples, int sampleRate, int bits, int channels);
virtual ~SoundData();
// Implements Data.
void *getData() const;
int getSize() const;
virtual int getChannels() const;
virtual int getBits() const;
virtual int getSampleRate() const;
void setSample(int i, float sample);
float getSample(int i) const;
private:
char *data;
int size;
int sampleRate;
int bits;
int channels;
}; // SoundData
} // sound
} // love
#endif // LOVE_SOUND_SOUND_DATA_H
+75 -75
View File
@@ -1,75 +1,75 @@
/**
* Copyright (c) 2006-2012 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-2012 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
+79 -79
View File
@@ -1,79 +1,79 @@
/**
* Copyright (c) 2006-2012 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
{
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();
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;
}; // Decoder
} // lullaby
} // sound
} // love
#endif // LOVE_SOUND_LULLABY_DECODER_H
/**
* Copyright (c) 2006-2012 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
{
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();
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;
}; // Decoder
} // lullaby
} // sound
} // love
#endif // LOVE_SOUND_LULLABY_DECODER_H
+185 -185
View File
@@ -1,186 +1,186 @@
/**
* Copyright (c) 2006-2012 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.
**/
#if 0
#include "FLACDecoder.h"
#include <set>
#include "common/Exception.h"
namespace love
{
namespace sound
{
namespace lullaby
{
FLACDecoder::FLACDecoder(Data *data, const std::string &ext, int nbufferSize)
: Decoder(data, ext, nbufferSize)
, pos(0)
{
init();
init_ogg();
process_until_end_of_metadata();
process_single();
seek(0);
bufferSize = 256 * getBits() * getChannels() * 2;
delete[](char *) buffer;
buffer = new char[bufferSize];
}
FLACDecoder::~FLACDecoder()
{
finish();
}
bool FLACDecoder::accepts(const std::string &ext)
{
static const std::string supported[] =
{
"flac", ""
};
for (int i = 0; !(supported[i].empty()); i++)
{
if (supported[i].compare(ext) == 0)
return true;
}
return false;
}
love::sound::Decoder *FLACDecoder::clone()
{
return new FLACDecoder(data, ext, bufferSize, sampleRate);
}
int FLACDecoder::decode()
{
process_single();
return bufferSize;
}
bool FLACDecoder::seek(float s)
{
return seek_absolute((int)(s*1000.0f));
}
bool FLACDecoder::rewind()
{
return seek_absolute(0);
}
bool FLACDecoder::isSeekable()
{
return true;
}
int FLACDecoder::getChannels() const
{
return get_channels();
}
int FLACDecoder::getBits() const
{
return get_bits_per_sample();
}
int FLACDecoder::getSampleRate() const
{
return get_sample_rate();
}
FLAC__StreamDecoderReadStatus FLACDecoder::read_callback(FLAC__byte buffer[], size_t *bytes)
{
int size = data->getSize();
char *d = (char *) data->getData() + pos;
if (pos >= size)
{
eof = true;
return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
}
if (pos+*bytes <= (unsigned int)size)
{
memcpy(buffer, d, *bytes);
pos = pos+*bytes;
}
else
{
memcpy(buffer, d, size-pos);
*bytes = size-pos;
pos = size;
}
return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
}
FLAC__StreamDecoderSeekStatus FLACDecoder::seek_callback(FLAC__uint64 offset)
{
pos = (int)offset;
return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
}
FLAC__StreamDecoderTellStatus FLACDecoder::tell_callback(FLAC__uint64 *offset)
{
*offset = pos;
return FLAC__STREAM_DECODER_TELL_STATUS_OK;
}
FLAC__StreamDecoderLengthStatus FLACDecoder::length_callback(FLAC__uint64 *length)
{
*length = data->getSize();
return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
}
bool FLACDecoder::eof_callback()
{
eof = (pos >= data->getSize());
return eof;
}
FLAC__StreamDecoderWriteStatus FLACDecoder::write_callback(const FLAC__Frame *frame, const FLAC__int32 *const fbuffer[])
{
int i, j;
for (i = 0, j = 0; i < bufferSize; i += 4, j++)
{
((char *)buffer)[i] = fbuffer[0][j];
((char *)buffer)[i+1] = fbuffer[0][j] >> 8;
((char *)buffer)[i+2] = fbuffer[1][j];
((char *)buffer)[i+3] = fbuffer[1][j] >> 8;
}
return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
}
void FLACDecoder::metadata_callback(const FLAC__StreamMetadata *metadata)
{
//we do nothing with metadata...
return;
}
void FLACDecoder::error_callback(FLAC__StreamDecoderErrorStatus status)
{
//wow.. error, let's throw one (please clean this part up sometime)
throw love::Exception("FLAC error: %s!", FLAC__StreamDecoderErrorStatusString[status]);
}
} // lullaby
} // sound
} // love
/**
* Copyright (c) 2006-2012 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.
**/
#if 0
#include "FLACDecoder.h"
#include <set>
#include "common/Exception.h"
namespace love
{
namespace sound
{
namespace lullaby
{
FLACDecoder::FLACDecoder(Data *data, const std::string &ext, int nbufferSize)
: Decoder(data, ext, nbufferSize)
, pos(0)
{
init();
init_ogg();
process_until_end_of_metadata();
process_single();
seek(0);
bufferSize = 256 * getBits() * getChannels() * 2;
delete[](char *) buffer;
buffer = new char[bufferSize];
}
FLACDecoder::~FLACDecoder()
{
finish();
}
bool FLACDecoder::accepts(const std::string &ext)
{
static const std::string supported[] =
{
"flac", ""
};
for (int i = 0; !(supported[i].empty()); i++)
{
if (supported[i].compare(ext) == 0)
return true;
}
return false;
}
love::sound::Decoder *FLACDecoder::clone()
{
return new FLACDecoder(data, ext, bufferSize, sampleRate);
}
int FLACDecoder::decode()
{
process_single();
return bufferSize;
}
bool FLACDecoder::seek(float s)
{
return seek_absolute((int)(s*1000.0f));
}
bool FLACDecoder::rewind()
{
return seek_absolute(0);
}
bool FLACDecoder::isSeekable()
{
return true;
}
int FLACDecoder::getChannels() const
{
return get_channels();
}
int FLACDecoder::getBits() const
{
return get_bits_per_sample();
}
int FLACDecoder::getSampleRate() const
{
return get_sample_rate();
}
FLAC__StreamDecoderReadStatus FLACDecoder::read_callback(FLAC__byte buffer[], size_t *bytes)
{
int size = data->getSize();
char *d = (char *) data->getData() + pos;
if (pos >= size)
{
eof = true;
return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
}
if (pos+*bytes <= (unsigned int)size)
{
memcpy(buffer, d, *bytes);
pos = pos+*bytes;
}
else
{
memcpy(buffer, d, size-pos);
*bytes = size-pos;
pos = size;
}
return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
}
FLAC__StreamDecoderSeekStatus FLACDecoder::seek_callback(FLAC__uint64 offset)
{
pos = (int)offset;
return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
}
FLAC__StreamDecoderTellStatus FLACDecoder::tell_callback(FLAC__uint64 *offset)
{
*offset = pos;
return FLAC__STREAM_DECODER_TELL_STATUS_OK;
}
FLAC__StreamDecoderLengthStatus FLACDecoder::length_callback(FLAC__uint64 *length)
{
*length = data->getSize();
return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
}
bool FLACDecoder::eof_callback()
{
eof = (pos >= data->getSize());
return eof;
}
FLAC__StreamDecoderWriteStatus FLACDecoder::write_callback(const FLAC__Frame *frame, const FLAC__int32 *const fbuffer[])
{
int i, j;
for (i = 0, j = 0; i < bufferSize; i += 4, j++)
{
((char *)buffer)[i] = fbuffer[0][j];
((char *)buffer)[i+1] = fbuffer[0][j] >> 8;
((char *)buffer)[i+2] = fbuffer[1][j];
((char *)buffer)[i+3] = fbuffer[1][j] >> 8;
}
return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
}
void FLACDecoder::metadata_callback(const FLAC__StreamMetadata *metadata)
{
//we do nothing with metadata...
return;
}
void FLACDecoder::error_callback(FLAC__StreamDecoderErrorStatus status)
{
//wow.. error, let's throw one (please clean this part up sometime)
throw love::Exception("FLAC error: %s!", FLAC__StreamDecoderErrorStatusString[status]);
}
} // lullaby
} // sound
} // love
#endif // 0
+76 -76
View File
@@ -1,76 +1,76 @@
/**
* Copyright (c) 2006-2012 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_FLAC_DECODER_H
#define LOVE_SOUND_LULLABY_FLAC_DECODER_H
#if 0
// LOVE
#include "common/Data.h"
#include "Decoder.h"
#include <FLAC++/decoder.h>
#include <string.h>
namespace love
{
namespace sound
{
namespace lullaby
{
class FLACDecoder : public Decoder, public FLAC::Decoder::Stream
{
public:
FLACDecoder(Data *data, const std::string &ext, int bufferSize);
~FLACDecoder();
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;
int getSampleRate() const;
//needed for FLAC
FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], size_t *bytes);
FLAC__StreamDecoderSeekStatus seek_callback(FLAC__uint64 offset);
FLAC__StreamDecoderTellStatus tell_callback(FLAC__uint64 *offset);
FLAC__StreamDecoderLengthStatus length_callback(FLAC__uint64 *length);
bool eof_callback();
FLAC__StreamDecoderWriteStatus write_callback(const FLAC__Frame *frame, const FLAC__int32 *const buffer[]);
void metadata_callback(const FLAC__StreamMetadata *metadata);
void error_callback(FLAC__StreamDecoderErrorStatus status);
private:
int pos;
}; // Decoder
} // lullaby
} // sound
} // love
#endif // 0
#endif // LOVE_SOUND_LULLABY_FLAC_DECODER_H
/**
* Copyright (c) 2006-2012 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_FLAC_DECODER_H
#define LOVE_SOUND_LULLABY_FLAC_DECODER_H
#if 0
// LOVE
#include "common/Data.h"
#include "Decoder.h"
#include <FLAC++/decoder.h>
#include <string.h>
namespace love
{
namespace sound
{
namespace lullaby
{
class FLACDecoder : public Decoder, public FLAC::Decoder::Stream
{
public:
FLACDecoder(Data *data, const std::string &ext, int bufferSize);
~FLACDecoder();
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;
int getSampleRate() const;
//needed for FLAC
FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], size_t *bytes);
FLAC__StreamDecoderSeekStatus seek_callback(FLAC__uint64 offset);
FLAC__StreamDecoderTellStatus tell_callback(FLAC__uint64 *offset);
FLAC__StreamDecoderLengthStatus length_callback(FLAC__uint64 *length);
bool eof_callback();
FLAC__StreamDecoderWriteStatus write_callback(const FLAC__Frame *frame, const FLAC__int32 *const buffer[]);
void metadata_callback(const FLAC__StreamMetadata *metadata);
void error_callback(FLAC__StreamDecoderErrorStatus status);
private:
int pos;
}; // Decoder
} // lullaby
} // sound
} // love
#endif // 0
#endif // LOVE_SOUND_LULLABY_FLAC_DECODER_H
+140 -140
View File
@@ -1,141 +1,141 @@
/**
* Copyright (c) 2006-2012 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"
#ifdef LOVE_SUPPORT_GME
#include "common/Exception.h"
#include "GmeDecoder.h"
namespace love
{
namespace sound
{
namespace lullaby
{
GmeDecoder::GmeDecoder(Data *data, const std::string &ext, int bufferSize)
: Decoder(data, ext, bufferSize)
, emu(0)
, num_tracks(0)
, cur_track(0)
{
void *d = data->getData();
int s = data->getSize();
if (gme_open_data(d, s, &emu, sampleRate) != 0)
throw love::Exception("Could not open game music file");
num_tracks = gme_track_count(emu);
if (num_tracks <= 0)
throw love::Exception("Game music file has no tracks");
if (gme_start_track(emu, cur_track) != 0)
throw love::Exception("Could not start game music playback");
}
GmeDecoder::~GmeDecoder()
{
if (emu)
gme_delete(emu);
}
bool GmeDecoder::accepts(const std::string &ext)
{
static const std::string supported[] =
{
"ay", "gbs", "gym", "hes", "kss", "nsf",
"nsfe", "sap", "spc", "vgm", "vgz"
};
for (int i = 0; !(supported[i].empty()); i++)
{
if (supported[i].compare(ext) == 0)
return true;
}
return false;
}
love::sound::Decoder *GmeDecoder::clone()
{
return new GmeDecoder(data, ext, bufferSize);
}
int GmeDecoder::decode()
{
short *sbuf = static_cast<short*>(buffer);
int size = bufferSize / sizeof(short);
if (gme_play(emu, size, sbuf) != 0)
throw love::Exception("Error while decoding game music");
if (!eof && gme_track_ended(emu))
{
// Start the next track if this one ended.
if (cur_track < num_tracks - 1)
gme_start_track(emu, ++cur_track);
else
eof = true;
}
return bufferSize;
}
bool GmeDecoder::seek(float s)
{
return gme_seek(emu, static_cast<long>(s * 1000.f)) != 0;
}
bool GmeDecoder::rewind()
{
// If we're in the first track, rewind.
if (cur_track == 0)
return gme_seek(emu, 0) == 0;
else
{
// Otherwise, start from the first track again.
cur_track = 0;
return gme_start_track(emu, cur_track) == 0;
}
}
bool GmeDecoder::isSeekable()
{
return true;
}
int GmeDecoder::getChannels() const
{
return 2;
}
int GmeDecoder::getBits() const
{
return 16;
}
} // lullaby
} // sound
} // love
/**
* Copyright (c) 2006-2012 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"
#ifdef LOVE_SUPPORT_GME
#include "common/Exception.h"
#include "GmeDecoder.h"
namespace love
{
namespace sound
{
namespace lullaby
{
GmeDecoder::GmeDecoder(Data *data, const std::string &ext, int bufferSize)
: Decoder(data, ext, bufferSize)
, emu(0)
, num_tracks(0)
, cur_track(0)
{
void *d = data->getData();
int s = data->getSize();
if (gme_open_data(d, s, &emu, sampleRate) != 0)
throw love::Exception("Could not open game music file");
num_tracks = gme_track_count(emu);
if (num_tracks <= 0)
throw love::Exception("Game music file has no tracks");
if (gme_start_track(emu, cur_track) != 0)
throw love::Exception("Could not start game music playback");
}
GmeDecoder::~GmeDecoder()
{
if (emu)
gme_delete(emu);
}
bool GmeDecoder::accepts(const std::string &ext)
{
static const std::string supported[] =
{
"ay", "gbs", "gym", "hes", "kss", "nsf",
"nsfe", "sap", "spc", "vgm", "vgz"
};
for (int i = 0; !(supported[i].empty()); i++)
{
if (supported[i].compare(ext) == 0)
return true;
}
return false;
}
love::sound::Decoder *GmeDecoder::clone()
{
return new GmeDecoder(data, ext, bufferSize);
}
int GmeDecoder::decode()
{
short *sbuf = static_cast<short*>(buffer);
int size = bufferSize / sizeof(short);
if (gme_play(emu, size, sbuf) != 0)
throw love::Exception("Error while decoding game music");
if (!eof && gme_track_ended(emu))
{
// Start the next track if this one ended.
if (cur_track < num_tracks - 1)
gme_start_track(emu, ++cur_track);
else
eof = true;
}
return bufferSize;
}
bool GmeDecoder::seek(float s)
{
return gme_seek(emu, static_cast<long>(s * 1000.f)) != 0;
}
bool GmeDecoder::rewind()
{
// If we're in the first track, rewind.
if (cur_track == 0)
return gme_seek(emu, 0) == 0;
else
{
// Otherwise, start from the first track again.
cur_track = 0;
return gme_start_track(emu, cur_track) == 0;
}
}
bool GmeDecoder::isSeekable()
{
return true;
}
int GmeDecoder::getChannels() const
{
return 2;
}
int GmeDecoder::getBits() const
{
return 16;
}
} // lullaby
} // sound
} // love
#endif // LOVE_SUPPORT_GME
+68 -68
View File
@@ -1,68 +1,68 @@
/**
* Copyright (c) 2006-2012 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_GME_DECODER_H
#define LOVE_SOUND_LULLABY_GME_DECODER_H
#ifdef LOVE_SUPPORT_GME
// LOVE
#include "common/Data.h"
#include "Decoder.h"
#include <gme.h>
namespace love
{
namespace sound
{
namespace lullaby
{
class GmeDecoder : public Decoder
{
public:
GmeDecoder(Data *data, const std::string &ext, int bufferSize);
virtual ~GmeDecoder();
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;
private:
Music_Emu *emu;
int num_tracks;
int cur_track;
}; // Decoder
} // lullaby
} // sound
} // love
#endif // LOVE_SUPPORT_GME
#endif // LOVE_SOUND_LULLABY_GME_DECODER_H
/**
* Copyright (c) 2006-2012 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_GME_DECODER_H
#define LOVE_SOUND_LULLABY_GME_DECODER_H
#ifdef LOVE_SUPPORT_GME
// LOVE
#include "common/Data.h"
#include "Decoder.h"
#include <gme.h>
namespace love
{
namespace sound
{
namespace lullaby
{
class GmeDecoder : public Decoder
{
public:
GmeDecoder(Data *data, const std::string &ext, int bufferSize);
virtual ~GmeDecoder();
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;
private:
Music_Emu *emu;
int num_tracks;
int cur_track;
}; // Decoder
} // lullaby
} // sound
} // love
#endif // LOVE_SUPPORT_GME
#endif // LOVE_SOUND_LULLABY_GME_DECODER_H
+147 -147
View File
@@ -1,147 +1,147 @@
/**
* Copyright (c) 2006-2012 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.
// Some settings not supported by some older versions
#ifndef LOVE_OLD_MODPLUG
settings.mStereoSeparation = 128;
settings.mMaxMixChannels = 32;
#endif
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-2012 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.
// Some settings not supported by some older versions
#ifndef LOVE_OLD_MODPLUG
settings.mStereoSeparation = 128;
settings.mMaxMixChannels = 32;
#endif
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
+65 -65
View File
@@ -1,65 +1,65 @@
/**
* Copyright (c) 2006-2012 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
{
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;
private:
ModPlugFile *plug;
ModPlug_Settings settings;
}; // Decoder
} // lullaby
} // sound
} // love
#endif // LOVE_SOUND_LULLABY_MODPLUG_DECODER_H
/**
* Copyright (c) 2006-2012 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
{
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;
private:
ModPlugFile *plug;
ModPlug_Settings settings;
}; // Decoder
} // lullaby
} // sound
} // love
#endif // LOVE_SOUND_LULLABY_MODPLUG_DECODER_H
+238 -238
View File
@@ -1,238 +1,238 @@
/**
* Copyright (c) 2006-2012 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_NOMPG123
#include "Mpg123Decoder.h"
#include "common/Exception.h"
#include <iostream>
namespace love
{
namespace sound
{
namespace lullaby
{
bool Mpg123Decoder::inited = false;
Mpg123Decoder::Mpg123Decoder(Data *data, const std::string &ext, int bufferSize)
: Decoder(data, ext, bufferSize)
, handle(0)
, channels(MPG123_STEREO)
{
data_size = data->getSize();
data_offset = 0;
int ret;
if (!inited)
{
ret = mpg123_init();
if (ret != MPG123_OK)
throw love::Exception("Could not initialize mpg123.");
inited = (ret == MPG123_OK);
}
//Intialize the handle
handle = mpg123_new(NULL, &ret);
if (handle == NULL)
throw love::Exception("Could not create handle.");
ret = mpg123_open_feed(handle);
if (ret != MPG123_OK)
throw love::Exception("Could not open feed.");
ret = feed(16384);
if (ret != MPG123_OK && ret != MPG123_DONE)
throw love::Exception("Could not feed!");
}
Mpg123Decoder::~Mpg123Decoder()
{
mpg123_delete(handle);
}
bool Mpg123Decoder::accepts(const std::string &ext)
{
static const std::string supported[] =
{
"mp3", ""
};
for (int i = 0; !(supported[i].empty()); i++)
{
if (supported[i].compare(ext) == 0)
return true;
}
return false;
}
void Mpg123Decoder::quit()
{
if (inited)
mpg123_exit();
}
love::sound::Decoder *Mpg123Decoder::clone()
{
return new Mpg123Decoder(data, ext, bufferSize);
}
int Mpg123Decoder::decode()
{
int size = 0;
bool done = false;
while (size < bufferSize && !done && !eof)
{
size_t numbytes = 0;
int r = mpg123_read(handle, (unsigned char *) buffer + size, bufferSize - size, &numbytes);
switch (r)
{
case MPG123_NEW_FORMAT:
{
size += numbytes;
long rate = 0;
int encoding = 0;
int ret = mpg123_getformat(handle, &rate, &channels, &encoding);
if (rate == 0)
rate = sampleRate;
else
sampleRate = rate;
if (channels == 0)
channels = MPG123_STEREO;
if (encoding == 0)
encoding = MPG123_ENC_SIGNED_16;
ret = mpg123_format(handle, rate, channels, encoding);
if (ret != MPG123_OK)
throw love::Exception("Could not set output format.");
}
continue;
case MPG123_NEED_MORE:
{
size += numbytes;
int v = feed(8192);
switch (v)
{
case MPG123_OK:
continue;
case MPG123_DONE:
if (numbytes == 0)
eof = true;
break;
default:
done = true;
}
continue;
}
case MPG123_OK:
size += numbytes;
continue;
case MPG123_DONE:
// Apparently, mpg123_read does not return MPG123_DONE, but
// let's keep it here anyway.
eof = true;
default:
done = true;
break;
}
}
return size;
}
bool Mpg123Decoder::seek(float s)
{
off_t offset = static_cast<off_t>(s * static_cast<float>(sampleRate));
if (offset < 0)
return false;
if (mpg123_feedseek(handle, offset, SEEK_SET, &offset) >= 0)
{
data_offset = offset;
eof = false;
return true;
}
else
return false;
}
bool Mpg123Decoder::rewind()
{
eof = false;
off_t offset;
if (mpg123_feedseek(handle, 0, SEEK_SET, &offset) >= 0)
{
data_offset = offset;
return true;
}
else
return false;
}
bool Mpg123Decoder::isSeekable()
{
return true;
}
int Mpg123Decoder::getChannels() const
{
return channels;
}
int Mpg123Decoder::getBits() const
{
return 16;
}
int Mpg123Decoder::feed(int bytes)
{
int remaining = data_size - data_offset;
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)
data_offset += feed_bytes;
return r;
}
} // lullaby
} // sound
} // love
#endif // LOVE_NOMPG123
/**
* Copyright (c) 2006-2012 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_NOMPG123
#include "Mpg123Decoder.h"
#include "common/Exception.h"
#include <iostream>
namespace love
{
namespace sound
{
namespace lullaby
{
bool Mpg123Decoder::inited = false;
Mpg123Decoder::Mpg123Decoder(Data *data, const std::string &ext, int bufferSize)
: Decoder(data, ext, bufferSize)
, handle(0)
, channels(MPG123_STEREO)
{
data_size = data->getSize();
data_offset = 0;
int ret;
if (!inited)
{
ret = mpg123_init();
if (ret != MPG123_OK)
throw love::Exception("Could not initialize mpg123.");
inited = (ret == MPG123_OK);
}
//Intialize the handle
handle = mpg123_new(NULL, &ret);
if (handle == NULL)
throw love::Exception("Could not create handle.");
ret = mpg123_open_feed(handle);
if (ret != MPG123_OK)
throw love::Exception("Could not open feed.");
ret = feed(16384);
if (ret != MPG123_OK && ret != MPG123_DONE)
throw love::Exception("Could not feed!");
}
Mpg123Decoder::~Mpg123Decoder()
{
mpg123_delete(handle);
}
bool Mpg123Decoder::accepts(const std::string &ext)
{
static const std::string supported[] =
{
"mp3", ""
};
for (int i = 0; !(supported[i].empty()); i++)
{
if (supported[i].compare(ext) == 0)
return true;
}
return false;
}
void Mpg123Decoder::quit()
{
if (inited)
mpg123_exit();
}
love::sound::Decoder *Mpg123Decoder::clone()
{
return new Mpg123Decoder(data, ext, bufferSize);
}
int Mpg123Decoder::decode()
{
int size = 0;
bool done = false;
while (size < bufferSize && !done && !eof)
{
size_t numbytes = 0;
int r = mpg123_read(handle, (unsigned char *) buffer + size, bufferSize - size, &numbytes);
switch (r)
{
case MPG123_NEW_FORMAT:
{
size += numbytes;
long rate = 0;
int encoding = 0;
int ret = mpg123_getformat(handle, &rate, &channels, &encoding);
if (rate == 0)
rate = sampleRate;
else
sampleRate = rate;
if (channels == 0)
channels = MPG123_STEREO;
if (encoding == 0)
encoding = MPG123_ENC_SIGNED_16;
ret = mpg123_format(handle, rate, channels, encoding);
if (ret != MPG123_OK)
throw love::Exception("Could not set output format.");
}
continue;
case MPG123_NEED_MORE:
{
size += numbytes;
int v = feed(8192);
switch (v)
{
case MPG123_OK:
continue;
case MPG123_DONE:
if (numbytes == 0)
eof = true;
break;
default:
done = true;
}
continue;
}
case MPG123_OK:
size += numbytes;
continue;
case MPG123_DONE:
// Apparently, mpg123_read does not return MPG123_DONE, but
// let's keep it here anyway.
eof = true;
default:
done = true;
break;
}
}
return size;
}
bool Mpg123Decoder::seek(float s)
{
off_t offset = static_cast<off_t>(s * static_cast<float>(sampleRate));
if (offset < 0)
return false;
if (mpg123_feedseek(handle, offset, SEEK_SET, &offset) >= 0)
{
data_offset = offset;
eof = false;
return true;
}
else
return false;
}
bool Mpg123Decoder::rewind()
{
eof = false;
off_t offset;
if (mpg123_feedseek(handle, 0, SEEK_SET, &offset) >= 0)
{
data_offset = offset;
return true;
}
else
return false;
}
bool Mpg123Decoder::isSeekable()
{
return true;
}
int Mpg123Decoder::getChannels() const
{
return channels;
}
int Mpg123Decoder::getBits() const
{
return 16;
}
int Mpg123Decoder::feed(int bytes)
{
int remaining = data_size - data_offset;
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)
data_offset += feed_bytes;
return r;
}
} // lullaby
} // sound
} // love
#endif // LOVE_NOMPG123
+80 -80
View File
@@ -1,80 +1,80 @@
/**
* Copyright (c) 2006-2012 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_NOMPG123
#ifndef LOVE_SOUND_LULLABY_LIBMPG123_DECODER_H
#define LOVE_SOUND_LULLABY_LIBMPG123_DECODER_H
// LOVE
#include "common/Data.h"
#include "Decoder.h"
// libmpg123
#ifdef LOVE_MACOSX
#include <mpg123/mpg123.h>
#else
#include <mpg123.h>
#endif
namespace love
{
namespace sound
{
namespace lullaby
{
class Mpg123Decoder : public Decoder
{
public:
Mpg123Decoder(Data *data, const std::string &ext, int bufferSize);
virtual ~Mpg123Decoder();
static bool accepts(const std::string &ext);
static void quit();
love::sound::Decoder *clone();
int decode();
bool seek(float s);
bool rewind();
bool isSeekable();
int getChannels() const;
int getBits() const;
private:
int feed(int bytes);
mpg123_handle *handle;
static bool inited;
int data_offset;
int data_size;
int channels;
}; // Decoder
} // lullaby
} // sound
} // love
#endif // LOVE_SOUND_LULLABY_LIBMPG123_DECODER_H
#endif // LOVE_NOMPG123
/**
* Copyright (c) 2006-2012 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_NOMPG123
#ifndef LOVE_SOUND_LULLABY_LIBMPG123_DECODER_H
#define LOVE_SOUND_LULLABY_LIBMPG123_DECODER_H
// LOVE
#include "common/Data.h"
#include "Decoder.h"
// libmpg123
#ifdef LOVE_MACOSX
#include <mpg123/mpg123.h>
#else
#include <mpg123.h>
#endif
namespace love
{
namespace sound
{
namespace lullaby
{
class Mpg123Decoder : public Decoder
{
public:
Mpg123Decoder(Data *data, const std::string &ext, int bufferSize);
virtual ~Mpg123Decoder();
static bool accepts(const std::string &ext);
static void quit();
love::sound::Decoder *clone();
int decode();
bool seek(float s);
bool rewind();
bool isSeekable();
int getChannels() const;
int getBits() const;
private:
int feed(int bytes);
mpg123_handle *handle;
static bool inited;
int data_offset;
int data_size;
int channels;
}; // Decoder
} // lullaby
} // sound
} // love
#endif // LOVE_SOUND_LULLABY_LIBMPG123_DECODER_H
#endif // LOVE_NOMPG123
+86 -86
View File
@@ -1,86 +1,86 @@
/**
* Copyright (c) 2006-2012 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 "Sound.h"
#include "ModPlugDecoder.h"
#include "Mpg123Decoder.h"
#include "VorbisDecoder.h"
#include "GmeDecoder.h"
//#include "FLACDecoder.h"
namespace love
{
namespace sound
{
namespace lullaby
{
Sound::Sound()
{
}
Sound::~Sound()
{
#ifndef LOVE_NOMPG123
Mpg123Decoder::quit();
#endif // LOVE_NOMPG123
}
const char *Sound::getName() const
{
return "love.sound.lullaby";
}
sound::Decoder *Sound::newDecoder(love::filesystem::File *file, int bufferSize)
{
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))
decoder = new ModPlugDecoder(data, ext, bufferSize);
#ifndef LOVE_NOMPG123
else if (Mpg123Decoder::accepts(ext))
decoder = new Mpg123Decoder(data, ext, bufferSize);
#endif // LOVE_NOMPG123
else if (VorbisDecoder::accepts(ext))
decoder = new VorbisDecoder(data, ext, bufferSize);
#ifdef LOVE_SUPPORT_GME
else if (GmeDecoder::accepts(ext))
decoder = new GmeDecoder(data, ext, bufferSize);
#endif // LOVE_SUPPORT_GME
/*else if (FLACDecoder::accepts(ext))
decoder = new FLACDecoder(data, ext, bufferSize);*/
// else if (OtherDecoder::accept(ext))
data->release();
return decoder;
}
} // lullaby
} // sound
} // love
/**
* Copyright (c) 2006-2012 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 "Sound.h"
#include "ModPlugDecoder.h"
#include "Mpg123Decoder.h"
#include "VorbisDecoder.h"
#include "GmeDecoder.h"
//#include "FLACDecoder.h"
namespace love
{
namespace sound
{
namespace lullaby
{
Sound::Sound()
{
}
Sound::~Sound()
{
#ifndef LOVE_NOMPG123
Mpg123Decoder::quit();
#endif // LOVE_NOMPG123
}
const char *Sound::getName() const
{
return "love.sound.lullaby";
}
sound::Decoder *Sound::newDecoder(love::filesystem::File *file, int bufferSize)
{
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))
decoder = new ModPlugDecoder(data, ext, bufferSize);
#ifndef LOVE_NOMPG123
else if (Mpg123Decoder::accepts(ext))
decoder = new Mpg123Decoder(data, ext, bufferSize);
#endif // LOVE_NOMPG123
else if (VorbisDecoder::accepts(ext))
decoder = new VorbisDecoder(data, ext, bufferSize);
#ifdef LOVE_SUPPORT_GME
else if (GmeDecoder::accepts(ext))
decoder = new GmeDecoder(data, ext, bufferSize);
#endif // LOVE_SUPPORT_GME
/*else if (FLACDecoder::accepts(ext))
decoder = new FLACDecoder(data, ext, bufferSize);*/
// else if (OtherDecoder::accept(ext))
data->release();
return decoder;
}
} // lullaby
} // sound
} // love
+69 -69
View File
@@ -1,70 +1,70 @@
/**
* Copyright (c) 2006-2012 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_SOUND_H
#define LOVE_SOUND_LULLABY_SOUND_H
// LOVE
#include <sound/Sound.h>
#include "sound/Decoder.h"
namespace love
{
namespace sound
{
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.
**/
class Sound : public love::sound::Sound
{
public:
/**
* Constructor. Initializes relevant libraries.
**/
Sound();
/**
* Destructor. Deinitializes relevant libraries.
**/
virtual ~Sound();
/// @copydoc love::Module::getName
const char *getName() const;
/// @copydoc love::sound::Sound::newDecoder
sound::Decoder *newDecoder(love::filesystem::File *file, int bufferSize);
}; // Sound
} // lullaby
} // sound
} // love
/**
* Copyright (c) 2006-2012 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_SOUND_H
#define LOVE_SOUND_LULLABY_SOUND_H
// LOVE
#include <sound/Sound.h>
#include "sound/Decoder.h"
namespace love
{
namespace sound
{
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.
**/
class Sound : public love::sound::Sound
{
public:
/**
* Constructor. Initializes relevant libraries.
**/
Sound();
/**
* Destructor. Deinitializes relevant libraries.
**/
virtual ~Sound();
/// @copydoc love::Module::getName
const char *getName() const;
/// @copydoc love::sound::Sound::newDecoder
sound::Decoder *newDecoder(love::filesystem::File *file, int bufferSize);
}; // Sound
} // lullaby
} // sound
} // love
#endif // LOVE_SOUND_LULLABY_SOUND_H
+258 -258
View File
@@ -1,258 +1,258 @@
/**
* Copyright (c) 2006-2012 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 "VorbisDecoder.h"
#include <string.h>
#include "common/config.h"
#include "common/Exception.h"
namespace love
{
namespace sound
{
namespace lullaby
{
/**
* CALLBACK FUNCTIONS
**/
int vorbisClose(void * /* ptr to the data that the vorbis files need*/)
{
// Does nothing (handled elsewhere)
return 1;
}
size_t vorbisRead(void *ptr /* ptr to the data that the vorbis files need*/,
size_t byteSize /* how big a byte is*/,
size_t sizeToRead /* How much we can read*/,
void *datasource /* this is a pointer to the data we passed into ov_open_callbacks (our SOggFile struct*/)
{
size_t spaceToEOF; // How much more we can read till we hit the EOF marker
size_t actualSizeToRead; // How much data we are actually going to read from memory
SOggFile *vorbisData; // Our vorbis data, for the typecast
// Get the data in the right format
vorbisData = (SOggFile *)datasource;
// Calculate how much we need to read. This can be sizeToRead*byteSize or less depending on how near the EOF marker we are
spaceToEOF = vorbisData->dataSize - vorbisData->dataRead;
if ((sizeToRead*byteSize) < spaceToEOF)
actualSizeToRead = (sizeToRead*byteSize);
else
actualSizeToRead = spaceToEOF;
// A simple copy of the data from memory to the datastruct that the vorbis libs will use
if (actualSizeToRead)
{
// Copy the data from the start of the file PLUS how much we have already read in
memcpy(ptr, (char *)vorbisData->dataPtr + vorbisData->dataRead, actualSizeToRead);
// Increase by how much we have read by
vorbisData->dataRead += (actualSizeToRead);
}
// Return how much we read (in the same way fread would)
return actualSizeToRead;
}
int vorbisSeek(void *datasource /* ptr to the data that the vorbis files need*/,
ogg_int64_t offset /*offset from the point we wish to seek to*/,
int whence /*where we want to seek to*/)
{
int spaceToEOF; // How much more we can read till we hit the EOF marker
ogg_int64_t actualOffset; // How much we can actually offset it by
SOggFile *vorbisData; // The data we passed in (for the typecast)
// Get the data in the right format
vorbisData = (SOggFile *) datasource;
// Goto where we wish to seek to
switch (whence)
{
case SEEK_SET: // Seek to the start of the data file
// Make sure we are not going to the end of the file
if (vorbisData->dataSize >= offset)
actualOffset = offset;
else
actualOffset = vorbisData->dataSize;
// Set where we now are
vorbisData->dataRead = (int)actualOffset;
break;
case SEEK_CUR: // Seek from where we are
// Make sure we dont go past the end
spaceToEOF = vorbisData->dataSize - vorbisData->dataRead;
if (offset < spaceToEOF)
actualOffset = (offset);
else
actualOffset = spaceToEOF;
// Seek from our currrent location
vorbisData->dataRead += (int)actualOffset;
break;
case SEEK_END: // Seek from the end of the file
vorbisData->dataRead = vorbisData->dataSize+1;
break;
default:
throw love::Exception("Unknown seek command in vorbisSeek\n");
break;
};
return 0;
}
long vorbisTell(void *datasource /* ptr to the data that the vorbis files need*/)
{
SOggFile *vorbisData;
vorbisData = (SOggFile *) datasource;
return vorbisData->dataRead;
}
/**
* END CALLBACK FUNCTIONS
**/
VorbisDecoder::VorbisDecoder(Data *data, const std::string &ext, int bufferSize)
: Decoder(data, ext, bufferSize)
{
// Initialize callbacks
vorbisCallbacks.close_func = vorbisClose;
vorbisCallbacks.seek_func = vorbisSeek;
vorbisCallbacks.read_func = vorbisRead;
vorbisCallbacks.tell_func = vorbisTell;
// Check endianness
#ifdef LOVE_BIG_ENDIAN
endian = 1;
#else
endian = 0;
#endif
// Initialize OGG file
oggFile.dataPtr = (char *) data->getData();
oggFile.dataSize = data->getSize();
oggFile.dataRead = 0;
// Open Vorbis handle
if (ov_open_callbacks(&oggFile, &handle, NULL, 0, vorbisCallbacks) < 0)
throw love::Exception("Could not read Ogg bitstream");
// Get info and comments
vorbisInfo = ov_info(&handle, -1);
vorbisComment = ov_comment(&handle, -1);
}
VorbisDecoder::~VorbisDecoder()
{
ov_clear(&handle);
}
bool VorbisDecoder::accepts(const std::string &ext)
{
static const std::string supported[] =
{
"ogg", "oga", ""
};
for (int i = 0; !(supported[i].empty()); i++)
{
if (supported[i].compare(ext) == 0)
return true;
}
return false;
}
love::sound::Decoder *VorbisDecoder::clone()
{
return new VorbisDecoder(data, ext, bufferSize);
}
int VorbisDecoder::decode()
{
int size = 0;
while (size < bufferSize)
{
int result = ov_read(&handle, (char *) buffer + size, bufferSize - size, endian, (getBits() == 16 ? 2 : 1), 1, 0);
if (result == OV_HOLE)
continue;
else if (result <= OV_EREAD)
return -1;
else if (result == 0)
{
eof = true;
break;
}
else if (result > 0)
size += result;
}
return size;
}
bool VorbisDecoder::seek(float s)
{
int result = ov_time_seek(&handle, s);
if (result == 0)
{
eof = false;
return true;
}
return false;
}
bool VorbisDecoder::rewind()
{
int result = ov_pcm_seek(&handle, 0);
if (result == 0)
{
eof = false;
return true;
}
return false;
}
bool VorbisDecoder::isSeekable()
{
long result = ov_seekable(&handle);
return (result != 0);
}
int VorbisDecoder::getChannels() const
{
return vorbisInfo->channels;
}
int VorbisDecoder::getBits() const
{
return 16;
}
int VorbisDecoder::getSampleRate() const
{
return vorbisInfo->rate;
}
} // lullaby
} // sound
} // love
/**
* Copyright (c) 2006-2012 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 "VorbisDecoder.h"
#include <string.h>
#include "common/config.h"
#include "common/Exception.h"
namespace love
{
namespace sound
{
namespace lullaby
{
/**
* CALLBACK FUNCTIONS
**/
int vorbisClose(void * /* ptr to the data that the vorbis files need*/)
{
// Does nothing (handled elsewhere)
return 1;
}
size_t vorbisRead(void *ptr /* ptr to the data that the vorbis files need*/,
size_t byteSize /* how big a byte is*/,
size_t sizeToRead /* How much we can read*/,
void *datasource /* this is a pointer to the data we passed into ov_open_callbacks (our SOggFile struct*/)
{
size_t spaceToEOF; // How much more we can read till we hit the EOF marker
size_t actualSizeToRead; // How much data we are actually going to read from memory
SOggFile *vorbisData; // Our vorbis data, for the typecast
// Get the data in the right format
vorbisData = (SOggFile *)datasource;
// Calculate how much we need to read. This can be sizeToRead*byteSize or less depending on how near the EOF marker we are
spaceToEOF = vorbisData->dataSize - vorbisData->dataRead;
if ((sizeToRead*byteSize) < spaceToEOF)
actualSizeToRead = (sizeToRead*byteSize);
else
actualSizeToRead = spaceToEOF;
// A simple copy of the data from memory to the datastruct that the vorbis libs will use
if (actualSizeToRead)
{
// Copy the data from the start of the file PLUS how much we have already read in
memcpy(ptr, (char *)vorbisData->dataPtr + vorbisData->dataRead, actualSizeToRead);
// Increase by how much we have read by
vorbisData->dataRead += (actualSizeToRead);
}
// Return how much we read (in the same way fread would)
return actualSizeToRead;
}
int vorbisSeek(void *datasource /* ptr to the data that the vorbis files need*/,
ogg_int64_t offset /*offset from the point we wish to seek to*/,
int whence /*where we want to seek to*/)
{
int spaceToEOF; // How much more we can read till we hit the EOF marker
ogg_int64_t actualOffset; // How much we can actually offset it by
SOggFile *vorbisData; // The data we passed in (for the typecast)
// Get the data in the right format
vorbisData = (SOggFile *) datasource;
// Goto where we wish to seek to
switch (whence)
{
case SEEK_SET: // Seek to the start of the data file
// Make sure we are not going to the end of the file
if (vorbisData->dataSize >= offset)
actualOffset = offset;
else
actualOffset = vorbisData->dataSize;
// Set where we now are
vorbisData->dataRead = (int)actualOffset;
break;
case SEEK_CUR: // Seek from where we are
// Make sure we dont go past the end
spaceToEOF = vorbisData->dataSize - vorbisData->dataRead;
if (offset < spaceToEOF)
actualOffset = (offset);
else
actualOffset = spaceToEOF;
// Seek from our currrent location
vorbisData->dataRead += (int)actualOffset;
break;
case SEEK_END: // Seek from the end of the file
vorbisData->dataRead = vorbisData->dataSize+1;
break;
default:
throw love::Exception("Unknown seek command in vorbisSeek\n");
break;
};
return 0;
}
long vorbisTell(void *datasource /* ptr to the data that the vorbis files need*/)
{
SOggFile *vorbisData;
vorbisData = (SOggFile *) datasource;
return vorbisData->dataRead;
}
/**
* END CALLBACK FUNCTIONS
**/
VorbisDecoder::VorbisDecoder(Data *data, const std::string &ext, int bufferSize)
: Decoder(data, ext, bufferSize)
{
// Initialize callbacks
vorbisCallbacks.close_func = vorbisClose;
vorbisCallbacks.seek_func = vorbisSeek;
vorbisCallbacks.read_func = vorbisRead;
vorbisCallbacks.tell_func = vorbisTell;
// Check endianness
#ifdef LOVE_BIG_ENDIAN
endian = 1;
#else
endian = 0;
#endif
// Initialize OGG file
oggFile.dataPtr = (char *) data->getData();
oggFile.dataSize = data->getSize();
oggFile.dataRead = 0;
// Open Vorbis handle
if (ov_open_callbacks(&oggFile, &handle, NULL, 0, vorbisCallbacks) < 0)
throw love::Exception("Could not read Ogg bitstream");
// Get info and comments
vorbisInfo = ov_info(&handle, -1);
vorbisComment = ov_comment(&handle, -1);
}
VorbisDecoder::~VorbisDecoder()
{
ov_clear(&handle);
}
bool VorbisDecoder::accepts(const std::string &ext)
{
static const std::string supported[] =
{
"ogg", "oga", ""
};
for (int i = 0; !(supported[i].empty()); i++)
{
if (supported[i].compare(ext) == 0)
return true;
}
return false;
}
love::sound::Decoder *VorbisDecoder::clone()
{
return new VorbisDecoder(data, ext, bufferSize);
}
int VorbisDecoder::decode()
{
int size = 0;
while (size < bufferSize)
{
int result = ov_read(&handle, (char *) buffer + size, bufferSize - size, endian, (getBits() == 16 ? 2 : 1), 1, 0);
if (result == OV_HOLE)
continue;
else if (result <= OV_EREAD)
return -1;
else if (result == 0)
{
eof = true;
break;
}
else if (result > 0)
size += result;
}
return size;
}
bool VorbisDecoder::seek(float s)
{
int result = ov_time_seek(&handle, s);
if (result == 0)
{
eof = false;
return true;
}
return false;
}
bool VorbisDecoder::rewind()
{
int result = ov_pcm_seek(&handle, 0);
if (result == 0)
{
eof = false;
return true;
}
return false;
}
bool VorbisDecoder::isSeekable()
{
long result = ov_seekable(&handle);
return (result != 0);
}
int VorbisDecoder::getChannels() const
{
return vorbisInfo->channels;
}
int VorbisDecoder::getBits() const
{
return 16;
}
int VorbisDecoder::getSampleRate() const
{
return vorbisInfo->rate;
}
} // lullaby
} // sound
} // love
+78 -78
View File
@@ -1,78 +1,78 @@
/**
* Copyright (c) 2006-2012 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_VORBIS_DECODER_H
#define LOVE_SOUND_LULLABY_VORBIS_DECODER_H
// LOVE
#include "common/Data.h"
#include "Decoder.h"
// vorbis
#include <vorbis/codec.h>
#include <vorbis/vorbisfile.h>
namespace love
{
namespace sound
{
namespace lullaby
{
// Struct for handling data
struct SOggFile
{
char *dataPtr; // Pointer to the data in memory
int dataSize; // Size of the data
int dataRead; // How much we've read so far
};
class VorbisDecoder : public Decoder
{
public:
VorbisDecoder(Data *data, const std::string &ext, int bufferSize);
virtual ~VorbisDecoder();
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;
int getSampleRate() const;
private:
SOggFile oggFile; // (see struct)
ov_callbacks vorbisCallbacks; // Callbacks used to read the file from mem
OggVorbis_File handle; // Handle to the file
vorbis_info *vorbisInfo; // Info
vorbis_comment *vorbisComment; // Comments
int endian; // Endianness
}; // VorbisDecoder
} // lullaby
} // sound
} // love
#endif // LOVE_SOUND_LULLABY_VORBIS_DECODER_H
/**
* Copyright (c) 2006-2012 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_VORBIS_DECODER_H
#define LOVE_SOUND_LULLABY_VORBIS_DECODER_H
// LOVE
#include "common/Data.h"
#include "Decoder.h"
// vorbis
#include <vorbis/codec.h>
#include <vorbis/vorbisfile.h>
namespace love
{
namespace sound
{
namespace lullaby
{
// Struct for handling data
struct SOggFile
{
char *dataPtr; // Pointer to the data in memory
int dataSize; // Size of the data
int dataRead; // How much we've read so far
};
class VorbisDecoder : public Decoder
{
public:
VorbisDecoder(Data *data, const std::string &ext, int bufferSize);
virtual ~VorbisDecoder();
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;
int getSampleRate() const;
private:
SOggFile oggFile; // (see struct)
ov_callbacks vorbisCallbacks; // Callbacks used to read the file from mem
OggVorbis_File handle; // Handle to the file
vorbis_info *vorbisInfo; // Info
vorbis_comment *vorbisComment; // Comments
int endian; // Endianness
}; // VorbisDecoder
} // lullaby
} // sound
} // love
#endif // LOVE_SOUND_LULLABY_VORBIS_DECODER_H
+68 -68
View File
@@ -1,68 +1,68 @@
/**
* Copyright (c) 2006-2012 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 "wrap_Decoder.h"
namespace love
{
namespace sound
{
Decoder *luax_checkdecoder(lua_State *L, int idx)
{
return luax_checktype<Decoder>(L, idx, "Decoder", SOUND_DECODER_T);
}
int w_Decoder_getChannels(lua_State *L)
{
Decoder *t = luax_checkdecoder(L, 1);
lua_pushinteger(L, t->getChannels());
return 1;
}
int w_Decoder_getBits(lua_State *L)
{
Decoder *t = luax_checkdecoder(L, 1);
lua_pushinteger(L, t->getBits());
return 1;
}
int w_Decoder_getSampleRate(lua_State *L)
{
Decoder *t = luax_checkdecoder(L, 1);
lua_pushinteger(L, t->getSampleRate());
return 1;
}
static const luaL_Reg functions[] =
{
{ "getChannels", w_Decoder_getChannels },
{ "getBits", w_Decoder_getBits },
{ "getSampleRate", w_Decoder_getSampleRate },
{ 0, 0 }
};
extern "C" int luaopen_decoder(lua_State *L)
{
return luax_register_type(L, "Decoder", functions);
}
} // sound
} // love
/**
* Copyright (c) 2006-2012 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 "wrap_Decoder.h"
namespace love
{
namespace sound
{
Decoder *luax_checkdecoder(lua_State *L, int idx)
{
return luax_checktype<Decoder>(L, idx, "Decoder", SOUND_DECODER_T);
}
int w_Decoder_getChannels(lua_State *L)
{
Decoder *t = luax_checkdecoder(L, 1);
lua_pushinteger(L, t->getChannels());
return 1;
}
int w_Decoder_getBits(lua_State *L)
{
Decoder *t = luax_checkdecoder(L, 1);
lua_pushinteger(L, t->getBits());
return 1;
}
int w_Decoder_getSampleRate(lua_State *L)
{
Decoder *t = luax_checkdecoder(L, 1);
lua_pushinteger(L, t->getSampleRate());
return 1;
}
static const luaL_Reg functions[] =
{
{ "getChannels", w_Decoder_getChannels },
{ "getBits", w_Decoder_getBits },
{ "getSampleRate", w_Decoder_getSampleRate },
{ 0, 0 }
};
extern "C" int luaopen_decoder(lua_State *L)
{
return luax_register_type(L, "Decoder", functions);
}
} // sound
} // love
+42 -42
View File
@@ -1,42 +1,42 @@
/**
* Copyright (c) 2006-2012 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_WRAP_DECODER_H
#define LOVE_SOUND_WRAP_DECODER_H
// LOVE
#include "common/runtime.h"
#include "Decoder.h"
namespace love
{
namespace sound
{
Decoder *luax_checkdecoder(lua_State *L, int idx);
int w_Decoder_getChannels(lua_State *L);
int w_Decoder_getBits(lua_State *L);
int w_Decoder_getSampleRate(lua_State *L);
extern "C" int luaopen_decoder(lua_State *L);
} // sound
} // love
#endif // LOVE_SOUND_WRAP_DECODER_H
/**
* Copyright (c) 2006-2012 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_WRAP_DECODER_H
#define LOVE_SOUND_WRAP_DECODER_H
// LOVE
#include "common/runtime.h"
#include "Decoder.h"
namespace love
{
namespace sound
{
Decoder *luax_checkdecoder(lua_State *L, int idx);
int w_Decoder_getChannels(lua_State *L);
int w_Decoder_getBits(lua_State *L);
int w_Decoder_getSampleRate(lua_State *L);
extern "C" int luaopen_decoder(lua_State *L);
} // sound
} // love
#endif // LOVE_SOUND_WRAP_DECODER_H
+147 -147
View File
@@ -1,147 +1,147 @@
/**
* Copyright (c) 2006-2012 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 "wrap_Sound.h"
// Implementations.
#include "lullaby/Sound.h"
namespace love
{
namespace sound
{
static Sound *instance = 0;
int w_newSoundData(lua_State *L)
{
SoundData *t = 0;
if (lua_isnumber(L, 1))
{
int samples = luaL_checkint(L, 1);
int sampleRate = luaL_optint(L, 2, Decoder::DEFAULT_SAMPLE_RATE);
int bits = luaL_optint(L, 3, Decoder::DEFAULT_BITS);
int channels = luaL_optint(L, 4, Decoder::DEFAULT_CHANNELS);
try
{
t = instance->newSoundData(samples, sampleRate, bits, channels);
}
catch(love::Exception &e)
{
return luaL_error(L, e.what());
}
}
// Must be string or decoder.
else
{
// Convert to Decoder, if necessary.
if (!luax_istype(L, 1, SOUND_DECODER_T))
{
w_newDecoder(L);
lua_replace(L, 1);
}
try
{
t = instance->newSoundData(luax_checkdecoder(L, 1));
}
catch(love::Exception &e)
{
return luaL_error(L, e.what());
}
}
luax_newtype(L, "SoundData", SOUND_SOUND_DATA_T, (void *)t);
return 1;
}
int w_newDecoder(lua_State *L)
{
// Convert to File, if necessary.
if (lua_isstring(L, 1))
luax_convobj(L, 1, "filesystem", "newFile");
love::filesystem::File *file = luax_checktype<love::filesystem::File>(L, 1, "File", FILESYSTEM_FILE_T);
int bufferSize = luaL_optint(L, 2, Decoder::DEFAULT_BUFFER_SIZE);
try
{
Decoder *t = instance->newDecoder(file, bufferSize);
if (t == 0)
return luaL_error(L, "Extension \"%s\" not supported.", file->getExtension().c_str());
luax_newtype(L, "Decoder", SOUND_DECODER_T, (void *)t);
}
catch(love::Exception &e)
{
return luaL_error(L, e.what());
}
return 1;
}
// List of functions to wrap.
static const luaL_Reg functions[] =
{
{ "newSoundData", w_newSoundData },
{ "newDecoder", w_newDecoder },
{ 0, 0 }
};
static const lua_CFunction types[] =
{
luaopen_sounddata,
luaopen_decoder,
0
};
extern "C" int luaopen_love_sound(lua_State *L)
{
if (instance == 0)
{
try
{
instance = new lullaby::Sound();
}
catch(Exception &e)
{
return luaL_error(L, e.what());
}
}
else
instance->retain();
WrappedModule w;
w.module = instance;
w.name = "sound";
w.flags = MODULE_SOUND_T;
w.functions = functions;
w.types = types;
return luax_register_module(L, w);
}
} // sound
} // love
/**
* Copyright (c) 2006-2012 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 "wrap_Sound.h"
// Implementations.
#include "lullaby/Sound.h"
namespace love
{
namespace sound
{
static Sound *instance = 0;
int w_newSoundData(lua_State *L)
{
SoundData *t = 0;
if (lua_isnumber(L, 1))
{
int samples = luaL_checkint(L, 1);
int sampleRate = luaL_optint(L, 2, Decoder::DEFAULT_SAMPLE_RATE);
int bits = luaL_optint(L, 3, Decoder::DEFAULT_BITS);
int channels = luaL_optint(L, 4, Decoder::DEFAULT_CHANNELS);
try
{
t = instance->newSoundData(samples, sampleRate, bits, channels);
}
catch(love::Exception &e)
{
return luaL_error(L, e.what());
}
}
// Must be string or decoder.
else
{
// Convert to Decoder, if necessary.
if (!luax_istype(L, 1, SOUND_DECODER_T))
{
w_newDecoder(L);
lua_replace(L, 1);
}
try
{
t = instance->newSoundData(luax_checkdecoder(L, 1));
}
catch(love::Exception &e)
{
return luaL_error(L, e.what());
}
}
luax_newtype(L, "SoundData", SOUND_SOUND_DATA_T, (void *)t);
return 1;
}
int w_newDecoder(lua_State *L)
{
// Convert to File, if necessary.
if (lua_isstring(L, 1))
luax_convobj(L, 1, "filesystem", "newFile");
love::filesystem::File *file = luax_checktype<love::filesystem::File>(L, 1, "File", FILESYSTEM_FILE_T);
int bufferSize = luaL_optint(L, 2, Decoder::DEFAULT_BUFFER_SIZE);
try
{
Decoder *t = instance->newDecoder(file, bufferSize);
if (t == 0)
return luaL_error(L, "Extension \"%s\" not supported.", file->getExtension().c_str());
luax_newtype(L, "Decoder", SOUND_DECODER_T, (void *)t);
}
catch(love::Exception &e)
{
return luaL_error(L, e.what());
}
return 1;
}
// List of functions to wrap.
static const luaL_Reg functions[] =
{
{ "newSoundData", w_newSoundData },
{ "newDecoder", w_newDecoder },
{ 0, 0 }
};
static const lua_CFunction types[] =
{
luaopen_sounddata,
luaopen_decoder,
0
};
extern "C" int luaopen_love_sound(lua_State *L)
{
if (instance == 0)
{
try
{
instance = new lullaby::Sound();
}
catch(Exception &e)
{
return luaL_error(L, e.what());
}
}
else
instance->retain();
WrappedModule w;
w.module = instance;
w.name = "sound";
w.flags = MODULE_SOUND_T;
w.functions = functions;
w.types = types;
return luax_register_module(L, w);
}
} // sound
} // love
+42 -42
View File
@@ -1,42 +1,42 @@
/**
* Copyright (c) 2006-2012 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_WRAP_SOUND_H
#define LOVE_SOUND_WRAP_SOUND_H
// LOVE
#include "common/config.h"
#include "Sound.h"
#include "wrap_SoundData.h"
#include "wrap_Decoder.h"
namespace love
{
namespace sound
{
int w_newSoundData(lua_State *L);
int w_newDecoder(lua_State *L);
extern "C" LOVE_EXPORT int luaopen_love_sound(lua_State *L);
} // sound
} // love
#endif // LOVE_SOUND_WRAP_SOUND_H
/**
* Copyright (c) 2006-2012 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_WRAP_SOUND_H
#define LOVE_SOUND_WRAP_SOUND_H
// LOVE
#include "common/config.h"
#include "Sound.h"
#include "wrap_SoundData.h"
#include "wrap_Decoder.h"
namespace love
{
namespace sound
{
int w_newSoundData(lua_State *L);
int w_newDecoder(lua_State *L);
extern "C" LOVE_EXPORT int luaopen_love_sound(lua_State *L);
} // sound
} // love
#endif // LOVE_SOUND_WRAP_SOUND_H
+94 -94
View File
@@ -1,94 +1,94 @@
/**
* Copyright (c) 2006-2012 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 "wrap_SoundData.h"
#include "common/wrap_Data.h"
namespace love
{
namespace sound
{
SoundData *luax_checksounddata(lua_State *L, int idx)
{
return luax_checktype<SoundData>(L, idx, "SoundData", SOUND_SOUND_DATA_T);
}
int w_SoundData_getChannels(lua_State *L)
{
SoundData *t = luax_checksounddata(L, 1);
lua_pushinteger(L, t->getChannels());
return 1;
}
int w_SoundData_getBits(lua_State *L)
{
SoundData *t = luax_checksounddata(L, 1);
lua_pushinteger(L, t->getBits());
return 1;
}
int w_SoundData_getSampleRate(lua_State *L)
{
SoundData *t = luax_checksounddata(L, 1);
lua_pushinteger(L, t->getSampleRate());
return 1;
}
int w_SoundData_setSample(lua_State *L)
{
SoundData *sd = luax_checksounddata(L, 1);
int i = (int)lua_tointeger(L, 2);
float sample = (float)lua_tonumber(L, 3);
sd->setSample(i, sample);
return 0;
}
int w_SoundData_getSample(lua_State *L)
{
SoundData *sd = luax_checksounddata(L, 1);
int i = (int)lua_tointeger(L, 2);
lua_pushnumber(L, sd->getSample(i));
return 1;
}
static const luaL_Reg functions[] =
{
// Data
{ "getPointer", w_Data_getPointer },
{ "getSize", w_Data_getSize },
{ "getChannels", w_SoundData_getChannels },
{ "getBits", w_SoundData_getBits },
{ "getSampleRate", w_SoundData_getSampleRate },
{ "setSample", w_SoundData_setSample },
{ "getSample", w_SoundData_getSample },
{ 0, 0 }
};
extern "C" int luaopen_sounddata(lua_State *L)
{
return luax_register_type(L, "SoundData", functions);
}
} // sound
} // love
/**
* Copyright (c) 2006-2012 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 "wrap_SoundData.h"
#include "common/wrap_Data.h"
namespace love
{
namespace sound
{
SoundData *luax_checksounddata(lua_State *L, int idx)
{
return luax_checktype<SoundData>(L, idx, "SoundData", SOUND_SOUND_DATA_T);
}
int w_SoundData_getChannels(lua_State *L)
{
SoundData *t = luax_checksounddata(L, 1);
lua_pushinteger(L, t->getChannels());
return 1;
}
int w_SoundData_getBits(lua_State *L)
{
SoundData *t = luax_checksounddata(L, 1);
lua_pushinteger(L, t->getBits());
return 1;
}
int w_SoundData_getSampleRate(lua_State *L)
{
SoundData *t = luax_checksounddata(L, 1);
lua_pushinteger(L, t->getSampleRate());
return 1;
}
int w_SoundData_setSample(lua_State *L)
{
SoundData *sd = luax_checksounddata(L, 1);
int i = (int)lua_tointeger(L, 2);
float sample = (float)lua_tonumber(L, 3);
sd->setSample(i, sample);
return 0;
}
int w_SoundData_getSample(lua_State *L)
{
SoundData *sd = luax_checksounddata(L, 1);
int i = (int)lua_tointeger(L, 2);
lua_pushnumber(L, sd->getSample(i));
return 1;
}
static const luaL_Reg functions[] =
{
// Data
{ "getPointer", w_Data_getPointer },
{ "getSize", w_Data_getSize },
{ "getChannels", w_SoundData_getChannels },
{ "getBits", w_SoundData_getBits },
{ "getSampleRate", w_SoundData_getSampleRate },
{ "setSample", w_SoundData_setSample },
{ "getSample", w_SoundData_getSample },
{ 0, 0 }
};
extern "C" int luaopen_sounddata(lua_State *L)
{
return luax_register_type(L, "SoundData", functions);
}
} // sound
} // love
+46 -46
View File
@@ -1,46 +1,46 @@
/**
* Copyright (c) 2006-2012 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_WRAP_SOUND_DATA_H
#define LOVE_SOUND_WRAP_SOUND_DATA_H
// LOVE
#include "common/runtime.h"
#include "SoundData.h"
namespace love
{
namespace sound
{
SoundData *luax_checksounddata(lua_State *L, int idx);
int w_getPointer(lua_State *L);
int w_getSize(lua_State *L);
int w_getChannels(lua_State *L);
int w_getBits(lua_State *L);
int w_getSampleRate(lua_State *L);
int w_setSample(lua_State *L);
int w_getSample(lua_State *L);
extern "C" int luaopen_sounddata(lua_State *L);
} // sound
} // love
#endif // LOVE_SOUND_WRAP_SOUND_DATA_H
/**
* Copyright (c) 2006-2012 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_WRAP_SOUND_DATA_H
#define LOVE_SOUND_WRAP_SOUND_DATA_H
// LOVE
#include "common/runtime.h"
#include "SoundData.h"
namespace love
{
namespace sound
{
SoundData *luax_checksounddata(lua_State *L, int idx);
int w_getPointer(lua_State *L);
int w_getSize(lua_State *L);
int w_getChannels(lua_State *L);
int w_getBits(lua_State *L);
int w_getSampleRate(lua_State *L);
int w_setSample(lua_State *L);
int w_getSample(lua_State *L);
extern "C" int luaopen_sounddata(lua_State *L);
} // sound
} // love
#endif // LOVE_SOUND_WRAP_SOUND_DATA_H