diff --git a/src/core.h b/src/core.h index a0dd4c6..4bf4ba9 100644 --- a/src/core.h +++ b/src/core.h @@ -104,6 +104,11 @@ #undef OS_PTHREAD_MT #undef USE_CUBEMAP_MIPS #define USE_ATLAS_RGBA16 + + // for 2352 stereo samples + // stb_vorbis - 8 ms + // libvorbis - 6 ms + #define USE_LIBVORBIS #elif _PSP #define _OS_PSP 1 #define _GAPI_GU 1 diff --git a/src/platform/3ds/Makefile b/src/platform/3ds/Makefile index 8d77d99..f8579da 100644 --- a/src/platform/3ds/Makefile +++ b/src/platform/3ds/Makefile @@ -59,13 +59,13 @@ CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11 ASFLAGS := -g $(ARCH) LDFLAGS = -specs=3dsx.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) -LIBS := -lcitro3d -lctru -lm +LIBS := -lcitro3d -lctru -lm -lvorbisidec -logg #--------------------------------------------------------------------------------- # list of directories containing libraries, this must be the top level containing # include and lib #--------------------------------------------------------------------------------- -LIBDIRS := $(CTRULIB) +LIBDIRS := $(CTRULIB) $(PORTLIBS) #--------------------------------------------------------------------------------- diff --git a/src/sound.h b/src/sound.h index 4c8e68e..6bb7ea2 100644 --- a/src/sound.h +++ b/src/sound.h @@ -19,8 +19,13 @@ #endif #ifdef DECODE_OGG - #define STB_VORBIS_HEADER_ONLY - #include "libs/stb_vorbis/stb_vorbis.c" + #ifdef USE_LIBVORBIS + #include + #include + #else + #define STB_VORBIS_HEADER_ONLY + #include "libs/stb_vorbis/stb_vorbis.c" + #endif #endif #define SND_CHANNELS_MAX 128 @@ -699,13 +704,60 @@ namespace Sound { #endif #ifdef DECODE_OGG + +#ifdef USE_LIBVORBIS + struct OGG : Decoder { + OggVorbis_File vf; + FILE *memFile; + uint8 *data; + + OGG(Stream *stream, int channels) : Decoder(stream, channels, 0) { + char buf[255]; + strcpy(buf, contentDir); + strcat(buf, stream->name); + + data = new uint8[stream->size]; + stream->raw(data, stream->size); + + memFile = fmemopen(data, stream->size, "rb"); + int err = ov_open(memFile, &vf, NULL, 0); + ASSERT(err >= 0); + vorbis_info *info = ov_info(&vf, -1); + this->channels = info->channels; + this->freq = info->rate; + } + + virtual ~OGG() { + ov_clear(&vf); + fclose(memFile); + delete[] data; + } + + virtual int decode(Frame *frames, int count) { + PROFILE_CPU_TIMING(stats.ogg); + int i = 0; + int bytes = count * sizeof(Frame); + while (i < bytes) { + int bitstream; + int res = ov_read(&vf, (char*)frames + i, bytes - i, &bitstream); + if (!res) break; + i += res; + } + return i / sizeof(Frame); + } + + virtual void replay() { + fseek(memFile, 0, SEEK_SET); + ov_open(memFile, &vf, NULL, 0); + } + }; +#else // stb_vorbis struct OGG : Decoder { stb_vorbis *ogg; stb_vorbis_alloc alloc; + uint8 *data; - uint8 *data; - - OGG(Stream *stream, int channels) : Decoder(stream, channels, 0), ogg(NULL) { + OGG(Stream *stream, int channels) : Decoder(stream, channels, 0) { char buf[255]; strcpy(buf, contentDir); strcat(buf, stream->name); @@ -744,6 +796,9 @@ namespace Sound { } }; #endif + +#endif // DECODE_OGG + Core::Mutex lock; struct Listener {