audio.h 5.92 KB
Newer Older
Andy Wingo Wingo's avatar
Andy Wingo Wingo committed
1
/* GStreamer
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
 * Library       <2001> Thomas Vander Stichele <thomas@apestaart.org>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include <gst/gst.h>

23
24
25
#ifndef __GST_AUDIO_AUDIO_H__
#define __GST_AUDIO_AUDIO_H__

26
G_BEGIN_DECLS
Johan Dahlin's avatar
Johan Dahlin committed
27

28
/* For people that are looking at this source: the purpose of these defines is
29
30
31
 * to make GstCaps a bit easier, in that you don't have to know all of the
 * properties that need to be defined. you can just use these macros. currently
 * (8/01) the only plugins that use these are the passthrough, speed, volume,
32
33
 * adder, and [de]interleave plugins. These are for convenience only, and do not
 * specify the 'limits' of GStreamer. you might also use these definitions as a
34
35
 * base for making your own caps, if need be.
 *
36
37
38
39
40
41
42
43
44
45
46
47
48
49
 * For example, to make a source pad that can output streams of either mono
 * float or any channel int:
 *
 *  template = gst_pad_template_new
 *    ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
 *    gst_caps_append(gst_caps_new ("sink_int",  "audio/x-raw-int",
 *                                  GST_AUDIO_INT_PAD_TEMPLATE_PROPS),
 *                    gst_caps_new ("sink_float", "audio/x-raw-float",
 *                                  GST_AUDIO_FLOAT_PAD_TEMPLATE_PROPS)),
 *    NULL);
 *
 *  sinkpad = gst_pad_new_from_template(template, "sink");
 *
 * Andy Wingo, 18 August 2001
50
 * Thomas, 6 September 2002 */
Johan Dahlin's avatar
Johan Dahlin committed
51

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
52
/* conversion macros */
53
54
55
56
57
58
59
/**
 * GST_FRAMES_TO_CLOCK_TIME:
 * @frames: sample frames
 * @rate: sampling rate
 * 
 * Calculate clocktime from sample @frames and @rate.
 */
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
60
#define GST_FRAMES_TO_CLOCK_TIME(frames, rate) \
61
  ((GstClockTime) gst_util_uint64_scale_round (frames, GST_SECOND, rate))
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
62

63
64
65
66
67
68
69
/**
 * GST_CLOCK_TIME_TO_FRAMES:
 * @clocktime: clock time
 * @rate: sampling rate
 * 
 * Calculate frames from @clocktime and sample @rate.
 */
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
70
#define GST_CLOCK_TIME_TO_FRAMES(clocktime, rate) \
71
  gst_util_uint64_scale_round (clocktime, rate, GST_SECOND)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
72

73
74
75
76
77
/**
 * GST_AUDIO_DEF_RATE:
 * 
 * Standard sampling rate used in consumer audio.
 */
78
#define GST_AUDIO_DEF_RATE 44100
Johan Dahlin's avatar
Johan Dahlin committed
79

80
81
82
83
84
85
/**
 * GST_AUDIO_INT_PAD_TEMPLATE_CAPS:
 * 
 * Template caps for integer audio. Can be used when defining a 
 * #GstStaticPadTemplate
 */
David Schleef's avatar
David Schleef committed
86
87
88
89
90
#define GST_AUDIO_INT_PAD_TEMPLATE_CAPS \
  "audio/x-raw-int, " \
  "rate = (int) [ 1, MAX ], " \
  "channels = (int) [ 1, MAX ], " \
  "endianness = (int) { LITTLE_ENDIAN, BIG_ENDIAN }, " \
91
  "width = (int) { 8, 16, 24, 32 }, " \
David Schleef's avatar
David Schleef committed
92
  "depth = (int) [ 1, 32 ], " \
93
  "signed = (boolean) { true, false }"
Johan Dahlin's avatar
Johan Dahlin committed
94

95
96
97
98
99
100
/**
 * 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
 */
