Skip to content

Make ps_start_stream() succeed when noise removal is disabled - #493

Open
lenzo-ka wants to merge 2 commits into
cmusphinx:mainfrom
lenzo-ka:start_stream_no_noise_stats
Open

Make ps_start_stream() succeed when noise removal is disabled#493
lenzo-ka wants to merge 2 commits into
cmusphinx:mainfrom
lenzo-ka:start_stream_no_noise_stats

Conversation

@lenzo-ka

@lenzo-ka lenzo-ka commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

ps_start_stream() returned -1 whenever noise removal was disabled, which is the shipped default (-remove_noise no). The front end allocates noise statistics only when noise removal is enabled, and ps_start_stream() treated their absence as an error, so a caller of this documented compatibility function got a failure return from a successfully initialized decoder. The header states no such precondition, and fe_reset_noisestats() is already a no-op on a null pointer.

The fix calls fe_reset_noisestats() unconditionally and returns 0; when there are no statistics to reset the call is a successful no-op, now stated in the header documentation. Behavior with noise removal enabled is unchanged.

A first commit moves the noise_stats_s definition from fe_noise.c into the internal header fe_noise.h, with no functional change, so internal consumers can compile against the real layout instead of duplicating it.

The new unit test test_start_stream initializes a real decoder both ways: with noise removal disabled it asserts a zero return, and with it enabled it asserts the statistics are actually reset. The disabled case fails against the previous implementation.

Fixes #496

Tested on macOS (Apple clang) and Linux x86-64 (GCC 13.3); full unit and regression suite passes on both.

No functional change. The definition was private to fe_noise.c;
internal consumers, including tests, can now compile against the
real layout instead of duplicating it.
With the default remove_noise=no the front end allocates no noise
statistics, and ps_start_stream() returned -1 on a successfully
initialized decoder. Callers that treat a negative return as failure
rejected a valid decoder in the default configuration, and the
documented contract states no such precondition.

fe_reset_noisestats() is already a no-op on a null pointer, so call
it unconditionally and return 0. Document the no-op case in the
header. Behavior with noise removal enabled is unchanged.

test_start_stream covers both settings: it asserts a zero return
with noise removal disabled, and that the statistics are actually
reset when it is enabled. The disabled case fails against the
previous implementation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

ps_start_stream() returns -1 when remove_noise is false

1 participant