From 4a2cc8ff7154fcbb4d6e68102e32b7720dec2acb Mon Sep 17 00:00:00 2001 From: xenakios Date: Sun, 3 Dec 2017 18:39:47 +0200 Subject: [PATCH] Initial work to separate spectrum processing implementations into stand alone functions from the ProcessedStretch class, to allow visualizations etc without having to instantiate the full ProcessedStretch object --- Source/PS_Source/ProcessedStretch.cpp | 9 -- Source/PS_Source/ProcessedStretch.h | 148 ++++++++++++++++++++++++++ 2 files changed, 148 insertions(+), 9 deletions(-) diff --git a/Source/PS_Source/ProcessedStretch.cpp b/Source/PS_Source/ProcessedStretch.cpp index 13291ba..3a26779 100644 --- a/Source/PS_Source/ProcessedStretch.cpp +++ b/Source/PS_Source/ProcessedStretch.cpp @@ -174,15 +174,6 @@ void ProcessedStretch::process_spectrum(REALTYPE *freq) //void ProcessedStretch::process_output(REALTYPE *smps,int nsmps){ //}; - -REALTYPE profile(REALTYPE fi, REALTYPE bwi){ - REALTYPE x=fi/bwi; - x*=x; - if (x>14.71280603) return 0.0; - return exp(-x);///bwi; - -}; - void ProcessedStretch::do_harmonics(REALTYPE *freq1,REALTYPE *freq2){ REALTYPE freq=pars.harmonics.freq; REALTYPE bandwidth=pars.harmonics.bandwidth; diff --git a/Source/PS_Source/ProcessedStretch.h b/Source/PS_Source/ProcessedStretch.h index 056b194..3a12640 100644 --- a/Source/PS_Source/ProcessedStretch.h +++ b/Source/PS_Source/ProcessedStretch.h @@ -180,6 +180,154 @@ struct ProcessParameters } }; +inline REALTYPE profile(REALTYPE fi, REALTYPE bwi) { + REALTYPE x = fi / bwi; + x *= x; + if (x>14.71280603) return 0.0; + return exp(-x);///bwi; + +}; + +inline void spectrum_do_harmonics(ProcessParameters& pars, std::vector& tmpfreq1, int nfreq, double samplerate, REALTYPE *freq1, REALTYPE *freq2) { + REALTYPE freq = pars.harmonics.freq; + REALTYPE bandwidth = pars.harmonics.bandwidth; + int nharmonics = pars.harmonics.nharmonics; + + if (freq<10.0) freq = 10.0; + + REALTYPE *amp = tmpfreq1.data(); + for (int i = 0; i= samplerate / 2) break; + + bw_Hz = (pow(2.0f, bandwidth / 1200.0f) - 1.0f)*f; + bwi = bw_Hz / (2.0f*samplerate); + fi = f / samplerate; + + REALTYPE sum = 0.0f; + REALTYPE max = 0.0f; + for (int i = 1; imax) max = amp[i]; + }; + if (max<1e-8f) max = 1e-8f; + + for (int i = 1; i0) && (i2= nfreq) break; + freq2[i2] += freq1[i]; + }; + }; + if (_rap >= 1.0) {//up + _rap = 1.0f / _rap; + for (int i = 0; i& sumfreq, + std::vector& tmpfreq1, + REALTYPE *freq1, REALTYPE *freq2) { + spectrum_zero(nfreq,sumfreq.data()); + if (pars.octave.om2>1e-3) { + spectrum_do_pitch_shift(pars,nfreq, freq1, tmpfreq1.data(), 0.25); + spectrum_add(nfreq, sumfreq.data(), tmpfreq1.data(), pars.octave.om2); + }; + if (pars.octave.om1>1e-3) { + spectrum_do_pitch_shift(pars,nfreq, freq1, tmpfreq1.data(), 0.5); + spectrum_add(nfreq,sumfreq.data(), tmpfreq1.data(), pars.octave.om1); + }; + if (pars.octave.o0>1e-3) { + spectrum_add(nfreq,sumfreq.data(), freq1, pars.octave.o0); + }; + if (pars.octave.o1>1e-3) { + spectrum_do_pitch_shift(pars,nfreq, freq1, tmpfreq1.data(), 2.0); + spectrum_add(nfreq,sumfreq.data(), tmpfreq1.data(), pars.octave.o1); + }; + if (pars.octave.o15>1e-3) { + spectrum_do_pitch_shift(pars,nfreq, freq1, tmpfreq1.data(), 3.0); + spectrum_add(nfreq,sumfreq.data(), tmpfreq1.data(), pars.octave.o15); + }; + if (pars.octave.o2>1e-3) { + spectrum_do_pitch_shift(pars, nfreq, freq1, tmpfreq1.data(), 4.0); + spectrum_add(nfreq,sumfreq.data(), tmpfreq1.data(), pars.octave.o2); + }; + + REALTYPE sum = 0.01f + pars.octave.om2 + pars.octave.om1 + pars.octave.o0 + pars.octave.o1 + pars.octave.o15 + pars.octave.o2; + if (sum<0.5f) sum = 0.5f; + for (int i = 0; i= ilow) && (i