Mercurial > audlegacy
annotate src/libSAD/common.h @ 4772:a98a8104f2eb
Add check for 'tr' in configure.
| author | Matti Hamalainen <ccr@tnsp.org> |
|---|---|
| date | Fri, 29 Aug 2008 02:03:58 +0300 |
| parents | bb0638143fc8 |
| children |
| rev | line source |
|---|---|
| 4246 | 1 /* Scale & Dither library (libSAD) |
| 2 * High-precision bit depth converter with ReplayGain support | |
| 3 * | |
| 4 * Copyright (c) 2007-2008 Eugene Zagidullin (e.asphyx@gmail.com) | |
| 5 * | |
| 6 * This program is free software; you can redistribute it and/or modify | |
| 7 * it under the terms of the GNU General Public License as published by | |
| 8 * the Free Software Foundation; either version 2 of the License, or | |
| 9 * (at your option) any later version. | |
| 10 * | |
| 11 * This program 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 | |
| 14 * GNU General Public License for more details. | |
| 15 * You should have received a copy of the GNU General Public License | |
| 16 * along with this program; if not, write to the Free Software | |
| 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 18 */ | |
| 19 | |
| 4262 | 20 #ifndef LIBSAD_COMMON_H |
| 21 #define LIBSAD_COMMON_H | |
| 4246 | 22 |
| 23 #include <stdio.h> | |
| 24 #include <stdlib.h> | |
| 25 #include <sys/types.h> | |
| 26 #include <math.h> | |
| 27 #include <inttypes.h> | |
| 28 | |
| 29 #ifndef TRUE | |
| 30 #define TRUE 1 | |
| 31 #endif | |
| 32 | |
| 33 #ifndef FALSE | |
| 34 #define FALSE 0 | |
| 35 #endif | |
| 36 | |
| 4260 | 37 #ifdef HAVE_CONFIG_H |
| 38 # include "config.h" | |
| 39 #endif | |
| 4246 | 40 |
| 41 typedef int SAD_error; | |
| 42 | |
| 43 typedef enum { | |
| 44 SAD_SAMPLE_S8, | |
| 45 SAD_SAMPLE_U8, | |
| 46 SAD_SAMPLE_S16, | |
| 47 SAD_SAMPLE_S16_LE, | |
| 48 SAD_SAMPLE_S16_BE, | |
| 49 SAD_SAMPLE_U16, | |
| 50 SAD_SAMPLE_U16_LE, | |
| 51 SAD_SAMPLE_U16_BE, | |
| 52 SAD_SAMPLE_S24, | |
| 53 SAD_SAMPLE_S24_LE, | |
| 54 SAD_SAMPLE_S24_BE, | |
| 55 SAD_SAMPLE_U24, | |
| 56 SAD_SAMPLE_U24_LE, | |
| 57 SAD_SAMPLE_U24_BE, | |
| 58 SAD_SAMPLE_S32, | |
| 59 SAD_SAMPLE_S32_LE, | |
| 60 SAD_SAMPLE_S32_BE, | |
| 61 SAD_SAMPLE_U32, | |
| 62 SAD_SAMPLE_U32_LE, | |
| 63 SAD_SAMPLE_U32_BE, | |
| 64 SAD_SAMPLE_FIXED32, | |
| 65 SAD_SAMPLE_FLOAT, | |
| 66 SAD_SAMPLE_MAX /*EOF*/ | |
| 67 } SAD_sample_format; | |
| 68 | |
| 69 /* sample format -> sample size */ | |
| 70 static inline unsigned sf2ss(SAD_sample_format fmt) { | |
| 71 switch(fmt) { | |
| 72 case SAD_SAMPLE_S8: | |
| 73 case SAD_SAMPLE_U8: return sizeof(int8_t); | |
| 74 case SAD_SAMPLE_S16: | |
| 75 case SAD_SAMPLE_S16_LE: | |
| 76 case SAD_SAMPLE_S16_BE: | |
| 77 case SAD_SAMPLE_U16: | |
| 78 case SAD_SAMPLE_U16_LE: | |
| 79 case SAD_SAMPLE_U16_BE: return sizeof(int16_t); | |
| 80 case SAD_SAMPLE_S24: | |
| 81 case SAD_SAMPLE_S24_LE: | |
| 82 case SAD_SAMPLE_S24_BE: | |
| 83 case SAD_SAMPLE_U24: | |
| 84 case SAD_SAMPLE_U24_LE: | |
| 85 case SAD_SAMPLE_U24_BE: | |
| 86 case SAD_SAMPLE_S32: | |
| 87 case SAD_SAMPLE_S32_LE: | |
| 88 case SAD_SAMPLE_S32_BE: | |
| 89 case SAD_SAMPLE_U32: | |
| 90 case SAD_SAMPLE_U32_LE: | |
| 91 case SAD_SAMPLE_U32_BE: | |
| 92 case SAD_SAMPLE_FIXED32: return sizeof(int32_t); | |
| 93 case SAD_SAMPLE_FLOAT: return sizeof(float); | |
| 94 default: return 0; | |
| 95 } | |
| 96 } | |
| 97 | |
| 98 typedef enum { | |
| 99 SAD_CHORDER_INTERLEAVED, | |
| 100 SAD_CHORDER_SEPARATED, | |
| 101 SAD_CHORDER_MAX /*EOF*/ | |
| 102 } SAD_channels_order; | |
| 103 | |
| 104 typedef struct { | |
| 105 SAD_sample_format sample_format; | |
| 106 int fracbits; /* for fixed-point only */ | |
| 107 int channels; | |
| 108 SAD_channels_order channels_order; | |
| 109 int samplerate; | |
| 110 } SAD_buffer_format; | |
| 111 | |
| 112 static inline unsigned bytes2frames(SAD_buffer_format *fmt, unsigned bytes) { | |
| 113 return bytes / sf2ss(fmt->sample_format) / fmt->channels; | |
| 114 } | |
| 115 | |
| 116 static inline unsigned frames2bytes(SAD_buffer_format *fmt, unsigned frames) { | |
| 117 return frames * sf2ss(fmt->sample_format) * fmt->channels; | |
| 118 } | |
| 119 | |
| 120 static inline float db2scale(float db) { | |
| 121 return pow(10, db / 20); | |
| 122 } | |
| 123 | |
| 124 enum { | |
| 125 SAD_RG_NONE, | |
| 126 SAD_RG_TRACK, | |
| 127 SAD_RG_ALBUM | |
| 128 }; | |
| 129 | |
| 130 #define SAD_ERROR_OK 0 | |
| 131 #define SAD_ERROR_FAIL -1 | |
| 132 | |
| 133 typedef struct { | |
| 134 int present; | |
| 135 float track_gain; /* in dB !!! */ | |
| 136 float track_peak; | |
| 137 float album_gain; | |
| 138 float album_peak; | |
| 139 } SAD_replaygain_info; | |
| 140 | |
| 141 typedef struct { | |
| 142 int mode; | |
| 143 int clipping_prevention; | |
| 144 int hard_limit; | |
|
4256
b0ca963fd965
adaptive scaler added, disabled hard limiter
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4246
diff
changeset
|
145 int adaptive_scaler; |
| 4246 | 146 float preamp; /* in dB ! */ |
| 147 } SAD_replaygain_mode; | |
| 148 | |
| 149 | |
| 150 #endif /* COMMON_H */ | |
| 151 |
