libsent/include/sent/adin.h File Reference

Definitions for A/D-in processing and speech detection. More...

#include <sent/stddefs.h>
#include <sent/speech.h>

Include dependency graph for adin.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define DEFAULT_WSTEP   1000
 Default unit size of speech input segment in bytes.
#define SUPPORTED_WAVEFILE_FORMAT   "RAW(BE),WAV,AU,SND,NIST,ADPCM and more"
#define ZMEANSAMPLES   48000

Enumerations

enum  {
  SP_RAWFILE, SP_MIC, SP_ADINNET, SP_MFCFILE,
  SP_NETAUDIO, SP_STDIN
}
 To select speech input source. More...

Functions

boolean adin_select (int source)
boolean adin_standby (int freq, void *arg)
boolean adin_begin ()
boolean adin_end ()
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 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 ()
int adin_go (int(*ad_process)(SP16 *, int), int(*ad_check)())
 Top function to start input processing.
boolean adin_mic_standby (int freq, void *arg)
boolean adin_mic_start ()
boolean adin_mic_stop ()
int adin_mic_read (SP16 *buf, int sampnum)
 Read samples from the daemon.
boolean adin_netaudio_standby (int freq, void *arg)
boolean adin_netaudio_start ()
boolean adin_netaudio_stop ()
int adin_netaudio_read (SP16 *buf, int sampnum)
 Read samples from the daemon.
int NA_standby (int, char *)
void NA_start ()
void NA_stop ()
int NA_read (SP16 *buf, int sampnum)
 Read samples from NetAudio port.
char * get_line (char *prompt)
boolean adin_file_standby (int freq, void *arg)
boolean adin_file_begin ()
 Begin reading audio data from a file.
int adin_file_read (SP16 *buf, int sampnum)
boolean adin_file_end ()
boolean adin_stdin_standby (int freq, void *arg)
boolean adin_stdin_begin ()
 Begin reading audio data from stdin.
int adin_stdin_read (SP16 *buf, int sampnum)
boolean adin_sndfile_standby (int freq, void *arg)
boolean adin_sndfile_begin ()
 Begin reading audio data from a file.
int adin_sndfile_read (SP16 *buf, int sampnum)
boolean adin_sndfile_end ()
boolean adin_tcpip_standby (int freq, void *arg)
boolean adin_tcpip_begin ()
boolean adin_tcpip_end ()
 End recording.
int adin_tcpip_read (SP16 *buf, int sampnum)
boolean adin_tcpip_send_pause ()
boolean adin_tcpip_send_terminate ()
boolean adin_tcpip_send_resume ()
void init_count_zc_e (int c_trigger, int c_length, int c_offset)
void end_count_zc_e ()
int count_zc_e (SP16 *buf, int step)
int count_zc_e_level (SP16 *buf, int step, int *levelp)
void zc_copy_buffer (SP16 *newbuf, int *len)
void zmean_reset ()
void sub_zmean (SP16 *speech, int samplenum)
 Remove DC offset.


Detailed Description

Definitions for A/D-in processing and speech detection.

Author:
Akinobu LEE
Date:
Thu Feb 10 17:22:36 2005
This file has some definitions relating audio input processing from various devices, and start/end of speech detection.
See also:
speech.h
Revision
1.4

Definition in file adin.h.


Define Documentation

#define SUPPORTED_WAVEFILE_FORMAT   "RAW(BE),WAV,AU,SND,NIST,ADPCM and more"

String describing the list of supported wave file formats. It depends on HAVE_LIBSNDFILE.

Definition at line 55 of file adin.h.

Referenced by detailed_help().

#define ZMEANSAMPLES   48000

Number of samples from beggining of input to be used for computing the zero mean of source channel (for microphone/network input).

Definition at line 65 of file adin.h.

Referenced by sub_zmean().


Enumeration Type Documentation

anonymous enum

To select speech input source.

Enumerator:
SP_RAWFILE  Wavefile.
SP_MIC  Live microphone device.
SP_ADINNET  Network client (adintool etc.).
SP_MFCFILE  HTK parameter file.
SP_NETAUDIO  Live NetAudio/DatLink input.
SP_STDIN  Standard input.

Definition at line 37 of file adin.h.


Function Documentation

boolean adin_select ( int  source  ) 

Select input source and setup device-specific functions.

Parameters:
source [In] selection ID of input source
See also:
adin.h
Returns:
TRUE on success, FALSE if source is not available.

Definition at line 134 of file adin.c.

Referenced by adin_initialize().

boolean adin_standby ( int  freq,
void *  arg 
)

Call device-specific initialization.

Parameters:
freq [in] sampling frequency
arg [in] device-dependent extra argument
Returns:
TRUE on success, FALSE on failure.

