static int record(inputThread_t *p_thread) { int ret = 0; int32 ts; //get audioBuffer for audioQueue audioBuffer_t *resultBuf = reserveAudioBuffer(); ret = initAudioBuffer(resultBuf); if(ret != 0) { PRINT_ERR("Failed to init resultBuf %d).\n", ret); return ret; } //start recording from audiodevice p_thread->listenState = INPUT_LISTENING; ret = ad_start_rec(p_thread->audioDevice); if (ret < 0) { PRINT_ERR("Could not start recording audio (%d).\n", ret); return ret; } //EXEC HOLD_TIME_TAKING(inputExecutionTime); //check if not silent while (((ret = cont_ad_read(p_thread->contAudioDevice, p_thread->inputBuffer, INPUT_BUFFER_SIZE)) == 0) && p_thread->keepRunning ) usleep(10000); //EXEC RESUME_TIME_TAKING(inputExecutionTime); RESTART_TIME_TAKING(totalReactionTime); RESTART_TIME_TAKING(inputReactionTime); ts = p_thread->contAudioDevice->read_ts; p_thread->listenState = INPUT_PROCESSING; //add read audio data to audioBuffer addAudioBuffer(resultBuf, p_thread->inputBuffer, ret); while(p_thread->keepRunning) { ret = cont_ad_read(p_thread->contAudioDevice, p_thread->inputBuffer, INPUT_BUFFER_SIZE); if (ret < 0) { //something went wrong PRINT_ERR("Failed to record audio (%d).\n", ret); break; } else if(ret > 0) { // valid speech data read // get new timestamp ts = p_thread->contAudioDevice->read_ts; addAudioBuffer(resultBuf, p_thread->inputBuffer, ret); if(isFullAudioBuffer(resultBuf)) { PRINT_INFO("AudioBuffer is full!\n"); break; } } else { //no data if(sphinxTimestampDiff(ts, p_thread->contAudioDevice->read_ts) >= MS_TO_SAMPLES(SILENCE_MS)) break; else usleep(10000); } } ad_stop_rec(p_thread->audioDevice); p_thread->listenState = INPUT_WAITING; while (ad_read(p_thread->audioDevice, p_thread->inputBuffer, INPUT_BUFFER_SIZE) >= 0); cont_ad_reset(p_thread->contAudioDevice); //EXEC HOLD_TIME_TAKING(inputExecutionTime); RESTART_TIME_TAKING(interpreterReactionTime); // enqueuing can also block enqueueBlockingQueue(p_thread->audioQueue, (void*) resultBuf); //EXEC RESUME_TIME_TAKING(inputExecutionTime); STOP_TIME_TAKING(inputReactionTime); return ret; }
int main() { //SD device initialization up_dev.device_reference = NULL; while(!loadSDCard(up_dev.device_reference)) { printf("SD card is not connected.\n"); } initVGA(); initAudioDeviceController(); initSoundMixer(); struct CmdScheduler* scheduler = initCmdScheduler(); //Serial device initialization com = initRS232(scheduler); initPushKeyController(); initDatabase(); initMemory(); //sync database update(); //Test VGA Output /*struct Image* testImg; while((testImg = loadSDImage("TEST.BMP")) == NULL); draw(35, 35, testImg); killImage(testImg);*/ //alt_up_char_buffer_string(char_buffer, "Initialization Completed", 27, 5); alt_up_pixel_buffer_dma_clear_screen(pixel_buffer, 0); alt_up_char_buffer_clear(char_buffer); //graphicTester(); struct Frame* mainFrame = initMainFrame(); mainFrame->drawFrame(mainFrame); //Test End mouse = initCursor(10, 100, mainFrame); //graphicTester(); //drawAllSongsInList(2); //drawAllSongsInList(2); /*int i; struct Frame* b; for (i = 0; i < 5000; i++){ drawAllSongsInList(2); //b = initSongInListPanel(mainFrame, 2); //killSongInListPanel(&b); printf("Iteration %d\n", i); }*/ initAudioBuffer(); initAnimate(mouse); int i = 2; syncPlay(1, 100, 0); while(1) { cmdProcessing(scheduler); i = soundTester(i); } return 0; }