aboutsummaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorAndreas Eversberg <jolly@eversberg.eu>2016-05-11 18:42:22 +0200
committerAndreas Eversberg <jolly@eversberg.eu>2016-05-13 09:37:02 +0200
commit42eefe90bff55b0fe534b5cb6beeb0d10ff8e19e (patch)
tree7db994babe1783cfb8f9bd438cfb811f749f9a28 /src/test
parent3a54f46b81b5dc0254ed6fd8a4994fd23f9ca143 (diff)
common code: Fixed de-emphasis by adding high pass filter
This high-pass filter filters out DC and frequencies below 300 Hz. Now de-emphases will not cause low frequencies to saturate audio level range or cause too high levels on low frequencies.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test_emphasis.c46
1 files changed, 22 insertions, 24 deletions
diff --git a/src/test/test_emphasis.c b/src/test/test_emphasis.c
index dc95023..5e4720e 100644
--- a/src/test/test_emphasis.c
+++ b/src/test/test_emphasis.c
@@ -3,6 +3,7 @@
#include <math.h>
#include <string.h>
#include "../common/emphasis.h"
+#include "../common/debug.h"
#define level2db(level) (20 * log10(level))
#define db2level(db) pow(10, (double)db / 20.0)
@@ -10,39 +11,36 @@
#define SAMPLERATE 48000
#define DEVIATION 8000.0
-static void check_level(int16_t *samples, const char *desc)
+static double test_freq[] = { 25, 50, 100, 150, 200, 250, 300, 350, 400, 500, 1000, 2000, 4000, 0 };
+
+static void check_level(int16_t *samples, double freq, const char *desc)
{
int i;
int last = 0, envelope = 0;
int up = 0;
- int freq;
for (i = 0; i < SAMPLERATE; i++) {
if (last < samples[i]) {
up = 1;
} else if (last > samples[i]) {
if (up) {
- envelope = last;
+ if (last > envelope)
+ envelope = last;
}
up = 0;
}
- if ((i % (SAMPLERATE/40)) == 0) {
- freq = 500 + 500 * (i / (SAMPLERATE / 8));
- printf("%s: f = %d envelop = %.4f\n", desc, freq, level2db((double)envelope / DEVIATION));
- }
last = samples[i];
}
+ printf("%s: f = %.0f envelop = %.4f\n", desc, freq, level2db((double)envelope / DEVIATION));
}
-static void gen_samples(int16_t *samples)
+static void gen_samples(int16_t *samples, double freq)
{
int i;
double value;
- int freq;
for (i = 0; i < SAMPLERATE; i++) {
- freq = 500 + 500 * (i / (SAMPLERATE / 8));
- value = sin(2.0 * M_PI * (double)freq / (double)SAMPLERATE * (double)i);
+ value = sin(2.0 * M_PI * freq / (double)SAMPLERATE * (double)i);
samples[i] = value * DEVIATION;
}
}
@@ -51,26 +49,26 @@ int main(void)
{
emphasis_t estate;
int16_t samples[SAMPLERATE];
+ int i;
- printf("1000 Hz shall be close to 0 dB, that is no significant change in volume.\n\n");
+ debuglevel = DEBUG_DEBUG;
- /* generate sweep 0..4khz */
- gen_samples(samples);
+ printf("1000 Hz shall be close to 0 dB, that is no significant change in volume.\n\n");
init_emphasis(&estate, SAMPLERATE);
-// check_level(samples, "unchanged");
-
- pre_emphasis(&estate, samples, SAMPLERATE);
-
- check_level(samples, "pre-emphasis");
+ for (i = 0; test_freq[i]; i++) {
+ gen_samples(samples, test_freq[i]);
+ pre_emphasis(&estate, samples, SAMPLERATE);
+ check_level(samples, test_freq[i], "pre-emphasis");
+ }
/* generate sweep 0..4khz */
- gen_samples(samples);
-
- de_emphasis(&estate, samples, SAMPLERATE);
-
- check_level(samples, "de-emphasis");
+ for (i = 0; test_freq[i]; i++) {
+ gen_samples(samples, test_freq[i]);
+ de_emphasis(&estate, samples, SAMPLERATE);
+ check_level(samples, test_freq[i], "de-emphasis");
+ }
return 0;
}