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));
225 memset(s->
in.
ch, 0,
sizeof(s->
in.
ch));
280 extern struct Resampler const soxr_resampler;
293 av_log(s,
AV_LOG_WARNING,
"Input channel layout has a different number of channels than the number of used channels, ignoring layout\n");
297 if(!s-> in_ch_layout)
343 if (s->
async > 1.0001) {
349 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);
361 #define RSC 1 //FIXME finetune
369 if(!s->
in.ch_count){
376 char l1[1024], l2[1024];
380 "but there is not enough information to do it\n", l1, l2);
394 s-> in_sample_fmt, s->
in.ch_count, NULL, 0);
446 if(a->
count >= count)
479 memcpy(out->
ch[ch], in->
ch[ch], count*out->
bps);
487 memset(out->
ch, 0,
sizeof(out->
ch));
490 out->
ch[i]= in_arg[i];
493 out->
ch[i]= in_arg[0] + i*out->
bps;
501 in_arg[i]= out->
ch[i];
503 in_arg[0]= out->
ch[0];
515 out->
ch[ch]= in->
ch[ch] + count*out->
bps;
517 for(ch=out->
ch_count-1; ch>=0; ch--)
527 const AudioData * in_param,
int in_count){
568 in_count -= consumed;
588 copy(&tmp, &in, count);
657 out_count=
FFMIN(out_count, in_count);
659 copy(out, in, out_count);
662 else if(preout==postin) preout= midbuf= postin=
out;
663 else if(preout==midbuf) preout= midbuf=
out;
673 out_count=
resample(s, midbuf, out_count, postin, in_count);
680 out_count=
resample(s, preout, out_count, midbuf, in_count);
683 if(preout != out && out_count){
687 int dither_count=
FFMAX(out_count, 1<<16);
707 int len1= out_count&~15;
708 int off = len1 * preout->
bps;
711 for(ch=0; ch<preout->
ch_count; ch++)
713 if(out_count != len1)
714 for(ch=0; ch<preout->
ch_count; ch++)
717 for(ch=0; ch<preout->
ch_count; ch++)
741 const uint8_t *in_arg [SWR_CH_MAX],
int in_count){
753 #define MAX_DROP_STEP 16384
812 if(in_count > out_count) {
824 size =
FFMIN(in_count, out_count);
834 copy(&tmp, in, in_count);
861 #define MAX_SILENCE_STEP 16384
893 if (!s || compensation_distance < 0)
895 if (!compensation_distance && sample_delta)
934 int comp = av_clipf(fdelta, -max_soft_compensation, max_soft_compensation) *
duration ;
935 av_log(s,
AV_LOG_VERBOSE,
"compensating audio timestamp drift:%f compensation:%d in:%d\n", fdelta, comp, duration);