diff options
author | wm4 <wm4@nowhere> | 2015-01-15 20:10:52 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2015-01-15 20:13:12 +0100 |
commit | 87fe7d878843688a0f530fc9ce5a1a0775c77b9e (patch) | |
tree | 185e92cf90cb51604161243f7e02eb977a05ae1d /audio/filter/af_sinesuppress.c | |
parent | ba0e8b754c4282bae941aa5d30614b2a305f9f5f (diff) | |
download | mpv-87fe7d878843688a0f530fc9ce5a1a0775c77b9e.tar.bz2 mpv-87fe7d878843688a0f530fc9ce5a1a0775c77b9e.tar.xz |
audio/filter: switch remaining in-place filters to refcounting
Adds about 7 lines of boilerplate per filter. This could be avoided by
providing a different entrypoint (something like af->filter_inplace),
which would basically mirror the old interface exactly for this kind of
filter. But I feel like it would just be a hack to support all those
old, useless filters better. (The ideal solution would be using a
language that can do closures to provide a compat. wrapper, but
whatever.)
af_bs2b has terribly repetitious code for setting up filter functions
for each format (most of them useless, in addition to bs2b being
useless), so I did something terrible with macros.
af_sinesuppress had commented code for float filtering (maybe it was
broken; it has been commented every since it was added in 2006). Remove
this code.
Diffstat (limited to 'audio/filter/af_sinesuppress.c')
-rw-r--r-- | audio/filter/af_sinesuppress.c | 53 |
1 files changed, 11 insertions, 42 deletions
diff --git a/audio/filter/af_sinesuppress.c b/audio/filter/af_sinesuppress.c index 95d2478b7e..32e074d508 100644 --- a/audio/filter/af_sinesuppress.c +++ b/audio/filter/af_sinesuppress.c @@ -41,9 +41,6 @@ typedef struct af_sinesuppress_s double pos; }af_sinesuppress_t; -static int play_s16(struct af_instance* af, struct mp_audio* data, int f); -//static struct mp_audio* play_float(struct af_instance* af, struct mp_audio* data); - // Initialization and runtime control static int control(struct af_instance* af, int cmd, void* arg) { @@ -54,18 +51,7 @@ static int control(struct af_instance* af, int cmd, void* arg) mp_audio_copy_config(af->data, (struct mp_audio*)arg); mp_audio_set_num_channels(af->data, 1); -#if 0 - if (((struct mp_audio*)arg)->format == AF_FORMAT_FLOAT) - { - af->data->format = AF_FORMAT_FLOAT; - af->data->bps = 4; - af->play = play_float; - }// else -#endif - { - mp_audio_set_format(af->data, AF_FORMAT_S16); - af->filter = play_s16; - } + mp_audio_set_format(af->data, AF_FORMAT_S16); return af_test_output(af,(struct mp_audio*)arg); } @@ -73,9 +59,15 @@ static int control(struct af_instance* af, int cmd, void* arg) return AF_UNKNOWN; } -// Filter data through filter -static int play_s16(struct af_instance* af, struct mp_audio* data, int f) +static int play_s16(struct af_instance *af, struct mp_audio *data) { + if (!data) + return 0; + if (af_make_writeable(af, data) < 0) { + talloc_free(data); + return -1; + } + af_sinesuppress_t *s = af->priv; register int i = 0; int16_t *a = (int16_t*)data->planes[0]; // Audio data @@ -101,37 +93,14 @@ static int play_s16(struct af_instance* af, struct mp_audio* data, int f) MP_VERBOSE(af, "f:%8.2f: amp:%8.2f\n", s->freq, sqrt(s->real*s->real + s->imag*s->imag) / s->ref); + af_add_output_frame(af, data); return 0; } -#if 0 -static struct mp_audio* play_float(struct af_instance* af, struct mp_audio* data) -{ - af_sinesuppress_t *s = af->setup; - register int i = 0; - float *a = (float*)data->audio; // Audio data - int len = data->len/4; // Number of samples - float avg, l, r; - - for (i = 0; i < len; i+=2) - { - avg = (a[i] + a[i + 1]) / 2; - -/* l = avg + (s->mul * (a[i] - avg)); - r = avg + (s->mul * (a[i + 1] - avg));*/ - - a[i] = af_softclip(l); - a[i + 1] = af_softclip(r); - } - - return data; -} -#endif - // Allocate memory and set function pointers static int af_open(struct af_instance* af){ af->control=control; - af->filter=play_s16; + af->filter_frame = play_s16; return AF_OK; } |