Renamed Decoder:getBits to Decoder:getBitDepth (see issue #636)

This commit is contained in:
Alex Szpakowski
2013-08-11 04:15:42 -03:00
parent daf50698b8
commit 66a773d2a7
20 changed files with 52 additions and 52 deletions
+6 -6
View File
@@ -544,15 +544,15 @@ void Source::setFloatv(float *dst, const float *src) const
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;
else if (channels == 1 && bits == 16)
else if (channels == 1 && bitDepth == 16)
return AL_FORMAT_MONO16;
else if (channels == 2 && bits == 8)
else if (channels == 2 && bitDepth == 8)
return AL_FORMAT_STEREO8;
else if (channels == 2 && bits == 16)
else if (channels == 2 && bitDepth == 16)
return AL_FORMAT_STEREO16;
else
return 0;
@@ -563,7 +563,7 @@ int Source::streamAtomic(ALuint buffer, love::sound::Decoder *d)
// Get more sound data.
int decoded = d->decode();
int fmt = getFormat(d->getChannels(), d->getBits());
int fmt = getFormat(d->getChannels(), d->getBitDepth());
if (fmt != 0)
alBufferData(buffer, fmt, d->getBuffer(), decoded, d->getSampleRate());
+2 -2
View File
@@ -108,10 +108,10 @@ private:
* Gets the OpenAL format identifier based on number of
* channels and bits.
* @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.
**/
ALenum getFormat(int channels, int bits) const;
ALenum getFormat(int channels, int bitDepth) const;
int streamAtomic(ALuint buffer, love::sound::Decoder *d);
+2 -2
View File
@@ -55,7 +55,7 @@ public:
/**
* 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
@@ -126,7 +126,7 @@ public:
* 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;
virtual int getBitDepth() const = 0;
/**
* Gets the sample rate for the Decoder, that is, samples per second.
+2 -2
View File
@@ -34,9 +34,9 @@ SoundData *Sound::newSoundData(Decoder *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);
}
+2 -2
View File
@@ -60,11 +60,11 @@ public:
* 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 bitDepth 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);
SoundData *newSoundData(int samples, int sampleRate, int bitDepth, int channels);
/**
* Attempts to find a decoder for the encoded sound data in the
+17 -17
View File
@@ -38,7 +38,7 @@ SoundData::SoundData(Decoder *decoder)
: data(0)
, size(0)
, sampleRate(Decoder::DEFAULT_SAMPLE_RATE)
, bits(0)
, bitDepth(0)
, channels(0)
{
size_t bufferSize = 524288;
@@ -79,19 +79,19 @@ SoundData::SoundData(Decoder *decoder)
data = (char *) realloc(data, size);
channels = decoder->getChannels();
bits = decoder->getBits();
bitDepth = decoder->getBitDepth();
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)
, size(samples*(bits/8)*channels)
, size(samples*(bitDepth/8)*channels)
, sampleRate(sampleRate)
, bits(bits)
, bitDepth(bitDepth)
, channels(channels)
{
double realsize = samples;
realsize *= (bits/8)*channels;
realsize *= (bitDepth/8)*channels;
if (realsize > INT_MAX)
throw love::Exception("Data is too big!");
data = (char *)malloc(size);
@@ -99,15 +99,15 @@ SoundData::SoundData(int samples, int sampleRate, int bits, int channels)
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)
, size(samples*(bits/8)*channels)
, size(samples*(bitDepth/8)*channels)
, sampleRate(sampleRate)
, bits(bits)
, bitDepth(bitDepth)
, channels(channels)
{
double realsize = samples;
realsize *= (bits/8)*channels;
realsize *= (bitDepth/8)*channels;
if (realsize > INT_MAX)
throw love::Exception("Data is too big!");
data = (char *)malloc(size);
@@ -139,7 +139,7 @@ int SoundData::getChannels() const
int SoundData::getBitDepth() const
{
return bits;
return bitDepth;
}
int SoundData::getSampleRate() const
@@ -149,21 +149,21 @@ int SoundData::getSampleRate() const
int SoundData::getSampleCount() const
{
return (size/channels)/(bits/8);
return (size/channels)/(bitDepth/8);
}
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)
{
// 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!");
if (bits == 16)
if (bitDepth == 16)
{
short *s = (short *)data;
s[i] = (short)(sample*(float)SHRT_MAX);
@@ -179,10 +179,10 @@ void SoundData::setSample(int i, float sample)
float SoundData::getSample(int i) const
{
// 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!");
if (bits == 16)
if (bitDepth == 16)
{
short *s = (short *)data;
return (float)s[i]/(float)SHRT_MAX;
+3 -3
View File
@@ -36,8 +36,8 @@ 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);
SoundData(int samples, int sampleRate, int bitDepth, int channels);
SoundData(void *d, int samples, int sampleRate, int bitDepth, int channels);
virtual ~SoundData();
@@ -61,7 +61,7 @@ private:
int size;
int sampleRate;
int bits;
int bitDepth;
int channels;
}; // SoundData
+2 -2
View File
@@ -41,7 +41,7 @@ FLACDecoder::FLACDecoder(Data *data, const std::string &ext, int nbufferSize)
process_until_end_of_metadata();
process_single();
seek(0);
bufferSize = 256 * getBits() * getChannels() * 2;
bufferSize = 256 * getBitDepth() * getChannels() * 2;
delete[](char *) buffer;
buffer = new char[bufferSize];
}
@@ -98,7 +98,7 @@ int FLACDecoder::getChannels() const
return get_channels();
}
int FLACDecoder::getBits() const
int FLACDecoder::getBitDepth() const
{
return get_bits_per_sample();
}
+1 -1
View File
@@ -50,7 +50,7 @@ public:
bool rewind();
bool isSeekable();
int getChannels() const;
int getBits() const;
int getBitDepth() const;
int getSampleRate() const;
//needed for FLAC
+1 -1
View File
@@ -137,7 +137,7 @@ int GmeDecoder::getChannels() const
return 2;
}
int GmeDecoder::getBits() const
int GmeDecoder::getBitDepth() const
{
return 16;
}
+1 -1
View File
@@ -55,7 +55,7 @@ public:
bool rewind();
bool isSeekable();
int getChannels() const;
int getBits() const;
int getBitDepth() const;
private:
Music_Emu *emu;
+1 -1
View File
@@ -137,7 +137,7 @@ int ModPlugDecoder::getChannels() const
return 2;
}
int ModPlugDecoder::getBits() const
int ModPlugDecoder::getBitDepth() const
{
return 16;
}
+1 -1
View File
@@ -50,7 +50,7 @@ public:
bool rewind();
bool isSeekable();
int getChannels() const;
int getBits() const;
int getBitDepth() const;
private:
+1 -1
View File
@@ -207,7 +207,7 @@ int Mpg123Decoder::getChannels() const
return channels;
}
int Mpg123Decoder::getBits() const
int Mpg123Decoder::getBitDepth() const
{
return 16;
}
+1 -1
View File
@@ -55,7 +55,7 @@ public:
bool rewind();
bool isSeekable();
int getChannels() const;
int getBits() const;
int getBitDepth() const;
private:
+2 -2
View File
@@ -188,7 +188,7 @@ int VorbisDecoder::decode()
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)
continue;
@@ -243,7 +243,7 @@ int VorbisDecoder::getChannels() const
return vorbisInfo->channels;
}
int VorbisDecoder::getBits() const
int VorbisDecoder::getBitDepth() const
{
return 16;
}
+1 -1
View File
@@ -59,7 +59,7 @@ public:
bool rewind();
bool isSeekable();
int getChannels() const;
int getBits() const;
int getBitDepth() const;
int getSampleRate() const;
private:
+3 -3
View File
@@ -37,10 +37,10 @@ int w_Decoder_getChannels(lua_State *L)
return 1;
}
int w_Decoder_getBits(lua_State *L)
int w_Decoder_getBitDepth(lua_State *L)
{
Decoder *t = luax_checkdecoder(L, 1);
lua_pushinteger(L, t->getBits());
lua_pushinteger(L, t->getBitDepth());
return 1;
}
@@ -54,7 +54,7 @@ int w_Decoder_getSampleRate(lua_State *L)
static const luaL_Reg functions[] =
{
{ "getChannels", w_Decoder_getChannels },
{ "getBits", w_Decoder_getBits },
{ "getBitDepth", w_Decoder_getBitDepth },
{ "getSampleRate", w_Decoder_getSampleRate },
{ 0, 0 }
};
+1 -1
View File
@@ -32,7 +32,7 @@ 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_getBitDepth(lua_State *L);
int w_Decoder_getSampleRate(lua_State *L);
extern "C" int luaopen_decoder(lua_State *L);
+2 -2
View File
@@ -38,12 +38,12 @@ int w_newSoundData(lua_State *L)
{
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 bitDepth = luaL_optint(L, 3, Decoder::DEFAULT_BIT_DEPTH);
int channels = luaL_optint(L, 4, Decoder::DEFAULT_CHANNELS);
try
{
t = instance->newSoundData(samples, sampleRate, bits, channels);
t = instance->newSoundData(samples, sampleRate, bitDepth, channels);
}
catch(love::Exception &e)
{