diff --git a/libs/audio/gstaudio.c b/libs/audio/gstaudio.c index 0b71609482..04d5b6bd63 100644 --- a/libs/audio/gstaudio.c +++ b/libs/audio/gstaudio.c @@ -119,3 +119,24 @@ gst_audio_length (GstPad* pad, GstBuffer* buf) } return length; } + +long +gst_audio_highest_sample_value (GstPad* pad) +/* calculate highest possible sample value + * based on capabilities of pad + */ +{ + gboolean is_signed = FALSE; + gint width = 0; + GstCaps *caps = NULL; + + caps = GST_PAD_CAPS (pad); + // FIXME : Please change this to a better warning method ! + if (caps == NULL) + printf ("WARNING: gstaudio: could not get caps of pad !\n"); + width = gst_caps_get_int (caps, "width"); + is_signed = gst_caps_get_boolean (caps, "signed"); + if (is_signed) --width; + /* example : 16 bit, signed : samples between -32768 and 32767 */ + return ((long) (1 << width)); +} diff --git a/libs/audio/gstaudio.h b/libs/audio/gstaudio.h index 4b0e081cec..c0d82ff9e4 100644 --- a/libs/audio/gstaudio.h +++ b/libs/audio/gstaudio.h @@ -37,3 +37,6 @@ long gst_audio_frame_rate (GstPad *pad); /* calculate length in seconds of audio buffer buf based on caps of pad */ double gst_audio_length (GstPad* pad, GstBuffer* buf); +/* calculate highest possible sample value based on capabilities of pad */ +long gst_audio_highest_sample_value (GstPad* pad); +