-
This commit is contained in:
@@ -5,7 +5,10 @@ all:
|
||||
(cd build; make)
|
||||
|
||||
install:
|
||||
(cd build; cp *.so /usr/local/lib)
|
||||
mkdir -p ../lib
|
||||
FILES=`ls build/*.so` 2>/dev/null; if [ "$$FILES" != "" ]; then cp $$FILES ../lib; fi
|
||||
FILES=`ls build/*.dll` 2>/dev/null; if [ "$$FILES" != "" ]; then cp $$FILES ../lib; fi
|
||||
|
||||
|
||||
clean:
|
||||
rm -rf build
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <assert.h>
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
#include <dlfcn.h>
|
||||
//#include <dlfcn.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -26,15 +26,17 @@ typedef struct _queue_ {
|
||||
} Queue_t;
|
||||
|
||||
typedef struct {
|
||||
Queue_t *play_queue;
|
||||
Queue_t *last_frame;
|
||||
ao_device *ao_device;
|
||||
Queue_t *play_queue;
|
||||
Queue_t *last_frame;
|
||||
ao_device *ao_device;
|
||||
pthread_mutex_t mutex;
|
||||
pthread_t thread;
|
||||
double at_second;
|
||||
pthread_t thread;
|
||||
double at_second;
|
||||
ao_play_func_t ao_play_f;
|
||||
int buf_size;
|
||||
} AO_Handle;
|
||||
|
||||
static int(*ao_play)(void *device, char *samples, uint32_t n) = NULL;
|
||||
//static int(*ao_play)(void *device, char *samples, uint32_t n) = NULL;
|
||||
|
||||
|
||||
static Queue_t *front(AO_Handle *h)
|
||||
@@ -53,6 +55,7 @@ static Queue_t *get(AO_Handle *h)
|
||||
} else {
|
||||
h->play_queue->prev = NULL;
|
||||
}
|
||||
h->buf_size -= q->buflen;
|
||||
return q;
|
||||
}
|
||||
|
||||
@@ -69,6 +72,7 @@ static void add(AO_Handle *h, Queue_t *elem)
|
||||
elem->next = NULL;
|
||||
h->last_frame = elem;
|
||||
}
|
||||
h->buf_size += elem->buflen;
|
||||
}
|
||||
|
||||
static Queue_t *new_elem(int command, double at_second, int buf_len, void *buf)
|
||||
@@ -125,7 +129,7 @@ static void *run(void *arg)
|
||||
if (q->command == STOP) {
|
||||
go_on = (1 == 0);
|
||||
} else {
|
||||
ao_play(handle->ao_device, q->buf, q->buflen);
|
||||
handle->ao_play_f(handle->ao_device, q->buf, q->buflen);
|
||||
}
|
||||
|
||||
del_elem(q);
|
||||
@@ -138,6 +142,7 @@ static void *run(void *arg)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
static void get_ao_play(void)
|
||||
{
|
||||
char *lib = "libao.so";
|
||||
@@ -155,11 +160,12 @@ static void get_ao_play(void)
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
void *ao_create_async(void *ao_device_yeah)
|
||||
void *ao_create_async(void *ao_device_yeah, void *ao_play_f)
|
||||
{
|
||||
if (ao_play == NULL) { get_ao_play(); }
|
||||
//if (ao_play == NULL) { get_ao_play(); }
|
||||
|
||||
AO_Handle *handle = (AO_Handle *) malloc(sizeof(AO_Handle));
|
||||
|
||||
@@ -169,6 +175,8 @@ void *ao_create_async(void *ao_device_yeah)
|
||||
handle->at_second = -1;
|
||||
pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
|
||||
handle->mutex = m;
|
||||
handle->ao_play_f = ao_play_f;
|
||||
handle->buf_size = 0;
|
||||
|
||||
pthread_create(&handle->thread, NULL, run, handle);
|
||||
|
||||
@@ -202,8 +210,19 @@ void ao_play_async(void *ao_handle, double at_second, int buf_size, void *mem)
|
||||
double ao_is_at_second_async(void *ao_handle)
|
||||
{
|
||||
AO_Handle *h = (AO_Handle *) ao_handle;
|
||||
return h->at_second;
|
||||
pthread_mutex_lock(&h->mutex);
|
||||
double s = h->at_second;
|
||||
pthread_mutex_unlock(&h->mutex);
|
||||
return s;
|
||||
}
|
||||
|
||||
int ao_bufsize_async(void *ao_handle)
|
||||
{
|
||||
AO_Handle *h = (AO_Handle *) ao_handle;
|
||||
pthread_mutex_lock(&h->mutex);
|
||||
int s = h->buf_size;
|
||||
pthread_mutex_unlock(&h->mutex);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
#ifndef AO_PLAYASYNC_H
|
||||
#define AO_PLAYASYNC_H
|
||||
|
||||
extern void *ao_create_async(void *ao_handle);
|
||||
#include <stdint.h>
|
||||
|
||||
typedef int(*ao_play_func_t)(void *, char *, uint32_t);
|
||||
|
||||
extern void *ao_create_async(void *ao_handle, void *ao_play_f);
|
||||
extern void ao_stop_async(void *handle);
|
||||
extern void ao_play_async(void *handle, double at_second, int buf_size, void *mem);
|
||||
extern double ao_is_at_second_async(void *handle);
|
||||
extern int ao_bufsize_async(void *handle);
|
||||
|
||||
#endif // AO_PLAYASYNC_H
|
||||
|
||||
BIN
libao/lib/libao-play-async.so
Executable file
BIN
libao/lib/libao-play-async.so
Executable file
Binary file not shown.
@@ -5,27 +5,32 @@
|
||||
ffi/unsafe/define
|
||||
setup/dirs
|
||||
"../utils/utils.rkt"
|
||||
racket/runtime-path
|
||||
"libao-ffi.rkt"
|
||||
)
|
||||
|
||||
(provide ao_create_async
|
||||
ao_stop_async
|
||||
ao_play_async
|
||||
ao_is_at_second_async
|
||||
ao_bufsize_async
|
||||
)
|
||||
|
||||
;(ffi-lib "/usr/local/lib/libao-play-async.so")
|
||||
(define-runtime-path libao-async-path "./lib/libao-play-async")
|
||||
|
||||
(define-ffi-definer define-libao-async
|
||||
(ffi-lib "libao-play-async" '("0" #f)
|
||||
#:get-lib-dirs (lambda ()
|
||||
(cons (build-path ".") (get-lib-search-dirs)))
|
||||
(ffi-lib libao-async-path '("0" #f)
|
||||
#:get-lib-dirs (λ ()
|
||||
(let ((sp (cons (build-path ".") (get-lib-search-dirs))))
|
||||
(displayln sp)
|
||||
sp))
|
||||
#:fail (λ () (error "Cannot load libao-play-async"))
|
||||
))
|
||||
|
||||
(define _libao-async-handle-pointer (_cpointer 'ao-async-handle))
|
||||
|
||||
;extern void *ao_create_async(void *ao_device);
|
||||
(define-libao-async ao_create_async(_fun _pointer -> _libao-async-handle-pointer))
|
||||
;extern void *ao_create_async(void *ao_device, );
|
||||
(define-libao-async ao_create_async(_fun _pointer _fpointer -> _libao-async-handle-pointer))
|
||||
|
||||
;extern void ao_stop_async(void *handle);
|
||||
(define-libao-async ao_stop_async(_fun _libao-async-handle-pointer -> _void))
|
||||
@@ -35,3 +40,6 @@
|
||||
|
||||
;extern double ao_is_at_second_async(void *handle);
|
||||
(define-libao-async ao_is_at_second_async(_fun _libao-async-handle-pointer -> _double))
|
||||
|
||||
;extern int ao_bufsize_async(void *handle);
|
||||
(define-libao-async ao_bufsize_async(_fun _libao-async-handle-pointer -> _int))
|
||||
@@ -13,6 +13,7 @@
|
||||
ao_driver_id
|
||||
ao_open_live
|
||||
ao_play
|
||||
ao_play_ptr
|
||||
ao_close
|
||||
ao_shutdown
|
||||
ao_append_option
|
||||
@@ -26,15 +27,18 @@
|
||||
)
|
||||
|
||||
|
||||
(define-ffi-definer define-libao
|
||||
(ffi-lib "libao" '("3" "4" "5" #f)
|
||||
#:get-lib-dirs (lambda ()
|
||||
(cons (build-path ".") (get-lib-search-dirs)))
|
||||
#:fail (lambda ()
|
||||
(ffi-lib (get-lib-path "libao-4.dll")))
|
||||
))
|
||||
(define ao_lib (ffi-lib "libao" '("3" "4" "5" #f)
|
||||
#:get-lib-dirs (λ ()
|
||||
(let ((sp (cons (build-path ".") (get-lib-search-dirs))))
|
||||
(displayln sp)
|
||||
sp))
|
||||
#:fail (λ ()
|
||||
(ffi-lib (get-lib-path "libao-4.dll")))
|
||||
))
|
||||
|
||||
|
||||
(define-ffi-definer define-libao ao_lib)
|
||||
|
||||
(define _libao-pointer (_cpointer 'ao_device))
|
||||
(define-cstruct _ao_sample_format (
|
||||
[bits _int] ; bits per sample
|
||||
@@ -66,6 +70,10 @@
|
||||
; int ao_play(ao_device *device, char *output_samples, uint_32 num_bytes);
|
||||
(define-libao ao_play (_fun _libao-pointer _pointer _uint32 -> _int))
|
||||
|
||||
(define ao_play_ptr (get-ffi-obj "ao_play" ao_lib _fpointer
|
||||
(λ () (error 'ao_lib "libao does not provide 'ao_play'"))
|
||||
))
|
||||
|
||||
; int ao_close(ao_device *device);
|
||||
(define-libao ao_close (_fun _libao-pointer -> _int))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user