From 7842ff07815c5fb2d371d4ed5bf62e24acb187c9 Mon Sep 17 00:00:00 2001 From: GaryOderNichts <12049776+GaryOderNichts@users.noreply.github.com> Date: Mon, 28 Dec 2020 22:22:50 +0100 Subject: [PATCH] wiiu: use dr_wav instead of sndfile - seems to be a bit faster - libsndfile no longer needed --- .gitmodules | 3 ++ Makefile | 5 ++- src/audio/oal/stream.cpp | 94 ++++++++++++++++++++++++++++++++++++++++ vendor/dr_libs | 1 + 4 files changed, 101 insertions(+), 2 deletions(-) create mode 160000 vendor/dr_libs diff --git a/.gitmodules b/.gitmodules index e786d9ec..f5d5a545 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "vendor/openal-soft"] path = vendor/openal-soft url = https://github.com/GaryOderNichts/openal-soft +[submodule "vendor/dr_libs"] + path = vendor/dr_libs + url = https://github.com/mackron/dr_libs.git diff --git a/Makefile b/Makefile index 3901e57e..32450e38 100644 --- a/Makefile +++ b/Makefile @@ -48,7 +48,8 @@ DATA := data INCLUDES := $(SOURCES) \ vendor/librw \ vendor/librw/inc \ - vendor/openal-soft/include + vendor/openal-soft/include \ + vendor/dr_libs #------------------------------------------------------------------------------- # options for code generation @@ -64,7 +65,7 @@ CXXFLAGS := $(CFLAGS) ASFLAGS := -g $(ARCH) LDFLAGS = -g $(ARCH) $(RPXSPECS) -Wl,-Map,$(notdir $*.map) -LIBS := -lrw -lmpg123 -lopenal -lSDL2 -lsndfile -lwut +LIBS := -lrw -lmpg123 -lopenal -lSDL2 -lwut #------------------------------------------------------------------------------- # list of directories containing libraries, this must be the top level diff --git a/src/audio/oal/stream.cpp b/src/audio/oal/stream.cpp index 90e90dd8..f0b9a819 100644 --- a/src/audio/oal/stream.cpp +++ b/src/audio/oal/stream.cpp @@ -11,7 +11,12 @@ #pragma comment( lib, "libsndfile-1.lib" ) #pragma comment( lib, "libmpg123-0.lib" ) #endif +#ifndef __WIIU__ #include +#else +#define DR_WAV_IMPLEMENTATION +#include "dr_wav.h" +#endif #include #endif @@ -20,6 +25,7 @@ #endif #ifndef AUDIO_OPUS +#ifndef __WIIU__ class CSndFile : public IDecoder { SNDFILE *m_pfSound; @@ -84,6 +90,90 @@ public: return sf_read_short(m_pfSound, (short *)buffer, GetBufferSamples()) * GetSampleSize(); } }; +#else +class CDrWav : public IDecoder +{ + drwav m_drWav; + bool m_bIsLoaded; +public: + CDrWav(const char *path) : + m_bIsLoaded(false) + { + memset(&m_drWav, 0, sizeof(m_drWav)); + if( !drwav_init_file(&m_drWav, path, NULL) ) { + return; + } + + m_bIsLoaded = true; + } + + ~CDrWav() + { + if ( m_bIsLoaded ) + { + drwav_uninit(&m_drWav); + m_bIsLoaded = false; + } + } + + bool IsOpened() + { + return m_bIsLoaded; + } + + uint32 GetSampleSize() + { + return drwav_get_bytes_per_pcm_frame(&m_drWav); + } + + uint32 GetSampleCount() + { + return m_drWav.totalPCMFrameCount; + } + + uint32 GetSampleRate() + { + return m_drWav.sampleRate; + } + + uint32 GetChannels() + { + return m_drWav.channels; + } + + void Seek(uint32 milliseconds) + { + if ( !IsOpened() ) return; + drwav_seek_to_pcm_frame(&m_drWav, ms2samples(milliseconds)); + } + + uint32 Tell() + { + if ( !IsOpened() ) return 0; + + if (drwav__is_compressed_format_tag(m_drWav.translatedFormatTag)) { + return samples2ms(m_drWav.compressed.iCurrentPCMFrame); + } else { + uint32 bytes_per_frame = GetSampleSize(); + return samples2ms( + ((m_drWav.totalPCMFrameCount * bytes_per_frame) - m_drWav.bytesRemaining) / bytes_per_frame + ); + } + } + + uint32 Decode(void *buffer) + { + if ( !IsOpened() ) return 0; + size_t read = drwav_read_raw(&m_drWav, GetBufferSize(), buffer); +#ifdef BIGENDIAN + for (int i = 0; i < GetBufferSize() / sizeof(uint16); i++) { + ((uint16*)buffer)[i] = BSWAP16(((uint16*)buffer)[i]); + } +#endif + return read; + } +}; +#endif class CMP3File : public IDecoder { @@ -318,7 +408,11 @@ CStream::CStream(char *filename, ALuint &source, ALuint (&buffers)[NUM_STREAMBUF if (!strcasecmp(&m_aFilename[strlen(m_aFilename) - strlen(".mp3")], ".mp3")) m_pSoundFile = new CMP3File(m_aFilename); else if (!strcasecmp(&m_aFilename[strlen(m_aFilename) - strlen(".wav")], ".wav")) +#ifndef __WIIU__ m_pSoundFile = new CSndFile(m_aFilename); +#else + m_pSoundFile = new CDrWav(m_aFilename); +#endif #else if (!strcasecmp(&m_aFilename[strlen(m_aFilename) - strlen(".opus")], ".opus")) m_pSoundFile = new COpusFile(m_aFilename); diff --git a/vendor/dr_libs b/vendor/dr_libs new file mode 160000 index 00000000..00370db8 --- /dev/null +++ b/vendor/dr_libs @@ -0,0 +1 @@ +Subproject commit 00370db889a8b7d46e4db51b5b4073428fd42ee8