mirror of
https://github.com/mpv-player/mpv.git
synced 2025-12-28 05:33:14 +00:00
af_scaletempo: use Hann function for overlap window
Better in theory, but not really noticable.
This commit is contained in:
committed by
Kacper Michajłow
parent
3a85fd97e5
commit
2287804739
@@ -35,6 +35,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#include "audio/aframe.h"
|
#include "audio/aframe.h"
|
||||||
#include "audio/format.h"
|
#include "audio/format.h"
|
||||||
@@ -422,18 +423,20 @@ static bool reinit(struct mp_filter *f)
|
|||||||
memset(s->buf_overlap, 0, s->bytes_overlap);
|
memset(s->buf_overlap, 0, s->bytes_overlap);
|
||||||
if (use_int) {
|
if (use_int) {
|
||||||
int32_t *pb = s->table_blend;
|
int32_t *pb = s->table_blend;
|
||||||
int64_t blend = 0;
|
const float scale = M_PI / frames_overlap;
|
||||||
for (int i = 0; i < frames_overlap; i++) {
|
for (int i = 0; i < frames_overlap; i++) {
|
||||||
int32_t v = blend / frames_overlap;
|
// Hann function
|
||||||
|
const int32_t v = 0.5f * (1.0f - cosf(i * scale)) * 65536 + 0.5;
|
||||||
for (int j = 0; j < nch; j++)
|
for (int j = 0; j < nch; j++)
|
||||||
*pb++ = v;
|
*pb++ = v;
|
||||||
blend += 65536; // 2^16
|
|
||||||
}
|
}
|
||||||
s->output_overlap = output_overlap_s16;
|
s->output_overlap = output_overlap_s16;
|
||||||
} else {
|
} else {
|
||||||
float *pb = s->table_blend;
|
float *pb = s->table_blend;
|
||||||
|
const float scale = M_PI / frames_overlap;
|
||||||
for (int i = 0; i < frames_overlap; i++) {
|
for (int i = 0; i < frames_overlap; i++) {
|
||||||
float v = i / (float)frames_overlap;
|
// Hann function
|
||||||
|
const float v = 0.5f * (1.0f - cosf(i * scale));
|
||||||
for (int j = 0; j < nch; j++)
|
for (int j = 0; j < nch; j++)
|
||||||
*pb++ = v;
|
*pb++ = v;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user