mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-21 14:50:06 +02:00
Bug971: spectrogram display
This commit is contained in:
parent
1ac7d15e5c
commit
7c17d99ea5
@ -1754,9 +1754,15 @@ void TrackArtist::DrawSpectrum(WaveTrack *track,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static float sumFreqValues(float *freq, int x0, float bin0, float bin1)
|
inline
|
||||||
|
static float sumFreqValues(
|
||||||
|
const float *freq, int x, int half, float bin0, float bin1,
|
||||||
|
bool autocorrelation, int range, int gain)
|
||||||
{
|
{
|
||||||
|
const int x0 = x * half;
|
||||||
float value;
|
float value;
|
||||||
|
#if 0
|
||||||
|
// Averaging method
|
||||||
if (int(bin1) == int(bin0)) {
|
if (int(bin1) == int(bin0)) {
|
||||||
value = freq[x0+int(bin0)];
|
value = freq[x0+int(bin0)];
|
||||||
} else {
|
} else {
|
||||||
@ -1768,9 +1774,28 @@ static float sumFreqValues(float *freq, int x0, float bin0, float bin1)
|
|||||||
value += freq[x0 + int(bin0)];
|
value += freq[x0 + int(bin0)];
|
||||||
bin0 += 1.0;
|
bin0 += 1.0;
|
||||||
}
|
}
|
||||||
|
// Do not reference past end of freq array.
|
||||||
|
if (int(bin1) >= half) {
|
||||||
|
bin1 -= 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
value += freq[x0 + int(bin1)] * (bin1 - int(bin1));
|
value += freq[x0 + int(bin1)] * (bin1 - int(bin1));
|
||||||
value /= binwidth;
|
value /= binwidth;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
// Maximum method, and no apportionment of any single bins over multiple pixel rows
|
||||||
|
// See Bug971
|
||||||
|
int bin = floor(0.5 + bin0);
|
||||||
|
const int limitBin = floor(0.5 + bin1);
|
||||||
|
value = freq[x0 + bin];
|
||||||
|
while (++bin < limitBin)
|
||||||
|
value = std::max(value, freq[x0 + bin]);
|
||||||
|
#endif
|
||||||
|
if (!autocorrelation) {
|
||||||
|
// Last step converts dB to a 0.0-1.0 range
|
||||||
|
value = (value + range + gain) / (double)range;
|
||||||
|
}
|
||||||
|
value = std::min(1.0f, std::max(0.0f, value));
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2090,37 +2115,8 @@ void TrackArtist::DrawClipSpectrum(WaveTrack *track,
|
|||||||
float value;
|
float value;
|
||||||
|
|
||||||
if(!usePxCache) {
|
if(!usePxCache) {
|
||||||
if (int (bin1) == int (bin0))
|
value = sumFreqValues(freq, x, half, bin0, bin1,
|
||||||
value = freq[half * x + int (bin0)];
|
autocorrelation, range, gain);
|
||||||
else {
|
|
||||||
float binwidth= bin1 - bin0;
|
|
||||||
value = freq[half * x + int (bin0)] * (1.f - bin0 + (int)bin0);
|
|
||||||
|
|
||||||
bin0 = 1 + int (bin0);
|
|
||||||
while (bin0 < int (bin1)) {
|
|
||||||
value += freq[half * x + int (bin0)];
|
|
||||||
bin0 += 1.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Do not reference past end of freq array.
|
|
||||||
if (int(bin1) >= half) {
|
|
||||||
bin1 -= 1.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
value += freq[half * x + int (bin1)] * (bin1 - int (bin1));
|
|
||||||
|
|
||||||
value /= binwidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!autocorrelation) {
|
|
||||||
// Last step converts dB to a 0.0-1.0 range
|
|
||||||
value = (value + range + gain) / (double)range;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value > 1.0)
|
|
||||||
value = float(1.0);
|
|
||||||
if (value < 0.0)
|
|
||||||
value = float(0.0);
|
|
||||||
clip->mSpecPxCache->values[x * mid.height + yy] = value;
|
clip->mSpecPxCache->values[x * mid.height + yy] = value;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -2138,7 +2134,6 @@ void TrackArtist::DrawClipSpectrum(WaveTrack *track,
|
|||||||
{
|
{
|
||||||
unsigned char rv, gv, bv;
|
unsigned char rv, gv, bv;
|
||||||
float value;
|
float value;
|
||||||
int x0=x*half;
|
|
||||||
|
|
||||||
#ifdef EXPERIMENTAL_FIND_NOTES
|
#ifdef EXPERIMENTAL_FIND_NOTES
|
||||||
int maximas=0;
|
int maximas=0;
|
||||||
@ -2256,17 +2251,8 @@ void TrackArtist::DrawClipSpectrum(WaveTrack *track,
|
|||||||
value = minColor;
|
value = minColor;
|
||||||
} else
|
} else
|
||||||
#endif //EXPERIMENTAL_FIND_NOTES
|
#endif //EXPERIMENTAL_FIND_NOTES
|
||||||
{
|
value=sumFreqValues(freq, x, half, bin0, bin1,
|
||||||
value=sumFreqValues(freq, x0, bin0, bin1);
|
autocorrelation, range, gain);
|
||||||
if (!autocorrelation) {
|
|
||||||
// Last step converts dB to a 0.0-1.0 range
|
|
||||||
value = (value + gain + range) / (double)range;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (value > 1.0)
|
|
||||||
value = float(1.0);
|
|
||||||
if (value < 0.0)
|
|
||||||
value = float(0.0);
|
|
||||||
clip->mSpecPxCache->values[x * mid.height + yy] = value;
|
clip->mSpecPxCache->values[x * mid.height + yy] = value;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user