aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/audio/sdl/source.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-05-23 08:26:48 +0800
committerchai <chaifix@163.com>2018-05-23 08:26:48 +0800
commit6cc59854d349a02263a5d27810fb824a9f4d1fde (patch)
tree6603725cdf07ca1ee3c3ce27b75619a8fa436c88 /src/libjin/audio/sdl/source.cpp
parent904e78d568bae0afe87d20cb412bdce38d550c1a (diff)
更新音频模块
Diffstat (limited to 'src/libjin/audio/sdl/source.cpp')
-rw-r--r--src/libjin/audio/sdl/source.cpp131
1 files changed, 122 insertions, 9 deletions
diff --git a/src/libjin/audio/sdl/source.cpp b/src/libjin/audio/sdl/source.cpp
index c36346c..ecdf5b5 100644
--- a/src/libjin/audio/sdl/source.cpp
+++ b/src/libjin/audio/sdl/source.cpp
@@ -1,3 +1,4 @@
+#include "../../utils/macros.h"
#include "source.h"
namespace jin
@@ -5,26 +6,138 @@ namespace jin
namespace audio
{
+ shared std::queue<SDLSource::Command*> SDLSource::commands;
+ shared std::stack<SDLSource::Command*> SDLSource::commandsPool;
+
void SDLSource::generateSamples(Uint8* streamIn, int len)
{
}
- void SDLSource::play() {}
- void SDLSource::stop() {}
- void SDLSource::pause() {}
- void SDLSource::resume() {}
- void SDLSource::rewind() {}
- void SDLSource::isStopped() const {}
+#define ActionNone(T)\
+do{\
+Command* cmd = getCommand(); \
+cmd->action = Command::Action::T; \
+cmd->source = this; \
+commands.push(cmd); \
+} while (0)
+
+#define ActionArg(T, ARGT, ARG)\
+do{\
+Command* cmd = getCommand(); \
+cmd->action = Command::Action::T; \
+cmd->ARGT = ARG; \
+cmd->source = this; \
+commands.push(cmd); \
+}while(0)
+
+#define ActionInt(T, INT) ActionArg(T, _integer, INT)
+#define ActionFloat(T, FLT) ActionArg(T, _float, FLT)
+#define ActionString(T, STR) ActionArg(T, _string, STR)
+#define ActionBool(T, BOL) ActionArg(T, _boolean, BOL)
+
+ void SDLSource::play()
+ {
+ ActionNone(Play);
+ }
+
+ void SDLSource::stop()
+ {
+ ActionNone(Stop);
+ }
+
+ void SDLSource::pause()
+ {
+ ActionNone(Pause);
+ }
+
+ void SDLSource::resume()
+ {
+ ActionNone(Resume);
+ }
+
+ void SDLSource::rewind()
+ {
+ ActionNone(Rewind);
+ }
+
+ void SDLSource::isStopped() const
+ {
+
+ }
+
void SDLSource::isPaused() const {}
+
void SDLSource::isFinished() const {}
- void SDLSource::setPitch(float pitch) {}
- void SDLSource::setVolume(float volume) {}
+
+ void SDLSource::setPitch(float pitch)
+ {
+ }
+
+ void SDLSource::setVolume(float volume)
+ {
+ ActionFloat(SetVolume, volume);
+ }
+
bool SDLSource::setLoop(bool loop)
{
+ ActionFloat(SetLoop, loop);
return false;
}
- void SDLSource::setRate(float rate) {}
+
+ void SDLSource::setRate(float rate)
+ {
+ ActionFloat(SetRate, rate);
+ }
+
+ shared SDLSource::Command* SDLSource::getCommand()
+ {
+ if (!commandsPool.empty())
+ {
+ Command* cmd = commandsPool.top();
+ commandsPool.pop();
+ }
+ return new Command();
+ }
+
+ shared void SDLSource::collectCommand(SDLSource::Command* cmd)
+ {
+ if (cmd != nullptr && cmd != NULL)
+ {
+ commandsPool.push(cmd);
+ }
+ }
+
+ shared void SDLSource::processCommand()
+ {
+ Command* cmd = NULL;
+ Source* source = NULL;
+ while (!commands.empty())
+ {
+ cmd = commands.front();
+ source = cmd->source;
+
+ commands.pop();
+ }
+ }
+
+ shared void SDLSource::processSource()
+ {
+
+ }
+
+ shared void SDLSource::removeSource(SDLSource* source)
+ {
+ std::vector<SDLSource*>::iterator it = sources.begin();
+ for (it = sources.begin(); it != sources.end(); ++it)
+ {
+ if (*it == source)
+ {
+ sources.erase(it);
+ return;
+ }
+ }
+ }
}
}