mirror of
https://github.com/love2d/love.git
synced 2026-08-19 12:14:20 +02:00
Renamed Decoder:getBits to Decoder:getBitDepth (see issue #636)
This commit is contained in:
@@ -544,15 +544,15 @@ void Source::setFloatv(float *dst, const float *src) const
|
|||||||
dst[2] = src[2];
|
dst[2] = src[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
ALenum Source::getFormat(int channels, int bits) const
|
ALenum Source::getFormat(int channels, int bitDepth) const
|
||||||
{
|
{
|
||||||
if (channels == 1 && bits == 8)
|
if (channels == 1 && bitDepth == 8)
|
||||||
return AL_FORMAT_MONO8;
|
return AL_FORMAT_MONO8;
|
||||||
else if (channels == 1 && bits == 16)
|
else if (channels == 1 && bitDepth == 16)
|
||||||
return AL_FORMAT_MONO16;
|
return AL_FORMAT_MONO16;
|
||||||
else if (channels == 2 && bits == 8)
|
else if (channels == 2 && bitDepth == 8)
|
||||||
return AL_FORMAT_STEREO8;
|
return AL_FORMAT_STEREO8;
|
||||||
else if (channels == 2 && bits == 16)
|
else if (channels == 2 && bitDepth == 16)
|
||||||
return AL_FORMAT_STEREO16;
|
return AL_FORMAT_STEREO16;
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
@@ -563,7 +563,7 @@ int Source::streamAtomic(ALuint buffer, love::sound::Decoder *d)
|
|||||||
// Get more sound data.
|
// Get more sound data.
|
||||||
int decoded = d->decode();
|
int decoded = d->decode();
|
||||||
|
|
||||||
int fmt = getFormat(d->getChannels(), d->getBits());
|
int fmt = getFormat(d->getChannels(), d->getBitDepth());
|
||||||
|
|
||||||
if (fmt != 0)
|
if (fmt != 0)
|
||||||
alBufferData(buffer, fmt, d->getBuffer(), decoded, d->getSampleRate());
|
alBufferData(buffer, fmt, d->getBuffer(), decoded, d->getSampleRate());
|
||||||
|
|||||||
@@ -108,10 +108,10 @@ private:
|
|||||||
* Gets the OpenAL format identifier based on number of
|
* Gets the OpenAL format identifier based on number of
|
||||||
* channels and bits.
|
* channels and bits.
|
||||||
* @param channels Either 1 (mono) or 2 (stereo).
|
* @param channels Either 1 (mono) or 2 (stereo).
|
||||||
* @param bits Either 8-bit samples, or 16-bit samples.
|
* @param bitDepth Either 8-bit samples, or 16-bit samples.
|
||||||
* @return One of AL_FORMAT_*, or 0 if unsupported format.
|
* @return One of AL_FORMAT_*, or 0 if unsupported format.
|
||||||
**/
|
**/
|
||||||
ALenum getFormat(int channels, int bits) const;
|
ALenum getFormat(int channels, int bitDepth) const;
|
||||||
|
|
||||||
int streamAtomic(ALuint buffer, love::sound::Decoder *d);
|
int streamAtomic(ALuint buffer, love::sound::Decoder *d);
|
||||||
|
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* 16 bit audio is the default.
|
* 16 bit audio is the default.
|
||||||
**/
|
**/
|
||||||
static const int DEFAULT_BITS = 16;
|
static const int DEFAULT_BIT_DEPTH = 16;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a deep of itself. The sound stream can (and should) be
|
* Creates a deep of itself. The sound stream can (and should) be
|
||||||
@@ -126,7 +126,7 @@ public:
|
|||||||
* Gets the number of bits per sample. Supported values are 8 or 16.
|
* Gets the number of bits per sample. Supported values are 8 or 16.
|
||||||
* @return Either 8, 16, or 0 if unsupported.
|
* @return Either 8, 16, or 0 if unsupported.
|
||||||
**/
|
**/
|
||||||
virtual int getBits() const = 0;
|
virtual int getBitDepth() const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the sample rate for the Decoder, that is, samples per second.
|
* Gets the sample rate for the Decoder, that is, samples per second.
|
||||||
|
|||||||
@@ -34,9 +34,9 @@ SoundData *Sound::newSoundData(Decoder *decoder)
|
|||||||
return new SoundData(decoder);
|
return new SoundData(decoder);
|
||||||
}
|
}
|
||||||
|
|
||||||
SoundData *Sound::newSoundData(int samples, int sampleRate, int bits, int channels)
|
SoundData *Sound::newSoundData(int samples, int sampleRate, int bitDepth, int channels)
|
||||||
{
|
{
|
||||||
return new SoundData(samples, sampleRate, bits, channels);
|
return new SoundData(samples, sampleRate, bitDepth, channels);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -60,11 +60,11 @@ public:
|
|||||||
* Creates a new SoundData with the specified number of samples and format.
|
* Creates a new SoundData with the specified number of samples and format.
|
||||||
* @param duration In seconds.
|
* @param duration In seconds.
|
||||||
* @param sampleRate Number of samples per second.
|
* @param sampleRate Number of samples per second.
|
||||||
* @param bits Bits per sample (8 or 16).
|
* @param bitDepth Bits per sample (8 or 16).
|
||||||
* @param channels Either 1 for mono, or 2 for stereo.
|
* @param channels Either 1 for mono, or 2 for stereo.
|
||||||
* @return A new SoundData object, or zero in case of errors.
|
* @return A new SoundData object, or zero in case of errors.
|
||||||
**/
|
**/
|
||||||
SoundData *newSoundData(int samples, int sampleRate, int bits, int channels);
|
SoundData *newSoundData(int samples, int sampleRate, int bitDepth, int channels);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempts to find a decoder for the encoded sound data in the
|
* Attempts to find a decoder for the encoded sound data in the
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ SoundData::SoundData(Decoder *decoder)
|
|||||||
: data(0)
|
: data(0)
|
||||||
, size(0)
|
, size(0)
|
||||||
, sampleRate(Decoder::DEFAULT_SAMPLE_RATE)
|
, sampleRate(Decoder::DEFAULT_SAMPLE_RATE)
|
||||||
, bits(0)
|
, bitDepth(0)
|
||||||
, channels(0)
|
, channels(0)
|
||||||
{
|
{
|
||||||
size_t bufferSize = 524288;
|
size_t bufferSize = 524288;
|
||||||
@@ -79,19 +79,19 @@ SoundData::SoundData(Decoder *decoder)
|
|||||||
data = (char *) realloc(data, size);
|
data = (char *) realloc(data, size);
|
||||||
|
|
||||||
channels = decoder->getChannels();
|
channels = decoder->getChannels();
|
||||||
bits = decoder->getBits();
|
bitDepth = decoder->getBitDepth();
|
||||||
sampleRate = decoder->getSampleRate();
|
sampleRate = decoder->getSampleRate();
|
||||||
}
|
}
|
||||||
|
|
||||||
SoundData::SoundData(int samples, int sampleRate, int bits, int channels)
|
SoundData::SoundData(int samples, int sampleRate, int bitDepth, int channels)
|
||||||
: data(0)
|
: data(0)
|
||||||
, size(samples*(bits/8)*channels)
|
, size(samples*(bitDepth/8)*channels)
|
||||||
, sampleRate(sampleRate)
|
, sampleRate(sampleRate)
|
||||||
, bits(bits)
|
, bitDepth(bitDepth)
|
||||||
, channels(channels)
|
, channels(channels)
|
||||||
{
|
{
|
||||||
double realsize = samples;
|
double realsize = samples;
|
||||||
realsize *= (bits/8)*channels;
|
realsize *= (bitDepth/8)*channels;
|
||||||
if (realsize > INT_MAX)
|
if (realsize > INT_MAX)
|
||||||
throw love::Exception("Data is too big!");
|
throw love::Exception("Data is too big!");
|
||||||
data = (char *)malloc(size);
|
data = (char *)malloc(size);
|
||||||
@@ -99,15 +99,15 @@ SoundData::SoundData(int samples, int sampleRate, int bits, int channels)
|
|||||||
throw love::Exception("Not enough memory.");
|
throw love::Exception("Not enough memory.");
|
||||||
}
|
}
|
||||||
|
|
||||||
SoundData::SoundData(void *d, int samples, int sampleRate, int bits, int channels)
|
SoundData::SoundData(void *d, int samples, int sampleRate, int bitDepth, int channels)
|
||||||
: data(0)
|
: data(0)
|
||||||
, size(samples*(bits/8)*channels)
|
, size(samples*(bitDepth/8)*channels)
|
||||||
, sampleRate(sampleRate)
|
, sampleRate(sampleRate)
|
||||||
, bits(bits)
|
, bitDepth(bitDepth)
|
||||||
, channels(channels)
|
, channels(channels)
|
||||||
{
|
{
|
||||||
double realsize = samples;
|
double realsize = samples;
|
||||||
realsize *= (bits/8)*channels;
|
realsize *= (bitDepth/8)*channels;
|
||||||
if (realsize > INT_MAX)
|
if (realsize > INT_MAX)
|
||||||
throw love::Exception("Data is too big!");
|
throw love::Exception("Data is too big!");
|
||||||
data = (char *)malloc(size);
|
data = (char *)malloc(size);
|
||||||
@@ -139,7 +139,7 @@ int SoundData::getChannels() const
|
|||||||
|
|
||||||
int SoundData::getBitDepth() const
|
int SoundData::getBitDepth() const
|
||||||
{
|
{
|
||||||
return bits;
|
return bitDepth;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SoundData::getSampleRate() const
|
int SoundData::getSampleRate() const
|
||||||
@@ -149,21 +149,21 @@ int SoundData::getSampleRate() const
|
|||||||
|
|
||||||
int SoundData::getSampleCount() const
|
int SoundData::getSampleCount() const
|
||||||
{
|
{
|
||||||
return (size/channels)/(bits/8);
|
return (size/channels)/(bitDepth/8);
|
||||||
}
|
}
|
||||||
|
|
||||||
float SoundData::getDuration() const
|
float SoundData::getDuration() const
|
||||||
{
|
{
|
||||||
return float(size) / (channels*sampleRate*bits/8);
|
return float(size) / (channels*sampleRate*bitDepth/8);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundData::setSample(int i, float sample)
|
void SoundData::setSample(int i, float sample)
|
||||||
{
|
{
|
||||||
// Check range.
|
// Check range.
|
||||||
if (i < 0 || i >= size/(bits/8))
|
if (i < 0 || i >= size/(bitDepth/8))
|
||||||
throw love::Exception("Attempt to set out-of-range sample!");
|
throw love::Exception("Attempt to set out-of-range sample!");
|
||||||
|
|
||||||
if (bits == 16)
|
if (bitDepth == 16)
|
||||||
{
|
{
|
||||||
short *s = (short *)data;
|
short *s = (short *)data;
|
||||||
s[i] = (short)(sample*(float)SHRT_MAX);
|
s[i] = (short)(sample*(float)SHRT_MAX);
|
||||||
@@ -179,10 +179,10 @@ void SoundData::setSample(int i, float sample)
|
|||||||
float SoundData::getSample(int i) const
|
float SoundData::getSample(int i) const
|
||||||
{
|
{
|
||||||
// Check range.
|
// Check range.
|
||||||
if (i < 0 || i >= size/(bits/8))
|
if (i < 0 || i >= size/(bitDepth/8))
|
||||||
throw love::Exception("Attempt to get out-of-range sample!");
|
throw love::Exception("Attempt to get out-of-range sample!");
|
||||||
|
|
||||||
if (bits == 16)
|
if (bitDepth == 16)
|
||||||
{
|
{
|
||||||
short *s = (short *)data;
|
short *s = (short *)data;
|
||||||
return (float)s[i]/(float)SHRT_MAX;
|
return (float)s[i]/(float)SHRT_MAX;
|
||||||
|
|||||||
@@ -36,8 +36,8 @@ class SoundData : public love::Data
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
SoundData(Decoder *decoder);
|
SoundData(Decoder *decoder);
|
||||||
SoundData(int samples, int sampleRate, int bits, int channels);
|
SoundData(int samples, int sampleRate, int bitDepth, int channels);
|
||||||
SoundData(void *d, int samples, int sampleRate, int bits, int channels);
|
SoundData(void *d, int samples, int sampleRate, int bitDepth, int channels);
|
||||||
|
|
||||||
virtual ~SoundData();
|
virtual ~SoundData();
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ private:
|
|||||||
int size;
|
int size;
|
||||||
|
|
||||||
int sampleRate;
|
int sampleRate;
|
||||||
int bits;
|
int bitDepth;
|
||||||
int channels;
|
int channels;
|
||||||
}; // SoundData
|
}; // SoundData
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ FLACDecoder::FLACDecoder(Data *data, const std::string &ext, int nbufferSize)
|
|||||||
process_until_end_of_metadata();
|
process_until_end_of_metadata();
|
||||||
process_single();
|
process_single();
|
||||||
seek(0);
|
seek(0);
|
||||||
bufferSize = 256 * getBits() * getChannels() * 2;
|
bufferSize = 256 * getBitDepth() * getChannels() * 2;
|
||||||
delete[](char *) buffer;
|
delete[](char *) buffer;
|
||||||
buffer = new char[bufferSize];
|
buffer = new char[bufferSize];
|
||||||
}
|
}
|
||||||
@@ -98,7 +98,7 @@ int FLACDecoder::getChannels() const
|
|||||||
return get_channels();
|
return get_channels();
|
||||||
}
|
}
|
||||||
|
|
||||||
int FLACDecoder::getBits() const
|
int FLACDecoder::getBitDepth() const
|
||||||
{
|
{
|
||||||
return get_bits_per_sample();
|
return get_bits_per_sample();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public:
|
|||||||
bool rewind();
|
bool rewind();
|
||||||
bool isSeekable();
|
bool isSeekable();
|
||||||
int getChannels() const;
|
int getChannels() const;
|
||||||
int getBits() const;
|
int getBitDepth() const;
|
||||||
int getSampleRate() const;
|
int getSampleRate() const;
|
||||||
|
|
||||||
//needed for FLAC
|
//needed for FLAC
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ int GmeDecoder::getChannels() const
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GmeDecoder::getBits() const
|
int GmeDecoder::getBitDepth() const
|
||||||
{
|
{
|
||||||
return 16;
|
return 16;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ public:
|
|||||||
bool rewind();
|
bool rewind();
|
||||||
bool isSeekable();
|
bool isSeekable();
|
||||||
int getChannels() const;
|
int getChannels() const;
|
||||||
int getBits() const;
|
int getBitDepth() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Music_Emu *emu;
|
Music_Emu *emu;
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ int ModPlugDecoder::getChannels() const
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ModPlugDecoder::getBits() const
|
int ModPlugDecoder::getBitDepth() const
|
||||||
{
|
{
|
||||||
return 16;
|
return 16;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public:
|
|||||||
bool rewind();
|
bool rewind();
|
||||||
bool isSeekable();
|
bool isSeekable();
|
||||||
int getChannels() const;
|
int getChannels() const;
|
||||||
int getBits() const;
|
int getBitDepth() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|||||||
@@ -207,7 +207,7 @@ int Mpg123Decoder::getChannels() const
|
|||||||
return channels;
|
return channels;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Mpg123Decoder::getBits() const
|
int Mpg123Decoder::getBitDepth() const
|
||||||
{
|
{
|
||||||
return 16;
|
return 16;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ public:
|
|||||||
bool rewind();
|
bool rewind();
|
||||||
bool isSeekable();
|
bool isSeekable();
|
||||||
int getChannels() const;
|
int getChannels() const;
|
||||||
int getBits() const;
|
int getBitDepth() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|||||||
@@ -188,7 +188,7 @@ int VorbisDecoder::decode()
|
|||||||
|
|
||||||
while (size < bufferSize)
|
while (size < bufferSize)
|
||||||
{
|
{
|
||||||
int result = ov_read(&handle, (char *) buffer + size, bufferSize - size, endian, (getBits() == 16 ? 2 : 1), 1, 0);
|
int result = ov_read(&handle, (char *) buffer + size, bufferSize - size, endian, (getBitDepth() == 16 ? 2 : 1), 1, 0);
|
||||||
|
|
||||||
if (result == OV_HOLE)
|
if (result == OV_HOLE)
|
||||||
continue;
|
continue;
|
||||||
@@ -243,7 +243,7 @@ int VorbisDecoder::getChannels() const
|
|||||||
return vorbisInfo->channels;
|
return vorbisInfo->channels;
|
||||||
}
|
}
|
||||||
|
|
||||||
int VorbisDecoder::getBits() const
|
int VorbisDecoder::getBitDepth() const
|
||||||
{
|
{
|
||||||
return 16;
|
return 16;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ public:
|
|||||||
bool rewind();
|
bool rewind();
|
||||||
bool isSeekable();
|
bool isSeekable();
|
||||||
int getChannels() const;
|
int getChannels() const;
|
||||||
int getBits() const;
|
int getBitDepth() const;
|
||||||
int getSampleRate() const;
|
int getSampleRate() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -37,10 +37,10 @@ int w_Decoder_getChannels(lua_State *L)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int w_Decoder_getBits(lua_State *L)
|
int w_Decoder_getBitDepth(lua_State *L)
|
||||||
{
|
{
|
||||||
Decoder *t = luax_checkdecoder(L, 1);
|
Decoder *t = luax_checkdecoder(L, 1);
|
||||||
lua_pushinteger(L, t->getBits());
|
lua_pushinteger(L, t->getBitDepth());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ int w_Decoder_getSampleRate(lua_State *L)
|
|||||||
static const luaL_Reg functions[] =
|
static const luaL_Reg functions[] =
|
||||||
{
|
{
|
||||||
{ "getChannels", w_Decoder_getChannels },
|
{ "getChannels", w_Decoder_getChannels },
|
||||||
{ "getBits", w_Decoder_getBits },
|
{ "getBitDepth", w_Decoder_getBitDepth },
|
||||||
{ "getSampleRate", w_Decoder_getSampleRate },
|
{ "getSampleRate", w_Decoder_getSampleRate },
|
||||||
{ 0, 0 }
|
{ 0, 0 }
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ namespace sound
|
|||||||
|
|
||||||
Decoder *luax_checkdecoder(lua_State *L, int idx);
|
Decoder *luax_checkdecoder(lua_State *L, int idx);
|
||||||
int w_Decoder_getChannels(lua_State *L);
|
int w_Decoder_getChannels(lua_State *L);
|
||||||
int w_Decoder_getBits(lua_State *L);
|
int w_Decoder_getBitDepth(lua_State *L);
|
||||||
int w_Decoder_getSampleRate(lua_State *L);
|
int w_Decoder_getSampleRate(lua_State *L);
|
||||||
extern "C" int luaopen_decoder(lua_State *L);
|
extern "C" int luaopen_decoder(lua_State *L);
|
||||||
|
|
||||||
|
|||||||
@@ -38,12 +38,12 @@ int w_newSoundData(lua_State *L)
|
|||||||
{
|
{
|
||||||
int samples = luaL_checkint(L, 1);
|
int samples = luaL_checkint(L, 1);
|
||||||
int sampleRate = luaL_optint(L, 2, Decoder::DEFAULT_SAMPLE_RATE);
|
int sampleRate = luaL_optint(L, 2, Decoder::DEFAULT_SAMPLE_RATE);
|
||||||
int bits = luaL_optint(L, 3, Decoder::DEFAULT_BITS);
|
int bitDepth = luaL_optint(L, 3, Decoder::DEFAULT_BIT_DEPTH);
|
||||||
int channels = luaL_optint(L, 4, Decoder::DEFAULT_CHANNELS);
|
int channels = luaL_optint(L, 4, Decoder::DEFAULT_CHANNELS);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
t = instance->newSoundData(samples, sampleRate, bits, channels);
|
t = instance->newSoundData(samples, sampleRate, bitDepth, channels);
|
||||||
}
|
}
|
||||||
catch(love::Exception &e)
|
catch(love::Exception &e)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user