26 #include "libavutil/avassert.h"
27 #include "libavutil/opt.h"
57 int nb_samples,
int channels);
60 #define OFFSET(x) offsetof(AudioPhaserContext, x)
61 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
122 void *
table,
int table_size,
123 double min,
double max,
double phase)
125 uint32_t i, phase_offset = phase /
M_PI / 2 * table_size + 0.5;
127 for (i = 0; i < table_size; i++) {
128 uint32_t point = (i + phase_offset) % table_size;
133 d = (sin((
double)point / table_size * 2 *
M_PI) + 1) / 2;
136 d = (double)point * 2 / table_size;
137 switch (4 * point / table_size) {
138 case 0: d = d + 0.5;
break;
140 case 2: d = 1.5 - d;
break;
141 case 3: d = d - 1.5;
break;
148 d = d * (max -
min) + min;
149 switch (sample_fmt) {
151 float *
fp = (
float *)table;
156 double *dp = (
double *)table;
162 d += d < 0 ? -0.5 : 0.5;
163 switch (sample_fmt) {
180 #define MOD(a, b) (((a) >= (b)) ? (a) - (b) : (a))
182 #define PHASER_PLANAR(name, type) \
183 static void phaser_## name ##p(AudioPhaserContext *p, \
184 uint8_t * const *src, uint8_t **dst, \
185 int nb_samples, int channels) \
187 int i, c, delay_pos, modulation_pos; \
189 av_assert0(channels > 0); \
190 for (c = 0; c < channels; c++) { \
191 type *s = (type *)src[c]; \
192 type *d = (type *)dst[c]; \
193 double *buffer = p->delay_buffer + \
194 c * p->delay_buffer_length; \
196 delay_pos = p->delay_pos; \
197 modulation_pos = p->modulation_pos; \
199 for (i = 0; i < nb_samples; i++, s++, d++) { \
200 double v = *s * p->in_gain + buffer[ \
201 MOD(delay_pos + p->modulation_buffer[ \
203 p->delay_buffer_length)] * p->decay; \
205 modulation_pos = MOD(modulation_pos + 1, \
206 p->modulation_buffer_length); \
207 delay_pos = MOD(delay_pos + 1, p->delay_buffer_length); \
208 buffer[delay_pos] = v; \
210 *d = v * p->out_gain; \
214 p->delay_pos = delay_pos; \
215 p->modulation_pos = modulation_pos; \
218 #define PHASER(name, type) \
219 static void phaser_## name (AudioPhaserContext *p, \
220 uint8_t * const *src, uint8_t **dst, \
221 int nb_samples, int channels) \
223 int i, c, delay_pos, modulation_pos; \
224 type *s = (type *)src[0]; \
225 type *d = (type *)dst[0]; \
226 double *buffer = p->delay_buffer; \
228 delay_pos = p->delay_pos; \
229 modulation_pos = p->modulation_pos; \
231 for (i = 0; i < nb_samples; i++) { \
232 int pos = MOD(delay_pos + p->modulation_buffer[modulation_pos], \
233 p->delay_buffer_length) * channels; \
236 delay_pos = MOD(delay_pos + 1, p->delay_buffer_length); \
237 npos = delay_pos * channels; \
238 for (c = 0; c < channels; c++, s++, d++) { \
239 double v = *s * p->in_gain + buffer[pos + c] * p->decay; \
241 buffer[npos + c] = v; \
243 *d = v * p->out_gain; \
246 modulation_pos = MOD(modulation_pos + 1, \
247 p->modulation_buffer_length); \
250 p->delay_pos = delay_pos; \
251 p->modulation_pos = modulation_pos; \
357 .priv_class = &aphaser_class,
static const AVOption aphaser_options[]
void * av_calloc(size_t nmemb, size_t size) av_malloc_attrib
Allocate a block of nmemb * size bytes with alignment suitable for all memory accesses (including vec...
This structure describes decoded (raw) audio or video data.
const char * name
Filter name.
void * priv
private data for use by the filter
#define AV_LOG_WARNING
Something somehow does not look correct.
static const AVFilterPad outputs[]
static struct endianess table[]
uint8_t ** extended_data
pointers to the data planes/channels.
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
static enum AVSampleFormat formats[]
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
const char * name
Pad name.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
static const AVFilterPad aphaser_outputs[]
static av_cold void uninit(AVFilterContext *ctx)
A filter pad used for either input or output.
A link between two filters.
int sample_rate
samples per second
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
#define PHASER(name, type)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
AVFilterContext * src
source filter
int av_frame_get_channels(const AVFrame *frame)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
static int config_output(AVFilterLink *outlink)
static int filter_frame(AVFilterLink *inlink, AVFrame *inbuf)
AVFilter avfilter_af_aphaser
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
static av_cold int init(AVFilterContext *ctx)
int format
agreed upon media format
static void generate_wave_table(enum WaveType wave_type, enum AVSampleFormat sample_fmt, void *table, int table_size, double min, double max, double phase)
A list of supported channel layouts.
Main libavfilter public API header.
AVFilterLink ** outputs
array of pointers to output links
AVSampleFormat
Audio Sample Formats.
typedef void(RENAME(mix_any_func_type))
Describe the class of an AVClass context structure.
static const AVFilterPad inputs[]
AVFilterLink ** inputs
array of pointers to input links
AVFilterContext * dst
dest filter
enum MovChannelLayoutTag * layouts
void(* phaser)(struct AudioPhaserContext *p, uint8_t *const *src, uint8_t **dst, int nb_samples, int channels)
int modulation_buffer_length
static int query_formats(AVFilterContext *ctx)
int channels
Number of channels.
#define AVFILTER_DEFINE_CLASS(fname)
int32_t * modulation_buffer
static enum AVSampleFormat sample_fmts[]
static const AVFilterPad aphaser_inputs[]
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int nb_samples
number of audio samples (per channel) described by this frame
#define PHASER_PLANAR(name, type)