00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef SWR_INTERNAL_H
00022 #define SWR_INTERNAL_H
00023
00024 #include "swresample.h"
00025 #include "libavutil/channel_layout.h"
00026 #include "config.h"
00027
00028 #define SQRT3_2 1.22474487139158904909
00029
00030 #if ARCH_X86_64
00031 typedef int64_t integer;
00032 #else
00033 typedef int integer;
00034 #endif
00035
00036 typedef void (mix_1_1_func_type)(void *out, const void *in, void *coeffp, integer index, integer len);
00037 typedef void (mix_2_1_func_type)(void *out, const void *in1, const void *in2, void *coeffp, integer index1, integer index2, integer len);
00038
00039 typedef void (mix_any_func_type)(uint8_t **out, const uint8_t **in1, void *coeffp, integer len);
00040
00041 typedef struct AudioData{
00042 uint8_t *ch[SWR_CH_MAX];
00043 uint8_t *data;
00044 int ch_count;
00045 int bps;
00046 int count;
00047 int planar;
00048 enum AVSampleFormat fmt;
00049 } AudioData;
00050
00051 struct SwrContext {
00052 const AVClass *av_class;
00053 int log_level_offset;
00054 void *log_ctx;
00055 enum AVSampleFormat in_sample_fmt;
00056 enum AVSampleFormat int_sample_fmt;
00057 enum AVSampleFormat out_sample_fmt;
00058 int64_t in_ch_layout;
00059 int64_t out_ch_layout;
00060 int in_sample_rate;
00061 int out_sample_rate;
00062 int flags;
00063 float slev;
00064 float clev;
00065 float lfe_mix_level;
00066 float rematrix_volume;
00067 enum AVMatrixEncoding matrix_encoding;
00068 const int *channel_map;
00069 int used_ch_count;
00070 enum SwrEngine engine;
00071 enum SwrDitherType dither_method;
00072 int dither_pos;
00073 float dither_scale;
00074 int filter_size;
00075 int phase_shift;
00076 int linear_interp;
00077 double cutoff;
00078 enum SwrFilterType filter_type;
00079 int kaiser_beta;
00080 double precision;
00081 int cheby;
00083 float min_compensation;
00084 float min_hard_compensation;
00085 float soft_compensation_duration;
00086 float max_soft_compensation;
00087
00088 int resample_first;
00089 int rematrix;
00090 int rematrix_custom;
00091
00092 AudioData in;
00093 AudioData postin;
00094 AudioData midbuf;
00095 AudioData preout;
00096 AudioData out;
00097 AudioData in_buffer;
00098 AudioData dither;
00099 int in_buffer_index;
00100 int in_buffer_count;
00101 int resample_in_constraint;
00102 int flushed;
00103 int64_t outpts;
00104 int drop_output;
00105
00106 struct AudioConvert *in_convert;
00107 struct AudioConvert *out_convert;
00108 struct AudioConvert *full_convert;
00109 struct ResampleContext *resample;
00110 struct Resampler const *resampler;
00111
00112 float matrix[SWR_CH_MAX][SWR_CH_MAX];
00113 uint8_t *native_matrix;
00114 uint8_t *native_one;
00115 uint8_t *native_simd_matrix;
00116 int32_t matrix32[SWR_CH_MAX][SWR_CH_MAX];
00117 uint8_t matrix_ch[SWR_CH_MAX][SWR_CH_MAX+1];
00118 mix_1_1_func_type *mix_1_1_f;
00119 mix_1_1_func_type *mix_1_1_simd;
00120
00121 mix_2_1_func_type *mix_2_1_f;
00122 mix_2_1_func_type *mix_2_1_simd;
00123
00124 mix_any_func_type *mix_any_f;
00125
00126
00127 };
00128
00129 typedef struct ResampleContext * (* resample_init_func)(struct ResampleContext *c, int out_rate, int in_rate, int filter_size, int phase_shift, int linear,
00130 double cutoff, enum AVSampleFormat format, enum SwrFilterType filter_type, int kaiser_beta, double precision, int cheby);
00131 typedef void (* resample_free_func)(struct ResampleContext **c);
00132 typedef int (* multiple_resample_func)(struct ResampleContext *c, AudioData *dst, int dst_size, AudioData *src, int src_size, int *consumed);
00133 typedef int (* resample_flush_func)(struct SwrContext *c);
00134 typedef int (* set_compensation_func)(struct ResampleContext *c, int sample_delta, int compensation_distance);
00135 typedef int64_t (* get_delay_func)(struct SwrContext *s, int64_t base);
00136
00137 struct Resampler {
00138 resample_init_func init;
00139 resample_free_func free;
00140 multiple_resample_func multiple_resample;
00141 resample_flush_func flush;
00142 set_compensation_func set_compensation;
00143 get_delay_func get_delay;
00144 };
00145
00146 extern struct Resampler const swri_resampler;
00147
00148 int swri_realloc_audio(AudioData *a, int count);
00149 int swri_resample_int16(struct ResampleContext *c, int16_t *dst, const int16_t *src, int *consumed, int src_size, int dst_size, int update_ctx);
00150 int swri_resample_int32(struct ResampleContext *c, int32_t *dst, const int32_t *src, int *consumed, int src_size, int dst_size, int update_ctx);
00151 int swri_resample_float(struct ResampleContext *c, float *dst, const float *src, int *consumed, int src_size, int dst_size, int update_ctx);
00152 int swri_resample_double(struct ResampleContext *c,double *dst, const double *src, int *consumed, int src_size, int dst_size, int update_ctx);
00153
00154 int swri_rematrix_init(SwrContext *s);
00155 void swri_rematrix_free(SwrContext *s);
00156 int swri_rematrix(SwrContext *s, AudioData *out, AudioData *in, int len, int mustcopy);
00157 void swri_rematrix_init_x86(struct SwrContext *s);
00158
00159 void swri_get_dither(SwrContext *s, void *dst, int len, unsigned seed, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt);
00160
00161 void swri_audio_convert_init_arm(struct AudioConvert *ac,
00162 enum AVSampleFormat out_fmt,
00163 enum AVSampleFormat in_fmt,
00164 int channels);
00165 void swri_audio_convert_init_x86(struct AudioConvert *ac,
00166 enum AVSampleFormat out_fmt,
00167 enum AVSampleFormat in_fmt,
00168 int channels);
00169 #endif