Changeset 1141:37c25717fca0 in roaraudio


Ignore:
Timestamp:
01/21/09 22:51:58 (15 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

added support to reset filters, some cleanup

Files:
9 edited

Legend:

Unmodified
Added
Removed
  • include/libroardsp/libroardsp.h

    r1131 r1141  
    137137int roardsp_lowp_calc16(struct roardsp_filter * filter, void * data, size_t samples); 
    138138int roardsp_lowp_ctl   (struct roardsp_filter * filter, int cmd, void * data); 
     139int roardsp_lowp_reset (struct roardsp_filter * filter, int what); 
    139140 
    140141int roardsp_highp_init  (struct roardsp_filter * filter, struct roar_stream * stream, int id); 
     
    142143int roardsp_highp_calc16(struct roardsp_filter * filter, void * data, size_t samples); 
    143144int roardsp_highp_ctl   (struct roardsp_filter * filter, int cmd, void * data); 
     145int roardsp_highp_reset (struct roardsp_filter * filter, int what); 
    144146#endif 
    145147 
     
    149151int roardsp_amp_calc8 (struct roardsp_filter * filter, void * data, size_t samples); 
    150152int roardsp_amp_ctl   (struct roardsp_filter * filter, int cmd, void * data); 
     153int roardsp_amp_reset (struct roardsp_filter * filter, int what); 
    151154 
    152155int roardsp_add_init  (struct roardsp_filter * filter, struct roar_stream * stream, int id); 
    153156int roardsp_add_calc16(struct roardsp_filter * filter, void * data, size_t samples); 
     157int roardsp_add_reset (struct roardsp_filter * filter, int what); 
    154158 
    155159int roardsp_quantify_init  (struct roardsp_filter * filter, struct roar_stream * stream, int id); 
     
    157161int roardsp_quantify_calc16(struct roardsp_filter * filter, void * data, size_t samples); 
    158162int roardsp_quantify_ctl   (struct roardsp_filter * filter, int cmd, void * data); 
     163int roardsp_quantify_reset (struct roardsp_filter * filter, int what); 
    159164 
    160 int roardsp_clip_init  (struct roardsp_filter * filter, struct roar_stream * stream, int id); 
    161165int roardsp_clip_calc16(struct roardsp_filter * filter, void * data, size_t samples); 
    162166int roardsp_clip_ctl   (struct roardsp_filter * filter, int cmd, void * data); 
     167int roardsp_clip_reset (struct roardsp_filter * filter, int what); 
    163168 
    164169int roardsp_downmix_init   (struct roardsp_filter * filter, struct roar_stream * stream, int id); 
    165170int roardsp_downmix_calc162(struct roardsp_filter * filter, void * data, size_t samples); 
    166171int roardsp_downmix_ctl    (struct roardsp_filter * filter, int cmd, void * data); 
     172int roardsp_downmix_reset  (struct roardsp_filter * filter, int what); 
    167173 
    168174int roardsp_dcblock_init   (struct roardsp_filter * filter, struct roar_stream * stream, int id); 
  • libroardsp/filter.c

    r1134 r1141  
    3434 int (*calc  [5][3])(struct roardsp_filter * filter, void * data, size_t samples); 
    3535} _roardsp_filterlist[] = { 
    36  {ROARDSP_FILTER_AMP, "AMP", roardsp_amp_init, roardsp_amp_uninit, roardsp_amp_ctl, NULL, { 
     36 {ROARDSP_FILTER_AMP, "AMP", roardsp_amp_init, roardsp_amp_uninit, roardsp_amp_ctl, roardsp_amp_reset, { 
    3737           {NULL, NULL, NULL},{roardsp_amp_calc8, NULL, NULL},{roardsp_amp_calc16, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL}}}, 
    38  {ROARDSP_FILTER_ADD, "Add", roardsp_add_init, roardsp_amp_uninit, roardsp_amp_ctl, NULL, { 
     38 {ROARDSP_FILTER_ADD, "Add", roardsp_add_init, roardsp_amp_uninit, roardsp_amp_ctl, roardsp_add_reset, { 
    3939           {NULL, NULL, NULL},{NULL, NULL, NULL},{roardsp_add_calc16, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL}}}, 
    4040#ifdef ROAR_HAVE_LIBM 
    41  {ROARDSP_FILTER_LOWP, "Lowpass", roardsp_lowp_init, roardsp_lowp_uninit, roardsp_lowp_ctl, NULL, { 
     41 {ROARDSP_FILTER_LOWP, "Lowpass", roardsp_lowp_init, roardsp_lowp_uninit, roardsp_lowp_ctl, roardsp_lowp_reset, { 
    4242           {NULL, NULL, NULL},{NULL, NULL, NULL},{roardsp_lowp_calc16, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL}}}, 
    43  {ROARDSP_FILTER_HIGHP, "Highpass", roardsp_highp_init, roardsp_highp_uninit, roardsp_highp_ctl, NULL, { 
     43 {ROARDSP_FILTER_HIGHP, "Highpass", roardsp_highp_init, roardsp_highp_uninit, roardsp_highp_ctl, roardsp_highp_reset, { 
    4444           {NULL, NULL, NULL},{NULL, NULL, NULL},{roardsp_highp_calc16, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL}}}, 
    4545#endif 
    46  {ROARDSP_FILTER_QUANTIFY, "Quantifier", roardsp_quantify_init, NULL, roardsp_quantify_ctl, NULL, { 
     46 {ROARDSP_FILTER_QUANTIFY, "Quantifier", roardsp_quantify_init, NULL, roardsp_quantify_ctl, roardsp_quantify_reset, { 
    4747           {NULL, NULL, NULL},{NULL, NULL, NULL},{roardsp_quantify_calc16, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL}}}, 
    48  {ROARDSP_FILTER_CLIP, "Clip", roardsp_clip_init, NULL, roardsp_clip_ctl, NULL, { 
     48 {ROARDSP_FILTER_CLIP, "Clip", roardsp_quantify_init, NULL, roardsp_clip_ctl, roardsp_clip_reset, { 
    4949           {NULL, NULL, NULL},{NULL, NULL, NULL},{roardsp_clip_calc16, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL}}}, 
    50  {ROARDSP_FILTER_DOWNMIX, "downmix", roardsp_downmix_init, NULL, roardsp_downmix_ctl, NULL, { 
     50 {ROARDSP_FILTER_DOWNMIX, "downmix", roardsp_quantify_init, NULL, roardsp_downmix_ctl, roardsp_downmix_reset, { 
    5151           {NULL, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, roardsp_downmix_calc162},{NULL, NULL, NULL},{NULL, NULL, NULL}}}, 
    5252 {ROARDSP_FILTER_DCBLOCK, "DCBlock", roardsp_dcblock_init, NULL, NULL, roardsp_dcblock_reset, { 
  • libroardsp/filter_add.c

    r979 r1141  
    2727int roardsp_add_init  (struct roardsp_filter * filter, struct roar_stream * stream, int id) { 
    2828 struct roardsp_amp * self = malloc(sizeof(struct roardsp_amp)); 
    29  int32_t fac; 
    3029 
    3130 if ( self == NULL ) 
     
    3635 filter->inst = (void*) self; 
    3736 
    38  fac = 0; 
    39  roardsp_amp_ctl(filter, ROARDSP_FCTL_MUL, &fac); 
    40  fac = 1; 
    41  roardsp_amp_ctl(filter, ROARDSP_FCTL_DIV, &fac); 
     37 roardsp_filter_reset(filter, ROARDSP_RESET_FULL); 
    4238 
    4339 return 0; 
     
    5652} 
    5753 
     54int roardsp_add_reset (struct roardsp_filter * filter, int what) { 
     55 struct roardsp_amp * self; 
     56 
     57 if ( filter == NULL ) 
     58  return -1; 
     59 
     60 if ( filter->inst == NULL ) 
     61  return -1; 
     62 
     63 self = filter->inst; 
     64 
     65 switch (what) { 
     66  case ROARDSP_RESET_NONE: 
     67  case ROARDSP_RESET_STATE: 
     68    return  0; 
     69   break; 
     70  case ROARDSP_RESET_FULL: 
     71    self->mul = 0; 
     72    self->div = 1; 
     73    return  0; 
     74   break; 
     75  default: 
     76    return -1; 
     77 } 
     78 
     79 return -1; 
     80} 
     81 
    5882//ll 
  • libroardsp/filter_amp.c

    r882 r1141  
    2727int roardsp_amp_init  (struct roardsp_filter * filter, struct roar_stream * stream, int id) { 
    2828 struct roardsp_amp * self = malloc(sizeof(struct roardsp_amp)); 
    29  int32_t fac; 
    3029 
    3130 if ( self == NULL ) 
     
    3635 filter->inst = (void*) self; 
    3736 
    38  fac = 1; 
    39  roardsp_amp_ctl(filter, ROARDSP_FCTL_MUL, &fac); 
    40  fac = 1; 
    41  roardsp_amp_ctl(filter, ROARDSP_FCTL_DIV, &fac); 
     37 roardsp_filter_reset(filter, ROARDSP_RESET_FULL); 
    4238 
    4339 return 0; 
     
    10399} 
    104100 
     101int roardsp_amp_reset (struct roardsp_filter * filter, int what) { 
     102 struct roardsp_amp * self; 
     103 
     104 if ( filter == NULL ) 
     105  return -1; 
     106 
     107 if ( filter->inst == NULL ) 
     108  return -1; 
     109 
     110 self = filter->inst; 
     111 
     112 switch (what) { 
     113  case ROARDSP_RESET_NONE: 
     114  case ROARDSP_RESET_STATE: 
     115    return  0; 
     116   break; 
     117  case ROARDSP_RESET_FULL: 
     118    self->mul = 1; 
     119    self->div = 1; 
     120    return  0; 
     121   break; 
     122  default: 
     123    return -1; 
     124 } 
     125 
     126 return -1; 
     127} 
     128 
    105129//ll 
  • libroardsp/filter_clip.c

    r987 r1141  
    2424 
    2525#include "libroardsp.h" 
    26  
    27 int roardsp_clip_init  (struct roardsp_filter * filter, struct roar_stream * stream, int id) { 
    28  int n = 64; 
    29  
    30  roardsp_amp_ctl(filter, ROARDSP_FCTL_N, &n); 
    31  
    32  return 0; 
    33 } 
    3426 
    3527int roardsp_clip_calc16  (struct roardsp_filter * filter, void * data, size_t samples) { 
     
    6759} 
    6860 
     61int roardsp_clip_reset (struct roardsp_filter * filter, int what) { 
     62 int32_t n = 16384; 
     63 
     64 if ( filter == NULL ) 
     65  return -1; 
     66 
     67 switch (what) { 
     68  case ROARDSP_RESET_NONE: 
     69  case ROARDSP_RESET_STATE: 
     70    return  0; 
     71   break; 
     72  case ROARDSP_RESET_FULL: 
     73    roardsp_clip_ctl(filter, ROARDSP_FCTL_LIMIT, &n); 
     74    return  0; 
     75   break; 
     76  default: 
     77    return -1; 
     78 } 
     79 
     80 return -1; 
     81} 
     82 
    6983//ll 
  • libroardsp/filter_downmix.c

    r1104 r1141  
    2424 
    2525#include "libroardsp.h" 
    26  
    27 int roardsp_downmix_init  (struct roardsp_filter * filter, struct roar_stream * stream, int id) { 
    28  int mode = ROARDSP_DOWNMIX_ARITHMETIC; 
    29  
    30  roardsp_downmix_ctl(filter, ROARDSP_FCTL_MODE, &mode); 
    31  
    32  ROAR_DBG("roardsp_downmix_init(*) = 0"); 
    33  return 0; 
    34 } 
    3526 
    3627int roardsp_downmix_calc162  (struct roardsp_filter * filter, void * data, size_t samples) { 
     
    10697} 
    10798 
     99int roardsp_downmix_reset  (struct roardsp_filter * filter, int what) { 
     100 int mode = ROARDSP_DOWNMIX_ARITHMETIC; 
     101 
     102 if ( filter == NULL ) 
     103  return -1; 
     104 
     105 switch (what) { 
     106  case ROARDSP_RESET_NONE: 
     107  case ROARDSP_RESET_STATE: 
     108    return  0; 
     109   break; 
     110  case ROARDSP_RESET_FULL: 
     111    roardsp_downmix_ctl(filter, ROARDSP_FCTL_MODE, &mode); 
     112    return  0; 
     113   break; 
     114  default: 
     115    return -1; 
     116 } 
     117 
     118 return -1; 
     119} 
     120 
    108121//ll 
  • libroardsp/filter_highp.c

    r1104 r1141  
    111111} 
    112112 
     113int roardsp_highp_reset (struct roardsp_filter * filter, int what) { 
     114 struct roardsp_highp * self; 
     115 float freq = 25; 
     116 
     117 if ( filter == NULL ) 
     118  return -1; 
     119 
     120 if ( filter->inst == NULL ) 
     121  return -1; 
     122 
     123 self = filter->inst; 
     124 
     125 switch (what) { 
     126  case ROARDSP_RESET_NONE: 
     127    return  0; 
     128   break; 
     129  case ROARDSP_RESET_FULL: 
     130    roardsp_highp_ctl(filter, ROARDSP_FCTL_FREQ, &freq); 
     131  case ROARDSP_RESET_STATE: 
     132    memset(self->oldin,  0, sizeof(int32_t)*ROAR_MAX_CHANNELS); 
     133    memset(self->oldout, 0, sizeof(int32_t)*ROAR_MAX_CHANNELS); 
     134    return  0; 
     135   break; 
     136  default: 
     137    return -1; 
     138 } 
     139 
     140 return -1; 
     141} 
     142 
    113143#endif 
    114144 
  • libroardsp/filter_lowp.c

    r1104 r1141  
    107107} 
    108108 
     109int roardsp_lowp_reset (struct roardsp_filter * filter, int what) { 
     110 struct roardsp_lowp * self; 
     111 float freq; 
     112 
     113 if ( filter == NULL ) 
     114  return -1; 
     115 
     116 if ( filter->inst == NULL ) 
     117  return -1; 
     118 
     119 self = filter->inst; 
     120 freq = filter->rate/2; 
     121 
     122 switch (what) { 
     123  case ROARDSP_RESET_NONE: 
     124    return  0; 
     125   break; 
     126  case ROARDSP_RESET_FULL: 
     127    roardsp_lowp_ctl(filter, ROARDSP_FCTL_FREQ, &freq); 
     128  case ROARDSP_RESET_STATE: 
     129    memset(self->old, 0, sizeof(int32_t)*ROAR_MAX_CHANNELS); 
     130    return  0; 
     131   break; 
     132  default: 
     133    return -1; 
     134 } 
     135 
     136 return -1; 
     137} 
     138 
    109139#endif 
    110140 
  • libroardsp/filter_quantify.c

    r987 r1141  
    2626 
    2727int roardsp_quantify_init  (struct roardsp_filter * filter, struct roar_stream * stream, int id) { 
    28  int n = 64; 
    2928 
    30  roardsp_amp_ctl(filter, ROARDSP_FCTL_N, &n); 
     29 roardsp_filter_reset(filter, ROARDSP_RESET_FULL); 
    3130 
    32  ROAR_DBG("roardsp_quantify_init(*) = 0"); 
    3331 return 0; 
    3432} 
     
    7169} 
    7270 
     71int roardsp_quantify_reset (struct roardsp_filter * filter, int what) { 
     72 int n = 64; 
     73 
     74 if ( filter == NULL ) 
     75  return -1; 
     76 
     77 switch (what) { 
     78  case ROARDSP_RESET_NONE: 
     79  case ROARDSP_RESET_STATE: 
     80    return  0; 
     81   break; 
     82  case ROARDSP_RESET_FULL: 
     83    roardsp_quantify_ctl(filter, ROARDSP_FCTL_N, &n); 
     84    return  0; 
     85   break; 
     86  default: 
     87    return -1; 
     88 } 
     89 
     90 return -1; 
     91} 
     92 
    7393//ll 
Note: See TracChangeset for help on using the changeset viewer.