libjulius/src/adin-cut.c File Reference

Capture audio and detect sound trigger. More...

#include <julius/julius.h>
#include <pthread.h>

Go to the source code of this file.

Defines

#define TMP_FIX_200602
 Define this if you want to output a debug message for threading.

Functions

void adin_setup_param (ADIn *adin, Jconf *jconf)
 Set up parameters for A/D-in and input detection.
static void adin_purge (ADIn *a, int from)
 Purge samples already processed in the temporary buffer.
static int adin_cut (int(*ad_process)(SP16 *, int, Recog *), int(*ad_check)(Recog *), Recog *recog)
 Main A/D-in and sound detection function.
static int adin_store_buffer (SP16 *now, int len, Recog *recog)
 Callback to store triggered samples within A/D-in thread.
static void adin_thread_input_main (void *dummy)
 A/D-in thread main function.
boolean adin_thread_create (Recog *recog)
 Start new A/D-in thread, and initialize buffer.
static int adin_thread_process (int(*ad_process)(SP16 *, int, Recog *), int(*ad_check)(Recog *), Recog *recog)
 Main processing function for thread mode.
int adin_go (int(*ad_process)(SP16 *, int, Recog *), int(*ad_check)(Recog *), Recog *recog)
 Top function to start input processing.
boolean adin_standby (ADIn *a, int freq, void *arg)
 Call device-specific initialization.
boolean adin_begin (ADIn *a)
 Call device-specific function to begin capturing of the audio stream.
boolean adin_end (ADIn *a)
 Call device-specific function to end capturing of the audio stream.
void adin_free_param (Recog *recog)
 Free memories of A/D-in work area.


Detailed Description

Capture audio and detect sound trigger.

This file contains functions to get waveform from an audio device and detect speech/sound input segment

Sound detection at this stage is based on level threshold and zero cross count. The number of zero cross are counted for each incoming sound fragment. If the number becomes larger than specified threshold, the fragment is treated as a beginning of sound/speech input (trigger on). If the number goes below the threshold, the fragment will be treated as an end of 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 (-zmean).

The triggered input data should be processed concurrently with the detection for real-time recognition. For this purpose, after the beginning of 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 data, 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 sound 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:

See also:
adin.c
Author:
Akinobu LEE
Date:
Sat Feb 12 13:20:53 2005
Revision
1.1.1.1

Definition in file adin-cut.c.


Define Documentation

#define TMP_FIX_200602

Define this if you want to output a debug message for threading.

Enable some fixes relating adinnet+module

Definition at line 116 of file adin-cut.c.


Function Documentation

void adin_setup_param ( ADIn adin,
Jconf jconf 
)

Set up parameters for A/D-in and input detection.

Set variables in work area according to the configuration values.

Parameters:
adin [in] AD-in work area
jconf [in] configuration data

Definition at line 138 of file adin-cut.c.

Referenced by adin_setup_all().

Here is the caller graph for this function:

static void adin_purge ( ADIn a,
int  from 
) [static]

Purge samples already processed in the temporary buffer.

Parameters:
a [in] AD-in work area
from [in] Purge samples in range [0..from-1].

Definition at line 209 of file adin-cut.c.

Referenced by adin_cut().

static int adin_cut ( int(*)(SP16 *, int, Recog *)  ad_process,
int(*)(Recog *)  ad_check,
Recog recog 
) [static]

Main A/D-in and sound detection function.

This function read inputs from device and do sound detection (both up trigger and down trigger) until end of device.

In threaded mode, this function will detach and loop forever as ad-in thread, (adin_thread_create()) storing triggered samples in speech[], and telling the status to another process thread via transfer_online in work area. The process thread, called from adin_go(), polls the length of speech[] and transfer_online in work area and process them if new samples has been stored.

In non-threaded mode, this function will be called directly from adin_go(), and triggered samples are immediately processed within here.

Threaded mode should be used for "live" input such as microphone input where input is infinite and capture delay is severe. For file input, adinnet input and other "buffered" input, non-threaded mode will be used.

