GuiLite/core/src/adapter/audio_linux.cpp

65 lines
1.0 KiB
C++
Raw Normal View History

2017-12-06 21:43:47 +08:00
#include "../../core_include/api.h"
#include "../../core_include/msg.h"
#include "../../core_include/audio.h"
#include <unistd.h>
#include <sys/types.h>
#include <stdlib.h>
#include <pthread.h>
#include <stdio.h>
typedef void(*ANDROID_PLAY_WAV)(const char* fileName);
ANDROID_PLAY_WAV gAndroidPlayWav;
typedef struct
{
AUDIO_TYPE type;
}AUDIO_REQUEST;
static c_fifo s_request_fifo("aduio fifo");
static void* render_thread(void* param)
{
while (true)
{
AUDIO_REQUEST request;
s_request_fifo.read(&request, sizeof(request));
if (AUDIO_MAX <= request.type)
{
continue;
}
if(gAndroidPlayWav)
{
2018-11-17 09:30:44 +08:00
gAndroidPlayWav("heart_beat.wav");
2017-12-06 21:43:47 +08:00
}
}
}
void c_audio::init()
{
static bool s_flag = false;
if (s_flag)
{
return;
}
unsigned long pid;
create_thread(&pid, NULL, render_thread, NULL);
s_flag = true;
}
int c_audio::play(AUDIO_TYPE type)
{
if (AUDIO_MAX <= type)
{
return -1;
}
init();
AUDIO_REQUEST request;
request.type = type;
s_request_fifo.write(&request, sizeof(request));
return 0;
}