Use a FileReader to handle music resources and audio decoding

Instead of the previous method where there'd be a filename and offset, and/or a
memory pointer, this uses a class to access resource data regardless of its
underlying form.
This commit is contained in:
Chris Robinson 2014-06-25 04:25:36 -07:00
commit 0017e1e6e8
29 changed files with 554 additions and 853 deletions

View file

@ -26,6 +26,7 @@
#include <io.h>
#endif
#include <fcntl.h>
#include <memory>
#include "i_system.h"
#include "i_sound.h"
@ -2435,7 +2436,7 @@ bool S_ChangeMusic (const char *musicname, int order, bool looping, bool force)
else
{
int lumpnum = -1;
int offset = 0, length = 0;
int length = 0;
int device = MDEV_DEFAULT;
MusInfo *handle = NULL;
FName musicasname = musicname;
@ -2456,6 +2457,7 @@ bool S_ChangeMusic (const char *musicname, int order, bool looping, bool force)
musicname += 7;
}
std::auto_ptr<FileReader> reader;
if (!FileExists (musicname))
{
if ((lumpnum = Wads.CheckNumForFullName (musicname, true, ns_music)) == -1)
@ -2485,8 +2487,6 @@ bool S_ChangeMusic (const char *musicname, int order, bool looping, bool force)
// shut down old music before reallocating and overwriting the cache!
S_StopMusic (true);
offset = -1; // this tells the low level code that the music
// is being used from memory
length = Wads.LumpLength (lumpnum);
if (length == 0)
{
@ -2494,15 +2494,16 @@ bool S_ChangeMusic (const char *musicname, int order, bool looping, bool force)
}
musiccache.Resize(length);
Wads.ReadLump(lumpnum, &musiccache[0]);
reader.reset(new MemoryReader((const char*)&musiccache[0], musiccache.Size()));
}
else
{
offset = Wads.GetLumpOffset (lumpnum);
length = Wads.LumpLength (lumpnum);
if (length == 0)
if (Wads.LumpLength (lumpnum) == 0)
{
return false;
}
reader.reset(Wads.ReopenLumpNum(lumpnum));
}
}
}
@ -2525,15 +2526,9 @@ bool S_ChangeMusic (const char *musicname, int order, bool looping, bool force)
{
mus_playing.handle = handle;
}
else if (offset != -1)
{
mus_playing.handle = I_RegisterSong (lumpnum != -1 ?
Wads.GetWadFullName (Wads.GetLumpFile (lumpnum)) :
musicname, NULL, offset, length, device);
}
else
{
mus_playing.handle = I_RegisterSong (NULL, &musiccache[0], -1, length, device);
mus_playing.handle = I_RegisterSong (reader, device);
}
}