added helper function to calculate maximum possible sample value based on caps

Original commit message from CVS:
added helper function to calculate maximum possible sample value based
on caps
This commit is contained in:
Thomas Vander Stichele 2001-06-13 15:33:03 +00:00
parent d3b914ad91
commit f9023ba24e
2 changed files with 24 additions and 0 deletions

View file

@ -119,3 +119,24 @@ gst_audio_length (GstPad* pad, GstBuffer* buf)
} }
return length; 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));
}

View file

@ -37,3 +37,6 @@ long gst_audio_frame_rate (GstPad *pad);
/* calculate length in seconds of audio buffer buf based on caps of pad */ /* calculate length in seconds of audio buffer buf based on caps of pad */
double gst_audio_length (GstPad* pad, GstBuffer* buf); 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);