1
0
mirror of https://github.com/XProger/OpenLara.git synced 2025-01-17 21:09:00 +01:00

add libvorbis for 3DS to save 2 ms per block (8 -> 6 ms for 2352 stereo samples)

This commit is contained in:
XProger 2020-02-20 03:17:46 +03:00
parent 96b34590ef
commit fbd5ccda5b
3 changed files with 67 additions and 7 deletions

View File

@ -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

View File

@ -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)
#---------------------------------------------------------------------------------

View File

@ -19,8 +19,13 @@
#endif
#ifdef DECODE_OGG
#define STB_VORBIS_HEADER_ONLY
#include "libs/stb_vorbis/stb_vorbis.c"
#ifdef USE_LIBVORBIS
#include <tremor/ivorbisfile.h>
#include <tremor/ivorbiscodec.h>
#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 {