TaudioFilterHeadphone2::af_hrtf_s::af_hrtf_s(const TsampleFormat &fmt):
    dlbuflen(DELAYBUFLEN),
    hrflen(HRTFFILTLEN),
    basslen(BASSFILTLEN),
    lf(DELAYBUFLEN),
    rf(DELAYBUFLEN),
    lr(DELAYBUFLEN),
    rr(DELAYBUFLEN),
    cf(DELAYBUFLEN),
    cr(DELAYBUFLEN),
    ba_l(DELAYBUFLEN),
    ba_r(DELAYBUFLEN),
    la(DELAYBUFLEN),
    ra(DELAYBUFLEN)
{
    cyc_pos = dlbuflen - 1;

    for(int i = 0; i < dlbuflen; i++)
        lf[i] = rf[i] = lr[i] = rr[i] = cf[i] =
                                            cr[i] = /* la[i] = ra[i] = */ 0;

    cf_ir = cf_filt + (cf_o = pulse_detect(cf_filt));
    af_ir = af_filt + (af_o = pulse_detect(af_filt));
    of_ir = of_filt + (of_o = pulse_detect(of_filt));
    ar_ir = ar_filt + (ar_o = pulse_detect(ar_filt));
    or_ir = or_filt + (or_o = pulse_detect(or_filt));
    cr_ir = cr_filt + (cr_o = pulse_detect(cr_filt));

    //ba_ir = (float*)malloc(basslen * sizeof(float));
    float fc = 2.0f * BASSFILTFREQ / (float)fmt.freq;
    ba_ir=TfirFilter::design_fir(&basslen, &fc, TfirSettings::LOWPASS, TfirSettings::WINDOW_KAISER, float(4*M_PI));
    for(unsigned int i = 0; i < basslen; i++) {
        ba_ir[i] *= BASSGAIN;
    }
}
Esempio n. 2
0
/* Allocate memory and set function pointers */
static int af_open(struct af_instance* af)
{
    int i;
    af_hrtf_t *s;
    float fc;

    af->control = control;
    af->uninit = uninit;
    af->play = play;
    af->setup = calloc(1, sizeof(af_hrtf_t));
    if(af->setup == NULL)
	return AF_ERROR;

    s = af->setup;

    s->dlbuflen = DELAYBUFLEN;
    s->hrflen = HRTFFILTLEN;
    s->basslen = BASSFILTLEN;

    s->cyc_pos = s->dlbuflen - 1;
    /* With a full (two axis) steering matrix decoder, s->matrix_mode
       should not be enabled lightly (it will also steer the Ls, Rs
       channels). */
    s->matrix_mode = 0;
    s->decode_mode = HRTF_MIX_51;

    s->print_flag = 1;

    if (allocate(s) != 0) {
 	mp_msg(MSGT_AFILTER, MSGL_ERR, "[hrtf] Memory allocation error.\n");
	return AF_ERROR;
    }

    for(i = 0; i < s->dlbuflen; i++)
	s->lf[i] = s->rf[i] = s->lr[i] = s->rr[i] = s->cf[i] =
	    s->cr[i] = 0;

    s->lr_fwr =
	s->rr_fwr = 0;

    s->cf_ir = cf_filt + (s->cf_o = pulse_detect(cf_filt));
    s->af_ir = af_filt + (s->af_o = pulse_detect(af_filt));
    s->of_ir = of_filt + (s->of_o = pulse_detect(of_filt));
    s->ar_ir = ar_filt + (s->ar_o = pulse_detect(ar_filt));
    s->or_ir = or_filt + (s->or_o = pulse_detect(or_filt));
    s->cr_ir = cr_filt + (s->cr_o = pulse_detect(cr_filt));

    if((s->ba_ir = malloc(s->basslen * sizeof(float))) == NULL) {
 	mp_msg(MSGT_AFILTER, MSGL_ERR, "[hrtf] Memory allocation error.\n");
	return AF_ERROR;
    }
    fc = 2.0 * BASSFILTFREQ / (float)af->data->rate;
    if(af_filter_design_fir(s->basslen, s->ba_ir, &fc, LP | KAISER, 4 * M_PI) ==
       -1) {
	mp_msg(MSGT_AFILTER, MSGL_ERR, "[hrtf] Unable to design low-pass "
	       "filter.\n");
	return AF_ERROR;
    }
    for(i = 0; i < s->basslen; i++)
	s->ba_ir[i] *= BASSGAIN;

    return AF_OK;
}
Esempio n. 3
0
File: af_hrtf.c Progetto: 0x0all/mpv
/* Allocate memory and set function pointers */
static int af_open(struct af_instance* af)
{
    int i;
    af_hrtf_t *s;
    float fc;

    af->control = control;
    af->uninit = uninit;
    af->filter = filter;

    s = af->priv;

    s->dlbuflen = DELAYBUFLEN;
    s->hrflen = HRTFFILTLEN;
    s->basslen = BASSFILTLEN;

    s->cyc_pos = s->dlbuflen - 1;
    /* With a full (two axis) steering matrix decoder, s->matrix_mode
       should not be enabled lightly (it will also steer the Ls, Rs
       channels). */
    s->matrix_mode = 0;
    s->decode_mode = HRTF_MIX_51;

    switch (s->mode) {
    case 0: /* Use matrix rear decoding. */
        s->matrix_mode = 1;
        break;
    case 1: /* Input needs matrix decoding. */
        s->decode_mode = HRTF_MIX_MATRIX2CH;
        break;
    case 2:
        s->matrix_mode = 0;
        break;
    }

    s->print_flag = 1;

    if (allocate(s) != 0) {
        MP_ERR(af, "Memory allocation error.\n");
        return AF_ERROR;
    }

    for(i = 0; i < s->dlbuflen; i++)
        s->lf[i] = s->rf[i] = s->lr[i] = s->rr[i] = s->cf[i] =
            s->cr[i] = 0;

    s->lr_fwr =
        s->rr_fwr = 0;

    s->cf_ir = cf_filt + (s->cf_o = pulse_detect(cf_filt));
    s->af_ir = af_filt + (s->af_o = pulse_detect(af_filt));
    s->of_ir = of_filt + (s->of_o = pulse_detect(of_filt));
    s->ar_ir = ar_filt + (s->ar_o = pulse_detect(ar_filt));
    s->or_ir = or_filt + (s->or_o = pulse_detect(or_filt));
    s->cr_ir = cr_filt + (s->cr_o = pulse_detect(cr_filt));

    if((s->ba_ir = malloc(s->basslen * sizeof(float))) == NULL) {
        MP_ERR(af, "Memory allocation error.\n");
        return AF_ERROR;
    }
    fc = 2.0 * BASSFILTFREQ / (float)af->data->rate;
    if(af_filter_design_fir(s->basslen, s->ba_ir, &fc, LP | KAISER, 4 * M_PI) ==
       -1) {
        MP_ERR(af, "Unable to design low-pass "
               "filter.\n");
        return AF_ERROR;
    }
    for(i = 0; i < s->basslen; i++)
        s->ba_ir[i] *= BASSGAIN;

    return AF_OK;
}