mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-06-07 17:11:56 +00:00
attempt to fix sounds from zip files not loading properly
This commit is contained in:
parent
43a4f60ab1
commit
af1b831c85
1 changed files with 12 additions and 16 deletions
|
@ -630,7 +630,7 @@ class OpenALSound
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
OpenALSound(VFILE *_fp, const bool _looping); // ctor for ogg streamed from file
|
OpenALSound(VFILE *_fp, const bool _looping); // ctor for ogg streamed from file
|
||||||
OpenALSound(void *_data, long _size, const bool _looping); // ctor for ogg streamed from memory
|
OpenALSound(void *_data, size_t _size, const bool _looping); // ctor for ogg streamed from memory
|
||||||
OpenALSound(ALuint _bid, const bool _looping); // ctor for raw samples already assigned an opanAL buffer ID
|
OpenALSound(ALuint _bid, const bool _looping); // ctor for raw samples already assigned an opanAL buffer ID
|
||||||
VFILE *getFile() const { return fp; }
|
VFILE *getFile() const { return fp; }
|
||||||
const void *getData() const { return data; }
|
const void *getData() const { return data; }
|
||||||
|
@ -647,7 +647,7 @@ public:
|
||||||
private:
|
private:
|
||||||
VFILE * const fp;
|
VFILE * const fp;
|
||||||
void * const data; // Only used if fp==NULL
|
void * const data; // Only used if fp==NULL
|
||||||
const long size; // Only used if fp==NULL
|
const size_t size; // Only used if fp==NULL
|
||||||
const bool looping;
|
const bool looping;
|
||||||
int refcount;
|
int refcount;
|
||||||
const bool raw; // true if buffer holds raw PCM data
|
const bool raw; // true if buffer holds raw PCM data
|
||||||
|
@ -667,7 +667,7 @@ OpenALSound::OpenALSound(VFILE *_fp, const bool _looping)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
OpenALSound::OpenALSound(void *_data, long _size, const bool _looping)
|
OpenALSound::OpenALSound(void *_data, size_t _size, const bool _looping)
|
||||||
: fp(NULL)
|
: fp(NULL)
|
||||||
, data(_data)
|
, data(_data)
|
||||||
, size(_size)
|
, size(_size)
|
||||||
|
@ -1436,6 +1436,11 @@ FMOD_RESULT OpenALSystem::createSound(const char *name_or_data, const FMOD_MODE
|
||||||
VFILE *io = vfopen(core->adjustFilenameCase(fname).c_str(), "rb");
|
VFILE *io = vfopen(core->adjustFilenameCase(fname).c_str(), "rb");
|
||||||
if (io == NULL)
|
if (io == NULL)
|
||||||
return FMOD_ERR_INTERNAL;
|
return FMOD_ERR_INTERNAL;
|
||||||
|
size_t filesize = 0;
|
||||||
|
if(vfsize(io, &filesize))
|
||||||
|
return FMOD_ERR_INTERNAL;
|
||||||
|
if(!filesize)
|
||||||
|
return FMOD_ERR_INTERNAL;
|
||||||
|
|
||||||
if (mode & FMOD_CREATESTREAM)
|
if (mode & FMOD_CREATESTREAM)
|
||||||
{
|
{
|
||||||
|
@ -1468,16 +1473,7 @@ FMOD_RESULT OpenALSystem::createSound(const char *name_or_data, const FMOD_MODE
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Create streaming memory decoder
|
// Create streaming memory decoder
|
||||||
vfseek(io, 0, SEEK_END);
|
void *data = malloc(filesize);
|
||||||
long size = vftell(io);
|
|
||||||
if (vfseek(io, 0, SEEK_SET) != 0)
|
|
||||||
{
|
|
||||||
debugLog("Seek error on " + std::string(fname));
|
|
||||||
vfclose(io);
|
|
||||||
return FMOD_ERR_INTERNAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *data = malloc(size);
|
|
||||||
if (data == NULL)
|
if (data == NULL)
|
||||||
{
|
{
|
||||||
debugLog("Out of memory for " + std::string(fname));
|
debugLog("Out of memory for " + std::string(fname));
|
||||||
|
@ -1485,16 +1481,16 @@ FMOD_RESULT OpenALSystem::createSound(const char *name_or_data, const FMOD_MODE
|
||||||
return FMOD_ERR_INTERNAL;
|
return FMOD_ERR_INTERNAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
long nread = vfread(data, 1, size, io);
|
size_t nread = vfread(data, 1, filesize, io);
|
||||||
vfclose(io);
|
vfclose(io);
|
||||||
if (nread != size)
|
if (nread != filesize)
|
||||||
{
|
{
|
||||||
debugLog("Failed to read data from " + std::string(fname));
|
debugLog("Failed to read data from " + std::string(fname));
|
||||||
free(data);
|
free(data);
|
||||||
return FMOD_ERR_INTERNAL;
|
return FMOD_ERR_INTERNAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
*sound = (Sound *) new OpenALSound(data, size, (((mode & FMOD_LOOP_OFF) == 0) && (mode & FMOD_LOOP_NORMAL)));
|
*sound = (Sound *) new OpenALSound(data, filesize, (((mode & FMOD_LOOP_OFF) == 0) && (mode & FMOD_LOOP_NORMAL)));
|
||||||
retval = FMOD_OK;
|
retval = FMOD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue