Changeset 5177:49fc5113e053 in roaraudio


Ignore:
Timestamp:
10/22/11 13:28:14 (12 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

added 8 and 32 bit support

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • include/libroardsp/filters.h

    r5173 r5177  
    130130int roardsp_clip_init  (struct roardsp_filter * filter, struct roar_stream * stream, int id); 
    131131int roardsp_clip_uninit(struct roardsp_filter * filter); 
     132int roardsp_clip_calc8 (struct roardsp_filter * filter, void * data, size_t samples); 
    132133int roardsp_clip_calc16(struct roardsp_filter * filter, void * data, size_t samples); 
     134int roardsp_clip_calc32(struct roardsp_filter * filter, void * data, size_t samples); 
    133135int roardsp_clip_ctl   (struct roardsp_filter * filter, int cmd, void * data); 
    134136int roardsp_clip_reset (struct roardsp_filter * filter, int what); 
  • libroardsp/filter.c

    r5173 r5177  
    4848           {NULL, NULL, NULL},{NULL, NULL, NULL},{roardsp_quantify_calc16, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL}}}, 
    4949 {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}}}, 
    5152 {ROARDSP_FILTER_DOWNMIX, "downmix", roardsp_quantify_init, NULL, roardsp_downmix_ctl, roardsp_downmix_reset, { 
    5253           {NULL, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, roardsp_downmix_calc162},{NULL, NULL, NULL},{NULL, NULL, NULL}}}, 
  • libroardsp/filter_clip.c

    r5175 r5177  
    3838} 
    3939 
    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) \ 
     41static 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; \ 
    6263} 
    6364 
    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) \ 
     66int 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} 
    6983 
    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) 
    7787 
    78  ROAR_DBG("roardsp_quantify_calc16(*) = 0"); 
    79  return 0; 
    80 } 
     88_setX(8) 
     89_setX(16) 
     90_setX(32) 
    8191 
    8292int roardsp_clip_ctl   (struct roardsp_filter * filter, int cmd, void * data) { 
     
    107117 
    108118int roardsp_clip_reset (struct roardsp_filter * filter, int what) { 
    109  int32_t n = 16384; 
    110119 int32_t mode = ROARDSP_CLIP_MODE_LIMIT; 
     120 int32_t n; 
    111121 
    112122 if ( filter == NULL ) 
    113123  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 } 
    114134 
    115135 switch (what) { 
Note: See TracChangeset for help on using the changeset viewer.