mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-18 22:36:33 +00:00
gst-libs/gst/audio/gstringbuffer.c: Calculate correct silence samples so we don't fill our ringbuffer with noise.
Original commit message from CVS: * gst-libs/gst/audio/gstringbuffer.c: (build_linear_format), (gst_ring_buffer_debug_spec_caps), (gst_ring_buffer_parse_caps): Calculate correct silence samples so we don't fill our ringbuffer with noise.
This commit is contained in:
parent
7b88e03196
commit
46d86d8005
2 changed files with 78 additions and 47 deletions
|
@ -1,3 +1,10 @@
|
|||
2006-07-12 Wim Taymans <wim@fluendo.com>
|
||||
|
||||
* gst-libs/gst/audio/gstringbuffer.c: (build_linear_format),
|
||||
(gst_ring_buffer_debug_spec_caps), (gst_ring_buffer_parse_caps):
|
||||
Calculate correct silence samples so we don't fill our ringbuffer
|
||||
with noise.
|
||||
|
||||
2006-07-12 Edward Hervey <edward@fluendo.com>
|
||||
|
||||
* ext/vorbis/vorbisdec.c: (gst_vorbis_dec_init),
|
||||
|
|
|
@ -130,55 +130,61 @@ gst_ring_buffer_finalize (GObject * object)
|
|||
G_OBJECT_CLASS (parent_class)->finalize (G_OBJECT (ringbuffer));
|
||||
}
|
||||
|
||||
static const int linear_formats[4 * 2 * 2] = {
|
||||
GST_S8,
|
||||
GST_S8,
|
||||
GST_U8,
|
||||
GST_U8,
|
||||
GST_S16_LE,
|
||||
GST_S16_BE,
|
||||
GST_U16_LE,
|
||||
GST_U16_BE,
|
||||
GST_S24_LE,
|
||||
GST_S24_BE,
|
||||
GST_U24_LE,
|
||||
GST_U24_BE,
|
||||
GST_S32_LE,
|
||||
GST_S32_BE,
|
||||
GST_U32_LE,
|
||||
GST_U32_BE
|
||||
typedef struct
|
||||
{
|
||||
GstBufferFormat format;
|
||||
guint8 silence[4];
|
||||
} FormatDef;
|
||||
|
||||
static const FormatDef linear_defs[4 * 2 * 2] = {
|
||||
{GST_S8, {0x00, 0x00, 0x00, 0x00}},
|
||||
{GST_S8, {0x00, 0x00, 0x00, 0x00}},
|
||||
{GST_U8, {0x80, 0x80, 0x80, 0x80}},
|
||||
{GST_U8, {0x80, 0x80, 0x80, 0x80}},
|
||||
{GST_S16_LE, {0x00, 0x00, 0x00, 0x00}},
|
||||
{GST_S16_BE, {0x00, 0x00, 0x00, 0x00}},
|
||||
{GST_U16_LE, {0x00, 0x80, 0x00, 0x80}},
|
||||
{GST_U16_BE, {0x80, 0x00, 0x80, 0x00}},
|
||||
{GST_S24_LE, {0x00, 0x00, 0x00, 0x00}},
|
||||
{GST_S24_BE, {0x00, 0x00, 0x00, 0x00}},
|
||||
{GST_U24_LE, {0x00, 0x00, 0x80, 0x00}},
|
||||
{GST_U24_BE, {0x80, 0x00, 0x00, 0x00}},
|
||||
{GST_S32_LE, {0x00, 0x00, 0x00, 0x00}},
|
||||
{GST_S32_BE, {0x00, 0x00, 0x00, 0x00}},
|
||||
{GST_U32_LE, {0x00, 0x00, 0x00, 0x80}},
|
||||
{GST_U32_BE, {0x80, 0x00, 0x00, 0x00}}
|
||||
};
|
||||
|
||||
static const int linear24_formats[3 * 2 * 2] = {
|
||||
GST_S24_3LE,
|
||||
GST_S24_3BE,
|
||||
GST_U24_3LE,
|
||||
GST_U24_3BE,
|
||||
GST_S20_3LE,
|
||||
GST_S20_3BE,
|
||||
GST_U20_3LE,
|
||||
GST_U20_3BE,
|
||||
GST_S18_3LE,
|
||||
GST_S18_3BE,
|
||||
GST_U18_3LE,
|
||||
GST_U18_3BE,
|
||||
static const FormatDef linear24_defs[3 * 2 * 2] = {
|
||||
{GST_S24_3LE, {0x00, 0x00, 0x00, 0x00}},
|
||||
{GST_S24_3BE, {0x00, 0x00, 0x00, 0x00}},
|
||||
{GST_U24_3LE, {0x00, 0x00, 0x80, 0x00}},
|
||||
{GST_U24_3BE, {0x80, 0x00, 0x00, 0x00}},
|
||||
{GST_S20_3LE, {0x00, 0x00, 0x00, 0x00}},
|
||||
{GST_S20_3BE, {0x00, 0x00, 0x00, 0x00}},
|
||||
{GST_U20_3LE, {0x00, 0x00, 0x08, 0x00}},
|
||||
{GST_U20_3BE, {0x08, 0x00, 0x00, 0x00}},
|
||||
{GST_S18_3LE, {0x00, 0x00, 0x00, 0x00}},
|
||||
{GST_S18_3BE, {0x00, 0x00, 0x00, 0x00}},
|
||||
{GST_U18_3LE, {0x00, 0x00, 0x02, 0x00}},
|
||||
{GST_U18_3BE, {0x02, 0x00, 0x00, 0x00}}
|
||||
};
|
||||
|
||||
static GstBufferFormat
|
||||
static const FormatDef *
|
||||
build_linear_format (int depth, int width, int unsignd, int big_endian)
|
||||
{
|
||||
const gint *formats;
|
||||
const FormatDef *formats;
|
||||
|
||||
if (width == 24) {
|
||||
switch (depth) {
|
||||
case 24:
|
||||
formats = &linear24_formats[0];
|
||||
formats = &linear24_defs[0];
|
||||
break;
|
||||
case 20:
|
||||
formats = &linear24_formats[4];
|
||||
formats = &linear24_defs[4];
|
||||
break;
|
||||
case 18:
|
||||
formats = &linear24_formats[8];
|
||||
formats = &linear24_defs[8];
|
||||
break;
|
||||
default:
|
||||
return GST_UNKNOWN;
|
||||
|
@ -186,16 +192,16 @@ build_linear_format (int depth, int width, int unsignd, int big_endian)
|
|||
} else {
|
||||
switch (depth) {
|
||||
case 8:
|
||||
formats = &linear_formats[0];
|
||||
formats = &linear_defs[0];
|
||||
break;
|
||||
case 16:
|
||||
formats = &linear_formats[4];
|
||||
formats = &linear_defs[4];
|
||||
break;
|
||||
case 24:
|
||||
formats = &linear_formats[8];
|
||||
formats = &linear_defs[8];
|
||||
break;
|
||||
case 32:
|
||||
formats = &linear_formats[12];
|
||||
formats = &linear_defs[12];
|
||||
break;
|
||||
default:
|
||||
return GST_UNKNOWN;
|
||||
|
@ -205,7 +211,8 @@ build_linear_format (int depth, int width, int unsignd, int big_endian)
|
|||
formats += 2;
|
||||
if (big_endian)
|
||||
formats += 1;
|
||||
return (GstBufferFormat) * formats;
|
||||
|
||||
return formats;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -217,6 +224,8 @@ build_linear_format (int depth, int width, int unsignd, int big_endian)
|
|||
void
|
||||
gst_ring_buffer_debug_spec_caps (GstRingBufferSpec * spec)
|
||||
{
|
||||
gint i, bytes;
|
||||
|
||||
GST_DEBUG ("spec caps: %p %" GST_PTR_FORMAT, spec->caps, spec->caps);
|
||||
GST_DEBUG ("parsed caps: type: %d", spec->type);
|
||||
GST_DEBUG ("parsed caps: format: %d", spec->format);
|
||||
|
@ -227,6 +236,10 @@ gst_ring_buffer_debug_spec_caps (GstRingBufferSpec * spec)
|
|||
GST_DEBUG ("parsed caps: rate: %d", spec->rate);
|
||||
GST_DEBUG ("parsed caps: channels: %d", spec->channels);
|
||||
GST_DEBUG ("parsed caps: sample bytes: %d", spec->bytes_per_sample);
|
||||
bytes = (spec->width >> 3) * spec->channels;
|
||||
for (i = 0; i < bytes; i++) {
|
||||
GST_DEBUG ("silence byte %d: %02x", i, spec->silence_sample[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -270,8 +283,15 @@ gst_ring_buffer_parse_caps (GstRingBufferSpec * spec, GstCaps * caps)
|
|||
/* we have to differentiate between int and float formats */
|
||||
mimetype = gst_structure_get_name (structure);
|
||||
|
||||
/* get rate and channels */
|
||||
if (!(gst_structure_get_int (structure, "rate", &spec->rate) &&
|
||||
gst_structure_get_int (structure, "channels", &spec->channels)))
|
||||
goto parse_error;
|
||||
|
||||
if (!strncmp (mimetype, "audio/x-raw-int", 15)) {
|
||||
gint endianness;
|
||||
const FormatDef *def;
|
||||
gint i, j, bytes;
|
||||
|
||||
spec->type = GST_BUFTYPE_LINEAR;
|
||||
|
||||
|
@ -291,9 +311,18 @@ gst_ring_buffer_parse_caps (GstRingBufferSpec * spec, GstCaps * caps)
|
|||
|
||||
spec->bigend = endianness == G_LITTLE_ENDIAN ? FALSE : TRUE;
|
||||
|
||||
spec->format =
|
||||
build_linear_format (spec->depth, spec->width, spec->sign ? 0 : 1,
|
||||
def = build_linear_format (spec->depth, spec->width, spec->sign ? 0 : 1,
|
||||
spec->bigend ? 1 : 0);
|
||||
|
||||
spec->format = def->format;
|
||||
|
||||
bytes = spec->width >> 3;
|
||||
|
||||
for (i = 0; i < spec->channels; i++) {
|
||||
for (j = 0; j < bytes; j++) {
|
||||
spec->silence_sample[i * bytes + j] = def->silence[j];
|
||||
}
|
||||
}
|
||||
} else if (!strncmp (mimetype, "audio/x-raw-float", 17)) {
|
||||
|
||||
spec->type = GST_BUFTYPE_FLOAT;
|
||||
|
@ -329,11 +358,6 @@ gst_ring_buffer_parse_caps (GstRingBufferSpec * spec, GstCaps * caps)
|
|||
goto parse_error;
|
||||
}
|
||||
|
||||
/* get rate and channels */
|
||||
if (!(gst_structure_get_int (structure, "rate", &spec->rate) &&
|
||||
gst_structure_get_int (structure, "channels", &spec->channels)))
|
||||
goto parse_error;
|
||||
|
||||
spec->bytes_per_sample = (spec->width >> 3) * spec->channels;
|
||||
|
||||
gst_caps_replace (&spec->caps, caps);
|
||||
|
|
Loading…
Reference in a new issue