FFmpeg
|
#include <float.h>
#include "libavutil/avassert.h"
#include "libavutil/avstring.h"
#include "libavutil/channel_layout.h"
#include "libavutil/eval.h"
#include "libavutil/opt.h"
#include "libavutil/samplefmt.h"
#include "libavutil/tx.h"
#include "avfilter.h"
#include "audio.h"
#include "internal.h"
Go to the source code of this file.
Data Structures | |
struct | AudioFragment |
A fragment of audio waveform. More... | |
struct | ATempoContext |
Filter state machine. More... | |
Macros | |
#define | YAE_ATEMPO_MIN 0.5 |
#define | YAE_ATEMPO_MAX 100.0 |
#define | OFFSET(x) offsetof(ATempoContext, x) |
#define | RE_MALLOC_OR_FAIL(field, field_size, element_size) |
#define | yae_init_xdat(scalar_type, scalar_max) |
A helper macro for initializing complex data buffer with scalar data of a given type. More... | |
#define | yae_blend(scalar_type) |
A helper macro for blending the overlap region of previous and current audio fragment. More... | |
Enumerations | |
enum | FilterState { YAE_LOAD_FRAGMENT, YAE_ADJUST_POSITION, YAE_RELOAD_FRAGMENT, YAE_OUTPUT_OVERLAP_ADD, YAE_FLUSH_OUTPUT } |
Filter state machine states. More... | |
Functions | |
AVFILTER_DEFINE_CLASS (atempo) | |
static AudioFragment * | yae_curr_frag (ATempoContext *atempo) |
static AudioFragment * | yae_prev_frag (ATempoContext *atempo) |
static void | yae_clear (ATempoContext *atempo) |
Reset filter to initial state, do not deallocate existing local buffers. More... | |
static void | yae_release_buffers (ATempoContext *atempo) |
Reset filter to initial state and deallocate all buffers. More... | |
static int | yae_reset (ATempoContext *atempo, enum AVSampleFormat format, int sample_rate, int channels) |
Prepare filter for processing audio data of given format, sample rate and number of channels. More... | |
static int | yae_update (AVFilterContext *ctx) |
static void | yae_downmix (ATempoContext *atempo, AudioFragment *frag) |
Initialize complex data buffer of a given audio fragment with down-mixed mono data of appropriate scalar type. More... | |
static int | yae_load_data (ATempoContext *atempo, const uint8_t **src_ref, const uint8_t *src_end, int64_t stop_here) |
Populate the internal data buffer on as-needed basis. More... | |
static int | yae_load_frag (ATempoContext *atempo, const uint8_t **src_ref, const uint8_t *src_end) |
Populate current audio fragment data buffer. More... | |
static void | yae_advance_to_next_frag (ATempoContext *atempo) |
Prepare for loading next audio fragment. More... | |
static void | yae_xcorr_via_rdft (float *xcorr_in, float *xcorr, AVTXContext *complex_to_real, av_tx_fn c2r_fn, const AVComplexFloat *xa, const AVComplexFloat *xb, const int window) |
Calculate cross-correlation via rDFT. More... | |
static int | yae_align (AudioFragment *frag, const AudioFragment *prev, const int window, const int delta_max, const int drift, float *correlation_in, float *correlation, AVTXContext *complex_to_real, av_tx_fn c2r_fn) |
Calculate alignment offset for given fragment relative to the previous fragment. More... | |
static int | yae_adjust_position (ATempoContext *atempo) |
Adjust current fragment position for better alignment with previous fragment. More... | |
static int | yae_overlap_add (ATempoContext *atempo, uint8_t **dst_ref, uint8_t *dst_end) |
Blend the overlap region of previous and current audio fragment and output the results to the given destination buffer. More... | |
static void | yae_apply (ATempoContext *atempo, const uint8_t **src_ref, const uint8_t *src_end, uint8_t **dst_ref, uint8_t *dst_end) |
Feed as much data to the filter as it is able to consume and receive as much processed data in the destination buffer as it is able to produce or store. More... | |
static int | yae_flush (ATempoContext *atempo, uint8_t **dst_ref, uint8_t *dst_end) |
Flush any buffered data from the filter. More... | |
static av_cold int | init (AVFilterContext *ctx) |
static av_cold void | uninit (AVFilterContext *ctx) |
static int | config_props (AVFilterLink *inlink) |
static int | push_samples (ATempoContext *atempo, AVFilterLink *outlink, int n_out) |
static int | filter_frame (AVFilterLink *inlink, AVFrame *src_buffer) |
static int | request_frame (AVFilterLink *outlink) |
static int | process_command (AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags) |
Variables | |
static const AVOption | atempo_options [] |
static enum AVSampleFormat | sample_fmts [] |
static const AVFilterPad | atempo_inputs [] |
static const AVFilterPad | atempo_outputs [] |
const AVFilter | ff_af_atempo |
tempo scaling audio filter – an implementation of WSOLA algorithm
Based on MIT licensed yaeAudioTempoFilter.h and yaeAudioFragment.h from Apprentice Video player by Pavel Koshevoy. https://sourceforge.net/projects/apprenticevideo/
An explanation of SOLA algorithm is available at http://www.surina.net/article/time-and-pitch-scaling.html
WSOLA is very similar to SOLA, only one major difference exists between these algorithms. SOLA shifts audio fragments along the output stream, where as WSOLA shifts audio fragments along the input stream.
The advantage of WSOLA algorithm is that the overlap region size is always the same, therefore the blending function is constant and can be precomputed.
Definition in file af_atempo.c.
#define YAE_ATEMPO_MIN 0.5 |
Definition at line 158 of file af_atempo.c.
#define YAE_ATEMPO_MAX 100.0 |
Definition at line 159 of file af_atempo.c.
#define OFFSET | ( | x | ) | offsetof(ATempoContext, x) |
Definition at line 161 of file af_atempo.c.
#define RE_MALLOC_OR_FAIL | ( | field, | |
field_size, | |||
element_size | |||
) |
#define yae_init_xdat | ( | scalar_type, | |
scalar_max | |||
) |
A helper macro for initializing complex data buffer with scalar data of a given type.
Definition at line 350 of file af_atempo.c.
#define yae_blend | ( | scalar_type | ) |
A helper macro for blending the overlap region of previous and current audio fragment.
Definition at line 729 of file af_atempo.c.
enum FilterState |
Filter state machine states.
Enumerator | |
---|---|
YAE_LOAD_FRAGMENT | |
YAE_ADJUST_POSITION | |
YAE_RELOAD_FRAGMENT | |
YAE_OUTPUT_OVERLAP_ADD | |
YAE_FLUSH_OUTPUT |
Definition at line 77 of file af_atempo.c.
AVFILTER_DEFINE_CLASS | ( | atempo | ) |
|
inlinestatic |
Definition at line 174 of file af_atempo.c.
Referenced by yae_adjust_position(), yae_advance_to_next_frag(), yae_apply(), yae_flush(), yae_load_frag(), and yae_overlap_add().
|
inlinestatic |
Definition at line 179 of file af_atempo.c.
Referenced by yae_adjust_position(), yae_advance_to_next_frag(), yae_overlap_add(), and yae_update().
|
static |
Reset filter to initial state, do not deallocate existing local buffers.
Definition at line 187 of file af_atempo.c.
Referenced by yae_release_buffers(), and yae_reset().
|
static |
Reset filter to initial state and deallocate all buffers.
Definition at line 228 of file af_atempo.c.
Referenced by uninit(), and yae_reset().
|
static |
Prepare filter for processing audio data of given format, sample rate and number of channels.
Definition at line 264 of file af_atempo.c.
Referenced by config_props().
|
static |
Definition at line 335 of file af_atempo.c.
Referenced by process_command().
|
static |
Initialize complex data buffer of a given audio fragment with down-mixed mono data of appropriate scalar type.
Definition at line 400 of file af_atempo.c.
Referenced by yae_apply(), and yae_flush().
|
static |
Populate the internal data buffer on as-needed basis.
Definition at line 428 of file af_atempo.c.
Referenced by yae_load_frag().
|
static |
Populate current audio fragment data buffer.
Definition at line 503 of file af_atempo.c.
Referenced by yae_apply(), and yae_flush().
|
static |
Prepare for loading next audio fragment.
Definition at line 583 of file af_atempo.c.
Referenced by yae_apply(), and yae_flush().
|
static |
Calculate cross-correlation via rDFT.
Multiply two vectors of complex numbers (result of real_to_complex rDFT) and transform back via complex_to_real rDFT.
Definition at line 605 of file af_atempo.c.
Referenced by yae_align().
|
static |
Calculate alignment offset for given fragment relative to the previous fragment.
Definition at line 631 of file af_atempo.c.
Referenced by yae_adjust_position().
|
static |
Adjust current fragment position for better alignment with previous fragment.
Definition at line 689 of file af_atempo.c.
Referenced by yae_apply(), and yae_flush().
|
static |
Blend the overlap region of previous and current audio fragment and output the results to the given destination buffer.
Definition at line 766 of file af_atempo.c.
Referenced by yae_apply(), and yae_flush().
|
static |
Feed as much data to the filter as it is able to consume and receive as much processed data in the destination buffer as it is able to produce or store.
Definition at line 821 of file af_atempo.c.
Referenced by filter_frame().
|
static |
Flush any buffered data from the filter.
Definition at line 895 of file af_atempo.c.
Referenced by request_frame().
|
static |
Definition at line 984 of file af_atempo.c.
|
static |
Definition at line 992 of file af_atempo.c.
|
static |
Definition at line 1013 of file af_atempo.c.
|
static |
Definition at line 1024 of file af_atempo.c.
Referenced by filter_frame(), and request_frame().
|
static |
Definition at line 1050 of file af_atempo.c.
|
static |
Definition at line 1098 of file af_atempo.c.
|
static |
Definition at line 1144 of file af_atempo.c.
|
static |
Definition at line 163 of file af_atempo.c.
|
static |
Definition at line 1004 of file af_atempo.c.
|
static |
Definition at line 1159 of file af_atempo.c.
|
static |
Definition at line 1168 of file af_atempo.c.
const AVFilter ff_af_atempo |
Definition at line 1176 of file af_atempo.c.