1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-01 16:19:43 +02:00

Performance improvements for track spectrum display and PCM

import submitted by Sami Liedes.
This commit is contained in:
BusinessmanProgrammerSteve 2010-09-13 01:31:54 +00:00
parent 1d6e1593ee
commit c0b5fb01da
6 changed files with 101 additions and 67 deletions

View File

@ -568,46 +568,58 @@ void AColor::DarkMIDIChannel(wxDC * dc, int channel /* 1 - 16 */ )
}
void GetColorGradient(float value,
bool selected,
bool grayscale,
unsigned char *red,
unsigned char *green, unsigned char *blue)
{
float r, g, b;
bool AColor::gradient_inited = 0;
if (grayscale) {
r = g = b = 0.84 - 0.84 * value;
} else {
const int gsteps = 4;
float gradient[gsteps + 1][3] = {
{float(0.75), float(0.75), float(0.75)}, // lt gray
{float(0.30), float(0.60), float(1.00)}, // lt blue
{float(0.90), float(0.10), float(0.90)}, // violet
{float(1.00), float(0.00), float(0.00)}, // red
{float(1.00), float(1.00), float(1.00)} // white
};
unsigned char AColor::gradient_pre[2][2][gradientSteps][3];
int left = int (value * gsteps);
int right = (left == gsteps ? gsteps : left + 1);
void AColor::PreComputeGradient() {
{
if (!gradient_inited) {
gradient_inited = 1;
float rweight = (value * gsteps) - left;
float lweight = 1.0 - rweight;
for (int selected = 0; selected <= 1; selected++)
for (int grayscale = 0; grayscale <= 1; grayscale++) {
float r, g, b;
r = (gradient[left][0] * lweight) + (gradient[right][0] * rweight);
g = (gradient[left][1] * lweight) + (gradient[right][1] * rweight);
b = (gradient[left][2] * lweight) + (gradient[right][2] * rweight);
int i;
for (i=0; i<gradientSteps; i++) {
float value = float(i)/gradientSteps;
if (grayscale) {
r = g = b = 0.84 - 0.84 * value;
} else {
const int gsteps = 4;
float gradient[gsteps + 1][3] = {
{float(0.75), float(0.75), float(0.75)}, // lt gray
{float(0.30), float(0.60), float(1.00)}, // lt blue
{float(0.90), float(0.10), float(0.90)}, // violet
{float(1.00), float(0.00), float(0.00)}, // red
{float(1.00), float(1.00), float(1.00)} // white
};
int left = int (value * gsteps);
int right = (left == gsteps ? gsteps : left + 1);
float rweight = (value * gsteps) - left;
float lweight = 1.0 - rweight;
r = (gradient[left][0] * lweight) + (gradient[right][0] * rweight);
g = (gradient[left][1] * lweight) + (gradient[right][1] * rweight);
b = (gradient[left][2] * lweight) + (gradient[right][2] * rweight);
}
if (selected) {
r *= 0.77f;
g *= 0.77f;
b *= 0.885f;
}
gradient_pre[selected][grayscale][i][0] = (unsigned char) (255 * r);
gradient_pre[selected][grayscale][i][1] = (unsigned char) (255 * g);
gradient_pre[selected][grayscale][i][2] = (unsigned char) (255 * b);
}
}
}
}
if (selected) {
r *= 0.77f;
g *= 0.77f;
b *= 0.885f;
}
*red = (unsigned char) (255 * r);
*green = (unsigned char) (255 * g);
*blue = (unsigned char) (255 * b);
}
// Indentation settings for Vim and Emacs and unique identifier for Arch, a

View File

@ -54,6 +54,8 @@ class AColor {
static void TrackFocusPen(wxDC * dc, int level /* 0 - 2 */);
static void SnapGuidePen(wxDC * dc);
static void PreComputeGradient();
// Member variables
static wxBrush lightBrush[2];
@ -93,6 +95,10 @@ class AColor {
static wxBrush tooltipBrush;
static bool gradient_inited;
static const int gradientSteps = 512;
static unsigned char gradient_pre[2][2][gradientSteps][3];
private:
static wxPen sparePen;
static wxBrush spareBrush;
@ -100,11 +106,20 @@ class AColor {
};
void GetColorGradient(float value,
bool selected,
bool grayscale,
unsigned char *red,
unsigned char *green, unsigned char *blue);
inline void GetColorGradient(float value,
bool selected,
bool grayscale,
unsigned char *red,
unsigned char *green, unsigned char *blue) {
if (!AColor::gradient_inited)
AColor::PreComputeGradient();
int idx = value * (AColor::gradientSteps - 1);
*red = AColor::gradient_pre[selected][grayscale][idx][0];
*green = AColor::gradient_pre[selected][grayscale][idx][1];
*blue = AColor::gradient_pre[selected][grayscale][idx][2];
}
#endif

View File

@ -27,7 +27,7 @@ static inline float todB_a(const float *x){
#else
static inline float todB_a(const float *x){
return (*(x)==0?-400.f:log(*(x)**(x))*4.34294480f);
return (*(x)==0?-400.f:logf(*(x)**(x))*4.34294480f);
}
#endif
@ -78,7 +78,7 @@ bool ComputeSpectrum(float * data, int width,
// of the power, instead of the square root
for (i = 0; i < windowSize; i++)
in[i] = pow(in[i], 1.0f / 3.0f);
in[i] = powf(in[i], 1.0f / 3.0f);
// Take FFT
#ifdef EXPERIMENTAL_USE_REALFFTF

View File

@ -1656,13 +1656,13 @@ void TrackArtist::DrawClipSpectrum(WaveTrack *track,
const float
// e=exp(1.0f),
f=rate/2.0f/half,
lmin=log(float(minFreq)),
lmax=log(float(maxFreq)),
lmin=logf(float(minFreq)),
lmax=logf(float(maxFreq)),
#ifdef EXPERIMENTAL_FIND_NOTES
log2=log(2.0f),
log2=logf(2.0f),
#ifdef EXPERIMENTAL_FFT_SKIP_POINTS
lmins=log(float(minFreq)/(mFftSkipPoints+1)),
lmaxs=log(float(maxFreq)/(mFftSkipPoints+1)),
lmins=logf(float(minFreq)/(mFftSkipPoints+1)),
lmaxs=logf(float(maxFreq)/(mFftSkipPoints+1)),
#else //!EXPERIMENTAL_FFT_SKIP_POINTS
lmins=lmin,
lmaxs=lmax,
@ -1681,10 +1681,10 @@ void TrackArtist::DrawClipSpectrum(WaveTrack *track,
for (int y = 0; y < mid.height; y++) {
float n =(float(y )/mid.height*scale2-lmin2)*12;
float n2=(float(y+1)/mid.height*scale2-lmin2)*12;
float f =float(minFreq)/(mFftSkipPoints+1)*pow(2.0f, n /12.0f+lmin2);
float f2=float(minFreq)/(mFftSkipPoints+1)*pow(2.0f, n2/12.0f+lmin2);
n =log(f /440)/log2*12;
n2=log(f2/440)/log2*12;
float f =float(minFreq)/(mFftSkipPoints+1)*powf(2.0f, n /12.0f+lmin2);
float f2=float(minFreq)/(mFftSkipPoints+1)*powf(2.0f, n2/12.0f+lmin2);
n =logf(f /440)/log2*12;
n2=logf(f2/440)/log2*12;
if (floor(n) < floor(n2))
yGrid[y]=true;
else
@ -1702,9 +1702,9 @@ void TrackArtist::DrawClipSpectrum(WaveTrack *track,
f2bin = half/(rate/2.0f),
#endif //EXPERIMENTAL_FFT_SKIP_POINTS
bin2f = 1.0f/f2bin,
minDistance = pow(2.0f, 2.0f/12.0f),
i0=exp(lmin)/f,
i1=exp(scale+lmin)/f,
minDistance = powf(2.0f, 2.0f/12.0f),
i0=expf(lmin)/f,
i1=expf(scale+lmin)/f,
minColor=0.0f;
const int maxTableSize=1024;
int *indexes=new int[maxTableSize];
@ -1819,19 +1819,19 @@ void TrackArtist::DrawClipSpectrum(WaveTrack *track,
}
// The f2pix helper macro converts a frequency into a pixel coordinate.
#define f2pix(f) (log(f)-lmins)/(lmaxs-lmins)*mid.height
#define f2pix(f) (logf(f)-lmins)/(lmaxs-lmins)*mid.height
// Possibly quantize the maxima frequencies and create the pixel block limits.
for (int i=0; i < maximas; i++) {
int index=maxima[i];
float f = float(index)*bin2f;
if (mFindNotesQuantize)
{ f = exp(int(log(f/440)/log2*12-0.5)/12.0f*log2)*440;
{ f = expf(int(log(f/440)/log2*12-0.5)/12.0f*log2)*440;
maxima[i] = f*f2bin;
}
float f0 = exp((log(f/440)/log2*24-1)/24.0f*log2)*440;
float f0 = expf((log(f/440)/log2*24-1)/24.0f*log2)*440;
maxima0[i] = f2pix(f0);
float f1 = exp((log(f/440)/log2*24+1)/24.0f*log2)*440;
float f1 = expf((log(f/440)/log2*24+1)/24.0f*log2)*440;
maxima1[i] = f2pix(f1);
}
}
@ -1840,17 +1840,18 @@ void TrackArtist::DrawClipSpectrum(WaveTrack *track,
bool inMaximum = false;
#endif //EXPERIMENTAL_FIND_NOTES
double yy2_base=exp(lmin)/f;
float yy2 = yy2_base;
double exp_scale_per_height = exp(scale/mid.height);
for (int yy = 0; yy < mid.height; yy++) {
if(!usePxCache) {
float h=float(yy)/mid.height;
float yy2=exp(h*scale+lmin)/f;
if (int(yy2)>=half)
yy2=half-1;
if (yy2<0)
yy2=0;
float bin0 = float(yy2);
float h1=float(yy+1)/mid.height;
float yy3=exp(h1*scale+lmin)/f;
yy2_base *= exp_scale_per_height;
float yy3 = yy2_base;
if (int(yy3)>=half)
yy3=half-1;
if (yy3<0)
@ -1896,6 +1897,7 @@ void TrackArtist::DrawClipSpectrum(WaveTrack *track,
if (value < 0.0)
value = float(0.0);
clip->mSpecPxCache->values[x * mid.height + yy] = value;
yy2 = yy2_base;
}
else
value = clip->mSpecPxCache->values[x * mid.height + yy];

View File

@ -285,7 +285,7 @@ void ComputeSpectrumUsingRealFFTf(float *buffer, HFFT hFFT, float *window, int l
if(power <= 0)
out[i] = -160.0;
else
out[i] = 10.0*log10(power);
out[i] = 10.0*log10f(power);
}
}
#endif // EXPERIMENTAL_USE_REALFFTF

View File

@ -253,7 +253,8 @@ int PCMImportFileHandle::Import(TrackFactory *trackFactory,
// lets use OD only if the file is longer than 30 seconds. Otherwise, why wake up extra threads.
//todo: make this a user pref.
bool useOD =fileTotalFrames>kMinimumODFileSampleSize;
int updateCounter = 0;
for (sampleCount i = 0; i < fileTotalFrames; i += maxBlockSize) {
sampleCount blockLen = maxBlockSize;
@ -263,10 +264,14 @@ int PCMImportFileHandle::Import(TrackFactory *trackFactory,
for (c = 0; c < mInfo.channels; c++)
channels[c]->AppendAlias(mFilename, i, blockLen, c,useOD);
updateResult = mProgress->Update(i, fileTotalFrames);
if (updateResult != eProgressSuccess)
break;
if (++updateCounter == 50) {
updateResult = mProgress->Update(i, fileTotalFrames);
updateCounter = 0;
if (updateResult != eProgressSuccess)
break;
}
}
updateResult = mProgress->Update(fileTotalFrames, fileTotalFrames);
//now go over the wavetrack/waveclip/sequence and load all the blockfiles into a ComputeSummaryTask.
//Add this task to the ODManager and the Track itself.