/* Generates impulse response */
static void test_ir()
{
    int N = 32768;
    float *data;
    struct eq *eq;
    double NQ = 44100 / 2; /* nyquist frequency */
    struct timespec tp1, tp2;
    int i;
    FILE *ir;

    data = calloc(1, sizeof(float) * N);
    data[0] = 1;

    eq = eq_new();
    eq_append_biquad(eq, BQ_PEAKING, 380/NQ, 3, -10);
    eq_append_biquad(eq, BQ_PEAKING, 720/NQ, 3, -12);
    eq_append_biquad(eq, BQ_PEAKING, 1705/NQ, 3, -8);
    eq_append_biquad(eq, BQ_HIGHPASS, 218/NQ, 0.7, -10.2);
    eq_append_biquad(eq, BQ_PEAKING, 580/NQ, 6, -8);
    eq_append_biquad(eq, BQ_HIGHSHELF, 8000/NQ, 3, 2);

    clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp1);
    eq_process(eq, data, N);
    clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp2);
    printf("processing takes %g seconds\n", tp_diff(&tp2, &tp1));
    eq_free(eq);

    ir = fopen("ir.dat", "w");
    for (i = 0; i < N; i++)
        fprintf(ir, "%g\n", data[i]);
    fclose(ir);
    free(data);
}
Exemple #2
0
static void eq_run(struct dsp_module *module, unsigned long sample_count)
{
	struct eq_data *data = (struct eq_data *) module->data;
	if (!data->eq) {
		float nyquist = data->sample_rate / 2;
		int i;

		data->eq = eq_new();
		for (i = 2; i < 2 + MAX_BIQUADS_PER_EQ * 4; i += 4) {
			if (!data->ports[i])
				break;
			int type = (int) *data->ports[i];
			float freq = *data->ports[i+1];
			float Q = *data->ports[i+2];
			float gain = *data->ports[i+3];
			eq_append_biquad(data->eq, type, freq / nyquist, Q,
					 gain);
		}
	}
	if (data->ports[0] != data->ports[1])
		memcpy(data->ports[1], data->ports[0],
		       sizeof(float) * sample_count);
	eq_process(data->eq, data->ports[1], (int) sample_count);
}
/* Processes a buffer of data chunk by chunk using eq */
static void process(struct eq *eq, float *data, int count)
{
    int start;
    for (start = 0; start < count; start += 2048)
        eq_process(eq, data + start, min(2048, count - start));
}