Added threading
This commit is contained in:
24
sound.c
24
sound.c
@@ -1,12 +1,26 @@
|
||||
#include <ao/ao.h>
|
||||
#include <mpg123.h>
|
||||
|
||||
#include <pthread.h>
|
||||
#include <error.h>
|
||||
#include <string.h>
|
||||
#include <ncurses.h>
|
||||
|
||||
#include "sound.h"
|
||||
|
||||
#include "config.h"
|
||||
#define BITS 8
|
||||
|
||||
|
||||
void playSound(const char *path) {
|
||||
pthread_t pth; //thread identifier
|
||||
//Create thread
|
||||
pthread_create(&pth, NULL, playThreadFunc, (void *) path);
|
||||
pthread_detach(pth); //detach to call this function multiple times
|
||||
}
|
||||
|
||||
|
||||
void *playThreadFunc(void *arg) {
|
||||
const char *path = (const char *) arg;
|
||||
|
||||
mpg123_handle *mh;
|
||||
unsigned char *buffer;
|
||||
size_t buffer_size;
|
||||
@@ -50,5 +64,9 @@ void playSound(const char *path) {
|
||||
mpg123_close(mh);
|
||||
mpg123_delete(mh);
|
||||
mpg123_exit();
|
||||
ao_shutdown();
|
||||
//ao_shutdown(); //don't call inside a thread
|
||||
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user