30 #define C15DB 1.189207115
32 #define C_15DB 0.840896415
33 #define C_30DB M_SQRT1_2
34 #define C_45DB 0.594603558
40 #define OFFSET(x) offsetof(SwrContext,x)
41 #define PARAM AV_OPT_FLAG_AUDIO_PARAM
90 {
"precision" ,
"set soxr resampling precision (in bits)"
92 {
"cheby" ,
"enable soxr Chebyshev passband & higher-precision irrational ratio approximation"
94 {
"min_comp" ,
"set minimum difference between timestamps and audio data (in seconds) below which no timestamp compensation of either kind is applied"
96 {
"min_hard_comp" ,
"set minimum difference between timestamps and audio data (in seconds) to trigger padding/trimming the data."
98 {
"comp_duration" ,
"set duration (in seconds) over which data is stretched/squeezed to make it match the timestamps."
100 {
"max_soft_comp" ,
"set maximum factor by which data is stretched/squeezed to make it match the timestamps."
102 {
"async" ,
"simplified 1 parameter audio timestamp matching, 0(disabled), 1(filling and trimming), >1(maximum stretch/squeeze in samples per second)"
142 return FFMPEG_CONFIGURATION;
147 #define LICENSE_PREFIX "libswresample license: "
175 int log_offset,
void *
log_ctx){
203 memset(a, 0,
sizeof(*a));
234 memset(s->
in.
ch, 0,
sizeof(s->
in.
ch));
283 extern struct Resampler const soxr_resampler;
298 if (s->
async > 1.0001) {
304 s->
resample = s->
resampler->
init(s->
resample, s->
out_sample_rate, s->
in_sample_rate, s->
filter_size, s->
phase_shift, s->
linear_interp, s->
cutoff, s->
int_sample_fmt, s->
filter_type, s->
kaiser_beta, s->
precision, s->
cheby);
320 av_log(s,
AV_LOG_WARNING,
"Input channel layout has a different number of channels than the number of used channels, ignoring layout\n");
324 if(!s-> in_ch_layout)
332 #define RSC 1 //FIXME finetune
340 if(!s-> in.ch_count){
347 char l1[1024], l2[1024];
351 "but there is not enough information to do it\n", l1, l2);
363 s-> in_sample_fmt, s-> in.ch_count,
NULL, 0);
409 if(count < 0 || count > INT_MAX/2/a->
bps/a->
ch_count)
412 if(a->
count >= count)
445 memcpy(out->
ch[ch], in->
ch[ch], count*out->
bps);
453 memset(out->
ch, 0,
sizeof(out->
ch));
456 out->
ch[i]= in_arg[i];
459 out->
ch[i]= in_arg[0] + i*out->
bps;
467 in_arg[i]= out->
ch[i];
469 in_arg[0]= out->
ch[0];
481 out->
ch[ch]= in->
ch[ch] + count*out->
bps;
483 for(ch=out->
ch_count-1; ch>=0; ch--)
493 const AudioData * in_param,
int in_count){
506 int ret,
size, consumed;
533 in_count -= consumed;
553 copy(&tmp, &in, count);
617 out_count=
FFMIN(out_count, in_count);
619 copy(out, in, out_count);
622 else if(preout==postin) preout= midbuf= postin= out;
623 else if(preout==midbuf) preout= midbuf= out;
633 out_count=
resample(s, midbuf, out_count, postin, in_count);
640 out_count=
resample(s, preout, out_count, midbuf, in_count);
643 if(preout != out && out_count){
646 int dither_count=
FFMAX(out_count, 1<<16);
659 for(ch=0; ch<preout->
ch_count; ch++)
671 const uint8_t *in_arg [SWR_CH_MAX],
int in_count){
738 if(in_count > out_count) {
750 size =
FFMIN(in_count, out_count);
760 copy(&tmp, in, in_count);
794 memset(silence.
ch[i], silence.
bps==1 ? 0x80 : 0, count*silence.
bps);
796 memset(silence.
ch[0], silence.
bps==1 ? 0x80 : 0, count*silence.
bps*silence.
ch_count);
816 if (!s || compensation_distance < 0)
818 if (!compensation_distance && sample_delta)
853 int comp = av_clipf(fdelta, -max_soft_compensation, max_soft_compensation) *
duration ;
854 av_log(s,
AV_LOG_VERBOSE,
"compensating audio timestamp drift:%f compensation:%d in:%d\n", fdelta, comp, duration);