1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-04 17:49:45 +02:00

Remove naked new[] in: tracks

This commit is contained in:
Paul Licameli 2016-04-14 12:17:59 -04:00
parent 2b23667211
commit 18be1bdad6
8 changed files with 62 additions and 107 deletions

View File

@ -251,8 +251,8 @@ void TimeTrack::Draw(wxDC & dc, const wxRect & r, const ZoomInfo &zoomInfo) cons
mRuler->SetFlip(GetHeight() > 75 ? true : true); // MB: so why don't we just call Invalidate()? :)
mRuler->Draw(dc, this);
double *envValues = new double[mid.width];
GetEnvelope()->GetValues(envValues, mid.width, 0, zoomInfo);
Doubles envValues{ size_t(mid.width) };
GetEnvelope()->GetValues(envValues.get(), mid.width, 0, zoomInfo);
dc.SetPen(AColor::envelopePen);
@ -267,9 +267,6 @@ void TimeTrack::Draw(wxDC & dc, const wxRect & r, const ZoomInfo &zoomInfo) cons
int thisy = r.y + (int)y;
AColor::Line(dc, mid.x + x, thisy - 1, mid.x + x, thisy+2);
}
if (envValues)
delete[]envValues;
}
void TimeTrack::testMe()

View File

@ -1159,13 +1159,13 @@ void TrackArtist::DrawMinMaxRMS(wxDC &dc, const wxRect & rect, const double env[
int lasth2 = std::numeric_limits<int>::min();
int h1;
int h2;
int *r1 = new int[rect.width];
int *r2 = new int[rect.width];
int *clipped = NULL;
ArrayOf<int> r1{ size_t(rect.width) };
ArrayOf<int> r2{ size_t(rect.width) };
ArrayOf<int> clipped;
int clipcnt = 0;
if (mShowClipping) {
clipped = new int[rect.width];
clipped.reinit( size_t(rect.width) );
}
long pixAnimOffset = (long)fabs((double)(wxDateTime::Now().GetTicks() * -10)) +
@ -1296,13 +1296,6 @@ void TrackArtist::DrawMinMaxRMS(wxDC &dc, const wxRect & rect, const double env[
AColor::Line(dc, xx, rect.y, xx, rect.y + rect.height);
}
}
if (mShowClipping) {
delete[] clipped;
}
delete [] r1;
delete [] r2;
}
void TrackArtist::DrawIndividualSamples(wxDC &dc, int leftOffset, const wxRect &rect,
@ -1330,16 +1323,16 @@ void TrackArtist::DrawIndividualSamples(wxDC &dc, int leftOffset, const wxRect &
if (slen <= 0)
return;
float *buffer = new float[slen];
clip->GetSamples((samplePtr)buffer, floatSample, s0, slen);
Floats buffer{ size_t(slen) };
clip->GetSamples((samplePtr)buffer.get(), floatSample, s0, slen);
int *xpos = new int[slen];
int *ypos = new int[slen];
int *clipped = NULL;
ArrayOf<int> xpos{ size_t(slen) };
ArrayOf<int> ypos{ size_t(slen) };
ArrayOf<int> clipped;
int clipcnt = 0;
if (mShowClipping)
clipped = new int[slen];
clipped.reinit( size_t(slen) );
dc.SetPen(muted ? muteSamplePen : samplePen);
@ -1394,14 +1387,6 @@ void TrackArtist::DrawIndividualSamples(wxDC &dc, int leftOffset, const wxRect &
AColor::Line(dc, rect.x + s, rect.y, rect.x + s, rect.y + rect.height);
}
}
if (mShowClipping) {
delete [] clipped;
}
delete[]buffer;
delete[]xpos;
delete[]ypos;
}
void TrackArtist::DrawEnvelope(wxDC &dc, const wxRect &rect, const double env[],
@ -2216,8 +2201,7 @@ void TrackArtist::DrawClipSpectrum(WaveTrackCache &waveTrackCache,
scale2 = (lmax - lmin) / log2,
lmin2 = lmin / log2;
bool *yGrid;
yGrid = new bool[mid.height];
ArrayOf<bool> yGrid{size_t(mid.height)};
for (int yy = 0; yy < mid.height; ++yy) {
float n = (float(yy) / mid.height*scale2 - lmin2) * 12;
float n2 = (float(yy + 1) / mid.height*scale2 - lmin2) * 12;
@ -2286,8 +2270,8 @@ void TrackArtist::DrawClipSpectrum(WaveTrackCache &waveTrackCache,
i0 = expf(lmin) / binUnit,
i1 = expf(scale + lmin) / binUnit,
minColor = 0.0f;
const int maxTableSize = 1024;
int *indexes = new int[maxTableSize];
const size_t maxTableSize = 1024;
ArrayOf<int> indexes{ maxTableSize };
#endif //EXPERIMENTAL_FIND_NOTES
#ifdef _OPENMP
@ -2525,10 +2509,6 @@ void TrackArtist::DrawClipSpectrum(WaveTrackCache &waveTrackCache,
memDC.SelectObject(converted);
dc.Blit(mid.x, mid.y, mid.width, mid.height, &memDC, 0, 0, wxCOPY, FALSE);
#ifdef EXPERIMENTAL_FFT_Y_GRID
delete[] yGrid;
#endif //EXPERIMENTAL_FFT_Y_GRID
}
#ifdef USE_MIDI

View File

@ -691,29 +691,31 @@ bool WaveClip::GetWaveDisplay(WaveDisplay &display, double t0,
//wxCriticalSectionLocker locker(mAppendCriticalSection);
if (right > left) {
float *b;
Floats b;
float *pb{};
// left is nonnegative and at most mAppendBufferLen:
auto sLeft = left.as_size_t();
// The difference is at most mAppendBufferLen:
size_t len = ( right - left ).as_size_t();
if (seqFormat == floatSample)
b = &((float *)mAppendBuffer.ptr())[sLeft];
pb = &((float *)mAppendBuffer.ptr())[sLeft];
else {
b = new float[len];
b.reinit(len);
pb = b.get();
CopySamples(mAppendBuffer.ptr() + sLeft * SAMPLE_SIZE(seqFormat),
seqFormat,
(samplePtr)b, floatSample, len);
(samplePtr)pb, floatSample, len);
}
float theMax, theMin, sumsq;
{
const float val = b[0];
const float val = pb[0];
theMax = theMin = val;
sumsq = val * val;
}
for(decltype(len) j = 1; j < len; j++) {
const float val = b[j];
const float val = pb[j];
theMax = std::max(theMax, val);
theMin = std::min(theMin, val);
sumsq += val * val;
@ -724,9 +726,6 @@ bool WaveClip::GetWaveDisplay(WaveDisplay &display, double t0,
rms[i] = (float)sqrt(sumsq / len);
bl[i] = 1; //for now just fake it.
if (seqFormat != floatSample)
delete[] b;
didUpdate=true;
}
}
@ -934,21 +933,21 @@ bool SpecCache::CalculateOneSpectrum
std::copy(scratch, scratch2, scratch3);
{
const float *const window = settings.window;
const float *const window = settings.window.get();
for (size_t ii = 0; ii < fftLen; ++ii)
scratch[ii] *= window[ii];
RealFFTf(scratch, hFFT);
}
{
const float *const dWindow = settings.dWindow;
const float *const dWindow = settings.dWindow.get();
for (size_t ii = 0; ii < fftLen; ++ii)
scratch2[ii] *= dWindow[ii];
RealFFTf(scratch2, hFFT);
}
{
const float *const tWindow = settings.tWindow;
const float *const tWindow = settings.tWindow.get();
for (size_t ii = 0; ii < fftLen; ++ii)
scratch3[ii] *= tWindow[ii];
RealFFTf(scratch3, hFFT);
@ -1025,7 +1024,7 @@ bool SpecCache::CalculateOneSpectrum
// This function mutates useBuffer
ComputeSpectrumUsingRealFFTf
(useBuffer, settings.hFFT, settings.window, fftLen, results);
(useBuffer, settings.hFFT, settings.window.get(), fftLen, results);
if (!gainFactors.empty()) {
// Apply a frequency-dependant gain factor
for (size_t ii = 0; ii < nBins; ++ii)
@ -1825,9 +1824,9 @@ bool WaveClip::Resample(int rate, ProgressDialog *progress)
double factor = (double)rate / (double)mRate;
::Resample resample(true, factor, factor); // constant rate resampling
size_t bufsize = 65536;
float* inBuffer = new float[bufsize];
float* outBuffer = new float[bufsize];
const size_t bufsize = 65536;
Floats inBuffer{ bufsize };
Floats outBuffer{ bufsize };
sampleCount pos = 0;
bool error = false;
int outGenerated = 0;
@ -1847,14 +1846,14 @@ bool WaveClip::Resample(int rate, ProgressDialog *progress)
bool isLast = ((pos + inLen) == numSamples);
if (!mSequence->Get((samplePtr)inBuffer, floatSample, pos, inLen))
if (!mSequence->Get((samplePtr)inBuffer.get(), floatSample, pos, inLen))
{
error = true;
break;
}
const auto results = resample.Process(factor, inBuffer, inLen, isLast,
outBuffer, bufsize);
const auto results = resample.Process(factor, inBuffer.get(), inLen, isLast,
outBuffer.get(), bufsize);
outGenerated = results.second;
pos += results.first;
@ -1865,7 +1864,7 @@ bool WaveClip::Resample(int rate, ProgressDialog *progress)
break;
}
if (!newSequence->Append((samplePtr)outBuffer, floatSample,
if (!newSequence->Append((samplePtr)outBuffer.get(), floatSample,
outGenerated))
{
error = true;
@ -1886,9 +1885,6 @@ bool WaveClip::Resample(int rate, ProgressDialog *progress)
}
}
delete[] inBuffer;
delete[] outBuffer;
if (!error)
{
mSequence = std::move(newSequence);

View File

@ -118,22 +118,17 @@ public:
class SpecPxCache {
public:
SpecPxCache(size_t cacheLen)
: len{ cacheLen }
, values{ len }
{
len = cacheLen;
values = new float[len];
valid = false;
scaleType = 0;
range = gain = -1;
minFreq = maxFreq = -1;
}
~SpecPxCache()
{
delete[] values;
}
size_t len;
float *values;
Floats values;
bool valid;
int scaleType;

View File

@ -1425,8 +1425,8 @@ bool WaveTrack::InsertSilence(double t, double len)
bool WaveTrack::Disjoin(double t0, double t1)
{
auto minSamples = TimeToLongSamples( WAVETRACK_MERGE_POINT_TOLERANCE );
size_t maxAtOnce = 1048576;
float *buffer = new float[ maxAtOnce ];
const size_t maxAtOnce = 1048576;
Floats buffer{ maxAtOnce };
Regions regions;
wxBusyCursor busy;
@ -1457,7 +1457,7 @@ bool WaveTrack::Disjoin(double t0, double t1)
{
auto numSamples = limitSampleBufferSize( maxAtOnce, len - done );
clip->GetSamples( ( samplePtr )buffer, floatSample, start + done,
clip->GetSamples( ( samplePtr )buffer.get(), floatSample, start + done,
numSamples );
for( decltype(numSamples) i = 0; i < numSamples; i++ )
{
@ -1498,7 +1498,6 @@ bool WaveTrack::Disjoin(double t0, double t1)
SplitDelete(region.start, region.end );
}
delete[] buffer;
return true;
}
@ -2609,7 +2608,6 @@ void WaveTrack::SetAutoSaveIdent(int ident)
WaveTrackCache::~WaveTrackCache()
{
Free();
}
void WaveTrackCache::SetTrack(const WaveTrack *pTrack)
@ -2620,8 +2618,8 @@ void WaveTrackCache::SetTrack(const WaveTrack *pTrack)
if (!mPTrack ||
mPTrack->GetMaxBlockSize() != mBufferSize) {
Free();
mBuffers[0].data = new float[mBufferSize];
mBuffers[1].data = new float[mBufferSize];
mBuffers[0].data = Floats{ mBufferSize };
mBuffers[1].data = Floats{ mBufferSize };
}
}
else
@ -2682,7 +2680,7 @@ constSamplePtr WaveTrackCache::Get(sampleFormat format,
if (start0 >= 0) {
const auto len0 = mPTrack->GetBestBlockSize(start0);
wxASSERT(len0 <= mBufferSize);
if (!mPTrack->Get(samplePtr(mBuffers[0].data), floatSample, start0, len0))
if (!mPTrack->Get(samplePtr(mBuffers[0].data.get()), floatSample, start0, len0))
return 0;
mBuffers[0].start = start0;
mBuffers[0].len = len0;
@ -2708,7 +2706,7 @@ constSamplePtr WaveTrackCache::Get(sampleFormat format,
if (start1 == end0) {
const auto len1 = mPTrack->GetBestBlockSize(start1);
wxASSERT(len1 <= mBufferSize);
if (!mPTrack->Get(samplePtr(mBuffers[1].data), floatSample, start1, len1))
if (!mPTrack->Get(samplePtr(mBuffers[1].data.get()), floatSample, start1, len1))
return 0;
mBuffers[1].start = start1;
mBuffers[1].len = len1;
@ -2755,7 +2753,7 @@ constSamplePtr WaveTrackCache::Get(sampleFormat format,
// All is contiguous already. We can completely avoid copying
// leni is nonnegative, therefore start falls within mBuffers[ii],
// so starti is bounded between 0 and buffer length
return samplePtr(mBuffers[ii].data + starti.as_size_t() );
return samplePtr(mBuffers[ii].data.get() + starti.as_size_t() );
}
else if (leni > 0) {
// leni is nonnegative, therefore start falls within mBuffers[ii]
@ -2767,7 +2765,7 @@ constSamplePtr WaveTrackCache::Get(sampleFormat format,
// leni is positive and not more than remaining
const size_t size = sizeof(float) * leni.as_size_t();
// starti is less than mBuffers[ii].len and nonnegative
memcpy(buffer, mBuffers[ii].data + starti.as_size_t(), size);
memcpy(buffer, mBuffers[ii].data.get() + starti.as_size_t(), size);
wxASSERT( leni <= remaining );
remaining -= leni.as_size_t();
start += leni;

View File

@ -653,17 +653,17 @@ private:
void Free();
struct Buffer {
float *data;
Floats data;
sampleCount start;
sampleCount len;
Buffer() : data(0), start(0), len(0) {}
void Free() { delete[] data; data = 0; start = 0; len = 0; }
Buffer() : start(0), len(0) {}
void Free() { data.reset(); start = 0; len = 0; }
sampleCount end() const { return start + len; }
void swap ( Buffer &other )
{
std::swap( data, other.data );
data .swap ( other.data );
std::swap( start, other.start );
std::swap( len, other.len );
}

View File

@ -352,18 +352,9 @@ void SpectrogramSettings::DestroyWindows()
EndFFT(hFFT);
hFFT = NULL;
}
if (window != NULL) {
delete[] window;
window = NULL;
}
if (dWindow != NULL) {
delete[] dWindow;
dWindow = NULL;
}
if (tWindow != NULL) {
delete[] tWindow;
tWindow = NULL;
}
window.reset();
dWindow.reset();
tWindow.reset();
}
@ -371,13 +362,11 @@ namespace
{
enum { WINDOW, TWINDOW, DWINDOW };
void RecreateWindow(
float *&window, int which, size_t fftLen,
Floats &window, int which, size_t fftLen,
size_t padding, int windowType, size_t windowSize, double &scale)
{
if (window != NULL)
delete[] window;
// Create the requested window function
window = new float[fftLen];
window = Floats{ fftLen };
int ii;
const bool extra = padding > 0;
@ -397,16 +386,15 @@ namespace
// Overwrite middle as needed
switch (which) {
case WINDOW:
NewWindowFunc(windowType, windowSize, extra, window + padding);
NewWindowFunc(windowType, windowSize, extra, window.get() + padding);
break;
// Future, reassignment
case TWINDOW:
NewWindowFunc(windowType, windowSize, extra, window + padding);
NewWindowFunc(windowType, windowSize, extra, window.get() + padding);
for (int ii = padding, multiplier = -(int)windowSize / 2; ii < endOfWindow; ++ii, ++multiplier)
window[ii] *= multiplier;
break;
case DWINDOW:
DerivativeOfWindowFunc(windowType, windowSize, extra, window + padding);
DerivativeOfWindowFunc(windowType, windowSize, extra, window.get() + padding);
break;
default:
wxASSERT(false);

View File

@ -12,6 +12,7 @@ Paul Licameli
#define __AUDACITY_SPECTROGRAM_SETTINGS__
#include "../Experimental.h"
#include "../SampleFormat.h"
#undef SPECTRAL_SELECTION_GLOBAL_SWITCH
@ -153,10 +154,10 @@ public:
// Variables used for computing the spectrum
mutable FFTParam *hFFT{};
mutable float *window{};
mutable Floats window;
// Two other windows for computing reassigned spectrogram
mutable float *tWindow{}; // Window times time parameter
mutable float *dWindow{}; // Derivative of window
mutable Floats tWindow; // Window times time parameter
mutable Floats dWindow; // Derivative of window
};
#endif