diff options
author | chai <chaifix@163.com> | 2020-02-11 11:29:07 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2020-02-11 11:29:07 +0800 |
commit | 160e1299ef3d95f8e8c48706d7f61dd3dc6c6b60 (patch) | |
tree | abe5ae5242d9cc6caf6edf103e662c44e978fca0 /src/libjin/audio/SDL/sdl_source.h | |
parent | e095043485d1d298571af6d9eca7f0db9009ea7a (diff) |
Diffstat (limited to 'src/libjin/audio/SDL/sdl_source.h')
-rw-r--r-- | src/libjin/audio/SDL/sdl_source.h | 492 |
1 files changed, 246 insertions, 246 deletions
diff --git a/src/libjin/audio/SDL/sdl_source.h b/src/libjin/audio/SDL/sdl_source.h index 967b0c2..ae634cf 100644 --- a/src/libjin/audio/SDL/sdl_source.h +++ b/src/libjin/audio/SDL/sdl_source.h @@ -12,252 +12,252 @@ namespace JinEngine { - namespace Audio - { - namespace SDL - { - - typedef struct SDLSourceCommand; - - class SDLSourceManager; - - /// - /// Audio source SDL implementation. - /// - class SDLSource : public Source - { - public: - /// - /// Source constructor. - /// - SDLSource(); - - /// - /// - /// - SDLSource(const char* file); - - /// - /// - /// - SDLSource(void* mem, size_t size); - - /// - /// Source destructor. - /// - ~SDLSource(); - - /// - /// Play source. - /// - void play() override; - - /// - /// Stop source. - /// - void stop() override; - - /// - /// Pause source. - /// - void pause() override; - - /// - /// Resume source. - /// - void resume() override; - - /// - /// Rewind source. - /// - void rewind() override; - - /// - /// Return if the source is stopped. - /// - /// @return True if the source is stopped, otherwise return false. - /// - bool isStopped() const override; - - /// - /// Return if the source is paused. - /// - /// @return True if the source is paused(, otherwise return false. - /// - bool isPaused() const override; - - /// - /// Set pitch. - /// - /// @param pitch Pitch of source. - /// - void setPitch(float pitch) override; - - /// - /// Set volume. - /// - /// @param volume Volume of source. - /// - void setVolume(float volume) override; - - /// - /// Set source loop. - /// - /// @param loop Looping or not. - /// - void setLoop(bool loop) override; - - /// - /// Set source rate. - /// - /// @param rate Rate of source. - /// - void setRate(float rate) override; - - /// - /// Handle a specific command. - /// - /// @param manager Audio manager. - /// @param cmd Source commad. - /// - inline void handle(SDLSourceManager* manager, SDLSourceCommand* cmd); - - /// - /// Process decoded source data. - /// - /// @param buffer Source data. - /// @param size Data size. - /// - inline void process(void* buffer, size_t size); - - protected: - /// - /// Decode wav file. - /// - /// @param mem Wav file data. - /// @param size Wav data size. - /// - void decode_wav(void* mem, int size); - - /// - /// Decode ogg file. - /// - /// @param mem ogg file data. - /// @param size ogg data size. - /// - void decode_ogg(void* mem, int size); - - /// - /// Check source state. - /// - /// @param state State to be checked. - /// @return True if state is given state, otherwise return false. - /// - inline bool is(int state) const - { - return (status.state & state) == state; - } - - // Source data. - struct { - const void* data; // Ƶ - int length; // dataֽڳ - const void* end; // dataβ = (unsigned char*)data + size - int samplerate; // Ƶ - unsigned char bitdepth; // ÿsampleıس - int samples; // sample = size / (bitdepth / 8) - unsigned char channels; // channel1(mono)2(stereo) - } raw; - // Procedure controller variable. - struct { - int pos; // ǰŵsample - int pitch; // pitch - int state; // ǰ״̬ - bool loop; // loop or not - float volume; // - } status; - - }; - - /// - /// Source manager. - /// - class SDLSourceManager : public Object - { - public: - /// - /// Get manager singleton. - /// - /// @return Singleton of SDL source manager. - /// - static SDLSourceManager* get(); - - /// - /// Process commands. - /// - void processCommands(); - - /// - /// Process sources. - /// - /// @param buffer Source data. - /// @param size Size of source data. - /// - void processSources(void* buffer, size_t size); - - /// - /// Clear source queue. - /// - /// This function will stop all sources. - /// - void removeAllSource(); - - /// - /// Remove specific source. - /// - /// @param source SDL audio source. - /// - void removeSource(SDLSource* source); - - /// - /// Push specific source into queue. - /// - /// @param source SDL audio source. - /// - void pushSource(SDLSource* source); - - /// - /// Get command from queue. - /// - /// @return Command at first place. - /// - SDLSourceCommand* getCommand(); - - /// - /// Push command. - /// - /// @param cmd Spcific command. - /// - void pushCommand(SDLSourceCommand* cmd); - - private: - std::queue<SDLSourceCommand*> commands; - std::stack<SDLSourceCommand*> commandsPool; - std::vector<SDLSource*> sources; // processing sources - static SDLSourceManager* manager; - - }; - - class SourceException : public Object, public std::exception - { - const char* what() const throw () - { - return "Load Source Exception"; - } - }; - - } // namespace SDL - } // namespace Audio + namespace Audio + { + namespace SDL + { + + typedef struct SDLSourceCommand; + + class SDLSourceManager; + + /// + /// Audio source SDL implementation. + /// + class SDLSource : public Source + { + public: + /// + /// Source constructor. + /// + SDLSource(); + + /// + /// + /// + SDLSource(const char* file); + + /// + /// + /// + SDLSource(void* mem, size_t size); + + /// + /// Source destructor. + /// + ~SDLSource(); + + /// + /// Play source. + /// + void play() override; + + /// + /// Stop source. + /// + void stop() override; + + /// + /// Pause source. + /// + void pause() override; + + /// + /// Resume source. + /// + void resume() override; + + /// + /// Rewind source. + /// + void rewind() override; + + /// + /// Return if the source is stopped. + /// + /// @return True if the source is stopped, otherwise return false. + /// + bool isStopped() const override; + + /// + /// Return if the source is paused. + /// + /// @return True if the source is paused(, otherwise return false. + /// + bool isPaused() const override; + + /// + /// Set pitch. + /// + /// @param pitch Pitch of source. + /// + void setPitch(float pitch) override; + + /// + /// Set volume. + /// + /// @param volume Volume of source. + /// + void setVolume(float volume) override; + + /// + /// Set source loop. + /// + /// @param loop Looping or not. + /// + void setLoop(bool loop) override; + + /// + /// Set source rate. + /// + /// @param rate Rate of source. + /// + void setRate(float rate) override; + + /// + /// Handle a specific command. + /// + /// @param manager Audio manager. + /// @param cmd Source commad. + /// + inline void handle(SDLSourceManager* manager, SDLSourceCommand* cmd); + + /// + /// Process decoded source data. + /// + /// @param buffer Source data. + /// @param size Data size. + /// + inline void process(void* buffer, size_t size); + + protected: + /// + /// Decode wav file. + /// + /// @param mem Wav file data. + /// @param size Wav data size. + /// + void decode_wav(void* mem, int size); + + /// + /// Decode ogg file. + /// + /// @param mem ogg file data. + /// @param size ogg data size. + /// + void decode_ogg(void* mem, int size); + + /// + /// Check source state. + /// + /// @param state State to be checked. + /// @return True if state is given state, otherwise return false. + /// + inline bool is(int state) const + { + return (status.state & state) == state; + } + + // Source data. + struct { + const void* data; // Ƶ + int length; // dataֽڳ + const void* end; // dataβ = (unsigned char*)data + size + int samplerate; // Ƶ + unsigned char bitdepth; // ÿsampleıس + int samples; // sample = size / (bitdepth / 8) + unsigned char channels; // channel1(mono)2(stereo) + } raw; + // Procedure controller variable. + struct { + int pos; // ǰŵsample + int pitch; // pitch + int state; // ǰ״̬ + bool loop; // loop or not + float volume; // + } status; + + }; + + /// + /// Source manager. + /// + class SDLSourceManager : public Object + { + public: + /// + /// Get manager singleton. + /// + /// @return Singleton of SDL source manager. + /// + static SDLSourceManager* get(); + + /// + /// Process commands. + /// + void processCommands(); + + /// + /// Process sources. + /// + /// @param buffer Source data. + /// @param size Size of source data. + /// + void processSources(void* buffer, size_t size); + + /// + /// Clear source queue. + /// + /// This function will stop all sources. + /// + void removeAllSource(); + + /// + /// Remove specific source. + /// + /// @param source SDL audio source. + /// + void removeSource(SDLSource* source); + + /// + /// Push specific source into queue. + /// + /// @param source SDL audio source. + /// + void pushSource(SDLSource* source); + + /// + /// Get command from queue. + /// + /// @return Command at first place. + /// + SDLSourceCommand* getCommand(); + + /// + /// Push command. + /// + /// @param cmd Spcific command. + /// + void pushCommand(SDLSourceCommand* cmd); + + private: + std::queue<SDLSourceCommand*> commands; + std::stack<SDLSourceCommand*> commandsPool; + std::vector<SDLSource*> sources; // processing sources + static SDLSourceManager* manager; + + }; + + class SourceException : public Object, public std::exception + { + const char* what() const throw () + { + return "Load Source Exception"; + } + }; + + } // namespace SDL + } // namespace Audio } // namespace JinEngine #endif // (jin_audio) && (jin_audio == jin_audio_sdl) |