stuff
This commit is contained in:
parent
a88fce53e2
commit
8e5b90f9aa
11 changed files with 51 additions and 35 deletions
|
|
@ -11,7 +11,7 @@ namespace fishbone {
|
|||
|
||||
namespace fishbone {
|
||||
class Mixer {
|
||||
fishbone::Mutex mutex;
|
||||
fishbone::Mutex* mutex;
|
||||
|
||||
public:
|
||||
Mixer();
|
||||
|
|
|
|||
|
|
@ -10,17 +10,10 @@ namespace fishbone {
|
|||
#include <fishbone/machdep.h>
|
||||
#include <fishbone/mixer.h>
|
||||
|
||||
#ifdef _FISHBONE
|
||||
#if defined(FISHBONE_SOUND_USE_SDL2)
|
||||
typedef size_t FISHBONE_SOUNDDRV_HANDLE;
|
||||
#endif
|
||||
#else
|
||||
typedef void* FISHBONE_SOUNDDRV_HANDLE;
|
||||
#endif
|
||||
|
||||
namespace fishbone {
|
||||
class SoundDriver {
|
||||
FISHBONE_SOUNDDRV_HANDLE sound;
|
||||
struct Impl;
|
||||
Impl* impl;
|
||||
|
||||
public:
|
||||
SoundDriver();
|
||||
|
|
|
|||
|
|
@ -8,19 +8,10 @@ namespace fishbone {
|
|||
|
||||
#include <fishbone/machdep.h>
|
||||
|
||||
#ifdef _FISHBONE
|
||||
#if defined(FISHBONE_THREAD_USE_SDL2)
|
||||
typedef SDL_mutex* FISHBONE_MUTEX_HANDLE;
|
||||
typedef SDL_Thread* FISHBONE_THREAD_HANDLE;
|
||||
#endif
|
||||
#else
|
||||
typedef void* FISHBONE_MUTEX_HANDLE;
|
||||
typedef void* FISHBONE_THREAD_HANDLE;
|
||||
#endif
|
||||
|
||||
namespace fishbone {
|
||||
class Thread {
|
||||
FISHBONE_THREAD_HANDLE thread;
|
||||
struct Impl;
|
||||
Impl* impl;
|
||||
|
||||
public:
|
||||
Thread(void (*call)(fishbone::Thread* thread, void* arg), void* arg);
|
||||
|
|
@ -30,7 +21,8 @@ namespace fishbone {
|
|||
};
|
||||
|
||||
class Mutex {
|
||||
FISHBONE_MUTEX_HANDLE mutex;
|
||||
struct Impl;
|
||||
Impl* impl;
|
||||
|
||||
public:
|
||||
Mutex();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include <fishbone/foundation.h>
|
||||
|
||||
fishbone::Mixer::Mixer() {
|
||||
this->mutex = new fishbone::Mutex();
|
||||
}
|
||||
|
||||
fishbone::Mixer::~Mixer() {
|
||||
|
|
@ -10,14 +11,26 @@ fishbone::Mixer::~Mixer() {
|
|||
for(int i = 0; i < this->loaders.size(); i++) {
|
||||
delete this->loaders[i];
|
||||
}
|
||||
|
||||
delete this->mutex;
|
||||
}
|
||||
|
||||
void fishbone::Mixer::read(short* buffer, size_t frames) {
|
||||
float* tmp = new float[frames * 2];
|
||||
|
||||
for(int i = 0; i < frames * 2; i++) tmp[i] = 0;
|
||||
|
||||
this->mutex->lock();
|
||||
this->mutex->unlock();
|
||||
|
||||
for(int i = 0; i < frames * 2; i++) buffer[i] = tmp[i] * 32767;
|
||||
|
||||
delete tmp;
|
||||
}
|
||||
|
||||
fishbone::Sound* fishbone::Mixer::open(const char* path) {
|
||||
for(int i = 0; i < this->loaders.size(); i++) {
|
||||
// this->loaders[i]->open();
|
||||
//this->loaders[i]->open();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
|
|
|
|||
|
|
@ -5,13 +5,17 @@
|
|||
static int sdl_audio_init = 0;
|
||||
|
||||
static void SDLCALL sound_callback(void* userdata, Uint8* stream, int len) {
|
||||
fishbone::Mixer* mixer = (fishbone::Mixer*)userdata;
|
||||
fishbone::SoundDriver* sd = (fishbone::SoundDriver*)userdata;
|
||||
|
||||
SDL_memset(stream, 0, len);
|
||||
|
||||
mixer->read((short*)stream, len / 4);
|
||||
sd->mixer.read((short*)stream, len / 4);
|
||||
}
|
||||
|
||||
struct fishbone::SoundDriver::Impl {
|
||||
SDL_AudioDeviceID id;
|
||||
};
|
||||
|
||||
fishbone::SoundDriver::SoundDriver() {
|
||||
SDL_AudioSpec spec;
|
||||
|
||||
|
|
@ -29,13 +33,15 @@ fishbone::SoundDriver::SoundDriver() {
|
|||
spec.callback = sound_callback;
|
||||
spec.userdata = this;
|
||||
|
||||
if((this->sound = SDL_OpenAudioDevice(NULL, 0, &spec, NULL, 0)) > 0) {
|
||||
SDL_PauseAudioDevice(this->sound, 0);
|
||||
this->impl = new fishbone::SoundDriver::Impl();
|
||||
|
||||
if((this->impl->id = SDL_OpenAudioDevice(NULL, 0, &spec, NULL, 0)) > 0) {
|
||||
SDL_PauseAudioDevice(this->impl->id, 0);
|
||||
}
|
||||
}
|
||||
|
||||
fishbone::SoundDriver::~SoundDriver() {
|
||||
SDL_PauseAudioDevice(this->sound, 1);
|
||||
SDL_CloseAudioDevice(this->sound);
|
||||
SDL_PauseAudioDevice(this->impl->id, 1);
|
||||
SDL_CloseAudioDevice(this->impl->id);
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
0
engine/src/soundldr/flac.cc
Normal file
0
engine/src/soundldr/flac.cc
Normal file
0
engine/src/soundldr/mod.cc
Normal file
0
engine/src/soundldr/mod.cc
Normal file
0
engine/src/soundldr/mp3.cc
Normal file
0
engine/src/soundldr/mp3.cc
Normal file
0
engine/src/soundldr/wav.cc
Normal file
0
engine/src/soundldr/wav.cc
Normal file
0
engine/src/soundldr/xm.cc
Normal file
0
engine/src/soundldr/xm.cc
Normal file
|
|
@ -18,6 +18,10 @@ static int SDLCALL thread_call(void* data) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
struct fishbone::Thread::Impl {
|
||||
SDL_Thread* thread;
|
||||
};
|
||||
|
||||
fishbone::Thread::Thread(void (*call)(fishbone::Thread* thread, void* arg), void* arg) {
|
||||
struct call_arg* data = new struct call_arg();
|
||||
|
||||
|
|
@ -25,7 +29,8 @@ fishbone::Thread::Thread(void (*call)(fishbone::Thread* thread, void* arg), void
|
|||
data->thread = this;
|
||||
data->arg = arg;
|
||||
|
||||
this->thread = SDL_CreateThread(thread_call, "FBThread", data);
|
||||
this->impl = new fishbone::Thread::Impl();
|
||||
this->impl->thread = SDL_CreateThread(thread_call, "FBThread", data);
|
||||
}
|
||||
|
||||
fishbone::Thread::~Thread() {
|
||||
|
|
@ -33,22 +38,29 @@ fishbone::Thread::~Thread() {
|
|||
}
|
||||
|
||||
void fishbone::Thread::join() {
|
||||
SDL_WaitThread(this->thread, nullptr);
|
||||
SDL_WaitThread(this->impl->thread, nullptr);
|
||||
}
|
||||
|
||||
struct fishbone::Mutex::Impl {
|
||||
SDL_mutex* mutex;
|
||||
};
|
||||
|
||||
fishbone::Mutex::Mutex() {
|
||||
this->mutex = SDL_CreateMutex();
|
||||
this->impl = new fishbone::Mutex::Impl();
|
||||
this->impl->mutex = SDL_CreateMutex();
|
||||
}
|
||||
|
||||
fishbone::Mutex::~Mutex() {
|
||||
SDL_DestroyMutex(this->mutex);
|
||||
SDL_DestroyMutex(this->impl->mutex);
|
||||
|
||||
delete this->impl;
|
||||
}
|
||||
|
||||
void fishbone::Mutex::lock() {
|
||||
SDL_LockMutex(this->mutex);
|
||||
SDL_LockMutex(this->impl->mutex);
|
||||
}
|
||||
|
||||
void fishbone::Mutex::unlock() {
|
||||
SDL_UnlockMutex(this->mutex);
|
||||
SDL_UnlockMutex(this->impl->mutex);
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue