Skip to content

Commit affa43f

Browse files
committed
Use WAV file sample rate unless user explicitly set samprate
Fixes issue where WAV file sample rates were ignored because the check for 'samprate == 0' always failed (samprate defaults to 16000). Now checks if -samprate was actually passed on the command line. If not, uses the WAV file's sample rate. If user explicitly set it, respects their choice. This allows WAV files with any sample rate (8kHz, 24kHz, 32kHz, 48kHz, etc.) to be processed correctly without requiring users to manually specify -samprate.
1 parent 71b75d4 commit affa43f

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

‎src/util/soundfiles.c‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include <pocketsphinx.h>
4444
#include "util/byteorder.h"
4545
#include "util/ckd_alloc.h"
46+
#include "util/cmd_ln.h"
4647

4748
#define TRY_FREAD(ptr, size, nmemb, stream) \
4849
if (fread(ptr, size, nmemb, stream) != (nmemb)) { \
@@ -51,6 +52,22 @@
5152
goto error_out; \
5253
}
5354

55+
static int
56+
arg_was_set(ps_config_t *config, const char *name)
57+
{
58+
uint32 i;
59+
cmd_ln_t *cmdln = (cmd_ln_t *)config;
60+
for (i = 0; i < cmdln->f_argc; i++) {
61+
if (cmdln->f_argv[i] && cmdln->f_argv[i][0] == '-') {
62+
const char *arg = cmdln->f_argv[i] + 1;
63+
if (*arg == '-') arg++;
64+
if (0 == strcmp(arg, name))
65+
return 1;
66+
}
67+
}
68+
return 0;
69+
}
70+
5471
int
5572
ps_config_soundfile(ps_config_t *config, FILE *infh, const char *file)
5673
{
@@ -154,9 +171,9 @@ ps_config_wavfile(ps_config_t *config, FILE *infh, const char *file)
154171
/* Sampling rate (finally!) */
155172
TRY_FREAD(&intval, 4, 1, infh);
156173
SWAP_LE_32(&intval);
157-
if (ps_config_int(config, "samprate") == 0)
174+
if (!arg_was_set(config, "samprate")) {
158175
ps_config_set_int(config, "samprate", intval);
159-
else if (ps_config_int(config, "samprate") != intval) {
176+
} else if (ps_config_int(config, "samprate") != intval) {
160177
E_WARN("WAVE file sampling rate %d != samprate %d\n",
161178
intval, ps_config_int(config, "samprate"));
162179
}

0 commit comments

Comments
 (0)