swr: change sample format representation so as to maintain the planer/packed distinction.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
pull/30/merge
Michael Niedermayer 13 years ago
parent 9d4a1aca88
commit edbde52226
  1. 2
      libswresample/audioconvert.c
  2. 3
      libswresample/dither.c
  3. 12
      libswresample/rematrix.c
  4. 24
      libswresample/resample.c
  5. 24
      libswresample/swresample.c
  6. 2
      libswresample/swresample_internal.h

@ -122,7 +122,7 @@ AudioConvert *swri_audio_convert_alloc(enum AVSampleFormat out_fmt,
int flags)
{
AudioConvert *ctx;
conv_func_type *f = fmt_pair_to_conv_functions[out_fmt + AV_SAMPLE_FMT_NB*in_fmt];
conv_func_type *f = fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt) + AV_SAMPLE_FMT_NB*av_get_packed_sample_fmt(in_fmt)];
if (!f)
return NULL;

@ -27,6 +27,9 @@ void swri_get_dither(SwrContext *s, void *dst, int len, unsigned seed, enum AVSa
double *tmp = av_malloc((len + TMP_EXTRA) * sizeof(double));
int i;
out_fmt = av_get_packed_sample_fmt(out_fmt);
in_fmt = av_get_packed_sample_fmt( in_fmt);
if(in_fmt == AV_SAMPLE_FMT_FLT || in_fmt == AV_SAMPLE_FMT_DBL){
if(out_fmt == AV_SAMPLE_FMT_S32) scale = 1.0/(1L<<31);
if(out_fmt == AV_SAMPLE_FMT_S16) scale = 1.0/(1L<<15);

@ -227,8 +227,8 @@ static int auto_matrix(SwrContext *s)
if(s->rematrix_volume < 0)
maxcoef = -s->rematrix_volume;
if(( s->out_sample_fmt < AV_SAMPLE_FMT_FLT
|| s->int_sample_fmt < AV_SAMPLE_FMT_FLT) && maxcoef > 1.0){
if(( av_get_packed_sample_fmt(s->out_sample_fmt) < AV_SAMPLE_FMT_FLT
|| av_get_packed_sample_fmt(s->int_sample_fmt) < AV_SAMPLE_FMT_FLT) && maxcoef > 1.0){
for(i=0; i<SWR_CH_MAX; i++)
for(j=0; j<SWR_CH_MAX; j++){
s->matrix[i][j] /= maxcoef;
@ -273,10 +273,10 @@ int swri_rematrix_init(SwrContext *s){
}
void swri_sum2(enum AVSampleFormat format, void *dst, const void *src0, const void *src1, float coef0, float coef1, int len){
if(format == AV_SAMPLE_FMT_FLT){
if(format == AV_SAMPLE_FMT_FLTP){
sum2_float((float *)dst, (const float *)src0, (const float *)src1, coef0, coef1, len);
}else{
av_assert1(format == AV_SAMPLE_FMT_S16);
av_assert1(format == AV_SAMPLE_FMT_S16P);
sum2_s16 ((int16_t*)dst, (const int16_t*)src0, (const int16_t*)src1, lrintf(coef0 * 32768), lrintf(coef1 * 32768), len);
}
}
@ -295,7 +295,7 @@ int swri_rematrix(SwrContext *s, AudioData *out, AudioData *in, int len, int mus
case 1:
in_i= s->matrix_ch[out_i][1];
if(mustcopy || s->matrix[out_i][in_i]!=1.0){
if(s->int_sample_fmt == AV_SAMPLE_FMT_FLT){
if(s->int_sample_fmt == AV_SAMPLE_FMT_FLTP){
copy_float((float *)out->ch[out_i], (const float *)in->ch[in_i], s->matrix [out_i][in_i], len);
}else
copy_s16 ((int16_t*)out->ch[out_i], (const int16_t*)in->ch[in_i], s->matrix32[out_i][in_i], len);
@ -308,7 +308,7 @@ int swri_rematrix(SwrContext *s, AudioData *out, AudioData *in, int len, int mus
s->matrix[out_i][ s->matrix_ch[out_i][1] ], s->matrix[out_i][ s->matrix_ch[out_i][2] ], len);
break;
default:
if(s->int_sample_fmt == AV_SAMPLE_FMT_FLT){
if(s->int_sample_fmt == AV_SAMPLE_FMT_FLTP){
for(i=0; i<len; i++){
float v=0;
for(j=0; j<s->matrix_ch[out_i][0]; j++){

@ -131,19 +131,19 @@ static int build_filter(ResampleContext *c, void *filter, double factor, int tap
/* normalize so that an uniform color remains the same */
switch(c->format){
case AV_SAMPLE_FMT_S16:
case AV_SAMPLE_FMT_S16P:
for(i=0;i<tap_count;i++)
((int16_t*)filter)[ph * tap_count + i] = av_clip(lrintf(tab[i] * scale / norm), INT16_MIN, INT16_MAX);
break;
case AV_SAMPLE_FMT_S32:
case AV_SAMPLE_FMT_S32P:
for(i=0;i<tap_count;i++)
((int32_t*)filter)[ph * tap_count + i] = av_clip(lrintf(tab[i] * scale / norm), INT32_MIN, INT32_MAX);
break;
case AV_SAMPLE_FMT_FLT:
case AV_SAMPLE_FMT_FLTP:
for(i=0;i<tap_count;i++)
((float*)filter)[ph * tap_count + i] = tab[i] * scale / norm;
break;
case AV_SAMPLE_FMT_DBL:
case AV_SAMPLE_FMT_DBLP:
for(i=0;i<tap_count;i++)
((double*)filter)[ph * tap_count + i] = tab[i] * scale / norm;
break;
@ -205,14 +205,14 @@ ResampleContext *swri_resample_init(ResampleContext *c, int out_rate, int in_rat
c->felem_size= av_get_bytes_per_sample(c->format);
switch(c->format){
case AV_SAMPLE_FMT_S16:
case AV_SAMPLE_FMT_S16P:
c->filter_shift = 15;
break;
case AV_SAMPLE_FMT_S32:
case AV_SAMPLE_FMT_S32P:
c->filter_shift = 30;
break;
case AV_SAMPLE_FMT_FLT:
case AV_SAMPLE_FMT_DBL:
case AV_SAMPLE_FMT_FLTP:
case AV_SAMPLE_FMT_DBLP:
c->filter_shift = 0;
break;
default:
@ -359,10 +359,10 @@ int swri_multiple_resample(ResampleContext *c, AudioData *dst, int dst_size, Aud
int i, ret= -1;
for(i=0; i<dst->ch_count; i++){
if(c->format == AV_SAMPLE_FMT_S16) ret= swri_resample_int16(c, (int16_t*)dst->ch[i], (const int16_t*)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count);
if(c->format == AV_SAMPLE_FMT_S32) ret= swri_resample_int32(c, (int32_t*)dst->ch[i], (const int32_t*)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count);
if(c->format == AV_SAMPLE_FMT_FLT) ret= swri_resample_float(c, (float *)dst->ch[i], (const float *)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count);
if(c->format == AV_SAMPLE_FMT_DBL) ret= swri_resample_double(c,(double *)dst->ch[i], (const double *)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count);
if(c->format == AV_SAMPLE_FMT_S16P) ret= swri_resample_int16(c, (int16_t*)dst->ch[i], (const int16_t*)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count);
if(c->format == AV_SAMPLE_FMT_S32P) ret= swri_resample_int32(c, (int32_t*)dst->ch[i], (const int32_t*)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count);
if(c->format == AV_SAMPLE_FMT_FLTP) ret= swri_resample_float(c, (float *)dst->ch[i], (const float *)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count);
if(c->format == AV_SAMPLE_FMT_DBLP) ret= swri_resample_double(c,(double *)dst->ch[i], (const double *)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count);
}
return ret;

@ -52,8 +52,8 @@ static const AVOption options[]={
{"in_sample_fmt" , "Input Sample Format" , OFFSET( in_sample_fmt ), AV_OPT_TYPE_INT , {.dbl=AV_SAMPLE_FMT_S16 }, 0 , AV_SAMPLE_FMT_NB-1+256, PARAM},
{"osf" , "Output Sample Format" , OFFSET(out_sample_fmt ), AV_OPT_TYPE_INT , {.dbl=AV_SAMPLE_FMT_S16 }, 0 , AV_SAMPLE_FMT_NB-1+256, PARAM},
{"out_sample_fmt" , "Output Sample Format" , OFFSET(out_sample_fmt ), AV_OPT_TYPE_INT , {.dbl=AV_SAMPLE_FMT_S16 }, 0 , AV_SAMPLE_FMT_NB-1+256, PARAM},
{"tsf" , "Internal Sample Format" , OFFSET(int_sample_fmt ), AV_OPT_TYPE_INT , {.dbl=AV_SAMPLE_FMT_NONE }, -1 , AV_SAMPLE_FMT_FLT, PARAM},
{"internal_sample_fmt" , "Internal Sample Format" , OFFSET(int_sample_fmt ), AV_OPT_TYPE_INT , {.dbl=AV_SAMPLE_FMT_NONE }, -1 , AV_SAMPLE_FMT_FLT, PARAM},
{"tsf" , "Internal Sample Format" , OFFSET(int_sample_fmt ), AV_OPT_TYPE_INT , {.dbl=AV_SAMPLE_FMT_NONE }, -1 , AV_SAMPLE_FMT_FLTP, PARAM},
{"internal_sample_fmt" , "Internal Sample Format" , OFFSET(int_sample_fmt ), AV_OPT_TYPE_INT , {.dbl=AV_SAMPLE_FMT_NONE }, -1 , AV_SAMPLE_FMT_FLTP, PARAM},
{"icl" , "Input Channel Layout" , OFFSET( in_ch_layout ), AV_OPT_TYPE_INT64, {.dbl=0 }, 0 , INT64_MAX , PARAM, "channel_layout"},
{"in_channel_layout" , "Input Channel Layout" , OFFSET( in_ch_layout ), AV_OPT_TYPE_INT64, {.dbl=0 }, 0 , INT64_MAX , PARAM, "channel_layout"},
{"ocl" , "Output Channel Layout" , OFFSET(out_ch_layout ), AV_OPT_TYPE_INT64, {.dbl=0 }, 0 , INT64_MAX , PARAM, "channel_layout"},
@ -193,8 +193,6 @@ int swr_init(struct SwrContext *s){
s-> in.planar= av_sample_fmt_is_planar(s-> in_sample_fmt);
s->out.planar= av_sample_fmt_is_planar(s->out_sample_fmt);
s-> in_sample_fmt= av_get_alt_sample_fmt(s-> in_sample_fmt, 0);
s->out_sample_fmt= av_get_alt_sample_fmt(s->out_sample_fmt, 0);
if(s-> in_sample_fmt >= AV_SAMPLE_FMT_NB){
av_log(s, AV_LOG_ERROR, "Requested input sample format %d is invalid\n", s->in_sample_fmt);
@ -206,14 +204,14 @@ int swr_init(struct SwrContext *s){
}
//FIXME should we allow/support using FLT on material that doesnt need it ?
if(s->in_sample_fmt <= AV_SAMPLE_FMT_S16 || s->int_sample_fmt==AV_SAMPLE_FMT_S16){
s->int_sample_fmt= AV_SAMPLE_FMT_S16;
if(av_get_planar_sample_fmt(s->in_sample_fmt) <= AV_SAMPLE_FMT_S16P || s->int_sample_fmt==AV_SAMPLE_FMT_S16P){
s->int_sample_fmt= AV_SAMPLE_FMT_S16P;
}else
s->int_sample_fmt= AV_SAMPLE_FMT_FLT;
s->int_sample_fmt= AV_SAMPLE_FMT_FLTP;
if( s->int_sample_fmt != AV_SAMPLE_FMT_S16
&&s->int_sample_fmt != AV_SAMPLE_FMT_S32
&&s->int_sample_fmt != AV_SAMPLE_FMT_FLT){
if( s->int_sample_fmt != AV_SAMPLE_FMT_S16P
&&s->int_sample_fmt != AV_SAMPLE_FMT_S32P
&&s->int_sample_fmt != AV_SAMPLE_FMT_FLTP){
av_log(s, AV_LOG_ERROR, "Requested sample format %s is not supported internally, S16/S32/FLT is supported\n", av_get_sample_fmt_name(s->int_sample_fmt));
return AVERROR(EINVAL);
}
@ -222,9 +220,9 @@ int swr_init(struct SwrContext *s){
s->resample = swri_resample_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);
}else
swri_resample_free(&s->resample);
if( s->int_sample_fmt != AV_SAMPLE_FMT_S16
&& s->int_sample_fmt != AV_SAMPLE_FMT_S32
&& s->int_sample_fmt != AV_SAMPLE_FMT_FLT
if( s->int_sample_fmt != AV_SAMPLE_FMT_S16P
&& s->int_sample_fmt != AV_SAMPLE_FMT_S32P
&& s->int_sample_fmt != AV_SAMPLE_FMT_FLTP
&& s->resample){
av_log(s, AV_LOG_ERROR, "Resampling only supported with internal s16/s32/flt\n");
return -1;

@ -37,7 +37,7 @@ struct SwrContext {
int log_level_offset; ///< logging level offset
void *log_ctx; ///< parent logging context
enum AVSampleFormat in_sample_fmt; ///< input sample format
enum AVSampleFormat int_sample_fmt; ///< internal sample format (AV_SAMPLE_FMT_FLT or AV_SAMPLE_FMT_S16)
enum AVSampleFormat int_sample_fmt; ///< internal sample format (AV_SAMPLE_FMT_FLTP or AV_SAMPLE_FMT_S16P)
enum AVSampleFormat out_sample_fmt; ///< output sample format
int64_t in_ch_layout; ///< input channel layout
int64_t out_ch_layout; ///< output channel layout

Loading…
Cancel
Save