From fa6bbdf47d8d69bddb32158293b0542974f1a6ec Mon Sep 17 00:00:00 2001 From: eraserxl Date: Wed, 15 Sep 2010 00:51:15 +0000 Subject: [PATCH] *[libwiigui] Minor adjustment of the ogg sound decoder to be capable of reading files into memory on its own. *Replaced libtremor with libvorbisidec --- HBC/META.XML | 4 +- Makefile | 2 +- source/libwiigui/gui_sound_decoder_ogg.cpp | 211 ++++++++++++++++++++- 3 files changed, 213 insertions(+), 4 deletions(-) diff --git a/HBC/META.XML b/HBC/META.XML index 81f15459..99441df4 100644 --- a/HBC/META.XML +++ b/HBC/META.XML @@ -2,8 +2,8 @@ USB Loader GX USB Loader GX Team - 1.0 r938 - 201007040019 + 1.0 r939 + 201009110014 Loads games from USB-devices USB Loader GX is a libwiigui based USB iso loader with a wii-like GUI. You can install games to your HDDs and boot them with shorter loading times. The interactive GUI is completely controllable with WiiMote, Classic Controller or GC Controller. diff --git a/Makefile b/Makefile index 263d9178..b060e306 100644 --- a/Makefile +++ b/Makefile @@ -64,7 +64,7 @@ LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map,--section-start,.init=0x80B00 #--------------------------------------------------------------------------------- # any extra libraries we wish to link with the project #--------------------------------------------------------------------------------- -LIBS := -lpngu -lpng -lm -lz -lwiiuse -lbte -lasnd -logc -lfreetype -ltremor -lmad -lmxml -ljpeg +LIBS := -lpngu -lpng -lm -lz -lwiiuse -lbte -lasnd -logc -lfreetype -lvorbisidec -lmad -lmxml -ljpeg #--------------------------------------------------------------------------------- # list of directories containing libraries, this must be the top level containing # include and lib diff --git a/source/libwiigui/gui_sound_decoder_ogg.cpp b/source/libwiigui/gui_sound_decoder_ogg.cpp index 94b6ce7b..de1920a8 100644 --- a/source/libwiigui/gui_sound_decoder_ogg.cpp +++ b/source/libwiigui/gui_sound_decoder_ogg.cpp @@ -16,9 +16,218 @@ #include #include #include +#include #include "gui_sound_decoder.h" +/* functions to read the Ogg file from memory */ + +static struct +{ + char *mem; + int size; + int pos; +} file[4]; + +static int f_read(void * punt, int bytes, int blocks, int *f) +{ + int b; + int c = 0; + int d; + + if (bytes * blocks <= 0) + return 0; + + blocks *= bytes; + + while (blocks > 0) + { + b = blocks; + if (b > 4096) + b = 4096; + + d = (*f) - 0x666; + if((unsigned)(d) <= (0x669 - 0x666)) + { + if (file[d].size == 0) + return -1; + if ((file[d].pos + b) > file[d].size) + b = file[d].size - file[d].pos; + if (b > 0) + { + memcpy(punt, file[d].mem + file[d].pos, b); + file[d].pos += b; + } + } + else + b = read(*f, ((char *) punt) + c, b); + + if (b <= 0) + { + return c / bytes; + } + c += b; + blocks -= b; + } + return c / bytes; +} + +static int f_seek(int *f, ogg_int64_t offset, int mode) +{ + if(f==NULL) return(-1); + + int k; + mode &= 3; + + int d = (*f) - 0x666; + if((unsigned)(d) <= (0x669 - 0x666)) + { + k = 0; + + if (file[d].size == 0) + return -1; + + if (mode == 0) + { + if ((offset) >= file[d].size) + { + file[d].pos = file[d].size; + k = -1; + } + else if ((offset) < 0) + { + file[d].pos = 0; + k = -1; + } + else + file[d].pos = offset; + } + else if (mode == 1) + { + if ((file[d].pos + offset) >= file[d].size) + { + file[d].pos = file[d].size; + k = -1; + } + else if ((file[d].pos + offset) < 0) + { + file[d].pos = 0; + k = -1; + } + else + file[d].pos += offset; + } + else if (mode == 2) + { + + if ((file[d].size + offset) >= file[d].size) + { + file[d].pos = file[d].size; + k = -1; + } + else if ((file[d].size + offset) < 0) + { + file[d].pos = 0; + k = -1; + } + else + file[d].pos = file[d].size + offset; + } + + } + else + k = lseek(*f, (int) offset, mode); + + if (k < 0) + k = -1; + else + k = 0; + return k; +} + +static int f_close(int *f) +{ + int d = (*f) - 0x666; + if((unsigned)(d) <= (0x669 - 0x666)) + { + file[d].size = 0; + file[d].pos = 0; + if (file[d].mem) + { + file[d].mem = (char *) 0; + } + return 0; + } + else + return close(*f); + return 0; +} + +static long f_tell(int *f) +{ + int k; + + int d = (*f) - 0x666; + if((unsigned)(d) <= (0x669 - 0x666)) + { + k = file[d].pos; + } + else + k = lseek(*f, 0, 1); + + return (long) k; +} + +static int mem_open(char * ogg, int size) +{ + static int one = 1; + int n; + if (one) + { + one = 0; + + file[0].size = 0; + file[1].size = 0; + file[2].size = 0; + file[3].size = 0; + file[0].mem = ogg; + file[0].size = size; + file[0].pos = 0; + return (0x666); + } + + for (n = 0; n < 4; n++) + { + if (file[n].size == 0) + { + file[n].mem = ogg; + file[n].size = size; + file[n].pos = 0; + return (0x666 + n); + } + } + return -1; +} + +static int mem_close(int fd) +{ + if((unsigned)((fd) - 0x666) <= (0x669 - 0x666)) // it is a memory file descriptor? + { + fd -= 0x666; + file[fd].size = 0; + return 0; + } + else + return f_close(&fd); +} + +static ov_callbacks callbacks = { + (size_t (*)(void *, size_t, size_t, void *)) f_read, + (int (*)(void *, ogg_int64_t, int)) f_seek, + (int (*)(void *)) f_close, + (long (*)(void *)) f_tell +}; + class GuiSoundDecoderOGG : public GuiSoundDecoder { protected: @@ -29,7 +238,7 @@ protected: ogg_fd = mem_open((char *)snd, len); if(ogg_fd < 0) throw("mem open failed"); - if (ov_open((FILE*)&ogg_fd, &ogg_file, NULL, 0) < 0) + if (ov_open_callbacks((void*)&ogg_fd, &ogg_file, NULL, 0, callbacks) < 0) { mem_close(ogg_fd); throw("ogg open failed");