diff options
author | Wim Taymans <wtaymans@redhat.com> | 2015-10-28 11:40:42 +0100 |
---|---|---|
committer | Wim Taymans <wtaymans@redhat.com> | 2015-10-30 17:51:47 +0100 |
commit | 26d469a04bb15166d4d6879f3614346d4daaa0f0 (patch) | |
tree | a897a5f5043f9729021012ea297bdd7f4fdcfee1 /gst/audioconvert | |
parent | 1da79c76a7f83a27fa7c6e788101291ee5e70560 (diff) |
audioquantize: make helper for add with saturation
Diffstat (limited to 'gst/audioconvert')
-rw-r--r-- | gst/audioconvert/gstaudioquantize.c | 29 |
1 files changed, 11 insertions, 18 deletions
diff --git a/gst/audioconvert/gstaudioquantize.c b/gst/audioconvert/gstaudioquantize.c index 8f7d1ec07..ac40659bd 100644 --- a/gst/audioconvert/gstaudioquantize.c +++ b/gst/audioconvert/gstaudioquantize.c @@ -62,6 +62,14 @@ struct _GstAudioQuantize #define MAKE_QUANTIZE_FUNC_NAME(name) \ gst_audio_quantize_quantize_##name +#define ADDSS(res,val) \ + if (val > 0 && res > 0 && G_MAXINT32 - res <= val) \ + res = G_MAXINT32; \ + else if (val < 0 && res < 0 && G_MININT32 - res >= val) \ + res = G_MININT32; \ + else \ + res += val; + /* Quantize functions for gint32 as intermediate format */ #define MAKE_QUANTIZE_FUNC_I(name, DITHER_INIT_FUNC, ADD_DITHER_FUNC, \ @@ -162,12 +170,7 @@ MAKE_QUANTIZE_FUNC_NAME (name) (GstAudioQuantize *quant, gdouble *src, \ #define ADD_DITHER_RPDF_I() \ rand = bias + RANDOM_INT_DITHER(dither); \ - if (rand > 0 && tmp > 0 && G_MAXINT32 - tmp <= rand) \ - tmp = G_MAXINT32; \ - else if (rand < 0 && tmp < 0 && G_MININT32 - tmp >= rand) \ - tmp = G_MININT32; \ - else \ - tmp += rand; + ADDSS (tmp, rand); #define INIT_DITHER_RPDF_F() \ gdouble dither = 1.0/(1U<<(32 - scale - 1)); @@ -182,12 +185,7 @@ MAKE_QUANTIZE_FUNC_NAME (name) (GstAudioQuantize *quant, gdouble *src, \ #define ADD_DITHER_TPDF_I() \ rand = bias + RANDOM_INT_DITHER(dither) \ + RANDOM_INT_DITHER(dither); \ - if (rand > 0 && tmp > 0 && G_MAXINT32 - tmp <= rand) \ - tmp = G_MAXINT32; \ - else if (rand < 0 && tmp < 0 && G_MININT32 - tmp >= rand) \ - tmp = G_MININT32; \ - else \ - tmp += rand; + ADDSS (tmp, rand); #define INIT_DITHER_TPDF_F() \ gdouble dither = 1.0/(1U<<(32 - scale)); @@ -205,12 +203,7 @@ MAKE_QUANTIZE_FUNC_NAME (name) (GstAudioQuantize *quant, gdouble *src, \ tmp_rand = RANDOM_INT_DITHER(dither); \ rand = bias + tmp_rand - last_random[chan_pos]; \ last_random[chan_pos] = tmp_rand; \ - if (rand > 0 && tmp > 0 && G_MAXINT32 - tmp <= rand) \ - tmp = G_MAXINT32; \ - else if (rand < 0 && tmp < 0 && G_MININT32 - tmp >= rand) \ - tmp = G_MININT32; \ - else \ - tmp += rand; + ADDSS (tmp, rand); /* Like TPDF dither but the dither noise is oriented more to the * higher frequencies */ |