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
101 {
"precision" ,
"set soxr resampling precision (in bits)"
103 {
"cheby" ,
"enable soxr Chebyshev passband & higher-precision irrational ratio approximation"
105 {
"min_comp" ,
"set minimum difference between timestamps and audio data (in seconds) below which no timestamp compensation of either kind is applied"
107 {
"min_hard_comp" ,
"set minimum difference between timestamps and audio data (in seconds) to trigger padding/trimming the data."
109 {
"comp_duration" ,
"set duration (in seconds) over which data is stretched/squeezed to make it match the timestamps."
111 {
"max_soft_comp" ,
"set maximum factor by which data is stretched/squeezed to make it match the timestamps."
113 {
"async" ,
"simplified 1 parameter audio timestamp matching, 0(disabled), 1(filling and trimming), >1(maximum stretch/squeeze in samples per second)"
115 {
"first_pts" ,
"Assume the first pts should be this value (in samples)."
156 return FFMPEG_CONFIGURATION;
161 #define LICENSE_PREFIX "libswresample license: "
189 int log_offset,
void *
log_ctx){
217 memset(a, 0,
sizeof(*a));
255 memset(s->
in.
ch, 0,
sizeof(s->
in.
ch));
285 extern struct Resampler const soxr_resampler;
298 av_log(s,
AV_LOG_WARNING,
"Input channel layout has a different number of channels than the number of used channels, ignoring layout\n");
302 if(!s-> in_ch_layout)
348 if (s->
async > 1.0001) {
354 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);
366 #define RSC 1 //FIXME finetune
374 if(!s->
in.ch_count){
381 char l1[1024], l2[1024];
385 "but there is not enough information to do it\n", l1, l2);
399 s-> in_sample_fmt, s->
in.ch_count, NULL, 0);
448 if(count < 0 || count > INT_MAX/2/a->
bps/a->
ch_count)
451 if(a->
count >= count)
484 memcpy(out->
ch[ch], in->
ch[ch], count*out->
bps);
492 memset(out->
ch, 0,
sizeof(out->
ch));
495 out->
ch[i]= in_arg[i];
498 out->
ch[i]= in_arg[0] + i*out->
bps;
506 in_arg[i]= out->
ch[i];
508 in_arg[0]= out->
ch[0];
520 out->
ch[ch]= in->
ch[ch] + count*out->
bps;
522 for(ch=out->
ch_count-1; ch>=0; ch--)
532 const AudioData * in_param,
int in_count){
572 in_count -= consumed;
592 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++)
737 const uint8_t *in_arg [SWR_CH_MAX],
int in_count){
744 #define MAX_DROP_STEP 16384
803 if(in_count > out_count) {
815 size =
FFMIN(in_count, out_count);
825 copy(&tmp, in, in_count);
852 #define MAX_SILENCE_STEP 16384
884 if (!s || compensation_distance < 0)
886 if (!compensation_distance && sample_delta)
925 int comp = av_clipf(fdelta, -max_soft_compensation, max_soft_compensation) *
duration ;
926 av_log(s,
AV_LOG_VERBOSE,
"compensating audio timestamp drift:%f compensation:%d in:%d\n", fdelta, comp, duration);