[651] | 1 | //libroardsp.h: |
---|
| 2 | |
---|
[687] | 3 | /* |
---|
[2316] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008, 2009 |
---|
[687] | 5 | * |
---|
| 6 | * This file is part of libroardsp a part of RoarAudio, |
---|
| 7 | * a cross-platform sound system for both, home and professional use. |
---|
| 8 | * See README for details. |
---|
| 9 | * |
---|
| 10 | * This file is free software; you can redistribute it and/or modify |
---|
| 11 | * it under the terms of the GNU General Public License version 3 |
---|
| 12 | * as published by the Free Software Foundation. |
---|
| 13 | * |
---|
| 14 | * libroardsp is distributed in the hope that it will be useful, |
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 17 | * GNU General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with this software; see the file COPYING. If not, write to |
---|
| 21 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
| 22 | * |
---|
| 23 | */ |
---|
| 24 | |
---|
[651] | 25 | #ifndef _LIBROARDSP_H_ |
---|
| 26 | #define _LIBROARDSP_H_ |
---|
| 27 | |
---|
[652] | 28 | #include <roaraudio.h> |
---|
| 29 | |
---|
[874] | 30 | __BEGIN_DECLS |
---|
| 31 | |
---|
[2992] | 32 | // enable Speex preprocessing and better type handling if speex > 1.1.8 |
---|
| 33 | #ifdef ROAR_HAVE_LIBSPEEX |
---|
| 34 | #include <speex/speex.h> |
---|
| 35 | #ifdef _SPEEX_TYPES_H |
---|
| 36 | #include <speex/speex_preprocess.h> |
---|
| 37 | #endif |
---|
| 38 | #endif |
---|
| 39 | |
---|
[686] | 40 | #include "midi.h" |
---|
[2425] | 41 | #include "synth.h" |
---|
[1368] | 42 | #include "poly.h" |
---|
[2434] | 43 | #include "fader.h" |
---|
[2929] | 44 | #include "mixer.h" |
---|
[2934] | 45 | #include "amp.h" |
---|
[1371] | 46 | #include "convert.h" |
---|
[1626] | 47 | #include "midside.h" |
---|
[2026] | 48 | #include "point.h" |
---|
[2143] | 49 | #include "remove.h" |
---|
[2316] | 50 | #include "rms.h" |
---|
[2169] | 51 | #include "transcode.h" |
---|
[2638] | 52 | #include "vio_transcode.h" |
---|
[686] | 53 | |
---|
[2187] | 54 | #ifdef ROAR_HAVE_LIBCELT |
---|
| 55 | #include "transcode_celt.h" |
---|
| 56 | #endif |
---|
[2294] | 57 | #ifdef ROAR_HAVE_LIBSPEEX |
---|
| 58 | #include "transcode_speex.h" |
---|
| 59 | #endif |
---|
[2187] | 60 | |
---|
[2386] | 61 | #ifdef ROAR_HAVE_LIBSAMPLERATE |
---|
| 62 | #include <samplerate.h> |
---|
| 63 | #endif |
---|
| 64 | |
---|
[659] | 65 | // defines |
---|
| 66 | #define ROARDSP_MAX_FILTERS_PER_CHAIN 8 |
---|
| 67 | |
---|
[662] | 68 | #define ROARDSP_FILTER_NONE 0 |
---|
| 69 | #define ROARDSP_FILTER_AMP 1 |
---|
| 70 | #define ROARDSP_FILTER_LOWP 2 |
---|
| 71 | #define ROARDSP_FILTER_HIGHP 3 |
---|
[979] | 72 | #define ROARDSP_FILTER_MODULATE 4 |
---|
| 73 | #define ROARDSP_FILTER_QUANTIFY 5 |
---|
| 74 | #define ROARDSP_FILTER_CLIP 6 |
---|
| 75 | #define ROARDSP_FILTER_ADD 7 |
---|
[1004] | 76 | #define ROARDSP_FILTER_DOWNMIX 8 |
---|
[1100] | 77 | #define ROARDSP_FILTER_DCBLOCK 9 |
---|
[1587] | 78 | #define ROARDSP_FILTER_SWAP 10 |
---|
[2979] | 79 | #define ROARDSP_FILTER_SPEEX_PREP 11 |
---|
| 80 | #define ROARDSP_FILTER_AGC 12 |
---|
[662] | 81 | |
---|
[672] | 82 | // filter CTLs: |
---|
| 83 | |
---|
[2992] | 84 | #define ROARDSP_FCTL_FREQ 1 /* float */ |
---|
[672] | 85 | #define ROARDSP_FCTL_TIME 2 |
---|
[3004] | 86 | #define ROARDSP_FCTL_MUL 3 /* int32_t */ |
---|
| 87 | #define ROARDSP_FCTL_DIV 4 /* int32_t */ |
---|
| 88 | #define ROARDSP_FCTL_N 5 /* int32_t */ |
---|
| 89 | #define ROARDSP_FCTL_LIMIT 6 /* int32_t */ |
---|
[979] | 90 | #define ROARDSP_FCTL_PHASE 7 |
---|
[3004] | 91 | #define ROARDSP_FCTL_Q 8 /* int32_t */ |
---|
| 92 | #define ROARDSP_FCTL_MODE 9 /* int32_t */ |
---|
[2992] | 93 | #define ROARDSP_FCTL_PACKET_SIZE 10 /* size_t */ |
---|
[672] | 94 | |
---|
[2989] | 95 | // consts for filter flags: |
---|
| 96 | #define ROARDSP_FFLAG_NONE 0x0000 |
---|
| 97 | #define ROARDSP_FFLAG_FREE 0x0001 |
---|
| 98 | |
---|
[1131] | 99 | // consts for filter(chain) reset: |
---|
| 100 | #define ROARDSP_RESET_NONE 0 |
---|
| 101 | #define ROARDSP_RESET_FULL 1 |
---|
| 102 | #define ROARDSP_RESET_STATE 2 |
---|
| 103 | |
---|
[1004] | 104 | // filter specific constants: |
---|
| 105 | #define ROARDSP_DOWNMIX_LEFT 1 |
---|
| 106 | #define ROARDSP_DOWNMIX_RIGHT 2 |
---|
| 107 | #define ROARDSP_DOWNMIX_ARITHMETIC 3 |
---|
| 108 | #define ROARDSP_DOWNMIX_RMS 4 |
---|
| 109 | |
---|
[1100] | 110 | #define ROARDSP_DCBLOCK_NUMBLOCKS 100 |
---|
| 111 | |
---|
[3004] | 112 | |
---|
| 113 | #define ROARDSP_SPEEX_PREP_ON 0x0001 |
---|
| 114 | #define ROARDSP_SPEEX_PREP_OFF 0x0002 |
---|
| 115 | #define ROARDSP_SPEEX_PREP_MASK (ROARDSP_SPEEX_PREP_ON|ROARDSP_SPEEX_PREP_OFF) |
---|
| 116 | |
---|
| 117 | // Config Bit Vector |
---|
| 118 | #define ROARDSP_SPEEX_PREP_CBV(opt,sw) ((sw)<<((opt)*2)) |
---|
| 119 | #define ROARDSP_SPEEX_PREP_CTB(opt,val) (((val) & ROARDSP_SPEEX_PREP_CBV((opt),ROARDSP_SPEEX_PREP_MASK)) >> ((opt)*2)) |
---|
| 120 | |
---|
| 121 | #define ROARDSP_SPEEX_PREP_DENOISE 0 |
---|
| 122 | #define ROARDSP_SPEEX_PREP_AGC 1 |
---|
| 123 | #define ROARDSP_SPEEX_PREP_VAD 2 |
---|
| 124 | |
---|
| 125 | #define ROARDSP_SPEEX_PREP_DENOISE_ON ROARDSP_SPEEX_PREP_CBV(ROARDSP_SPEEX_PREP_DENOISE, ROARDSP_SPEEX_PREP_ON) |
---|
| 126 | #define ROARDSP_SPEEX_PREP_DENOISE_OFF ROARDSP_SPEEX_PREP_CBV(ROARDSP_SPEEX_PREP_DENOISE, ROARDSP_SPEEX_PREP_OFF) |
---|
| 127 | #define ROARDSP_SPEEX_PREP_AGC_ON ROARDSP_SPEEX_PREP_CBV(ROARDSP_SPEEX_PREP_AGC, ROARDSP_SPEEX_PREP_ON) |
---|
| 128 | #define ROARDSP_SPEEX_PREP_AGC_OFF ROARDSP_SPEEX_PREP_CBV(ROARDSP_SPEEX_PREP_AGC, ROARDSP_SPEEX_PREP_OFF) |
---|
| 129 | #define ROARDSP_SPEEX_PREP_VAD_ON ROARDSP_SPEEX_PREP_CBV(ROARDSP_SPEEX_PREP_VAD, ROARDSP_SPEEX_PREP_ON) |
---|
| 130 | #define ROARDSP_SPEEX_PREP_VAD_OFF ROARDSP_SPEEX_PREP_CBV(ROARDSP_SPEEX_PREP_VAD, ROARDSP_SPEEX_PREP_OFF) |
---|
| 131 | |
---|
| 132 | |
---|
[659] | 133 | // types: |
---|
| 134 | |
---|
| 135 | struct roardsp_filter { |
---|
| 136 | int channels; |
---|
| 137 | int bits; |
---|
[673] | 138 | int rate; |
---|
[659] | 139 | void * inst; |
---|
[2989] | 140 | uint_least16_t flags; |
---|
[659] | 141 | int (*calc )(struct roardsp_filter * filter, void * data, size_t samples); |
---|
| 142 | int (*uninit)(struct roardsp_filter * filter); |
---|
[672] | 143 | int (*ctl )(struct roardsp_filter * filter, int cmd, void * data); |
---|
[1131] | 144 | int (*reset )(struct roardsp_filter * filter, int what); |
---|
[659] | 145 | }; |
---|
| 146 | |
---|
| 147 | struct roardsp_filterchain { |
---|
| 148 | int filters; |
---|
| 149 | struct roardsp_filter * filter[ROARDSP_MAX_FILTERS_PER_CHAIN]; |
---|
| 150 | }; |
---|
| 151 | |
---|
[1105] | 152 | #ifdef ROAR_HAVE_LIBM |
---|
[659] | 153 | struct roardsp_lowp { |
---|
| 154 | uint32_t freq; // in mHz (0Hz..4MHz) |
---|
| 155 | uint16_t a, b; |
---|
| 156 | int32_t old[ROAR_MAX_CHANNELS]; |
---|
| 157 | }; |
---|
| 158 | |
---|
[685] | 159 | struct roardsp_highp { |
---|
| 160 | uint32_t freq; // in mHz (0Hz..4MHz) |
---|
| 161 | int32_t a, b, c; |
---|
| 162 | int32_t oldout[ROAR_MAX_CHANNELS]; |
---|
| 163 | int32_t oldin[ROAR_MAX_CHANNELS]; |
---|
| 164 | }; |
---|
[1105] | 165 | #endif |
---|
[685] | 166 | |
---|
[882] | 167 | struct roardsp_amp { |
---|
| 168 | int32_t mul; |
---|
| 169 | int32_t div; |
---|
| 170 | }; |
---|
| 171 | |
---|
[1100] | 172 | struct roardsp_dcblock { |
---|
| 173 | int cur; |
---|
| 174 | int32_t dc[ROARDSP_DCBLOCK_NUMBLOCKS]; |
---|
| 175 | }; |
---|
| 176 | |
---|
[1587] | 177 | struct roardsp_swap { |
---|
| 178 | int map[ROAR_MAX_CHANNELS]; |
---|
| 179 | }; |
---|
| 180 | |
---|
[2980] | 181 | struct roardsp_agc { |
---|
| 182 | struct roardsp_filter * amp; |
---|
[3010] | 183 | uint32_t target_amp; |
---|
[2980] | 184 | }; |
---|
| 185 | |
---|
| 186 | struct roardsp_speex_prep { |
---|
[2992] | 187 | #ifdef _SPEEX_TYPES_H |
---|
| 188 | SpeexPreprocessState *preprocess; |
---|
| 189 | int frame_size; |
---|
| 190 | #else |
---|
[2980] | 191 | char dummy[8]; |
---|
[2992] | 192 | #endif |
---|
[2980] | 193 | }; |
---|
| 194 | |
---|
[659] | 195 | // funcs: |
---|
[664] | 196 | int roardsp_filter_str2id(char * str); |
---|
| 197 | char * roardsp_filter_id2str(int id); |
---|
[2989] | 198 | int roardsp_filter_new (struct roardsp_filter ** filter, struct roar_stream * stream, int id); |
---|
[3010] | 199 | #define roardsp_filter_free(x) roardsp_filter_uninit((x)) |
---|
[2989] | 200 | int roardsp_filter_init (struct roardsp_filter * filter, struct roar_stream * stream, int id); |
---|
| 201 | int roardsp_filter_uninit(struct roardsp_filter * filter); |
---|
| 202 | int roardsp_filter_calc (struct roardsp_filter * filter, void * data, size_t len); |
---|
| 203 | int roardsp_filter_ctl (struct roardsp_filter * filter, int cmd, void * data); |
---|
| 204 | int roardsp_filter_reset (struct roardsp_filter * filter, int what); |
---|
[659] | 205 | |
---|
| 206 | int roardsp_fchain_init (struct roardsp_filterchain * chain); |
---|
| 207 | int roardsp_fchain_uninit(struct roardsp_filterchain * chain); |
---|
| 208 | int roardsp_fchain_add (struct roardsp_filterchain * chain, struct roardsp_filter * filter); |
---|
| 209 | int roardsp_fchain_calc (struct roardsp_filterchain * chain, void * data, size_t len); |
---|
[1131] | 210 | int roardsp_fchain_reset (struct roardsp_filterchain * chain, int what); |
---|
[679] | 211 | int roardsp_fchain_num (struct roardsp_filterchain * chain); |
---|
[659] | 212 | |
---|
[676] | 213 | // filter: |
---|
| 214 | |
---|
[1105] | 215 | #ifdef ROAR_HAVE_LIBM |
---|
[676] | 216 | int roardsp_lowp_init (struct roardsp_filter * filter, struct roar_stream * stream, int id); |
---|
| 217 | int roardsp_lowp_uninit(struct roardsp_filter * filter); |
---|
| 218 | int roardsp_lowp_calc16(struct roardsp_filter * filter, void * data, size_t samples); |
---|
| 219 | int roardsp_lowp_ctl (struct roardsp_filter * filter, int cmd, void * data); |
---|
[1141] | 220 | int roardsp_lowp_reset (struct roardsp_filter * filter, int what); |
---|
[676] | 221 | |
---|
[685] | 222 | int roardsp_highp_init (struct roardsp_filter * filter, struct roar_stream * stream, int id); |
---|
| 223 | int roardsp_highp_uninit(struct roardsp_filter * filter); |
---|
| 224 | int roardsp_highp_calc16(struct roardsp_filter * filter, void * data, size_t samples); |
---|
| 225 | int roardsp_highp_ctl (struct roardsp_filter * filter, int cmd, void * data); |
---|
[1141] | 226 | int roardsp_highp_reset (struct roardsp_filter * filter, int what); |
---|
[1105] | 227 | #endif |
---|
[676] | 228 | |
---|
[882] | 229 | int roardsp_amp_init (struct roardsp_filter * filter, struct roar_stream * stream, int id); |
---|
| 230 | int roardsp_amp_uninit(struct roardsp_filter * filter); |
---|
| 231 | int roardsp_amp_calc16(struct roardsp_filter * filter, void * data, size_t samples); |
---|
| 232 | int roardsp_amp_calc8 (struct roardsp_filter * filter, void * data, size_t samples); |
---|
| 233 | int roardsp_amp_ctl (struct roardsp_filter * filter, int cmd, void * data); |
---|
[1141] | 234 | int roardsp_amp_reset (struct roardsp_filter * filter, int what); |
---|
[882] | 235 | |
---|
[979] | 236 | int roardsp_add_init (struct roardsp_filter * filter, struct roar_stream * stream, int id); |
---|
| 237 | int roardsp_add_calc16(struct roardsp_filter * filter, void * data, size_t samples); |
---|
[1141] | 238 | int roardsp_add_reset (struct roardsp_filter * filter, int what); |
---|
[979] | 239 | |
---|
| 240 | int roardsp_quantify_init (struct roardsp_filter * filter, struct roar_stream * stream, int id); |
---|
| 241 | int roardsp_quantify_uninit(struct roardsp_filter * filter); |
---|
| 242 | int roardsp_quantify_calc16(struct roardsp_filter * filter, void * data, size_t samples); |
---|
| 243 | int roardsp_quantify_ctl (struct roardsp_filter * filter, int cmd, void * data); |
---|
[1141] | 244 | int roardsp_quantify_reset (struct roardsp_filter * filter, int what); |
---|
[979] | 245 | |
---|
| 246 | int roardsp_clip_calc16(struct roardsp_filter * filter, void * data, size_t samples); |
---|
| 247 | int roardsp_clip_ctl (struct roardsp_filter * filter, int cmd, void * data); |
---|
[1141] | 248 | int roardsp_clip_reset (struct roardsp_filter * filter, int what); |
---|
[979] | 249 | |
---|
[1004] | 250 | int roardsp_downmix_init (struct roardsp_filter * filter, struct roar_stream * stream, int id); |
---|
| 251 | int roardsp_downmix_calc162(struct roardsp_filter * filter, void * data, size_t samples); |
---|
| 252 | int roardsp_downmix_ctl (struct roardsp_filter * filter, int cmd, void * data); |
---|
[1141] | 253 | int roardsp_downmix_reset (struct roardsp_filter * filter, int what); |
---|
[1004] | 254 | |
---|
[1100] | 255 | int roardsp_dcblock_init (struct roardsp_filter * filter, struct roar_stream * stream, int id); |
---|
| 256 | int roardsp_dcblock_uninit (struct roardsp_filter * filter); |
---|
| 257 | int roardsp_dcblock_calc16 (struct roardsp_filter * filter, void * data, size_t samples); |
---|
[1131] | 258 | int roardsp_dcblock_reset (struct roardsp_filter * filter, int what); |
---|
[1100] | 259 | |
---|
[1587] | 260 | int roardsp_swap_init (struct roardsp_filter * filter, struct roar_stream * stream, int id); |
---|
| 261 | int roardsp_swap_uninit (struct roardsp_filter * filter); |
---|
| 262 | int roardsp_swap_calc162(struct roardsp_filter * filter, void * data, size_t samples); |
---|
| 263 | int roardsp_swap_ctl (struct roardsp_filter * filter, int cmd, void * data); |
---|
| 264 | int roardsp_swap_reset (struct roardsp_filter * filter, int what); |
---|
| 265 | |
---|
[3010] | 266 | int roardsp_agc_init (struct roardsp_filter * filter, struct roar_stream * stream, int id); |
---|
| 267 | int roardsp_agc_uninit (struct roardsp_filter * filter); |
---|
| 268 | int roardsp_agc_ctl (struct roardsp_filter * filter, int cmd, void * data); |
---|
| 269 | int roardsp_agc_reset (struct roardsp_filter * filter, int what); |
---|
| 270 | |
---|
[2992] | 271 | #ifdef _SPEEX_TYPES_H |
---|
| 272 | int roardsp_speex_prep_init (struct roardsp_filter * filter, struct roar_stream * stream, int id); |
---|
| 273 | int roardsp_speex_prep_uninit (struct roardsp_filter * filter); |
---|
[2998] | 274 | int roardsp_speex_prep_calc161(struct roardsp_filter * filter, void * data, size_t samples); |
---|
[2992] | 275 | int roardsp_speex_prep_ctl (struct roardsp_filter * filter, int cmd, void * data); |
---|
| 276 | int roardsp_speex_prep_reset (struct roardsp_filter * filter, int what); |
---|
| 277 | #endif |
---|
| 278 | |
---|
[735] | 279 | // codecs: |
---|
| 280 | int roardsp_conv_alaw2pcm16 (int16_t * out, char * in, size_t len); |
---|
[816] | 281 | int roardsp_conv_pcm162alaw (char * out, int16_t * in, size_t len); |
---|
[735] | 282 | |
---|
[922] | 283 | int roardsp_conv_mulaw2pcm16 (int16_t * out, char * in, size_t len); |
---|
| 284 | int roardsp_conv_pcm162mulaw (char * out, int16_t * in, size_t len); |
---|
| 285 | |
---|
[874] | 286 | __END_DECLS |
---|
| 287 | |
---|
[651] | 288 | #endif |
---|
| 289 | |
---|
| 290 | //ll |
---|