diff --git a/src/sound/i_sound.cpp b/src/sound/i_sound.cpp index 88cece9d4..ec2071106 100644 --- a/src/sound/i_sound.cpp +++ b/src/sound/i_sound.cpp @@ -56,6 +56,9 @@ extern HINSTANCE g_hInst; #include "fmodsound.h" #include "oalsound.h" +#include "mpg123_decoder.h" +#include "sndfile_decoder.h" + #include "m_swap.h" #include "stats.h" #include "files.h" diff --git a/src/sound/i_soundinternal.h b/src/sound/i_soundinternal.h index dd9fb35f8..14dadf3e2 100644 --- a/src/sound/i_soundinternal.h +++ b/src/sound/i_soundinternal.h @@ -139,88 +139,4 @@ private: SoundDecoder& operator=(const SoundDecoder &rhs); }; -#ifdef HAVE_MPG123 -#include "mpg123.h" -struct MPG123Decoder : public SoundDecoder -{ - virtual void getInfo(int *samplerate, ChannelConfig *chans, SampleType *type); - - virtual size_t read(char *buffer, size_t bytes); - virtual bool seek(size_t ms_offset); - virtual size_t getSampleOffset(); - - MPG123Decoder() : MPG123(0), File(0) { } - virtual ~MPG123Decoder(); - -protected: - virtual bool open(const char *data, size_t length); - virtual bool open(const char *fname, size_t offset, size_t length); - -private: - mpg123_handle *MPG123; - bool Done; - - FILE *File; - size_t FileLength; - size_t FileOffset; - static off_t file_lseek(void *handle, off_t offset, int whence); - static ssize_t file_read(void *handle, void *buffer, size_t bytes); - - const char *MemData; - size_t MemLength; - size_t MemPos; - static off_t mem_lseek(void *handle, off_t offset, int whence); - static ssize_t mem_read(void *handle, void *buffer, size_t bytes); - - // Make non-copyable - MPG123Decoder(const MPG123Decoder &rhs); - MPG123Decoder& operator=(const MPG123Decoder &rhs); -}; -#endif -#ifdef HAVE_SNDFILE -#include "sndfile.h" -struct SndFileDecoder : public SoundDecoder -{ - virtual void getInfo(int *samplerate, ChannelConfig *chans, SampleType *type); - - virtual size_t read(char *buffer, size_t bytes); - virtual std::vector readAll(); - virtual bool seek(size_t ms_offset); - virtual size_t getSampleOffset(); - - SndFileDecoder() : SndFile(0), File(0) { } - virtual ~SndFileDecoder(); - -protected: - virtual bool open(const char *data, size_t length); - virtual bool open(const char *fname, size_t offset, size_t length); - -private: - SNDFILE *SndFile; - SF_INFO SndInfo; - - FILE *File; - size_t FileLength; - size_t FileOffset; - static sf_count_t file_get_filelen(void *user_data); - static sf_count_t file_seek(sf_count_t offset, int whence, void *user_data); - static sf_count_t file_read(void *ptr, sf_count_t count, void *user_data); - static sf_count_t file_write(const void *ptr, sf_count_t count, void *user_data); - static sf_count_t file_tell(void *user_data); - - const char *MemData; - size_t MemLength; - size_t MemPos; - static sf_count_t mem_get_filelen(void *user_data); - static sf_count_t mem_seek(sf_count_t offset, int whence, void *user_data); - static sf_count_t mem_read(void *ptr, sf_count_t count, void *user_data); - static sf_count_t mem_write(const void *ptr, sf_count_t count, void *user_data); - static sf_count_t mem_tell(void *user_data); - - // Make non-copyable - SndFileDecoder(const SndFileDecoder &rhs); - SndFileDecoder& operator=(const SndFileDecoder &rhs); -}; -#endif - #endif diff --git a/src/sound/mpg123_decoder.cpp b/src/sound/mpg123_decoder.cpp index bacb7df46..c3a811b40 100644 --- a/src/sound/mpg123_decoder.cpp +++ b/src/sound/mpg123_decoder.cpp @@ -1,4 +1,4 @@ -#include "i_soundinternal.h" +#include "mpg123_decoder.h" #ifdef HAVE_MPG123 static bool inited = false; diff --git a/src/sound/mpg123_decoder.h b/src/sound/mpg123_decoder.h new file mode 100644 index 000000000..216eae2f9 --- /dev/null +++ b/src/sound/mpg123_decoder.h @@ -0,0 +1,48 @@ +#ifndef MPG123_DECODER_H +#define MPG123_DECODER_H + +#include "i_soundinternal.h" + +#ifdef HAVE_MPG123 + +#include "mpg123.h" + +struct MPG123Decoder : public SoundDecoder +{ + virtual void getInfo(int *samplerate, ChannelConfig *chans, SampleType *type); + + virtual size_t read(char *buffer, size_t bytes); + virtual bool seek(size_t ms_offset); + virtual size_t getSampleOffset(); + + MPG123Decoder() : MPG123(0), File(0) { } + virtual ~MPG123Decoder(); + +protected: + virtual bool open(const char *data, size_t length); + virtual bool open(const char *fname, size_t offset, size_t length); + +private: + mpg123_handle *MPG123; + bool Done; + + FILE *File; + size_t FileLength; + size_t FileOffset; + static off_t file_lseek(void *handle, off_t offset, int whence); + static ssize_t file_read(void *handle, void *buffer, size_t bytes); + + const char *MemData; + size_t MemLength; + size_t MemPos; + static off_t mem_lseek(void *handle, off_t offset, int whence); + static ssize_t mem_read(void *handle, void *buffer, size_t bytes); + + // Make non-copyable + MPG123Decoder(const MPG123Decoder &rhs); + MPG123Decoder& operator=(const MPG123Decoder &rhs); +}; + +#endif + +#endif /* MPG123_DECODER_H */ diff --git a/src/sound/sndfile_decoder.cpp b/src/sound/sndfile_decoder.cpp index d90e74abc..534cf343f 100644 --- a/src/sound/sndfile_decoder.cpp +++ b/src/sound/sndfile_decoder.cpp @@ -1,4 +1,4 @@ -#include "i_soundinternal.h" +#include "sndfile_decoder.h" #ifdef HAVE_SNDFILE sf_count_t SndFileDecoder::file_get_filelen(void *user_data) diff --git a/src/sound/sndfile_decoder.h b/src/sound/sndfile_decoder.h new file mode 100644 index 000000000..ec59af98f --- /dev/null +++ b/src/sound/sndfile_decoder.h @@ -0,0 +1,55 @@ +#ifndef SNDFILE_DECODER_H +#define SNDFILE_DECODER_H + +#include "i_soundinternal.h" + +#ifdef HAVE_SNDFILE + +#include "sndfile.h" + +struct SndFileDecoder : public SoundDecoder +{ + virtual void getInfo(int *samplerate, ChannelConfig *chans, SampleType *type); + + virtual size_t read(char *buffer, size_t bytes); + virtual std::vector readAll(); + virtual bool seek(size_t ms_offset); + virtual size_t getSampleOffset(); + + SndFileDecoder() : SndFile(0), File(0) { } + virtual ~SndFileDecoder(); + +protected: + virtual bool open(const char *data, size_t length); + virtual bool open(const char *fname, size_t offset, size_t length); + +private: + SNDFILE *SndFile; + SF_INFO SndInfo; + + FILE *File; + size_t FileLength; + size_t FileOffset; + static sf_count_t file_get_filelen(void *user_data); + static sf_count_t file_seek(sf_count_t offset, int whence, void *user_data); + static sf_count_t file_read(void *ptr, sf_count_t count, void *user_data); + static sf_count_t file_write(const void *ptr, sf_count_t count, void *user_data); + static sf_count_t file_tell(void *user_data); + + const char *MemData; + size_t MemLength; + size_t MemPos; + static sf_count_t mem_get_filelen(void *user_data); + static sf_count_t mem_seek(sf_count_t offset, int whence, void *user_data); + static sf_count_t mem_read(void *ptr, sf_count_t count, void *user_data); + static sf_count_t mem_write(const void *ptr, sf_count_t count, void *user_data); + static sf_count_t mem_tell(void *user_data); + + // Make non-copyable + SndFileDecoder(const SndFileDecoder &rhs); + SndFileDecoder& operator=(const SndFileDecoder &rhs); +}; + +#endif + +#endif /* SNDFILE_DECODER_H */