mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-26 06:54:49 +00:00
spectrum: code cleanup for copying data to ring-buffer
Rename fp to is_float and restructure if-else part for handling the different formats.
This commit is contained in:
parent
787aca6898
commit
b60675acaf
1 changed files with 38 additions and 31 deletions
|
@ -601,7 +601,8 @@ gst_spectrum_transform_ip (GstBaseTransform * trans, GstBuffer * buffer)
|
||||||
gfloat max_value =
|
gfloat max_value =
|
||||||
(1UL << (GST_AUDIO_FILTER (spectrum)->format.depth - 1)) - 1;
|
(1UL << (GST_AUDIO_FILTER (spectrum)->format.depth - 1)) - 1;
|
||||||
guint width = GST_AUDIO_FILTER (spectrum)->format.width / 8;
|
guint width = GST_AUDIO_FILTER (spectrum)->format.width / 8;
|
||||||
gboolean fp = (GST_AUDIO_FILTER (spectrum)->format.type == GST_BUFTYPE_FLOAT);
|
gboolean is_float =
|
||||||
|
(GST_AUDIO_FILTER (spectrum)->format.type == GST_BUFTYPE_FLOAT);
|
||||||
guint bands = spectrum->bands;
|
guint bands = spectrum->bands;
|
||||||
guint nfft = 2 * bands - 2;
|
guint nfft = 2 * bands - 2;
|
||||||
guint input_pos;
|
guint input_pos;
|
||||||
|
@ -650,38 +651,44 @@ gst_spectrum_transform_ip (GstBaseTransform * trans, GstBuffer * buffer)
|
||||||
* take the average of all channels
|
* take the average of all channels
|
||||||
*/
|
*/
|
||||||
input[input_pos] = 0.0;
|
input[input_pos] = 0.0;
|
||||||
if (fp && width == 4) {
|
if (is_float) {
|
||||||
gfloat *in = (gfloat *) data;
|
if (width == 4) {
|
||||||
for (i = 0; i < channels; i++)
|
gfloat *in = (gfloat *) data;
|
||||||
input[input_pos] += in[i];
|
for (i = 0; i < channels; i++)
|
||||||
} else if (fp && width == 8) {
|
input[input_pos] += in[i];
|
||||||
gdouble *in = (gdouble *) data;
|
} else if (width == 8) {
|
||||||
for (i = 0; i < channels; i++)
|
gdouble *in = (gdouble *) data;
|
||||||
input[input_pos] += in[i];
|
for (i = 0; i < channels; i++)
|
||||||
} else if (!fp && width == 4) {
|
input[input_pos] += in[i];
|
||||||
gint32 *in = (gint32 *) data;
|
} else {
|
||||||
for (i = 0; i < channels; i++)
|
g_assert_not_reached ();
|
||||||
/* max_value will be 0 when depth is 1, interpret -1 and 0
|
|
||||||
* as -1 and +1 if that's the case.
|
|
||||||
*/
|
|
||||||
input[input_pos] += max_value ? in[i] / max_value : in[i] * 2 + 1;
|
|
||||||
} else if (!fp && width == 3) {
|
|
||||||
for (i = 0; i < channels; i++) {
|
|
||||||
#if G_BYTE_ORDER == G_BIG_ENDIAN
|
|
||||||
gint32 value = GST_READ_UINT24_BE (data);
|
|
||||||
#else
|
|
||||||
gint32 value = GST_READ_UINT24_LE (data);
|
|
||||||
#endif
|
|
||||||
if (value & 0x00800000)
|
|
||||||
value |= 0xff000000;
|
|
||||||
input[input_pos] += max_value ? value / max_value : value * 2 + 1;
|
|
||||||
}
|
}
|
||||||
} else if (!fp && width == 2) {
|
|
||||||
gint16 *in = (gint16 *) data;
|
|
||||||
for (i = 0; i < channels; i++)
|
|
||||||
input[input_pos] += max_value ? in[i] / max_value : in[i] * 2 + 1;
|
|
||||||
} else {
|
} else {
|
||||||
g_assert_not_reached ();
|
if (width == 4) {
|
||||||
|
gint32 *in = (gint32 *) data;
|
||||||
|
for (i = 0; i < channels; i++)
|
||||||
|
/* max_value will be 0 when depth is 1, interpret -1 and 0
|
||||||
|
* as -1 and +1 if that's the case.
|
||||||
|
*/
|
||||||
|
input[input_pos] += max_value ? in[i] / max_value : in[i] * 2 + 1;
|
||||||
|
} else if (width == 3) {
|
||||||
|
for (i = 0; i < channels; i++) {
|
||||||
|
#if G_BYTE_ORDER == G_BIG_ENDIAN
|
||||||
|
gint32 value = GST_READ_UINT24_BE (data);
|
||||||
|
#else
|
||||||
|
gint32 value = GST_READ_UINT24_LE (data);
|
||||||
|
#endif
|
||||||
|
if (value & 0x00800000)
|
||||||
|
value |= 0xff000000;
|
||||||
|
input[input_pos] += max_value ? value / max_value : value * 2 + 1;
|
||||||
|
}
|
||||||
|
} else if (width == 2) {
|
||||||
|
gint16 *in = (gint16 *) data;
|
||||||
|
for (i = 0; i < channels; i++)
|
||||||
|
input[input_pos] += max_value ? in[i] / max_value : in[i] * 2 + 1;
|
||||||
|
} else {
|
||||||
|
g_assert_not_reached ();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
input[input_pos] /= channels;
|
input[input_pos] /= channels;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue