Revision 51a88020

View differences:

libavcodec/resample2.c
31 31
#define PHASE_SHIFT 10
32 32
#define PHASE_COUNT (1<<PHASE_SHIFT)
33 33
#define PHASE_MASK (PHASE_COUNT-1)
34
#define FILTER_SIZE 16
35
//#define LINEAR 1
36

  
37
#if 1
34 38
#define FILTER_SHIFT 15
35 39

  
40
#define FELEM int16_t
41
#define FELEM2 int32_t
42
#define FELEM_MAX INT16_MAX
43
#define FELEM_MIN INT16_MIN
44
#else
45
#define FILTER_SHIFT 24
46

  
47
#define FELEM int32_t
48
#define FELEM2 int64_t
49
#define FELEM_MAX INT32_MAX
50
#define FELEM_MIN INT32_MIN
51
#endif
52

  
53

  
36 54
typedef struct AVResampleContext{
37
    short *filter_bank;
55
    FELEM *filter_bank;
38 56
    int filter_length;
39 57
    int ideal_dst_incr;
40 58
    int dst_incr;
......
65 83
 * @param scale wanted sum of coefficients for each filter
66 84
 * @param type 0->cubic, 1->blackman nuttall windowed sinc, 2->kaiser windowed sinc beta=16
67 85
 */
68
void av_build_filter(int16_t *filter, double factor, int tap_count, int phase_count, int scale, int type){
86
void av_build_filter(FELEM *filter, double factor, int tap_count, int phase_count, int scale, int type){
69 87
    int ph, i, v;
70 88
    double x, y, w, tab[tap_count];
71 89
    const int center= (tap_count-1)/2;
......
104 122

  
105 123
        /* normalize so that an uniform color remains the same */
106 124
        for(i=0;i<tap_count;i++) {
107
            v = clip(lrintf(tab[i] * scale / norm + e), -32768, 32767);
125
            v = clip(lrintf(tab[i] * scale / norm + e), FELEM_MIN, FELEM_MAX);
108 126
            filter[ph * tap_count + i] = v;
109 127
            e += tab[i] * scale / norm - v;
110 128
        }
......
121 139

  
122 140
    memset(c, 0, sizeof(AVResampleContext));
123 141

  
124
    c->filter_length= ceil(16.0/factor);
125
    c->filter_bank= av_mallocz(c->filter_length*(PHASE_COUNT+1)*sizeof(short));
142
    c->filter_length= ceil(FILTER_SIZE/factor);
143
    c->filter_bank= av_mallocz(c->filter_length*(PHASE_COUNT+1)*sizeof(FELEM));
126 144
    av_build_filter(c->filter_bank, factor, c->filter_length, PHASE_COUNT, 1<<FILTER_SHIFT, 1);
127
    memcpy(&c->filter_bank[c->filter_length*PHASE_COUNT+1], c->filter_bank, (c->filter_length-1)*sizeof(short));
145
    memcpy(&c->filter_bank[c->filter_length*PHASE_COUNT+1], c->filter_bank, (c->filter_length-1)*sizeof(FELEM));
128 146
    c->filter_bank[c->filter_length*PHASE_COUNT]= c->filter_bank[c->filter_length - 1];
129 147

  
130 148
    c->src_incr= out_rate;
......
163 181
    int compensation_distance= c->compensation_distance;
164 182
    
165 183
    for(dst_index=0; dst_index < dst_size; dst_index++){
166
        short *filter= c->filter_bank + c->filter_length*(index & PHASE_MASK);
184
        FELEM *filter= c->filter_bank + c->filter_length*(index & PHASE_MASK);
167 185
        int sample_index= index >> PHASE_SHIFT;
168
        int val=0;
186
        FELEM2 val=0;
169 187
                
170 188
        if(sample_index < 0){
171 189
            for(i=0; i<c->filter_length; i++)
......
173 191
        }else if(sample_index + c->filter_length > src_size){
174 192
            break;
175 193
        }else{
176
#if 0
194
#ifdef LINEAR
177 195
            int64_t v=0;
178 196
            int sub_phase= (frac<<12) / c->src_incr;
179 197
            for(i=0; i<c->filter_length; i++){
180
                int64_t coeff= filter[i]*(4096 - sub_phase) + filter[i + c->filter_length]*sub_phase;
198
                int64_t coeff= filter[i]*(FELEM2)(4096 - sub_phase) + filter[i + c->filter_length]*(FELEM2)sub_phase;
181 199
                v += src[sample_index + i] * coeff;
182 200
            }
183 201
            val= v>>12;
184 202
#else
185 203
            for(i=0; i<c->filter_length; i++){
186
                val += src[sample_index + i] * filter[i];
204
                val += src[sample_index + i] * (FELEM2)filter[i];
187 205
            }
188 206
#endif
189 207
        }

Also available in: Unified diff