Definition at line 227 of file adin.c.

Referenced by adin_initialize().

boolean adin_begin (  ) 

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

Returns:
TRUE on success, FALSE on failure.

Definition at line 239 of file adin.c.

Referenced by main_recognition_loop().

boolean adin_end (  ) 

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

Returns:
TRUE on success, FALSE on failure.

Definition at line 251 of file adin.c.

Referenced by main_recognition_loop().

void adin_setup_func ( int(*)(SP16 *, int)  cad_read,
boolean(*)()  cad_pause,
boolean(*)()  cad_resume,
boolean  use_cut_def,
boolean  need_thread 
)

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().

Parameters:
cad_read  [in] function to read input samples
cad_pause  [in] function to stop input
cad_resume  [in] function to (re-)start input
use_cut_def  [in] TRUE if the device needs speech segment detection by default
need_thread  [in] TRUE if the device is live input and needs threading

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

Referenced by adin_register_func().

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 
)

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.

Parameters:
silence_cut [in] whether to perform silence cutting. 0=force off, 1=force on, 2=keep device-specific default
strip_zero [in] TRUE if enables stripping of zero samples
cthres [in] input level threshold (0-32767)
czc [in] zero-cross count threshold in a second
head_margin [in] header margin length in msec
tail_margin [in] tail margin length in msec
sample_freq [in] sampling frequency: just providing value for computing other variables
ignore_speech [in] TRUE if ignore speech input between call, while waiting recognition process
need_zeromean [in] TRUE if perform zero-mean subtraction

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

Referenced by adin_initialize().

boolean query_segment_on (  ) 

Query function to check whether the input speech detection is on or off.

Returns:
TRUE if on, FALSE if off.

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

boolean query_thread_on (  ) 

Query function to check whether the input threading is on or off.

Returns:
TRUE if on, FALSE if off.

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

void adin_reset_zmean (  ) 

Reset zero mean data to re-estimate zero mean at the next input.

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

Referenced by adin_begin(), and adin_standby().

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

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 the recorded fragments
ad_check [in] function to be called periodically for checking incoming user command in module mode.
Returns:
the same as adin_thread_process() in threading mode, or same as adin_cut() when non-threaded mode.

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

Referenced by main_recognition_loop().

boolean adin_mic_standby ( int  sfreq,
void *  dummy 
)

Device initialization: check device capability and open for recording.

Parameters:
sfreq [in] required sampling frequency.
dummy [in] a dummy data
Returns:
TRUE on success, FALSE on failure.

Definition at line 51 of file adin_esd.c.

Referenced by adin_select().

boolean adin_mic_start (  ) 

Start recording.

Returns:
TRUE on success, FALSE on failure.

Definition at line 75 of file adin_esd.c.

Referenced by adin_mic_standby(), and adin_select().

boolean adin_mic_stop (  ) 

Stop recording.

Returns:
TRUE on success, FALSE on failure.

Definition at line 86 of file adin_esd.c.

Referenced by adin_mic_standby(), and adin_select().

int adin_mic_read ( SP16 buf,
int  sampnum 
)

Read samples from the daemon.

Try to read sampnum samples and returns actual number of recorded samples currently available. This function will block until at least some samples are obtained.

Parameters:
buf [out] samples obtained in this function
sampnum [in] wanted number of samples to be read
Returns:
actural number of read samples, -2 if an error occured.

Definition at line 104 of file adin_esd.c.

Referenced by adin_select().

boolean adin_netaudio_standby ( int  sfreq,
void *  arg 
)

Connection initialization: check connectivity and open for recording.

Parameters:
sfreq [in] required sampling frequency
arg [in] server device name string to connect
Returns:
TRUE on success, FALSE on failure.

Definition at line 57 of file adin_netaudio.c.

Referenced by adin_select().

boolean adin_netaudio_start (  ) 

Start recording.

Returns:
TRUE on success, FALSE on failure.

Definition at line 71 of file adin_netaudio.c.

Referenced by adin_select().

boolean adin_netaudio_stop (  ) 

Stop recording.

Returns:
TRUE on success, FALSE on failure.

Definition at line 84 of file adin_netaudio.c.

Referenced by adin_select().

int adin_netaudio_read ( SP16 buf,
int  sampnum 
)

Read samples from the daemon.

Try to read sampnum samples and returns actual number of recorded samples currently available. This function will block until at least one sample can be obtained.

Parameters:
buf [out] samples obtained in this function
sampnum [in] wanted number of samples to be read
Returns:
actural number of read samples, -2 if an error occured.

Definition at line 103 of file adin_netaudio.c.

Referenced by adin_select().

int NA_standby ( int  sfreq,
char *  server_devname 
)

Initialize NetAudio device.

