From ddc4b06eba4c0ff60cada59481c234dc6456a28e Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sun, 23 Oct 2016 21:32:20 -0300 Subject: [PATCH] Moved the base Decoder implementation out of the lullaby subfolder. --HG-- branch : minor --- CMakeLists.txt | 3 +- .../xcode/liblove.xcodeproj/project.pbxproj | 6 +- src/modules/sound/{lullaby => }/Decoder.cpp | 4 - src/modules/sound/Decoder.h | 41 +++++++--- src/modules/sound/lullaby/CoreAudioDecoder.h | 2 +- src/modules/sound/lullaby/Decoder.h | 79 ------------------- src/modules/sound/lullaby/FLACDecoder.h | 2 +- src/modules/sound/lullaby/GmeDecoder.h | 2 +- src/modules/sound/lullaby/ModPlugDecoder.h | 2 +- src/modules/sound/lullaby/Mpg123Decoder.h | 2 +- src/modules/sound/lullaby/VorbisDecoder.h | 2 +- src/modules/sound/lullaby/WaveDecoder.h | 2 +- 12 files changed, 41 insertions(+), 106 deletions(-) rename src/modules/sound/{lullaby => }/Decoder.cpp (97%) delete mode 100644 src/modules/sound/lullaby/Decoder.h diff --git a/CMakeLists.txt b/CMakeLists.txt index a74fd7056..d73cc6f1f 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -818,6 +818,7 @@ source_group("modules\\physics\\box2d" FILES ${LOVE_SRC_MODULE_PHYSICS_BOX2D}) # set(LOVE_SRC_MODULE_SOUND_ROOT + src/modules/sound/Decoder.cpp src/modules/sound/Decoder.h src/modules/sound/Sound.cpp src/modules/sound/Sound.h @@ -832,8 +833,6 @@ set(LOVE_SRC_MODULE_SOUND_ROOT ) set(LOVE_SRC_MODULE_SOUND_LULLABY - src/modules/sound/lullaby/Decoder.cpp - src/modules/sound/lullaby/Decoder.h src/modules/sound/lullaby/FLACDecoder.cpp src/modules/sound/lullaby/FLACDecoder.h src/modules/sound/lullaby/GmeDecoder.cpp diff --git a/platform/xcode/liblove.xcodeproj/project.pbxproj b/platform/xcode/liblove.xcodeproj/project.pbxproj index 2d6fb8255..84a45b40f 100644 --- a/platform/xcode/liblove.xcodeproj/project.pbxproj +++ b/platform/xcode/liblove.xcodeproj/project.pbxproj @@ -719,7 +719,6 @@ FA0B7E871A95902C000E1D17 /* CoreAudioDecoder.h in Headers */ = {isa = PBXBuildFile; fileRef = FA0B7C7F1A95902C000E1D17 /* CoreAudioDecoder.h */; }; FA0B7E881A95902C000E1D17 /* Decoder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7C801A95902C000E1D17 /* Decoder.cpp */; }; FA0B7E891A95902C000E1D17 /* Decoder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7C801A95902C000E1D17 /* Decoder.cpp */; }; - FA0B7E8A1A95902C000E1D17 /* Decoder.h in Headers */ = {isa = PBXBuildFile; fileRef = FA0B7C811A95902C000E1D17 /* Decoder.h */; }; FA0B7E8B1A95902C000E1D17 /* FLACDecoder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7C821A95902C000E1D17 /* FLACDecoder.cpp */; }; FA0B7E8C1A95902C000E1D17 /* FLACDecoder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7C821A95902C000E1D17 /* FLACDecoder.cpp */; }; FA0B7E8D1A95902C000E1D17 /* FLACDecoder.h in Headers */ = {isa = PBXBuildFile; fileRef = FA0B7C831A95902C000E1D17 /* FLACDecoder.h */; }; @@ -1441,7 +1440,6 @@ FA0B7C7E1A95902C000E1D17 /* CoreAudioDecoder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CoreAudioDecoder.cpp; sourceTree = ""; }; FA0B7C7F1A95902C000E1D17 /* CoreAudioDecoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CoreAudioDecoder.h; sourceTree = ""; }; FA0B7C801A95902C000E1D17 /* Decoder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Decoder.cpp; sourceTree = ""; }; - FA0B7C811A95902C000E1D17 /* Decoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Decoder.h; sourceTree = ""; }; FA0B7C821A95902C000E1D17 /* FLACDecoder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FLACDecoder.cpp; sourceTree = ""; }; FA0B7C831A95902C000E1D17 /* FLACDecoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLACDecoder.h; sourceTree = ""; }; FA0B7C841A95902C000E1D17 /* GmeDecoder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GmeDecoder.cpp; sourceTree = ""; }; @@ -2630,6 +2628,7 @@ FA0B7C7B1A95902C000E1D17 /* sound */ = { isa = PBXGroup; children = ( + FA0B7C801A95902C000E1D17 /* Decoder.cpp */, FA0B7C7C1A95902C000E1D17 /* Decoder.h */, FA0B7C7D1A95902C000E1D17 /* lullaby */, FA0B7C901A95902C000E1D17 /* Sound.cpp */, @@ -2652,8 +2651,6 @@ children = ( FA0B7C7E1A95902C000E1D17 /* CoreAudioDecoder.cpp */, FA0B7C7F1A95902C000E1D17 /* CoreAudioDecoder.h */, - FA0B7C801A95902C000E1D17 /* Decoder.cpp */, - FA0B7C811A95902C000E1D17 /* Decoder.h */, FA0B7C821A95902C000E1D17 /* FLACDecoder.cpp */, FA0B7C831A95902C000E1D17 /* FLACDecoder.h */, FA0B7C841A95902C000E1D17 /* GmeDecoder.cpp */, @@ -3200,7 +3197,6 @@ FA0B7DEA1A95902C000E1D17 /* Mouse.h in Headers */, FA0B7E931A95902C000E1D17 /* ModPlugDecoder.h in Headers */, FA0B7D111A95902C000E1D17 /* BMFontRasterizer.h in Headers */, - FA0B7E8A1A95902C000E1D17 /* Decoder.h in Headers */, FA0B7E3E1A95902C000E1D17 /* wrap_Body.h in Headers */, FA0B7A571A958EA3000E1D17 /* b2Settings.h in Headers */, FA0B7B321A958EA3000E1D17 /* wuff.h in Headers */, diff --git a/src/modules/sound/lullaby/Decoder.cpp b/src/modules/sound/Decoder.cpp similarity index 97% rename from src/modules/sound/lullaby/Decoder.cpp rename to src/modules/sound/Decoder.cpp index c6421a4ce..93805e458 100644 --- a/src/modules/sound/lullaby/Decoder.cpp +++ b/src/modules/sound/Decoder.cpp @@ -26,8 +26,6 @@ namespace love { namespace sound { -namespace lullaby -{ Decoder::Decoder(Data *data, const std::string &ext, int bufferSize) : data(data) @@ -66,7 +64,5 @@ bool Decoder::isFinished() return eof; } - -} // lullaby } // sound } // love diff --git a/src/modules/sound/Decoder.h b/src/modules/sound/Decoder.h index 4f8f806e6..11683dafb 100644 --- a/src/modules/sound/Decoder.h +++ b/src/modules/sound/Decoder.h @@ -23,6 +23,9 @@ // LOVE #include "common/Object.h" +#include "filesystem/File.h" + +#include namespace love { @@ -36,6 +39,9 @@ class Decoder : public Object { public: + Decoder(Data *data, const std::string &ext, int bufferSize); + virtual ~Decoder(); + /** * Indicates how many bytes of raw data should be generated at each * call to Decode. @@ -64,11 +70,6 @@ public: **/ virtual Decoder *clone() = 0; - /** - * Destructor. Should free internal buffer. - **/ - virtual ~Decoder() {} - /** * Decodes the next chunk of the music stream, this will usually be * bufferSize amount of bytes, unless EOF occurs. Zero or negative values @@ -81,14 +82,14 @@ public: * Gets the size of the buffer (NOT the size of the entire stream). * @return The size of the buffer. **/ - virtual int getSize() const = 0; + virtual int getSize() const; /** * Gets a pointer to the actual data. The contents of this buffer will * change with each call to decode, so the client must copy the data. * @return A buffer to raw sound data. **/ - virtual void *getBuffer() const = 0; + virtual void *getBuffer() const; /** * Seeks to the specified position, if possible. @@ -114,7 +115,7 @@ public: * rewind to start the stream again. * @return False if there is more data, true on EOF. **/ - virtual bool isFinished() = 0; + virtual bool isFinished(); /** * Gets the number of channels in a stream. Supported values are 1 (mono) or 2 (stereo). @@ -132,7 +133,7 @@ public: * Gets the sample rate for the Decoder, that is, samples per second. * @return The sample rate, eg. 44100. **/ - virtual int getSampleRate() const = 0; + virtual int getSampleRate() const; /** * Gets the estimated total duration of the stream. in seconds. May return @@ -140,6 +141,28 @@ public: **/ virtual double getDuration() = 0; +protected: + + // The encoded data. This should be replaced with buffered file + // reads in the future. + StrongRef data; + + // File extension. + std::string ext; + + // When the decoder decodes data incrementally, it writes + // this many bytes at a time (at most). + int bufferSize; + + // The desired frequency of the samples. 44100, 22050, or 11025. + int sampleRate; + + // Holds internal memory. + void *buffer; + + // Set this to true when eof has been reached. + bool eof; + }; // Decoder } // sound diff --git a/src/modules/sound/lullaby/CoreAudioDecoder.h b/src/modules/sound/lullaby/CoreAudioDecoder.h index 90bed3736..e22b99dd6 100644 --- a/src/modules/sound/lullaby/CoreAudioDecoder.h +++ b/src/modules/sound/lullaby/CoreAudioDecoder.h @@ -27,7 +27,7 @@ // LOVE #include "common/Data.h" -#include "Decoder.h" +#include "sound/Decoder.h" // Core Audio #include diff --git a/src/modules/sound/lullaby/Decoder.h b/src/modules/sound/lullaby/Decoder.h deleted file mode 100644 index 6e36df9b2..000000000 --- a/src/modules/sound/lullaby/Decoder.h +++ /dev/null @@ -1,79 +0,0 @@ -/** - * Copyright (c) 2006-2016 LOVE Development Team - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - **/ - -#ifndef LOVE_SOUND_LULLABY_DECODER_H -#define LOVE_SOUND_LULLABY_DECODER_H - -// LOVE -#include "sound/Decoder.h" -#include "filesystem/File.h" - -#include - -namespace love -{ -namespace sound -{ -namespace lullaby -{ - -class Decoder : public love::sound::Decoder -{ -public: - - Decoder(Data *data, const std::string &ext, int bufferSize); - - virtual ~Decoder(); - - // Implement some of love::sound::Decoder, but allow subclasses - // to override them. - virtual void *getBuffer() const; - virtual int getSize() const; - virtual int getSampleRate() const; - virtual bool isFinished(); - -protected: - - // The encoded data. This should be replaced with buffered file - // reads in the future. - StrongRef data; - - // File extension. - std::string ext; - - // When the decoder decodes data incrementally, it writes - // this many bytes at a time (at most). - int bufferSize; - - // The desired frequency of the samples. 44100, 22050, or 11025. - int sampleRate; - - // Holds internal memory. - void *buffer; - - // Set this to true when eof has been reached. - bool eof; -}; // Decoder - -} // lullaby -} // sound -} // love - -#endif // LOVE_SOUND_LULLABY_DECODER_H diff --git a/src/modules/sound/lullaby/FLACDecoder.h b/src/modules/sound/lullaby/FLACDecoder.h index 77d7a6278..169d30a49 100644 --- a/src/modules/sound/lullaby/FLACDecoder.h +++ b/src/modules/sound/lullaby/FLACDecoder.h @@ -25,7 +25,7 @@ // LOVE #include "common/Data.h" -#include "Decoder.h" +#include "sound/Decoder.h" #include #include diff --git a/src/modules/sound/lullaby/GmeDecoder.h b/src/modules/sound/lullaby/GmeDecoder.h index efa15e3c6..2eb6313cd 100644 --- a/src/modules/sound/lullaby/GmeDecoder.h +++ b/src/modules/sound/lullaby/GmeDecoder.h @@ -25,7 +25,7 @@ // LOVE #include "common/Data.h" -#include "Decoder.h" +#include "sound/Decoder.h" #ifdef LOVE_APPLE_USE_FRAMEWORKS #include diff --git a/src/modules/sound/lullaby/ModPlugDecoder.h b/src/modules/sound/lullaby/ModPlugDecoder.h index 99aea50a8..d84e91730 100644 --- a/src/modules/sound/lullaby/ModPlugDecoder.h +++ b/src/modules/sound/lullaby/ModPlugDecoder.h @@ -27,7 +27,7 @@ // LOVE #include "common/Data.h" -#include "Decoder.h" +#include "sound/Decoder.h" // libmodplug #if defined(LOVE_ANDROID) || defined(LOVE_IOS) diff --git a/src/modules/sound/lullaby/Mpg123Decoder.h b/src/modules/sound/lullaby/Mpg123Decoder.h index edb3b139d..704b0cac5 100644 --- a/src/modules/sound/lullaby/Mpg123Decoder.h +++ b/src/modules/sound/lullaby/Mpg123Decoder.h @@ -23,7 +23,7 @@ // LOVE #include "common/Data.h" -#include "Decoder.h" +#include "sound/Decoder.h" #ifndef LOVE_NOMPG123 diff --git a/src/modules/sound/lullaby/VorbisDecoder.h b/src/modules/sound/lullaby/VorbisDecoder.h index 458888e7a..185679c99 100644 --- a/src/modules/sound/lullaby/VorbisDecoder.h +++ b/src/modules/sound/lullaby/VorbisDecoder.h @@ -24,7 +24,7 @@ // LOVE #include "common/Data.h" #include "common/int.h" -#include "Decoder.h" +#include "sound/Decoder.h" // vorbis #define OV_EXCLUDE_STATIC_CALLBACKS diff --git a/src/modules/sound/lullaby/WaveDecoder.h b/src/modules/sound/lullaby/WaveDecoder.h index 27fde4947..93aaadfac 100644 --- a/src/modules/sound/lullaby/WaveDecoder.h +++ b/src/modules/sound/lullaby/WaveDecoder.h @@ -23,7 +23,7 @@ // LOVE #include "common/Data.h" -#include "Decoder.h" +#include "sound/Decoder.h" #include "libraries/Wuff/wuff.h"