Changeset 683:61cb5393b9a5 in roaraudio
- Timestamp:
- 08/27/08 16:50:45 (16 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- libroardsp
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libroardsp/filter.c
r681 r683 37 37 {ROARDSP_FILTER_LOWP, "Lowpass", roardsp_lowp_init, roardsp_lowp_uninit, roardsp_lowp_ctl, { 38 38 {NULL, NULL, NULL},{NULL, NULL, NULL},{roardsp_lowp_calc16, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL}}}, 39 {ROARDSP_FILTER_HIGHP, "Highpass", NULL, NULL, NULL, {40 {NULL, NULL, NULL},{NULL, NULL, NULL},{ NULL, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL}}},39 {ROARDSP_FILTER_HIGHP, "Highpass", roardsp_highp_init, roardsp_highp_uninit, roardsp_highp_ctl, { 40 {NULL, NULL, NULL},{NULL, NULL, NULL},{roardsp_highp_calc16, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL}}}, 41 41 {-1, NULL, NULL, NULL, NULL, { 42 42 // ? 8Bit 16Bit 24Bit 32Bit -
libroardsp/filter_highp.c
r658 r683 25 25 #include "libroardsp.h" 26 26 27 int roardsp_highp_init (struct roardsp_filter * filter, struct roar_stream * stream, int id) { 28 struct roardsp_highp * self = malloc(sizeof(struct roardsp_highp)); 29 float freq = 25; 30 31 if ( self == NULL ) 32 return -1; 33 34 memset(self, 0, sizeof(struct roardsp_highp)); 35 36 filter->inst = (void*) self; 37 38 roardsp_highp_ctl(filter, ROARDSP_FCTL_FREQ, &freq); 39 40 return 0; 41 } 42 43 int roardsp_highp_uninit(struct roardsp_filter * filter) { 44 45 free(filter->inst); 46 return 0; 47 } 48 49 int roardsp_highp_calc16(struct roardsp_filter * filter, void * data, size_t samples) { 50 struct roardsp_highp * self = (struct roardsp_highp *) filter->inst; 51 int16_t * samp = (int16_t *) data; 52 register int32_t s; 53 int i, c; 54 int channels = filter->channels; 55 56 if ( channels > ROAR_MAX_CHANNELS ) 57 return -1; 58 59 samples /= channels; 60 61 ROAR_DBG("roardsp_highp_calc16(*): filtering %i frames of %i channels...", samples, channels); 62 63 // * output[N] = A0 * input[N] + A1 * input[N-1] + B1 * output[N-1] 64 65 66 for (i = 0; i < samples; i++) { 67 for (c = 0; c < channels; c++) { 68 s = samp[i*channels + c] * self->a + self->oldin[c] * self->b + self->oldout[c] * self->c; 69 70 s /= 65536; 71 72 self->oldin[ c] = s; 73 samp[i*channels + c] = s; 74 self->oldout[ c] = s; 75 } 76 } 77 78 return 0; 79 } 80 81 int roardsp_highp_ctl (struct roardsp_filter * filter, int cmd, void * data) { 82 struct roardsp_highp * self = (struct roardsp_highp *) filter->inst; 83 float lp; 84 float oldfreq; 85 float newfreq; 86 87 if ( cmd != ROARDSP_FCTL_FREQ ) 88 return -1; 89 90 newfreq = *(float*)data; 91 92 lp = exp(-2 * M_PI * newfreq / filter->rate) * 65536; 93 94 self->a = (65536 + lp)/2; 95 self->b = -(65536 + lp)/2; 96 self->c = lp; 97 98 99 oldfreq = self->freq / 1000; 100 self->freq = newfreq * 1000; 101 102 *(float*)data = oldfreq; 103 104 ROAR_DBG("roardsp_highp_ctl(); oldfreq=%f, newfreq=%f", oldfreq, newfreq); 105 106 return 0; 107 } 108 27 109 //ll
Note: See TracChangeset
for help on using the changeset viewer.