mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-17 03:35:21 +00:00
ext/speex/: Use integer encoding and decoding functions instead of converting the integer input to float in the eleme...
Original commit message from CVS: * ext/speex/gstspeexdec.c: (speex_dec_chain_parse_data): * ext/speex/gstspeexdec.h: * ext/speex/gstspeexenc.c: (gst_speex_enc_encode): * ext/speex/gstspeexenc.h: Use integer encoding and decoding functions instead of converting the integer input to float in the element. The libspeex integer functions are doing this for us already or, if libspeex was compiled in integer mode, they're doing everything using integer arithmetics. Also saves some copying around.
This commit is contained in:
parent
1ebf38c959
commit
3fa17e67a4
5 changed files with 39 additions and 39 deletions
12
ChangeLog
12
ChangeLog
|
@ -1,3 +1,15 @@
|
|||
2008-09-02 Sebastian Dröge <sebastian.droege@collabora.co.uk>
|
||||
|
||||
* ext/speex/gstspeexdec.c: (speex_dec_chain_parse_data):
|
||||
* ext/speex/gstspeexdec.h:
|
||||
* ext/speex/gstspeexenc.c: (gst_speex_enc_encode):
|
||||
* ext/speex/gstspeexenc.h:
|
||||
Use integer encoding and decoding functions instead of converting
|
||||
the integer input to float in the element. The libspeex integer
|
||||
functions are doing this for us already or, if libspeex was compiled
|
||||
in integer mode, they're doing everything using integer arithmetics.
|
||||
Also saves some copying around.
|
||||
|
||||
2008-09-01 Tim-Philipp Müller <tim.muller at collabora co uk>
|
||||
|
||||
* configure.ac:
|
||||
|
|
|
@ -685,27 +685,10 @@ speex_dec_chain_parse_data (GstSpeexDec * dec, GstBuffer * buf,
|
|||
for (i = 0; i < fpp; i++) {
|
||||
GstBuffer *outbuf;
|
||||
gint16 *out_data;
|
||||
gint ret, j;
|
||||
gint ret;
|
||||
|
||||
GST_LOG_OBJECT (dec, "decoding frame %d/%d", i, fpp);
|
||||
|
||||
ret = speex_decode (dec->state, bits, dec->output);
|
||||
if (ret == -1) {
|
||||
/* uh? end of stream */
|
||||
GST_WARNING_OBJECT (dec, "Unexpected end of stream found");
|
||||
break;
|
||||
} else if (ret == -2) {
|
||||
GST_WARNING_OBJECT (dec, "Decoding error: corrupted stream?");
|
||||
break;
|
||||
}
|
||||
|
||||
if (bits && speex_bits_remaining (bits) < 0) {
|
||||
GST_WARNING_OBJECT (dec, "Decoding overflow: corrupted stream?");
|
||||
break;
|
||||
}
|
||||
if (dec->header->nb_channels == 2)
|
||||
speex_decode_stereo (dec->output, dec->frame_size, &dec->stereo);
|
||||
|
||||
res = gst_pad_alloc_buffer_and_set_caps (dec->srcpad,
|
||||
GST_BUFFER_OFFSET_NONE, dec->frame_size * dec->header->nb_channels * 2,
|
||||
GST_PAD_CAPS (dec->srcpad), &outbuf);
|
||||
|
@ -717,16 +700,29 @@ speex_dec_chain_parse_data (GstSpeexDec * dec, GstBuffer * buf,
|
|||
|
||||
out_data = (gint16 *) GST_BUFFER_DATA (outbuf);
|
||||
|
||||
/*PCM saturation (just in case) */
|
||||
for (j = 0; j < dec->frame_size * dec->header->nb_channels; j++) {
|
||||
if (dec->output[j] > 32767.0)
|
||||
out_data[j] = 32767;
|
||||
else if (dec->output[i] < -32768.0)
|
||||
out_data[j] = -32768;
|
||||
else
|
||||
out_data[j] = (gint16) dec->output[j];
|
||||
ret = speex_decode_int (dec->state, bits, out_data);
|
||||
if (ret == -1) {
|
||||
/* uh? end of stream */
|
||||
GST_WARNING_OBJECT (dec, "Unexpected end of stream found");
|
||||
gst_buffer_unref (outbuf);
|
||||
outbuf = NULL;
|
||||
break;
|
||||
} else if (ret == -2) {
|
||||
GST_WARNING_OBJECT (dec, "Decoding error: corrupted stream?");
|
||||
gst_buffer_unref (outbuf);
|
||||
outbuf = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
if (bits && speex_bits_remaining (bits) < 0) {
|
||||
GST_WARNING_OBJECT (dec, "Decoding overflow: corrupted stream?");
|
||||
gst_buffer_unref (outbuf);
|
||||
outbuf = NULL;
|
||||
break;
|
||||
}
|
||||
if (dec->header->nb_channels == 2)
|
||||
speex_decode_stereo_int (out_data, dec->frame_size, &dec->stereo);
|
||||
|
||||
if (dec->granulepos == -1) {
|
||||
if (dec->segment.format != GST_FORMAT_TIME) {
|
||||
GST_WARNING_OBJECT (dec, "segment not initialized or not TIME format");
|
||||
|
|
|
@ -63,8 +63,6 @@ struct _GstSpeexDec {
|
|||
SpeexCallback callback;
|
||||
SpeexBits bits;
|
||||
|
||||
gfloat output[DEC_MAX_FRAME_SIZE];
|
||||
|
||||
gboolean enh;
|
||||
|
||||
gint frame_size;
|
||||
|
|
|
@ -867,25 +867,21 @@ gst_speex_enc_encode (GstSpeexEnc * enc, gboolean flush)
|
|||
|
||||
while (gst_adapter_available (enc->adapter) >= bytes) {
|
||||
gint16 *data;
|
||||
gint i;
|
||||
gint outsize, written;
|
||||
GstBuffer *outbuf;
|
||||
|
||||
data = (gint16 *) gst_adapter_peek (enc->adapter, bytes);
|
||||
|
||||
for (i = 0; i < frame_size * enc->channels; i++) {
|
||||
enc->input[i] = (gfloat) data[i];
|
||||
}
|
||||
gst_adapter_flush (enc->adapter, bytes);
|
||||
data = (gint16 *) gst_adapter_take (enc->adapter, bytes);
|
||||
|
||||
enc->samples_in += frame_size;
|
||||
|
||||
GST_DEBUG_OBJECT (enc, "encoding %d samples (%d bytes)", frame_size, bytes);
|
||||
|
||||
if (enc->channels == 2) {
|
||||
speex_encode_stereo (enc->input, frame_size, &enc->bits);
|
||||
speex_encode_stereo_int (data, frame_size, &enc->bits);
|
||||
}
|
||||
speex_encode (enc->state, enc->input, &enc->bits);
|
||||
speex_encode_int (enc->state, data, &enc->bits);
|
||||
|
||||
g_free (data);
|
||||
|
||||
enc->frameno++;
|
||||
enc->frameno_out++;
|
||||
|
|
|
@ -107,8 +107,6 @@ struct _GstSpeexEnc {
|
|||
guint8 *comments;
|
||||
gint comment_len;
|
||||
|
||||
gfloat input[MAX_FRAME_SIZE];
|
||||
|
||||
/* Timestamp and granulepos tracking */
|
||||
GstClockTime start_ts;
|
||||
GstClockTime next_ts;
|
||||
|
|
Loading…
Reference in a new issue