diff --git a/libaf/af_lavcresample.c b/libaf/af_lavcresample.c
index 2dbdf78..c06104b 100644
|
a
|
b
|
|
| 28 | 28 | #include "libavcodec/avcodec.h" |
| 29 | 29 | #include "libavutil/rational.h" |
| 30 | 30 | |
| | 31 | #define FORMAT float |
| | 32 | |
| 31 | 33 | // Data for specific instances of this filter |
| 32 | 34 | typedef struct af_resample_s{ |
| 33 | 35 | struct AVResampleContext *avrctx; |
| 34 | | int16_t *in[AF_NCH]; |
| | 36 | FORMAT *in[AF_NCH]; |
| 35 | 37 | int in_alloc; |
| 36 | 38 | int index; |
| 37 | 39 | |
| … |
… |
static int control(struct af_instance_s* af, int cmd, void* arg)
|
| 56 | 58 | |
| 57 | 59 | af->data->nch = data->nch; |
| 58 | 60 | 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); |
| 61 | 63 | af->mul = (double)af->data->rate / data->rate; |
| 62 | 64 | af->delay = af->data->nch * s->filter_length / min(af->mul, 1); // *bps*.5 |
| 63 | 65 | |
| … |
… |
static af_data_t* play(struct af_instance_s* af, af_data_t* data)
|
| 104 | 106 | { |
| 105 | 107 | af_resample_t *s = af->setup; |
| 106 | 108 | 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; |
| 109 | 111 | int chans = data->nch; |
| 110 | | int in_len = data->len/(2*chans); |
| | 112 | int in_len = data->len/(sizeof(FORMAT)*chans); |
| 111 | 113 | int out_len = in_len * af->mul + 10; |
| 112 | | int16_t tmp[AF_NCH][out_len]; |
| | 114 | FORMAT tmp[AF_NCH][out_len]; |
| 113 | 115 | |
| 114 | 116 | if(AF_OK != RESIZE_LOCAL_BUFFER(af,data)) |
| 115 | 117 | return NULL; |
| 116 | 118 | |
| 117 | | out= (int16_t*)af->data->audio; |
| | 119 | out= (FORMAT*)af->data->audio; |
| 118 | 120 | |
| 119 | | out_len= min(out_len, af->data->len/(2*chans)); |
| | 121 | out_len= min(out_len, af->data->len/(sizeof(FORMAT)*chans)); |
| 120 | 122 | |
| 121 | 123 | if(s->in_alloc < in_len + s->index){ |
| 122 | 124 | s->in_alloc= in_len + s->index; |
| 123 | 125 | 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)); |
| 125 | 127 | } |
| 126 | 128 | } |
| 127 | 129 | |
| 128 | 130 | 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)); |
| 130 | 132 | }else if(chans==2){ |
| 131 | 133 | for(j=0; j<in_len; j++){ |
| 132 | 134 | s->in[0][j + s->index]= *(in++); |
| … |
… |
static af_data_t* play(struct af_instance_s* af, af_data_t* data)
|
| 148 | 150 | |
| 149 | 151 | s->index= in_len - consumed; |
| 150 | 152 | 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)); |
| 152 | 154 | } |
| 153 | 155 | |
| 154 | 156 | if(chans==1){ |
| 155 | | memcpy(out, tmp[0], out_len*sizeof(int16_t)); |
| | 157 | memcpy(out, tmp[0], out_len*sizeof(FORMAT)); |
| 156 | 158 | }else if(chans==2){ |
| 157 | 159 | for(j=0; j<out_len; j++){ |
| 158 | 160 | *(out++)= tmp[0][j]; |
| … |
… |
static af_data_t* play(struct af_instance_s* af, af_data_t* data)
|
| 167 | 169 | } |
| 168 | 170 | |
| 169 | 171 | data->audio = af->data->audio; |
| 170 | | data->len = out_len*chans*2; |
| | 172 | data->len = out_len*chans*sizeof(FORMAT); |
| 171 | 173 | data->rate = af->data->rate; |
| 172 | 174 | return data; |
| 173 | 175 | } |
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
|
| 2407 | 2407 | void audio_resample_close(ReSampleContext *s); |
| 2408 | 2408 | |
| 2409 | 2409 | struct 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); |
| | 2410 | int av_resample(struct AVResampleContext *c, float *dst, float *src, int *consumed, int src_size, int dst_size, int update_ctx); |
| 2411 | 2411 | void av_resample_compensate(struct AVResampleContext *c, int sample_delta, int compensation_distance); |
| 2412 | 2412 | void av_resample_close(struct AVResampleContext *c); |
| 2413 | 2413 | |
diff --git a/libavcodec/resample2.c b/libavcodec/resample2.c
index 4397d2a..710eb75 100644
|
a
|
b
|
|
| 28 | 28 | #include "avcodec.h" |
| 29 | 29 | #include "dsputil.h" |
| 30 | 30 | |
| 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 |
| 50 | 31 | #define FILTER_SHIFT 0 |
| 51 | 32 | |
| 52 | 33 | #define FELEM double |
| 53 | 34 | #define FELEM2 double |
| 54 | 35 | #define FELEML double |
| 55 | 36 | #define WINDOW_TYPE 24 |
| 56 | | #endif |
| 57 | 37 | |
| | 38 | #define FORMAT float |
| 58 | 39 | |
| 59 | 40 | typedef struct AVResampleContext{ |
| 60 | 41 | FELEM *filter_bank; |
| … |
… |
void av_build_filter(FELEM *filter, double factor, int tap_count, int phase_coun
|
| 130 | 111 | |
| 131 | 112 | /* normalize so that an uniform color remains the same */ |
| 132 | 113 | for(i=0;i<tap_count;i++) { |
| 133 | | #ifdef CONFIG_RESAMPLE_AUDIOPHILE_KIDDY_MODE |
| | 114 | //#ifdef CONFIG_RESAMPLE_AUDIOPHILE_KIDDY_MODE |
| 134 | 115 | filter[ph * tap_count + i] = tab[i] / norm; |
| | 116 | /* |
| 135 | 117 | #else |
| 136 | 118 | filter[ph * tap_count + i] = av_clip(lrintf(tab[i] * scale / norm), FELEM_MIN, FELEM_MAX); |
| 137 | 119 | #endif |
| | 120 | */ |
| 138 | 121 | } |
| 139 | 122 | } |
| 140 | 123 | #if 0 |
| … |
… |
void av_resample_compensate(AVResampleContext *c, int sample_delta, int compensa
|
| 233 | 216 | * @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. |
| 234 | 217 | * @return the number of samples written in dst or -1 if an error occurred |
| 235 | 218 | */ |
| 236 | | int av_resample(AVResampleContext *c, short *dst, short *src, int *consumed, int src_size, int dst_size, int update_ctx){ |
| | 219 | int av_resample(AVResampleContext *c, float *dst, float *src, int *consumed, int src_size, int dst_size, int update_ctx){ |
| 237 | 220 | int dst_index, i; |
| 238 | 221 | int index= c->index; |
| 239 | 222 | int frac= c->frac; |
| … |
… |
int av_resample(AVResampleContext *c, short *dst, short *src, int *consumed, int
|
| 277 | 260 | val += src[sample_index + i] * (FELEM2)filter[i]; |
| 278 | 261 | } |
| 279 | 262 | } |
| 280 | | |
| | 263 | if (val>1){ |
| | 264 | val=1; |
| | 265 | } if (val<-1){ |
| | 266 | val=-1; |
| | 267 | }; |
| | 268 | dst[dst_index] = val; |
| | 269 | /* |
| 281 | 270 | #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 | |
| 283 | 273 | #else |
| 284 | 274 | val = (val + (1<<(FILTER_SHIFT-1)))>>FILTER_SHIFT; |
| 285 | 275 | dst[dst_index] = (unsigned)(val + 32768) > 65535 ? (val>>31) ^ 32767 : val; |
| 286 | 276 | #endif |
| | 277 | */ |
| 287 | 278 | |
| 288 | 279 | frac += dst_incr_frac; |
| 289 | 280 | index += dst_incr; |