Changeset 5177:49fc5113e053 in roaraudio
- Timestamp:
- 10/22/11 13:28:14 (11 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
include/libroardsp/filters.h
r5173 r5177 130 130 int roardsp_clip_init (struct roardsp_filter * filter, struct roar_stream * stream, int id); 131 131 int roardsp_clip_uninit(struct roardsp_filter * filter); 132 int roardsp_clip_calc8 (struct roardsp_filter * filter, void * data, size_t samples); 132 133 int roardsp_clip_calc16(struct roardsp_filter * filter, void * data, size_t samples); 134 int roardsp_clip_calc32(struct roardsp_filter * filter, void * data, size_t samples); 133 135 int roardsp_clip_ctl (struct roardsp_filter * filter, int cmd, void * data); 134 136 int roardsp_clip_reset (struct roardsp_filter * filter, int what); -
libroardsp/filter.c
r5173 r5177 48 48 {NULL, NULL, NULL},{NULL, NULL, NULL},{roardsp_quantify_calc16, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL}}}, 49 49 {ROARDSP_FILTER_CLIP, "Clip", roardsp_clip_init, roardsp_clip_uninit, roardsp_clip_ctl, roardsp_clip_reset, { 50 {NULL, NULL, NULL},{NULL, NULL, NULL},{roardsp_clip_calc16, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL}}}, 50 {NULL, NULL, NULL},{roardsp_clip_calc8, NULL, NULL},{roardsp_clip_calc16, NULL, NULL}, 51 {NULL, NULL, NULL},{roardsp_clip_calc32, NULL, NULL}}}, 51 52 {ROARDSP_FILTER_DOWNMIX, "downmix", roardsp_quantify_init, NULL, roardsp_downmix_ctl, roardsp_downmix_reset, { 52 53 {NULL, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, roardsp_downmix_calc162},{NULL, NULL, NULL},{NULL, NULL, NULL}}}, -
libroardsp/filter_clip.c
r5175 r5177 38 38 } 39 39 40 static inline int16_t _clip16(int16_t s, struct roardsp_clip * self) { 41 switch (self->mode) { 42 case ROARDSP_CLIP_MODE_LIMIT: 43 return s > 0 ? self->limit : -self->limit; 44 break; 45 case ROARDSP_CLIP_MODE_ZERO: 46 return 0; 47 break; 48 case ROARDSP_CLIP_MODE_WARP: 49 if ( s > 0 ) { 50 return s - 2*self->limit; 51 } else { 52 return s + 2*self->limit; 53 } 54 break; 55 case ROARDSP_CLIP_MODE_NOISE: 56 return (s > 0 ? 1 : -1) * (self->limit - (roar_random_uint16() & 0xFF)); 57 break; 58 } 59 60 ROAR_WARN("_clip16(s=%i, self=%p{.mode=%i, ...}) = 0 // ERROR: Bad mode", (int)s, self, (int)self->mode); 61 return 0; 40 #define _clipX(bits) \ 41 static inline int##bits##_t _clip##bits (int##bits##_t s, struct roardsp_clip * self) { \ 42 switch (self->mode) { \ 43 case ROARDSP_CLIP_MODE_LIMIT: \ 44 return s > 0 ? self->limit : -self->limit; \ 45 break; \ 46 case ROARDSP_CLIP_MODE_ZERO: \ 47 return 0; \ 48 break; \ 49 case ROARDSP_CLIP_MODE_WARP: \ 50 if ( s > 0 ) { \ 51 return s - 2*self->limit; \ 52 } else { \ 53 return s + 2*self->limit; \ 54 } \ 55 break; \ 56 case ROARDSP_CLIP_MODE_NOISE: \ 57 return (s > 0 ? 1 : -1) * (self->limit - (roar_random_uint16() & 0xFF)); \ 58 break; \ 59 } \ 60 \ 61 ROAR_WARN("_clip16(s=%i, self=%p{.mode=%i, ...}) = 0 // ERROR: Bad mode", (int)s, self, (int)self->mode); \ 62 return 0; \ 62 63 } 63 64 64 int roardsp_clip_calc16 (struct roardsp_filter * filter, void * data, size_t samples) { 65 struct roardsp_clip * self = filter->inst; 66 int16_t * samp = (int16_t *) data; 67 register int32_t s = self->limit; 68 size_t i; 65 #define _calcX(bits) \ 66 int roardsp_clip_calc##bits (struct roardsp_filter * filter, void * data, size_t samples) { \ 67 struct roardsp_clip * self = filter->inst; \ 68 int##bits##_t * samp = (int##bits##_t *) data; \ 69 register int32_t s = self->limit; \ 70 size_t i; \ 71 \ 72 for (i = 0; i < samples; i++) { \ 73 if ( samp[i] > s ) { \ 74 samp[i] = _clip##bits (samp[i], self); \ 75 } else if ( -samp[i] > s ) { \ 76 samp[i] = _clip##bits (samp[i], self); \ 77 } \ 78 } \ 79 \ 80 ROAR_DBG("roardsp_quantify_calc16(*) = 0"); \ 81 return 0; \ 82 } 69 83 70 for (i = 0; i < samples; i++) { 71 if ( samp[i] > s ) { 72 samp[i] = _clip16(samp[i], self); 73 } else if ( -samp[i] > s ) { 74 samp[i] = _clip16(samp[i], self); 75 } 76 } 84 #define _setX(bits) \ 85 _clipX(bits) \ 86 _calcX(bits) 77 87 78 ROAR_DBG("roardsp_quantify_calc16(*) = 0"); 79 return 0; 80 } 88 _setX(8) 89 _setX(16) 90 _setX(32) 81 91 82 92 int roardsp_clip_ctl (struct roardsp_filter * filter, int cmd, void * data) { … … 107 117 108 118 int roardsp_clip_reset (struct roardsp_filter * filter, int what) { 109 int32_t n = 16384;110 119 int32_t mode = ROARDSP_CLIP_MODE_LIMIT; 120 int32_t n; 111 121 112 122 if ( filter == NULL ) 113 123 return -1; 124 125 switch (filter->bits) { 126 case 8: n = 64L; break; 127 case 16: n = 16384L; break; 128 case 32: n = 1073741824L; break; 129 default: 130 roar_err_set(ROAR_ERROR_NOTSUP); 131 return -1; 132 break; 133 } 114 134 115 135 switch (what) {
Note: See TracChangeset
for help on using the changeset viewer.