mirror of
https://github.com/cookiengineer/audacity
synced 2025-05-03 17:19:43 +02:00
Comments and minor off by one fixes for drawing wave clips...
... and rename two shadowing variables
This commit is contained in:
parent
921b769b52
commit
a9d33f87c4
@ -783,17 +783,22 @@ bool SpecCache::CalculateOneSpectrum
|
|||||||
(settings.algorithm == SpectrogramSettings::algReassignment);
|
(settings.algorithm == SpectrogramSettings::algReassignment);
|
||||||
const size_t windowSize = settings.WindowSize();
|
const size_t windowSize = settings.WindowSize();
|
||||||
|
|
||||||
sampleCount start;
|
sampleCount from;
|
||||||
|
|
||||||
|
// xx may be for a column that is out of the visible bounds, but only
|
||||||
|
// when we are calculating reassignment contributions that may cross into
|
||||||
|
// the visible area.
|
||||||
|
|
||||||
if (xx < 0)
|
if (xx < 0)
|
||||||
start = sampleCount(
|
from = sampleCount(
|
||||||
where[0].as_double() + xx * (rate / pixelsPerSecond)
|
where[0].as_double() + xx * (rate / pixelsPerSecond)
|
||||||
);
|
);
|
||||||
else if (xx > len)
|
else if (xx > len)
|
||||||
start = sampleCount(
|
from = sampleCount(
|
||||||
where[len].as_double() + (xx - len) * (rate / pixelsPerSecond)
|
where[len].as_double() + (xx - len) * (rate / pixelsPerSecond)
|
||||||
);
|
);
|
||||||
else
|
else
|
||||||
start = where[xx];
|
from = where[xx];
|
||||||
|
|
||||||
const bool autocorrelation =
|
const bool autocorrelation =
|
||||||
settings.algorithm == SpectrogramSettings::algPitchEAC;
|
settings.algorithm == SpectrogramSettings::algPitchEAC;
|
||||||
@ -802,7 +807,7 @@ bool SpecCache::CalculateOneSpectrum
|
|||||||
const size_t fftLen = windowSize * zeroPaddingFactor;
|
const size_t fftLen = windowSize * zeroPaddingFactor;
|
||||||
const auto half = fftLen / 2;
|
const auto half = fftLen / 2;
|
||||||
|
|
||||||
if (start <= 0 || start >= numSamples) {
|
if (from < 0 || from >= numSamples) {
|
||||||
if (xx >= 0 && xx < len) {
|
if (xx >= 0 && xx < len) {
|
||||||
// Pixel column is out of bounds of the clip! Should not happen.
|
// Pixel column is out of bounds of the clip! Should not happen.
|
||||||
float *const results = &out[half * xx];
|
float *const results = &out[half * xx];
|
||||||
@ -820,21 +825,21 @@ bool SpecCache::CalculateOneSpectrum
|
|||||||
{
|
{
|
||||||
auto myLen = windowSize;
|
auto myLen = windowSize;
|
||||||
// Take a window of the track centered at this sample.
|
// Take a window of the track centered at this sample.
|
||||||
start -= windowSize >> 1;
|
from -= windowSize >> 1;
|
||||||
if (start < 0) {
|
if (from < 0) {
|
||||||
// Near the start of the clip, pad left with zeroes as needed.
|
// Near the start of the clip, pad left with zeroes as needed.
|
||||||
// Start is at least -windowSize / 2
|
// from is at least -windowSize / 2
|
||||||
for (auto ii = start; ii < 0; ++ii)
|
for (auto ii = from; ii < 0; ++ii)
|
||||||
*adj++ = 0;
|
*adj++ = 0;
|
||||||
myLen += start.as_long_long(); // add a negative
|
myLen += from.as_long_long(); // add a negative
|
||||||
start = 0;
|
from = 0;
|
||||||
copy = true;
|
copy = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (start + myLen > numSamples) {
|
if (from + myLen >= numSamples) {
|
||||||
// Near the end of the clip, pad right with zeroes as needed.
|
// Near the end of the clip, pad right with zeroes as needed.
|
||||||
// newlen is bounded by myLen:
|
// newlen is bounded by myLen:
|
||||||
auto newlen = ( numSamples - start ).as_size_t();
|
auto newlen = ( numSamples - from ).as_size_t();
|
||||||
for (decltype(myLen) ii = newlen; ii < myLen; ++ii)
|
for (decltype(myLen) ii = newlen; ii < myLen; ++ii)
|
||||||
adj[ii] = 0;
|
adj[ii] = 0;
|
||||||
myLen = newlen;
|
myLen = newlen;
|
||||||
@ -844,7 +849,7 @@ bool SpecCache::CalculateOneSpectrum
|
|||||||
if (myLen > 0) {
|
if (myLen > 0) {
|
||||||
useBuffer = (float*)(waveTrackCache.Get(
|
useBuffer = (float*)(waveTrackCache.Get(
|
||||||
floatSample, sampleCount(
|
floatSample, sampleCount(
|
||||||
floor(0.5 + start.as_double() + offset * rate)
|
floor(0.5 + from.as_double() + offset * rate)
|
||||||
),
|
),
|
||||||
myLen)
|
myLen)
|
||||||
);
|
);
|
||||||
@ -858,6 +863,8 @@ bool SpecCache::CalculateOneSpectrum
|
|||||||
useBuffer = scratch;
|
useBuffer = scratch;
|
||||||
|
|
||||||
if (autocorrelation) {
|
if (autocorrelation) {
|
||||||
|
// not reassignment, xx is surely within bounds.
|
||||||
|
wxASSERT(xx >= 0);
|
||||||
float *const results = &out[half * xx];
|
float *const results = &out[half * xx];
|
||||||
// This function does not mutate useBuffer
|
// This function does not mutate useBuffer
|
||||||
ComputeSpectrum(useBuffer, windowSize, windowSize,
|
ComputeSpectrum(useBuffer, windowSize, windowSize,
|
||||||
@ -941,20 +948,22 @@ bool SpecCache::CalculateOneSpectrum
|
|||||||
{
|
{
|
||||||
result = true;
|
result = true;
|
||||||
|
|
||||||
// Can this be negative?
|
// This is non-negative, because bin and correctedX are
|
||||||
int index = (int)half * correctedX + bin;
|
auto ind = (int)half * correctedX + bin;
|
||||||
#ifdef _OPENMP
|
#ifdef _OPENMP
|
||||||
// This assignment can race if index reaches into another thread's bins.
|
// This assignment can race if index reaches into another thread's bins.
|
||||||
// The probability of a race very low, so this carries little overhead,
|
// The probability of a race very low, so this carries little overhead,
|
||||||
// about 5% slower vs allowing it to race.
|
// about 5% slower vs allowing it to race.
|
||||||
#pragma omp atomic update
|
#pragma omp atomic update
|
||||||
#endif
|
#endif
|
||||||
out[index] += power;
|
out[ind] += power;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
// not reassignment, xx is surely within bounds.
|
||||||
|
wxASSERT(xx >= 0);
|
||||||
float *const results = &out[half * xx];
|
float *const results = &out[half * xx];
|
||||||
|
|
||||||
// Do the FFT. Note that useBuffer is multiplied by the window,
|
// Do the FFT. Note that useBuffer is multiplied by the window,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user