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

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

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

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

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

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

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