本文整理汇总了C++中realvec::setval方法的典型用法代码示例。如果您正苦于以下问题:C++ realvec::setval方法的具体用法?C++ realvec::setval怎么用?C++ realvec::setval使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类realvec
的用法示例。
在下文中一共展示了realvec::setval方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: in
void
StandardDeviation::myProcess(realvec& in, realvec& out)
{
mrs_natural t,o;
//checkFlow(in,out);
out.setval(0.0);
for (o=0; o < inObservations_; o++)
{
for (t = 0; t < inSamples_; t++)
{
// Calculate mean
obsrow_(t) = in(o,t);
}
out(o,0) = obsrow_.std();
}
// VERY INEFFICIENT - LOTS OF MEMORY ALLOCATION AND COPYING
// out = in.stdObs();
}
示例2: sine
void
PeakSynthOsc::myProcess(realvec& in, realvec& out)
{
out.setval(0);
silence_ = true;
pkGrp2Synth_ = ctrl_peakGroup2Synth_->to<mrs_natural>();
Nb_ = in.getSize()/peakView::nbPkParameters ; //number of peaks in the current frame
nbH_ = ctrl_harmonize_->to<mrs_realvec>().getSize();
if(nbH_)
for(mrs_natural j=0 ; j<(nbH_-1)/2 ; j++)
{
mulF_ = ctrl_harmonize_->to<mrs_realvec>()(1+j*2);
mulA_ = ctrl_harmonize_->to<mrs_realvec>()(2+j*2);
//cout << "mulF_" << mulF_ << "mulA_" << mulA_ << endl;
for (mrs_natural i=0; i < Nb_; ++i)
{
// either synthesize peaks with a corresponding GroupID or all with a group ID >= 0
mrs_bool synthMe = (pkGrp2Synth_ < 0)? (in(i+peakView::pkGroup*Nb_) >= 0) : (in(i+peakView::pkGroup*Nb_) == pkGrp2Synth_);
if( synthMe )
{
sine(out, in(i)*mulF_, in(i+Nb_)*mulA_, in(i+2*Nb_));
silence_ = false;
}
}
}
else
for (mrs_natural i=0; i < Nb_; ++i)
{
// either synthesize peaks with a corresponding GroupID or all with a group ID >= 0
mrs_bool synthMe = (pkGrp2Synth_ < 0)? (in(i+peakView::pkGroup*Nb_) >= 0) : (in(i+peakView::pkGroup*Nb_) == pkGrp2Synth_);
if( synthMe )
{
sine(out, in(i), in(i+Nb_), in(i+2*Nb_));
silence_ = false;
}
}
//signal if at least one peak was synthesized or not
ctrl_isSilence_->setValue(silence_);
}
示例3: in
void
SCF::myProcess(realvec& in, realvec& out)
{
mrs_natural i, k, bandwidth;
double c, maxc;
double aritMean ;
//default SCF value = 1.0; (defines SCF=1.0 for silence)
out.setval(1.0);
//MPEG7 defines a grouping mechanism for the frequency bands above 1KHz
//in order to reduce computational effort of the following calculation.
//For now such grouping mechanism is not implemented...
for(i = 0; i < nrValidBands_; ++i)
{
aritMean = 0.0;
maxc = 0.0;
bandwidth = ih_[i] - il_[i] + 1;
for(k = il_[i]; k <= ih_[i]; k++)
{
c = in(k); //power spectrum coeff
aritMean += c / bandwidth;
if(c > maxc)
maxc = c;
}
if (aritMean != 0.0)
{
out(i) = (float)(maxc/aritMean);
}
//else //mean power = 0 => silence...
// out(i) = 1.0; //as used for the SFM (MPEG-7)...
}
//for freq bands above the nyquist freq
//return SFM value defined in MPEG7 for silence
//for(i = nrValidBands_; i < nrBands_; ++i)
// out(i) = 1.0;
}
示例4: in
void
Krumhansl_key_finder::myProcess(realvec& in, realvec& out)
{
mrs_natural o,k;
scores_.setval(0.0);
// Correlate with each key profile
for (k = 0; k < 12; k++)
{
for (o = 0; o < inObservations_; o++)
{
scores_(k) += in(o,0) * major_profile_((o+k)%12);
}
}
mrs_real max_score = 0.0;
mrs_natural max_index = 0;
for (int k=0; k < 12; k++)
{
if (scores_(k) >= max_score)
{
max_score = scores_(k);
max_index = k;
}
}
ctrl_key_->setValue(max_index, NOUPDATE);
ctrl_key_name_->setValue(key_names_[max_index], NOUPDATE);
out.setval(0.0);
out(max_index,0) = 1.0;
}
示例5: in
//.........这里部分代码省略.........
else
{
re_ = tmp[0];
re_ = sqrt(re_ * re_);
tmp[0] = pow(re_, k_);
re_ = tmp[1];
re_ = sqrt(re_ * re_);
tmp[1] = pow(re_, k_);
}
// Compress the magnitude spectrum and zero
// the imaginary part.
for (t=1; t < fftSize_/2; t++)
{
re_ = tmp[2*t];
im_ = tmp[2*t+1];
if (k_ == 2.0)
am_ = re_ * re_ + im_ * im_;
else
{
am_ = sqrt(re_ * re_ + im_ * im_);
am_ = pow(am_, k_);
}
tmp[2*t] = am_;
tmp[2*t+1] = 0;
}
// Take the inverse Fourier Transform (of size fftSize_)
myfft_->rfft(tmp, fftSize_/2, FFT_INVERSE);
// Copy result to output
if(normalize_)
{
for (t=0; t < onSamples_; t++)
{
out(o,t) = scratch_(t)*norm_(t);
}
}
else
for (t=0; t < onSamples_; t++)
{
// out(o,t) = 0.1 * scratch_(t) + 0.99 * out(o,t);
out(o,t) = 1.0 * scratch_(t) + 0.0 * out(o,t);
// out(o,t) = 0.5 * scratch_(t) + 0.5 * out(o,t);
// out(o,t) += scratch_(t);
}
}
if (ctrl_makePositive_->to<mrs_bool>())
{
out -= out.minval();
}
if(octaveCost_) //is there a reference for this octaveCost computation [?]
{
for (o=0; o < inObservations_; o++)
{
mrs_real maxOut = 0;
for (t=1 ; t<onSamples_/2 ; t++)
if (out(o, t)> out(o, t+1) && out(o, t) > out(o, t-1) && out(o, t)>maxOut)
maxOut = out(o, t) ;
cout << maxOut/out(o, 0)<< " " << 1+voicing_ << endl;
if(maxOut && maxOut/out(o, 0) > 1-voicing_)
for (t=1; t < onSamples_; t++)
out(o, t) += octaveMax_-octaveCost_*log(36.0*t);
else
out.setval(0);
}
}
if (ctrl_setr0to1_->to<mrs_bool>())
{
// out -= out.minval();
/* for (o=0; o < onObservations_; o++)
for (t=0; t< onSamples_-1; t++)
{
out(o,t) = out(o,t) / (onSamples_ - 1 - t);
if (t > onSamples_-1-100)
out(o,t) = 0.0;
}
*/
// mrs_real myNorm = out(0,0);
// if (myNorm > 0)
// out /= myNorm;
}
if (ctrl_setr0to0_->to<mrs_bool>())
{
for (o=0; o < onObservations_; o++)
for (t=0; t < onSamples_; t++)
{
out(o,t) = out(o,t);
}
}
}
示例6: if
void
EnhADRess::myProcess(realvec& in, realvec& out)
{
out.setval(0.0);
for(mrs_natural t=0; t < inSamples_; ++t)
{
for (mrs_natural k=0; k < N4_; k++)
{
//get left channel spectrum bin
if (k==0) //DC bin (i.e. 0)
{
rel_ = in(0,t);
iml_ = 0.0;
}
else if (k == N4_-1) //Nyquist bin (i.e. N/2)
{
rel_ = in(1, t);
iml_ = 0.0;
}
else //all other bins
{
rel_ = in(2*k, t);
iml_ = in(2*k+1, t);
}
//get right channel spectrum bin
if (k==0) //DC bin (i.e. 0)
{
rer_ = in(N2_,t);
imr_ = 0.0;
}
else if (k == N4_-1) //Nyquist bin (i.e. N/2)
{
rer_ = in(N2_+1, t);
imr_ = 0.0;
}
else //all other bins
{
rer_ = in(N2_ + 2*k, t);
imr_ = in(N2_ + 2*k+1, t);
}
phaseL_ = atan2(iml_, rel_); //left channel phases
phaseR_ = atan2(imr_, rer_); //right channel phases
deltaPhase_ = abs(phaseL_ - phaseR_);
//wrap phase into the 0~2*PI range
deltaPhase_ = (mrs_real)fmod((double)deltaPhase_, (double)2*PI);
//left amplitude value
Lk_ = sqrt(rel_*rel_ + iml_*iml_);
//right amplitude value
Rk_ = sqrt(rer_*rer_ + imr_*imr_);
if(deltaPhase_ < PI/2)
{
minLk_ = Lk_ * sin(deltaPhase_);
minRk_ = Rk_ * sin(deltaPhase_);
if(Lk_ < Rk_) // i.e. minLk < minRk --> sound panned right
{
//store magnitude to output
mrs_real mag = Rk_ - minLk_;
// bins with amplitude inferior to -100dB are discarded
if(20.0*log10(mag*mag+0.000000001) > -100.0)
{
out(k,t) = mag;
//store phase to output
out(k+N4_,t) = phaseR_;
//store azimuth to output
out(k+N4_*2,t) = 1.0 - Lk_ * cos(deltaPhase_) / Rk_ ; //-1.0-> L; 0.0-> C;
}
}
else if(Lk_ > Rk_) // i.e. minLk > minRk --> sound panned left
{
//store magnitude to output
mrs_real mag = Lk_ - minRk_;
// bins with amplitude inferior to -100dB are discarded
if(20.0*log10(mag*mag+0.000000001) > -100.0)
{
out(k,t) = mag;
//store phase to output
out(k+N4_,t) = phaseL_;
//store azimuth to output
out(k+N4_*2,t) = Rk_ * cos(deltaPhase_) / Lk_ -1.0; //0.0 -> C; 1.0-> R;
}
}
else if(Lk_ == Rk_) //sound panned at the CENTER
{
//store magnitude to output
mrs_real mag = Lk_ - minRk_;
// bins with amplitude inferior to -100dB are discarded
if(20.0*log10(mag*mag+0.000000001) > -100.0)
//.........这里部分代码省略.........
示例7: getctrl
void
PeakerAdaptive::myProcess(realvec& in, realvec& out)
{
mrs_natural t,o;
mrs_real peakSpacing;
mrs_real peakStrength;
mrs_real peakGain;
mrs_natural peakStart;
mrs_natural peakEnd;
mrs_natural peakStrengthReset;
mrs_real peakDecay;
peakSpacing = getctrl("mrs_real/peakSpacing")->to<mrs_real>();
peakStrength = getctrl("mrs_real/peakStrength")->to<mrs_real>();
peakStart = getctrl("mrs_natural/peakStart")->to<mrs_natural>();
peakEnd = getctrl("mrs_natural/peakEnd")->to<mrs_natural>();
peakGain = getctrl("mrs_real/peakGain")->to<mrs_real>();
peakStrengthReset = getctrl("mrs_natural/peakStrengthReset")->to<mrs_natural>();
peakDecay = getctrl("mrs_real/peakDecay")->to<mrs_real>();
out.setval(0.0);
MRSMSG("peakEnd = " << peakEnd);
for (o = 0; o < inObservations_; o++)
{
peakSpacing = (mrs_real)(peakSpacing * inSamples_);
mrs_real max;
mrs_natural maxIndex = 0;
bool peakFound = false;
for (t=peakStart+1; t < peakEnd-1; t++)
{
if (fabs(in(o,t)) > rms_)
rms_ = fabs(in(o,t));
}
for (t=peakStart+1; t < peakEnd-1; t++)
{
// peak has to be larger than neighbors
if ((in(o,t -1) < in(o,t))
&& (in(o,t+1) < in(o,t))
&& (fabs(in(o,t)) > peakStrength * rms_)
)
{
max = in(o,t);
maxIndex = t;
for (int j=0; j < (mrs_natural)peakSpacing; j++)
{
if (t+j < peakEnd-1)
if (in(o,t+j) > max)
{
max = in(o,t+j);
maxIndex = t+j;
}
}
t += (mrs_natural)peakSpacing;
if ((peakHysterisis_ > peakStrengthReset) ||
(peakHysterisis_ == 0)
)
{
out(o,maxIndex) = fabs(in(o,maxIndex));
peakHysterisis_ = 1;
}
rms_ = fabs(in(o,maxIndex));
peakFound = true;
}
}
if (!peakFound)
{
rms_ *= peakDecay;
setctrl("mrs_bool/peakFound", false);
}
else
setctrl("mrs_bool/peakFound", true);
peakHysterisis_ ++;
}
}
示例8: pkViewOut
void
PeakConvert::myProcess(realvec& in, realvec& out)
{
mrs_natural o;
mrs_real a, c;
mrs_real b, d;
mrs_real phasediff;
out.setval(0);
peakView pkViewOut(out);
for(mrs_natural f=0 ; f < inSamples_; ++f)
{
//we should avoid the first empty frames,
//that will contain silence and consequently create
//discontinuities in the signal, ruining the peak calculation!
//only process if we have a full data vector (i.e. no zeros)
if(frame_ >= skip_)
{
// handle amplitudes from shifted spectrums at input
for (o=0; o < size_; o++)
{
if (o==0) //DC bins
{
a = in(0,f);
b = 0.0;
c = in(N_, f);
d = 0.0;
}
else if (o == size_-1) //Nyquist bins
{
a = in(1, f);
b = 0.0;
c = in(N_+1, f);
d = 0.0;
}
else //all other bins
{
a = in(2*o, f);
b = in(2*o+1, f);
c = in(N_+2*o, f);
d = in(N_+2*o+1, f);
}
// computer magnitude value
//mrs_real par = lobe_value_compute (0, 1, 2048); //[?]
// compute phase
phase_(o) = atan2(b,a);
// compute precise frequency using the phase difference
lastphase_(o)= atan2(d,c);
if(phase_(o) >= lastphase_(o))
phasediff = phase_(o)-lastphase_(o);
else
phasediff = phase_(o)-lastphase_(o)+TWOPI;
if(prec_)
frequency_(o) = phasediff * factor_ ;
else
frequency_(o) = o*fundamental_;
// compute precise amplitude
mag_(o) = sqrt((a*a + b*b))*2; //*4/0.884624;//*50/3); // [!]
mrs_real mag = lobe_value_compute((o * fundamental_-frequency_(o))/factor_, 1, N_);
magCorr_(o) = mag_(o)/mag;
// computing precise frequency using the derivative method // use at your own risk [?]
/* mrs_real lastmag = sqrt(c*c + d*d);
mrs_real rap = (mag_(o)-lastmag)/(lastmag*2);
f=asin(rap);
f *= (getctrl("mrs_real/israte")->to<mrs_real>()*inObservations/2.0)/PI;
*/
// rough frequency and amplitude
//frequency_(o) = o * fundamental_;
//magCorr_(o) = mag_(o);
if(lastfrequency_(o) != 0.0)
deltafrequency_(o) = (frequency_(o)-lastfrequency_(o))/(frequency_(o)+lastfrequency_(o));
deltamag_(o) = (mag_(o)-lastmag_(o))/(mag_(o)+lastmag_(o));
// remove potential peak if frequency too irrelevant
if(abs(frequency_(o)-o*fundamental_) > 0.5*fundamental_)
frequency_(o)=0.0;
lastfrequency_(o) = frequency_(o);
lastmag_(o) = mag_(o);
}
// select bins with local maxima in magnitude (--> peaks)
realvec peaks_ = mag_;
realvec tmp_;
peaker_->updControl("mrs_real/peakStrength", 0.2);// to be set as a control [!]
peaker_->updControl("mrs_natural/peakStart", downFrequency_); // 0
peaker_->updControl("mrs_natural/peakEnd", upFrequency_); // size_
peaker_->updControl("mrs_natural/inSamples", mag_.getCols());
peaker_->updControl("mrs_natural/inObservations", mag_.getRows());
peaker_->updControl("mrs_natural/onSamples", peaks_.getCols());
peaker_->updControl("mrs_natural/onObservations", peaks_.getRows());
if(pick_)
//.........这里部分代码省略.........
示例9: if
void
ADRessSpectrum::myProcess(realvec& in, realvec& out)
{
mrs_natural t;
out.setval(0.0);
//output spectrum of the "selected" source, given d and H
mrs_natural H = (mrs_natural)(beta_* ctrl_H_->to<mrs_natural>());
if(H < 0)
{
H = 0;
ctrl_H_->setValue(0.0);
}
if(H > beta_)
{
H = beta_;
ctrl_H_->setValue(1.0);
}
mrs_natural H2 = H/2;
mrs_natural d = (mrs_natural)(beta_*ctrl_d_->to<mrs_real>());
if(d < 0)
{
d = 0;
ctrl_d_->setValue(0.0);
}
if(d > beta_)
{
d = beta_;
ctrl_d_->setValue(1.0);
}
mrs_real mag = 0;
mrs_real phase = 0;
mrs_real azim = 0;
for(mrs_natural k=0; k < N2_; ++k)
{
//get magnitude, phase and azimuth of bin k from input
mag = 0.0;
for(t=0; t <= beta_; ++t)
{
//search for non-zero values in azimuth plane
azim = -1;
if(in(k,t+1) > 0.0)
{
azim = t;
mag = in(k,t+1);
phase = in(k, 0);
break;
}
if(in(k+N2_,t+1) > 0.0)
{
azim = beta_*2-t;
mag = in(k+N2_,t+1);
phase = in(k+N2_, 0);
break;
}
}
if(azim < 0)
{
//no sound at this bin,
//so do not send anything to output
continue;
}
//check if bin is inside specified range,
//otherwise, send nothing to output
if(abs(d-azim) <= H2)
{
//convert back to rectangular form
re_ = mag*cos(phase);
im_ = mag*sin(phase);
//write bin to output
if (k==0)
{
out(0,0) = re_; //DC
}
else if (k == N2_-1)
{
out(1, 0) = re_; //Nyquist
}
else
{
out(2*k, 0) = re_; //all other bins
out(2*k+1, 0) = im_;
}
}
}
}
示例10: getctrl
void
Peaker::myProcess(realvec& in, realvec& out)
{
mrs_natural t,o;
const mrs_natural peakSpacing = (mrs_natural)(inSamples_ *getctrl("mrs_real/peakSpacing")->to<mrs_real>() + .5);
mrs_real peakStrengthRelRms,
peakStrengthRelMax,
peakStrengthRelThresh,
peakStrengthAbs;
//mrs_real peakGain;
mrs_bool peakHarmonics;
mrs_bool rmsNormalize;
mrs_natural peakStart;
mrs_natural peakEnd;
mrs_natural interpolationMode;
mrs_natural peakNeighbors;
peakStrengthRelRms = getctrl("mrs_real/peakStrength")->to<mrs_real>();
peakStrengthRelMax = getctrl("mrs_real/peakStrengthRelMax")->to<mrs_real>();
peakStrengthRelThresh = getctrl("mrs_real/peakStrengthRelThresh")->to<mrs_real>();
lpCoeff_ = getctrl("mrs_real/peakStrengthThreshLpParam")->to<mrs_real>();
peakStrengthAbs = getctrl("mrs_real/peakStrengthAbs")->to<mrs_real>();
peakStart = getctrl("mrs_natural/peakStart")->to<mrs_natural>();
peakEnd = getctrl("mrs_natural/peakEnd")->to<mrs_natural>();
interpolationMode = getctrl("mrs_natural/interpolation")->to<mrs_natural>();
//peakGain = getctrl("mrs_real/peakGain")->to<mrs_real>();
peakHarmonics = getctrl("mrs_bool/peakHarmonics")->to<mrs_bool>();
rmsNormalize = getctrl("mrs_bool/rmsNormalize")->to<mrs_bool>();
peakNeighbors = getctrl("mrs_natural/peakNeighbors")->to<mrs_natural>();
if (peakEnd == 0)
peakEnd = inSamples_;
// FIXME This line defines an unused variable
// mrs_real srate = getctrl("mrs_real/israte")->to<mrs_real>();
out.setval(0.0);
//peakStrengthRelRms = 0.0;
for (o = 0; o < inObservations_; o++)
{
rms_ = 0.0;
max_ = -1e37;
for (t=peakStart; t < peakEnd; t++)
{
rms_ += in(o,t) * in(o,t);
if (max_ < in(o,t))
max_ = in(o,t);
}
if (rms_ != 0.0)
rms_ /= (peakEnd - peakStart);
rms_ = sqrt(rms_);
mrs_real max;
mrs_natural maxIndex;
bool peakFound = false;
if (peakStrengthRelThresh > .0)
{
in.getRow (o,lpThresh_);
compLpThresh (lpThresh_, lpThresh_); // do it inplace to avoid another copy...
}
for (t=peakStart; t < peakEnd; t++)
{
peakFound = true;
// peak has to be larger than neighbors
for (int j = 1; j < peakNeighbors; j++)
{
mrs_natural index=t-j;
if (index<0) index=0;
if (in(o,index) >= in(o,t))
{
peakFound = false;
break;
}
index=t+j;
if (index>=inSamples_) index=inSamples_-1;
if (in(o,index) >= in(o,t))
{
peakFound = false;
break;
}
}
if (peakFound)
{
currThresh_ = lpThresh_(t);
peakFound = doThresholding (in(o,t), peakStrengthRelRms, peakStrengthRelMax, peakStrengthRelThresh, peakStrengthAbs);
//.........这里部分代码省略.........
示例11: myProcess
void PeakInObservation::myProcess(realvec& inVec, realvec& outVec)
{
// (!!) Should be simplified
outVec.setval(0.f);
//int nmin = 0;
mrs_real vmin = inVec(0);
int nmax = 0;
mrs_real vmax = inVec(0);
int nthresh = 0;
bool theValid = true;
bool theMaxFlag = true;
for (mrs_natural n = 1; n < inVec.getSize(); n++){
if (theMaxFlag)
if (inVec(n) > vmax){
// Zone 1: [min hysteresis, max]
vmax = inVec(n);
nmax = n;
nthresh = n;
theValid = true;
vmin = vmax;
//nmin = nmax;
}else{
if (inVec(n)<vmax/HystFactor_ && nmax!=0){
// Zone 3: [max hysteresis, min]
if ((mrs_natural)n > nthresh + HystLength_){
// Maximum was WIDE ENOUGH
if (theValid){
outVec(nmax) = vmax;
theMaxFlag = false;
}else{
//Search for new maximum
vmax = inVec(n);
nmax = n;
nthresh = n;
theValid = true;
vmin = vmax;
//nmin = nmax;
}
}else{
// Maximum was TOO SMALL
if (inVec(n) < vmin){
vmin = inVec(n);
//nmin = n;
}
}
}else{
// Zone 2: [max, max hysteresis]
if (nthresh != (mrs_natural)n-1){
theValid = false;
if ((mrs_natural)n > nthresh + HystLength_){
// Search for new maximum
vmax = inVec(n);
nmax = n;
nthresh = n;
theValid = true;
vmin = vmax;
//nmin = nmax;
}
}else
nthresh = n;
}
}
else
if (inVec(n) < vmin){
vmin = inVec(n);
//nmin = n;
}else
if (inVec(n) > vmin*HystFactor_){
vmax = inVec(n);
nmax = n;
nthresh = 0;
vmin = vmax;
//nmin = nmax;
theValid = true;
theMaxFlag = true;
}
}
}
示例12: in
void
PeakerOnset::myProcess(realvec& in, realvec& out)
{
mrs_natural o,t;
(void) o;
ctrl_onsetDetected_->setValue(false);
ctrl_confidence_->setValue(0.0);
out.setval(0.0);
mrs_natural w = ctrl_lookAheadSamples_->to<mrs_natural>();
if(w == 0)
return;
//point to check for an onset
mrs_natural checkPoint = inSamples_-1-w;
mrs_real checkPointValue = in(checkPoint);
mrs_bool isOnset = true;
//check first condition
mrs_natural interval = mrs_natural(2.0/3.0*w);
//for (t = inSamples_-1; t >= inSamples_-1-2*w ; t--)
for(t=checkPoint-interval; t <= checkPoint+interval; t++)
{
if(checkPointValue < in(t))
{
isOnset = false;
MRSDIAG("PeakerOnset::myProcess() - Failed 1st condition!");
break;
}
}
// //new check proposed by Fabien Gouyon
// mrs_real ww = w/2;
// mrs_real maxVal = MINREAL;
// for(t = inSamples_-1-ww; t > checkPoint; t--)
// {
// if(in(t) > maxVal)
// {
// maxVal = in(t);
// }
// else
// {
// isOnset = false;
// //cout << "failed 1st condition!" << endl;
// break;
// }
// }
// maxVal = MINREAL;
// for(t = inSamples_-1-2*ww; t < checkPoint; t++)
// {
// if(in(t) > maxVal)
// {
// maxVal = in(t);
// }
// else
// {
// isOnset = false;
// //cout << "failed 1st condition!" << endl;
// break;
// }
// }
/* Last version (by lgmartins) -> corrected (below) for not being strict to the window size defined by the precede ShiftInput
//check second condition
mrs_real m = 0.0;
for(t=0; t < inSamples_; t++)
m += in(t);
m /= inSamples_;
*/
mrs_natural mul = 3; //multiplier proposed in Dixon2006
mrs_real m = 0.0;
for(t=checkPoint-(mul*w); t < inSamples_; t++)
m += in(t);
m /= (w*4+1);
//checkPoint value should be higher than the window mean and mean should
//be a significant value (otherwise we most probably are in a silence segment,
//and we do not want to detect onsets on segments!)
if(checkPointValue <= (m * ctrl_threshold_->to<mrs_real>()) || m < 10e-20)
{
isOnset = false;
MRSDIAG("PeakerOnset::myProcess() - Failed 2nd condition!");
}
//third condition from Dixon2006 (DAFx paper) is not implemented
//since it was found on that paper that its impact is minimal...
if(isOnset)
{
ctrl_onsetDetected_->setValue(true);
//ctrl_confidence_->setValue(1.0); //[!] must still find a way to output a confidence...
ctrl_confidence_->setValue(checkPointValue/100.0); // ad-hoc value which should still have more meaning than a pure 1.0 vs. 0.0.
out.setval(1.0);
MRSDIAG("PeakerOnset::myProcess() - Onset Detected!");
}
//used for toy_with_onsets.m (DO NOT DELETE! - COMMENT INSTEAD)
//.........这里部分代码省略.........
示例13: getctrl
void
TimeFreqPeakConnectivity::myProcess(realvec& in, realvec& out)
{
// get pitch resolution
const mrs_real reso = ctrl_reso_->to<mrs_real>();
const mrs_bool isInBark = getctrl("mrs_bool/inBark")->to<mrs_bool>();
// a matrix indicating where peaks are in the time frequency plane
MRSASSERT(textWinSize_ >= in(1,inSamples_-1)-in(1,0));
peakMatrix_.stretch(numBands_, textWinSize_);
// init
peakMatrix_.setval (1);
for (t = 0; t < textWinSize_; t++)
for (o=0; o < numBands_; o++)
peakIndices_[o][t] = -1;
// initialized pseudo spectrogram representation
for (t = 0; t < inSamples_; t++)
{
mrs_natural row = (isInBark)? Freq2RowIdx (in(0,t),reso) : Freq2RowIdx (bark2hertz(in(0,t)),reso), // input is in bark frequency, so we might have to convert it back
col = (mrs_natural)(in(1,t)-in(1,0)+.1);
MRSASSERT(col >= 0 && col < textWinSize_);
MRSASSERT(row >= 0 && row < numBands_);
// check whether more than one peak are at that matrix pos, i.e. we already have set the entry
if (peakIndices_[row][col] != -1)
{
multipleIndices->AddIndex (row,col,peakIndices_[row][col]);
multipleIndices->AddIndex (row,col,t);
peakIndices_[row][col] = -2;
}
else
peakIndices_[row][col] = t; // a matrix indicating which matrix bin corresponds to which input index
peakMatrix_(row, col) = 0;
}
// initialize output
out.setval (costInit);
#ifdef MATLAB_DBG_OUT
#ifdef MARSYAS_MATLAB
MATLAB_PUT(peakMatrix_, "peakMatrix");
MATLAB_EVAL ("figure(1),imagesc(peakMatrix),colorbar");
#endif
#endif
// iteration over all pairs
for (t = 0; t < inSamples_; t++)
{
for (o=inSamples_-1; o >= t;o--)
{
// don't compute distance if we already have it
if (out(t,o) != costInit)
continue;
// get peak matrix indices
mrs_natural rowt = (isInBark)? Freq2RowIdx (in(0,t),reso) : Freq2RowIdx (bark2hertz(in(0,t)),reso), // input is in bark frequency, so we might have to convert it back
rowo = (isInBark)? Freq2RowIdx (in(0,o),reso) : Freq2RowIdx (bark2hertz(in(0,o)),reso), // input is in bark frequency, so we might have to convert it back
colt = (mrs_natural)(in(1,t)-in(1,0)+.1),
colo = (mrs_natural)(in(1,o)-in(1,0)+.1),
pathLength;
MRSASSERT(colt >= 0 && colt < textWinSize_);
MRSASSERT(colo >= 0 && colo < textWinSize_);
MRSASSERT(rowt >= 0 && rowt < numBands_);
MRSASSERT(rowo >= 0 && rowo < numBands_);
// self similarity and similarity with overlapping peaks
if ((t == o) || (rowt == rowo && colt == colo))
{
SetOutput(out, 0, rowt, colt, rowo, colo);
continue;
}
// check if path calculation makes sense with the current dp step size
if (abs(rowt - rowo) > abs(colt-colo))
{
SetOutput(out, 1, rowt, colt, rowo, colo);
continue;
}
// let's calculate only from left to right
if (colo < colt)
continue;
// dynamic programming
CalcDp (peakMatrix_, rowt, colt, rowo, colo);
pathLength = colo-colt+1;
#ifdef MATLAB_DBG_OUT
#ifdef MARSYAS_MATLAB
MATLAB_PUT(costMatrix_, "cost");
MATLAB_EVAL ("figure(2),imagesc(cost,[0 10]),colorbar");
#endif
#endif
// set cost for this path and all subpaths
for (mrs_natural i = 0; i < pathLength; i++)
{
//.........这里部分代码省略.........
示例14: pkViewOut
void
PeakConvert2::myProcess(realvec& in, realvec& out)
{
mrs_natural o,i;
out.setval(0);
peakView pkViewOut(out);
const mrs_bool useMasking = getctrl("mrs_bool/useMasking")->to<mrs_bool>();
const mrs_real probThresh = getctrl("mrs_real/probabilityTresh")->to<mrs_real>();
max_->updControl("mrs_natural/nMaximums", frameMaxNumPeaks_);
max_->setctrl("mrs_natural/inSamples", size_);
max_->setctrl("mrs_natural/inObservations", 1);
max_->update();
tmp_.stretch(frameMaxNumPeaks_*2);
for(mrs_natural f=0 ; f < inSamples_; ++f)
{
//we should avoid the first empty frames,
//that will contain silence and consequently create
//discontinuities in the signal, ruining the peak calculation!
//only process if we have a full data vector (i.e. no zeros)
if(frame_ >= skip_)
{
// get pair of ffts
in.getCol (f, tmpBuff_);
// compute magnitude, phase, and instantaneous frequency
this->ComputeMagnitudeAndPhase (tmpBuff_);
// compute masking threshold
if (useMasking && pick_)
ComputeMasking (tmpBuff_);
else
masked_.setval(10.);
// select bins with local maxima in magnitude (--> peaks)
peaks_ = mag_;
if(pick_)
this->ComputePeaker (mag_, peaks_);
else
{
for (o = 0 ; o < downFrequency_ ; o++)
peaks_(o)=0.0;
for (o = upFrequency_ ; o < (mrs_natural)peaks_.getSize() ; o++)
peaks_(o)=0.0;
}
if (lpCoeff_ > 0)
FreqSmear (lpPeakerRes_);
//compute the probability of a peak being a peak
for(o=0 ; o < size_ ; o++)
{
if (peaks_(o) <= 0)
{
frequency_(o) = .0;
//lastmag_(o) = .0;
lastfrequency_(o) = .0;
// time smearing if no new peak
lpPeakerRes_(o) *=lpCoeff_;
continue;
}
#ifdef ORIGINAL_VERSION
// probability of peak being a masker
peakProb_(0) = 0;
// probability of peak being stationary
peakProb_(1) = 0;
// probability of peak being tonal
peakProb_(2) = (abs(frequency_(o)/fundamental_-o) > .5)? 0 : 1;
#else
// probability of peak being a masker
peakProb_(0) = max((mrs_real).1, (mrs_real).5 * (mrs_real)(log10(masked_(o)) +1.));
// probability of peak being stationary
peakProb_(1) = max((mrs_real).1, (mrs_real)lpPeakerRes_(o));
// probability or peak being tonal
peakProb_(2) = GaussianPdf (frequency_(o)/fundamental_-o, gaussianStd);
#endif
// reset lpPeakerRes with peaker results
lpPeakerRes_(o) = 1;
peakProb_ *= peakProbWeight_;
if ((peakProb_.sum() < probThresh) && pick_)
{
peaks_(o) = .0;
frequency_(o) = .0;
//lastmag_(o) = .0;
lastfrequency_(o) = .0;
}
}
// keep only the frameMaxNumPeaks_ highest amplitude local maxima
tmp_.setval(0.);
max_->process(peaks_, tmp_);
nbPeaks_=tmp_.getSize()/2;
realvec index_(nbPeaks_); //[!] make member to avoid reallocation at each tick!
for (i=0 ; i<nbPeaks_ ; i++)
//.........这里部分代码省略.........
示例15: if
void
PeakSynthOscBank::myProcess(realvec& in, realvec& out)
{
mrs_natural t,c;
out.setval(0.0);
if (P_ > 1.0)
NP_ = (mrs_natural)(N_/P_);
else
NP_ = N_;
Iinv_ = (mrs_real)(1.0 / I_);
Pinc_ = P_ * L_ / R_;
nextamp_.setval(0);
nextfreq_.setval(0);
nextindex_.setval(0);
// FIXME This line defines a (possibly) unused variable
// bool flag = false;
if(nbH_)
{
for(mrs_natural j=0 ; j<nbH_ ; j++)
{
mrs_real mulF = ctrl_harmonize_->to<mrs_realvec>()(1+j*2);
mrs_real mulA = ctrl_harmonize_->to<mrs_realvec>()(2+j*2);
for (t=0; t < NP_; t++)
{
mrs_natural index = (mrs_natural) ceil(in(t)/R_*2048*2+0.5);
if (in(t) == 0.0 || index >= 2048)
break;
index+=j*2048;
/* save current values for next iteration */
if(nextfreq_(index))
{
cout << "PROBLEM"<<endl;
}
nextamp_(index) = in(t+NP_)*mulA;
nextfreq_(index) = in(t)*Pinc_*mulF;
}
}
}
for (mrs_natural t=0; t < nextamp_.getSize(); t++)
{
// cout << endl << index << endl;
if(lastfreq_(t) && nextfreq_(t))
{
f_ = lastfreq_(t);
finc_ = (nextfreq_(t) - f_)*Iinv_;
}
else if(nextfreq_(t))
{
f_ = nextfreq_(t);
finc_=0;
}
else
{
f_ = lastfreq_(t);
finc_=0;
}
a_ = lastamp_(t);
ainc_ = (nextamp_(t) - a_)*Iinv_;
address_ = index_(t);
/* avoid extra computing */
if ((a_ != 0.0 || ainc_!=0.0))
{
// accumulate I samples from each oscillator
// into output slice
for (c=0; c < I_; ++c)
{
naddress_ = (mrs_natural)address_ % L_;
out(0, c) += a_ * table_(naddress_);
address_ += f_;
while (address_ >= L_)
address_ -= L_;
while (address_ < 0)
address_ += L_;
a_ += ainc_;
f_ += finc_;
}
// move down one parenthesis
}
nextindex_(t) = address_;
}
lastamp_ = nextamp_;
lastfreq_ = nextfreq_;
index_ = nextindex_;
}