added an endianness check in VorbisDecoder.cpp

This commit is contained in:
bill@Ixion
2009-08-31 16:29:27 -05:00
parent d3d7d787e4
commit b8677cebd0
3 changed files with 145 additions and 128 deletions
+8
View File
@@ -35,6 +35,14 @@
# define LOVE_MACOS 1 # define LOVE_MACOS 1
#endif #endif
// Endianness.
#if defined(__i386__) || defined(__i386)
# define LOVE_LITTLE_ENDIAN 1
#endif
#if defined(__ppc__) || defined(__ppc)
# define LOVE_BIG_ENDIAN 1
#endif
// Warnings. // Warnings.
#ifndef _CRT_SECURE_NO_WARNINGS #ifndef _CRT_SECURE_NO_WARNINGS
# define _CRT_SECURE_NO_WARNINGS # define _CRT_SECURE_NO_WARNINGS
+9 -1
View File
@@ -21,6 +21,7 @@
#include "VorbisDecoder.h" #include "VorbisDecoder.h"
#include <string.h> #include <string.h>
#include <common/config.h>
#include <common/Exception.h> #include <common/Exception.h>
namespace love namespace love
@@ -133,6 +134,13 @@ namespace lullaby
vorbisCallbacks.read_func = vorbisRead; vorbisCallbacks.read_func = vorbisRead;
vorbisCallbacks.tell_func = vorbisTell; vorbisCallbacks.tell_func = vorbisTell;
// Check endianness
#ifdef LOVE_BIG_ENDIAN
endian = 1;
#else
endian = 0;
#endif
// Initialize OGG file // Initialize OGG file
oggFile.dataPtr = (char *) data->getData(); oggFile.dataPtr = (char *) data->getData();
oggFile.dataSize = data->getSize(); oggFile.dataSize = data->getSize();
@@ -186,7 +194,7 @@ namespace lullaby
while(size < bufferSize) while(size < bufferSize)
{ {
result = ov_read(&handle, (char*) buffer + size, bufferSize - size, 0, bits, 1, &section); result = ov_read(&handle, (char*) buffer + size, bufferSize - size, endian, bits, 1, &section);
if(result > 0) if(result > 0)
size += result; size += result;
@@ -51,6 +51,7 @@ namespace lullaby
OggVorbis_File handle; // Handle to the file OggVorbis_File handle; // Handle to the file
vorbis_info * vorbisInfo; // Info vorbis_info * vorbisInfo; // Info
vorbis_comment * vorbisComment; // Comments vorbis_comment * vorbisComment; // Comments
int endian; // Endianness
public: public: