[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 | |
---|
[3034] | 40 | #include "interleave.h" |
---|
[686] | 41 | #include "midi.h" |
---|
[2425] | 42 | #include "synth.h" |
---|
[1368] | 43 | #include "poly.h" |
---|
[2434] | 44 | #include "fader.h" |
---|
[2929] | 45 | #include "mixer.h" |
---|
[2934] | 46 | #include "amp.h" |
---|
[1371] | 47 | #include "convert.h" |
---|
[1626] | 48 | #include "midside.h" |
---|
[2026] | 49 | #include "point.h" |
---|
[2143] | 50 | #include "remove.h" |
---|
[2316] | 51 | #include "rms.h" |
---|
[2169] | 52 | #include "transcode.h" |
---|
[2638] | 53 | #include "vio_transcode.h" |
---|
[686] | 54 | |
---|
[2187] | 55 | #ifdef ROAR_HAVE_LIBCELT |
---|
| 56 | #include "transcode_celt.h" |
---|
| 57 | #endif |
---|
[2294] | 58 | #ifdef ROAR_HAVE_LIBSPEEX |
---|
| 59 | #include "transcode_speex.h" |
---|
| 60 | #endif |
---|
[2187] | 61 | |
---|
[2386] | 62 | #ifdef ROAR_HAVE_LIBSAMPLERATE |
---|
| 63 | #include <samplerate.h> |
---|
| 64 | #endif |
---|
| 65 | |
---|
[659] | 66 | // defines |
---|
| 67 | #define ROARDSP_MAX_FILTERS_PER_CHAIN 8 |
---|
| 68 | |
---|
[662] | 69 | #define ROARDSP_FILTER_NONE 0 |
---|
| 70 | #define ROARDSP_FILTER_AMP 1 |
---|
| 71 | #define ROARDSP_FILTER_LOWP 2 |
---|
| 72 | #define ROARDSP_FILTER_HIGHP 3 |
---|
[979] | 73 | #define ROARDSP_FILTER_MODULATE 4 |
---|
| 74 | #define ROARDSP_FILTER_QUANTIFY 5 |
---|
| 75 | #define ROARDSP_FILTER_CLIP 6 |
---|
| 76 | #define ROARDSP_FILTER_ADD 7 |
---|
[1004] | 77 | #define ROARDSP_FILTER_DOWNMIX 8 |
---|
[1100] | 78 | #define ROARDSP_FILTER_DCBLOCK 9 |
---|
[1587] | 79 | #define ROARDSP_FILTER_SWAP 10 |
---|
[2979] | 80 | #define ROARDSP_FILTER_SPEEX_PREP 11 |
---|
| 81 | #define ROARDSP_FILTER_AGC 12 |
---|
[662] | 82 | |
---|
[672] | 83 | // filter CTLs: |
---|
| 84 | |
---|
[2992] | 85 | #define ROARDSP_FCTL_FREQ 1 /* float */ |
---|
[672] | 86 | #define ROARDSP_FCTL_TIME 2 |
---|
[3004] | 87 | #define ROARDSP_FCTL_MUL 3 /* int32_t */ |
---|
| 88 | #define ROARDSP_FCTL_DIV 4 /* int32_t */ |
---|
| 89 | #define ROARDSP_FCTL_N 5 /* int32_t */ |
---|
| 90 | #define ROARDSP_FCTL_LIMIT 6 /* int32_t */ |
---|
[979] | 91 | #define ROARDSP_FCTL_PHASE 7 |
---|
[3004] | 92 | #define ROARDSP_FCTL_Q 8 /* int32_t */ |
---|
| 93 | #define ROARDSP_FCTL_MODE 9 /* int32_t */ |
---|
[2992] | 94 | #define ROARDSP_FCTL_PACKET_SIZE 10 /* size_t */ |
---|
[672] | 95 | |
---|
[2989] | 96 | // consts for filter flags: |
---|
| 97 | #define ROARDSP_FFLAG_NONE 0x0000 |
---|
| 98 | #define ROARDSP_FFLAG_FREE 0x0001 |
---|
| 99 | |
---|
[1131] | 100 | // consts for filter(chain) reset: |
---|
| 101 | #define ROARDSP_RESET_NONE 0 |
---|
| 102 | #define ROARDSP_RESET_FULL 1 |
---|
| 103 | #define ROARDSP_RESET_STATE 2 |
---|
| 104 | |
---|
[1004] | 105 | // filter specific constants: |
---|
| 106 | #define ROARDSP_DOWNMIX_LEFT 1 |
---|
| 107 | #define ROARDSP_DOWNMIX_RIGHT 2 |
---|
| 108 | #define ROARDSP_DOWNMIX_ARITHMETIC 3 |
---|
| 109 | #define ROARDSP_DOWNMIX_RMS 4 |
---|
| 110 | |
---|
[1100] | 111 | #define ROARDSP_DCBLOCK_NUMBLOCKS 100 |
---|
| 112 | |
---|
[3004] | 113 | |
---|
| 114 | #define ROARDSP_SPEEX_PREP_ON 0x0001 |
---|
| 115 | #define ROARDSP_SPEEX_PREP_OFF 0x0002 |
---|
| 116 | #define ROARDSP_SPEEX_PREP_MASK (ROARDSP_SPEEX_PREP_ON|ROARDSP_SPEEX_PREP_OFF) |
---|
| 117 | |
---|
| 118 | // Config Bit Vector |
---|
| 119 | #define ROARDSP_SPEEX_PREP_CBV(opt,sw) ((sw)<<((opt)*2)) |
---|
| 120 | #define ROARDSP_SPEEX_PREP_CTB(opt,val) (((val) & ROARDSP_SPEEX_PREP_CBV((opt),ROARDSP_SPEEX_PREP_MASK)) >> ((opt)*2)) |
---|
| 121 | |
---|
| 122 | #define ROARDSP_SPEEX_PREP_DENOISE 0 |
---|
| 123 | #define ROARDSP_SPEEX_PREP_AGC 1 |
---|
| 124 | #define ROARDSP_SPEEX_PREP_VAD 2 |
---|
| 125 | |
---|
| 126 | #define ROARDSP_SPEEX_PREP_DENOISE_ON ROARDSP_SPEEX_PREP_CBV(ROARDSP_SPEEX_PREP_DENOISE, ROARDSP_SPEEX_PREP_ON) |
---|
| 127 | #define ROARDSP_SPEEX_PREP_DENOISE_OFF ROARDSP_SPEEX_PREP_CBV(ROARDSP_SPEEX_PREP_DENOISE, ROARDSP_SPEEX_PREP_OFF) |
---|
| 128 | #define ROARDSP_SPEEX_PREP_AGC_ON ROARDSP_SPEEX_PREP_CBV(ROARDSP_SPEEX_PREP_AGC, ROARDSP_SPEEX_PREP_ON) |
---|
| 129 | #define ROARDSP_SPEEX_PREP_AGC_OFF ROARDSP_SPEEX_PREP_CBV(ROARDSP_SPEEX_PREP_AGC, ROARDSP_SPEEX_PREP_OFF) |
---|
| 130 | #define ROARDSP_SPEEX_PREP_VAD_ON ROARDSP_SPEEX_PREP_CBV(ROARDSP_SPEEX_PREP_VAD, ROARDSP_SPEEX_PREP_ON) |
---|
| 131 | #define ROARDSP_SPEEX_PREP_VAD_OFF ROARDSP_SPEEX_PREP_CBV(ROARDSP_SPEEX_PREP_VAD, ROARDSP_SPEEX_PREP_OFF) |
---|
| 132 | |
---|
| 133 | |
---|
[659] | 134 | // types: |
---|
| 135 | |
---|
| 136 | struct roardsp_filter { |
---|
| 137 | int channels; |
---|
| 138 | int bits; |
---|
[673] | 139 | int rate; |
---|
[659] | 140 | void * inst; |
---|
[2989] | 141 | uint_least16_t flags; |
---|
[659] | 142 | int (*calc )(struct roardsp_filter * filter, void * data, size_t samples); |
---|
| 143 | int (*uninit)(struct roardsp_filter * filter); |
---|
[672] | 144 | int (*ctl )(struct roardsp_filter * filter, int cmd, void * data); |
---|
[1131] | 145 | int (*reset )(struct roardsp_filter * filter, int what); |
---|
[659] | 146 | }; |
---|
| 147 | |
---|
| 148 | struct roardsp_filterchain { |
---|
| 149 | int filters; |
---|
| 150 | struct roardsp_filter * filter[ROARDSP_MAX_FILTERS_PER_CHAIN]; |
---|
| 151 | }; |
---|
| 152 | |
---|
[1105] | 153 | #ifdef ROAR_HAVE_LIBM |
---|
[659] | 154 | struct roardsp_lowp { |
---|
| 155 | uint32_t freq; // in mHz (0Hz..4MHz) |
---|
| 156 | uint16_t a, b; |
---|
| 157 | int32_t old[ROAR_MAX_CHANNELS]; |
---|
| 158 | }; |
---|
| 159 | |
---|
[685] | 160 | struct roardsp_highp { |
---|
| 161 | uint32_t freq; // in mHz (0Hz..4MHz) |
---|
| 162 | int32_t a, b, c; |
---|
| 163 | int32_t oldout[ROAR_MAX_CHANNELS]; |
---|
| 164 | int32_t oldin[ROAR_MAX_CHANNELS]; |
---|
| 165 | }; |
---|
[1105] | 166 | #endif |
---|
[685] | 167 | |
---|
[882] | 168 | struct roardsp_amp { |
---|
| 169 | int32_t mul; |
---|
| 170 | int32_t div; |
---|
| 171 | }; |
---|
| 172 | |
---|
[1100] | 173 | struct roardsp_dcblock { |
---|
| 174 | int cur; |
---|
| 175 | int32_t dc[ROARDSP_DCBLOCK_NUMBLOCKS]; |
---|
| 176 | }; |
---|
| 177 | |
---|
[1587] | 178 | struct roardsp_swap { |
---|
| 179 | int map[ROAR_MAX_CHANNELS]; |
---|
| 180 | }; |
---|
| 181 | |
---|
[2980] | 182 | struct roardsp_agc { |
---|
| 183 | struct roardsp_filter * amp; |
---|
[3010] | 184 | uint32_t target_amp; |
---|
[2980] | 185 | }; |
---|
| 186 | |
---|
| 187 | struct roardsp_speex_prep { |
---|
[2992] | 188 | #ifdef _SPEEX_TYPES_H |
---|
| 189 | SpeexPreprocessState *preprocess; |
---|
| 190 | int frame_size; |
---|
| 191 | #else |
---|
[2980] | 192 | char dummy[8]; |
---|
[2992] | 193 | #endif |
---|
[2980] | 194 | }; |
---|
| 195 | |
---|
[659] | 196 | // funcs: |
---|
[664] | 197 | int roardsp_filter_str2id(char * str); |
---|
| 198 | char * roardsp_filter_id2str(int id); |
---|
[2989] | 199 | int roardsp_filter_new (struct roardsp_filter ** filter, struct roar_stream * stream, int id); |
---|
[3010] | 200 | #define roardsp_filter_free(x) roardsp_filter_uninit((x)) |
---|
[2989] | 201 | int roardsp_filter_init (struct roardsp_filter * filter, struct roar_stream * stream, int id); |
---|
| 202 | int roardsp_filter_uninit(struct roardsp_filter * filter); |
---|
| 203 | int roardsp_filter_calc (struct roardsp_filter * filter, void * data, size_t len); |
---|
| 204 | int roardsp_filter_ctl (struct roardsp_filter * filter, int cmd, void * data); |
---|
| 205 | int roardsp_filter_reset (struct roardsp_filter * filter, int what); |
---|
[659] | 206 | |
---|
| 207 | int roardsp_fchain_init (struct roardsp_filterchain * chain); |
---|
| 208 | int roardsp_fchain_uninit(struct roardsp_filterchain * chain); |
---|
| 209 | int roardsp_fchain_add (struct roardsp_filterchain * chain, struct roardsp_filter * filter); |
---|
| 210 | int roardsp_fchain_calc (struct roardsp_filterchain * chain, void * data, size_t len); |
---|
[1131] | 211 | int roardsp_fchain_reset (struct roardsp_filterchain * chain, int what); |
---|
[679] | 212 | int roardsp_fchain_num (struct roardsp_filterchain * chain); |
---|
[659] | 213 | |
---|
[676] | 214 | // filter: |
---|
| 215 | |
---|
[1105] | 216 | #ifdef ROAR_HAVE_LIBM |
---|
[676] | 217 | int roardsp_lowp_init (struct roardsp_filter * filter, struct roar_stream * stream, int id); |
---|
| 218 | int roardsp_lowp_uninit(struct roardsp_filter * filter); |
---|
| 219 | int roardsp_lowp_calc16(struct roardsp_filter * filter, void * data, size_t samples); |
---|
| 220 | int roardsp_lowp_ctl (struct roardsp_filter * filter, int cmd, void * data); |
---|
[1141] | 221 | int roardsp_lowp_reset (struct roardsp_filter * filter, int what); |
---|
[676] | 222 | |
---|
[685] | 223 | int roardsp_highp_init (struct roardsp_filter * filter, struct roar_stream * stream, int id); |
---|
| 224 | int roardsp_highp_uninit(struct roardsp_filter * filter); |
---|
| 225 | int roardsp_highp_calc16(struct roardsp_filter * filter, void * data, size_t samples); |
---|
| 226 | int roardsp_highp_ctl (struct roardsp_filter * filter, int cmd, void * data); |
---|
[1141] | 227 | int roardsp_highp_reset (struct roardsp_filter * filter, int what); |
---|
[1105] | 228 | #endif |
---|
[676] | 229 | |
---|
[882] | 230 | int roardsp_amp_init (struct roardsp_filter * filter, struct roar_stream * stream, int id); |
---|
| 231 | int roardsp_amp_uninit(struct roardsp_filter * filter); |
---|
| 232 | int roardsp_amp_calc16(struct roardsp_filter * filter, void * data, size_t samples); |
---|
| 233 | int roardsp_amp_calc8 (struct roardsp_filter * filter, void * data, size_t samples); |
---|
| 234 | int roardsp_amp_ctl (struct roardsp_filter * filter, int cmd, void * data); |
---|
[1141] | 235 | int roardsp_amp_reset (struct roardsp_filter * filter, int what); |
---|
[882] | 236 | |
---|
[979] | 237 | int roardsp_add_init (struct roardsp_filter * filter, struct roar_stream * stream, int id); |
---|
| 238 | int roardsp_add_calc16(struct roardsp_filter * filter, void * data, size_t samples); |
---|
[1141] | 239 | int roardsp_add_reset (struct roardsp_filter * filter, int what); |
---|
[979] | 240 | |
---|
| 241 | int roardsp_quantify_init (struct roardsp_filter * filter, struct roar_stream * stream, int id); |
---|
| 242 | int roardsp_quantify_uninit(struct roardsp_filter * filter); |
---|
| 243 | int roardsp_quantify_calc16(struct roardsp_filter * filter, void * data, size_t samples); |
---|
| 244 | int roardsp_quantify_ctl (struct roardsp_filter * filter, int cmd, void * data); |
---|
[1141] | 245 | int roardsp_quantify_reset (struct roardsp_filter * filter, int what); |
---|
[979] | 246 | |
---|
| 247 | int roardsp_clip_calc16(struct roardsp_filter * filter, void * data, size_t samples); |
---|
| 248 | int roardsp_clip_ctl (struct roardsp_filter * filter, int cmd, void * data); |
---|
[1141] | 249 | int roardsp_clip_reset (struct roardsp_filter * filter, int what); |
---|
[979] | 250 | |
---|
[1004] | 251 | int roardsp_downmix_init (struct roardsp_filter * filter, struct roar_stream * stream, int id); |
---|
| 252 | int roardsp_downmix_calc162(struct roardsp_filter * filter, void * data, size_t samples); |
---|
| 253 | int roardsp_downmix_ctl (struct roardsp_filter * filter, int cmd, void * data); |
---|
[1141] | 254 | int roardsp_downmix_reset (struct roardsp_filter * filter, int what); |
---|
[1004] | 255 | |
---|
[1100] | 256 | int roardsp_dcblock_init (struct roardsp_filter * filter, struct roar_stream * stream, int id); |
---|
| 257 | int roardsp_dcblock_uninit (struct roardsp_filter * filter); |
---|
| 258 | int roardsp_dcblock_calc16 (struct roardsp_filter * filter, void * data, size_t samples); |
---|
[1131] | 259 | int roardsp_dcblock_reset (struct roardsp_filter * filter, int what); |
---|
[1100] | 260 | |
---|
[1587] | 261 | int roardsp_swap_init (struct roardsp_filter * filter, struct roar_stream * stream, int id); |
---|
| 262 | int roardsp_swap_uninit (struct roardsp_filter * filter); |
---|
| 263 | int roardsp_swap_calc162(struct roardsp_filter * filter, void * data, size_t samples); |
---|
| 264 | int roardsp_swap_ctl (struct roardsp_filter * filter, int cmd, void * data); |
---|
| 265 | int roardsp_swap_reset (struct roardsp_filter * filter, int what); |
---|
| 266 | |
---|
[3010] | 267 | int roardsp_agc_init (struct roardsp_filter * filter, struct roar_stream * stream, int id); |
---|
| 268 | int roardsp_agc_uninit (struct roardsp_filter * filter); |
---|
| 269 | int roardsp_agc_ctl (struct roardsp_filter * filter, int cmd, void * data); |
---|
| 270 | int roardsp_agc_reset (struct roardsp_filter * filter, int what); |
---|
| 271 | |
---|
[2992] | 272 | #ifdef _SPEEX_TYPES_H |
---|
[3029] | 273 | #define ROAR_HAVE_SPEEX_FILTER |
---|
[2992] | 274 | int roardsp_speex_prep_init (struct roardsp_filter * filter, struct roar_stream * stream, int id); |
---|
| 275 | int roardsp_speex_prep_uninit (struct roardsp_filter * filter); |
---|
[2998] | 276 | int roardsp_speex_prep_calc161(struct roardsp_filter * filter, void * data, size_t samples); |
---|
[2992] | 277 | int roardsp_speex_prep_ctl (struct roardsp_filter * filter, int cmd, void * data); |
---|
| 278 | int roardsp_speex_prep_reset (struct roardsp_filter * filter, int what); |
---|
| 279 | #endif |
---|
| 280 | |
---|
[735] | 281 | // codecs: |
---|
| 282 | int roardsp_conv_alaw2pcm16 (int16_t * out, char * in, size_t len); |
---|
[816] | 283 | int roardsp_conv_pcm162alaw (char * out, int16_t * in, size_t len); |
---|
[735] | 284 | |
---|
[922] | 285 | int roardsp_conv_mulaw2pcm16 (int16_t * out, char * in, size_t len); |
---|
| 286 | int roardsp_conv_pcm162mulaw (char * out, int16_t * in, size_t len); |
---|
| 287 | |
---|
[874] | 288 | __END_DECLS |
---|
| 289 | |
---|
[651] | 290 | #endif |
---|
| 291 | |
---|
| 292 | //ll |
---|