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:
Wim Taymans 2006-07-12 10:58:42 +00:00
parent 7b88e03196
commit 46d86d8005
2 changed files with 78 additions and 47 deletions

View file

@ -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> 2006-07-12 Edward Hervey <edward@fluendo.com>
* ext/vorbis/vorbisdec.c: (gst_vorbis_dec_init), * ext/vorbis/vorbisdec.c: (gst_vorbis_dec_init),

View file

@ -130,55 +130,61 @@ gst_ring_buffer_finalize (GObject * object)
G_OBJECT_CLASS (parent_class)->finalize (G_OBJECT (ringbuffer)); G_OBJECT_CLASS (parent_class)->finalize (G_OBJECT (ringbuffer));
} }
static const int linear_formats[4 * 2 * 2] = { typedef struct
GST_S8, {
GST_S8, GstBufferFormat format;
GST_U8, guint8 silence[4];
GST_U8, } FormatDef;
GST_S16_LE,
GST_S16_BE, static const FormatDef linear_defs[4 * 2 * 2] = {
GST_U16_LE, {GST_S8, {0x00, 0x00, 0x00, 0x00}},
GST_U16_BE, {GST_S8, {0x00, 0x00, 0x00, 0x00}},
GST_S24_LE, {GST_U8, {0x80, 0x80, 0x80, 0x80}},
GST_S24_BE, {GST_U8, {0x80, 0x80, 0x80, 0x80}},
GST_U24_LE, {GST_S16_LE, {0x00, 0x00, 0x00, 0x00}},
GST_U24_BE, {GST_S16_BE, {0x00, 0x00, 0x00, 0x00}},
GST_S32_LE, {GST_U16_LE, {0x00, 0x80, 0x00, 0x80}},
GST_S32_BE, {GST_U16_BE, {0x80, 0x00, 0x80, 0x00}},
GST_U32_LE, {GST_S24_LE, {0x00, 0x00, 0x00, 0x00}},
GST_U32_BE {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] = { static const FormatDef linear24_defs[3 * 2 * 2] = {
GST_S24_3LE, {GST_S24_3LE, {0x00, 0x00, 0x00, 0x00}},
GST_S24_3BE, {GST_S24_3BE, {0x00, 0x00, 0x00, 0x00}},
GST_U24_3LE, {GST_U24_3LE, {0x00, 0x00, 0x80, 0x00}},
GST_U24_3BE, {GST_U24_3BE, {0x80, 0x00, 0x00, 0x00}},
GST_S20_3LE, {GST_S20_3LE, {0x00, 0x00, 0x00, 0x00}},
GST_S20_3BE, {GST_S20_3BE, {0x00, 0x00, 0x00, 0x00}},
GST_U20_3LE, {GST_U20_3LE, {0x00, 0x00, 0x08, 0x00}},
GST_U20_3BE, {GST_U20_3BE, {0x08, 0x00, 0x00, 0x00}},
GST_S18_3LE, {GST_S18_3LE, {0x00, 0x00, 0x00, 0x00}},
GST_S18_3BE, {GST_S18_3BE, {0x00, 0x00, 0x00, 0x00}},
GST_U18_3LE, {GST_U18_3LE, {0x00, 0x00, 0x02, 0x00}},
GST_U18_3BE, {GST_U18_3BE, {0x02, 0x00, 0x00, 0x00}}
}; };
static GstBufferFormat static const FormatDef *
build_linear_format (int depth, int width, int unsignd, int big_endian) build_linear_format (int depth, int width, int unsignd, int big_endian)
{ {
const gint *formats; const FormatDef *formats;
if (width == 24) { if (width == 24) {
switch (depth) { switch (depth) {
case 24: case 24:
formats = &linear24_formats[0]; formats = &linear24_defs[0];
break; break;
case 20: case 20:
formats = &linear24_formats[4]; formats = &linear24_defs[4];
break; break;
case 18: case 18:
formats = &linear24_formats[8]; formats = &linear24_defs[8];
break; break;
default: default:
return GST_UNKNOWN; return GST_UNKNOWN;
@ -186,16 +192,16 @@ build_linear_format (int depth, int width, int unsignd, int big_endian)
} else { } else {
switch (depth) { switch (depth) {
case 8: case 8:
formats = &linear_formats[0]; formats = &linear_defs[0];
break; break;
case 16: case 16:
formats = &linear_formats[4]; formats = &linear_defs[4];
break; break;
case 24: case 24:
formats = &linear_formats[8]; formats = &linear_defs[8];
break; break;
case 32: case 32:
formats = &linear_formats[12]; formats = &linear_defs[12];
break; break;
default: default:
return GST_UNKNOWN; return GST_UNKNOWN;
@ -205,7 +211,8 @@ build_linear_format (int depth, int width, int unsignd, int big_endian)
formats += 2; formats += 2;
if (big_endian) if (big_endian)
formats += 1; formats += 1;
return (GstBufferFormat) * formats;
return formats;
} }
/** /**
@ -217,6 +224,8 @@ build_linear_format (int depth, int width, int unsignd, int big_endian)
void void
gst_ring_buffer_debug_spec_caps (GstRingBufferSpec * spec) 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 ("spec caps: %p %" GST_PTR_FORMAT, spec->caps, spec->caps);
GST_DEBUG ("parsed caps: type: %d", spec->type); GST_DEBUG ("parsed caps: type: %d", spec->type);
GST_DEBUG ("parsed caps: format: %d", spec->format); 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: rate: %d", spec->rate);
GST_DEBUG ("parsed caps: channels: %d", spec->channels); GST_DEBUG ("parsed caps: channels: %d", spec->channels);
GST_DEBUG ("parsed caps: sample bytes: %d", spec->bytes_per_sample); 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 */ /* we have to differentiate between int and float formats */
mimetype = gst_structure_get_name (structure); 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)) { if (!strncmp (mimetype, "audio/x-raw-int", 15)) {
gint endianness; gint endianness;
const FormatDef *def;
gint i, j, bytes;
spec->type = GST_BUFTYPE_LINEAR; 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->bigend = endianness == G_LITTLE_ENDIAN ? FALSE : TRUE;
spec->format = def = build_linear_format (spec->depth, spec->width, spec->sign ? 0 : 1,
build_linear_format (spec->depth, spec->width, spec->sign ? 0 : 1,
spec->bigend ? 1 : 0); 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)) { } else if (!strncmp (mimetype, "audio/x-raw-float", 17)) {
spec->type = GST_BUFTYPE_FLOAT; spec->type = GST_BUFTYPE_FLOAT;
@ -329,11 +358,6 @@ gst_ring_buffer_parse_caps (GstRingBufferSpec * spec, GstCaps * caps)
goto parse_error; 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; spec->bytes_per_sample = (spec->width >> 3) * spec->channels;
gst_caps_replace (&spec->caps, caps); gst_caps_replace (&spec->caps, caps);