Changeset 5173:96a378947ca8 in roaraudio for libroardsp/filter_clip.c
- Timestamp:
- 10/22/11 00:44:25 (13 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libroardsp/filter_clip.c
r4708 r5173 26 26 #include "libroardsp.h" 27 27 28 int roardsp_clip_init (struct roardsp_filter * filter, struct roar_stream * stream, int id) { 29 if ( (filter->inst = roar_mm_malloc(sizeof(struct roardsp_clip))) == NULL ) 30 return -1; 31 32 return roardsp_filter_reset(filter, ROARDSP_RESET_FULL); 33 } 34 35 int roardsp_clip_uninit(struct roardsp_filter * filter) { 36 roar_mm_free(filter->inst); 37 return 0; 38 } 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 - self->limit - 32768; 51 } else { 52 return 32767 - s + 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; 62 } 63 28 64 int roardsp_clip_calc16 (struct roardsp_filter * filter, void * data, size_t samples) { 65 struct roardsp_clip * self = filter->inst; 29 66 int16_t * samp = (int16_t *) data; 30 register int32_t s = (ROAR_INSTINT)filter->inst;67 register int32_t s = self->limit; 31 68 size_t i; 32 69 33 70 for (i = 0; i < samples; i++) { 34 71 if ( samp[i] > s ) { 35 samp[i] = s;72 samp[i] = _clip16(samp[i], self); 36 73 } else if ( -samp[i] > s ) { 37 samp[i] = -s;74 samp[i] = _clip16(samp[i], self); 38 75 } 39 76 } … … 44 81 45 82 int roardsp_clip_ctl (struct roardsp_filter * filter, int cmd, void * data) { 83 struct roardsp_clip * self = filter->inst; 46 84 int32_t old; 47 85 48 if ( cmd == ROARDSP_FCTL_LIMIT ) { 49 old = (ROAR_INSTINT)filter->inst; 50 filter->inst = (void*)(ROAR_INSTINT)labs(*(int32_t*)data); 51 *(int32_t*)data = old; 52 } else { 53 ROAR_DBG("roardsp_clip_ctl(*) = -1"); 54 return -1; 86 switch (cmd) { 87 case ROARDSP_FCTL_LIMIT: 88 old = self->limit; 89 self->limit = labs(*(int32_t*)data); 90 *(int32_t*)data = old; 91 break; 92 case ROARDSP_FCTL_MODE: 93 old = self->mode; 94 self->mode = *(int32_t*)data; 95 *(int32_t*)data = old; 96 break; 97 default: 98 ROAR_DBG("roardsp_clip_ctl(*) = -1"); 99 return -1; 100 break; 55 101 } 56 102 … … 62 108 int roardsp_clip_reset (struct roardsp_filter * filter, int what) { 63 109 int32_t n = 16384; 110 int32_t mode = ROARDSP_CLIP_MODE_LIMIT; 64 111 65 112 if ( filter == NULL ) … … 73 120 case ROARDSP_RESET_FULL: 74 121 roardsp_clip_ctl(filter, ROARDSP_FCTL_LIMIT, &n); 122 roardsp_clip_ctl(filter, ROARDSP_FCTL_MODE, &mode); 75 123 return 0; 76 124 break;
Note: See TracChangeset
for help on using the changeset viewer.