Parameters:
sfreq [in] sampling frequency
server_devname [in] server host name
Returns:
1 on success, 0 on failure.

Definition at line 59 of file adin_na.c.

Referenced by adin_netaudio_standby().

void NA_start (  ) 

Begin recording.

Definition at line 128 of file adin_na.c.

Referenced by adin_netaudio_start().

void NA_stop (  ) 

Pause the recording.

Definition at line 138 of file adin_na.c.

Referenced by adin_netaudio_stop().

int NA_read ( SP16 buf,
int  sampnum 
)

Read samples from NetAudio port.

Try to read sampnum samples and returns actual number of recorded samples currently available. This function will block until at least some samples are obtained.

Parameters:
buf [out] samples obtained in this function
sampnum [in] wanted number of samples to be read
Returns:
actural number of read samples, -1 if an error occured.

Definition at line 156 of file adin_na.c.

Referenced by adin_netaudio_read().

char* get_line ( char *  prompt  ) 

Get one file name from stdin with a prompt . Blank line is omitted.

Parameters:
prompt [in] prompt string
Returns:
newly allocated buffer filled with the input.

Definition at line 314 of file adin_file.c.

Referenced by adin_file_begin(), adin_sndfile_begin(), and main_recognition_loop().

boolean adin_file_standby ( int  freq,
void *  arg 
)

Initialization: if listfile is specified, open it here.

Parameters:
freq [in] required sampling frequency.
arg [in] file name of listfile, or NULL if not use
Returns:
TRUE on success, FALSE on failure.

Definition at line 355 of file adin_file.c.

Referenced by adin_select().

boolean adin_file_begin (  ) 

Begin reading audio data from a file.

If listfile was specified in adin_file_standby(), the next filename will be read from the listfile. Otherwise, the filename will be obtained from stdin. Then the file will be opened here.

Returns:
TRUE on success, FALSE on failure.

Definition at line 385 of file adin_file.c.

Referenced by adin_select().

int adin_file_read ( SP16 buf,
int  sampnum 
)

Try to read sampnum samples and returns actual sample num recorded.

Parameters:
buf [out] samples obtained in this function
sampnum [in] wanted number of samples to be read
Returns:
actural number of read samples, -1 if EOF, -2 if error.

Definition at line 429 of file adin_file.c.

Referenced by adin_select().

boolean adin_file_end (  ) 

End recording.

Returns:
TRUE on success, FALSE on failure.

Definition at line 476 of file adin_file.c.

Referenced by adin_select().

boolean adin_stdin_standby ( int  freq,
void *  arg 
)

Initialization for speech input via stdin.

Parameters:
freq [in] required sampling frequency.
arg dummy, ignored
Returns:
TRUE on success, FALSE on failure.

Definition at line 492 of file adin_file.c.

Referenced by adin_select().

boolean adin_stdin_begin (  ) 

Begin reading audio data from stdin.

Returns:
TRUE on success, FALSE on failure.

Definition at line 505 of file adin_file.c.

Referenced by adin_select().

int adin_stdin_read ( SP16 buf,
int  sampnum 
)

Try to read sampnum samples and returns actual sample num recorded.

Parameters:
buf [out] samples obtained in this function
sampnum [in] wanted number of samples to be read
Returns:
actural number of read samples, -1 if EOF, -2 if error.

Definition at line 528 of file adin_file.c.

Referenced by adin_select().

boolean adin_sndfile_standby ( int  freq,
void *  arg 
)

Initialization: if listfile is specified, open it here. Else, just store the required frequency.

Parameters:
freq [in] required sampling frequency
arg [in] file name of listfile, or NULL if not use
Returns:
TRUE on success, FALSE on failure.

Definition at line 202 of file adin_sndfile.c.

Referenced by adin_select().

boolean adin_sndfile_begin (  ) 

Begin reading audio data from a file.

If listfile was specified in adin_sndfile_standby(), the next filename will be read from the listfile. Otherwise, the filename will be obtained from stdin. Then the file will be opened here.

Returns:
TRUE on success, FALSE on failure.

Definition at line 232 of file adin_sndfile.c.

Referenced by adin_select().

int adin_sndfile_read ( SP16 buf,
int  sampnum 
)

Try to read sampnum samples and returns actual sample num recorded.

Parameters:
buf [out] samples obtained in this function
sampnum [in] wanted number of samples to be read
Returns:
actural number of read samples, -1 if EOF, -2 if error.

Definition at line 313 of file adin_sndfile.c.

Referenced by adin_select().

boolean adin_sndfile_end (  ) 

End recording.

Returns:
TRUE on success, FALSE on failure.

Definition at line 334 of file adin_sndfile.c.

Referenced by adin_select().