Argument "ad_process()" should be a function to process the triggered input samples. On real-time recognition, a frame-synchronous search function for the first pass will be specified by the caller. The current input will be segmented if it returns 1, and will be terminated as error if it returns -1.

When the argument "ad_check()" specified, it will be called periodically. When it returns less than 0, this function will be terminated.

Parameters:
ad_process [in] function to process triggerted input.
ad_check [in] function to be called periodically.
recog [in] engine instance
Returns:
2 when input termination requested by ad_process(), 1 when if detect end of an input segment (down trigger detected after up trigger), 0 when reached end of input device, -1 on error, -2 when input termination requested by ad_check().

Definition at line 290 of file adin-cut.c.

static int adin_store_buffer ( SP16 now,
int  len,
Recog recog 
) [static]

Callback to store triggered samples within A/D-in thread.

Parameters:
now [in] triggered fragment
len [in] length of above
recog [in] engine instance
Returns:
always 0, to tell caller to just continue the input

Definition at line 900 of file adin-cut.c.

Referenced by adin_cut().

static void adin_thread_input_main ( void *  dummy  )  [static]

A/D-in thread main function.

Parameters:
dummy [in] a dummy data, not used.

Definition at line 934 of file adin-cut.c.

Referenced by adin_thread_create().

boolean adin_thread_create ( Recog recog  ) 

Start new A/D-in thread, and initialize buffer.

Parameters:
recog [in] engine instance

< Thread information

Definition at line 956 of file adin-cut.c.

Referenced by j_adin_init(), and j_adin_init_user().

Here is the caller graph for this function:

static int adin_thread_process ( int(*)(SP16 *, int, Recog *)  ad_process,
int(*)(Recog *)  ad_check,
Recog recog 
) [static]

Main processing function for thread mode.

It waits for the new samples to be stored in speech by A/D-in thread, and if found, process them. The interface are the same as adin_cut().

Parameters:
ad_process [in] function to process triggerted input.
ad_check [in] function to be called periodically.
recog [in] engine instance
Returns:
2 when input termination requested by ad_process(), 1 when if detect end of an input segment (down trigger detected after up trigger), 0 when reached end of input device, -1 on error, -2 when input termination requested by ad_check().

Definition at line 1015 of file adin-cut.c.

int adin_go ( int(*)(SP16 *, int, Recog *)  ad_process,
int(*)(Recog *)  ad_check,
Recog recog 
)

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.

Parameters:
ad_process [in] function to process triggerted input.
ad_check [in] function to be called periodically.
recog [in] engine instance
Returns:
2 when input termination requested by ad_process(), 1 when if detect end of an input segment (down trigger detected after up trigger), 0 when reached end of input device, -1 on error, -2 when input termination requested by ad_check().

Definition at line 1185 of file adin-cut.c.

boolean adin_standby ( ADIn a,
int  freq,
void *  arg 
)

Call device-specific initialization.

Parameters:
a [in] A/D-in work area
freq [in] sampling frequency
arg [in] device-dependent argument
Returns:
TRUE if succeeded, FALSE if failed.

Definition at line 1214 of file adin-cut.c.

Referenced by adin_setup_all().

Here is the caller graph for this function:

boolean adin_begin ( ADIn a  ) 

Call device-specific function to begin capturing of the audio stream.

Parameters:
a [in] A/D-in work area
Returns:
TRUE on success, FALSE on failure.

Definition at line 1237 of file adin-cut.c.

boolean adin_end ( ADIn a  ) 

Call device-specific function to end capturing of the audio stream.

Parameters:
a [in] A/D-in work area
Returns:
TRUE on success, FALSE on failure.

Definition at line 1259 of file adin-cut.c.

void adin_free_param ( Recog recog  ) 

Free memories of A/D-in work area.

Parameters:
recog [in] engine instance

Definition at line 1280 of file adin-cut.c.

Referenced by j_recog_free().

Here is the caller graph for this function:


Generated on Tue Dec 18 16:00:52 2007 for Julius by  doxygen 1.5.4