Beispiel #1
0
/*
 * slapi_eq_once: cause an event to happen exactly once.
 * 
 * Arguments:
 *  fn: the function to call
 *  arg: an argument to pass to the called function
 *  when: the time that the function should be called
 * Returns:
 *  slapi_eq_context - a handle to an opaque object which
 *  the caller can use to refer to this particular scheduled
 *  event.
 */
Slapi_Eq_Context
slapi_eq_once(slapi_eq_fn_t fn, void *arg, time_t when)
{
	slapi_eq_context *tmp;
	PR_ASSERT(eq_initialized);
	if (!eq_stopped) {
		
		Slapi_Eq_Context id;

		tmp = eq_new(fn, arg, when, 0UL);
		id = tmp->ec_id;

		eq_enqueue(tmp);

		/* After this point, <tmp> may have      */
		/* been freed, depending on the thread   */
		/* scheduling. Too bad			 */

		slapi_log_error(SLAPI_LOG_HOUSE, NULL,
				"added one-time event id %p at time %ld\n",
				id, when);
		return(id);
	}
	return NULL; /* JCM - Not sure if this should be 0 or something else. */
}
/* 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);
}
/* Runs the filters on an input file */
static void test_file(const char *input_filename, const char *output_filename)
{
    size_t frames;
    int i;
    double NQ = 44100 / 2; /* nyquist frequency */
    struct timespec tp1, tp2;
    struct eq *eq;

    float *data = read_raw(input_filename, &frames);

    /* Set some data to 0 to test for denormals. */
    for (i = frames / 10; i < frames; i++)
        data[i] = 0.0;

    /* Left eq chain */
    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);
    process(eq, data, frames);
    clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp2);
    printf("processing takes %g seconds for %zu samples\n",
           tp_diff(&tp2, &tp1), frames);
    eq_free(eq);

    /* Right eq chain */
    eq = eq_new();
    eq_append_biquad(eq, BQ_PEAKING, 450/NQ, 3, -12);
    eq_append_biquad(eq, BQ_PEAKING, 721/NQ, 3, -12);
    eq_append_biquad(eq, BQ_PEAKING, 1800/NQ, 8, -10.2);
    eq_append_biquad(eq, BQ_PEAKING, 580/NQ, 6, -8);
    eq_append_biquad(eq, BQ_HIGHPASS, 250/NQ, 0.6578, 0);
    eq_append_biquad(eq, BQ_HIGHSHELF, 8000/NQ, 0, 2);
    clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp1);
    process(eq, data + frames, frames);
    clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp2);
    printf("processing takes %g seconds for %zu samples\n",
           tp_diff(&tp2, &tp1), frames);
    eq_free(eq);

    write_raw(output_filename, data, frames);
    free(data);
}
Beispiel #4
0
/*
 * slapi_eq_repeat: cause an event to happen repeatedly.
 * 
 * Arguments:
 *  fn: the function to call
 *  arg: an argument to pass to the called function
 *  when: the time that the function should first be called
 *  interval: the amount of time (in milliseconds) between
 *            successive calls to the function
 * Returns:
 *  slapi_eq_context - a handle to an opaque object which
 *  the caller can use to refer to this particular scheduled
 */
Slapi_Eq_Context
slapi_eq_repeat(slapi_eq_fn_t fn, void *arg, time_t when, unsigned long interval)
{
	slapi_eq_context *tmp ;
	PR_ASSERT(eq_initialized);
	if (!eq_stopped) {
		tmp = eq_new(fn, arg, when, interval);
		eq_enqueue(tmp);
		slapi_log_error(SLAPI_LOG_HOUSE, NULL,
				"added repeating event id %p at time %ld, interval %lu\n",
				tmp->ec_id, when, interval);
		return(tmp->ec_id);
	}
	return NULL; /* JCM - Not sure if this should be 0 or something else. */
}
Beispiel #5
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);
}