Skip to content

Commit b5f2e21

Browse files
committed
Made sample rate a changeable parameter.
1 parent a715054 commit b5f2e21

File tree

3 files changed

+109
-70
lines changed

3 files changed

+109
-70
lines changed

examples/rnnoise_demo.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,23 @@ int main(int argc, char **argv) {
4040
int channels;
4141
float x[FRAME_SIZE];
4242
short *tmp;
43+
int sample_rate;
4344
RNNModel *model = NULL;
4445
DenoiseState **sts;
4546
float max_attenuation;
46-
if (argc < 3) {
47-
fprintf(stderr, "usage: %s <channels> <max attenuation dB> [model]\n", argv[0]);
47+
if (argc < 4) {
48+
fprintf(stderr, "usage: %s <sample rate> <channels> <max attenuation dB> [model]\n", argv[0]);
4849
return 1;
4950
}
5051

51-
channels = atoi(argv[1]);
52+
sample_rate = atoi(argv[1]);
53+
if (sample_rate <= 0) sample_rate = 48000;
54+
channels = atoi(argv[2]);
5255
if (channels < 1) channels = 1;
53-
max_attenuation = pow(10, -atof(argv[2])/10);
56+
max_attenuation = pow(10, -atof(argv[3])/10);
5457

55-
if (argc >= 4) {
56-
model = rnnoise_get_model(argv[3]);
58+
if (argc >= 5) {
59+
model = rnnoise_get_model(argv[4]);
5760
if (!model) {
5861
fprintf(stderr, "Model not found!\n");
5962
return 1;
@@ -73,6 +76,7 @@ int main(int argc, char **argv) {
7376
for (i = 0; i < channels; i++) {
7477
sts[i] = rnnoise_create(model);
7578
rnnoise_set_param(sts[i], RNNOISE_PARAM_MAX_ATTENUATION, max_attenuation);
79+
rnnoise_set_param(sts[i], RNNOISE_PARAM_SAMPLE_RATE, sample_rate);
7680
}
7781

7882
while (1) {

include/rnnoise.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,17 @@ RNNOISE_EXPORT const char **rnnoise_models(void);
6767
RNNOISE_EXPORT RNNModel *rnnoise_get_model(const char *name);
6868

6969
/* Parameters to a denoise state */
70+
71+
/* RNNOISE_PARAM_MAX_ATTENUATION: The maximum attenuation to perform. Note that
72+
* this is described in terms of *minimum* gain, so for a 20dB maximum
73+
* attenuation, the correct value is 0.01. */
7074
#define RNNOISE_PARAM_MAX_ATTENUATION 1
7175

76+
/* RNNOISE_PARAM_SAMPLE_RATE: Sets the sample rate. This is just used to decide
77+
* how to bin the audio so that it matches the bins in the neural network. This
78+
* does not affect the frame size, which is always 480 samples. */
79+
#define RNNOISE_PARAM_SAMPLE_RATE 2
80+
7281
RNNOISE_EXPORT void rnnoise_set_param(DenoiseState *st, int param, float value);
7382

7483
#endif

0 commit comments

Comments
 (0)