Audacity  3.2.0
Functions
anonymous_namespace{WaveClip.cpp} Namespace Reference

Functions

void findCorrection (const std::vector< sampleCount > &oldWhere, size_t oldLen, size_t newLen, double t0, double rate, double samplesPerPixel, int &oldX0, double &correction)
 
void fillWhere (std::vector< sampleCount > &where, size_t len, double bias, double correction, double t0, double rate, double samplesPerPixel)
 
void ComputeSpectrogramGainFactors (size_t fftLen, double rate, int frequencyGain, std::vector< float > &gainFactors)
 

Function Documentation

◆ ComputeSpectrogramGainFactors()

void anonymous_namespace{WaveClip.cpp}::ComputeSpectrogramGainFactors ( size_t  fftLen,
double  rate,
int  frequencyGain,
std::vector< float > &  gainFactors 
)

Definition at line 523 of file WaveClip.cpp.

525 {
526  if (frequencyGain > 0) {
527  // Compute a frequency-dependent gain factor
528  // scaled such that 1000 Hz gets a gain of 0dB
529 
530  // This is the reciprocal of the bin number of 1000 Hz:
531  const double factor = ((double)rate / (double)fftLen) / 1000.0;
532 
533  auto half = fftLen / 2;
534  gainFactors.reserve(half);
535  // Don't take logarithm of zero! Let bin 0 replicate the gain factor for bin 1.
536  gainFactors.push_back(frequencyGain*log10(factor));
537  for (decltype(half) x = 1; x < half; x++) {
538  gainFactors.push_back(frequencyGain*log10(factor * x));
539  }
540  }
541 }

Referenced by SpecCache::Populate().

Here is the caller graph for this function:

◆ fillWhere()

void anonymous_namespace{WaveClip.cpp}::fillWhere ( std::vector< sampleCount > &  where,
size_t  len,
double  bias,
double  correction,
double  t0,
double  rate,
double  samplesPerPixel 
)
inline

Definition at line 297 of file WaveClip.cpp.

299 {
300  // Be careful to make the first value non-negative
301  const double w0 = 0.5 + correction + bias + t0 * rate;
302  where[0] = sampleCount( std::max(0.0, floor(w0)) );
303  for (decltype(len) x = 1; x < len + 1; x++)
304  where[x] = sampleCount( floor(w0 + double(x) * samplesPerPixel) );
305 }

Referenced by WaveClip::GetSpectrogram(), and WaveClip::GetWaveDisplay().

Here is the caller graph for this function:

◆ findCorrection()

void anonymous_namespace{WaveClip.cpp}::findCorrection ( const std::vector< sampleCount > &  oldWhere,
size_t  oldLen,
size_t  newLen,
double  t0,
double  rate,
double  samplesPerPixel,
int &  oldX0,
double &  correction 
)
inline

Definition at line 253 of file WaveClip.cpp.

257 {
258  // Mitigate the accumulation of location errors
259  // in copies of copies of ... of caches.
260  // Look at the loop that populates "where" below to understand this.
261 
262  // Find the sample position that is the origin in the old cache.
263  const double oldWhere0 = oldWhere[1].as_double() - samplesPerPixel;
264  const double oldWhereLast = oldWhere0 + oldLen * samplesPerPixel;
265  // Find the length in samples of the old cache.
266  const double denom = oldWhereLast - oldWhere0;
267 
268  // What sample would go in where[0] with no correction?
269  const double guessWhere0 = t0 * rate;
270 
271  if ( // Skip if old and NEW are disjoint:
272  oldWhereLast <= guessWhere0 ||
273  guessWhere0 + newLen * samplesPerPixel <= oldWhere0 ||
274  // Skip unless denom rounds off to at least 1.
275  denom < 0.5)
276  {
277  // The computation of oldX0 in the other branch
278  // may underflow and the assertion would be violated.
279  oldX0 = oldLen;
280  correction = 0.0;
281  }
282  else
283  {
284  // What integer position in the old cache array does that map to?
285  // (even if it is out of bounds)
286  oldX0 = floor(0.5 + oldLen * (guessWhere0 - oldWhere0) / denom);
287  // What sample count would the old cache have put there?
288  const double where0 = oldWhere0 + double(oldX0) * samplesPerPixel;
289  // What correction is needed to align the NEW cache with the old?
290  const double correction0 = where0 - guessWhere0;
291  correction = std::max(-samplesPerPixel, std::min(samplesPerPixel, correction0));
292  wxASSERT(correction == correction0);
293  }
294 }

References min().

Referenced by WaveClip::GetSpectrogram(), and WaveClip::GetWaveDisplay().

Here is the call graph for this function:
Here is the caller graph for this function:
min
int min(int a, int b)
Definition: CompareAudioCommand.cpp:106
sampleCount
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:18