gstaudio

## gstaudio gstaudio — Support library for audio elements |

## Synopsis

    #include <gst/audio/audio.h>

    enum                GstAudioFieldFlag;
    #define             GST_FRAMES_TO_CLOCK_TIME            (frames, rate)
    #define             GST_CLOCK_TIME_TO_FRAMES            (clocktime, rate)
    #define             GST_AUDIO_DEF_RATE
    #define             GST_AUDIO_FLOAT_PAD_TEMPLATE_CAPS
    #define             GST_AUDIO_FLOAT_STANDARD_PAD_TEMPLATE_CAPS
    #define             GST_AUDIO_INT_PAD_TEMPLATE_CAPS
    #define             GST_AUDIO_INT_STANDARD_PAD_TEMPLATE_CAPS
    int                 gst_audio_frame_byte_size           (GstPad *pad);
    long                gst_audio_frame_length              (GstPad *pad,
                                                             GstBuffer *buf);
    GstClockTime        gst_audio_duration_from_pad_buffer  (GstPad *pad,
                                                             GstBuffer *buf);
    gboolean            gst_audio_is_buffer_framed          (GstPad *pad,
                                                             GstBuffer *buf);
    void                gst_audio_structure_set_int         (GstStructure *structure,
                                                             GstAudioFieldFlag flag);
    GstBuffer *         gst_audio_buffer_clip               (GstBuffer *buffer,
                                                             GstSegment *segment,
                                                             gint rate,
                                                             gint frame_size);

## Description

This library contains some helper functions for audio elements.

## Details

### enum GstAudioFieldFlag

    typedef enum {
      GST_AUDIO_FIELD_RATE          = (1 << 0),
      GST_AUDIO_FIELD_CHANNELS      = (1 << 1),
      GST_AUDIO_FIELD_ENDIANNESS    = (1 << 2),
      GST_AUDIO_FIELD_WIDTH         = (1 << 3),
      GST_AUDIO_FIELD_DEPTH         = (1 << 4),
      GST_AUDIO_FIELD_SIGNED        = (1 << 5)
    } GstAudioFieldFlag;

### Warning

`GstAudioFieldFlag` is deprecated and should not be used in newly-written code. use `gst_structure_set()` directly

Do not use anymore.

### GST_FRAMES_TO_CLOCK_TIME()

    #define             GST_FRAMES_TO_CLOCK_TIME(frames, rate)

Calculate clocktime from sample `frames` and `rate`.

`frames` : | sample frames
`rate` : | sampling rate

### GST_CLOCK_TIME_TO_FRAMES()

    #define             GST_CLOCK_TIME_TO_FRAMES(clocktime, rate)

Calculate frames from `clocktime` and sample `rate`.

`clocktime` : | clock time
`rate` : | sampling rate

### GST_AUDIO_DEF_RATE

    #define GST_AUDIO_DEF_RATE 44100

Standard sampling rate used in consumer audio.

### GST_AUDIO_FLOAT_PAD_TEMPLATE_CAPS

    #define             GST_AUDIO_FLOAT_PAD_TEMPLATE_CAPS

Template caps for float audio. Can be used when defining a GstStaticPadTemplate

### GST_AUDIO_FLOAT_STANDARD_PAD_TEMPLATE_CAPS

    #define             GST_AUDIO_FLOAT_STANDARD_PAD_TEMPLATE_CAPS

Template caps for 32bit float mono audio in native byte-order. Can be used when defining a GstStaticPadTemplate

### GST_AUDIO_INT_PAD_TEMPLATE_CAPS

    #define             GST_AUDIO_INT_PAD_TEMPLATE_CAPS

Template caps for integer audio. Can be used when defining a GstStaticPadTemplate

### GST_AUDIO_INT_STANDARD_PAD_TEMPLATE_CAPS

    #define             GST_AUDIO_INT_STANDARD_PAD_TEMPLATE_CAPS

Template caps for 16bit integer stereo audio in native byte-order. Can be used when defining a GstStaticPadTemplate

### gst_audio_frame_byte_size ()

    int                 gst_audio_frame_byte_size           (GstPad *pad);

Calculate byte size of an audio frame.

`pad` : | the GstPad to get the caps from
Returns : | the byte size, or 0 if there was an error

### gst_audio_frame_length ()

    long                gst_audio_frame_length              (GstPad *pad,
                                                             GstBuffer *buf);

Calculate length of buffer in frames.

`pad` : | the GstPad to get the caps from
`buf` : | the GstBuffer
Returns : | 0 if there's an error, or the number of frames if everything's ok

### gst_audio_duration_from_pad_buffer ()

    GstClockTime        gst_audio_duration_from_pad_buffer  (GstPad *pad,
                                                             GstBuffer *buf);

Calculate length in nanoseconds of audio buffer `buf` based on capabilities of `pad`.

`pad` : | the GstPad to get the caps from
`buf` : | the GstBuffer
Returns : | the length.

### gst_audio_is_buffer_framed ()

    gboolean            gst_audio_is_buffer_framed          (GstPad *pad,
                                                             GstBuffer *buf);

Check if the buffer size is a whole multiple of the frame size.

`pad` : | the GstPad to get the caps from
`buf` : | the GstBuffer
Returns : | `TRUE` if buffer size is multiple.

### gst_audio_structure_set_int ()

    void                gst_audio_structure_set_int         (GstStructure *structure,
                                                             GstAudioFieldFlag flag);

### Warning

`gst_audio_structure_set_int` is deprecated and should not be used in newly-written code. use `gst_structure_set()`

Do not use anymore.

`structure` : | a GstStructure
`flag` : | a set of GstAudioFieldFlag

### gst_audio_buffer_clip ()

    GstBuffer *         gst_audio_buffer_clip               (GstBuffer *buffer,
                                                             GstSegment *segment,
                                                             gint rate,
                                                             gint frame_size);

Clip the the buffer to the given `GstSegment`.

After calling this function the caller does not own a reference to `buffer` anymore.

`buffer` : | The buffer to clip.
`segment` : | Segment in `GST_FORMAT_TIME` or `GST_FORMAT_DEFAULT` to which the buffer should be clipped.
`rate` : | sample rate.
`frame_size` : | size of one audio frame in bytes.
Returns : | `NULL` if the buffer is completely outside the configured segment, otherwise the clipped buffer is returned. If the buffer has no timestamp, it is assumed to be inside the segment and is not clipped

Since 0.10.14