diff --git a/include/pocketsphinx.h b/include/pocketsphinx.h index 22bcbdd01..fe2d4a53d 100644 --- a/include/pocketsphinx.h +++ b/include/pocketsphinx.h @@ -771,7 +771,9 @@ int ps_decode_senscr(ps_decoder_t *ps, FILE *senfh); * * @deprecated This function is retained for compatibility, but its * only effect is to reset the noise removal statistics, which are - * otherwise retained across utterances. You do not need to call it. + * otherwise retained across utterances. If noise removal is disabled, + * there are no statistics to reset and this is a successful no-op. You + * do not need to call it. * * @memberof ps_decoder_t * @return 0 for success, <0 on error. diff --git a/src/fe/fe_noise.c b/src/fe/fe_noise.c index c3a994ede..76b7f1471 100644 --- a/src/fe/fe_noise.c +++ b/src/fe/fe_noise.c @@ -62,7 +62,6 @@ #include "fe/fe_internal.h" /* Noise suppression constants */ -#define SMOOTH_WINDOW 4 #define LAMBDA_POWER 0.7 #define LAMBDA_A 0.995 #define LAMBDA_B 0.5 @@ -73,41 +72,6 @@ #define SLOW_PEAK_LEARN_FACTOR 0.9 #define SPEECH_VOLUME_RANGE 8.0 -struct noise_stats_s { - /* Smoothed power */ - powspec_t *power; - /* Noise estimate */ - powspec_t *noise; - /* Signal floor estimate */ - powspec_t *floor; - /* Peak for temporal masking */ - powspec_t *peak; - /* Buffers used in update_noisestats */ - powspec_t *signal, *gain; - - /* Initialize it next time */ - int undefined; - /* Number of items to process */ - int num_filters; - - /* Sum of slow peaks for VAD */ - powspec_t slow_peak_sum; - - /* Precomputed constants */ - powspec_t lambda_power; - powspec_t comp_lambda_power; - powspec_t lambda_a; - powspec_t comp_lambda_a; - powspec_t lambda_b; - powspec_t comp_lambda_b; - powspec_t lambda_t; - powspec_t mu_t; - powspec_t max_gain; - powspec_t inv_max_gain; - - powspec_t smooth_scaling[2 * SMOOTH_WINDOW + 3]; -}; - static void fe_lower_envelope(noise_stats_t *noise_stats, const powspec_t *buf, powspec_t *floor_buf, int32 num_filt) { diff --git a/src/fe/fe_noise.h b/src/fe/fe_noise.h index 964e29812..5765c4205 100644 --- a/src/fe/fe_noise.h +++ b/src/fe/fe_noise.h @@ -43,6 +43,43 @@ typedef struct noise_stats_s noise_stats_t; +#define SMOOTH_WINDOW 4 + +struct noise_stats_s { + /* Smoothed power */ + powspec_t *power; + /* Noise estimate */ + powspec_t *noise; + /* Signal floor estimate */ + powspec_t *floor; + /* Peak for temporal masking */ + powspec_t *peak; + /* Buffers used in update_noisestats */ + powspec_t *signal, *gain; + + /* Initialize it next time */ + int undefined; + /* Number of items to process */ + int num_filters; + + /* Sum of slow peaks for VAD */ + powspec_t slow_peak_sum; + + /* Precomputed constants */ + powspec_t lambda_power; + powspec_t comp_lambda_power; + powspec_t lambda_a; + powspec_t comp_lambda_a; + powspec_t lambda_b; + powspec_t comp_lambda_b; + powspec_t lambda_t; + powspec_t mu_t; + powspec_t max_gain; + powspec_t inv_max_gain; + + powspec_t smooth_scaling[2 * SMOOTH_WINDOW + 3]; +}; + /* Creates noisestats object */ noise_stats_t *fe_init_noisestats(int num_filters); diff --git a/src/pocketsphinx.c b/src/pocketsphinx.c index 84cfc4b67..55a5d9fcf 100644 --- a/src/pocketsphinx.c +++ b/src/pocketsphinx.c @@ -1076,8 +1076,6 @@ ps_start_stream(ps_decoder_t *ps) return -1; if (ps->acmod->fe == NULL) return -1; - if (ps->acmod->fe->noise_stats == NULL) - return -1; fe_reset_noisestats(ps->acmod->fe->noise_stats); return 0; } diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index 4c0d08db7..88e60977a 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -37,6 +37,7 @@ set(TESTS test_senfh test_set_search test_simple + test_start_stream test_state_align test_vad test_vad_alloc diff --git a/test/unit/test_start_stream.c b/test/unit/test_start_stream.c new file mode 100644 index 000000000..1c07b2d83 --- /dev/null +++ b/test/unit/test_start_stream.c @@ -0,0 +1,47 @@ +#include + +#include "pocketsphinx_internal.h" +#include "fe/fe_internal.h" +#include "fe/fe_noise.h" +#include "test_macros.h" + +static ps_config_t * +make_config(void) +{ + return ps_config_parse_json( + NULL, + "hmm: \"" DATADIR "/an4_ci_cont\"," + "lm: \"" DATADIR "/turtle.lm.bin\"," + "dict: \"" DATADIR "/turtle.dic\"," + "samprate: 16000"); +} + +int +main(int argc, char *argv[]) +{ + ps_config_t *config; + ps_decoder_t *ps; + + (void)argc; + (void)argv; + + TEST_ASSERT(config = make_config()); + TEST_ASSERT(ps = ps_init(config)); + TEST_ASSERT(!ps_config_bool(ps_get_config(ps), "remove_noise")); + TEST_EQUAL(0, ps_start_stream(ps)); + ps_free(ps); + ps_config_free(config); + + TEST_ASSERT(config = make_config()); + TEST_ASSERT(ps_config_set_bool(config, "remove_noise", TRUE)); + TEST_ASSERT(ps = ps_init(config)); + TEST_ASSERT(ps_config_bool(ps_get_config(ps), "remove_noise")); + TEST_ASSERT(ps->acmod->fe->noise_stats != NULL); + ps->acmod->fe->noise_stats->undefined = FALSE; + TEST_EQUAL(0, ps_start_stream(ps)); + TEST_ASSERT(ps->acmod->fe->noise_stats->undefined); + ps_free(ps); + ps_config_free(config); + + return 0; +}