annotate src/libSAD/libSAD.h @ 4232:704607c1f858

1st attempt to integrate dithering and RG engine
author Eugene Zagidullin <e.asphyx@gmail.com>
date Wed, 30 Jan 2008 01:22:37 +0300
parents
children 74c6f3d3cf1d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4232
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
1 /* Scale & Dither library (libSAD)
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
2 * High-precision bit depth converter with ReplayGain support
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
3 *
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
4 * (c)2007 by Eugene Zagidullin (e.asphyx@gmail.com)
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
5 *
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
9 * (at your option) any later version.
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
10 *
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
14 * GNU General Public License for more details.
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
16 * along with this program; if not, write to the Free Software
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
18 */
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
19
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
20 #ifndef COMMON_H
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
21 #define COMMON_H
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
22
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
23 #include <stdio.h>
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
24 #include <stdlib.h>
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
25 #include <sys/types.h>
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
26 #include <math.h>
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
27
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
28 #ifndef TRUE
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
29 #define TRUE 1
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
30 #endif
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
31
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
32 #ifndef FALSE
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
33 #define FALSE 0
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
34 #endif
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
35
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
36 #include "../config.h"
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
37
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
38 #ifdef ENABLE_NLS
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
39 # include <libintl.h>
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
40 # include <locale.h>
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
41 # define _(String) dgettext(PACKAGE,String)
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
42 #else
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
43 # define _(String) (String)
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
44 #endif
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
45
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
46 typedef u_int8_t sad_uint8;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
47 typedef int8_t sad_sint8;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
48
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
49 #if SIZEOF_SHORT == 2
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
50 typedef unsigned short sad_uint16;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
51 typedef short sad_sint16;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
52 #else
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
53 # error "Unsupported sizeof(short)"
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
54 #endif
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
55
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
56 #if SIZEOF_INT == 4
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
57 typedef unsigned int sad_uint32;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
58 typedef int sad_sint32;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
59 #else
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
60 # error "Unsupported sizeof(int)"
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
61 #endif
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
62
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
63 typedef size_t sad_size_t;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
64
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
65 typedef int SAD_error;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
66
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
67 typedef enum {
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
68 SAD_SAMPLE_S8,
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
69 SAD_SAMPLE_U8,
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
70 SAD_SAMPLE_S16,
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
71 SAD_SAMPLE_S16_LE,
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
72 SAD_SAMPLE_S16_BE,
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
73 SAD_SAMPLE_U16,
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
74 SAD_SAMPLE_U16_LE,
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
75 SAD_SAMPLE_U16_BE,
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
76 SAD_SAMPLE_S24,
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
77 SAD_SAMPLE_S24_LE,
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
78 SAD_SAMPLE_S24_BE,
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
79 SAD_SAMPLE_U24,
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
80 SAD_SAMPLE_U24_LE,
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
81 SAD_SAMPLE_U24_BE,
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
82 SAD_SAMPLE_S32,
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
83 SAD_SAMPLE_S32_LE,
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
84 SAD_SAMPLE_S32_BE,
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
85 SAD_SAMPLE_U32,
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
86 SAD_SAMPLE_U32_LE,
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
87 SAD_SAMPLE_U32_BE,
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
88 SAD_SAMPLE_FIXED32,
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
89 SAD_SAMPLE_FLOAT,
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
90 SAD_SAMPLE_MAX /*EOF*/
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
91 } SAD_sample_format;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
92
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
93 /* sample format -> sample size */
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
94 static inline sad_size_t sf2ss(SAD_sample_format fmt) {
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
95 switch(fmt) {
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
96 case SAD_SAMPLE_S8:
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
97 case SAD_SAMPLE_U8: return sizeof(sad_sint8);
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
98 case SAD_SAMPLE_S16:
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
99 case SAD_SAMPLE_S16_LE:
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
100 case SAD_SAMPLE_S16_BE:
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
101 case SAD_SAMPLE_U16:
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
102 case SAD_SAMPLE_U16_LE:
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
103 case SAD_SAMPLE_U16_BE: return sizeof(sad_sint16);
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
104 case SAD_SAMPLE_S24:
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
105 case SAD_SAMPLE_S24_LE:
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
106 case SAD_SAMPLE_S24_BE:
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
107 case SAD_SAMPLE_U24:
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
108 case SAD_SAMPLE_U24_LE:
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
109 case SAD_SAMPLE_U24_BE:
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
110 case SAD_SAMPLE_S32:
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
111 case SAD_SAMPLE_S32_LE:
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
112 case SAD_SAMPLE_S32_BE:
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
113 case SAD_SAMPLE_U32:
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
114 case SAD_SAMPLE_U32_LE:
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
115 case SAD_SAMPLE_U32_BE:
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
116 case SAD_SAMPLE_FIXED32: return sizeof(sad_sint32);
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
117 case SAD_SAMPLE_FLOAT: return sizeof(float);
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
118 default: return 0;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
119 }
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
120 }
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
121
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
122 typedef enum {
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
123 SAD_CHORDER_INTERLEAVED,
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
124 SAD_CHORDER_SEPARATED,
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
125 SAD_CHORDER_MAX /*EOF*/
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
126 } SAD_channels_order;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
127
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
128 typedef struct {
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
129 SAD_sample_format sample_format;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
130 int fracbits; /* for fixed-point only */
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
131 int channels;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
132 SAD_channels_order channels_order;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
133 int samplerate;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
134 } SAD_buffer_format;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
135
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
136 static inline sad_size_t bytes2frames(SAD_buffer_format *fmt, sad_size_t bytes) {
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
137 return bytes / sf2ss(fmt->sample_format) / fmt->channels;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
138 }
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
139
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
140 static inline sad_size_t frames2bytes(SAD_buffer_format *fmt, sad_size_t frames) {
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
141 return frames * sf2ss(fmt->sample_format) * fmt->channels;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
142 }
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
143
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
144 static inline float db2scale(float db) {
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
145 return pow(10, db / 20);
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
146 }
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
147
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
148 enum {
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
149 SAD_RG_NONE,
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
150 SAD_RG_TRACK,
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
151 SAD_RG_ALBUM
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
152 };
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
153
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
154 #define SAD_ERROR_OK 0
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
155 #define SAD_ERROR_FAIL -1
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
156
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
157 #ifdef DEBUG
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
158 #define DEBUG_MSG(f,x) {printf("debug: "f, x);}
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
159 #else
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
160 #define DEBUG_MSG(f,x) {}
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
161 #endif
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
162
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
163 typedef struct {
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
164 int present;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
165 float track_gain; // in dB !!!
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
166 float track_peak;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
167 float album_gain;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
168 float album_peak;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
169 } SAD_replaygain_info;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
170
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
171 typedef struct {
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
172 int mode;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
173 int clipping_prevention;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
174 int hard_limit;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
175 float preamp;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
176 } SAD_replaygain_mode;
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
177
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
178
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
179 #endif /* COMMON_H */
704607c1f858 1st attempt to integrate dithering and RG engine
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
180