gst/audioconvert/: Implement dithering and noise shaping in audioconvert. By default now
Original commit message from CVS:
* gst/audioconvert/Makefile.am:
* gst/audioconvert/audioconvert.c: (audio_convert_get_func_index),
(check_default), (audio_convert_prepare_context),
(audio_convert_clean_context), (audio_convert_convert):
* gst/audioconvert/audioconvert.h:
* gst/audioconvert/gstaudioconvert.c:
(gst_audio_convert_dithering_get_type),
(gst_audio_convert_ns_get_type), (gst_audio_convert_class_init),
(gst_audio_convert_init), (gst_audio_convert_set_caps),
(gst_audio_convert_set_property), (gst_audio_convert_get_property):
* gst/audioconvert/gstaudioconvert.h:
* gst/audioconvert/gstaudioquantize.c:
(gst_audio_quantize_setup_noise_shaping),
(gst_audio_quantize_free_noise_shaping),
(gst_audio_quantize_setup_dither),
(gst_audio_quantize_free_dither),
(gst_audio_quantize_setup_quantize_func),
(gst_audio_quantize_setup), (gst_audio_quantize_free):
* gst/audioconvert/gstaudioquantize.h:
Implement dithering and noise shaping in audioconvert. By default now
TPDF dithering (and no noise shaping) will be used when converting
from a higher bit depth to 20 bit depth or smaller, otherwise
everything will be as it is now.
For the last audioconvert in a pipeline it would make sense to
use some kind of noise shaping, enabling it by default for all
conversions would give undesired results though. Fixes #360246.
* tests/check/elements/audioconvert.c: (setup_audioconvert),
(GST_START_TEST):
Adjust unit test for the new audioconvert.
2007-06-28 20:37:58 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2007 Sebastian Dröge <slomo@circular-chaos.org>
|
|
|
|
*
|
|
|
|
* gstaudioquantize.c: quantizes audio to the target format and optionally
|
|
|
|
* applies dithering and noise shaping.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-03 23:05:09 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
gst/audioconvert/: Implement dithering and noise shaping in audioconvert. By default now
Original commit message from CVS:
* gst/audioconvert/Makefile.am:
* gst/audioconvert/audioconvert.c: (audio_convert_get_func_index),
(check_default), (audio_convert_prepare_context),
(audio_convert_clean_context), (audio_convert_convert):
* gst/audioconvert/audioconvert.h:
* gst/audioconvert/gstaudioconvert.c:
(gst_audio_convert_dithering_get_type),
(gst_audio_convert_ns_get_type), (gst_audio_convert_class_init),
(gst_audio_convert_init), (gst_audio_convert_set_caps),
(gst_audio_convert_set_property), (gst_audio_convert_get_property):
* gst/audioconvert/gstaudioconvert.h:
* gst/audioconvert/gstaudioquantize.c:
(gst_audio_quantize_setup_noise_shaping),
(gst_audio_quantize_free_noise_shaping),
(gst_audio_quantize_setup_dither),
(gst_audio_quantize_free_dither),
(gst_audio_quantize_setup_quantize_func),
(gst_audio_quantize_setup), (gst_audio_quantize_free):
* gst/audioconvert/gstaudioquantize.h:
Implement dithering and noise shaping in audioconvert. By default now
TPDF dithering (and no noise shaping) will be used when converting
from a higher bit depth to 20 bit depth or smaller, otherwise
everything will be as it is now.
For the last audioconvert in a pipeline it would make sense to
use some kind of noise shaping, enabling it by default for all
conversions would give undesired results though. Fixes #360246.
* tests/check/elements/audioconvert.c: (setup_audioconvert),
(GST_START_TEST):
Adjust unit test for the new audioconvert.
2007-06-28 20:37:58 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FIXME: When doing dithering with int as intermediate format
|
|
|
|
* one gets audible harmonics while the noise floor is
|
|
|
|
* constant for double as intermediate format!
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* TODO: - Maybe drop 5-pole noise shaping and use coefficients
|
|
|
|
* generated by dmaker
|
|
|
|
* http://shibatch.sf.net
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include "audioconvert.h"
|
|
|
|
#include "gstaudioquantize.h"
|
|
|
|
|
2008-07-23 18:34:19 +00:00
|
|
|
#include "gstfastrandom.h"
|
|
|
|
|
gst/audioconvert/: Implement dithering and noise shaping in audioconvert. By default now
Original commit message from CVS:
* gst/audioconvert/Makefile.am:
* gst/audioconvert/audioconvert.c: (audio_convert_get_func_index),
(check_default), (audio_convert_prepare_context),
(audio_convert_clean_context), (audio_convert_convert):
* gst/audioconvert/audioconvert.h:
* gst/audioconvert/gstaudioconvert.c:
(gst_audio_convert_dithering_get_type),
(gst_audio_convert_ns_get_type), (gst_audio_convert_class_init),
(gst_audio_convert_init), (gst_audio_convert_set_caps),
(gst_audio_convert_set_property), (gst_audio_convert_get_property):
* gst/audioconvert/gstaudioconvert.h:
* gst/audioconvert/gstaudioquantize.c:
(gst_audio_quantize_setup_noise_shaping),
(gst_audio_quantize_free_noise_shaping),
(gst_audio_quantize_setup_dither),
(gst_audio_quantize_free_dither),
(gst_audio_quantize_setup_quantize_func),
(gst_audio_quantize_setup), (gst_audio_quantize_free):
* gst/audioconvert/gstaudioquantize.h:
Implement dithering and noise shaping in audioconvert. By default now
TPDF dithering (and no noise shaping) will be used when converting
from a higher bit depth to 20 bit depth or smaller, otherwise
everything will be as it is now.
For the last audioconvert in a pipeline it would make sense to
use some kind of noise shaping, enabling it by default for all
conversions would give undesired results though. Fixes #360246.
* tests/check/elements/audioconvert.c: (setup_audioconvert),
(GST_START_TEST):
Adjust unit test for the new audioconvert.
2007-06-28 20:37:58 +00:00
|
|
|
#define MAKE_QUANTIZE_FUNC_NAME(name) \
|
|
|
|
gst_audio_quantize_quantize_##name
|
|
|
|
|
|
|
|
/* Quantize functions for gint32 as intermediate format */
|
|
|
|
|
|
|
|
#define MAKE_QUANTIZE_FUNC_I(name, DITHER_INIT_FUNC, ADD_DITHER_FUNC, \
|
|
|
|
ROUND_FUNC) \
|
|
|
|
static void \
|
|
|
|
MAKE_QUANTIZE_FUNC_NAME (name) (AudioConvertCtx *ctx, gint32 *src, \
|
|
|
|
gint32 *dst, gint count) \
|
|
|
|
{ \
|
|
|
|
gint scale = ctx->out_scale; \
|
|
|
|
gint channels = ctx->out.channels; \
|
|
|
|
gint chan_pos; \
|
|
|
|
\
|
|
|
|
if (scale > 0) { \
|
|
|
|
gint32 tmp; \
|
|
|
|
guint32 mask = 0xffffffff & (0xffffffff << scale); \
|
|
|
|
guint32 bias = 1U << (scale - 1); \
|
2007-08-03 19:40:14 +00:00
|
|
|
DITHER_INIT_FUNC() \
|
gst/audioconvert/: Implement dithering and noise shaping in audioconvert. By default now
Original commit message from CVS:
* gst/audioconvert/Makefile.am:
* gst/audioconvert/audioconvert.c: (audio_convert_get_func_index),
(check_default), (audio_convert_prepare_context),
(audio_convert_clean_context), (audio_convert_convert):
* gst/audioconvert/audioconvert.h:
* gst/audioconvert/gstaudioconvert.c:
(gst_audio_convert_dithering_get_type),
(gst_audio_convert_ns_get_type), (gst_audio_convert_class_init),
(gst_audio_convert_init), (gst_audio_convert_set_caps),
(gst_audio_convert_set_property), (gst_audio_convert_get_property):
* gst/audioconvert/gstaudioconvert.h:
* gst/audioconvert/gstaudioquantize.c:
(gst_audio_quantize_setup_noise_shaping),
(gst_audio_quantize_free_noise_shaping),
(gst_audio_quantize_setup_dither),
(gst_audio_quantize_free_dither),
(gst_audio_quantize_setup_quantize_func),
(gst_audio_quantize_setup), (gst_audio_quantize_free):
* gst/audioconvert/gstaudioquantize.h:
Implement dithering and noise shaping in audioconvert. By default now
TPDF dithering (and no noise shaping) will be used when converting
from a higher bit depth to 20 bit depth or smaller, otherwise
everything will be as it is now.
For the last audioconvert in a pipeline it would make sense to
use some kind of noise shaping, enabling it by default for all
conversions would give undesired results though. Fixes #360246.
* tests/check/elements/audioconvert.c: (setup_audioconvert),
(GST_START_TEST):
Adjust unit test for the new audioconvert.
2007-06-28 20:37:58 +00:00
|
|
|
\
|
|
|
|
for (;count;count--) { \
|
|
|
|
for (chan_pos = 0; chan_pos < channels; chan_pos++) { \
|
|
|
|
tmp = *src++; \
|
2007-08-03 19:40:14 +00:00
|
|
|
ADD_DITHER_FUNC() \
|
|
|
|
ROUND_FUNC() \
|
gst/audioconvert/: Implement dithering and noise shaping in audioconvert. By default now
Original commit message from CVS:
* gst/audioconvert/Makefile.am:
* gst/audioconvert/audioconvert.c: (audio_convert_get_func_index),
(check_default), (audio_convert_prepare_context),
(audio_convert_clean_context), (audio_convert_convert):
* gst/audioconvert/audioconvert.h:
* gst/audioconvert/gstaudioconvert.c:
(gst_audio_convert_dithering_get_type),
(gst_audio_convert_ns_get_type), (gst_audio_convert_class_init),
(gst_audio_convert_init), (gst_audio_convert_set_caps),
(gst_audio_convert_set_property), (gst_audio_convert_get_property):
* gst/audioconvert/gstaudioconvert.h:
* gst/audioconvert/gstaudioquantize.c:
(gst_audio_quantize_setup_noise_shaping),
(gst_audio_quantize_free_noise_shaping),
(gst_audio_quantize_setup_dither),
(gst_audio_quantize_free_dither),
(gst_audio_quantize_setup_quantize_func),
(gst_audio_quantize_setup), (gst_audio_quantize_free):
* gst/audioconvert/gstaudioquantize.h:
Implement dithering and noise shaping in audioconvert. By default now
TPDF dithering (and no noise shaping) will be used when converting
from a higher bit depth to 20 bit depth or smaller, otherwise
everything will be as it is now.
For the last audioconvert in a pipeline it would make sense to
use some kind of noise shaping, enabling it by default for all
conversions would give undesired results though. Fixes #360246.
* tests/check/elements/audioconvert.c: (setup_audioconvert),
(GST_START_TEST):
Adjust unit test for the new audioconvert.
2007-06-28 20:37:58 +00:00
|
|
|
*dst = tmp & mask; \
|
|
|
|
dst++; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} else { \
|
|
|
|
for (;count;count--) { \
|
|
|
|
for (chan_pos = 0; chan_pos < channels; chan_pos++) { \
|
|
|
|
*dst = *src++; \
|
|
|
|
dst++; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Quantize functions for gdouble as intermediate format with
|
|
|
|
* int as target */
|
|
|
|
|
|
|
|
#define MAKE_QUANTIZE_FUNC_F(name, DITHER_INIT_FUNC, NS_INIT_FUNC, \
|
|
|
|
ADD_NS_FUNC, ADD_DITHER_FUNC, \
|
|
|
|
UPDATE_ERROR_FUNC) \
|
|
|
|
static void \
|
|
|
|
MAKE_QUANTIZE_FUNC_NAME (name) (AudioConvertCtx *ctx, gdouble *src, \
|
|
|
|
gdouble *dst, gint count) \
|
|
|
|
{ \
|
|
|
|
gint scale = ctx->out_scale; \
|
|
|
|
gint channels = ctx->out.channels; \
|
|
|
|
gint chan_pos; \
|
|
|
|
gdouble factor = (1U<<(32-scale-1)) - 1; \
|
|
|
|
\
|
|
|
|
if (scale > 0) { \
|
|
|
|
gdouble tmp; \
|
2007-08-03 19:40:14 +00:00
|
|
|
DITHER_INIT_FUNC() \
|
|
|
|
NS_INIT_FUNC() \
|
gst/audioconvert/: Implement dithering and noise shaping in audioconvert. By default now
Original commit message from CVS:
* gst/audioconvert/Makefile.am:
* gst/audioconvert/audioconvert.c: (audio_convert_get_func_index),
(check_default), (audio_convert_prepare_context),
(audio_convert_clean_context), (audio_convert_convert):
* gst/audioconvert/audioconvert.h:
* gst/audioconvert/gstaudioconvert.c:
(gst_audio_convert_dithering_get_type),
(gst_audio_convert_ns_get_type), (gst_audio_convert_class_init),
(gst_audio_convert_init), (gst_audio_convert_set_caps),
(gst_audio_convert_set_property), (gst_audio_convert_get_property):
* gst/audioconvert/gstaudioconvert.h:
* gst/audioconvert/gstaudioquantize.c:
(gst_audio_quantize_setup_noise_shaping),
(gst_audio_quantize_free_noise_shaping),
(gst_audio_quantize_setup_dither),
(gst_audio_quantize_free_dither),
(gst_audio_quantize_setup_quantize_func),
(gst_audio_quantize_setup), (gst_audio_quantize_free):
* gst/audioconvert/gstaudioquantize.h:
Implement dithering and noise shaping in audioconvert. By default now
TPDF dithering (and no noise shaping) will be used when converting
from a higher bit depth to 20 bit depth or smaller, otherwise
everything will be as it is now.
For the last audioconvert in a pipeline it would make sense to
use some kind of noise shaping, enabling it by default for all
conversions would give undesired results though. Fixes #360246.
* tests/check/elements/audioconvert.c: (setup_audioconvert),
(GST_START_TEST):
Adjust unit test for the new audioconvert.
2007-06-28 20:37:58 +00:00
|
|
|
\
|
|
|
|
for (;count;count--) { \
|
|
|
|
for (chan_pos = 0; chan_pos < channels; chan_pos++) { \
|
|
|
|
tmp = *src++; \
|
2007-08-03 19:40:14 +00:00
|
|
|
ADD_NS_FUNC() \
|
|
|
|
ADD_DITHER_FUNC() \
|
gst/audioconvert/: Implement dithering and noise shaping in audioconvert. By default now
Original commit message from CVS:
* gst/audioconvert/Makefile.am:
* gst/audioconvert/audioconvert.c: (audio_convert_get_func_index),
(check_default), (audio_convert_prepare_context),
(audio_convert_clean_context), (audio_convert_convert):
* gst/audioconvert/audioconvert.h:
* gst/audioconvert/gstaudioconvert.c:
(gst_audio_convert_dithering_get_type),
(gst_audio_convert_ns_get_type), (gst_audio_convert_class_init),
(gst_audio_convert_init), (gst_audio_convert_set_caps),
(gst_audio_convert_set_property), (gst_audio_convert_get_property):
* gst/audioconvert/gstaudioconvert.h:
* gst/audioconvert/gstaudioquantize.c:
(gst_audio_quantize_setup_noise_shaping),
(gst_audio_quantize_free_noise_shaping),
(gst_audio_quantize_setup_dither),
(gst_audio_quantize_free_dither),
(gst_audio_quantize_setup_quantize_func),
(gst_audio_quantize_setup), (gst_audio_quantize_free):
* gst/audioconvert/gstaudioquantize.h:
Implement dithering and noise shaping in audioconvert. By default now
TPDF dithering (and no noise shaping) will be used when converting
from a higher bit depth to 20 bit depth or smaller, otherwise
everything will be as it is now.
For the last audioconvert in a pipeline it would make sense to
use some kind of noise shaping, enabling it by default for all
conversions would give undesired results though. Fixes #360246.
* tests/check/elements/audioconvert.c: (setup_audioconvert),
(GST_START_TEST):
Adjust unit test for the new audioconvert.
2007-06-28 20:37:58 +00:00
|
|
|
tmp = floor(tmp * factor + 0.5); \
|
|
|
|
*dst = CLAMP (tmp, -factor - 1, factor); \
|
2007-08-03 19:40:14 +00:00
|
|
|
UPDATE_ERROR_FUNC() \
|
gst/audioconvert/: Implement dithering and noise shaping in audioconvert. By default now
Original commit message from CVS:
* gst/audioconvert/Makefile.am:
* gst/audioconvert/audioconvert.c: (audio_convert_get_func_index),
(check_default), (audio_convert_prepare_context),
(audio_convert_clean_context), (audio_convert_convert):
* gst/audioconvert/audioconvert.h:
* gst/audioconvert/gstaudioconvert.c:
(gst_audio_convert_dithering_get_type),
(gst_audio_convert_ns_get_type), (gst_audio_convert_class_init),
(gst_audio_convert_init), (gst_audio_convert_set_caps),
(gst_audio_convert_set_property), (gst_audio_convert_get_property):
* gst/audioconvert/gstaudioconvert.h:
* gst/audioconvert/gstaudioquantize.c:
(gst_audio_quantize_setup_noise_shaping),
(gst_audio_quantize_free_noise_shaping),
(gst_audio_quantize_setup_dither),
(gst_audio_quantize_free_dither),
(gst_audio_quantize_setup_quantize_func),
(gst_audio_quantize_setup), (gst_audio_quantize_free):
* gst/audioconvert/gstaudioquantize.h:
Implement dithering and noise shaping in audioconvert. By default now
TPDF dithering (and no noise shaping) will be used when converting
from a higher bit depth to 20 bit depth or smaller, otherwise
everything will be as it is now.
For the last audioconvert in a pipeline it would make sense to
use some kind of noise shaping, enabling it by default for all
conversions would give undesired results though. Fixes #360246.
* tests/check/elements/audioconvert.c: (setup_audioconvert),
(GST_START_TEST):
Adjust unit test for the new audioconvert.
2007-06-28 20:37:58 +00:00
|
|
|
dst++; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} else { \
|
|
|
|
for (;count;count--) { \
|
|
|
|
for (chan_pos = 0; chan_pos < channels; chan_pos++) { \
|
|
|
|
*dst = *src++ * 2147483647.0; \
|
|
|
|
dst++; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Rounding functions for int as intermediate format, only used when
|
|
|
|
* not using dithering. With dithering we include this offset in our
|
|
|
|
* dither noise instead. */
|
|
|
|
|
|
|
|
#define ROUND() \
|
|
|
|
if (tmp > 0 && G_MAXINT32 - tmp <= bias) \
|
|
|
|
tmp = G_MAXINT32; \
|
|
|
|
else \
|
|
|
|
tmp += bias;
|
|
|
|
|
|
|
|
|
|
|
|
#define NONE_FUNC()
|
|
|
|
|
|
|
|
/* Dithering definitions
|
|
|
|
* See http://en.wikipedia.org/wiki/Dithering or
|
audioconvert: Avoid int division in quantization
Since range size is always 2^n, we can simply use modulo (implemented
with a bitmask).
The previous implementation used 64-bit integer division, which is
done in software on ARMv7. Although the divisor was constant, the
division could not be transformed into "multiplication by magic number"
since the dividend was 64-bit.
The now-unused and not-so-fast gst_fast_random_(u)int32_range functions
were removed.
Also, implementing bug fixes:
1) ADD_DITHER_TPDF_HF_I no longer discards bias.
2) We change TPDF's noise range to be the same as RPDF's. Previously,
RPDF's noise ranged:
{ bias - dither, bias + dither }
while TPDF's noise ranged:
{ bias/2 - dither/2, bias/2 + dither/2 - 1 } +
{ bias/2 - dither/2, bias/2 + dither/2 - 1 } =
{ bias - dither, bias + dither - 2 }
Now, both range:
{ bias - dither, bias + dither - 1 }
https://bugzilla.gnome.org/show_bug.cgi?id=746661
2015-03-24 01:01:22 +00:00
|
|
|
* http://www.users.qwest.net/~volt42/cadenzarecording/DitherExplained.pdf for explainations.
|
gst/audioconvert/: Implement dithering and noise shaping in audioconvert. By default now
Original commit message from CVS:
* gst/audioconvert/Makefile.am:
* gst/audioconvert/audioconvert.c: (audio_convert_get_func_index),
(check_default), (audio_convert_prepare_context),
(audio_convert_clean_context), (audio_convert_convert):
* gst/audioconvert/audioconvert.h:
* gst/audioconvert/gstaudioconvert.c:
(gst_audio_convert_dithering_get_type),
(gst_audio_convert_ns_get_type), (gst_audio_convert_class_init),
(gst_audio_convert_init), (gst_audio_convert_set_caps),
(gst_audio_convert_set_property), (gst_audio_convert_get_property):
* gst/audioconvert/gstaudioconvert.h:
* gst/audioconvert/gstaudioquantize.c:
(gst_audio_quantize_setup_noise_shaping),
(gst_audio_quantize_free_noise_shaping),
(gst_audio_quantize_setup_dither),
(gst_audio_quantize_free_dither),
(gst_audio_quantize_setup_quantize_func),
(gst_audio_quantize_setup), (gst_audio_quantize_free):
* gst/audioconvert/gstaudioquantize.h:
Implement dithering and noise shaping in audioconvert. By default now
TPDF dithering (and no noise shaping) will be used when converting
from a higher bit depth to 20 bit depth or smaller, otherwise
everything will be as it is now.
For the last audioconvert in a pipeline it would make sense to
use some kind of noise shaping, enabling it by default for all
conversions would give undesired results though. Fixes #360246.
* tests/check/elements/audioconvert.c: (setup_audioconvert),
(GST_START_TEST):
Adjust unit test for the new audioconvert.
2007-06-28 20:37:58 +00:00
|
|
|
*
|
|
|
|
* We already add the rounding offset to the dither noise here
|
|
|
|
* to have only one overflow check instead of two. */
|
|
|
|
|
|
|
|
#define INIT_DITHER_RPDF_I() \
|
|
|
|
gint32 rand; \
|
|
|
|
gint32 dither = (1<<(scale));
|
|
|
|
|
audioconvert: Avoid int division in quantization
Since range size is always 2^n, we can simply use modulo (implemented
with a bitmask).
The previous implementation used 64-bit integer division, which is
done in software on ARMv7. Although the divisor was constant, the
division could not be transformed into "multiplication by magic number"
since the dividend was 64-bit.
The now-unused and not-so-fast gst_fast_random_(u)int32_range functions
were removed.
Also, implementing bug fixes:
1) ADD_DITHER_TPDF_HF_I no longer discards bias.
2) We change TPDF's noise range to be the same as RPDF's. Previously,
RPDF's noise ranged:
{ bias - dither, bias + dither }
while TPDF's noise ranged:
{ bias/2 - dither/2, bias/2 + dither/2 - 1 } +
{ bias/2 - dither/2, bias/2 + dither/2 - 1 } =
{ bias - dither, bias + dither - 2 }
Now, both range:
{ bias - dither, bias + dither - 1 }
https://bugzilla.gnome.org/show_bug.cgi?id=746661
2015-03-24 01:01:22 +00:00
|
|
|
/* Assuming dither == 2^n,
|
|
|
|
* returns one of 2^(n+1) possible random values:
|
|
|
|
* -dither <= retval < dither */
|
|
|
|
#define RANDOM_INT_DITHER(dither) \
|
|
|
|
(- dither + (gst_fast_random_int32 () & ((dither << 1) - 1)))
|
|
|
|
|
gst/audioconvert/: Implement dithering and noise shaping in audioconvert. By default now
Original commit message from CVS:
* gst/audioconvert/Makefile.am:
* gst/audioconvert/audioconvert.c: (audio_convert_get_func_index),
(check_default), (audio_convert_prepare_context),
(audio_convert_clean_context), (audio_convert_convert):
* gst/audioconvert/audioconvert.h:
* gst/audioconvert/gstaudioconvert.c:
(gst_audio_convert_dithering_get_type),
(gst_audio_convert_ns_get_type), (gst_audio_convert_class_init),
(gst_audio_convert_init), (gst_audio_convert_set_caps),
(gst_audio_convert_set_property), (gst_audio_convert_get_property):
* gst/audioconvert/gstaudioconvert.h:
* gst/audioconvert/gstaudioquantize.c:
(gst_audio_quantize_setup_noise_shaping),
(gst_audio_quantize_free_noise_shaping),
(gst_audio_quantize_setup_dither),
(gst_audio_quantize_free_dither),
(gst_audio_quantize_setup_quantize_func),
(gst_audio_quantize_setup), (gst_audio_quantize_free):
* gst/audioconvert/gstaudioquantize.h:
Implement dithering and noise shaping in audioconvert. By default now
TPDF dithering (and no noise shaping) will be used when converting
from a higher bit depth to 20 bit depth or smaller, otherwise
everything will be as it is now.
For the last audioconvert in a pipeline it would make sense to
use some kind of noise shaping, enabling it by default for all
conversions would give undesired results though. Fixes #360246.
* tests/check/elements/audioconvert.c: (setup_audioconvert),
(GST_START_TEST):
Adjust unit test for the new audioconvert.
2007-06-28 20:37:58 +00:00
|
|
|
#define ADD_DITHER_RPDF_I() \
|
audioconvert: Avoid int division in quantization
Since range size is always 2^n, we can simply use modulo (implemented
with a bitmask).
The previous implementation used 64-bit integer division, which is
done in software on ARMv7. Although the divisor was constant, the
division could not be transformed into "multiplication by magic number"
since the dividend was 64-bit.
The now-unused and not-so-fast gst_fast_random_(u)int32_range functions
were removed.
Also, implementing bug fixes:
1) ADD_DITHER_TPDF_HF_I no longer discards bias.
2) We change TPDF's noise range to be the same as RPDF's. Previously,
RPDF's noise ranged:
{ bias - dither, bias + dither }
while TPDF's noise ranged:
{ bias/2 - dither/2, bias/2 + dither/2 - 1 } +
{ bias/2 - dither/2, bias/2 + dither/2 - 1 } =
{ bias - dither, bias + dither - 2 }
Now, both range:
{ bias - dither, bias + dither - 1 }
https://bugzilla.gnome.org/show_bug.cgi?id=746661
2015-03-24 01:01:22 +00:00
|
|
|
rand = bias + RANDOM_INT_DITHER(dither); \
|
gst/audioconvert/: Implement dithering and noise shaping in audioconvert. By default now
Original commit message from CVS:
* gst/audioconvert/Makefile.am:
* gst/audioconvert/audioconvert.c: (audio_convert_get_func_index),
(check_default), (audio_convert_prepare_context),
(audio_convert_clean_context), (audio_convert_convert):
* gst/audioconvert/audioconvert.h:
* gst/audioconvert/gstaudioconvert.c:
(gst_audio_convert_dithering_get_type),
(gst_audio_convert_ns_get_type), (gst_audio_convert_class_init),
(gst_audio_convert_init), (gst_audio_convert_set_caps),
(gst_audio_convert_set_property), (gst_audio_convert_get_property):
* gst/audioconvert/gstaudioconvert.h:
* gst/audioconvert/gstaudioquantize.c:
(gst_audio_quantize_setup_noise_shaping),
(gst_audio_quantize_free_noise_shaping),
(gst_audio_quantize_setup_dither),
(gst_audio_quantize_free_dither),
(gst_audio_quantize_setup_quantize_func),
(gst_audio_quantize_setup), (gst_audio_quantize_free):
* gst/audioconvert/gstaudioquantize.h:
Implement dithering and noise shaping in audioconvert. By default now
TPDF dithering (and no noise shaping) will be used when converting
from a higher bit depth to 20 bit depth or smaller, otherwise
everything will be as it is now.
For the last audioconvert in a pipeline it would make sense to
use some kind of noise shaping, enabling it by default for all
conversions would give undesired results though. Fixes #360246.
* tests/check/elements/audioconvert.c: (setup_audioconvert),
(GST_START_TEST):
Adjust unit test for the new audioconvert.
2007-06-28 20:37:58 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
#define INIT_DITHER_RPDF_F() \
|
|
|
|
gdouble dither = 1.0/(1U<<(32 - scale - 1));
|
|
|
|
|
|
|
|
#define ADD_DITHER_RPDF_F() \
|
2008-07-23 18:34:19 +00:00
|
|
|
tmp += gst_fast_random_double_range (- dither, dither);
|
gst/audioconvert/: Implement dithering and noise shaping in audioconvert. By default now
Original commit message from CVS:
* gst/audioconvert/Makefile.am:
* gst/audioconvert/audioconvert.c: (audio_convert_get_func_index),
(check_default), (audio_convert_prepare_context),
(audio_convert_clean_context), (audio_convert_convert):
* gst/audioconvert/audioconvert.h:
* gst/audioconvert/gstaudioconvert.c:
(gst_audio_convert_dithering_get_type),
(gst_audio_convert_ns_get_type), (gst_audio_convert_class_init),
(gst_audio_convert_init), (gst_audio_convert_set_caps),
(gst_audio_convert_set_property), (gst_audio_convert_get_property):
* gst/audioconvert/gstaudioconvert.h:
* gst/audioconvert/gstaudioquantize.c:
(gst_audio_quantize_setup_noise_shaping),
(gst_audio_quantize_free_noise_shaping),
(gst_audio_quantize_setup_dither),
(gst_audio_quantize_free_dither),
(gst_audio_quantize_setup_quantize_func),
(gst_audio_quantize_setup), (gst_audio_quantize_free):
* gst/audioconvert/gstaudioquantize.h:
Implement dithering and noise shaping in audioconvert. By default now
TPDF dithering (and no noise shaping) will be used when converting
from a higher bit depth to 20 bit depth or smaller, otherwise
everything will be as it is now.
For the last audioconvert in a pipeline it would make sense to
use some kind of noise shaping, enabling it by default for all
conversions would give undesired results though. Fixes #360246.
* tests/check/elements/audioconvert.c: (setup_audioconvert),
(GST_START_TEST):
Adjust unit test for the new audioconvert.
2007-06-28 20:37:58 +00:00
|
|
|
|
|
|
|
#define INIT_DITHER_TPDF_I() \
|
|
|
|
gint32 rand; \
|
audioconvert: Avoid int division in quantization
Since range size is always 2^n, we can simply use modulo (implemented
with a bitmask).
The previous implementation used 64-bit integer division, which is
done in software on ARMv7. Although the divisor was constant, the
division could not be transformed into "multiplication by magic number"
since the dividend was 64-bit.
The now-unused and not-so-fast gst_fast_random_(u)int32_range functions
were removed.
Also, implementing bug fixes:
1) ADD_DITHER_TPDF_HF_I no longer discards bias.
2) We change TPDF's noise range to be the same as RPDF's. Previously,
RPDF's noise ranged:
{ bias - dither, bias + dither }
while TPDF's noise ranged:
{ bias/2 - dither/2, bias/2 + dither/2 - 1 } +
{ bias/2 - dither/2, bias/2 + dither/2 - 1 } =
{ bias - dither, bias + dither - 2 }
Now, both range:
{ bias - dither, bias + dither - 1 }
https://bugzilla.gnome.org/show_bug.cgi?id=746661
2015-03-24 01:01:22 +00:00
|
|
|
gint32 dither = (1<<(scale - 1));
|
gst/audioconvert/: Implement dithering and noise shaping in audioconvert. By default now
Original commit message from CVS:
* gst/audioconvert/Makefile.am:
* gst/audioconvert/audioconvert.c: (audio_convert_get_func_index),
(check_default), (audio_convert_prepare_context),
(audio_convert_clean_context), (audio_convert_convert):
* gst/audioconvert/audioconvert.h:
* gst/audioconvert/gstaudioconvert.c:
(gst_audio_convert_dithering_get_type),
(gst_audio_convert_ns_get_type), (gst_audio_convert_class_init),
(gst_audio_convert_init), (gst_audio_convert_set_caps),
(gst_audio_convert_set_property), (gst_audio_convert_get_property):
* gst/audioconvert/gstaudioconvert.h:
* gst/audioconvert/gstaudioquantize.c:
(gst_audio_quantize_setup_noise_shaping),
(gst_audio_quantize_free_noise_shaping),
(gst_audio_quantize_setup_dither),
(gst_audio_quantize_free_dither),
(gst_audio_quantize_setup_quantize_func),
(gst_audio_quantize_setup), (gst_audio_quantize_free):
* gst/audioconvert/gstaudioquantize.h:
Implement dithering and noise shaping in audioconvert. By default now
TPDF dithering (and no noise shaping) will be used when converting
from a higher bit depth to 20 bit depth or smaller, otherwise
everything will be as it is now.
For the last audioconvert in a pipeline it would make sense to
use some kind of noise shaping, enabling it by default for all
conversions would give undesired results though. Fixes #360246.
* tests/check/elements/audioconvert.c: (setup_audioconvert),
(GST_START_TEST):
Adjust unit test for the new audioconvert.
2007-06-28 20:37:58 +00:00
|
|
|
|
|
|
|
#define ADD_DITHER_TPDF_I() \
|
audioconvert: Avoid int division in quantization
Since range size is always 2^n, we can simply use modulo (implemented
with a bitmask).
The previous implementation used 64-bit integer division, which is
done in software on ARMv7. Although the divisor was constant, the
division could not be transformed into "multiplication by magic number"
since the dividend was 64-bit.
The now-unused and not-so-fast gst_fast_random_(u)int32_range functions
were removed.
Also, implementing bug fixes:
1) ADD_DITHER_TPDF_HF_I no longer discards bias.
2) We change TPDF's noise range to be the same as RPDF's. Previously,
RPDF's noise ranged:
{ bias - dither, bias + dither }
while TPDF's noise ranged:
{ bias/2 - dither/2, bias/2 + dither/2 - 1 } +
{ bias/2 - dither/2, bias/2 + dither/2 - 1 } =
{ bias - dither, bias + dither - 2 }
Now, both range:
{ bias - dither, bias + dither - 1 }
https://bugzilla.gnome.org/show_bug.cgi?id=746661
2015-03-24 01:01:22 +00:00
|
|
|
rand = bias + RANDOM_INT_DITHER(dither) \
|
|
|
|
+ RANDOM_INT_DITHER(dither); \
|
gst/audioconvert/: Implement dithering and noise shaping in audioconvert. By default now
Original commit message from CVS:
* gst/audioconvert/Makefile.am:
* gst/audioconvert/audioconvert.c: (audio_convert_get_func_index),
(check_default), (audio_convert_prepare_context),
(audio_convert_clean_context), (audio_convert_convert):
* gst/audioconvert/audioconvert.h:
* gst/audioconvert/gstaudioconvert.c:
(gst_audio_convert_dithering_get_type),
(gst_audio_convert_ns_get_type), (gst_audio_convert_class_init),
(gst_audio_convert_init), (gst_audio_convert_set_caps),
(gst_audio_convert_set_property), (gst_audio_convert_get_property):
* gst/audioconvert/gstaudioconvert.h:
* gst/audioconvert/gstaudioquantize.c:
(gst_audio_quantize_setup_noise_shaping),
(gst_audio_quantize_free_noise_shaping),
(gst_audio_quantize_setup_dither),
(gst_audio_quantize_free_dither),
(gst_audio_quantize_setup_quantize_func),
(gst_audio_quantize_setup), (gst_audio_quantize_free):
* gst/audioconvert/gstaudioquantize.h:
Implement dithering and noise shaping in audioconvert. By default now
TPDF dithering (and no noise shaping) will be used when converting
from a higher bit depth to 20 bit depth or smaller, otherwise
everything will be as it is now.
For the last audioconvert in a pipeline it would make sense to
use some kind of noise shaping, enabling it by default for all
conversions would give undesired results though. Fixes #360246.
* tests/check/elements/audioconvert.c: (setup_audioconvert),
(GST_START_TEST):
Adjust unit test for the new audioconvert.
2007-06-28 20:37:58 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
#define INIT_DITHER_TPDF_F() \
|
|
|
|
gdouble dither = 1.0/(1U<<(32 - scale));
|
|
|
|
|
|
|
|
#define ADD_DITHER_TPDF_F() \
|
2008-07-23 18:34:19 +00:00
|
|
|
tmp += gst_fast_random_double_range (- dither, dither) \
|
|
|
|
+ gst_fast_random_double_range (- dither, dither);
|
gst/audioconvert/: Implement dithering and noise shaping in audioconvert. By default now
Original commit message from CVS:
* gst/audioconvert/Makefile.am:
* gst/audioconvert/audioconvert.c: (audio_convert_get_func_index),
(check_default), (audio_convert_prepare_context),
(audio_convert_clean_context), (audio_convert_convert):
* gst/audioconvert/audioconvert.h:
* gst/audioconvert/gstaudioconvert.c:
(gst_audio_convert_dithering_get_type),
(gst_audio_convert_ns_get_type), (gst_audio_convert_class_init),
(gst_audio_convert_init), (gst_audio_convert_set_caps),
(gst_audio_convert_set_property), (gst_audio_convert_get_property):
* gst/audioconvert/gstaudioconvert.h:
* gst/audioconvert/gstaudioquantize.c:
(gst_audio_quantize_setup_noise_shaping),
(gst_audio_quantize_free_noise_shaping),
(gst_audio_quantize_setup_dither),
(gst_audio_quantize_free_dither),
(gst_audio_quantize_setup_quantize_func),
(gst_audio_quantize_setup), (gst_audio_quantize_free):
* gst/audioconvert/gstaudioquantize.h:
Implement dithering and noise shaping in audioconvert. By default now
TPDF dithering (and no noise shaping) will be used when converting
from a higher bit depth to 20 bit depth or smaller, otherwise
everything will be as it is now.
For the last audioconvert in a pipeline it would make sense to
use some kind of noise shaping, enabling it by default for all
conversions would give undesired results though. Fixes #360246.
* tests/check/elements/audioconvert.c: (setup_audioconvert),
(GST_START_TEST):
Adjust unit test for the new audioconvert.
2007-06-28 20:37:58 +00:00
|
|
|
|
|
|
|
#define INIT_DITHER_TPDF_HF_I() \
|
|
|
|
gint32 rand; \
|
|
|
|
gint32 dither = (1<<(scale-1)); \
|
audioconvert: Avoid int division in quantization
Since range size is always 2^n, we can simply use modulo (implemented
with a bitmask).
The previous implementation used 64-bit integer division, which is
done in software on ARMv7. Although the divisor was constant, the
division could not be transformed into "multiplication by magic number"
since the dividend was 64-bit.
The now-unused and not-so-fast gst_fast_random_(u)int32_range functions
were removed.
Also, implementing bug fixes:
1) ADD_DITHER_TPDF_HF_I no longer discards bias.
2) We change TPDF's noise range to be the same as RPDF's. Previously,
RPDF's noise ranged:
{ bias - dither, bias + dither }
while TPDF's noise ranged:
{ bias/2 - dither/2, bias/2 + dither/2 - 1 } +
{ bias/2 - dither/2, bias/2 + dither/2 - 1 } =
{ bias - dither, bias + dither - 2 }
Now, both range:
{ bias - dither, bias + dither - 1 }
https://bugzilla.gnome.org/show_bug.cgi?id=746661
2015-03-24 01:01:22 +00:00
|
|
|
gint32 *last_random = (gint32 *) ctx->last_random, tmp_rand;
|
gst/audioconvert/: Implement dithering and noise shaping in audioconvert. By default now
Original commit message from CVS:
* gst/audioconvert/Makefile.am:
* gst/audioconvert/audioconvert.c: (audio_convert_get_func_index),
(check_default), (audio_convert_prepare_context),
(audio_convert_clean_context), (audio_convert_convert):
* gst/audioconvert/audioconvert.h:
* gst/audioconvert/gstaudioconvert.c:
(gst_audio_convert_dithering_get_type),
(gst_audio_convert_ns_get_type), (gst_audio_convert_class_init),
(gst_audio_convert_init), (gst_audio_convert_set_caps),
(gst_audio_convert_set_property), (gst_audio_convert_get_property):
* gst/audioconvert/gstaudioconvert.h:
* gst/audioconvert/gstaudioquantize.c:
(gst_audio_quantize_setup_noise_shaping),
(gst_audio_quantize_free_noise_shaping),
(gst_audio_quantize_setup_dither),
(gst_audio_quantize_free_dither),
(gst_audio_quantize_setup_quantize_func),
(gst_audio_quantize_setup), (gst_audio_quantize_free):
* gst/audioconvert/gstaudioquantize.h:
Implement dithering and noise shaping in audioconvert. By default now
TPDF dithering (and no noise shaping) will be used when converting
from a higher bit depth to 20 bit depth or smaller, otherwise
everything will be as it is now.
For the last audioconvert in a pipeline it would make sense to
use some kind of noise shaping, enabling it by default for all
conversions would give undesired results though. Fixes #360246.
* tests/check/elements/audioconvert.c: (setup_audioconvert),
(GST_START_TEST):
Adjust unit test for the new audioconvert.
2007-06-28 20:37:58 +00:00
|
|
|
|
|
|
|
#define ADD_DITHER_TPDF_HF_I() \
|
audioconvert: Avoid int division in quantization
Since range size is always 2^n, we can simply use modulo (implemented
with a bitmask).
The previous implementation used 64-bit integer division, which is
done in software on ARMv7. Although the divisor was constant, the
division could not be transformed into "multiplication by magic number"
since the dividend was 64-bit.
The now-unused and not-so-fast gst_fast_random_(u)int32_range functions
were removed.
Also, implementing bug fixes:
1) ADD_DITHER_TPDF_HF_I no longer discards bias.
2) We change TPDF's noise range to be the same as RPDF's. Previously,
RPDF's noise ranged:
{ bias - dither, bias + dither }
while TPDF's noise ranged:
{ bias/2 - dither/2, bias/2 + dither/2 - 1 } +
{ bias/2 - dither/2, bias/2 + dither/2 - 1 } =
{ bias - dither, bias + dither - 2 }
Now, both range:
{ bias - dither, bias + dither - 1 }
https://bugzilla.gnome.org/show_bug.cgi?id=746661
2015-03-24 01:01:22 +00:00
|
|
|
tmp_rand = RANDOM_INT_DITHER(dither); \
|
|
|
|
rand = bias + tmp_rand - last_random[chan_pos]; \
|
gst/audioconvert/: Implement dithering and noise shaping in audioconvert. By default now
Original commit message from CVS:
* gst/audioconvert/Makefile.am:
* gst/audioconvert/audioconvert.c: (audio_convert_get_func_index),
(check_default), (audio_convert_prepare_context),
(audio_convert_clean_context), (audio_convert_convert):
* gst/audioconvert/audioconvert.h:
* gst/audioconvert/gstaudioconvert.c:
(gst_audio_convert_dithering_get_type),
(gst_audio_convert_ns_get_type), (gst_audio_convert_class_init),
(gst_audio_convert_init), (gst_audio_convert_set_caps),
(gst_audio_convert_set_property), (gst_audio_convert_get_property):
* gst/audioconvert/gstaudioconvert.h:
* gst/audioconvert/gstaudioquantize.c:
(gst_audio_quantize_setup_noise_shaping),
(gst_audio_quantize_free_noise_shaping),
(gst_audio_quantize_setup_dither),
(gst_audio_quantize_free_dither),
(gst_audio_quantize_setup_quantize_func),
(gst_audio_quantize_setup), (gst_audio_quantize_free):
* gst/audioconvert/gstaudioquantize.h:
Implement dithering and noise shaping in audioconvert. By default now
TPDF dithering (and no noise shaping) will be used when converting
from a higher bit depth to 20 bit depth or smaller, otherwise
everything will be as it is now.
For the last audioconvert in a pipeline it would make sense to
use some kind of noise shaping, enabling it by default for all
conversions would give undesired results though. Fixes #360246.
* tests/check/elements/audioconvert.c: (setup_audioconvert),
(GST_START_TEST):
Adjust unit test for the new audioconvert.
2007-06-28 20:37:58 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
/* Like TPDF dither but the dither noise is oriented more to the
|
|
|
|
* higher frequencies */
|
|
|
|
|
|
|
|
#define INIT_DITHER_TPDF_HF_F() \
|
|
|
|
gdouble rand; \
|
|
|
|
gdouble dither = 1.0/(1U<<(32 - scale)); \
|
|
|
|
gdouble *last_random = (gdouble *) ctx->last_random, tmp_rand;
|
|
|
|
|
|
|
|
#define ADD_DITHER_TPDF_HF_F() \
|
2008-07-23 18:34:19 +00:00
|
|
|
tmp_rand = gst_fast_random_double_range (- dither, dither); \
|
gst/audioconvert/: Implement dithering and noise shaping in audioconvert. By default now
Original commit message from CVS:
* gst/audioconvert/Makefile.am:
* gst/audioconvert/audioconvert.c: (audio_convert_get_func_index),
(check_default), (audio_convert_prepare_context),
(audio_convert_clean_context), (audio_convert_convert):
* gst/audioconvert/audioconvert.h:
* gst/audioconvert/gstaudioconvert.c:
(gst_audio_convert_dithering_get_type),
(gst_audio_convert_ns_get_type), (gst_audio_convert_class_init),
(gst_audio_convert_init), (gst_audio_convert_set_caps),
(gst_audio_convert_set_property), (gst_audio_convert_get_property):
* gst/audioconvert/gstaudioconvert.h:
* gst/audioconvert/gstaudioquantize.c:
(gst_audio_quantize_setup_noise_shaping),
(gst_audio_quantize_free_noise_shaping),
(gst_audio_quantize_setup_dither),
(gst_audio_quantize_free_dither),
(gst_audio_quantize_setup_quantize_func),
(gst_audio_quantize_setup), (gst_audio_quantize_free):
* gst/audioconvert/gstaudioquantize.h:
Implement dithering and noise shaping in audioconvert. By default now
TPDF dithering (and no noise shaping) will be used when converting
from a higher bit depth to 20 bit depth or smaller, otherwise
everything will be as it is now.
For the last audioconvert in a pipeline it would make sense to
use some kind of noise shaping, enabling it by default for all
conversions would give undesired results though. Fixes #360246.
* tests/check/elements/audioconvert.c: (setup_audioconvert),
(GST_START_TEST):
Adjust unit test for the new audioconvert.
2007-06-28 20:37:58 +00:00
|
|
|
rand = tmp_rand - last_random[chan_pos]; \
|
|
|
|
last_random[chan_pos] = tmp_rand; \
|
|
|
|
tmp += rand;
|
|
|
|
|
|
|
|
/* Noise shaping definitions.
|
2007-08-03 19:40:14 +00:00
|
|
|
* See http://en.wikipedia.org/wiki/Noise_shaping for explanations. */
|
gst/audioconvert/: Implement dithering and noise shaping in audioconvert. By default now
Original commit message from CVS:
* gst/audioconvert/Makefile.am:
* gst/audioconvert/audioconvert.c: (audio_convert_get_func_index),
(check_default), (audio_convert_prepare_context),
(audio_convert_clean_context), (audio_convert_convert):
* gst/audioconvert/audioconvert.h:
* gst/audioconvert/gstaudioconvert.c:
(gst_audio_convert_dithering_get_type),
(gst_audio_convert_ns_get_type), (gst_audio_convert_class_init),
(gst_audio_convert_init), (gst_audio_convert_set_caps),
(gst_audio_convert_set_property), (gst_audio_convert_get_property):
* gst/audioconvert/gstaudioconvert.h:
* gst/audioconvert/gstaudioquantize.c:
(gst_audio_quantize_setup_noise_shaping),
(gst_audio_quantize_free_noise_shaping),
(gst_audio_quantize_setup_dither),
(gst_audio_quantize_free_dither),
(gst_audio_quantize_setup_quantize_func),
(gst_audio_quantize_setup), (gst_audio_quantize_free):
* gst/audioconvert/gstaudioquantize.h:
Implement dithering and noise shaping in audioconvert. By default now
TPDF dithering (and no noise shaping) will be used when converting
from a higher bit depth to 20 bit depth or smaller, otherwise
everything will be as it is now.
For the last audioconvert in a pipeline it would make sense to
use some kind of noise shaping, enabling it by default for all
conversions would give undesired results though. Fixes #360246.
* tests/check/elements/audioconvert.c: (setup_audioconvert),
(GST_START_TEST):
Adjust unit test for the new audioconvert.
2007-06-28 20:37:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Simple error feedback: Just accumulate the dithering and quantization
|
|
|
|
* error and remove it from each sample. */
|
|
|
|
|
|
|
|
#define INIT_NS_ERROR_FEEDBACK() \
|
|
|
|
gdouble orig; \
|
|
|
|
gdouble *errors = ctx->error_buf;
|
|
|
|
|
|
|
|
#define ADD_NS_ERROR_FEEDBACK() \
|
|
|
|
orig = tmp; \
|
|
|
|
tmp -= errors[chan_pos];
|
|
|
|
|
|
|
|
#define UPDATE_ERROR_ERROR_FEEDBACK() \
|
|
|
|
errors[chan_pos] += (*dst)/factor - orig;
|
|
|
|
|
|
|
|
/* Same as error feedback but also add 1/2 of the previous error value.
|
|
|
|
* This moves the noise a bit more into the higher frequencies. */
|
|
|
|
|
|
|
|
#define INIT_NS_SIMPLE() \
|
|
|
|
gdouble orig; \
|
|
|
|
gdouble *errors = ctx->error_buf, cur_error;
|
|
|
|
|
|
|
|
#define ADD_NS_SIMPLE() \
|
|
|
|
cur_error = errors[chan_pos*2] - 0.5 * errors[chan_pos*2 + 1]; \
|
|
|
|
tmp -= cur_error; \
|
|
|
|
orig = tmp;
|
|
|
|
|
|
|
|
#define UPDATE_ERROR_SIMPLE() \
|
|
|
|
errors[chan_pos*2 + 1] = errors[chan_pos*2]; \
|
|
|
|
errors[chan_pos*2] = (*dst)/factor - orig;
|
|
|
|
|
|
|
|
|
|
|
|
/* Noise shaping coefficients from[1], moves most power of the
|
|
|
|
* error noise into inaudible frequency ranges.
|
|
|
|
*
|
|
|
|
* [1]
|
|
|
|
* "Minimally Audible Noise Shaping", Stanley P. Lipshitz,
|
|
|
|
* John Vanderkooy, and Robert A. Wannamaker,
|
|
|
|
* J. Audio Eng. Soc., Vol. 39, No. 11, November 1991. */
|
|
|
|
|
|
|
|
static const gdouble ns_medium_coeffs[] = {
|
|
|
|
2.033, -2.165, 1.959, -1.590, 0.6149
|
|
|
|
};
|
|
|
|
|
|
|
|
#define INIT_NS_MEDIUM() \
|
|
|
|
gdouble orig; \
|
|
|
|
gdouble *errors = ctx->error_buf, cur_error; \
|
|
|
|
int j;
|
|
|
|
|
|
|
|
#define ADD_NS_MEDIUM() \
|
|
|
|
cur_error = 0.0; \
|
|
|
|
for (j = 0; j < 5; j++) \
|
|
|
|
cur_error += errors[chan_pos*5 + j] * ns_medium_coeffs[j]; \
|
|
|
|
tmp -= cur_error; \
|
|
|
|
orig = tmp;
|
|
|
|
|
|
|
|
#define UPDATE_ERROR_MEDIUM() \
|
|
|
|
for (j = 4; j > 0; j--) \
|
|
|
|
errors[chan_pos*5 + j] = errors[chan_pos*5 + j-1]; \
|
|
|
|
errors[chan_pos*5] = (*dst)/factor - orig;
|
|
|
|
|
|
|
|
/* Noise shaping coefficients by David Schleef, moves most power of the
|
|
|
|
* error noise into inaudible frequency ranges */
|
|
|
|
|
|
|
|
static const gdouble ns_high_coeffs[] = {
|
|
|
|
2.08484, -2.92975, 3.27918, -3.31399, 2.61339, -1.72008, 0.876066, -0.340122
|
|
|
|
};
|
|
|
|
|
|
|
|
#define INIT_NS_HIGH() \
|
|
|
|
gdouble orig; \
|
|
|
|
gdouble *errors = ctx->error_buf, cur_error; \
|
|
|
|
int j;
|
|
|
|
|
|
|
|
#define ADD_NS_HIGH() \
|
|
|
|
cur_error = 0.0; \
|
|
|
|
for (j = 0; j < 8; j++) \
|
|
|
|
cur_error += errors[chan_pos + j] * ns_high_coeffs[j]; \
|
|
|
|
tmp -= cur_error; \
|
|
|
|
orig = tmp;
|
|
|
|
|
|
|
|
#define UPDATE_ERROR_HIGH() \
|
|
|
|
for (j = 7; j > 0; j--) \
|
|
|
|
errors[chan_pos + j] = errors[chan_pos + j-1]; \
|
|
|
|
errors[chan_pos] = (*dst)/factor - orig;
|
|
|
|
|
|
|
|
|
2015-03-24 15:28:51 +00:00
|
|
|
MAKE_QUANTIZE_FUNC_I (int_none_none, NONE_FUNC, NONE_FUNC, ROUND);
|
|
|
|
MAKE_QUANTIZE_FUNC_I (int_rpdf_none, INIT_DITHER_RPDF_I, ADD_DITHER_RPDF_I,
|
gst/audioconvert/: Implement dithering and noise shaping in audioconvert. By default now
Original commit message from CVS:
* gst/audioconvert/Makefile.am:
* gst/audioconvert/audioconvert.c: (audio_convert_get_func_index),
(check_default), (audio_convert_prepare_context),
(audio_convert_clean_context), (audio_convert_convert):
* gst/audioconvert/audioconvert.h:
* gst/audioconvert/gstaudioconvert.c:
(gst_audio_convert_dithering_get_type),
(gst_audio_convert_ns_get_type), (gst_audio_convert_class_init),
(gst_audio_convert_init), (gst_audio_convert_set_caps),
(gst_audio_convert_set_property), (gst_audio_convert_get_property):
* gst/audioconvert/gstaudioconvert.h:
* gst/audioconvert/gstaudioquantize.c:
(gst_audio_quantize_setup_noise_shaping),
(gst_audio_quantize_free_noise_shaping),
(gst_audio_quantize_setup_dither),
(gst_audio_quantize_free_dither),
(gst_audio_quantize_setup_quantize_func),
(gst_audio_quantize_setup), (gst_audio_quantize_free):
* gst/audioconvert/gstaudioquantize.h:
Implement dithering and noise shaping in audioconvert. By default now
TPDF dithering (and no noise shaping) will be used when converting
from a higher bit depth to 20 bit depth or smaller, otherwise
everything will be as it is now.
For the last audioconvert in a pipeline it would make sense to
use some kind of noise shaping, enabling it by default for all
conversions would give undesired results though. Fixes #360246.
* tests/check/elements/audioconvert.c: (setup_audioconvert),
(GST_START_TEST):
Adjust unit test for the new audioconvert.
2007-06-28 20:37:58 +00:00
|
|
|
NONE_FUNC);
|
2015-03-24 15:28:51 +00:00
|
|
|
MAKE_QUANTIZE_FUNC_I (int_tpdf_none, INIT_DITHER_TPDF_I, ADD_DITHER_TPDF_I,
|
gst/audioconvert/: Implement dithering and noise shaping in audioconvert. By default now
Original commit message from CVS:
* gst/audioconvert/Makefile.am:
* gst/audioconvert/audioconvert.c: (audio_convert_get_func_index),
(check_default), (audio_convert_prepare_context),
(audio_convert_clean_context), (audio_convert_convert):
* gst/audioconvert/audioconvert.h:
* gst/audioconvert/gstaudioconvert.c:
(gst_audio_convert_dithering_get_type),
(gst_audio_convert_ns_get_type), (gst_audio_convert_class_init),
(gst_audio_convert_init), (gst_audio_convert_set_caps),
(gst_audio_convert_set_property), (gst_audio_convert_get_property):
* gst/audioconvert/gstaudioconvert.h:
* gst/audioconvert/gstaudioquantize.c:
(gst_audio_quantize_setup_noise_shaping),
(gst_audio_quantize_free_noise_shaping),
(gst_audio_quantize_setup_dither),
(gst_audio_quantize_free_dither),
(gst_audio_quantize_setup_quantize_func),
(gst_audio_quantize_setup), (gst_audio_quantize_free):
* gst/audioconvert/gstaudioquantize.h:
Implement dithering and noise shaping in audioconvert. By default now
TPDF dithering (and no noise shaping) will be used when converting
from a higher bit depth to 20 bit depth or smaller, otherwise
everything will be as it is now.
For the last audioconvert in a pipeline it would make sense to
use some kind of noise shaping, enabling it by default for all
conversions would give undesired results though. Fixes #360246.
* tests/check/elements/audioconvert.c: (setup_audioconvert),
(GST_START_TEST):
Adjust unit test for the new audioconvert.
2007-06-28 20:37:58 +00:00
|
|
|
NONE_FUNC);
|
2015-03-24 15:28:51 +00:00
|
|
|
MAKE_QUANTIZE_FUNC_I (int_tpdf_hf_none, INIT_DITHER_TPDF_HF_I,
|
gst/audioconvert/: Implement dithering and noise shaping in audioconvert. By default now
Original commit message from CVS:
* gst/audioconvert/Makefile.am:
* gst/audioconvert/audioconvert.c: (audio_convert_get_func_index),
(check_default), (audio_convert_prepare_context),
(audio_convert_clean_context), (audio_convert_convert):
* gst/audioconvert/audioconvert.h:
* gst/audioconvert/gstaudioconvert.c:
(gst_audio_convert_dithering_get_type),
(gst_audio_convert_ns_get_type), (gst_audio_convert_class_init),
(gst_audio_convert_init), (gst_audio_convert_set_caps),
(gst_audio_convert_set_property), (gst_audio_convert_get_property):
* gst/audioconvert/gstaudioconvert.h:
* gst/audioconvert/gstaudioquantize.c:
(gst_audio_quantize_setup_noise_shaping),
(gst_audio_quantize_free_noise_shaping),
(gst_audio_quantize_setup_dither),
(gst_audio_quantize_free_dither),
(gst_audio_quantize_setup_quantize_func),
(gst_audio_quantize_setup), (gst_audio_quantize_free):
* gst/audioconvert/gstaudioquantize.h:
Implement dithering and noise shaping in audioconvert. By default now
TPDF dithering (and no noise shaping) will be used when converting
from a higher bit depth to 20 bit depth or smaller, otherwise
everything will be as it is now.
For the last audioconvert in a pipeline it would make sense to
use some kind of noise shaping, enabling it by default for all
conversions would give undesired results though. Fixes #360246.
* tests/check/elements/audioconvert.c: (setup_audioconvert),
(GST_START_TEST):
Adjust unit test for the new audioconvert.
2007-06-28 20:37:58 +00:00
|
|
|
ADD_DITHER_TPDF_HF_I, NONE_FUNC);
|
|
|
|
|
|
|
|
MAKE_QUANTIZE_FUNC_F (float_none_error_feedback, NONE_FUNC,
|
|
|
|
INIT_NS_ERROR_FEEDBACK, ADD_NS_ERROR_FEEDBACK, NONE_FUNC,
|
|
|
|
UPDATE_ERROR_ERROR_FEEDBACK);
|
|
|
|
MAKE_QUANTIZE_FUNC_F (float_none_simple, NONE_FUNC, INIT_NS_SIMPLE,
|
|
|
|
ADD_NS_SIMPLE, NONE_FUNC, UPDATE_ERROR_SIMPLE);
|
|
|
|
MAKE_QUANTIZE_FUNC_F (float_none_medium, NONE_FUNC, INIT_NS_MEDIUM,
|
|
|
|
ADD_NS_MEDIUM, NONE_FUNC, UPDATE_ERROR_MEDIUM);
|
|
|
|
MAKE_QUANTIZE_FUNC_F (float_none_high, NONE_FUNC, INIT_NS_HIGH, ADD_NS_HIGH,
|
|
|
|
NONE_FUNC, UPDATE_ERROR_HIGH);
|
|
|
|
|
|
|
|
MAKE_QUANTIZE_FUNC_F (float_rpdf_error_feedback, INIT_DITHER_RPDF_F,
|
|
|
|
INIT_NS_ERROR_FEEDBACK, ADD_NS_ERROR_FEEDBACK, ADD_DITHER_RPDF_F,
|
|
|
|
UPDATE_ERROR_ERROR_FEEDBACK);
|
|
|
|
MAKE_QUANTIZE_FUNC_F (float_rpdf_simple, INIT_DITHER_RPDF_F, INIT_NS_SIMPLE,
|
|
|
|
ADD_NS_SIMPLE, ADD_DITHER_RPDF_F, UPDATE_ERROR_SIMPLE);
|
|
|
|
MAKE_QUANTIZE_FUNC_F (float_rpdf_medium, INIT_DITHER_RPDF_F, INIT_NS_MEDIUM,
|
|
|
|
ADD_NS_MEDIUM, ADD_DITHER_RPDF_F, UPDATE_ERROR_MEDIUM);
|
|
|
|
MAKE_QUANTIZE_FUNC_F (float_rpdf_high, INIT_DITHER_RPDF_F, INIT_NS_HIGH,
|
|
|
|
ADD_NS_HIGH, ADD_DITHER_RPDF_F, UPDATE_ERROR_HIGH);
|
|
|
|
|
|
|
|
MAKE_QUANTIZE_FUNC_F (float_tpdf_error_feedback, INIT_DITHER_TPDF_F,
|
|
|
|
INIT_NS_ERROR_FEEDBACK, ADD_NS_ERROR_FEEDBACK, ADD_DITHER_TPDF_F,
|
|
|
|
UPDATE_ERROR_ERROR_FEEDBACK);
|
|
|
|
MAKE_QUANTIZE_FUNC_F (float_tpdf_simple, INIT_DITHER_TPDF_F, INIT_NS_SIMPLE,
|
|
|
|
ADD_NS_SIMPLE, ADD_DITHER_TPDF_F, UPDATE_ERROR_SIMPLE);
|
|
|
|
MAKE_QUANTIZE_FUNC_F (float_tpdf_medium, INIT_DITHER_TPDF_F, INIT_NS_MEDIUM,
|
|
|
|
ADD_NS_MEDIUM, ADD_DITHER_TPDF_F, UPDATE_ERROR_MEDIUM);
|
|
|
|
MAKE_QUANTIZE_FUNC_F (float_tpdf_high, INIT_DITHER_TPDF_F, INIT_NS_HIGH,
|
|
|
|
ADD_NS_HIGH, ADD_DITHER_TPDF_F, UPDATE_ERROR_HIGH);
|
|
|
|
|
|
|
|
MAKE_QUANTIZE_FUNC_F (float_tpdf_hf_error_feedback, INIT_DITHER_TPDF_HF_F,
|
|
|
|
INIT_NS_ERROR_FEEDBACK, ADD_NS_ERROR_FEEDBACK, ADD_DITHER_TPDF_HF_F,
|
|
|
|
UPDATE_ERROR_ERROR_FEEDBACK);
|
|
|
|
MAKE_QUANTIZE_FUNC_F (float_tpdf_hf_simple, INIT_DITHER_TPDF_HF_F,
|
|
|
|
INIT_NS_SIMPLE, ADD_NS_SIMPLE, ADD_DITHER_TPDF_HF_F, UPDATE_ERROR_SIMPLE);
|
|
|
|
MAKE_QUANTIZE_FUNC_F (float_tpdf_hf_medium, INIT_DITHER_TPDF_HF_F,
|
|
|
|
INIT_NS_MEDIUM, ADD_NS_MEDIUM, ADD_DITHER_TPDF_HF_F, UPDATE_ERROR_MEDIUM);
|
|
|
|
MAKE_QUANTIZE_FUNC_F (float_tpdf_hf_high, INIT_DITHER_TPDF_HF_F, INIT_NS_HIGH,
|
|
|
|
ADD_NS_HIGH, ADD_DITHER_TPDF_HF_F, UPDATE_ERROR_HIGH);
|
|
|
|
|
2015-01-21 08:49:47 +00:00
|
|
|
static const AudioConvertQuantize quantize_funcs[] = {
|
2015-03-24 15:28:51 +00:00
|
|
|
(AudioConvertQuantize) MAKE_QUANTIZE_FUNC_NAME (int_none_none),
|
|
|
|
(AudioConvertQuantize) MAKE_QUANTIZE_FUNC_NAME (int_rpdf_none),
|
|
|
|
(AudioConvertQuantize) MAKE_QUANTIZE_FUNC_NAME (int_tpdf_none),
|
|
|
|
(AudioConvertQuantize) MAKE_QUANTIZE_FUNC_NAME (int_tpdf_hf_none),
|
gst/audioconvert/: Implement dithering and noise shaping in audioconvert. By default now
Original commit message from CVS:
* gst/audioconvert/Makefile.am:
* gst/audioconvert/audioconvert.c: (audio_convert_get_func_index),
(check_default), (audio_convert_prepare_context),
(audio_convert_clean_context), (audio_convert_convert):
* gst/audioconvert/audioconvert.h:
* gst/audioconvert/gstaudioconvert.c:
(gst_audio_convert_dithering_get_type),
(gst_audio_convert_ns_get_type), (gst_audio_convert_class_init),
(gst_audio_convert_init), (gst_audio_convert_set_caps),
(gst_audio_convert_set_property), (gst_audio_convert_get_property):
* gst/audioconvert/gstaudioconvert.h:
* gst/audioconvert/gstaudioquantize.c:
(gst_audio_quantize_setup_noise_shaping),
(gst_audio_quantize_free_noise_shaping),
(gst_audio_quantize_setup_dither),
(gst_audio_quantize_free_dither),
(gst_audio_quantize_setup_quantize_func),
(gst_audio_quantize_setup), (gst_audio_quantize_free):
* gst/audioconvert/gstaudioquantize.h:
Implement dithering and noise shaping in audioconvert. By default now
TPDF dithering (and no noise shaping) will be used when converting
from a higher bit depth to 20 bit depth or smaller, otherwise
everything will be as it is now.
For the last audioconvert in a pipeline it would make sense to
use some kind of noise shaping, enabling it by default for all
conversions would give undesired results though. Fixes #360246.
* tests/check/elements/audioconvert.c: (setup_audioconvert),
(GST_START_TEST):
Adjust unit test for the new audioconvert.
2007-06-28 20:37:58 +00:00
|
|
|
(AudioConvertQuantize) MAKE_QUANTIZE_FUNC_NAME (float_none_error_feedback),
|
|
|
|
(AudioConvertQuantize) MAKE_QUANTIZE_FUNC_NAME (float_none_simple),
|
|
|
|
(AudioConvertQuantize) MAKE_QUANTIZE_FUNC_NAME (float_none_medium),
|
|
|
|
(AudioConvertQuantize) MAKE_QUANTIZE_FUNC_NAME (float_none_high),
|
|
|
|
(AudioConvertQuantize) MAKE_QUANTIZE_FUNC_NAME (float_rpdf_error_feedback),
|
|
|
|
(AudioConvertQuantize) MAKE_QUANTIZE_FUNC_NAME (float_rpdf_simple),
|
|
|
|
(AudioConvertQuantize) MAKE_QUANTIZE_FUNC_NAME (float_rpdf_medium),
|
|
|
|
(AudioConvertQuantize) MAKE_QUANTIZE_FUNC_NAME (float_rpdf_high),
|
|
|
|
(AudioConvertQuantize) MAKE_QUANTIZE_FUNC_NAME (float_tpdf_error_feedback),
|
|
|
|
(AudioConvertQuantize) MAKE_QUANTIZE_FUNC_NAME (float_tpdf_simple),
|
|
|
|
(AudioConvertQuantize) MAKE_QUANTIZE_FUNC_NAME (float_tpdf_medium),
|
|
|
|
(AudioConvertQuantize) MAKE_QUANTIZE_FUNC_NAME (float_tpdf_high),
|
|
|
|
(AudioConvertQuantize) MAKE_QUANTIZE_FUNC_NAME (float_tpdf_hf_error_feedback),
|
|
|
|
(AudioConvertQuantize) MAKE_QUANTIZE_FUNC_NAME (float_tpdf_hf_simple),
|
|
|
|
(AudioConvertQuantize) MAKE_QUANTIZE_FUNC_NAME (float_tpdf_hf_medium),
|
2007-08-03 19:40:14 +00:00
|
|
|
(AudioConvertQuantize) MAKE_QUANTIZE_FUNC_NAME (float_tpdf_hf_high)
|
gst/audioconvert/: Implement dithering and noise shaping in audioconvert. By default now
Original commit message from CVS:
* gst/audioconvert/Makefile.am:
* gst/audioconvert/audioconvert.c: (audio_convert_get_func_index),
(check_default), (audio_convert_prepare_context),
(audio_convert_clean_context), (audio_convert_convert):
* gst/audioconvert/audioconvert.h:
* gst/audioconvert/gstaudioconvert.c:
(gst_audio_convert_dithering_get_type),
(gst_audio_convert_ns_get_type), (gst_audio_convert_class_init),
(gst_audio_convert_init), (gst_audio_convert_set_caps),
(gst_audio_convert_set_property), (gst_audio_convert_get_property):
* gst/audioconvert/gstaudioconvert.h:
* gst/audioconvert/gstaudioquantize.c:
(gst_audio_quantize_setup_noise_shaping),
(gst_audio_quantize_free_noise_shaping),
(gst_audio_quantize_setup_dither),
(gst_audio_quantize_free_dither),
(gst_audio_quantize_setup_quantize_func),
(gst_audio_quantize_setup), (gst_audio_quantize_free):
* gst/audioconvert/gstaudioquantize.h:
Implement dithering and noise shaping in audioconvert. By default now
TPDF dithering (and no noise shaping) will be used when converting
from a higher bit depth to 20 bit depth or smaller, otherwise
everything will be as it is now.
For the last audioconvert in a pipeline it would make sense to
use some kind of noise shaping, enabling it by default for all
conversions would give undesired results though. Fixes #360246.
* tests/check/elements/audioconvert.c: (setup_audioconvert),
(GST_START_TEST):
Adjust unit test for the new audioconvert.
2007-06-28 20:37:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_audio_quantize_setup_noise_shaping (AudioConvertCtx * ctx)
|
|
|
|
{
|
|
|
|
switch (ctx->ns) {
|
|
|
|
case NOISE_SHAPING_HIGH:{
|
|
|
|
ctx->error_buf = g_new0 (gdouble, ctx->out.channels * 8);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NOISE_SHAPING_MEDIUM:{
|
|
|
|
ctx->error_buf = g_new0 (gdouble, ctx->out.channels * 5);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NOISE_SHAPING_SIMPLE:{
|
|
|
|
ctx->error_buf = g_new0 (gdouble, ctx->out.channels * 2);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NOISE_SHAPING_ERROR_FEEDBACK:
|
|
|
|
ctx->error_buf = g_new0 (gdouble, ctx->out.channels);
|
|
|
|
break;
|
|
|
|
case NOISE_SHAPING_NONE:
|
|
|
|
default:
|
|
|
|
ctx->error_buf = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_audio_quantize_free_noise_shaping (AudioConvertCtx * ctx)
|
|
|
|
{
|
|
|
|
switch (ctx->ns) {
|
|
|
|
case NOISE_SHAPING_HIGH:
|
|
|
|
case NOISE_SHAPING_MEDIUM:
|
|
|
|
case NOISE_SHAPING_SIMPLE:
|
|
|
|
case NOISE_SHAPING_ERROR_FEEDBACK:
|
|
|
|
case NOISE_SHAPING_NONE:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (ctx->error_buf);
|
|
|
|
ctx->error_buf = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_audio_quantize_setup_dither (AudioConvertCtx * ctx)
|
|
|
|
{
|
|
|
|
switch (ctx->dither) {
|
|
|
|
case DITHER_TPDF_HF:
|
2011-08-20 08:49:17 +00:00
|
|
|
if (GST_AUDIO_FORMAT_INFO_IS_INTEGER (ctx->out.finfo))
|
gst/audioconvert/: Implement dithering and noise shaping in audioconvert. By default now
Original commit message from CVS:
* gst/audioconvert/Makefile.am:
* gst/audioconvert/audioconvert.c: (audio_convert_get_func_index),
(check_default), (audio_convert_prepare_context),
(audio_convert_clean_context), (audio_convert_convert):
* gst/audioconvert/audioconvert.h:
* gst/audioconvert/gstaudioconvert.c:
(gst_audio_convert_dithering_get_type),
(gst_audio_convert_ns_get_type), (gst_audio_convert_class_init),
(gst_audio_convert_init), (gst_audio_convert_set_caps),
(gst_audio_convert_set_property), (gst_audio_convert_get_property):
* gst/audioconvert/gstaudioconvert.h:
* gst/audioconvert/gstaudioquantize.c:
(gst_audio_quantize_setup_noise_shaping),
(gst_audio_quantize_free_noise_shaping),
(gst_audio_quantize_setup_dither),
(gst_audio_quantize_free_dither),
(gst_audio_quantize_setup_quantize_func),
(gst_audio_quantize_setup), (gst_audio_quantize_free):
* gst/audioconvert/gstaudioquantize.h:
Implement dithering and noise shaping in audioconvert. By default now
TPDF dithering (and no noise shaping) will be used when converting
from a higher bit depth to 20 bit depth or smaller, otherwise
everything will be as it is now.
For the last audioconvert in a pipeline it would make sense to
use some kind of noise shaping, enabling it by default for all
conversions would give undesired results though. Fixes #360246.
* tests/check/elements/audioconvert.c: (setup_audioconvert),
(GST_START_TEST):
Adjust unit test for the new audioconvert.
2007-06-28 20:37:58 +00:00
|
|
|
ctx->last_random = g_new0 (gint32, ctx->out.channels);
|
|
|
|
else
|
|
|
|
ctx->last_random = g_new0 (gdouble, ctx->out.channels);
|
|
|
|
break;
|
|
|
|
case DITHER_RPDF:
|
|
|
|
case DITHER_TPDF:
|
|
|
|
ctx->last_random = NULL;
|
|
|
|
break;
|
|
|
|
case DITHER_NONE:
|
|
|
|
default:
|
|
|
|
ctx->last_random = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_audio_quantize_free_dither (AudioConvertCtx * ctx)
|
|
|
|
{
|
|
|
|
g_free (ctx->last_random);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_audio_quantize_setup_quantize_func (AudioConvertCtx * ctx)
|
|
|
|
{
|
|
|
|
gint index = 0;
|
|
|
|
|
2011-08-20 08:49:17 +00:00
|
|
|
if (!GST_AUDIO_FORMAT_INFO_IS_INTEGER (ctx->out.finfo)) {
|
gst/audioconvert/: Implement dithering and noise shaping in audioconvert. By default now
Original commit message from CVS:
* gst/audioconvert/Makefile.am:
* gst/audioconvert/audioconvert.c: (audio_convert_get_func_index),
(check_default), (audio_convert_prepare_context),
(audio_convert_clean_context), (audio_convert_convert):
* gst/audioconvert/audioconvert.h:
* gst/audioconvert/gstaudioconvert.c:
(gst_audio_convert_dithering_get_type),
(gst_audio_convert_ns_get_type), (gst_audio_convert_class_init),
(gst_audio_convert_init), (gst_audio_convert_set_caps),
(gst_audio_convert_set_property), (gst_audio_convert_get_property):
* gst/audioconvert/gstaudioconvert.h:
* gst/audioconvert/gstaudioquantize.c:
(gst_audio_quantize_setup_noise_shaping),
(gst_audio_quantize_free_noise_shaping),
(gst_audio_quantize_setup_dither),
(gst_audio_quantize_free_dither),
(gst_audio_quantize_setup_quantize_func),
(gst_audio_quantize_setup), (gst_audio_quantize_free):
* gst/audioconvert/gstaudioquantize.h:
Implement dithering and noise shaping in audioconvert. By default now
TPDF dithering (and no noise shaping) will be used when converting
from a higher bit depth to 20 bit depth or smaller, otherwise
everything will be as it is now.
For the last audioconvert in a pipeline it would make sense to
use some kind of noise shaping, enabling it by default for all
conversions would give undesired results though. Fixes #360246.
* tests/check/elements/audioconvert.c: (setup_audioconvert),
(GST_START_TEST):
Adjust unit test for the new audioconvert.
2007-06-28 20:37:58 +00:00
|
|
|
ctx->quantize = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ctx->ns == NOISE_SHAPING_NONE) {
|
|
|
|
index += ctx->dither;
|
|
|
|
} else {
|
2015-03-24 15:28:51 +00:00
|
|
|
index += 4 + (4 * ctx->dither);
|
gst/audioconvert/: Implement dithering and noise shaping in audioconvert. By default now
Original commit message from CVS:
* gst/audioconvert/Makefile.am:
* gst/audioconvert/audioconvert.c: (audio_convert_get_func_index),
(check_default), (audio_convert_prepare_context),
(audio_convert_clean_context), (audio_convert_convert):
* gst/audioconvert/audioconvert.h:
* gst/audioconvert/gstaudioconvert.c:
(gst_audio_convert_dithering_get_type),
(gst_audio_convert_ns_get_type), (gst_audio_convert_class_init),
(gst_audio_convert_init), (gst_audio_convert_set_caps),
(gst_audio_convert_set_property), (gst_audio_convert_get_property):
* gst/audioconvert/gstaudioconvert.h:
* gst/audioconvert/gstaudioquantize.c:
(gst_audio_quantize_setup_noise_shaping),
(gst_audio_quantize_free_noise_shaping),
(gst_audio_quantize_setup_dither),
(gst_audio_quantize_free_dither),
(gst_audio_quantize_setup_quantize_func),
(gst_audio_quantize_setup), (gst_audio_quantize_free):
* gst/audioconvert/gstaudioquantize.h:
Implement dithering and noise shaping in audioconvert. By default now
TPDF dithering (and no noise shaping) will be used when converting
from a higher bit depth to 20 bit depth or smaller, otherwise
everything will be as it is now.
For the last audioconvert in a pipeline it would make sense to
use some kind of noise shaping, enabling it by default for all
conversions would give undesired results though. Fixes #360246.
* tests/check/elements/audioconvert.c: (setup_audioconvert),
(GST_START_TEST):
Adjust unit test for the new audioconvert.
2007-06-28 20:37:58 +00:00
|
|
|
index += ctx->ns - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->quantize = quantize_funcs[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_audio_quantize_setup (AudioConvertCtx * ctx)
|
|
|
|
{
|
|
|
|
gst_audio_quantize_setup_dither (ctx);
|
|
|
|
gst_audio_quantize_setup_noise_shaping (ctx);
|
|
|
|
gst_audio_quantize_setup_quantize_func (ctx);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_audio_quantize_free (AudioConvertCtx * ctx)
|
|
|
|
{
|
|
|
|
gst_audio_quantize_free_dither (ctx);
|
|
|
|
gst_audio_quantize_free_noise_shaping (ctx);
|
|
|
|
}
|