Hash :
1765b28f
Author :
Thomas de Grivel
Date :
2021-02-20T22:17:09
wip remove autotools
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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425
/*
* Copyright 2018 Thomas de Grivel <thoxdg@gmail.com> +33614550127
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef RTBUF_SIGNAL_H
#define RTBUF_SIGNAL_H
#include <assert.h>
#include "../librtbuf/rtbuf.h"
typedef double t_rtbuf_signal_sample;
#define RTBUF_SIGNAL_SAMPLE_SIZE sizeof(t_rtbuf_signal_sample)
#define RTBUF_SIGNAL_SAMPLE_TYPE "double"
#define RTBUF_SIGNAL_SAMPLES 256
#define RTBUF_SIGNAL_SAMPLERATE 48000
#define RTBUF_SIGNAL_DT \
((double) RTBUF_SIGNAL_SAMPLES / RTBUF_SIGNAL_SAMPLERATE)
typedef t_rtbuf_signal_sample t_rtbuf_signal[RTBUF_SIGNAL_SAMPLES];
#define RTBUF_SIGNAL_SIZE sizeof(t_rtbuf_signal)
typedef t_rtbuf_signal_sample
f_rtbuf_signal (const t_rtbuf_signal_sample *signal,
unsigned int sample);
typedef struct rtbuf_signal_fun {
f_rtbuf_signal *sample_fun;
const t_rtbuf_signal_sample *signal;
} s_rtbuf_signal_fun;
void rtbuf_signal_zero (t_rtbuf_signal_sample *signal);
t_rtbuf_signal_sample
rtbuf_signal_sample (s_rtbuf *rtb,
unsigned int in,
t_rtbuf_signal_sample default_value);
void rtbuf_signal_fun (s_rtbuf *rtb,
unsigned int in,
s_rtbuf_signal_fun *data);
f_rtbuf_signal rtbuf_signal_sample_from_sample;
f_rtbuf_signal rtbuf_signal_sample_from_signal;
const double g_rtbuf_signal_sample_zero;
const double g_rtbuf_signal_sample_half;
const double g_rtbuf_signal_sample_one;
const double g_rtbuf_signal_sample_2pi;
const double g_rtbuf_signal_default_frequency;
/* butterworth bandpass filter, second order */
typedef struct rtbuf_signal_bandpass2_data {
t_rtbuf_signal signal;
t_rtbuf_signal_sample x1;
t_rtbuf_signal_sample x2;
t_rtbuf_signal_sample x3;
t_rtbuf_signal_sample x4;
t_rtbuf_signal_sample y1;
t_rtbuf_signal_sample y2;
t_rtbuf_signal_sample y3;
t_rtbuf_signal_sample y4;
} s_rtbuf_signal_bandpass2_data;
enum {
RTBUF_SIGNAL_BANDPASS_IN_SIGNAL = 0,
RTBUF_SIGNAL_BANDPASS_IN_CUTOFF,
RTBUF_SIGNAL_BANDPASS_IN_QFACTOR,
RTBUF_SIGNAL_BANDPASS_INS
};
int rtbuf_signal_bandpass2 (s_rtbuf *rtb);
int rtbuf_signal_bandpass2_start (s_rtbuf *rtb);
/* delay */
#define RTBUF_SIGNAL_DELAY_MAX 10
#define RTBUF_SIGNAL_DELAY_SAMPLES_MAX (RTBUF_SIGNAL_DELAY_MAX * \
RTBUF_SIGNAL_SAMPLERATE)
typedef struct rtbuf_signal_delay_data {
t_rtbuf_signal signal;
t_rtbuf_signal_sample in[RTBUF_SIGNAL_DELAY_SAMPLES_MAX];
unsigned int pos;
} s_rtbuf_signal_delay_data;
enum {
RTBUF_SIGNAL_DELAY_IN_SIGNAL = 0,
RTBUF_SIGNAL_DELAY_IN_DELAY,
RTBUF_SIGNAL_DELAY_IN_FEEDBACK,
RTBUF_SIGNAL_DELAY_INS
};
int rtbuf_signal_delay (s_rtbuf *rtb);
int rtbuf_signal_delay_start (s_rtbuf *rtb);
/* butterworth second order 10 band equalizer */
typedef struct rtbuf_signal_equalizer10_data {
t_rtbuf_signal signal;
t_rtbuf_signal signal32;
t_rtbuf_signal signal64;
t_rtbuf_signal signal128;
t_rtbuf_signal signal256;
t_rtbuf_signal signal512;
t_rtbuf_signal signal1k;
t_rtbuf_signal signal2k;
t_rtbuf_signal signal4k;
t_rtbuf_signal signal8k;
t_rtbuf_signal signal16k;
t_rtbuf_signal_sample x1;
t_rtbuf_signal_sample x2;
t_rtbuf_signal_sample x3;
t_rtbuf_signal_sample x4;
t_rtbuf_signal_sample y0_1;
t_rtbuf_signal_sample y0_2;
t_rtbuf_signal_sample y0_3;
t_rtbuf_signal_sample y0_4;
t_rtbuf_signal_sample y1_1;
t_rtbuf_signal_sample y1_2;
t_rtbuf_signal_sample y1_3;
t_rtbuf_signal_sample y1_4;
t_rtbuf_signal_sample y2_1;
t_rtbuf_signal_sample y2_2;
t_rtbuf_signal_sample y2_3;
t_rtbuf_signal_sample y2_4;
t_rtbuf_signal_sample y3_1;
t_rtbuf_signal_sample y3_2;
t_rtbuf_signal_sample y3_3;
t_rtbuf_signal_sample y3_4;
t_rtbuf_signal_sample y4_1;
t_rtbuf_signal_sample y4_2;
t_rtbuf_signal_sample y4_3;
t_rtbuf_signal_sample y4_4;
t_rtbuf_signal_sample y5_1;
t_rtbuf_signal_sample y5_2;
t_rtbuf_signal_sample y5_3;
t_rtbuf_signal_sample y5_4;
t_rtbuf_signal_sample y6_1;
t_rtbuf_signal_sample y6_2;
t_rtbuf_signal_sample y6_3;
t_rtbuf_signal_sample y6_4;
t_rtbuf_signal_sample y7_1;
t_rtbuf_signal_sample y7_2;
t_rtbuf_signal_sample y7_3;
t_rtbuf_signal_sample y7_4;
t_rtbuf_signal_sample y8_1;
t_rtbuf_signal_sample y8_2;
t_rtbuf_signal_sample y8_3;
t_rtbuf_signal_sample y8_4;
t_rtbuf_signal_sample y9_1;
t_rtbuf_signal_sample y9_2;
t_rtbuf_signal_sample y9_3;
t_rtbuf_signal_sample y9_4;
} s_rtbuf_signal_equalizer10_data;
enum {
RTBUF_SIGNAL_EQUALIZER10_IN_SIGNAL = 0,
RTBUF_SIGNAL_EQUALIZER10_IN_AMP32,
RTBUF_SIGNAL_EQUALIZER10_IN_AMP64,
RTBUF_SIGNAL_EQUALIZER10_IN_AMP128,
RTBUF_SIGNAL_EQUALIZER10_IN_AMP256,
RTBUF_SIGNAL_EQUALIZER10_IN_AMP512,
RTBUF_SIGNAL_EQUALIZER10_IN_AMP1K,
RTBUF_SIGNAL_EQUALIZER10_IN_AMP2K,
RTBUF_SIGNAL_EQUALIZER10_IN_AMP4K,
RTBUF_SIGNAL_EQUALIZER10_IN_AMP8K,
RTBUF_SIGNAL_EQUALIZER10_IN_AMP16K,
RTBUF_SIGNAL_EQUALIZER10_INS
};
int rtbuf_signal_equalizer10 (s_rtbuf *rtb);
int rtbuf_signal_equalizer10_start (s_rtbuf *rtb);
/* flanger */
#define RTBUF_SIGNAL_FLANGER_MAX 1
#define RTBUF_SIGNAL_FLANGER_SAMPLES_MAX (RTBUF_SIGNAL_FLANGER_MAX * \
RTBUF_SIGNAL_SAMPLERATE)
typedef struct rtbuf_signal_flanger_data {
t_rtbuf_signal signal;
double phase;
t_rtbuf_signal_sample in[RTBUF_SIGNAL_FLANGER_SAMPLES_MAX];
unsigned int pos;
unsigned int ds;
} s_rtbuf_signal_flanger_data;
enum {
RTBUF_SIGNAL_FLANGER_IN_SIGNAL = 0,
RTBUF_SIGNAL_FLANGER_IN_FREQUENCY,
RTBUF_SIGNAL_FLANGER_IN_AMPLITUDE,
RTBUF_SIGNAL_FLANGER_IN_DELAY,
RTBUF_SIGNAL_FLANGER_IN_FEEDBACK,
RTBUF_SIGNAL_FLANGER_IN_N
};
int rtbuf_signal_flanger (s_rtbuf *rtb);
int rtbuf_signal_flanger_start (s_rtbuf *rtb);
/* butterworth hipass filter, first order */
typedef struct rtbuf_signal_hipass_data {
t_rtbuf_signal signal;
t_rtbuf_signal_sample x1;
t_rtbuf_signal_sample y1;
} s_rtbuf_signal_hipass_data;
enum {
RTBUF_SIGNAL_HIPASS_IN_SIGNAL = 0,
RTBUF_SIGNAL_HIPASS_IN_CUTOFF,
RTBUF_SIGNAL_HIPASS_INS
};
int rtbuf_signal_hipass (s_rtbuf *rtb);
int rtbuf_signal_hipass_start (s_rtbuf *rtb);
/* butterworth hipass filter, second order */
typedef struct rtbuf_signal_hipass2_data {
t_rtbuf_signal signal;
t_rtbuf_signal_sample x1;
t_rtbuf_signal_sample x2;
t_rtbuf_signal_sample y1;
t_rtbuf_signal_sample y2;
} s_rtbuf_signal_hipass2_data;
int rtbuf_signal_hipass2 (s_rtbuf *rtb);
int rtbuf_signal_hipass2_start (s_rtbuf *rtb);
/* butterworth hipass filter, third order */
typedef struct rtbuf_signal_hipass3_data {
t_rtbuf_signal signal;
t_rtbuf_signal_sample x1;
t_rtbuf_signal_sample x2;
t_rtbuf_signal_sample x3;
t_rtbuf_signal_sample y1;
t_rtbuf_signal_sample y2;
t_rtbuf_signal_sample y3;
} s_rtbuf_signal_hipass3_data;
int rtbuf_signal_hipass3 (s_rtbuf *rtb);
int rtbuf_signal_hipass3_start (s_rtbuf *rtb);
/* butterworth hipass filter, fourth order */
typedef struct rtbuf_signal_hipass4_data {
t_rtbuf_signal signal;
t_rtbuf_signal_sample x1;
t_rtbuf_signal_sample x2;
t_rtbuf_signal_sample x3;
t_rtbuf_signal_sample x4;
t_rtbuf_signal_sample y1;
t_rtbuf_signal_sample y2;
t_rtbuf_signal_sample y3;
t_rtbuf_signal_sample y4;
} s_rtbuf_signal_hipass4_data;
int rtbuf_signal_hipass4 (s_rtbuf *rtb);
int rtbuf_signal_hipass4_start (s_rtbuf *rtb);
/* butterworth hipass filter, fifth order */
typedef struct rtbuf_signal_hipass5_data {
t_rtbuf_signal signal;
t_rtbuf_signal_sample x1;
t_rtbuf_signal_sample x2;
t_rtbuf_signal_sample x3;
t_rtbuf_signal_sample x4;
t_rtbuf_signal_sample x5;
t_rtbuf_signal_sample y1;
t_rtbuf_signal_sample y2;
t_rtbuf_signal_sample y3;
t_rtbuf_signal_sample y4;
t_rtbuf_signal_sample y5;
} s_rtbuf_signal_hipass5_data;
int rtbuf_signal_hipass5 (s_rtbuf *rtb);
int rtbuf_signal_hipass5_start (s_rtbuf *rtb);
/* butterworth lowpass filter, first order */
typedef struct rtbuf_signal_lowpass_data {
t_rtbuf_signal signal;
t_rtbuf_signal_sample x1;
t_rtbuf_signal_sample y1;
} s_rtbuf_signal_lowpass_data;
enum {
RTBUF_SIGNAL_LOWPASS_IN_SIGNAL = 0,
RTBUF_SIGNAL_LOWPASS_IN_CUTOFF,
RTBUF_SIGNAL_LOWPASS_INS
};
int rtbuf_signal_lowpass (s_rtbuf *rtb);
int rtbuf_signal_lowpass_start (s_rtbuf *rtb);
/* butterworth lowpass filter, second order */
typedef struct rtbuf_signal_lowpass2_data {
t_rtbuf_signal signal;
t_rtbuf_signal_sample x1;
t_rtbuf_signal_sample x2;
t_rtbuf_signal_sample y1;
t_rtbuf_signal_sample y2;
} s_rtbuf_signal_lowpass2_data;
int rtbuf_signal_lowpass2 (s_rtbuf *rtb);
int rtbuf_signal_lowpass2_start (s_rtbuf *rtb);
/* butterworth lowpass filter, third order */
typedef struct rtbuf_signal_lowpass3_data {
t_rtbuf_signal signal;
t_rtbuf_signal_sample x1;
t_rtbuf_signal_sample x2;
t_rtbuf_signal_sample x3;
t_rtbuf_signal_sample y1;
t_rtbuf_signal_sample y2;
t_rtbuf_signal_sample y3;
} s_rtbuf_signal_lowpass3_data;
int rtbuf_signal_lowpass3 (s_rtbuf *rtb);
int rtbuf_signal_lowpass3_start (s_rtbuf *rtb);
/* butterworth lowpass filter, fourth order */
typedef struct rtbuf_signal_lowpass4_data {
t_rtbuf_signal signal;
t_rtbuf_signal_sample x1;
t_rtbuf_signal_sample x2;
t_rtbuf_signal_sample x3;
t_rtbuf_signal_sample x4;
t_rtbuf_signal_sample y1;
t_rtbuf_signal_sample y2;
t_rtbuf_signal_sample y3;
t_rtbuf_signal_sample y4;
} s_rtbuf_signal_lowpass4_data;
int rtbuf_signal_lowpass4 (s_rtbuf *rtb);
int rtbuf_signal_lowpass4_start (s_rtbuf *rtb);
/* butterworth lowpass filter, fifth order */
typedef struct rtbuf_signal_lowpass5_data {
t_rtbuf_signal signal;
t_rtbuf_signal_sample x1;
t_rtbuf_signal_sample x2;
t_rtbuf_signal_sample x3;
t_rtbuf_signal_sample x4;
t_rtbuf_signal_sample x5;
t_rtbuf_signal_sample y1;
t_rtbuf_signal_sample y2;
t_rtbuf_signal_sample y3;
t_rtbuf_signal_sample y4;
t_rtbuf_signal_sample y5;
} s_rtbuf_signal_lowpass5_data;
int rtbuf_signal_lowpass5 (s_rtbuf *rtb);
int rtbuf_signal_lowpass5_start (s_rtbuf *rtb);
/* sawtooth */
typedef struct rtbuf_signal_sawtooth_data {
t_rtbuf_signal signal;
double phase;
} s_rtbuf_signal_sawtooth_data;
enum {
RTBUF_SIGNAL_SAWTOOTH_IN_FREQUENCY = 0,
RTBUF_SIGNAL_SAWTOOTH_IN_AMPLITUDE,
RTBUF_SIGNAL_SAWTOOTH_IN_N
};
int rtbuf_signal_sawtooth (s_rtbuf *rtb);
int rtbuf_signal_sawtooth_start (s_rtbuf *rtb);
/* sinus */
typedef struct rtbuf_signal_sinus_data {
t_rtbuf_signal signal;
double phase;
} s_rtbuf_signal_sinus_data;
enum {
RTBUF_SIGNAL_SINUS_IN_FREQUENCY = 0,
RTBUF_SIGNAL_SINUS_IN_AMPLITUDE,
RTBUF_SIGNAL_SINUS_IN_N
};
int rtbuf_signal_sinus (s_rtbuf *rtb);
int rtbuf_signal_sinus_start (s_rtbuf *rtb);
/* square */
enum {
RTBUF_SIGNAL_SQUARE_IN_FREQUENCY = 0,
RTBUF_SIGNAL_SQUARE_IN_AMPLITUDE,
RTBUF_SIGNAL_SQUARE_IN_PULSE,
RTBUF_SIGNAL_SQUARE_IN_N
};
typedef struct rtbuf_signal_square_data {
t_rtbuf_signal signal;
double phase;
} s_rtbuf_signal_square_data;
int rtbuf_signal_square (s_rtbuf *rtb);
int rtbuf_signal_square_start (s_rtbuf *rtb);
const double sqrt2_2;
#endif /* RTBUF_SIGNAL_H */