summaryrefslogtreecommitdiffstats
path: root/ext
diff options
context:
space:
mode:
authorSebastian Dröge <slomo@circular-chaos.org>2008-08-07 14:34:03 +0000
committerSebastian Dröge <slomo@circular-chaos.org>2008-08-07 14:34:03 +0000
commiteea5ff778fcde82cdf415f38a8104b218fc396db (patch)
tree48da8e5a08fa597acb54003d1bca67873e53f624 /ext
parent2e1e65e1541347bdcf5253e367297f1a8dca1354 (diff)
downloadgst-plugins-bad-eea5ff778fcde82cdf415f38a8104b218fc396db.tar.gz
gst-plugins-bad-eea5ff778fcde82cdf415f38a8104b218fc396db.tar.bz2
gst-plugins-bad-eea5ff778fcde82cdf415f38a8104b218fc396db.zip
ext/twolame/gsttwolame.*: Allow raw float samples as input for encoding.
Original commit message from CVS: * ext/twolame/gsttwolame.c: (gst_two_lame_sink_setcaps), (gst_two_lame_chain): * ext/twolame/gsttwolame.h: Allow raw float samples as input for encoding.
Diffstat (limited to 'ext')
-rw-r--r--ext/twolame/gsttwolame.c51
-rw-r--r--ext/twolame/gsttwolame.h1
2 files changed, 40 insertions, 12 deletions
diff --git a/ext/twolame/gsttwolame.c b/ext/twolame/gsttwolame.c
index 53acf20d..3700aa35 100644
--- a/ext/twolame/gsttwolame.c
+++ b/ext/twolame/gsttwolame.c
@@ -62,11 +62,16 @@ GST_DEBUG_CATEGORY_STATIC (debug);
/* TwoLAME can do MPEG-1, MPEG-2 so it has 6 possible
* sample rates it supports */
static GstStaticPadTemplate gst_two_lame_sink_template =
-GST_STATIC_PAD_TEMPLATE ("sink",
+ GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
- GST_STATIC_CAPS ("audio/x-raw-int, "
- "endianness = (int) " G_STRINGIFY (G_BYTE_ORDER) ", "
+ GST_STATIC_CAPS ("audio/x-raw-float, "
+ "endianness = (int) BYTE_ORDER, "
+ "width = (int) 32, "
+ "rate = (int) { 16000, 22050, 24000, 32000, 44100, 48000 }, "
+ "channels = (int) [ 1, 2 ]; "
+ "audio/x-raw-int, "
+ "endianness = (int) BYTE_ORDER, "
"signed = (boolean) true, "
"width = (int) 16, "
"depth = (int) 16, "
@@ -355,6 +360,11 @@ gst_two_lame_sink_setcaps (GstPad * pad, GstCaps * caps)
twolame = GST_TWO_LAME (GST_PAD_PARENT (pad));
structure = gst_caps_get_structure (caps, 0);
+ if (strcmp (gst_structure_get_name (structure), "audio/x-raw-int") == 0)
+ twolame->float_input = FALSE;
+ else
+ twolame->float_input = TRUE;
+
if (!gst_structure_get_int (structure, "rate", &twolame->samplerate))
goto no_rate;
if (!gst_structure_get_int (structure, "channels", &twolame->num_channels))
@@ -720,27 +730,44 @@ gst_two_lame_chain (GstPad * pad, GstBuffer * buf)
data = GST_BUFFER_DATA (buf);
size = GST_BUFFER_SIZE (buf);
- num_samples = size / 2;
+ if (twolame->float_input)
+ num_samples = size / 4;
+ else
+ num_samples = size / 2;
/* allocate space for output */
mp3_buffer_size = 1.25 * num_samples + 16384;
mp3_data = g_malloc (mp3_buffer_size);
if (twolame->num_channels == 1) {
- mp3_size = twolame_encode_buffer (twolame->glopts,
- (short int *) data,
- (short int *) data, num_samples, mp3_data, mp3_buffer_size);
+ if (twolame->float_input)
+ mp3_size = twolame_encode_buffer_float32 (twolame->glopts,
+ (float *) data,
+ (float *) data, num_samples, mp3_data, mp3_buffer_size);
+ else
+ mp3_size = twolame_encode_buffer (twolame->glopts,
+ (short int *) data,
+ (short int *) data, num_samples, mp3_data, mp3_buffer_size);
} else {
- mp3_size = twolame_encode_buffer_interleaved (twolame->glopts,
- (short int *) data,
- num_samples / twolame->num_channels, mp3_data, mp3_buffer_size);
+ if (twolame->float_input)
+ mp3_size = twolame_encode_buffer_float32_interleaved (twolame->glopts,
+ (float *) data,
+ num_samples / twolame->num_channels, mp3_data, mp3_buffer_size);
+ else
+ mp3_size = twolame_encode_buffer_interleaved (twolame->glopts,
+ (short int *) data,
+ num_samples / twolame->num_channels, mp3_data, mp3_buffer_size);
}
GST_LOG_OBJECT (twolame, "encoded %d bytes of audio to %d bytes of mp3",
size, mp3_size);
- duration = gst_util_uint64_scale_int (size, GST_SECOND,
- 2 * twolame->samplerate * twolame->num_channels);
+ if (twolame->float_input)
+ duration = gst_util_uint64_scale_int (size, GST_SECOND,
+ 4 * twolame->samplerate * twolame->num_channels);
+ else
+ duration = gst_util_uint64_scale_int (size, GST_SECOND,
+ 2 * twolame->samplerate * twolame->num_channels);
if (GST_BUFFER_DURATION (buf) != GST_CLOCK_TIME_NONE &&
GST_BUFFER_DURATION (buf) != duration) {
diff --git a/ext/twolame/gsttwolame.h b/ext/twolame/gsttwolame.h
index 53c003f5..d8630c23 100644
--- a/ext/twolame/gsttwolame.h
+++ b/ext/twolame/gsttwolame.h
@@ -56,6 +56,7 @@ struct _GstTwoLame {
gint samplerate;
gint num_channels;
+ gboolean float_input;
gboolean setup;
gint mode;