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 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882
|
/*
* Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/>
* (C) 2020 Stefano Tronci <stefano.tronci@protonmail.com>
*
* This file is part of lsp-dsp-units
* Created on: 12 Jul 2017
*
* lsp-dsp-units is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* lsp-dsp-units is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with lsp-dsp-units. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef LSP_PLUG_IN_DSP_UNITS_UTIL_SYNCCHIRPPROCESSOR_H_
#define LSP_PLUG_IN_DSP_UNITS_UTIL_SYNCCHIRPPROCESSOR_H_
#include <lsp-plug.in/dsp-units/version.h>
#include <lsp-plug.in/dsp-units/iface/IStateDumper.h>
#include <lsp-plug.in/dsp-units/util/Oversampler.h>
#include <lsp-plug.in/dsp-units/sampling/Sample.h>
#include <lsp-plug.in/dsp-units/misc/windows.h>
#include <lsp-plug.in/common/status.h>
#include <lsp-plug.in/runtime/LSPString.h>
#include <lsp-plug.in/io/Path.h>
namespace lsp
{
namespace dspu
{
enum scp_method_t
{
SCP_SYNTH_SIMPLE, // Pure math chirp and inverse filter
SCP_SYNTH_CHIRPBANDLIMITED, // Band limited chirp, pure math inverse filter
SCP_SYNTH_BANDLIMITED, // Band limited chirp and inverse filter
SCP_SYNTH_MAX
};
enum scp_fade_t
{
SCP_FADE_NONE, // No fade in - fade out
SCP_FADE_RAISED_COSINES, // Raised cosine like shapes for fade in and fade out
SCP_FADE_MAX
};
enum scp_rtcalc_t
{
SCP_RT_EDT_0, // Early Decay Time with 0 dB upper limit
SCP_RT_EDT_1, // Early Decay Time with 1 dB upper limit
SCP_RT_T_10, // T 19
SCP_RT_T_20, // T 20
SCP_RT_T_30, // T 30
SCP_RT_MAX,
SCP_RT_DEFAULT = SCP_RT_EDT_0
};
class LSP_DSP_UNITS_PUBLIC SyncChirpProcessor
{
private:
SyncChirpProcessor & operator = (const SyncChirpProcessor &);
SyncChirpProcessor(const SyncChirpProcessor &);
protected:
// Chirp parameters:
typedef struct chirp_t
{
// Tunable properties:
scp_method_t enMethod; // Synthesis method
double initialFrequency; // Initial chirp frequency [Hz]
double finalFrequency; // Final chirp frequency [Hz]
float fDuration; // Chirp duration [s]
float fAlpha; // Chirp amplitude. This parameter is here as the inverse filter needs scaling too to be matched to the chirp.
// Calculated properties:
float fDurationCoarse; // Pre-optimisation value of fDuration [s]
size_t nDuration; // Chirp duration [samples]
size_t nTimeLags; // Number of higher order responses time lags calculated
size_t nOrder; // Number of harmonics of the initial frequency covered by the chirp
double beta; // Initial angular frequency [rad /s]
double gamma; // Exponential time constant [1 / s]
double delta; // Chirp constant
float fConvScale; // Scale factor for convolution
bool bAsymptotic; // True if the chirp is asymptotic. The theory of nonlinear profiling holds for asymptotic chirps.
bool bRecalculate; // If true, recalculate the chirp related parameters
bool bReconfigure; // If true, reconfigure all the time series
} chirp_t;
// Fader parameters:
typedef struct fader_t
{
// Tunable properties:
scp_fade_t enMethod; // Fading method
float fFadeIn; // Fade in time [s]
float fFadeOut; // Fade out time [s]
// Calculated properties:
size_t nFadeIn; // Fade in time [samples]
size_t nFadeIn_Over; // Fade in time, oversampled [samples]
size_t nFadeOut; // Fade out time [samples]
size_t nFadeOut_Over; // Fade out time, oversampled [samples]
} fader_t;
// Convolution Parameters
typedef struct conv_t
{
size_t nChannels; // Number of channels of convolution result
size_t nPartitionSize; // Size of the partition used to compute convolution [samples]
size_t nConvRank; // Rank of single partition convolution
size_t nImage; // Size of single partition convolution images [samples]
size_t nAllocationSize; // Number of samples to allocate for convolution result AudioFile object [samples]
size_t *vPartitions; // Number of partitions used to cover each single padded input time series for each channel
size_t *vPaddedLengths; // Length of each input time series for each channel, padded with zeros so to be long an integer number of partition sizes [samples] - The zero pad is not real (allocated), but convolution happens as if it was.
size_t *vInversePrepends; // Length of the zero prepending at the inverse filter, so that the total length of prepend + filter is the same as the padded channel length [samples] - The zero prepend is not real (allocated), but convolution happens as if it was.
size_t *vConvLengths; // For each channel in the convolution result, the length of the result stored therein, counted from the beginning [samples]
size_t *vAlignOffsets; // For each channel in the convolution result, the offset with which the result has to be stored so that all the origins of times are aligned [samples]
uint8_t *pData;
float *vInPart; // Holds a single input time series partition
float *vInvPart; // Holds a single inverse filter partition
float *vInImage; // Holds a single input time series FFT image
float *vInvImage; // Holds a single inverse filter FFT image
float *vTemp; // Holds temporary data
uint8_t *pTempData;
bool bReallocateTemp;
} conv_t;
// Convolution Result Post-processing values:
typedef struct crpostproc_t
{
// Background Noise Properties
double noiseLevel; // Background noise level [dB]
double noiseValue; // Background noise level [linear scale]
// Optimal Convolution Result Positive Time Backwards Integration limit
float fIrLimit; // Integration Limit [s]
size_t nIrLimit; // Integration Limit [samples]
// Background Noise Properties, normalised by Positive Time Convolution Result Total Energy
// (energy within origin of time and the optimal limit)
double noiseLevelNorm;
double noiseValueNorm;
bool bLowNoise; // If true, the noise was low enough for the requested RT calculation
// Reverberation time, through Convolution Result Positive Time Backwards Integration
size_t nRT; // Reverberation time [samples]
float fRT; // Reverberation time [s]
float fCorrelation; // Reverberation regression line correlation coefficient
// Matrices for nonlinear identification procedure:
size_t nHamOrder; // Order of the Hammerstain model to identify
size_t nHwinSize; // Size of the window to separate higher order responses
size_t nWinRank; // Rank of the window (power of two expressing the window size)
double mCoeffsReDet; // Determinant of matrix of Linear System Coefficients (Real Part)
double mCoeffsImDet; // Determinant of matrix of Linear System Coefficients (Imaginary Part)
float *mCoeffsRe; // Matrix of real parts of Linear System Coefficients
float *mCoeffsIm; // Matrix of imag parts of Linear System Coefficients
float *mHigherRe; // Matrix of real parts of higher order frequency responses
float *mHigherIm; // Matrix of imag parts of higher order frequency responses
float *mKernelsRe; // Matrix of real parts of model kernels
float *mKernelsIm; // Matrix of imag parts of model kernels
float *vTemprow1Re; // Temporary rows for kernel matrix calculation
float *vTemprow1Im;
float *vTemprow2Re;
float *vTemprow2Im;
uint8_t *pData;
} crpostproc_t;
private:
size_t nSampleRate;
chirp_t sChirpParams;
fader_t sFader;
conv_t sConvParams;
crpostproc_t sCRPostProc;
Sample *pChirp;
Sample *pInverseFilter;
Sample *pConvResult;
Oversampler sOver1; // Oversampler for Band Limited chirp synthesis.
Oversampler sOver2; // Oversampler for Band Limited inverse filter synthesis.
over_mode_t enOverMode; // Oversampler mode.
size_t nOversampling; // Hold oversampling factor. This assumes all the oversamples used here will have the same factor.
float *vOverBuffer1; // Temporary buffer for oversampled synthesis
float *vOverBuffer2; // Temporary buffer for oversampled synthesis
float *vEnvelopeBuffer; // Buffer for Convolution Result Envelope processing
uint8_t *pData;
bool bSync;
public:
explicit SyncChirpProcessor();
~SyncChirpProcessor();
void construct();
/** Initialise SynchronizedChirp
*
*/
bool init();
/** Destroy SynchronizedChirp
*
*/
void destroy();
protected:
/** Calculate the best partition size for convolution. Also computes rank and image size.
*
* @param partSizeLimit max partition size
*/
void calculateConvolutionPartitionSize(size_t partSizeLimit);
/** Allocate arrays for channel dependent properties.
*
* @param nchannels number of channels in the convolution result.
*/
status_t allocateConvolutionParameters(size_t nchannels);
/** Destroy arrays for channel dependent properties.
*
*/
void destroyConvolutionParameters();
/** Calculate convolution parameters from convolution operation input.
*
* @param data array of pointers to mono Sample objects, as many as the allocated number of channels for the result.
* @param offset 0 time index for the time series
*/
void calculateConvolutionParameters(Sample **data, size_t *offset);
/** Allocate temporary arrays for convolution.
*
*/
status_t allocateConvolutionTempArrays();
/** Destroy temporary arrays for convolution.
*
*/
void destroyConvolutionTempArrays();
/** Allocate memory for the convolution result
*
* @param size_t sampleRate sample rate of the convolution result
* @param size_t nchannels number of channels of the convolution result
* @param size_t count number of samples to be allocated
* @return status
*/
status_t allocateConvolutionResult(size_t sampleRate, size_t nchannels, size_t count);
/** Convolve a time series with the inverse filter
*
* @param data pointer to Sample object containing the time series
* @param offset 0 time index for the time series
* @param channel channel destination in the multichannel convolution result
* @return status
*/
status_t do_linear_convolution(Sample *data, size_t offset, size_t channel);
/** Allocate memory for the nonlinear identification matrices
*
* @param size_t order order of the Hammerstein model
* @param size_t windowSize size of the window to isolate the higher order responses
* @return status
*/
status_t allocateIdentificationMatrices(size_t order, size_t windowSize);
/** Destroy the nonlinear identification matrices
*
*/
void destroyIdentificationMatrices();
/** Convert from matrix subscript to allocated memory index for coefficients matrices
*
* @param size_t r row subscript
* @param size_t c column subscript
*/
inline size_t sub2ind_Coeffs(size_t r, size_t c);
/** Convert from matrix subscript to allocated memory index for data matrices (Higher and Kernels)
*
* @param size_t r row subscript
* @param size_t c column subscript
*/
inline size_t sub2ind_Data(size_t r, size_t c);
/** Fill matrices of coefficients with their values
*
*/
void fillCoefficientsMatrices();
/** Solve identification problem
*
*/
void solve();
/** Force DC Blocking in identified Hammerstein Kernels.
*
*/
void force_kernels_DC_block();
/** Window Higher Order Responses
*
* @param channel channel in the convolution result
* @param doInnerSmoothing if true, it will apply a fade in and fadeout to the the higher order response
* @param nFadeIn number of samples for the inner fade in
* @param nFadeOut number of samples for the inner fade out
* @param windowType type of smoothing window to be applied to the whole of the higher order response vector
*/
void windowHigherOrderResponses(size_t channel, bool doInnerSmoothing, size_t nFadeIn, size_t nFadeOut, windows::window_t windowType);
/** Calculate a sample of a synchronized chirp wave
*
* @param size_t sampleRate sample rate of the chirp wave
* @param size_t chirpIdx index (sample number)
* @return sample number [chirpIdx] of the chirp wave
*/
inline double calculate_chirp_sample(size_t sampleRate, size_t chirpIdx);
/** Calculate a sample of a matched synchronized chirp inverse filter (uses sample from generating chirp)
*
* @param sampleRate sample rate of the generating chirp wave (same as sample rate of the inverse filter)
* @param chirpValue value of the generating chirp wave sample
* @param chirpIdx index (sample number) of the generating chirp wave sample
* @return sample number [L - chirpIdx - 1] of the inverse filter, where L is the length of the generating chirp
*/
inline double calculate_inverse_filter_sample(size_t sampleRate, double chirpValue, size_t chirpIdx);
/** Calculate a sample of the fade-out fade-in window
*
* @param windowIdx index (sample number)
* @return sample number [windowIdx] of the fade-out fade-in window
*/
float calculate_fading_window_sample(size_t windowIdx);
/** Profile Convolution Result Background Noise (by looking at the negative times of the Convolution Result)
*
* @param head sample of the convolution result at which start analysis [samples]
* @param count number of samples to process [samples]
* @param limit number of negative time samples to use in the assessment [samples]
* @return status
*/
status_t profile_background_noise(size_t channel, size_t head, size_t count);
/** Calibrate backwards integration limit. This will calculate the limit for a backwards integration which starts
* at the supplied head parameter
*
* @param channel channel in the convolution result
* @param head sample of the convolution result from which to start analysis [samples]
* @oaram windowSize size of the window used for the envelope follower [samples]
* @param tolerance level above background noise below which, even if convolution result peaks are found, the convolution result is considered faded into noise [dB]
* @return status
*/
status_t calibrate_backwards_integration_limit(size_t channel, size_t head, size_t windowSize, double tolerance);
/** Calculate reverberation time of the positive time response by backward integration, relative to head.
*
* @param channel channel in the convolution result
* @param head sample of the convolution result from which to start analysis [samples]
* @param decayThreshold IR level threshold below which reverberation is considered complete [dB]
* @param highRegLevel higher level of the limits at which regression line fitting is to be performed [dB]
* @param lowRegLevel lower level of the limits at which regression line fitting is to be performed [dB]
* @param limit limit sample up to which the squared impulse response is summed, with respect head [samples]
* @return status
*/
status_t calculate_reverberation_time(size_t channel, size_t head, double decayThreshold, double highRegLevel, double lowRegLevel, size_t limit);
/** Calculate reverberation time of the positive time response by backward integration, relative to head.
*
* @param channel channel in the convolution result
* @param head sample of the convolution result from which to start analysis [samples]
* @param rtCalc reverberation time calculation method
* @param limit integration limit [samples]
* @return status
*/
status_t calculate_reverberation_time(size_t channel, size_t head, scp_rtcalc_t rtCalc, size_t limit);
/** Calculate the binomial coefficient n over k (n choose k)
*
* @param n top integer or set size
* @param k bottom integer or subset size
* @return value of the binomial coefficient given an and k
*/
double nchoosek(size_t n, size_t k);
public:
/** Allocate and calculate time series
*
* @return status
*/
status_t reconfigure();
/** Do multiple convolutions, each for each channel in the convolution result
*
* @param data array of pointers to mono Sample objects, as many as the allocated number of channels for the result.
* @param offset 0 time index for the time series
* @param nchannels number of channels in the convolution result
* @param partSizeLimit maximum size for convolution partision size
*/
status_t do_linear_convolutions(Sample **data, size_t *offset, size_t nchannels, size_t partSizeLimit);
/** Postprocess the Linear Convolution result
*
* @param channel channel in the convolution result
* @param offset samples offset from the middle of the convolution result [samples]
* @param rtCalc reverberation time calculation method
* @oaram windowSize size of the window used for the envelope follower [s]
* @param tolerance level above background noise below which, even if convolution result peaks are found, the convolution result is considered faded into noise [dB]
*
*/
status_t postprocess_linear_convolution(size_t channel, ssize_t offset, scp_rtcalc_t rtCalc, float windowSize, double tolerance);
/** Postprocess the Nonlinear Convolution result
*
* @param channel channel in the convolution result
* @param order order of the model
* @param nFadeIn number of samples for the inner fade in
* @param nFadeOut number of samples for the inner fade out
* @param windowType type of smoothing window to be applied to the whole of the higher order response vector
* @param nWindowRank rank of resulting FIR responses kernels (exponent of 2 defining their length: 2^nWindowRank)
* @return status
*/
status_t postprocess_nonlinear_convolution(size_t channel, size_t order, bool doInnerSmoothing, size_t nFadeIn, size_t nFadeOut, windows::window_t windowType, size_t nWindowRank);
/** Save linear convolution result to file, any wanted interval
*
* @param path to file
* @param head number of the first frame to be saved
* @param count number of frames to be saved
* @return status
*/
status_t save_linear_convolution(const char *path, size_t head, size_t count);
status_t save_linear_convolution(const LSPString *path, size_t head, size_t count);
status_t save_linear_convolution(const io::Path *path, size_t head, size_t count);
/** Save linear convolution result to file, any wanted interval, starting point specified
* as offset from middle of convolution result.
*
* @param path to file
* @param offset frames offset from the middle frame
* @param count number of frames to be saved
* @return status
*/
status_t save_linear_convolution(const char *path, ssize_t offset, size_t count);
status_t save_linear_convolution(const LSPString *path, ssize_t offset, size_t count);
status_t save_linear_convolution(const io::Path *path, ssize_t offset, size_t count);
/** Save linear convolution result to file, positive time only
*
* @param path to file
* @param count number of frames to be saved
* @return status
*/
status_t save_linear_convolution(const char *path, size_t count);
status_t save_linear_convolution(const LSPString *path, size_t count);
status_t save_linear_convolution(const io::Path *path, size_t count);
/** Save nonlinear convolution result to file
*
* @path path to file
* @param offset frames offset from the middle frame (stored as a value only)
* @return status
*/
status_t save_to_lspc(const char *path, ssize_t offset = 0);
status_t save_to_lspc(const LSPString *path, ssize_t offset = 0);
status_t save_to_lspc(const io::Path *path, ssize_t offset = 0);
/** Load convolution result and chirp parameters from lspc file
*
* @path path to file
* @return status
*/
status_t load_from_lspc(const char *path);
status_t load_from_lspc(const LSPString *path);
status_t load_from_lspc(const io::Path *path);
public:
/** Check that SynchronizedChirp needs settings update
*
* @return true if SynchronizedChirp needs setting update
*/
inline bool needs_update() const
{
return bSync;
}
/** Update SynchronizedChirp stateful settings
*
*/
void update_settings();
/** Set sample rate for SynchronizedChirp
*
* @param sr sample rate
*/
inline void set_sample_rate(size_t sr)
{
if (nSampleRate == sr)
return;
nSampleRate = sr;
sChirpParams.bRecalculate = true;
sChirpParams.bReconfigure = true;
bSync = true;
}
/** Set chirp synthesis method
*
* @param method synthesis method
*/
inline void set_chirp_synthesis_method(scp_method_t method)
{
if ((method < SCP_SYNTH_SIMPLE) || (method >= SCP_SYNTH_MAX))
return;
sChirpParams.enMethod = method;
sChirpParams.bReconfigure = true;
}
/** Set chirp initial frequency
*
* @param initialFrequency initial frequency in Hertz
*/
inline void set_chirp_initial_frequency(double initialFrequency)
{
if (sChirpParams.initialFrequency == initialFrequency)
return;
sChirpParams.initialFrequency = initialFrequency;
sChirpParams.bRecalculate = true;
sChirpParams.bReconfigure = true;
bSync = true;
}
/** Set chirp final frequency
*
* @param finalFrequency final frequency in Hertz
*/
inline void set_chirp_final_frequency(double finalFrequency)
{
if (sChirpParams.finalFrequency == finalFrequency)
return;
sChirpParams.finalFrequency = finalFrequency;
sChirpParams.bRecalculate = true;
sChirpParams.bReconfigure = true;
bSync = true;
}
/** Set chirp duration in seconds
*
* @param duration chirp duration in seconds
*/
inline void set_chirp_duration(float duration)
{
if ((sChirpParams.fDurationCoarse <= duration) && (sChirpParams.fDuration >= duration)) // Same coarse value => same optimized value
return;
sChirpParams.fDuration = duration;
sChirpParams.bRecalculate = true;
sChirpParams.bReconfigure = true;
bSync = true;
}
/** Set chirp amplitude
*
* @param amplitude chirp amplitude
*/
inline void set_chirp_amplitude(float amplitude)
{
if (sChirpParams.fAlpha == amplitude)
return;
sChirpParams.fAlpha = amplitude;
sChirpParams.bReconfigure = true;
bSync = true;
}
/** Set fader fading method
*
* @param method fading method
*/
inline void set_fader_fading_method(scp_fade_t method)
{
if ((method < SCP_FADE_NONE) || (method >= SCP_FADE_MAX))
return;
sFader.enMethod = method;
sChirpParams.bReconfigure = true;
}
/** Set fader fade in time
*
* @param fadeIn fading in time [s]
*/
inline void set_fader_fadein(float fadeIn)
{
if (sFader.fFadeIn == fadeIn)
return;
sFader.fFadeIn = fadeIn;
sChirpParams.bReconfigure = true;
bSync = true;
}
/** Set fader fade out time
*
* @param fadeOut fading out time [s]
*/
inline void set_fader_fadeout(float fadeOut)
{
if (sFader.fFadeOut == fadeOut)
return;
sFader.fFadeOut = fadeOut;
sChirpParams.bReconfigure = true;
bSync = true;
}
/** Get chirp initial frequency
*
* @return chirp initial frequency
*/
inline double get_chirp_initial_frequency() const
{
return sChirpParams.initialFrequency;
}
/** Get chirp final frequency
*
* @return chirp final frequency
*/
inline double get_chirp_final_frequency() const
{
return sChirpParams.finalFrequency;
}
/** Get chirp amplitude
*
* @return chirp amplitude
*/
inline float get_chirp_alpha() const
{
return sChirpParams.fAlpha;
}
/** Get chirp gamma factor
*
* @return chirp gamma
*/
inline double get_chirp_gamma() const
{
return sChirpParams.gamma;
}
/** Get chirp delta factor
*
* @return chirp delta
*/
inline double get_chirp_delta() const
{
return sChirpParams.delta;
}
/** Get chirp duration
*
* @return chirp duration in seconds
*/
inline float get_chirp_duration_seconds() const
{
return sChirpParams.fDuration;
}
/** Get integration limit time in seconds
*
*/
inline float get_integration_limit_seconds() const
{
return sCRPostProc.fIrLimit;
}
/** Return whether the background noise was optimal for the requested RT measurement
*
*/
inline bool get_background_noise_optimality() const
{
return sCRPostProc.bLowNoise;
}
/** Get reverberation time in samples
*
*/
inline size_t get_reverberation_time_samples() const
{
return sCRPostProc.nRT;
}
/** Get reverberation time in seconds
*
*/
inline float get_reverberation_time_seconds() const
{
return sCRPostProc.fRT;
}
/** Get reverberation regression line correlation coefficient
*
*/
inline float get_reverberation_correlation() const
{
return sCRPostProc.fCorrelation;
}
/** Get coefficients matrix real part
*
*/
inline float * get_coefficients_matrix_real_part() const
{
return sCRPostProc.mCoeffsRe;
}
/** Get coefficients matrix imaginary part
*
*/
inline float * get_coefficients_matrix_imaginary_part() const
{
return sCRPostProc.mCoeffsIm;
}
/** Get higher order responses matrix real part
*
*/
inline float * get_higher_matrix_real_part() const
{
return sCRPostProc.mHigherRe;
}
/** Get higher order responses matrix imaginary part
*
*/
inline float * get_higher_matrix_imaginary_part() const
{
return sCRPostProc.mHigherIm;
}
/** Get kernels matrix real part
*
*/
inline float * get_kernels_matrix_real_part() const
{
return sCRPostProc.mKernelsRe;
}
/** Get kernels matrix imaginary part
*
*/
inline float * get_kernels_matrix_imaginary_part() const
{
return sCRPostProc.mKernelsIm;
}
/** Fill a matrix with kernel FIR taps
*
* dst destination matrix. Must be size of order by windowSize.
* return status
*/
status_t fill_with_kernel_taps(float *dst);
/** Get a single kernel FIR taps
* dst destination buffer. Must be at least windowSize long.
* order requested order.
* return status
*/
status_t get_kernel_fir(float *dst, size_t order);
/** Get chirp
*
* @return pointer to chirp Sample object
*/
inline Sample * get_chirp() const
{
return pChirp;
}
/** Get inverse filter
*
* @return pointer to inverse filter Sample object
*/
inline Sample * get_inverse_filter() const
{
return pInverseFilter;
}
/** Get convolution result
*
* @return pointer to convolution result Sample object
*/
inline Sample * get_convolution_result() const
{
return pConvResult;
}
/** Get convolution result positive time length in seconds
*
* @return length convolution result positive time length in seconds
*/
float get_convolution_result_positive_time_length() const;
/** Get convolution result samples for plots, arbitrary initial head
*
* @param channel channel in the convolution result
* @param dst pointer to destination data
* @param head sample of the convolution result from which to start collecting plot data
* @param convLimit sample of the convolution result up to which the plot data are extracted, relative to head
* @param plotCount requested samples for plot
*/
void get_convolution_result_plottable_samples(size_t channel, float *dst, size_t head, size_t convLimit, size_t plotCount, bool normalize = true);
/** Get convolution result samples for plots, arbitrary initial offset
*
* @param channel channel in the convolution result
* @param dst pointer to destination data
* @param offset samples offset from the middle of the convolution result from which to start collecting plot data
* @param convLimit sample of the convolution result up to which the plot data are extracted, relative to head
* @param plotCount requested samples for plot
* @param normalize if true, normalise the plot samples with respect convolution result peak
*/
void get_convolution_result_plottable_samples(size_t channel, float *dst, ssize_t offset, size_t convLimit, size_t plotCount, bool normalize = true);
/** Get convolution result samples for plots, starting from middle of convolution result
*
* @param channel channel in the convolution result
* @param dst pointer to destination data
* @param convLimit sample of the convolution result up to which the plot data are extracted, relative to middle
* @param plotCount requested samples for plot
*/
void get_convolution_result_plottable_samples(size_t channel, float *dst, size_t convLimit, size_t plotCount, bool normalize = true);
/** Set Oversampler mode
*
* @param mode oversampler mode
*/
inline void set_oversampler_mode(over_mode_t mode)
{
if (mode == enOverMode)
return;
enOverMode = mode;
sChirpParams.bReconfigure = true;
bSync = true;
}
/**
* Dump the state
* @param dumper dumper
*/
void dump(IStateDumper *v) const;
};
}
}
#endif /* LSP_PLUG_IN_DSP_UNITS_UTIL_SYNCCHIRPPROCESSOR_H_ */
|