1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-25 16:48:44 +02:00

Avoid needless mix/max/rms calculation when showing individual samples.

This commit is contained in:
Paul Licameli 2015-06-08 15:19:18 -04:00
parent 1b125f8fe3
commit 35e0897bf7
3 changed files with 31 additions and 24 deletions

View File

@ -988,7 +988,7 @@ void TrackArtist::DrawNegativeOffsetTrackArrows(wxDC &dc, const wxRect &rect)
void TrackArtist::DrawWaveformBackground(wxDC &dc, const wxRect &rect, const double env[],
float zoomMin, float zoomMax, bool dB,
const sampleCount where[],
const ViewInfo &viewInfo, double t0, double rate,
sampleCount ssel0, sampleCount ssel1,
bool drawEnvelope, bool bIsSyncLockSelected)
{
@ -1015,7 +1015,10 @@ void TrackArtist::DrawWaveformBackground(wxDC &dc, const wxRect &rect, const dou
dc.SetBrush(blankBrush);
dc.DrawRectangle(rect);
for (xx = 0; xx < rect.width; ++xx) {
const double samplesPerPixel = rate / viewInfo.zoom;
double where = t0 * rate;
for (xx = 0; xx < rect.width; ++xx, where += samplesPerPixel) {
// First we compute the truncated shape of the waveform background.
// If drawEnvelope is true, then we compute the lower border of the
// envelope.
@ -1040,7 +1043,7 @@ void TrackArtist::DrawWaveformBackground(wxDC &dc, const wxRect &rect, const dou
}
// We don't draw selection color for sync-lock selected tracks.
sel = (ssel0 <= where[xx] && where[xx + 1] < ssel1) && !bIsSyncLockSelected;
sel = (ssel0 <= where && where + samplesPerPixel < ssel1) && !bIsSyncLockSelected;
if (lmaxtop == maxtop &&
lmintop == mintop &&
@ -1085,9 +1088,10 @@ void TrackArtist::DrawWaveformBackground(wxDC &dc, const wxRect &rect, const dou
if (bIsSyncLockSelected && ssel0 < ssel1) {
// Find the beginning/end of the selection
int begin, end;
for (xx = 0; xx < rect.width && where[xx] < ssel0; ++xx);
double where = t0 * rate;
for (xx = 0; xx < rect.width && where < ssel0; ++xx, where += samplesPerPixel);
begin = xx;
for (; xx < rect.width && where[xx] < ssel1; ++xx);
for (; xx < rect.width && where < ssel1; ++xx, where += samplesPerPixel);
end = xx;
DrawSyncLockTiles(&dc, wxRect(rect.x + begin, rect.y, end - 1 - begin, rect.height));
}
@ -1650,6 +1654,7 @@ void TrackArtist::DrawClipWaveform(WaveTrack *track,
const double &tpre = params.tpre;
const double &tpost = params.tpost;
const double &t1 = params.t1;
const double &rate = params.rate;
// Calculate sample-based offset-corrected selection
@ -1664,18 +1669,6 @@ void TrackArtist::DrawClipWaveform(WaveTrack *track,
float zoomMin, zoomMax;
track->GetDisplayBounds(&zoomMin, &zoomMax);
WaveDisplay display(mid.width);
bool isLoadingOD = false;//true if loading on demand block in sequence.
// The WaveClip class handles the details of computing the shape
// of the waveform. The only way GetWaveDisplay will fail is if
// there's a serious error, like some of the waveform data can't
// be loaded. So if the function returns false, we can just exit.
if (!clip->GetWaveDisplay(display,
t0, pps, isLoadingOD)) {
return;
}
// Get the values of the envelope corresponding to each pixel
// in the display, and use these to compute the height of the
// track at each pixel
@ -1687,10 +1680,23 @@ void TrackArtist::DrawClipWaveform(WaveTrack *track,
// the envelope and using a colored pen for the selected
// part of the waveform
DrawWaveformBackground(dc, mid, envValues, zoomMin, zoomMax, dB,
&display.where[0], ssel0, ssel1, drawEnvelope,
*viewInfo, t0, rate,
ssel0, ssel1, drawEnvelope,
!track->GetSelected());
if (!showIndividualSamples) {
WaveDisplay display(mid.width);
bool isLoadingOD = false;//true if loading on demand block in sequence.
// The WaveClip class handles the details of computing the shape
// of the waveform. The only way GetWaveDisplay will fail is if
// there's a serious error, like some of the waveform data can't
// be loaded. So if the function returns false, we can just exit.
if (!clip->GetWaveDisplay(display,
t0, pps, isLoadingOD)) {
return;
}
#ifdef EXPERIMENTAL_OUTPUT_DISPLAY
DrawMinMaxRMS(dc, mid, envValues, zoomMin, zoomMax, dB,
min, max, rms, bl, isLoadingOD, muted, track->GetChannelGain(track->GetChannel()));

View File

@ -21,7 +21,7 @@
#include <wx/brush.h>
#include <wx/pen.h>
#include "Experimental.h"
#include "Sequence.h"
#include "audacity/Types.h"
class wxDC;
class wxRect;
@ -144,7 +144,7 @@ class AUDACITY_DLL_API TrackArtist {
void DrawWaveformBackground(wxDC & dc, const wxRect &rect, const double env[],
float zoomMin, float zoomMax, bool dB,
const sampleCount where[],
const ViewInfo &viewInfo, double t0, double rate,
sampleCount ssel0, sampleCount ssel1,
bool drawEnvelope, bool bIsSyncLockSelected);
void DrawMinMaxRMS(wxDC &dc, const wxRect &rect, const double env[],

View File

@ -349,7 +349,8 @@ public:
#ifdef EXPERIMENTAL_USE_REALFFTF
#include "FFT.h"
static void ComputeSpectrumUsingRealFFTf(float *buffer, HFFT hFFT, const float *window, int len, float *out)
static void ComputeSpectrumUsingRealFFTf
(float *buffer, HFFT hFFT, const float *window, int len, float *out)
{
int i;
if(len > hFFT->Points*2)
@ -568,11 +569,11 @@ fillWhere(std::vector<sampleCount> &where, int len, double bias, double correcti
double t0, double rate, double samplesPerPixel)
{
// Be careful to make the first value non-negative
correction += 0.5 + bias;
where[0] = sampleCount(std::max(0.0, floor(correction + t0 * rate)));
const double w0 = 0.5 + correction + bias + t0 * rate;
where[0] = sampleCount(std::max(0.0, floor(w0)));
for (sampleCount x = 1; x < len + 1; x++)
where[x] = sampleCount(
floor(correction + t0 * rate + double(x) * samplesPerPixel)
floor(w0 + double(x) * samplesPerPixel)
);
}