aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/3rdparty/wav/wav.h2
-rw-r--r--src/libjin/audio/sdl/audio.cpp4
-rw-r--r--src/libjin/audio/sdl/source.cpp131
-rw-r--r--src/libjin/audio/sdl/source.h33
-rw-r--r--src/libjin/audio/source.h2
-rw-r--r--src/libjin/common/subsystem.h2
-rw-r--r--src/libjin/utils/utils.h1
7 files changed, 156 insertions, 19 deletions
diff --git a/src/3rdparty/wav/wav.h b/src/3rdparty/wav/wav.h
index 888e522..0849dfe 100644
--- a/src/3rdparty/wav/wav.h
+++ b/src/3rdparty/wav/wav.h
@@ -32,4 +32,4 @@ enum {
int wav_read(wav_t *w, const void *data, size_t len);
const char *wav_strerror(int err);
-#endif
+#endif \ No newline at end of file
diff --git a/src/libjin/audio/sdl/audio.cpp b/src/libjin/audio/sdl/audio.cpp
index cdf84aa..7870329 100644
--- a/src/libjin/audio/sdl/audio.cpp
+++ b/src/libjin/audio/sdl/audio.cpp
@@ -38,9 +38,9 @@ namespace audio
shared void SDLAudio::defaultCallback(void *userdata, Uint8 *stream, int size)
{
- SDLAudio* audio = (SDLAudio*)userdata;
+ SDLAudio* audio = (SDLAudio*)userdata;
int16_t* buffer = (int16_t*)stream;
- int len = size >> 1;
+ int len = size >> 1;
audio->processSources(len);
}
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;
+ }
+ }
+ }
}
}
diff --git a/src/libjin/audio/sdl/source.h b/src/libjin/audio/sdl/source.h
index 0c8e938..682ff50 100644
--- a/src/libjin/audio/sdl/source.h
+++ b/src/libjin/audio/sdl/source.h
@@ -1,6 +1,10 @@
#ifndef __JIN_SOURCE_SDL_H
#define __JIN_SOURCE_SDL_H
+#include <vector>
+#include <queue>
+#include <stack>
+
#include "3rdparty/wav/wav.h"
#define STB_VORBIS_HEADER_ONLY
#include "3rdparty/stb/stb_vorbis.c"
@@ -37,9 +41,14 @@ namespace audio
bool setLoop(bool loop) override;
void setRate(float rate) override;
+ /* process function */
+ static void processCommand();
+ static void processSource();
+ static void removeSource(SDLSource* source);
+
private:
- typedef struct Command
+ struct Command
{
typedef enum Action
{
@@ -50,16 +59,34 @@ namespace audio
Resume,
Rewind,
SetVolume,
+ SetLoop,
+ SetRate,
};
Action action;
union {
int _integer;
+ float _float;
bool _boolean;
const char* _string;
- } parameter;
+ };
+ SDLSource* source;
};
- Command command;
+ static std::queue<Command*> commands;
+ static std::stack<Command*> commandsPool;
+ static Command* getCommand();
+ static void collectCommand(Command* cmd);
+
+ static std::vector<SDLSource*> sources;
+
+ void* data;
+ void* pos;
+ int length;
+ int pitch;
+ bool paused;
+ bool playing;
+ bool stopped;
+
};
}
diff --git a/src/libjin/audio/source.h b/src/libjin/audio/source.h
index 1929f76..4ed8752 100644
--- a/src/libjin/audio/source.h
+++ b/src/libjin/audio/source.h
@@ -40,8 +40,6 @@ namespace audio
Source();
virtual ~Source();
- private:
-
};
}
diff --git a/src/libjin/common/subsystem.h b/src/libjin/common/subsystem.h
index 8c1b59b..abe509e 100644
--- a/src/libjin/common/subsystem.h
+++ b/src/libjin/common/subsystem.h
@@ -21,7 +21,7 @@ namespace jin
protected:
- Subsystem() {};
+ Subsystem() {};
virtual ~Subsystem() {};
virtual onlyonce bool _init(const Setting* setting) = 0;
diff --git a/src/libjin/utils/utils.h b/src/libjin/utils/utils.h
index d597c83..9073d59 100644
--- a/src/libjin/utils/utils.h
+++ b/src/libjin/utils/utils.h
@@ -1,7 +1,6 @@
#ifndef __JIN_UTILS_H
#define __JIN_UTILS_H
-
#include "macros.h"
#include "endian.h"