Changeset 5181:ca57e34b2a35 in roaraudio for libroardsp/filter_lowp.c
- Timestamp:
- 10/22/11 16:17:35 (13 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libroardsp/filter_lowp.c
r5170 r5181 30 30 int roardsp_lowp_init (struct roardsp_filter * filter, struct roar_stream * stream, int id) { 31 31 struct roardsp_lowp * self = roar_mm_malloc(sizeof(struct roardsp_lowp)); 32 float freq = filter->rate/2.45;33 32 34 33 ROAR_DBG("roardsp_lowp_init(*): self=%p", self); … … 41 40 filter->inst = (void*) self; 42 41 43 roardsp_lowp_ctl(filter, ROARDSP_FCTL_FREQ, &freq); 44 45 return 0; 42 return roardsp_filter_reset(filter, ROARDSP_RESET_FULL); 46 43 } 47 44 48 45 int roardsp_lowp_uninit(struct roardsp_filter * filter) { 49 50 46 roar_mm_free(filter->inst); 51 47 return 0; 52 48 } 53 49 54 int roardsp_lowp_calc16 (struct roardsp_filter * filter, void * data, size_t samples) { 55 struct roardsp_lowp * self = (struct roardsp_lowp *) filter->inst; 56 int16_t * samp = (int16_t *) data; 57 register int32_t s; 58 int i, c; 59 int channels = filter->channels; 50 #define _calcX(bits,twobits) \ 51 int roardsp_lowp_calc##bits (struct roardsp_filter * filter, void * data, size_t samples) { \ 52 struct roardsp_lowp * self = (struct roardsp_lowp *) filter->inst; \ 53 int##bits##_t * samp = (int##bits##_t *) data; \ 54 register int##twobits##_t s; \ 55 int i, c; \ 56 int channels = filter->channels; \ 57 \ 58 if ( channels > ROAR_MAX_CHANNELS ) \ 59 return -1; \ 60 \ 61 samples /= channels; \ 62 \ 63 ROAR_DBG("roardsp_lowp_calc16(*): filtering %i frames of %i channels...", samples, channels); \ 64 \ 65 /* * output[N] = input[N] * A + output[N-1] * B */ \ 66 \ 67 for (i = 0; i < samples; i++) { \ 68 for (c = 0; c < channels; c++) { \ 69 s = (int##twobits##_t)samp[i*channels + c] * self->a + (int##twobits##_t)self->old[c] * self->b; \ 70 \ 71 s /= 65536; \ 72 \ 73 samp[i*channels + c] = s; \ 74 self->old[ c] = s; \ 75 } \ 76 } \ 77 \ 78 return 0; \ 79 } 60 80 61 if ( channels > ROAR_MAX_CHANNELS ) 62 return -1; 63 64 samples /= channels; 65 66 ROAR_DBG("roardsp_lowp_calc16(*): filtering %i frames of %i channels...", samples, channels); 67 68 // * output[N] = input[N] * A + output[N-1] * B 69 70 for (i = 0; i < samples; i++) { 71 for (c = 0; c < channels; c++) { 72 s = samp[i*channels + c] * self->a + self->old[c] * self->b; 73 74 s /= 65536; 75 76 samp[i*channels + c] = s; 77 self->old[ c] = s; 78 } 79 } 80 81 return 0; 82 } 81 _calcX(8,32) /* we need 32 bit not 16 bit here as we multiplay with 65536 internally */ 82 _calcX(16,32) 83 _calcX(32,64) 83 84 84 85 int roardsp_lowp_ctl (struct roardsp_filter * filter, int cmd, void * data) { … … 88 89 float newfreq; 89 90 90 if ( cmd != ROARDSP_FCTL_FREQ ) 91 if ( cmd != ROARDSP_FCTL_FREQ ) { 92 roar_err_set(ROAR_ERROR_BADRQC); 91 93 return -1; 94 } 92 95 93 96 newfreq = *(float*)data; 94 97 95 lp = exp(-2 * M_PI * newfreq / filter->rate) * 65536;98 lp = exp(-2. * M_PI * newfreq / filter->rate) * 65536.; 96 99 97 100 self->b = lp; 98 self->a = 65536 - lp;101 self->a = 65536. - lp; 99 102 100 oldfreq = self->freq / 1000 ;101 self->freq = newfreq * 1000 ;103 oldfreq = self->freq / 1000.; 104 self->freq = newfreq * 1000.; 102 105 103 106 *(float*)data = oldfreq;
Note: See TracChangeset
for help on using the changeset viewer.