Changeset 5181:ca57e34b2a35 in roaraudio for libroardsp
- Timestamp:
- 10/22/11 16:17:35 (13 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- libroardsp
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
libroardsp/filter.c
r5177 r5181 36 36 } _roardsp_filterlist[] = { 37 37 {ROARDSP_FILTER_AMP, "AMP", roardsp_amp_init, roardsp_amp_uninit, roardsp_amp_ctl, roardsp_amp_reset, { 38 {NULL, NULL, NULL},{roardsp_amp_calc8, NULL, NULL},{roardsp_amp_calc16, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL}}}, 39 {ROARDSP_FILTER_ADD, "Add", roardsp_add_init, roardsp_amp_uninit, roardsp_amp_ctl, roardsp_add_reset, { 40 {NULL, NULL, NULL},{NULL, NULL, NULL},{roardsp_add_calc16, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL}}}, 38 {NULL, NULL, NULL},{roardsp_amp_calc8, NULL, NULL},{roardsp_amp_calc16, NULL, NULL}, 39 {NULL, NULL, NULL},{roardsp_amp_calc32, NULL, NULL}}}, 40 {ROARDSP_FILTER_ADD, "Add", roardsp_amp_init, roardsp_amp_uninit, roardsp_amp_ctl, roardsp_add_reset, { 41 {NULL, NULL, NULL},{roardsp_add_calc8, NULL, NULL},{roardsp_add_calc16, NULL, NULL}, 42 {NULL, NULL, NULL},{roardsp_add_calc32, NULL, NULL}}}, 41 43 #ifdef ROAR_HAVE_LIBM 42 44 {ROARDSP_FILTER_LOWP, "Lowpass", roardsp_lowp_init, roardsp_lowp_uninit, roardsp_lowp_ctl, roardsp_lowp_reset, { 43 {NULL, NULL, NULL},{NULL, NULL, NULL},{roardsp_lowp_calc16, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL}}}, 45 {NULL, NULL, NULL},{roardsp_lowp_calc8, NULL, NULL},{roardsp_lowp_calc16, NULL, NULL}, 46 {NULL, NULL, NULL},{roardsp_lowp_calc32, NULL, NULL}}}, 44 47 {ROARDSP_FILTER_HIGHP, "Highpass", roardsp_highp_init, roardsp_highp_uninit, roardsp_highp_ctl, roardsp_highp_reset, { 45 {NULL, NULL, NULL},{NULL, NULL, NULL},{roardsp_highp_calc16, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL}}}, 48 {NULL, NULL, NULL},{roardsp_highp_calc8, NULL, NULL},{roardsp_highp_calc16, NULL, NULL}, 49 {NULL, NULL, NULL},{roardsp_highp_calc32, NULL, NULL}}}, 46 50 #endif 47 51 {ROARDSP_FILTER_QUANTIFY, "Quantifier", roardsp_quantify_init, NULL, roardsp_quantify_ctl, roardsp_quantify_reset, { 48 {NULL, NULL, NULL},{NULL, NULL, NULL},{roardsp_quantify_calc16, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL}}}, 52 {NULL, NULL, NULL},{roardsp_quantify_calc8, NULL, NULL},{roardsp_quantify_calc16, NULL, NULL}, 53 {NULL, NULL, NULL},{roardsp_quantify_calc32, NULL, NULL}}}, 49 54 {ROARDSP_FILTER_CLIP, "Clip", roardsp_clip_init, roardsp_clip_uninit, roardsp_clip_ctl, roardsp_clip_reset, { 50 55 {NULL, NULL, NULL},{roardsp_clip_calc8, NULL, NULL},{roardsp_clip_calc16, NULL, NULL}, … … 55 60 {NULL, NULL, NULL},{NULL, NULL, NULL},{roardsp_dcblock_calc16, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL}}}, 56 61 {ROARDSP_FILTER_SWAP, "Swap", roardsp_swap_init, roardsp_swap_uninit, roardsp_swap_ctl, roardsp_swap_reset, { 57 {NULL, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, roardsp_swap_calc162},{NULL, NULL, NULL},{NULL, NULL, NULL}}}, 62 {NULL, NULL, NULL},{NULL, NULL, roardsp_swap_calc82},{NULL, NULL, roardsp_swap_calc162}, 63 {NULL, NULL, NULL},{NULL, NULL, roardsp_swap_calc322}}}, 58 64 {ROARDSP_FILTER_AGC, "AGC", roardsp_agc_init, roardsp_agc_uninit, roardsp_agc_ctl, roardsp_agc_reset, { 59 65 {NULL, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL}}}, -
libroardsp/filter_add.c
r4708 r5181 26 26 #include "libroardsp.h" 27 27 28 int roardsp_add_init (struct roardsp_filter * filter, struct roar_stream * stream, int id) { 29 struct roardsp_amp * self = roar_mm_malloc(sizeof(struct roardsp_amp)); 30 31 if ( self == NULL ) 32 return -1; 33 34 memset(self, 0, sizeof(struct roardsp_amp)); 35 36 filter->inst = (void*) self; 37 38 roardsp_filter_reset(filter, ROARDSP_RESET_FULL); 39 40 return 0; 28 #define _calcX(bits) \ 29 int roardsp_add_calc##bits (struct roardsp_filter * filter, void * data, size_t samples) { \ 30 struct roardsp_amp * self = (struct roardsp_amp *) filter->inst; \ 31 int##bits##_t * samp = (int##bits##_t *) data; \ 32 size_t i; \ 33 \ 34 for (i = 0; i < samples; i++) { \ 35 samp[i] += self->mul / self->div; \ 36 }; \ 37 \ 38 return 0; \ 41 39 } 42 40 43 int roardsp_add_calc16 (struct roardsp_filter * filter, void * data, size_t samples) { 44 struct roardsp_amp * self = (struct roardsp_amp *) filter->inst; 45 int16_t * samp = (int16_t *) data; 46 size_t i; 47 48 for (i = 0; i < samples; i++) { 49 samp[i] += self->mul / self->div; 50 }; 51 52 return 0; 53 } 41 _calcX(8) 42 _calcX(16) 43 _calcX(32) 54 44 55 45 int roardsp_add_reset (struct roardsp_filter * filter, int what) { -
libroardsp/filter_amp.c
r4708 r5181 47 47 } 48 48 49 int roardsp_amp_calc8 (struct roardsp_filter * filter, void * data, size_t samples) { 50 struct roardsp_amp * self = (struct roardsp_amp *) filter->inst; 51 int8_t * samp = (int8_t *) data; 52 register int_least32_t s; 53 size_t i; 54 55 for (i = 0; i < samples; i++) { 56 s = samp[i]; 57 s *= self->mul; 58 s /= self->div; 59 samp[i] = s; 60 }; 61 62 return 0; 49 #define _calcX(bits,twobits) \ 50 int roardsp_amp_calc##bits (struct roardsp_filter * filter, void * data, size_t samples) { \ 51 struct roardsp_amp * self = (struct roardsp_amp *) filter->inst; \ 52 int##bits##_t * samp = (int##bits##_t *) data; \ 53 register int##twobits##_t s; \ 54 size_t i; \ 55 \ 56 for (i = 0; i < samples; i++) { \ 57 s = samp[i]; \ 58 s *= self->mul; \ 59 s /= self->div; \ 60 samp[i] = s; \ 61 }; \ 62 \ 63 return 0; \ 63 64 } 64 65 65 int roardsp_amp_calc16 (struct roardsp_filter * filter, void * data, size_t samples) { 66 struct roardsp_amp * self = (struct roardsp_amp *) filter->inst; 67 int16_t * samp = (int16_t *) data; 68 register int_least32_t s; 69 size_t i; 70 71 for (i = 0; i < samples; i++) { 72 s = samp[i]; 73 s *= self->mul; 74 s /= self->div; 75 // ROAR_DBG("roardsp_amp_calc16(*): samp[i=%u] = %i, s=%i, self->mul=%i, self->div=%i", i, samp[i], s, self->mul, self->div); 76 samp[i] = s; 77 }; 78 79 return 0; 80 } 66 _calcX(8,16) 67 _calcX(16,32) 68 _calcX(32,64) 81 69 82 70 int roardsp_amp_ctl (struct roardsp_filter * filter, int cmd, void * data) { -
libroardsp/filter_downmix.c
r4708 r5181 99 99 100 100 int roardsp_downmix_reset (struct roardsp_filter * filter, int what) { 101 int mode = ROARDSP_DOWNMIX_ARITHMETIC;101 int32_t mode = ROARDSP_DOWNMIX_ARITHMETIC; 102 102 103 103 if ( filter == NULL ) -
libroardsp/filter_highp.c
r4708 r5181 30 30 int roardsp_highp_init (struct roardsp_filter * filter, struct roar_stream * stream, int id) { 31 31 struct roardsp_highp * self = roar_mm_malloc(sizeof(struct roardsp_highp)); 32 float freq = 25;33 32 34 33 if ( self == NULL ) … … 39 38 filter->inst = (void*) self; 40 39 41 roardsp_highp_ctl(filter, ROARDSP_FCTL_FREQ, &freq); 42 43 return 0; 40 return roardsp_filter_reset(filter, ROARDSP_RESET_FULL); 44 41 } 45 42 … … 50 47 } 51 48 52 int roardsp_highp_calc16(struct roardsp_filter * filter, void * data, size_t samples) { 53 struct roardsp_highp * self = (struct roardsp_highp *) filter->inst; 54 int16_t * samp = (int16_t *) data; 55 register int32_t s, h; 56 int i, c; 57 int channels = filter->channels; 49 #define _calcX(bits,twobits) \ 50 int roardsp_highp_calc##bits (struct roardsp_filter * filter, void * data, size_t samples) { \ 51 struct roardsp_highp * self = (struct roardsp_highp *) filter->inst; \ 52 int##bits##_t * samp = (int##bits##_t *) data; \ 53 register int##twobits##_t s, h; \ 54 int i, c; \ 55 int channels = filter->channels; \ 56 \ 57 if ( channels > ROAR_MAX_CHANNELS ) \ 58 return -1; \ 59 \ 60 samples /= channels; \ 61 \ 62 ROAR_DBG("roardsp_highp_calc16(*): filtering %i frames of %i channels...", samples, channels); \ 63 \ 64 /* * output[N] = A0 * input[N] + A1 * input[N-1] + B1 * output[N-1] */ \ 65 \ 66 \ 67 for (i = 0; i < samples; i++) { \ 68 for (c = 0; c < channels; c++) { \ 69 h = samp[i*channels + c]; \ 70 s = (int##twobits##_t)samp[i*channels + c] * self->a + (int##twobits##_t)self->oldin[c] * self->b + (int##twobits##_t)self->oldout[c] * self->c; \ 71 \ 72 s /= 65536; \ 73 \ 74 self->oldin[ c] = h; \ 75 samp[i*channels + c] = s; \ 76 self->oldout[ c] = s; \ 77 } \ 78 } \ 79 \ 80 return 0; \ 81 } 58 82 59 if ( channels > ROAR_MAX_CHANNELS ) 60 return -1; 61 62 samples /= channels; 63 64 ROAR_DBG("roardsp_highp_calc16(*): filtering %i frames of %i channels...", samples, channels); 65 66 // * output[N] = A0 * input[N] + A1 * input[N-1] + B1 * output[N-1] 67 68 69 for (i = 0; i < samples; i++) { 70 for (c = 0; c < channels; c++) { 71 h = samp[i*channels + c]; 72 s = samp[i*channels + c] * self->a + self->oldin[c] * self->b + self->oldout[c] * self->c; 73 74 s /= 65536; 75 76 self->oldin[ c] = h; 77 samp[i*channels + c] = s; 78 self->oldout[ c] = s; 79 } 80 } 81 82 return 0; 83 } 83 _calcX(8,32) /* we need 32 bit not 16 bit here as we multiplay with 65536 internally */ 84 _calcX(16,32) 85 _calcX(32,64) 84 86 85 87 int roardsp_highp_ctl (struct roardsp_filter * filter, int cmd, void * data) { … … 114 116 int roardsp_highp_reset (struct roardsp_filter * filter, int what) { 115 117 struct roardsp_highp * self; 116 float freq = 25 ;118 float freq = 25.; 117 119 118 120 if ( filter == NULL ) -
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; -
libroardsp/filter_quantify.c
r4708 r5181 33 33 } 34 34 35 int roardsp_quantify_calc16 (struct roardsp_filter * filter, void * data, size_t samples) { 36 int16_t * samp = (int16_t *) data; 37 register float s; 38 size_t i; 35 static inline int16_t _calc(int16_t val, void * inst) { 36 register float s = val; 37 s /= 32768; 38 s *= (ROAR_INSTINT)inst; 39 s = (int16_t)s; 40 s /= (ROAR_INSTINT)inst; 41 s *= 32768; 42 return s; 43 } 39 44 40 for (i = 0; i < samples; i++) { 41 s = samp[i]; 42 s /= 32768; 43 s *= (ROAR_INSTINT)filter->inst; 44 s = (int16_t)s; 45 // ROAR_WARN("roardsp_quantify_calc16(*): s=%f", s); 46 s /= (ROAR_INSTINT)filter->inst; 47 s *= 32768; 48 samp[i] = s; 49 }; 45 #define _calcX(bits,rshift,lshift) \ 46 /* this code is buggy for 8 bit filters */ \ 47 int roardsp_quantify_calc##bits (struct roardsp_filter * filter, void * data, size_t samples) { \ 48 int##bits##_t * samp = (int##bits##_t *) data; \ 49 size_t i; \ 50 \ 51 for (i = 0; i < samples; i++) { \ 52 samp[i] = _calc(samp[i] rshift, filter->inst) lshift; \ 53 } \ 54 \ 55 ROAR_DBG("roardsp_quantify_calc%i(*) = 0", bits); \ 56 return 0; \ 57 } 50 58 51 ROAR_DBG("roardsp_quantify_calc16(*) = 0"); 52 return 0; 53 } 59 /* look at our nice parameters ;) */ 60 _calcX(8,<< 8,>> 8) 61 _calcX(16,,) 62 _calcX(32,>> 16,<< 16) 54 63 55 64 int roardsp_quantify_ctl (struct roardsp_filter * filter, int cmd, void * data) { -
libroardsp/filter_swap.c
r4708 r5181 54 54 } 55 55 56 int roardsp_swap_calc162(struct roardsp_filter * filter, void * data, size_t samples) { 57 int16_t * d = data; 58 register int16_t s; 59 int i; 56 #define _calcX2(bits) \ 57 int roardsp_swap_calc##bits##2(struct roardsp_filter * filter, void * data, size_t samples) { \ 58 int##bits##_t * d = data; \ 59 register int##bits##_t s; \ 60 size_t i; \ 61 \ 62 for (i = 0; i < samples; i += 2) { \ 63 ROAR_DBG("roardsp_swap_calc*2(*): d[i]=%i, d[i+1]=%i", d[i], d[i+1]); \ 64 s = d[i]; \ 65 d[i] = d[i+1]; \ 66 d[i+1] = s; \ 67 } \ 68 \ 69 return 0; \ 70 } 60 71 61 for (i = 0; i < samples; i += 2) { 62 ROAR_DBG("roardsp_swap_calc162(*): d[i]=%i, d[i+1]=%i", d[i], d[i+1]); 63 s = d[i]; 64 d[i] = d[i+1]; 65 d[i+1] = s; 66 } 67 68 return 0; 69 } 72 _calcX2(8) 73 _calcX2(16) 74 _calcX2(32) 70 75 71 76 int roardsp_swap_ctl (struct roardsp_filter * filter, int cmd, void * data) {
Note: See TracChangeset
for help on using the changeset viewer.