#include <sent/stddefs.h>
#include <sent/speech.h>
#include <sent/adin.h>
#include <pthread.h>
Include dependency graph for adin-cut.c:
Go to the source code of this file.
Variables of zero-cross parameters and buffer sizes | |
static int | c_length = 5000 |
Computed length of cycle buffer for zero-cross, actually equals to head margin length. | |
static int | c_offset = 0 |
Static data DC offset (obsolute, should be 0). | |
static int | wstep = DEFAULT_WSTEP |
Data fragment size. | |
static int | thres |
Input Level threshold (0-32767). | |
static int | noise_zerocross |
Computed threshold of zerocross num in the cycle buffer. | |
static int | nc_max |
Computed number of fragments for tail margin. | |
Variables for delayed tail silence processing | |
static SP16 * | swapbuf |
Buffer for re-triggering in tail margin. | |
static int | sbsize |
static int | sblen |
Size and current length of swapbuf. | |
static int | rest_tail |
Samples not processed yet in swap buffer. | |
Work area for device configurations for local use | |
static boolean(* | ad_resume )() |
Function pointer to (re)start input. | |
static boolean(* | ad_pause )() |
Function pointer to stop input. | |
static int(* | ad_read )(SP16 *, int) |
Function pointer to read in input samples. | |
static boolean | adin_cut_on |
TRUE if do input segmentation by silence. | |
static boolean | silence_cut_default |
Device-dependent default value of adin_cut_on(). | |
static boolean | strip_flag |
TRUE if skip invalid zero samples. | |
static boolean | enable_thread = FALSE |
TRUE if input device needs threading. | |
static boolean | ignore_speech_while_recog = TRUE |
TRUE if ignore speech input between call, while waiting recognition process. | |
static boolean | need_zmean |
TRUE if perform zmeansource. | |
Variables related to POSIX threading | |
static pthread_t | adin_thread |
Thread information. | |
static pthread_mutex_t | mutex |
Lock primitive. | |
static SP16 * | speech |
Unprocessed samples recorded by A/D-in thread. | |
static int | speechlen |
Current length of speech. | |
static boolean | transfer_online = FALSE |
Semaphore to start/stop recognition. | |
static boolean | adinthread_buffer_overflowed = FALSE |
Will be set to TRUE if speech has been overflowed. | |
Input data buffer | |
static SP16 * | buffer = NULL |
Temporary buffer to hold input samples. | |
static int | bpmax |
Maximum length of buffer. | |
static int | bp |
Current point to store the next data. | |
static int | current_len |
Current length of stored samples. | |
static SP16 * | cbuf |
Buffer for flushing cycle buffer just after detecting trigger. | |
Functions | |
static void | adin_thread_create () |
create and start A/D-in and detection thread | |
void | adin_setup_func (int(*cad_read)(SP16 *, int), boolean(*cad_pause)(), boolean(*cad_resume)(), boolean use_cut_def, boolean need_thread) |
void | adin_setup_param (int silence_cut, boolean strip_zero, int cthres, int czc, int head_margin, int tail_margin, int sample_freq, boolean ignore_speech, boolean need_zeromean) |
boolean | query_segment_on () |
boolean | query_thread_on () |
void | adin_reset_zmean () |
static void | adin_purge (int from) |
static int | adin_cut (int(*ad_process)(SP16 *, int), int(*ad_check)()) |
Main A/D-in function. | |
static int | adin_store_buffer (SP16 *now, int len) |
void | adin_thread_input_main (void *dummy) |
static int | adin_thread_process (int(*ad_process)(SP16 *, int), int(*ad_check)()) |
Main function of processing triggered samples at main thread. | |
int | adin_go (int(*ad_process)(SP16 *, int), int(*ad_check)()) |
Top function to start input processing. |
Speech detection is based on level threshold and zero cross count. The number of zero cross are counted for each incoming speech fragment. If the number becomes larger than specified threshold, the fragment is treated as a beginning of speech input (trigger on). If the number goes below the threshold, the fragment will be treated as an end of speech input (trigger off). In actual detection, margins are considered on the beginning and ending point, which will be treated as head and tail silence part. DC offset normalization will be also performed if configured so.
The triggered input speech data should be processed concurrently with the detection for real-time recognition. For this purpose, after the beginning of speech input has been detected, the following triggered input fragments (samples of a certain period in live input, or buffer size in file input) are passed sequencially in turn to a callback function. The callback function should be specified by the caller, typicaly to store the recoded speech, or to process them into a frame-synchronous recognition process.
When source is a live input such as microphone, the device buffer will overflow if the processing callback is slow. In that case, some input fragments may be lost. To prevent this, the A/D-in part together with speech detection will become an independent thread if pthread functions are supported. The A/D-in and detection thread will cooperate with the original main thread through speech buffer, like the followings:
adin_setup_func() is used to switch audio input by specifying device-dependent open/read/close functions, and should be called at first. Function adin_setup_param() should be called after adin_setup_func() to set various parameters for speech detection. The adin_go() function is the top function that will be called from outside, to perform actual input processing. adin_cut() is the main function to read audio input and detect speech segment.
Definition in file adin-cut.c.
|
create and start A/D-in and detection thread Start new A/D-in thread, and also initialize buffer speech. Definition at line 954 of file adin-cut.c. Referenced by adin_setup_param(). |
|
Store the given device-dependent functions and configuration values to local work area. This function will be called from adin_select() via adin_register_func().
Definition at line 178 of file adin-cut.c. Referenced by adin_register_func(). |
|
Setup silence detection parameters (should be called after adin_select()). If using pthread, the A/D-in and detection thread will be started at the end of this function.
Definition at line 215 of file adin-cut.c. Referenced by adin_initialize(). |
|
Query function to check whether the input speech detection is on or off.
Definition at line 253 of file adin-cut.c. Referenced by print_info(). |
|
Query function to check whether the input threading is on or off.
Definition at line 264 of file adin-cut.c. Referenced by print_info(). |
|
Reset zero mean data to re-estimate zero mean at the next input. Definition at line 274 of file adin-cut.c. Referenced by adin_begin(), and adin_standby(). |
|
Purge samples already processed in the temporary buffer buffer.
Definition at line 323 of file adin-cut.c. Referenced by adin_cut(). |
|
Main A/D-in function. In threaded mode, this function will detach and loop forever in ad-in thread, storing triggered samples in speech, and telling the status to another process thread via transfer_online. The process thread, called from adin_go(), polls the length of speech and transfer_online, and if there are stored samples, process them. In non-threaded mode, this function will be called directly from adin_go(), and triggered samples are immediately processed within here. In module mode, the function argument ad_check should be specified to poll the status of incoming command from client while recognition.
Definition at line 350 of file adin-cut.c. Referenced by adin_go(), and adin_thread_input_main(). |
|
Callback for storing triggered samples to speech in A/D-in thread.
Definition at line 917 of file adin-cut.c. Referenced by adin_thread_input_main(). |
|
A/D-in thread main function: just call adin_cut() with storing function.
Definition at line 944 of file adin-cut.c. Referenced by adin_thread_create(). |
|
Main function of processing triggered samples at main thread. Wait for the new samples to be stored in speech by A/D-in thread, and if found, process them.
Definition at line 994 of file adin-cut.c. Referenced by adin_go(). |
|
Top function to start input processing. If threading mode is enabled, this function simply enters to adin_thread_process() to process triggered samples detected by another running A/D-in thread. If threading mode is not available or disabled by either device requirement or OS capability, this function simply calls adin_cut() to detect speech segment from input device and process them concurrently by one process.
Definition at line 1123 of file adin-cut.c. Referenced by main_recognition_loop(). |
|
Semaphore to start/stop recognition. If TRUE, A/D-in thread will store incoming samples to speech and main thread will detect and process them. If FALSE, A/D-in thread will still get input and check trigger as the same as TRUE case, but does not store them to speech. Definition at line 299 of file adin-cut.c. |