boolean adin_tcpip_standby ( int  freq,
void *  port_str 
)

Initialize as adinnet server: prepare to become server.

Parameters:
freq [in] required sampling frequency
port_str [in] port number in string
Returns:
TRUE on success, FALSE on failure.

Definition at line 78 of file adin_tcpip.c.

Referenced by adin_select().

boolean adin_tcpip_begin (  ) 

Wait for connection from adinnet client and begin audio input stream.

Returns:
TRUE on success, FALSE on failure.

Definition at line 100 of file adin_tcpip.c.

Referenced by adin_select().

boolean adin_tcpip_end (  ) 

End recording.

If last input segment was segmented by end of connection, close socket and wait for next connection. Otherwise, it means that the last input segment was segmented by either end-of-segment signal from client side or speech detection function in server side, so just wait for a next input in the current socket.

Returns:
TRUE on success, FALSE on failure.

Definition at line 146 of file adin_tcpip.c.

Referenced by adin_select().

int adin_tcpip_read ( SP16 buf,
int  sampnum 
)

Try to read sampnum samples and returns actual sample num recorded. This function will not block.

If data of zero length has been received, it is treated as a end-of-segment marker from the client. If data below zero length has been received, it means the client has finished the overall input stream transmission and want to disconnect.

Parameters:
buf [out] samples obtained in this function
sampnum [in] wanted number of samples to be read
Returns:
actural number of read samples, -1 if EOF, -2 if error.

Definition at line 177 of file adin_tcpip.c.

Referenced by adin_select().

boolean adin_tcpip_send_pause (  ) 

Tell the adinnet client to pause transfer.

Returns:
TRUE on success, FALSE on failure.

Definition at line 223 of file adin_tcpip.c.

Referenced by msock_exec_command().

boolean adin_tcpip_send_terminate (  ) 

Tell the adinnet client to terminate transfer.

Returns:
TRUE on success, FALSE on failure.

Definition at line 257 of file adin_tcpip.c.

Referenced by msock_exec_command().

boolean adin_tcpip_send_resume (  ) 

Tell the adinnet client to resume the paused transfer.

Returns:
TRUE on success, FALSE on failure.

Definition at line 240 of file adin_tcpip.c.

Referenced by msock_exec_command().

void init_count_zc_e ( int  c_trigger,
int  c_length,
int  c_offset 
)

Initialize all parameters and buffers for zero-cross counting.

Parameters:
c_trigger [in] Tgigger level threshold
c_length [in] Cycle buffer size = Number of samples to hold
c_offset [in] Static DC offset of input data

Definition at line 63 of file zc-e.c.

Referenced by adin_cut().

void end_count_zc_e (  ) 

End procedure: free all buffers.

Definition at line 91 of file zc-e.c.

Referenced by adin_cut().

int count_zc_e ( SP16 buf,
int  step 
)

Adding buf[0..step-1] to the cycle buffer and update the count of zero cross. Also swap them with the oldest ones in the cycle buffer.

Parameters:
buf [I/O] new samples given, and swapped samples will be returned.
step [in] length of above.
Returns:
zero-cross count of the samples in the cycle buffer.

Definition at line 107 of file zc-e.c.

Referenced by adin_cut().

int count_zc_e_level ( SP16 buf,
int  step,
int *  levelp 
)

Adding buf[0..step-1] to the cycle buffer and update the count of zero cross. Also swap them with the oldest ones in the cycle buffer. Also get the maximum level in the cycle buffer.

Parameters:
buf [I/O] new samples, will be swapped by old samples when returned.
step [in] length of above.
levelp [out] maximum level in the cycle buffer.
Returns:
zero-cross count of the samples in the cycle buffer.

Definition at line 157 of file zc-e.c.

void zc_copy_buffer ( SP16 newbuf,
int *  len 
)

Flush samples in the current cycle buffer.

Parameters:
newbuf [out] the samples in teh cycle buffer will be written here.
len [out] length of above.

Definition at line 205 of file zc-e.c.

Referenced by adin_cut().

void zmean_reset (  ) 

Reset status.

Definition at line 50 of file zmean.c.

Referenced by adin_reset_zmean().

void sub_zmean ( SP16 speech,
int  samplenum 
)

Remove DC offset.

The DC offset is estimated by the first samples after zmean_reset() was called. If the first input segment is longer than ZMEANSAMPLES, the whole input is used to estimate the zero mean. Otherwise, the zero mean will continue to be updated until the read length exceed ZMEANSAMPLES.

Parameters:
speech [I/O] input speech data, will be subtracted by DC offset.
samplenum [in] length of above.

Definition at line 69 of file zmean.c.

Referenced by adin_cut().


Generated on Tue Dec 26 12:53:51 2006 for Julian by  doxygen 1.5.0