aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/Audio
diff options
context:
space:
mode:
Diffstat (limited to 'src/libjin/Audio')
-rw-r--r--src/libjin/Audio/SDL/je_sdl_audio.h83
-rw-r--r--src/libjin/Audio/SDL/je_sdl_source.cpp3
-rw-r--r--src/libjin/Audio/SDL/je_sdl_source.h186
-rw-r--r--src/libjin/Audio/je_audio_manager.h34
-rw-r--r--src/libjin/Audio/je_source.h77
5 files changed, 359 insertions, 24 deletions
diff --git a/src/libjin/Audio/SDL/je_sdl_audio.h b/src/libjin/Audio/SDL/je_sdl_audio.h
index 01da7b3..b13dc10 100644
--- a/src/libjin/Audio/SDL/je_sdl_audio.h
+++ b/src/libjin/Audio/SDL/je_sdl_audio.h
@@ -18,9 +18,15 @@ namespace JinEngine
#define SDLAUDIO_BYTEDEPTH (SDLAUDIO_BITDEPTH >> 3)
#define SDLAUDIO_CHANNELS 2
+ ///
+ /// Audio system SDL implementation.
+ ///
class SDLAudio : public AudioManager<SDLAudio>
{
public:
+ ///
+ /// SDL audio setting.
+ ///
struct Setting : SettingBase
{
public:
@@ -28,29 +34,95 @@ namespace JinEngine
int samples; // sample<=samplerate
};
- /* IAudio interface */
+ ///
+ /// Play all sources whose state is playing.
+ ///
void play() override;
+
+ ///
+ /// Stop and remove all sources from the queue.
+ ///
void stop() override;
+
+ ///
+ /// Pause audio.
+ ///
void pause() override;
+
+ ///
+ /// Resume audio.
+ ///
void resume() override;
+
+ ///
+ /// Set global audio volume.
+ ///
void setVolume(float volume) override;
- /* process functions*/
+
+ ///
+ /// Process all commands in the queue.
+ ///
void processCommands();
+
+ ///
+ /// Process all sources.
+ ///
+ /// @param buffer Source buffer.
+ /// @param len Source length.
+ ///
void processSources(void* buffer, size_t len);
+
+ ///
+ /// Process audio buffer.
+ ///
+ /// @param buffer Audio stream buffer.
+ /// @param len Length of stream buffer.
+ ///
void processBuffer(void* buffer, size_t len);
+
+ ///
+ /// Goon process.
+ ///
+ /// @return True if sucessful, otherwise return false.
+ ///
bool goOnProcess();
- /* thread-safe */
+
+ ///
+ /// Lock audio device.
+ ///
void lock();
+
+ ///
+ /// Unlock audio device.
+ ///
void unlock();
private:
singleton(SDLAudio);
+
+ ///
+ /// SDL audio constructor.
+ ///
SDLAudio() {};
+
+ ///
+ /// SDL audio destructor.
+ ///
~SDLAudio() {};
- /* subsystem interface */
+
+ ///
+ /// Initialize audio system.
+ ///
+ /// @param setting Audio setting.
+ ///
bool initSystem(const SettingBase* setting) override;
+
+ ///
+ /// Quit audio system.
+ ///
void quitSystem() override;
+ // Audio device id.
unsigned int audioDevice;
};
@@ -59,4 +131,5 @@ namespace JinEngine
} // namespace JinEngine
#endif // LIBJIN_MODULES_AUDIO && LIBJIN_AUDIO_SDLAUDIO
-#endif // __JE_AUDIO_SDL_H
+
+#endif // __JE_AUDIO_SDL_H \ No newline at end of file
diff --git a/src/libjin/Audio/SDL/je_sdl_source.cpp b/src/libjin/Audio/SDL/je_sdl_source.cpp
index 210d058..8f4a2dc 100644
--- a/src/libjin/Audio/SDL/je_sdl_source.cpp
+++ b/src/libjin/Audio/SDL/je_sdl_source.cpp
@@ -233,10 +233,9 @@ namespace JinEngine
ActionFloat(SetVolume, clamp(volume, 0.0f, 1.0f));
}
- bool SDLSource::setLoop(bool loop)
+ void SDLSource::setLoop(bool loop)
{
ActionBool(SetLoop, loop);
- return false;
}
void SDLSource::setRate(float rate)
diff --git a/src/libjin/Audio/SDL/je_sdl_source.h b/src/libjin/Audio/SDL/je_sdl_source.h
index b32ecce..fe6abc3 100644
--- a/src/libjin/Audio/SDL/je_sdl_source.h
+++ b/src/libjin/Audio/SDL/je_sdl_source.h
@@ -16,39 +16,154 @@ namespace JinEngine
{
typedef struct SDLSourceCommand;
+
class SDLSourceManager;
+ ///
+ /// Audio source SDL implementation.
+ ///
class SDLSource : public Source
{
public:
+ ///
+ /// Create source from raw source data file.
+ ///
+ /// @param file Audio source file.
+ /// @return Return source if create successful, otherwise return null.
+ ///
static SDLSource* createSource(const char* file);
+
+ ///
+ /// Create source from raw source data.
+ ///
+ /// @param mem Source data.
+ /// @param size Source data size.
+ /// @return Return source if create successful, otherwise return null.
+ ///
static SDLSource* createSource(void* mem, size_t size);
+ ///
+ /// Source destructor.
+ ///
~SDLSource();
- /* ISource interface */
+
+ ///
+ /// 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;
- bool setLoop(bool loop) 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 and process anduio clip */
+
+ ///
+ /// 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:
+ ///
+ /// Source constructor.
+ ///
SDLSource();
- /* decode raw audio data */
+
+ ///
+ /// 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 state */
- inline bool is(int state) const { return (status.state & state) == state; }
+ ///
+ /// 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ֽڳ
@@ -58,7 +173,7 @@ namespace JinEngine
int samples; // sample = size / (bitdepth / 8)
unsigned char channels; // channel1(mono)2(stereo)
} raw;
- /* Procedure controller variable */
+ // Procedure controller variable.
struct{
int pos; // ǰŵsample
int pitch; // pitch
@@ -69,22 +184,68 @@ namespace JinEngine
};
+ ///
+ /// Source manager.
+ ///
class SDLSourceManager
{
public:
+ ///
+ /// Get manager singleton.
+ ///
+ /// @return Singleton of SDL source manager.
+ ///
static SDLSourceManager* get();
- /* Process function */
+ ///
+ /// Process commands.
+ ///
void processCommands();
+
+ ///
+ /// Process sources.
+ ///
+ /// @param buffer Source data.
+ /// @param size Size of source data.
+ ///
void processSources(void* buffer, size_t size);
- /* control flow */
+
+ ///
+ /// 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 :
+ private:
std::queue<SDLSourceCommand*> commands;
std::stack<SDLSourceCommand*> commandsPool;
std::vector<SDLSource*> sources; // processing sources
@@ -94,7 +255,7 @@ namespace JinEngine
class SourceException : public std::exception
{
- const char * what() const throw ()
+ const char* what() const throw ()
{
return "Load Source Exception";
}
@@ -104,4 +265,5 @@ namespace JinEngine
} // namespace JinEngine
#endif // LIBJIN_MODULES_AUDIO && LIBJIN_AUDIO_SDLAUDIO
-#endif // __JE_SOURCE_SDL_H
+
+#endif // __JE_SOURCE_SDL_H \ No newline at end of file
diff --git a/src/libjin/Audio/je_audio_manager.h b/src/libjin/Audio/je_audio_manager.h
index 86716ef..10df08c 100644
--- a/src/libjin/Audio/je_audio_manager.h
+++ b/src/libjin/Audio/je_audio_manager.h
@@ -16,10 +16,16 @@ namespace JinEngine
class Source;
+ ///
+ /// Audio manager.
+ ///
template<class SubAudio>
class AudioManager : public Subsystem<SubAudio>
{
public:
+ ///
+ /// Audio state.
+ ///
enum State
{
PLAY ,
@@ -27,19 +33,45 @@ namespace JinEngine
PAUSE,
};
+ ///
+ /// Play all sources whose state is playing.
+ ///
virtual void play() = 0;
+
+ ///
+ /// Stop and remove all sources from the queue.
+ ///
virtual void stop() = 0;
+
+ ///
+ /// Pause audio.
+ ///
virtual void pause() = 0;
+
+ ///
+ /// Resume audio.
+ ///
virtual void resume() = 0;
+
+ ///
+ /// Set global audio volume.
+ ///
virtual void setVolume(float volume) = 0;
protected:
singleton(AudioManager);
+ ///
+ /// AudioManager constructor.
+ ///
AudioManager()
: volume(1)
, state(State::PLAY)
{};
+
+ ///
+ /// AudioManager destructor.
+ ///
virtual ~AudioManager() {};
float volume;
@@ -52,4 +84,4 @@ namespace JinEngine
#endif // LIBJIN_MODULES_AUDIO
-#endif // __JE_AUDIO_H
+#endif // __JE_AUDIO_H \ No newline at end of file
diff --git a/src/libjin/Audio/je_source.h b/src/libjin/Audio/je_source.h
index 9ef0b46..ac87c07 100644
--- a/src/libjin/Audio/je_source.h
+++ b/src/libjin/Audio/je_source.h
@@ -10,6 +10,9 @@ namespace JinEngine
namespace Audio
{
+ ///
+ /// Audio source encoding type.
+ ///
enum SourceType
{
INVALID = 0,
@@ -17,25 +20,90 @@ namespace JinEngine
OGG,
};
+ ///
+ /// Audio source.
+ ///
class Source
{
public:
+ ///
+ /// Source constructor.
+ ///
Source() {};
+
+ ///
+ /// Source destructor.
+ ///
virtual ~Source() {};
- /* interface */
- virtual void play() = 0;
+
+ ///
+ /// Start playing source.
+ ///
+ virtual void play() = 0;
+
+ ///
+ /// Stop playing source.
+ ///
virtual void stop() = 0;
+
+ ///
+ /// Pause source.
+ ///
virtual void pause() = 0;
+
+ ///
+ /// Resume source.
+ ///
virtual void resume() = 0;
+
+ ///
+ /// Rewind source.
+ ///
virtual void rewind() = 0;
+
+ ///
+ /// Whether the source is playing or not.
+ ///
virtual bool isStopped() const = 0;
+
+ ///
+ /// Whether the source is paused or not.
+ ///
virtual bool isPaused() const = 0;
+
+ ///
+ /// Set source pitch.
+ ///
+ /// @param pitch Pitch of source.
+ ///
virtual void setPitch(float pitch) = 0;
+
+ ///
+ /// Set volume of source.
+ ///
+ /// @param volume Volume of source.
+ ///
virtual void setVolume(float volume) = 0;
- virtual bool setLoop(bool loop) = 0;
+
+ ///
+ /// Set source loop.
+ ///
+ /// @param loop Looping or not.
+ ///
+ virtual void setLoop(bool loop) = 0;
+
+ ///
+ /// Set source rate.
+ ///
+ /// @param rate Rate of source.
+ ///
virtual void setRate(float rate) = 0;
protected:
+
+ ///
+ /// Get type of source data.
+ ///
static SourceType getType(const void* mem, int size);
};
@@ -44,4 +112,5 @@ namespace JinEngine
} // namespace JinEngine
#endif // LIBJIN_MODULES_AUDIO
-#endif // __JE_AUDIO_SOURCE_H
+
+#endif // __JE_AUDIO_SOURCE_H \ No newline at end of file