Audacity  3.0.3
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 589 of file WaveClip.cpp.

591 {
592  if (frequencyGain > 0) {
593  // Compute a frequency-dependent gain factor
594  // scaled such that 1000 Hz gets a gain of 0dB
595 
596  // This is the reciprocal of the bin number of 1000 Hz:
597  const double factor = ((double)rate / (double)fftLen) / 1000.0;
598 
599  auto half = fftLen / 2;
600  gainFactors.reserve(half);
601  // Don't take logarithm of zero! Let bin 0 replicate the gain factor for bin 1.
602  gainFactors.push_back(frequencyGain*log10(factor));
603  for (decltype(half) x = 1; x < half; x++) {
604  gainFactors.push_back(frequencyGain*log10(factor * x));
605  }
606  }
607 }

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 365 of file WaveClip.cpp.

367 {
368  // Be careful to make the first value non-negative
369  const double w0 = 0.5 + correction + bias + t0 * rate;
370  where[0] = sampleCount( std::max(0.0, floor(w0)) );
371  for (decltype(len) x = 1; x < len + 1; x++)
372  where[x] = sampleCount( floor(w0 + double(x) * samplesPerPixel) );
373 }

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 321 of file WaveClip.cpp.

325 {
326  // Mitigate the accumulation of location errors
327  // in copies of copies of ... of caches.
328  // Look at the loop that populates "where" below to understand this.
329 
330  // Find the sample position that is the origin in the old cache.
331  const double oldWhere0 = oldWhere[1].as_double() - samplesPerPixel;
332  const double oldWhereLast = oldWhere0 + oldLen * samplesPerPixel;
333  // Find the length in samples of the old cache.
334  const double denom = oldWhereLast - oldWhere0;
335 
336  // What sample would go in where[0] with no correction?
337  const double guessWhere0 = t0 * rate;
338 
339  if ( // Skip if old and NEW are disjoint:
340  oldWhereLast <= guessWhere0 ||
341  guessWhere0 + newLen * samplesPerPixel <= oldWhere0 ||
342  // Skip unless denom rounds off to at least 1.
343  denom < 0.5)
344  {
345  // The computation of oldX0 in the other branch
346  // may underflow and the assertion would be violated.
347  oldX0 = oldLen;
348  correction = 0.0;
349  }
350  else
351  {
352  // What integer position in the old cache array does that map to?
353  // (even if it is out of bounds)
354  oldX0 = floor(0.5 + oldLen * (guessWhere0 - oldWhere0) / denom);
355  // What sample count would the old cache have put there?
356  const double where0 = oldWhere0 + double(oldX0) * samplesPerPixel;
357  // What correction is needed to align the NEW cache with the old?
358  const double correction0 = where0 - guessWhere0;
359  correction = std::max(-samplesPerPixel, std::min(samplesPerPixel, correction0));
360  wxASSERT(correction == correction0);
361  }
362 }

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