David Schleef's avatar
David Schleef committed
101
102
103
104
105
106
107
#define GST_AUDIO_INT_STANDARD_PAD_TEMPLATE_CAPS \
  "audio/x-raw-int, " \
  "rate = (int) [ 1, MAX ], " \
  "channels = (int) 2, " \
  "endianness = (int) BYTE_ORDER, " \
  "width = (int) 16, " \
  "depth = (int) 16, " \
108
  "signed = (boolean) true"
Johan Dahlin's avatar
Johan Dahlin committed
109

110
111
112
113
114
115
/**
 * GST_AUDIO_FLOAT_PAD_TEMPLATE_CAPS:
 * 
 * Template caps for float audio. Can be used when defining a 
 * #GstStaticPadTemplate
 */
David Schleef's avatar
David Schleef committed
116
117
118
119
120
#define GST_AUDIO_FLOAT_PAD_TEMPLATE_CAPS \
  "audio/x-raw-float, " \
  "rate = (int) [ 1, MAX ], " \
  "channels = (int) [ 1, MAX ], " \
  "endianness = (int) { LITTLE_ENDIAN , BIG_ENDIAN }, " \
Wim Taymans's avatar
Wim Taymans committed
121
  "width = (int) { 32, 64 }"
Johan Dahlin's avatar
Johan Dahlin committed
122

123
124
125
126
127
128
/**
 * 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
 */
David Schleef's avatar
David Schleef committed
129
130
#define GST_AUDIO_FLOAT_STANDARD_PAD_TEMPLATE_CAPS \
  "audio/x-raw-float, " \
131
  "width = (int) 32, " \
David Schleef's avatar
David Schleef committed
132
133
  "rate = (int) [ 1, MAX ], " \
  "channels = (int) 1, " \
Wim Taymans's avatar
Wim Taymans committed
134
  "endianness = (int) BYTE_ORDER"
Johan Dahlin's avatar
Johan Dahlin committed
135

136
137
138
139
/*
 * this library defines and implements some helper functions for audio
 * handling
 */
Johan Dahlin's avatar
Johan Dahlin committed
140

141
/* get byte size of audio frame (based on caps of pad */
Johan Dahlin's avatar
Johan Dahlin committed
142
int      gst_audio_frame_byte_size      (GstPad* pad);
143
144

/* get length in frames of buffer */
Johan Dahlin's avatar
Johan Dahlin committed
145
long     gst_audio_frame_length         (GstPad* pad, GstBuffer* buf);
146

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

149
/* check if the buffer size is a whole multiple of the frame size */
Johan Dahlin's avatar
Johan Dahlin committed
150
gboolean gst_audio_is_buffer_framed     (GstPad* pad, GstBuffer* buf);
151

152
/* functions useful for _getcaps functions */
153
154
/**
 * GstAudioFieldFlag:
155
156
157
158
159
160
 * @GST_AUDIO_FIELD_RATE: add rate field to caps
 * @GST_AUDIO_FIELD_CHANNELS: add channels field to caps
 * @GST_AUDIO_FIELD_ENDIANNESS: add endianness field to caps
 * @GST_AUDIO_FIELD_WIDTH: add width field to caps
 * @GST_AUDIO_FIELD_DEPTH: add depth field to caps
 * @GST_AUDIO_FIELD_SIGNED: add signed field to caps
161
162
 *
 * Do not use anymore.
163
164
 *
 * Deprecated: use gst_structure_set() directly
165
 */
166
#ifndef GST_DISABLE_DEPRECATED
Johan Dahlin's avatar
Johan Dahlin committed
167
168
169
170
171
172
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),
173
  GST_AUDIO_FIELD_SIGNED        = (1 << 5)
174
} GstAudioFieldFlag;
175
#endif
176

177
#ifndef GST_DISABLE_DEPRECATED
Johan Dahlin's avatar
Johan Dahlin committed
178
void gst_audio_structure_set_int (GstStructure *structure, GstAudioFieldFlag flag);
179
180
181
#endif /* GST_DISABLE_DEPRECATED */

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

183
G_END_DECLS
Johan Dahlin's avatar
Johan Dahlin committed
184

185
#endif /* __GST_AUDIO_AUDIO_H__ */