更新star,stop语音采集控制逻辑
This commit is contained in:
parent
96db686de5
commit
64d5078780
|
@ -10,7 +10,7 @@ static PCMContainer_t g_pcmParam;
|
||||||
static apr_aiwrap_t* g_aprHandle;
|
static apr_aiwrap_t* g_aprHandle;
|
||||||
static void* g_libInterface;
|
static void* g_libInterface;
|
||||||
static pthread_t g_voiceThread;
|
static pthread_t g_voiceThread;
|
||||||
static int g_isStopVoice;
|
static int g_isStopVoice = 1;
|
||||||
|
|
||||||
#define MAX_BUF_TIME 128000
|
#define MAX_BUF_TIME 128000
|
||||||
#define NUM_CHANNELS 8
|
#define NUM_CHANNELS 8
|
||||||
|
@ -26,8 +26,10 @@ static void* voiceCB(void* arg) {
|
||||||
int len;
|
int len;
|
||||||
unsigned char* pBufData = (unsigned char*)malloc(BUFFER_SIZE);
|
unsigned char* pBufData = (unsigned char*)malloc(BUFFER_SIZE);
|
||||||
|
|
||||||
while (pBufData && g_isStopVoice) {
|
while (pBufData) {
|
||||||
usleep(1000);
|
usleep(1000);
|
||||||
|
|
||||||
|
if(g_isStopVoice == 0) {
|
||||||
len = alsa_read_tdmin_pcm(&g_pcmParam);
|
len = alsa_read_tdmin_pcm(&g_pcmParam);
|
||||||
memcpy(pBufData, g_pcmParam.data_buf, g_pcmParam.chunk_bytes);
|
memcpy(pBufData, g_pcmParam.data_buf, g_pcmParam.chunk_bytes);
|
||||||
|
|
||||||
|
@ -35,10 +37,9 @@ static void* voiceCB(void* arg) {
|
||||||
_apr_aiwrap_write(g_aprHandle, pBufData, len);
|
_apr_aiwrap_write(g_aprHandle, pBufData, len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
g_isStopVoice = 2;
|
|
||||||
pthread_detach(pthread_self());
|
pthread_detach(pthread_self());
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,33 +87,24 @@ int mic_asp_init(MicDataCallback cb) {
|
||||||
return -5;
|
return -5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pthread_create(&g_voiceThread, NULL, voiceCB, NULL) == -1) {
|
||||||
|
return -6;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int mic_asp_start() {
|
int mic_asp_start() {
|
||||||
int err = _apr_aiwrap_start(g_aprHandle);
|
int err = _apr_aiwrap_start(g_aprHandle);
|
||||||
|
|
||||||
if(err != 0) {
|
if(err == 0) {
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_isStopVoice = 0;
|
g_isStopVoice = 0;
|
||||||
|
|
||||||
if (pthread_create(&g_voiceThread, NULL, voiceCB, NULL) == -1) {
|
|
||||||
return -2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
int mic_asp_stop() {
|
int mic_asp_stop() {
|
||||||
g_isStopVoice = 1;
|
g_isStopVoice = 1;
|
||||||
|
|
||||||
while(g_isStopVoice != 2) {
|
|
||||||
usleep(1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_isStopVoice = 0;
|
|
||||||
|
|
||||||
return _apr_aiwrap_stop(g_aprHandle);
|
return _apr_aiwrap_stop(g_aprHandle);
|
||||||
}
|
}
|
Loading…
Reference in New Issue