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_bs2b.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_bs2b.c')
-rw-r--r-- | audio/filter/af_bs2b.c | 89 |
1 files changed, 42 insertions, 47 deletions
diff --git a/audio/filter/af_bs2b.c b/audio/filter/af_bs2b.c index 29d646a9a9..874dbc6786 100644 --- a/audio/filter/af_bs2b.c +++ b/audio/filter/af_bs2b.c @@ -37,26 +37,49 @@ struct af_bs2b { t_bs2bdp filter; ///< instance of a library filter }; -#define FILTER(name, type) \ -static int filter_##name(struct af_instance *af, struct mp_audio *data, int f) \ +#define DEF_FILTER(fmt, name) \ +static int filter_##name(struct af_instance *af, struct mp_audio *data) \ { \ - /* filter is called for all pairs of samples available in the buffer */ \ + if (!data) \ + return 0; \ + if (af_make_writeable(af, data) < 0) { \ + talloc_free(data); \ + return -1; \ + } \ bs2b_cross_feed_##name(((struct af_bs2b*)(af->priv))->filter, \ - (type*)(data->planes[0]), data->samples); \ -\ + (data->planes[0]), data->samples); \ + af_add_output_frame(af, data); \ return 0; \ } -FILTER(f, float) -FILTER(s32, int32_t) -FILTER(u32, uint32_t) -FILTER(s24, bs2b_int24_t) -FILTER(u24, bs2b_uint24_t) -FILTER(s16, int16_t) -FILTER(u16, uint16_t) -FILTER(s8, int8_t) -FILTER(u8, uint8_t) - +#define GET_FILTER(fmt, name) \ + case AF_FORMAT_##fmt: return filter_##name; + +#define FILTERS \ + FILTER(FLOAT, f) \ + FILTER(S32, s32) \ + FILTER(U32, u32) \ + FILTER(S24, s24) \ + FILTER(U24, u24) \ + FILTER(S16, s16) \ + FILTER(U16, u16) \ + FILTER(S8, s8) \ + FILTER(U8, u8) + +#define FILTER DEF_FILTER +FILTERS +#undef FILTER + +typedef int (*filter)(struct af_instance *af, struct mp_audio *d); +static filter get_filter(int fmt) +{ + switch (fmt) { +#define FILTER GET_FILTER +FILTERS +#undef FILTER + default: return NULL; + } +} /// Initialization and runtime control static int control(struct af_instance *af, int cmd, void *arg) @@ -76,38 +99,10 @@ static int control(struct af_instance *af, int cmd, void *arg) /* check for formats supported by libbs2b and assign corresponding handlers */ - switch (format) { - case AF_FORMAT_FLOAT: - af->filter = filter_f; - break; - case AF_FORMAT_S32: - af->filter = filter_s32; - break; - case AF_FORMAT_U32: - af->filter = filter_u32; - break; - case AF_FORMAT_S24: - af->filter = filter_s24; - break; - case AF_FORMAT_U24: - af->filter = filter_u24; - break; - case AF_FORMAT_S16: - af->filter = filter_s16; - break; - case AF_FORMAT_U16: - af->filter = filter_u16; - break; - case AF_FORMAT_S8: - af->filter = filter_s8; - break; - case AF_FORMAT_U8: - af->filter = filter_u8; - break; - default: - af->filter = filter_f; - mp_audio_set_format(af->data, AF_FORMAT_FLOAT); - break; + af->filter_frame = get_filter(format); + if (!af->filter_frame) { + af->filter_frame = filter_f; + mp_audio_set_format(af->data, AF_FORMAT_FLOAT); } // bs2b have srate limits, try to resample if needed |