2016-04-23 16:50:11 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <string.h>
|
2017-11-18 07:06:06 +00:00
|
|
|
#include "../libsample/sample.h"
|
2017-11-13 18:15:09 +00:00
|
|
|
#include "../libfilter/iir_filter.h"
|
2017-11-16 17:16:53 +00:00
|
|
|
#include "../libemphasis/emphasis.h"
|
2017-11-18 07:58:57 +00:00
|
|
|
#include "../libdebug/debug.h"
|
2016-04-23 16:50:11 +00:00
|
|
|
|
|
|
|
#define level2db(level) (20 * log10(level))
|
|
|
|
#define db2level(db) pow(10, (double)db / 20.0)
|
|
|
|
|
|
|
|
#define SAMPLERATE 48000
|
|
|
|
|
2017-01-29 06:25:12 +00:00
|
|
|
static double get_level(sample_t *samples)
|
2016-04-23 16:50:11 +00:00
|
|
|
{
|
|
|
|
int i;
|
2017-01-28 07:02:11 +00:00
|
|
|
double envelope = 0;
|
|
|
|
for (i = SAMPLERATE/2; i < SAMPLERATE; i++) {
|
|
|
|
if (samples[i] > envelope)
|
|
|
|
envelope = samples[i];
|
2016-04-23 16:50:11 +00:00
|
|
|
}
|
2017-01-28 07:02:11 +00:00
|
|
|
|
|
|
|
return envelope;
|
2016-04-23 16:50:11 +00:00
|
|
|
}
|
|
|
|
|
2017-01-29 06:25:12 +00:00
|
|
|
static void gen_samples(sample_t *samples, double freq)
|
2016-04-23 16:50:11 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
double value;
|
|
|
|
|
|
|
|
for (i = 0; i < SAMPLERATE; i++) {
|
2017-01-28 07:02:11 +00:00
|
|
|
value = cos(2.0 * M_PI * freq / (double)SAMPLERATE * (double)i);
|
|
|
|
samples[i] = value;
|
2016-04-23 16:50:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-03 08:30:54 +00:00
|
|
|
int num_kanal;
|
2017-08-20 06:27:02 +00:00
|
|
|
|
2016-04-23 16:50:11 +00:00
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
emphasis_t estate;
|
2017-01-28 07:02:11 +00:00
|
|
|
double cut_off = CUT_OFF_EMPHASIS_DEFAULT;
|
2017-01-29 06:25:12 +00:00
|
|
|
sample_t samples[SAMPLERATE];
|
2017-01-28 07:02:11 +00:00
|
|
|
double level;
|
|
|
|
double i;
|
2016-04-23 16:50:11 +00:00
|
|
|
|
2018-01-20 14:49:19 +00:00
|
|
|
init_emphasis(&estate, SAMPLERATE, cut_off, CUT_OFF_HIGHPASS_DEFAULT, CUT_OFF_LOWPASS_DEFAULT);
|
2016-04-23 16:50:11 +00:00
|
|
|
|
2017-01-28 07:02:11 +00:00
|
|
|
printf("testing pre-emphasis filter with cut-off frequency %.1f\n", cut_off);
|
2016-04-23 16:50:11 +00:00
|
|
|
|
2017-01-28 07:02:11 +00:00
|
|
|
for (i = 31.25; i < 4001; i = i * sqrt(sqrt(2.0))) {
|
|
|
|
gen_samples(samples, (double)i);
|
2016-05-11 16:42:22 +00:00
|
|
|
pre_emphasis(&estate, samples, SAMPLERATE);
|
2017-01-28 07:02:11 +00:00
|
|
|
level = get_level(samples);
|
|
|
|
printf("%s%.0f Hz: %.1f dB", debug_db(level), i, level2db(level));
|
|
|
|
if ((int)round(i) == 1000)
|
|
|
|
printf(" level=%.6f\n", level);
|
|
|
|
else
|
|
|
|
printf("\n");
|
2016-05-11 16:42:22 +00:00
|
|
|
}
|
2016-04-23 16:50:11 +00:00
|
|
|
|
2017-01-28 07:02:11 +00:00
|
|
|
printf("testing de-emphasis filter with cut-off frequency %.1f\n", cut_off);
|
|
|
|
|
|
|
|
for (i = 31.25; i < 4001; i = i * sqrt(sqrt(2.0))) {
|
|
|
|
gen_samples(samples, (double)i);
|
2017-01-28 17:18:44 +00:00
|
|
|
dc_filter(&estate, samples, SAMPLERATE);
|
2016-05-11 16:42:22 +00:00
|
|
|
de_emphasis(&estate, samples, SAMPLERATE);
|
2017-01-28 07:02:11 +00:00
|
|
|
level = get_level(samples);
|
|
|
|
printf("%s%.0f Hz: %.1f dB", debug_db(level), i, level2db(level));
|
|
|
|
if ((int)round(i) == 1000)
|
|
|
|
printf(" level=%.6f\n", level);
|
|
|
|
else
|
|
|
|
printf("\n");
|
2016-05-11 16:42:22 +00:00
|
|
|
}
|
2016-04-23 16:50:11 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|