1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
/* GStreamer
* Copyright (C) 2004 Ronald Bultje <rbultje@ronald.bitfreak.net>
*
* audioconvert.h: audio format conversion library
*
* 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.
*/
#ifndef __AUDIO_CONVERT_H__
#define __AUDIO_CONVERT_H__
#include <gst/gst.h>
#include <gst/audio/multichannel.h>
GST_DEBUG_CATEGORY_EXTERN (audio_convert_debug);
#define GST_CAT_DEFAULT (audio_convert_debug)
/**
* GstAudioConvertDithering:
* @DITHER_NONE: No dithering
* @DITHER_RPDF: Rectangular dithering
* @DITHER_TPDF: Triangular dithering (default)
* @DITHER_TPDF_HF: High frequency triangular dithering
*
* Set of available dithering methods when converting audio.
*/
typedef enum
{
DITHER_NONE = 0,
DITHER_RPDF,
DITHER_TPDF,
DITHER_TPDF_HF
} GstAudioConvertDithering;
/**
* GstAudioConvertNoiseShaping:
* @NOISE_SHAPING_NONE: No noise shaping (default)
* @NOISE_SHAPING_ERROR_FEEDBACK: Error feedback
* @NOISE_SHAPING_SIMPLE: Simple 2-pole noise shaping
* @NOISE_SHAPING_MEDIUM: Medium 5-pole noise shaping
* @NOISE_SHAPING_HIGH: High 8-pole noise shaping
*
* Set of available noise shaping methods
*/
typedef enum
{
NOISE_SHAPING_NONE = 0,
NOISE_SHAPING_ERROR_FEEDBACK,
NOISE_SHAPING_SIMPLE,
NOISE_SHAPING_MEDIUM,
NOISE_SHAPING_HIGH
} GstAudioConvertNoiseShaping;
typedef struct _AudioConvertCtx AudioConvertCtx;
typedef struct _AudioConvertFmt AudioConvertFmt;
struct _AudioConvertFmt
{
/* general caps */
gboolean is_int;
gint endianness;
gint width;
gint rate;
gint channels;
GstAudioChannelPosition *pos;
gboolean unpositioned_layout;
/* int audio caps */
gboolean sign;
gint depth;
gint unit_size;
};
typedef void (*AudioConvertUnpack) (gpointer src, gpointer dst, gint scale,
gint count);
typedef void (*AudioConvertPack) (gpointer src, gpointer dst, gint scale,
gint count);
typedef void (*AudioConvertMix) (AudioConvertCtx *, gpointer, gpointer, gint);
typedef void (*AudioConvertQuantize) (AudioConvertCtx * ctx, gpointer src,
gpointer dst, gint count);
struct _AudioConvertCtx
{
AudioConvertFmt in;
AudioConvertFmt out;
AudioConvertUnpack unpack;
AudioConvertPack pack;
/* channel conversion matrix, m[in_channels][out_channels].
* If identity matrix, passthrough applies. */
gfloat **matrix;
/* temp storage for channelmix */
gpointer tmp;
gboolean in_default;
gboolean mix_passthrough;
gboolean out_default;
gpointer tmpbuf;
gint tmpbufsize;
gint in_scale;
gint out_scale;
AudioConvertMix channel_mix;
AudioConvertQuantize quantize;
GstAudioConvertDithering dither;
GstAudioConvertNoiseShaping ns;
/* last random number generated per channel for hifreq TPDF dither */
gpointer last_random;
/* contains the past quantization errors, error[out_channels][count] */
gdouble *error_buf;
};
gboolean audio_convert_clean_fmt (AudioConvertFmt * fmt);
gboolean audio_convert_prepare_context (AudioConvertCtx * ctx,
AudioConvertFmt * in, AudioConvertFmt * out,
GstAudioConvertDithering dither, GstAudioConvertNoiseShaping ns);
gboolean audio_convert_get_sizes (AudioConvertCtx * ctx, gint samples,
gint * srcsize, gint * dstsize);
gboolean audio_convert_clean_context (AudioConvertCtx * ctx);
gboolean audio_convert_convert (AudioConvertCtx * ctx, gpointer src,
gpointer dst, gint samples, gboolean src_writable);
#endif /* __AUDIO_CONVERT_H__ */
|