31 #ifndef CONFIG_RESAMPLE_HP
32 #define FILTER_SHIFT 15
35 #define FELEM2 int32_t
36 #define FELEML int64_t
37 #define FELEM_MAX INT16_MAX
38 #define FELEM_MIN INT16_MIN
40 #elif !defined(CONFIG_RESAMPLE_AUDIOPHILE_KIDDY_MODE)
41 #define FILTER_SHIFT 30
44 #define FELEM2 int64_t
45 #define FELEML int64_t
46 #define FELEM_MAX INT32_MAX
47 #define FELEM_MIN INT32_MIN
48 #define WINDOW_TYPE 12
50 #define FILTER_SHIFT 0
55 #define WINDOW_TYPE 24
84 for(i=1; v != lastv; i++){
103 const int center= (tap_count-1)/2;
112 for(ph=0;ph<phase_count;ph++) {
114 for(i=0;i<tap_count;i++) {
115 x =
M_PI * ((double)(i - center) - (double)ph / phase_count) * factor;
121 x = fabs(((
double)(i - center) - (
double)ph / phase_count) * factor);
122 if(x<1.0) y= 1 - 3*x*x + 2*x*x*x + d*( -x*x + x*x*x);
123 else y= d*(-4 + 8*x - 5*x*x + x*x*x);
126 w = 2.0*x / (factor*tap_count) +
M_PI;
127 y *= 0.3635819 - 0.4891775 * cos(w) + 0.1365995 * cos(2*w) - 0.0106411 * cos(3*w);
130 w = 2.0*x / (factor*tap_count*
M_PI);
140 for(i=0;i<tap_count;i++) {
141 #ifdef CONFIG_RESAMPLE_AUDIOPHILE_KIDDY_MODE
142 filter[ph * tap_count + i] = tab[i] / norm;
152 double sine[LEN + tap_count];
153 double filtered[LEN];
154 double maxff=-2, minff=2, maxsf=-2, minsf=2;
155 for(i=0; i<LEN; i++){
156 double ss=0, sf=0, ff=0;
157 for(j=0; j<LEN+tap_count; j++)
158 sine[j]= cos(i*j*
M_PI/LEN);
159 for(j=0; j<LEN; j++){
162 for(k=0; k<tap_count; k++)
163 sum += filter[ph * tap_count + k] * sine[k+j];
165 ss+= sine[j + center] * sine[j + center];
166 ff+= filtered[j] * filtered[j];
167 sf+= sine[j + center] * filtered[j];
172 maxff=
FFMAX(maxff, ff);
173 minff=
FFMIN(minff, ff);
174 maxsf=
FFMAX(maxsf, sf);
175 minsf=
FFMIN(minsf, sf);
177 av_log(
NULL,
AV_LOG_ERROR,
"i:%4d ss:%f ff:%13.6e-%13.6e sf:%13.6e-%13.6e\n", i, ss, maxff, minff, maxsf, minsf);
191 double factor=
FFMIN(out_rate * cutoff / in_rate, 1.0);
192 int phase_count= 1<<phase_shift;
241 int64_t index2= ((int64_t)index)<<32;
245 for(dst_index=0; dst_index < dst_size; dst_index++){
246 dst[dst_index] = src[index2>>32];
249 frac += dst_index * dst_incr_frac;
250 index += dst_index * dst_incr;
254 for(dst_index=0; dst_index < dst_size; dst_index++){
259 if(sample_index < 0){
261 val += src[
FFABS(sample_index + i) % src_size] * filter[i];
267 val += src[sample_index + i] * (
FELEM2)filter[i];
273 val += src[sample_index + i] * (
FELEM2)filter[i];
277 #ifdef CONFIG_RESAMPLE_AUDIOPHILE_KIDDY_MODE
278 dst[dst_index] = av_clip_int16(
lrintf(val));
281 dst[dst_index] = (unsigned)(val + 32768) > 65535 ? (val>>31) ^ 32767 : val;
284 frac += dst_incr_frac;
291 if(dst_index + 1 == compensation_distance){
292 compensation_distance= 0;
301 if(compensation_distance){
302 compensation_distance -= dst_index;
303 assert(compensation_distance > 0);
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
AVResampleContext * av_resample_init(int out_rate, int in_rate, int filter_size, int phase_shift, int linear, double cutoff)
Initialize an audio resampler.
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
struct AVResampleContext AVResampleContext
static double bessel(double x)
0th order modified bessel function of the first kind.
int av_resample(AVResampleContext *c, short *dst, short *src, int *consumed, int src_size, int dst_size, int update_ctx)
Resample an array of samples using a previously configured context.
void av_resample_close(AVResampleContext *c)
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
void av_resample_compensate(AVResampleContext *c, int sample_delta, int compensation_distance)
Compensate samplerate/timestamp drift.
void av_log(void *avcl, int level, const char *fmt,...)
int compensation_distance
static void filter(MpegAudioContext *s, int ch, const short *samples, int incr)
static av_always_inline av_const long int lrintf(float x)
static int build_filter(FELEM *filter, double factor, int tap_count, int phase_count, int scale, int type)
Build a polyphase filterbank.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Describe the class of an AVClass context structure.
static const uint16_t scale[4]
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static const struct @46 tab
TwinVQ codebooks.