windows support
This commit is contained in:
parent
f1cd631aae
commit
b9004acd79
16 changed files with 208 additions and 32 deletions
|
|
@ -1,4 +1,11 @@
|
|||
include(MDEPkgConfig)
|
||||
|
||||
setup_lib(audio Audio)
|
||||
target_link_libraries(
|
||||
MDEAudio
|
||||
PRIVATE
|
||||
MDECore
|
||||
)
|
||||
|
||||
find_package(PkgConfig)
|
||||
|
||||
|
|
@ -29,7 +36,7 @@ macro(check_backend uppername name)
|
|||
target_link_libraries(
|
||||
MDEAudio
|
||||
PRIVATE
|
||||
${${uppername}_LIBRARIES} pthread
|
||||
${${uppername}_LIBRARIES}
|
||||
)
|
||||
target_compile_definitions(
|
||||
MDEAudio
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ typedef struct driver_context {
|
|||
snd_pcm_hw_params_t* params;
|
||||
} driver_context_t;
|
||||
|
||||
#include "pthread/decl.c"
|
||||
#include "thread/decl.c"
|
||||
|
||||
static void drv_write(driver_t* drv, void* data, int frames) {
|
||||
if(snd_pcm_writei(drv->context.device, data, frames) == -EPIPE) {
|
||||
|
|
@ -72,5 +72,5 @@ static void drv_close(driver_t* drv) {
|
|||
}
|
||||
}
|
||||
|
||||
#include "pthread/body.c"
|
||||
#include "thread/body.c"
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ typedef struct driver_context {
|
|||
ao_device* device;
|
||||
} driver_context_t;
|
||||
|
||||
#include "pthread/decl.c"
|
||||
#include "thread/decl.c"
|
||||
|
||||
static void drv_write(driver_t* drv, void* data, int frames) {
|
||||
ao_play(drv->context.device, (char*)data, frames * 2 * 2);
|
||||
|
|
@ -42,5 +42,5 @@ static void drv_close(driver_t* drv) {
|
|||
}
|
||||
}
|
||||
|
||||
#include "pthread/body.c"
|
||||
#include "thread/body.c"
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
static void* thread_routine(void* arg) {
|
||||
static void thread_routine(void* arg) {
|
||||
driver_t* drv = arg;
|
||||
void* data;
|
||||
|
||||
|
|
@ -9,17 +9,15 @@ static void* thread_routine(void* arg) {
|
|||
|
||||
drv_write(drv, data, drv->frames);
|
||||
|
||||
pthread_mutex_lock(&drv->mutex);
|
||||
MDEMutexLock(drv->mutex);
|
||||
if(drv->quit) {
|
||||
pthread_mutex_unlock(&drv->mutex);
|
||||
MDEMutexUnlock(&drv->mutex);
|
||||
break;
|
||||
}
|
||||
pthread_mutex_unlock(&drv->mutex);
|
||||
MDEMutexUnlock(drv->mutex);
|
||||
}
|
||||
|
||||
free(data);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
MDEAudio MDEAudioOpen(MDEAudioHandler handler, void* user) {
|
||||
|
|
@ -32,7 +30,7 @@ MDEAudio MDEAudioOpen(MDEAudioHandler handler, void* user) {
|
|||
drv->user = user;
|
||||
drv->init = 0;
|
||||
|
||||
pthread_mutex_init(&drv->mutex, NULL);
|
||||
drv->mutex = MDEMutexCreate();
|
||||
|
||||
if(!(drv->init = drv_open(drv))) {
|
||||
MDEAudioClose(drv);
|
||||
|
|
@ -44,16 +42,15 @@ MDEAudio MDEAudioOpen(MDEAudioHandler handler, void* user) {
|
|||
|
||||
void MDEAudioClose(MDEAudio handle) {
|
||||
driver_t* drv = handle;
|
||||
void* ret;
|
||||
|
||||
if(drv->init) {
|
||||
pthread_mutex_lock(&drv->mutex);
|
||||
MDEMutexLock(drv->mutex);
|
||||
drv->quit = 1;
|
||||
pthread_mutex_unlock(&drv->mutex);
|
||||
pthread_join(drv->thread, &ret);
|
||||
MDEMutexLock(drv->mutex);
|
||||
MDEThreadJoin(drv->thread);
|
||||
}
|
||||
|
||||
pthread_mutex_destroy(&drv->mutex);
|
||||
MDEMutexDestroy(drv->mutex);
|
||||
|
||||
drv_close(drv);
|
||||
|
||||
|
|
@ -63,5 +60,5 @@ void MDEAudioClose(MDEAudio handle) {
|
|||
void MDEAudioStart(MDEAudio handle) {
|
||||
driver_t* drv = handle;
|
||||
|
||||
pthread_create(&drv->thread, NULL, thread_routine, handle);
|
||||
drv->thread = MDEThreadCreate(thread_routine, handle);
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#include <MDE/Audio/Audio.h>
|
||||
|
||||
#include <pthread.h>
|
||||
#include <MDE/Core/Thread.h>
|
||||
#include <MDE/Core/Mutex.h>
|
||||
|
||||
typedef struct driver {
|
||||
driver_context_t context;
|
||||
|
|
@ -11,7 +11,7 @@ typedef struct driver {
|
|||
MDEAudioHandler handler;
|
||||
void* user;
|
||||
|
||||
int quit;
|
||||
pthread_t thread;
|
||||
pthread_mutex_t mutex;
|
||||
int quit;
|
||||
MDEThread thread;
|
||||
MDEMutex mutex;
|
||||
} driver_t;
|
||||
Loading…
Add table
Add a link
Reference in a new issue