Added threading

This commit is contained in:
2017-12-15 16:10:36 +01:00
parent 4651ee674a
commit 27233290cf
6 changed files with 53 additions and 11 deletions

24
sound.c
View File

@@ -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);
}