本文整理汇总了C++中Spectrum::getBinCount方法的典型用法代码示例。如果您正苦于以下问题:C++ Spectrum::getBinCount方法的具体用法?C++ Spectrum::getBinCount怎么用?C++ Spectrum::getBinCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Spectrum
的用法示例。
在下文中一共展示了Spectrum::getBinCount方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: renderColor
void LightEffectSoundSolid::renderColor(Spectrum spectrum) {
double bassFreq = getParameter("bass freq").getValue().getDouble();
double trebbleFreq = getParameter("trebble freq").getValue().getDouble();
double bassBoost = getParameter("bass boost").getValue().getDouble();
double trebbleBoost = getParameter("trebble boost").getValue().getDouble();
double fStart = getParameter("start frequency").getValue().getDouble();
double fEnd = getParameter("end frequency").getValue().getDouble();
double dbScaler = getParameter("db scaler").getValue().getDouble();
double dbFactor = getParameter("db factor").getValue().getDouble();
double avgFactor = getParameter("average factor").getValue().getDouble();
double changeFactor = getParameter("change factor").getValue().getDouble();
double noiseFloor = getParameter("noise floor").getValue().getDouble();
double avgFilterStrength = getParameter("average filter strength").getValue().getDouble();
uint8_t minSaturation = getParameter("min saturation").getValue().getDouble()*255;
double filterStrength = getParameter("color filter strength").getValue().getDouble();
uint8_t threshold = getParameter("threshold").getValue().getDouble()*255;
double r = 0., g = 0., b = 0.;
size_t binCount = spectrum.getBinCount();
if(bassIndex == -1) {
for(bassIndex = 0; (bassIndex < binCount) &&
(spectrum.getByIndex(bassIndex).getFreqCenter() <= bassFreq); ++bassIndex);
std::cout << "Bass Index: " << bassIndex << std::endl;
for(endIndex = 0; (endIndex < binCount) &&
(spectrum.getByIndex(endIndex).getFreqCenter() <= fEnd); ++endIndex);
std::cout << "End Index: " << endIndex << std::endl;
prevSpectrum = spectrum;
}
//Compute average
double curAvg = 0;
for(unsigned int i = 0; i < endIndex; ++i) {
curAvg += spectrum.getByIndex(i).getEnergy();
}
curAvg = 20.*std::log10(curAvg/endIndex) + noiseFloor;
//double curAvg = spectrum.getAverageEnergyDB() + noiseFloor;
if(curAvg < 0)
curAvg = 0;
avg = avg*avgFilterStrength
+ curAvg*(1. - avgFilterStrength);
//Scale to be applied to each bin
double scale = 1. / dbScaler;
for(unsigned int i = 0; i < binCount; ++i) {
FrequencyBin& bin = spectrum.getByIndex(i);
double f = bin.getFreqCenter();
if(f > fEnd)
break;
if(f >= fStart) {
//float hue = (f <= bassFreq) ? 40.f*std::pow((double)i/(bassIndex-1), 4.)
//: (45.f + 240.f * (i-bassIndex) / (binCount - bassIndex - 1));
//float hue = 240. * i / (binCount - 1);
int yellowPoint = 11;
float hue;
if(i < yellowPoint) {
hue = 60. * i / (yellowPoint-1);
}
else {
hue = 60. + 180.*(i-yellowPoint) / (binCount - yellowPoint - 1);
}
Color c = Color::HSV(255.f*hue/360.f, 255, 255);
double db = bin.getEnergyDB();
FrequencyBin& prevBin = prevSpectrum.getByIndex(i);
double change = db - prevBin.getEnergyDB();
if(change < 0)
change = 0;
//Bass boost
if(f <= bassFreq)
db += bassBoost;
//Trebble boost
if(f >= trebbleFreq)
db += trebbleBoost;
//Raise by noise floor, subtract loosly-tracking average
db += noiseFloor - avg;
//Reject anything below the average
if(db < 0)
continue;
//Scale partially based on average level
db *= dbFactor;
//.........这里部分代码省略.........