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
102 {
"precision" ,
"set soxr resampling precision (in bits)"
104 {
"cheby" ,
"enable soxr Chebyshev passband & higher-precision irrational ratio approximation"
106 {
"min_comp" ,
"set minimum difference between timestamps and audio data (in seconds) below which no timestamp compensation of either kind is applied"
108 {
"min_hard_comp" ,
"set minimum difference between timestamps and audio data (in seconds) to trigger padding/trimming the data."
110 {
"comp_duration" ,
"set duration (in seconds) over which data is stretched/squeezed to make it match the timestamps."
112 {
"max_soft_comp" ,
"set maximum factor by which data is stretched/squeezed to make it match the timestamps."
114 {
"async" ,
"simplified 1 parameter audio timestamp matching, 0(disabled), 1(filling and trimming), >1(maximum stretch/squeeze in samples per second)"
116 {
"first_pts" ,
"Assume the first pts should be this value (in samples)."
157 return FFMPEG_CONFIGURATION;
162 #define LICENSE_PREFIX "libswresample license: "
190 int log_offset,
void *
log_ctx){
218 memset(a, 0,
sizeof(*a));
256 memset(s->
in.
ch, 0,
sizeof(s->
in.
ch));
286 extern struct Resampler const soxr_resampler;
299 av_log(s,
AV_LOG_WARNING,
"Input channel layout has a different number of channels than the number of used channels, ignoring layout\n");
303 if(!s-> in_ch_layout)
349 if (s->
async > 1.0001) {
355 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);
367 #define RSC 1 //FIXME finetune
375 if(!s->
in.ch_count){
382 char l1[1024], l2[1024];
386 "but there is not enough information to do it\n", l1, l2);
400 s-> in_sample_fmt, s->
in.ch_count, NULL, 0);
449 if(count < 0 || count > INT_MAX/2/a->
bps/a->
ch_count)
452 if(a->
count >= count)
485 memcpy(out->
ch[ch], in->
ch[ch], count*out->
bps);
493 memset(out->
ch, 0,
sizeof(out->
ch));
496 out->
ch[i]= in_arg[i];
499 out->
ch[i]= in_arg[0] + i*out->
bps;
507 in_arg[i]= out->
ch[i];
509 in_arg[0]= out->
ch[0];
521 out->
ch[ch]= in->
ch[ch] + count*out->
bps;
523 for(ch=out->
ch_count-1; ch>=0; ch--)
533 const AudioData * in_param,
int in_count){
573 in_count -= consumed;
593 copy(&tmp, &in, count);
658 out_count=
FFMIN(out_count, in_count);
660 copy(out, in, out_count);
663 else if(preout==postin) preout= midbuf= postin=
out;
664 else if(preout==midbuf) preout= midbuf=
out;
674 out_count=
resample(s, midbuf, out_count, postin, in_count);
681 out_count=
resample(s, preout, out_count, midbuf, in_count);
684 if(preout != out && out_count){
688 int dither_count=
FFMAX(out_count, 1<<16);
708 int len1= out_count&~15;
709 int off = len1 * preout->
bps;
712 for(ch=0; ch<preout->
ch_count; ch++)
714 if(out_count != len1)
715 for(ch=0; ch<preout->
ch_count; ch++)
718 for(ch=0; ch<preout->
ch_count; ch++)
738 const uint8_t *in_arg [SWR_CH_MAX],
int in_count){
745 #define MAX_DROP_STEP 16384
804 if(in_count > out_count) {
816 size =
FFMIN(in_count, out_count);
826 copy(&tmp, in, in_count);
853 #define MAX_SILENCE_STEP 16384
885 if (!s || compensation_distance < 0)
887 if (!compensation_distance && sample_delta)
926 int comp = av_clipf(fdelta, -max_soft_compensation, max_soft_compensation) *
duration ;
927 av_log(s,
AV_LOG_VERBOSE,
"compensating audio timestamp drift:%f compensation:%d in:%d\n", fdelta, comp, duration);