Ticket #1344: mplayer-float-resample.diff

File mplayer-float-resample.diff, 6.4 KB (added by wbrana@…, 18 years ago)

patch

  • libaf/af_lavcresample.c

    diff --git a/libaf/af_lavcresample.c b/libaf/af_lavcresample.c
    index 2dbdf78..c06104b 100644
    a b  
    2828#include "libavcodec/avcodec.h"
    2929#include "libavutil/rational.h"
    3030
     31#define FORMAT float
     32
    3133// Data for specific instances of this filter
    3234typedef struct af_resample_s{
    3335    struct AVResampleContext *avrctx;
    34     int16_t *in[AF_NCH];
     36    FORMAT *in[AF_NCH];
    3537    int in_alloc;
    3638    int index;
    3739   
    static int control(struct af_instance_s* af, int cmd, void* arg)  
    5658
    5759    af->data->nch    = data->nch;
    5860    if (af->data->nch > AF_NCH) af->data->nch = AF_NCH;
    59     af->data->format = AF_FORMAT_S16_NE;
    60     af->data->bps    = 2;
     61    af->data->format = AF_FORMAT_FLOAT_NE;
     62    af->data->bps    = sizeof(FORMAT);
    6163    af->mul = (double)af->data->rate / data->rate;
    6264    af->delay = af->data->nch * s->filter_length / min(af->mul, 1); // *bps*.5
    6365
    static af_data_t* play(struct af_instance_s* af, af_data_t* data)  
    104106{   
    105107  af_resample_t *s = af->setup;
    106108  int i, j, consumed, ret;
    107   int16_t *in = (int16_t*)data->audio;
    108   int16_t *out;
     109  FORMAT *in = (FORMAT*)data->audio;
     110  FORMAT *out;
    109111  int chans   = data->nch;
    110   int in_len  = data->len/(2*chans);
     112  int in_len  = data->len/(sizeof(FORMAT)*chans);
    111113  int out_len = in_len * af->mul + 10;
    112   int16_t tmp[AF_NCH][out_len];
     114  FORMAT tmp[AF_NCH][out_len];
    113115   
    114116  if(AF_OK != RESIZE_LOCAL_BUFFER(af,data))
    115117      return NULL;
    116118 
    117   out= (int16_t*)af->data->audio;
     119  out= (FORMAT*)af->data->audio;
    118120 
    119   out_len= min(out_len, af->data->len/(2*chans));
     121  out_len= min(out_len, af->data->len/(sizeof(FORMAT)*chans));
    120122 
    121123  if(s->in_alloc < in_len + s->index){
    122124      s->in_alloc= in_len + s->index;
    123125      for(i=0; i<chans; i++){
    124           s->in[i]= realloc(s->in[i], s->in_alloc*sizeof(int16_t));
     126          s->in[i]= realloc(s->in[i], s->in_alloc*sizeof(FORMAT));
    125127      }
    126128  }
    127129
    128130  if(chans==1){
    129       memcpy(&s->in[0][s->index], in, in_len * sizeof(int16_t));
     131      memcpy(&s->in[0][s->index], in, in_len * sizeof(FORMAT));
    130132  }else if(chans==2){
    131133      for(j=0; j<in_len; j++){
    132134          s->in[0][j + s->index]= *(in++);
    static af_data_t* play(struct af_instance_s* af, af_data_t* data)  
    148150 
    149151  s->index= in_len - consumed;
    150152  for(i=0; i<chans; i++){
    151       memmove(s->in[i], s->in[i] + consumed, s->index*sizeof(int16_t));
     153      memmove(s->in[i], s->in[i] + consumed, s->index*sizeof(FORMAT));
    152154  }
    153155
    154156  if(chans==1){
    155       memcpy(out, tmp[0], out_len*sizeof(int16_t));
     157      memcpy(out, tmp[0], out_len*sizeof(FORMAT));
    156158  }else if(chans==2){
    157159      for(j=0; j<out_len; j++){
    158160          *(out++)= tmp[0][j];
    static af_data_t* play(struct af_instance_s* af, af_data_t* data)  
    167169  }
    168170
    169171  data->audio = af->data->audio;
    170   data->len   = out_len*chans*2;
     172  data->len   = out_len*chans*sizeof(FORMAT);
    171173  data->rate  = af->data->rate;
    172174  return data;
    173175}
  • libavcodec/avcodec.h

    diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
    index 53ded30..13bdc0e 100644
    a b int audio_resample(ReSampleContext *s, short *output, short *input, int nb_sampl  
    24072407void audio_resample_close(ReSampleContext *s);
    24082408
    24092409struct AVResampleContext *av_resample_init(int out_rate, int in_rate, int filter_length, int log2_phase_count, int linear, double cutoff);
    2410 int av_resample(struct AVResampleContext *c, short *dst, short *src, int *consumed, int src_size, int dst_size, int update_ctx);
     2410int av_resample(struct AVResampleContext *c, float *dst, float *src, int *consumed, int src_size, int dst_size, int update_ctx);
    24112411void av_resample_compensate(struct AVResampleContext *c, int sample_delta, int compensation_distance);
    24122412void av_resample_close(struct AVResampleContext *c);
    24132413
  • libavcodec/resample2.c

    diff --git a/libavcodec/resample2.c b/libavcodec/resample2.c
    index 4397d2a..710eb75 100644
    a b  
    2828#include "avcodec.h"
    2929#include "dsputil.h"
    3030
    31 #ifndef CONFIG_RESAMPLE_HP
    32 #define FILTER_SHIFT 15
    33 
    34 #define FELEM int16_t
    35 #define FELEM2 int32_t
    36 #define FELEML int64_t
    37 #define FELEM_MAX INT16_MAX
    38 #define FELEM_MIN INT16_MIN
    39 #define WINDOW_TYPE 9
    40 #elif !defined(CONFIG_RESAMPLE_AUDIOPHILE_KIDDY_MODE)
    41 #define FILTER_SHIFT 30
    42 
    43 #define FELEM int32_t
    44 #define FELEM2 int64_t
    45 #define FELEML int64_t
    46 #define FELEM_MAX INT32_MAX
    47 #define FELEM_MIN INT32_MIN
    48 #define WINDOW_TYPE 12
    49 #else
    5031#define FILTER_SHIFT 0
    5132
    5233#define FELEM double
    5334#define FELEM2 double
    5435#define FELEML double
    5536#define WINDOW_TYPE 24
    56 #endif
    5737
     38#define FORMAT float
    5839
    5940typedef struct AVResampleContext{
    6041    FELEM *filter_bank;
    void av_build_filter(FELEM *filter, double factor, int tap_count, int phase_coun  
    130111
    131112        /* normalize so that an uniform color remains the same */
    132113        for(i=0;i<tap_count;i++) {
    133 #ifdef CONFIG_RESAMPLE_AUDIOPHILE_KIDDY_MODE
     114//#ifdef CONFIG_RESAMPLE_AUDIOPHILE_KIDDY_MODE
    134115            filter[ph * tap_count + i] = tab[i] / norm;
     116/*
    135117#else
    136118            filter[ph * tap_count + i] = av_clip(lrintf(tab[i] * scale / norm), FELEM_MIN, FELEM_MAX);
    137119#endif
     120*/
    138121        }
    139122    }
    140123#if 0
    void av_resample_compensate(AVResampleContext *c, int sample_delta, int compensa  
    233216 * @param update_ctx If this is 0 then the context will not be modified, that way several channels can be resampled with the same context.
    234217 * @return the number of samples written in dst or -1 if an error occurred
    235218 */
    236 int av_resample(AVResampleContext *c, short *dst, short *src, int *consumed, int src_size, int dst_size, int update_ctx){
     219int av_resample(AVResampleContext *c, float *dst, float *src, int *consumed, int src_size, int dst_size, int update_ctx){
    237220    int dst_index, i;
    238221    int index= c->index;
    239222    int frac= c->frac;
    int av_resample(AVResampleContext *c, short *dst, short *src, int *consumed, int  
    277260                val += src[sample_index + i] * (FELEM2)filter[i];
    278261            }
    279262        }
    280 
     263        if (val>1){
     264                val=1;
     265        } if (val<-1){
     266                val=-1;
     267        };
     268                dst[dst_index] = val;
     269/*
    281270#ifdef CONFIG_RESAMPLE_AUDIOPHILE_KIDDY_MODE
    282         dst[dst_index] = av_clip_int16(lrintf(val));
     271      dst[dst_index] = av_clip_int16(lrintf(val));
     272
    283273#else
    284274        val = (val + (1<<(FILTER_SHIFT-1)))>>FILTER_SHIFT;
    285275        dst[dst_index] = (unsigned)(val + 32768) > 65535 ? (val>>31) ^ 32767 : val;
    286276#endif
     277*/
    287278
    288279        frac += dst_incr_frac;
    289280        index += dst_incr;