Tizen 2.1 base
[profile/ivi/gst-plugins-base0.10.git] / gst / audioconvert / audioconvert.h
1 /* GStreamer
2  * Copyright (C) 2004 Ronald Bultje <rbultje@ronald.bitfreak.net>
3  *
4  * audioconvert.h: audio format conversion library
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21
22 #ifndef __AUDIO_CONVERT_H__
23 #define __AUDIO_CONVERT_H__
24
25 #include <gst/gst.h>
26 #include <gst/audio/multichannel.h>
27
28 GST_DEBUG_CATEGORY_EXTERN (audio_convert_debug);
29 #define GST_CAT_DEFAULT (audio_convert_debug)
30
31 /**
32  * GstAudioConvertDithering:
33  * @DITHER_NONE: No dithering
34  * @DITHER_RPDF: Rectangular dithering
35  * @DITHER_TPDF: Triangular dithering (default)
36  * @DITHER_TPDF_HF: High frequency triangular dithering
37  *
38  * Set of available dithering methods when converting audio.
39  */
40 typedef enum
41 {
42   DITHER_NONE = 0,
43   DITHER_RPDF,
44   DITHER_TPDF,
45   DITHER_TPDF_HF
46 } GstAudioConvertDithering;
47
48 /**
49  * GstAudioConvertNoiseShaping:
50  * @NOISE_SHAPING_NONE: No noise shaping (default)
51  * @NOISE_SHAPING_ERROR_FEEDBACK: Error feedback
52  * @NOISE_SHAPING_SIMPLE: Simple 2-pole noise shaping
53  * @NOISE_SHAPING_MEDIUM: Medium 5-pole noise shaping
54  * @NOISE_SHAPING_HIGH: High 8-pole noise shaping
55  *
56  * Set of available noise shaping methods
57  */
58 typedef enum
59 {
60   NOISE_SHAPING_NONE = 0,
61   NOISE_SHAPING_ERROR_FEEDBACK,
62   NOISE_SHAPING_SIMPLE,
63   NOISE_SHAPING_MEDIUM,
64   NOISE_SHAPING_HIGH
65 } GstAudioConvertNoiseShaping;
66
67 typedef struct _AudioConvertCtx AudioConvertCtx;
68 typedef struct _AudioConvertFmt AudioConvertFmt;
69
70 struct _AudioConvertFmt
71 {
72   /* general caps */
73   gboolean is_int;
74   gint endianness;
75   gint width;
76   gint rate;
77   gint channels;
78   GstAudioChannelPosition *pos;
79   gboolean unpositioned_layout;
80
81   /* int audio caps */
82   gboolean sign;
83   gint depth;
84
85   gint unit_size;
86 };
87
88 typedef void (*AudioConvertUnpack) (gpointer src, gpointer dst, gint scale,
89     gint count);
90 typedef void (*AudioConvertPack) (gpointer src, gpointer dst, gint scale,
91     gint count);
92
93 typedef void (*AudioConvertMix) (AudioConvertCtx *, gpointer, gpointer, gint);
94 typedef void (*AudioConvertQuantize) (AudioConvertCtx * ctx, gpointer src,
95     gpointer dst, gint count);
96
97 struct _AudioConvertCtx
98 {
99   AudioConvertFmt in;
100   AudioConvertFmt out;
101
102   AudioConvertUnpack unpack;
103   AudioConvertPack pack;
104
105   /* channel conversion matrix, m[in_channels][out_channels].
106    * If identity matrix, passthrough applies. */
107   gfloat **matrix;
108   /* temp storage for channelmix */
109   gpointer tmp;
110
111   gboolean in_default;
112   gboolean mix_passthrough;
113   gboolean out_default;
114
115   gpointer tmpbuf;
116   gint tmpbufsize;
117
118   gint in_scale;
119   gint out_scale;
120
121   AudioConvertMix channel_mix;
122
123   AudioConvertQuantize quantize;
124
125   GstAudioConvertDithering dither;
126   GstAudioConvertNoiseShaping ns;
127   /* last random number generated per channel for hifreq TPDF dither */
128   gpointer last_random;
129   /* contains the past quantization errors, error[out_channels][count] */
130   gdouble *error_buf;
131 };
132
133 gboolean audio_convert_clean_fmt (AudioConvertFmt * fmt);
134
135 gboolean audio_convert_prepare_context (AudioConvertCtx * ctx,
136     AudioConvertFmt * in, AudioConvertFmt * out,
137     GstAudioConvertDithering dither, GstAudioConvertNoiseShaping ns);
138 gboolean audio_convert_get_sizes (AudioConvertCtx * ctx, gint samples,
139     gint * srcsize, gint * dstsize);
140
141 gboolean audio_convert_clean_context (AudioConvertCtx * ctx);
142
143 gboolean audio_convert_convert (AudioConvertCtx * ctx, gpointer src,
144     gpointer dst, gint samples, gboolean src_writable);
145
146 #endif /* __AUDIO_CONVERT_H__ */