Using latest love-android branch (e263d91d136d)

This commit is contained in:
fysx
2014-04-04 11:37:36 +02:00
parent 8acfb8d91a
commit e96eef4435
87 changed files with 1070 additions and 397 deletions
+1 -1
View File
@@ -67,7 +67,7 @@ public:
/**
* Destructor. Should free internal buffer.
**/
virtual ~Decoder() {};
virtual ~Decoder() {}
/**
* Decodes the next chunk of the music stream, this will usually be
+29 -25
View File
@@ -21,11 +21,11 @@
#include "SoundData.h"
// C
#include <climits>
#include <cstdlib>
#include <cstring>
// STL
// C++
#include <limits>
#include <iostream>
#include <vector>
@@ -48,11 +48,11 @@ SoundData::SoundData(Decoder *decoder)
{
// Expand or allocate buffer. Note that realloc may move
// memory to other locations.
if (!data || bufferSize < (size_t) size + decoded)
if (!data || bufferSize < size + decoded)
{
while (bufferSize < (size_t) size + decoded)
while (bufferSize < size + decoded)
bufferSize <<= 1;
data = (char *)realloc(data, bufferSize);
data = (uint8 *) realloc(data, bufferSize);
}
if (!data)
@@ -61,22 +61,22 @@ SoundData::SoundData(Decoder *decoder)
// 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)
if (size > std::numeric_limits<size_t>::max() - decoded)
{
free(data);
throw love::Exception("Not enough memory.");
}
// Keep this up to date.
size += decoded;
decoded = decoder->decode();
}
// Shrink buffer if necessary.
if (data && bufferSize > (size_t) size)
data = (char *) realloc(data, size);
if (data && bufferSize > size)
data = (uint8 *) realloc(data, size);
channels = decoder->getChannels();
bitDepth = decoder->getBitDepth();
@@ -136,15 +136,17 @@ void SoundData::load(int samples, int sampleRate, int bitDepth, int channels, vo
double realsize = samples;
realsize *= (bitDepth / 8) * channels;
if (realsize > INT_MAX)
if (realsize > std::numeric_limits<size_t>::max())
throw love::Exception("Data is too big!");
data = (char *)malloc(size);
data = (uint8 *) malloc(size);
if (!data)
throw love::Exception("Not enough memory.");
if (newData)
memcpy(data, newData, size);
else
memset(data, bitDepth == 8 ? 128 : 0, size);
}
void *SoundData::getData() const
@@ -152,9 +154,9 @@ void *SoundData::getData() const
return (void *)data;
}
int SoundData::getSize() const
size_t SoundData::getSize() const
{
return (int)size;
return size;
}
int SoundData::getChannels() const
@@ -185,36 +187,38 @@ float SoundData::getDuration() const
void SoundData::setSample(int i, float sample)
{
// Check range.
if (i < 0 || i >= size/(bitDepth/8))
if (i < 0 || (size_t) i >= size/(bitDepth/8))
throw love::Exception("Attempt to set out-of-range sample!");
if (bitDepth == 16)
{
short *s = (short *)data;
s[i] = (short)(sample*(float)SHRT_MAX);
return;
// 16-bit sample values are signed.
int16 *s = (int16 *) data;
s[i] = (int16) (sample * (float) LOVE_INT16_MAX);
}
else
{
data[i] = (char)(sample*(float)CHAR_MAX);
return;
// 8-bit sample values are unsigned internally.
data[i] = (uint8) ((sample * 127.0f) + 128.0f);
}
}
float SoundData::getSample(int i) const
{
// Check range.
if (i < 0 || i >= size/(bitDepth/8))
if (i < 0 || (size_t) i >= size/(bitDepth/8))
throw love::Exception("Attempt to get out-of-range sample!");
if (bitDepth == 16)
{
short *s = (short *)data;
return (float)s[i]/(float)SHRT_MAX;
// 16-bit sample values are signed.
int16 *s = (int16 *) data;
return (float) s[i] / (float) LOVE_INT16_MAX;
}
else
{
return (float)data[i]/(float)CHAR_MAX;
// 8-bit sample values are unsigned internally.
return ((float) data[i] - 128.0f) / 127.0f;
}
}
+5 -4
View File
@@ -23,7 +23,7 @@
// LOVE
#include "filesystem/File.h"
#include "common/int.h"
#include "Decoder.h"
namespace love
@@ -43,7 +43,7 @@ public:
// Implements Data.
void *getData() const;
int getSize() const;
size_t getSize() const;
virtual int getChannels() const;
virtual int getBitDepth() const;
@@ -59,12 +59,13 @@ private:
void load(int samples, int sampleRate, int bitDepth, int channels, void *newData = 0);
char *data;
int size;
uint8 *data;
size_t size;
int sampleRate;
int bitDepth;
int channels;
}; // SoundData
} // sound
@@ -183,4 +183,4 @@ void FLACDecoder::error_callback(FLAC__StreamDecoderErrorStatus status)
} // sound
} // love
#endif // 0
#endif // 0
@@ -146,4 +146,4 @@ int GmeDecoder::getBitDepth() const
} // sound
} // love
#endif // LOVE_SUPPORT_GME
#endif // LOVE_SUPPORT_GME