cont_ad.h
Go to the documentation of this file.
/* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
/* ====================================================================
* Copyright (c) 1999-2001 Carnegie Mellon University. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* This work was supported in part by funding from the Defense Advanced
* Research Projects Agency and the National Science Foundation of the
* United States of America, and the CMU Sphinx Speech Consortium.
*
* THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
* ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
* NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ====================================================================
*
*/
/*
* cont_ad.h -- Continuous A/D listening and silence filtering module.
*
* **********************************************
* CMU ARPA Speech Project
*
* Copyright (c) 1996 Carnegie Mellon University.
* ALL RIGHTS RESERVED.
* **********************************************
*
* HISTORY
*
* 13-Jul-98 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University
* Added spf and adbufsize to cont_ad_t in order to support variable
* frame sizes depending on audio sampling rate.
*
* 30-Jun-98 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University
* Added FILE* argument to cont_ad_powhist_dump().
*
* 16-Jan-98 Paul Placeway (pwp@cs.cmu.edu) at Carnegie Mellon University
* Changed to use dB instead of the weird power measure.
* Added most system parameters to cont_ad_t instead of hardwiring
* them in cont_ad.c.
* Added cont_ad_set_params() and cont_ad_get_params().
*
* 28-Jul-96 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University
* Added cont_ad_t.siglvl.
*
* 27-Jun-96 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University
* Added the option for cont_ad_read to return -1 on EOF.
*
* 21-Jun-96 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University
* Added cont_ad_set_thresh().
*
* 20-Jun-96 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University
* Separated thresholds for speech and silence.
*
* 17-Jun-96 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University
* Created, based loosely on Steve Reed's original implementation.
*/
#ifndef _CONT_AD_H_
#define _CONT_AD_H_
/* Win32/WinCE DLL gunk */
#include <sphinxbase/sphinxbase_export.h>
#include <sphinxbase/prim_type.h>
#include <sphinxbase/ad.h>
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
#if 0
/* Fool Emacs. */
}
#endif
/* States of continuous listening module */
#define CONT_AD_STATE_SIL 0
#define CONT_AD_STATE_SPEECH 1
typedef struct spseg_s {
int32 startfrm;
int32 nfrm;
struct spseg_s *next;
} spseg_t;
typedef struct {
/* Function to be called for obtaining A/D data (see prototype for ad_read in ad.h) */
int32 (*adfunc)(ad_rec_t *ad, int16 *buf, int32 max);
ad_rec_t *ad;
int32 rawmode;
int16 *adbuf;
/* **************************************************************************
* state, read_ts, and siglvl are provided for READ-ONLY use by client
* applications, and are updated by calls to cont_ad_read() (see below). All
* other variables should be left alone.
*/
int32 state;
int32 read_ts;
int32 seglen;
int32 siglvl;
/* ************************************************************************ */
int32 sps;
int32 eof;
int32 spf;
int32 adbufsize;
int32 prev_sample;
int32 headfrm;
int32 n_frm;
int32 n_sample;
int32 tot_frm;
int32 noise_level;
int32 *pow_hist;
char *frm_pow;
int32 auto_thresh;
int32 delta_sil;
int32 delta_speech;
int32 min_noise;
int32 max_noise;
int32 winsize;
int32 speech_onset;
int32 sil_onset;
int32 leader;
int32 trailer;
int32 thresh_speech;
int32 thresh_sil;
int32 thresh_update;
float32 adapt_rate;
int32 tail_state;
int32 win_startfrm;
int32 win_validfrm;
int32 n_other;
spseg_t *spseg_head;
spseg_t *spseg_tail;
FILE *rawfp;
FILE *logfp;
int32 n_calib_frame;
} cont_ad_t;
SPHINXBASE_EXPORT
cont_ad_t *cont_ad_init (ad_rec_t *ad,
int32 (*adfunc)(ad_rec_t *ad, int16 *buf, int32 max)
);
SPHINXBASE_EXPORT
cont_ad_t *cont_ad_init_rawmode (ad_rec_t *ad,
int32 (*adfunc)(ad_rec_t *ad, int16 *buf, int32 max));
SPHINXBASE_EXPORT
int32 cont_ad_read (cont_ad_t *r,
int16 *buf,
int32 max
);
SPHINXBASE_EXPORT
int32 cont_ad_buffer_space(cont_ad_t *r);
SPHINXBASE_EXPORT
int32 cont_ad_calib (cont_ad_t *cont
);
SPHINXBASE_EXPORT
int32 cont_ad_calib_loop (cont_ad_t *r, int16 *buf, int32 max);
SPHINXBASE_EXPORT
int32 cont_ad_calib_size(cont_ad_t *r);
SPHINXBASE_EXPORT
int32 cont_ad_set_thresh (cont_ad_t *cont,
int32 sil,
int32 sp
);
SPHINXBASE_EXPORT
int32 cont_ad_set_params (cont_ad_t *r, int32 delta_sil, int32 delta_speech,
int32 min_noise, int32 max_noise,
int32 winsize, int32 speech_onset, int32 sil_onset,
int32 leader, int32 trailer,
float32 adapt_rate);
SPHINXBASE_EXPORT
int32 cont_ad_get_params (cont_ad_t *r, int32 *delta_sil, int32 *delta_speech,
int32 *min_noise, int32 *max_noise,
int32 *winsize, int32 *speech_onset, int32 *sil_onset,
int32 *leader, int32 *trailer,
float32 *adapt_rate);
SPHINXBASE_EXPORT
int32 cont_ad_reset (cont_ad_t *cont); /* In: Object pointer from cont_ad_init */
SPHINXBASE_EXPORT
int32 cont_ad_close (cont_ad_t *cont); /* In: Object pointer from cont_ad_init */
SPHINXBASE_EXPORT
void cont_ad_powhist_dump (FILE *fp, cont_ad_t *cont);
SPHINXBASE_EXPORT
int32 cont_ad_detach (cont_ad_t *c);
SPHINXBASE_EXPORT
int32 cont_ad_attach (cont_ad_t *c, ad_rec_t *a, int32 (*func)(ad_rec_t *, int16 *, int32));
SPHINXBASE_EXPORT
int32 cont_ad_set_rawfp (cont_ad_t *c, /* The cont_ad object being addressed */
FILE *fp); /* File to which raw audio data is to
be dumped; NULL to stop dumping. */
SPHINXBASE_EXPORT
int32 cont_ad_set_logfp (cont_ad_t *c, /* The cont_ad object being addressed */
FILE *fp); /* File to which logs are written;
NULL to stop logging. */
SPHINXBASE_EXPORT
int32 cont_set_thresh(cont_ad_t *r, int32 silence, int32 speech);
#ifdef __cplusplus
}
#endif
#endif
cont_ad_init_rawmode
SPHINXBASE_EXPORT cont_ad_t * cont_ad_init_rawmode(ad_rec_t *ad, int32(*adfunc)(ad_rec_t *ad, int16 *buf, int32 max))
Initializes a continuous listening object which simply passes data through (!)
cont_ad_t::spseg_tail
spseg_t * spseg_tail
Last of unconsumed speech segments.
Definition: cont_ad.h:225
cont_ad_t::tot_frm
int32 tot_frm
Total number of frames of A/D data read, including consumed ones.
Definition: cont_ad.h:191
cont_ad_t::max_noise
int32 max_noise
noise higher than this signals an error
Definition: cont_ad.h:201
cont_ad_t::sps
int32 sps
Samples/sec; moved from ad->sps to break dependence on ad by N.
Definition: cont_ad.h:180
spseg_s::startfrm
int32 startfrm
Frame-id in adbuf (see below) of start of this segment.
Definition: cont_ad.h:136
cont_ad_t::rawfp
FILE * rawfp
If non-NULL, raw audio input data processed by cont_ad is dumped to this file.
Definition: cont_ad.h:227
cont_ad_t::seglen
int32 seglen
Total no.
Definition: cont_ad.h:171
cont_ad_reset
SPHINXBASE_EXPORT int32 cont_ad_reset(cont_ad_t *cont)
Reset, discarding any accumulated speech segments.
Definition: cont_ad_base.c:1236
ad_rec_t
Definition: ad.h:255
cont_ad_t::adbuf
int16 * adbuf
Circular buffer for maintaining A/D data read until consumed.
Definition: cont_ad.h:158
cont_ad_read
SPHINXBASE_EXPORT int32 cont_ad_read(cont_ad_t *r, int16 *buf, int32 max)
Read raw audio data into the silence filter.
Definition: cont_ad_base.c:863
cont_ad_t::state
int32 state
State of data returned by most recent cont_ad_read call; CONT_AD_STATE_SIL or CONT_AD_STATE_SPEECH.
Definition: cont_ad.h:165
cont_ad_set_logfp
SPHINXBASE_EXPORT int32 cont_ad_set_logfp(cont_ad_t *c, FILE *fp)
Set the file to which cont_ad logs its progress.
Definition: cont_ad_base.c:1360
cont_ad_t::pow_hist
int32 * pow_hist
Histogram of frame power, moving window, decayed.
Definition: cont_ad.h:194
cont_ad_t::eof
int32 eof
Whether the source ad device has encountered EOF.
Definition: cont_ad.h:183
cont_ad_t::leader
int32 leader
pad beggining of speech with this many extra frms
Definition: cont_ad.h:205
spseg_t
(FOR INTERNAL USE ) Data structure for maintaining speech (non-silence) segments not yet consumed by ...
cont_ad_t::logfp
FILE * logfp
If non-NULL, write detailed logs of this object&#39;s progress to the file.
Definition: cont_ad.h:231
prim_type.h
Basic type definitions used in Sphinx.
cont_ad_t::frm_pow
char * frm_pow
Frame power.
Definition: cont_ad.h:195
cont_ad_t::speech_onset
int32 speech_onset
start speech on >= these many frames out of winsize, of >= delta_speech
Definition: cont_ad.h:203
cont_ad_t::headfrm
int32 headfrm
Frame number in adbuf with unconsumed A/D data.
Definition: cont_ad.h:188
cont_ad_close
SPHINXBASE_EXPORT int32 cont_ad_close(cont_ad_t *cont)
Close the continuous listening object.
Definition: cont_ad_base.c:1264
cont_ad_t::auto_thresh
int32 auto_thresh
Do automatic threshold adjustment or not.
Definition: cont_ad.h:197
cont_ad_t::spseg_head
spseg_t * spseg_head
First of unconsumed speech segments.
Definition: cont_ad.h:224
cont_ad_t::n_calib_frame
int32 n_calib_frame
Number of frames of calibration data seen so far.
Definition: cont_ad.h:236
cont_ad_t::win_startfrm
int32 win_startfrm
Where next analysis window begins.
Definition: cont_ad.h:220
cont_ad_t::n_sample
int32 n_sample
Number of samples of unconsumed data in adbuf.
Definition: cont_ad.h:190
spseg_s
Definition: cont_ad.h:135
cont_ad_init
SPHINXBASE_EXPORT cont_ad_t * cont_ad_init(ad_rec_t *ad, int32(*adfunc)(ad_rec_t *ad, int16 *buf, int32 max))
Initialize a continuous listening/silence filtering object.
cont_ad_t::win_validfrm
int32 win_validfrm
Number of frames currently available from win_startfrm for analysis.
Definition: cont_ad.h:221
cont_ad_t::n_other
int32 n_other
If in SILENCE state, number of frames in analysis window considered to be speech; otherwise number of...
Definition: cont_ad.h:222
cont_ad_powhist_dump
SPHINXBASE_EXPORT void cont_ad_powhist_dump(FILE *fp, cont_ad_t *cont)
Dump the power histogram.
Definition: cont_ad_base.c:231
cont_set_thresh
SPHINXBASE_EXPORT int32 cont_set_thresh(cont_ad_t *r, int32 silence, int32 speech)
Set the silence and speech thresholds.
Definition: cont_ad_base.c:1308
spseg_s::nfrm
int32 nfrm
Number of frames in segment (may wrap around adbuf)
Definition: cont_ad.h:137
cont_ad_t::delta_sil
int32 delta_sil
Max silence power/frame ABOVE noise level.
Definition: cont_ad.h:198
cont_ad_calib
SPHINXBASE_EXPORT int32 cont_ad_calib(cont_ad_t *cont)
Calibrate the silence filter.
Definition: cont_ad_base.c:1022
cont_ad_detach
SPHINXBASE_EXPORT int32 cont_ad_detach(cont_ad_t *c)
Detach the given continuous listening module from the associated audio device.
Definition: cont_ad_base.c:1281
cont_ad_calib_size
SPHINXBASE_EXPORT int32 cont_ad_calib_size(cont_ad_t *r)
Get the number of samples required to calibrate the silence filter.
Definition: cont_ad_base.c:1058
ad.h
generic live audio interface for recording and playback
cont_ad_t::tail_state
int32 tail_state
State at the end of its internal buffer (internal use): CONT_AD_STATE_SIL or CONT_AD_STATE_SPEECH.
Definition: cont_ad.h:217
cont_ad_t::min_noise
int32 min_noise
noise lower than this we ignore
Definition: cont_ad.h:200
cont_ad_attach
SPHINXBASE_EXPORT int32 cont_ad_attach(cont_ad_t *c, ad_rec_t *a, int32(*func)(ad_rec_t *, int16 *, int32))
Attach the continuous listening module to the given audio device/function.
Definition: cont_ad_base.c:1293
cont_ad_set_rawfp
SPHINXBASE_EXPORT int32 cont_ad_set_rawfp(cont_ad_t *c, FILE *fp)
Set a file for dumping raw audio input.
Definition: cont_ad_base.c:1346
cont_ad_get_params
SPHINXBASE_EXPORT int32 cont_ad_get_params(cont_ad_t *r, int32 *delta_sil, int32 *delta_speech, int32 *min_noise, int32 *max_noise, int32 *winsize, int32 *speech_onset, int32 *sil_onset, int32 *leader, int32 *trailer, float32 *adapt_rate)
PWP 1/14/98 – get the changable params.
Definition: cont_ad_base.c:1199
cont_ad_t::noise_level
int32 noise_level
PWP: what we claim as the "current" noise level.
Definition: cont_ad.h:192
cont_ad_t
Continuous listening module or object Continuous listening module or object.
Definition: cont_ad.h:151
cont_ad_t::n_frm
int32 n_frm
Number of complete frames of unconsumed A/D data in adbuf.
Definition: cont_ad.h:189
cont_ad_buffer_space
SPHINXBASE_EXPORT int32 cont_ad_buffer_space(cont_ad_t *r)
Get the maximum number of samples which can be passed into cont_ad_read().
Definition: cont_ad_base.c:707
cont_ad_t::adapt_rate
float32 adapt_rate
Linear interpolation constant for rate at which noise level adapted to each estimate; range: 0-1; 0=>...
Definition: cont_ad.h:213
cont_ad_t::delta_speech
int32 delta_speech
Min speech power/frame ABOVE noise level.
Definition: cont_ad.h:199
cont_ad_calib_loop
SPHINXBASE_EXPORT int32 cont_ad_calib_loop(cont_ad_t *r, int16 *buf, int32 max)
Calibrate the silence filter without an audio device.
Definition: cont_ad_base.c:1064
cont_ad_t::prev_sample
int32 prev_sample
For pre-emphasis filter.
Definition: cont_ad.h:187
cont_ad_t::spf
int32 spf
Samples/frame; audio level is analyzed within frames.
Definition: cont_ad.h:185
cont_ad_t::read_ts
int32 read_ts
Absolute timestamp (total no.
Definition: cont_ad.h:167
spseg_s::next
struct spseg_s * next
Next speech segment (with some intervening silence)
Definition: cont_ad.h:138
cont_ad_t::ad
ad_rec_t * ad
A/D device argument for adfunc.
Definition: cont_ad.h:154
cont_ad_t::rawmode
int32 rawmode
Pass all input data through, without filtering silence.
Definition: cont_ad.h:156
cont_ad_t::siglvl
int32 siglvl
Max signal level for the data consumed by the most recent cont_ad_read call (dB range: 0-99)...
Definition: cont_ad.h:175
cont_ad_t::winsize
int32 winsize
how many frames to look at for speech det
Definition: cont_ad.h:202
cont_ad_t::thresh_update
int32 thresh_update
Number of frames before next update to pow_hist/thresholds.
Definition: cont_ad.h:212
cont_ad_t::sil_onset
int32 sil_onset
end speech on >= these many frames out of winsize, of <= delta_sil
Definition: cont_ad.h:204
cont_ad_set_thresh
SPHINXBASE_EXPORT int32 cont_ad_set_thresh(cont_ad_t *cont, int32 sil, int32 sp)
Set silence and speech threshold parameters.
Definition: cont_ad_base.c:1100
cont_ad_t::trailer
int32 trailer
pad end of speech with this many extra frms
Definition: cont_ad.h:206
cont_ad_t::adbufsize
int32 adbufsize
Buffer size (Number of samples)
Definition: cont_ad.h:186
cont_ad_t::thresh_speech
int32 thresh_speech
Frame considered to be speech if power >= thresh_speech (for transitioning from SILENCE to SPEECH sta...
Definition: cont_ad.h:208
cont_ad_t::thresh_sil
int32 thresh_sil
Frame considered to be silence if power <= thresh_sil (for transitioning from SPEECH to SILENCE state...
Definition: cont_ad.h:210
cont_ad_set_params
SPHINXBASE_EXPORT int32 cont_ad_set_params(cont_ad_t *r, int32 delta_sil, int32 delta_speech, int32 min_noise, int32 max_noise, int32 winsize, int32 speech_onset, int32 sil_onset, int32 leader, int32 trailer, float32 adapt_rate)
Set the changable parameters.
Definition: cont_ad_base.c:1126