aboutsummaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
authorAndreas Eversberg <jolly@eversberg.eu>2017-03-04 16:52:20 +0100
committerAndreas Eversberg <jolly@eversberg.eu>2017-03-04 16:52:20 +0100
commit8e0d7d2513110e39d67dd7c31ae91dd95226f122 (patch)
tree27163815dca7590c5e32b114a6fe825a96a83f00 /src/common
parent3fc4fc54be56310650a9f7ea1183aa71a3d3ac4d (diff)
samplerate.c: Allow transcoding to lower sample rate other than 8000 Hz
Diffstat (limited to 'src/common')
-rw-r--r--src/common/call.c2
-rw-r--r--src/common/samplerate.c22
-rw-r--r--src/common/samplerate.h2
-rw-r--r--src/common/sender.c2
4 files changed, 13 insertions, 15 deletions
diff --git a/src/common/call.c b/src/common/call.c
index a8ac8e1..ff6128e 100644
--- a/src/common/call.c
+++ b/src/common/call.c
@@ -497,7 +497,7 @@ int call_init(const char *station_id, const char *audiodev, int samplerate, int
if (!audiodev[0])
return 0;
- rc = init_samplerate(&call.srstate, samplerate);
+ rc = init_samplerate(&call.srstate, 8000.0, (double)samplerate);
if (rc < 0) {
PDEBUG(DSENDER, DEBUG_ERROR, "Failed to init sample rate conversion!\n");
goto error;
diff --git a/src/common/samplerate.c b/src/common/samplerate.c
index 6eb4729..8187748 100644
--- a/src/common/samplerate.c
+++ b/src/common/samplerate.c
@@ -25,24 +25,22 @@
#include "sample.h"
#include "samplerate.h"
-int init_samplerate(samplerate_t *state, double samplerate)
+int init_samplerate(samplerate_t *state, double low_samplerate, double high_samplerate)
{
-#if 0
- if ((samplerate % 8000)) {
- fprintf(stderr, "Sample rate must be a muliple of 8000 to support MNCC socket interface, aborting!\n");
- return -EINVAL;
- }
-#endif
memset(state, 0, sizeof(*state));
- state->factor = samplerate / 8000.0;
+ state->factor = high_samplerate / low_samplerate;
+ if (state->factor < 1.0) {
+ fprintf(stderr, "Software error: Low sample rate must be lower than high sample rate, aborting!\n");
+ abort();
+ }
- filter_lowpass_init(&state->up.lp, 3300.0, samplerate, 2);
- filter_lowpass_init(&state->down.lp, 3300.0, samplerate, 2);
+ filter_lowpass_init(&state->up.lp, 3300.0, high_samplerate, 2);
+ filter_lowpass_init(&state->down.lp, 3300.0, high_samplerate, 2);
return 0;
}
-/* convert input sample rate to 8000 Hz */
+/* convert high sample rate to low sample rate */
int samplerate_downsample(samplerate_t *state, sample_t *samples, int input_num)
{
int output_num = 0, i, idx;
@@ -96,7 +94,7 @@ int samplerate_downsample(samplerate_t *state, sample_t *samples, int input_num)
return output_num;
}
-/* convert 8000 Hz sample rate to output sample rate */
+/* convert low sample rate to high sample rate */
int samplerate_upsample(samplerate_t *state, sample_t *input, int input_num, sample_t *output)
{
int output_num = 0, i, idx;
diff --git a/src/common/samplerate.h b/src/common/samplerate.h
index 5892bd8..8c69741 100644
--- a/src/common/samplerate.h
+++ b/src/common/samplerate.h
@@ -14,6 +14,6 @@ typedef struct samplerate {
} up;
} samplerate_t;
-int init_samplerate(samplerate_t *state, double samplerate);
+int init_samplerate(samplerate_t *state, double low_samplerate, double high_samplerate);
int samplerate_downsample(samplerate_t *state, sample_t *samples, int input_num);
int samplerate_upsample(samplerate_t *state, sample_t *input, int input_num, sample_t *output);
diff --git a/src/common/sender.c b/src/common/sender.c
index 055f84e..ca73496 100644
--- a/src/common/sender.c
+++ b/src/common/sender.c
@@ -114,7 +114,7 @@ int sender_create(sender_t *sender, int kanal, double sendefrequenz, double empf
}
}
- rc = init_samplerate(&sender->srstate, samplerate);
+ rc = init_samplerate(&sender->srstate, 8000.0, (double)samplerate);
if (rc < 0) {
PDEBUG(DSENDER, DEBUG_ERROR, "Failed to init sample rate conversion!\n");
goto error;