gst/audioconvert/: Add support for more than 8 channels and NONE channel layouts...
[platform/upstream/gstreamer.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 typedef enum
29 {
30   DITHER_NONE = 0,
31   DITHER_RPDF,
32   DITHER_TPDF,
33   DITHER_TPDF_HF
34 } DitherType;
35
36 typedef enum
37 {
38   NOISE_SHAPING_NONE = 0,
39   NOISE_SHAPING_ERROR_FEEDBACK,
40   NOISE_SHAPING_SIMPLE,
41   NOISE_SHAPING_MEDIUM,
42   NOISE_SHAPING_HIGH
43 } NoiseShapingType;
44
45 typedef struct _AudioConvertCtx AudioConvertCtx;
46 typedef struct _AudioConvertFmt AudioConvertFmt;
47
48 struct _AudioConvertFmt
49 {
50   /* general caps */
51   gboolean is_int;
52   gint endianness;
53   gint width;
54   gint rate;
55   gint channels;
56   GstAudioChannelPosition *pos;
57   gboolean unpositioned_layout;
58
59   /* int audio caps */
60   gboolean sign;
61   gint depth;
62
63   gint unit_size;
64 };
65
66 typedef void (*AudioConvertUnpack) (gpointer src, gpointer dst, gint scale,
67     gint count);
68 typedef void (*AudioConvertPack) (gpointer src, gpointer dst, gint scale,
69     gint count);
70
71 typedef void (*AudioConvertMix) (AudioConvertCtx *, gpointer, gpointer, gint);
72 typedef void (*AudioConvertQuantize) (AudioConvertCtx * ctx, gpointer src,
73     gpointer dst, gint count);
74
75 struct _AudioConvertCtx
76 {
77   AudioConvertFmt in;
78   AudioConvertFmt out;
79
80   AudioConvertUnpack unpack;
81   AudioConvertPack pack;
82
83   /* channel conversion matrix, m[in_channels][out_channels].
84    * If identity matrix, passthrough applies. */
85   gfloat **matrix;
86   /* temp storage for channelmix */
87   gpointer tmp;
88
89   gboolean in_default;
90   gboolean mix_passthrough;
91   gboolean out_default;
92
93   gpointer tmpbuf;
94   gint tmpbufsize;
95
96   gint in_scale;
97   gint out_scale;
98
99   AudioConvertMix channel_mix;
100
101   AudioConvertQuantize quantize;
102   DitherType dither;
103   NoiseShapingType ns;
104   /* random number generate for dither noise */
105   GRand *dither_random;
106   /* last random number generated per channel for hifreq TPDF dither */
107   gpointer last_random;
108   /* contains the past quantization errors, error[out_channels][count] */
109   gdouble *error_buf;
110 };
111
112 gboolean audio_convert_clean_fmt (AudioConvertFmt * fmt);
113
114 gboolean audio_convert_prepare_context (AudioConvertCtx * ctx,
115     AudioConvertFmt * in, AudioConvertFmt * out, DitherType dither,
116     NoiseShapingType ns);
117 gboolean audio_convert_get_sizes (AudioConvertCtx * ctx, gint samples,
118     gint * srcsize, gint * dstsize);
119
120 gboolean audio_convert_clean_context (AudioConvertCtx * ctx);
121
122 gboolean audio_convert_convert (AudioConvertCtx * ctx, gpointer src,
123     gpointer dst, gint samples, gboolean src_writable);
124
125 #endif /* __AUDIO_CONVERT_H__ */