mirror of
https://github.com/cookiengineer/audacity
synced 2025-05-02 08:39:46 +02:00
Remove naked new[] in: various
This commit is contained in:
parent
ce2e154e89
commit
692a033968
@ -641,9 +641,8 @@ void AutoSaveFile::CheckSpace(wxMemoryOutputStream & os)
|
||||
if (left == 0)
|
||||
{
|
||||
size_t origPos = buf->GetIntPosition();
|
||||
char *temp = new char[mAllocSize];
|
||||
buf->Write(temp, mAllocSize);
|
||||
delete[] temp;
|
||||
ArrayOf<char> temp{ mAllocSize };
|
||||
buf->Write(temp.get(), mAllocSize);
|
||||
buf->SetIntPosition(origPos);
|
||||
}
|
||||
}
|
||||
@ -739,25 +738,27 @@ bool AutoSaveFile::Decode(const wxString & fileName)
|
||||
return true;
|
||||
}
|
||||
|
||||
XMLFileWriter out;
|
||||
wxString tempName;
|
||||
len = file.Length() - len;
|
||||
char *buf = new char[len];
|
||||
|
||||
if (file.Read(buf, len) != len)
|
||||
{
|
||||
delete[] buf;
|
||||
using Chars = ArrayOf < char >;
|
||||
using WxChars = ArrayOf < wxChar >;
|
||||
Chars buf{ len };
|
||||
|
||||
if (file.Read(buf.get(), len) != len)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
wxMemoryInputStream in(buf, len);
|
||||
wxMemoryInputStream in(buf.get(), len);
|
||||
|
||||
file.Close();
|
||||
|
||||
// Decode to a temporary file to preserve the orignal.
|
||||
wxString tempName = fn.CreateTempFileName(fnPath);
|
||||
// Decode to a temporary file to preserve the original.
|
||||
tempName = fn.CreateTempFileName(fnPath);
|
||||
bool opened = false;
|
||||
|
||||
XMLFileWriter out;
|
||||
|
||||
// JKC: ANSWER-ME: Is the try catch actually doing anything?
|
||||
// If it is useful, why are we not using it everywhere?
|
||||
// If it isn't useful, why are we doing it here?
|
||||
@ -772,8 +773,6 @@ bool AutoSaveFile::Decode(const wxString & fileName)
|
||||
|
||||
if (!opened)
|
||||
{
|
||||
delete[] buf;
|
||||
|
||||
wxRemoveFile(tempName);
|
||||
|
||||
return false;
|
||||
@ -807,11 +806,10 @@ bool AutoSaveFile::Decode(const wxString & fileName)
|
||||
|
||||
in.Read(&id, sizeof(id));
|
||||
in.Read(&len, sizeof(len));
|
||||
wxChar *name = new wxChar[len / sizeof(wxChar)];
|
||||
in.Read(name, len);
|
||||
WxChars name{ len / sizeof(wxChar) };
|
||||
in.Read(name.get(), len);
|
||||
|
||||
mIds[id] = wxString(name, len / sizeof(wxChar));
|
||||
delete[] name;
|
||||
mIds[id] = wxString(name.get(), len / sizeof(wxChar));
|
||||
}
|
||||
break;
|
||||
|
||||
@ -837,11 +835,10 @@ bool AutoSaveFile::Decode(const wxString & fileName)
|
||||
|
||||
in.Read(&id, sizeof(id));
|
||||
in.Read(&len, sizeof(len));
|
||||
wxChar *val = new wxChar[len / sizeof(wxChar)];
|
||||
in.Read(val, len);
|
||||
WxChars val{ len / sizeof(wxChar) };
|
||||
in.Read(val.get(), len);
|
||||
|
||||
out.WriteAttr(mIds[id], wxString(val, len / sizeof(wxChar)));
|
||||
delete[] val;
|
||||
out.WriteAttr(mIds[id], wxString(val.get(), len / sizeof(wxChar)));
|
||||
}
|
||||
break;
|
||||
|
||||
@ -931,11 +928,10 @@ bool AutoSaveFile::Decode(const wxString & fileName)
|
||||
int len;
|
||||
|
||||
in.Read(&len, sizeof(len));
|
||||
wxChar *val = new wxChar[len / sizeof(wxChar)];
|
||||
in.Read(val, len);
|
||||
WxChars val{ len / sizeof(wxChar) };
|
||||
in.Read(val.get(), len);
|
||||
|
||||
out.WriteData(wxString(val, len / sizeof(wxChar)));
|
||||
delete[] val;
|
||||
out.WriteData(wxString(val.get(), len / sizeof(wxChar)));
|
||||
}
|
||||
break;
|
||||
|
||||
@ -944,11 +940,10 @@ bool AutoSaveFile::Decode(const wxString & fileName)
|
||||
int len;
|
||||
|
||||
in.Read(&len, sizeof(len));
|
||||
wxChar *val = new wxChar[len / sizeof(wxChar)];
|
||||
in.Read(val, len);
|
||||
WxChars val{ len / sizeof(wxChar) };
|
||||
in.Read(val.get(), len);
|
||||
|
||||
out.Write(wxString(val, len / sizeof(wxChar)));
|
||||
delete[] val;
|
||||
out.Write(wxString(val.get(), len / sizeof(wxChar)));
|
||||
}
|
||||
break;
|
||||
|
||||
@ -957,8 +952,7 @@ bool AutoSaveFile::Decode(const wxString & fileName)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
delete[] buf;
|
||||
}
|
||||
|
||||
bool error = out.Error();
|
||||
|
||||
|
66
src/FFT.cpp
66
src/FFT.cpp
@ -39,7 +39,10 @@
|
||||
* 9: Gaussian(a=4.5)
|
||||
*/
|
||||
|
||||
#include "Audacity.h"
|
||||
#include "FFT.h"
|
||||
#include "MemoryX.h"
|
||||
#include "SampleFormat.h"
|
||||
|
||||
#include <wx/intl.h>
|
||||
#include <stdlib.h>
|
||||
@ -49,7 +52,7 @@
|
||||
#include "RealFFTf.h"
|
||||
#include "Experimental.h"
|
||||
|
||||
static int **gFFTBitTable = NULL;
|
||||
static ArraysOf<int> gFFTBitTable;
|
||||
static const size_t MaxFastBits = 16;
|
||||
|
||||
/* Declare Static functions */
|
||||
@ -94,15 +97,14 @@ int ReverseBits(size_t index, size_t NumBits)
|
||||
|
||||
void InitFFT()
|
||||
{
|
||||
gFFTBitTable = new int *[MaxFastBits];
|
||||
gFFTBitTable.reinit(MaxFastBits);
|
||||
|
||||
size_t len = 2;
|
||||
for (size_t b = 1; b <= MaxFastBits; b++) {
|
||||
|
||||
gFFTBitTable[b - 1] = new int[len];
|
||||
|
||||
auto &array = gFFTBitTable[b - 1];
|
||||
array.reinit(len);
|
||||
for (size_t i = 0; i < len; i++)
|
||||
gFFTBitTable[b - 1][i] = ReverseBits(i, b);
|
||||
array[i] = ReverseBits(i, b);
|
||||
|
||||
len <<= 1;
|
||||
}
|
||||
@ -110,12 +112,7 @@ void InitFFT()
|
||||
|
||||
void DeinitFFT()
|
||||
{
|
||||
if (gFFTBitTable) {
|
||||
for (size_t b = 1; b <= MaxFastBits; b++) {
|
||||
delete[] gFFTBitTable[b-1];
|
||||
}
|
||||
delete[] gFFTBitTable;
|
||||
}
|
||||
gFFTBitTable.reset();
|
||||
// Deallocate any unused RealFFTf tables
|
||||
CleanupFFT();
|
||||
}
|
||||
@ -233,31 +230,30 @@ void FFT(size_t NumSamples,
|
||||
|
||||
void RealFFT(size_t NumSamples, const float *RealIn, float *RealOut, float *ImagOut)
|
||||
{
|
||||
size_t i;
|
||||
HFFT hFFT = GetFFT(NumSamples);
|
||||
float *pFFT = new float[NumSamples];
|
||||
Floats pFFT{ NumSamples };
|
||||
// Copy the data into the processing buffer
|
||||
for(i = 0; i < NumSamples; i++)
|
||||
for(size_t i = 0; i < NumSamples; i++)
|
||||
pFFT[i] = RealIn[i];
|
||||
|
||||
// Perform the FFT
|
||||
RealFFTf(pFFT, hFFT);
|
||||
RealFFTf(pFFT.get(), hFFT);
|
||||
|
||||
// Copy the data into the real and imaginary outputs
|
||||
for(i = 1; i < (NumSamples / 2); i++) {
|
||||
for (size_t i = 1; i<(NumSamples / 2); i++) {
|
||||
RealOut[i]=pFFT[hFFT->BitReversed[i] ];
|
||||
ImagOut[i]=pFFT[hFFT->BitReversed[i]+1];
|
||||
}
|
||||
// Handle the (real-only) DC and Fs/2 bins
|
||||
RealOut[0] = pFFT[0];
|
||||
RealOut[i] = pFFT[1];
|
||||
ImagOut[0] = ImagOut[i] = 0;
|
||||
RealOut[NumSamples / 2] = pFFT[1];
|
||||
ImagOut[0] = ImagOut[NumSamples / 2] = 0;
|
||||
// Fill in the upper half using symmetry properties
|
||||
for(i++ ; i < NumSamples; i++) {
|
||||
for(size_t i = NumSamples / 2 + 1; i < NumSamples; i++) {
|
||||
RealOut[i] = RealOut[NumSamples-i];
|
||||
ImagOut[i] = -ImagOut[NumSamples-i];
|
||||
}
|
||||
delete [] pFFT;
|
||||
|
||||
ReleaseFFT(hFFT);
|
||||
}
|
||||
|
||||
@ -275,29 +271,27 @@ void RealFFT(size_t NumSamples, const float *RealIn, float *RealOut, float *Imag
|
||||
void InverseRealFFT(size_t NumSamples, const float *RealIn, const float *ImagIn,
|
||||
float *RealOut)
|
||||
{
|
||||
size_t i;
|
||||
HFFT hFFT = GetFFT(NumSamples);
|
||||
float *pFFT = new float[NumSamples];
|
||||
Floats pFFT{ NumSamples };
|
||||
// Copy the data into the processing buffer
|
||||
for(i = 0; i < (NumSamples / 2); i++)
|
||||
for (size_t i = 0; i < (NumSamples / 2); i++)
|
||||
pFFT[2*i ] = RealIn[i];
|
||||
if(ImagIn == NULL) {
|
||||
for(i = 0; i < (NumSamples/2); i++)
|
||||
for (size_t i = 0; i < (NumSamples / 2); i++)
|
||||
pFFT[2*i+1] = 0;
|
||||
} else {
|
||||
for(i = 0; i < (NumSamples/2); i++)
|
||||
for (size_t i = 0; i < (NumSamples / 2); i++)
|
||||
pFFT[2*i+1] = ImagIn[i];
|
||||
}
|
||||
// Put the fs/2 component in the imaginary part of the DC bin
|
||||
pFFT[1] = RealIn[i];
|
||||
pFFT[1] = RealIn[NumSamples / 2];
|
||||
|
||||
// Perform the FFT
|
||||
InverseRealFFTf(pFFT, hFFT);
|
||||
InverseRealFFTf(pFFT.get(), hFFT);
|
||||
|
||||
// Copy the data to the (purely real) output buffer
|
||||
ReorderToTime(hFFT, pFFT, RealOut);
|
||||
ReorderToTime(hFFT, pFFT.get(), RealOut);
|
||||
|
||||
delete [] pFFT;
|
||||
ReleaseFFT(hFFT);
|
||||
}
|
||||
|
||||
@ -314,25 +308,23 @@ void InverseRealFFT(size_t NumSamples, const float *RealIn, const float *ImagIn,
|
||||
|
||||
void PowerSpectrum(size_t NumSamples, const float *In, float *Out)
|
||||
{
|
||||
size_t i;
|
||||
HFFT hFFT = GetFFT(NumSamples);
|
||||
float *pFFT = new float[NumSamples];
|
||||
Floats pFFT{ NumSamples };
|
||||
// Copy the data into the processing buffer
|
||||
for(i = 0; i < NumSamples; i++)
|
||||
for (size_t i = 0; i<NumSamples; i++)
|
||||
pFFT[i] = In[i];
|
||||
|
||||
// Perform the FFT
|
||||
RealFFTf(pFFT, hFFT);
|
||||
RealFFTf(pFFT.get(), hFFT);
|
||||
|
||||
// Copy the data into the real and imaginary outputs
|
||||
for(i = 1; i < NumSamples / 2; i++) {
|
||||
for (size_t i = 1; i<NumSamples / 2; i++) {
|
||||
Out[i]= (pFFT[hFFT->BitReversed[i] ]*pFFT[hFFT->BitReversed[i] ])
|
||||
+ (pFFT[hFFT->BitReversed[i]+1]*pFFT[hFFT->BitReversed[i]+1]);
|
||||
}
|
||||
// Handle the (real-only) DC and Fs/2 bins
|
||||
Out[0] = pFFT[0]*pFFT[0];
|
||||
Out[i] = pFFT[1]*pFFT[1];
|
||||
delete [] pFFT;
|
||||
Out[NumSamples / 2] = pFFT[1]*pFFT[1];
|
||||
ReleaseFFT(hFFT);
|
||||
}
|
||||
|
||||
|
@ -189,7 +189,6 @@ FreqWindow::FreqWindow(wxWindow * parent, wxWindowID id,
|
||||
const wxPoint & pos)
|
||||
: wxDialogWrapper(parent, id, title, pos, wxDefaultSize,
|
||||
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxMAXIMIZE_BOX),
|
||||
mData(NULL),
|
||||
mAnalyst(std::make_unique<SpectrumAnalyst>())
|
||||
{
|
||||
SetName(GetTitle());
|
||||
@ -514,8 +513,6 @@ FreqWindow::FreqWindow(wxWindow * parent, wxWindowID id,
|
||||
|
||||
FreqWindow::~FreqWindow()
|
||||
{
|
||||
if (mData)
|
||||
delete[] mData;
|
||||
}
|
||||
|
||||
bool FreqWindow::Show(bool show)
|
||||
@ -546,10 +543,7 @@ bool FreqWindow::Show(bool show)
|
||||
|
||||
void FreqWindow::GetAudio()
|
||||
{
|
||||
if (mData) {
|
||||
delete [] mData;
|
||||
mData = NULL;
|
||||
}
|
||||
mData.reset();
|
||||
mDataLen = 0;
|
||||
|
||||
int selcount = 0;
|
||||
@ -571,23 +565,21 @@ void FreqWindow::GetAudio()
|
||||
else
|
||||
// dataLen is not more than 10 * 2 ^ 20
|
||||
mDataLen = dataLen.as_size_t();
|
||||
mData = new float[mDataLen];
|
||||
track->Get((samplePtr)mData, floatSample, start, mDataLen);
|
||||
mData = Floats{ mDataLen };
|
||||
track->Get((samplePtr)mData.get(), floatSample, start, mDataLen);
|
||||
}
|
||||
else {
|
||||
if (track->GetRate() != mRate) {
|
||||
wxMessageBox(_("To plot the spectrum, all selected tracks must be the same sample rate."));
|
||||
delete[] mData;
|
||||
mData = NULL;
|
||||
mData.reset();
|
||||
mDataLen = 0;
|
||||
return;
|
||||
}
|
||||
auto start = track->TimeToLongSamples(p->mViewInfo.selectedRegion.t0());
|
||||
float *buffer2 = new float[mDataLen];
|
||||
track->Get((samplePtr)buffer2, floatSample, start, mDataLen);
|
||||
Floats buffer2{ mDataLen };
|
||||
track->Get((samplePtr)buffer2.get(), floatSample, start, mDataLen);
|
||||
for (size_t i = 0; i < mDataLen; i++)
|
||||
mData[i] += buffer2[i];
|
||||
delete[] buffer2;
|
||||
}
|
||||
selcount++;
|
||||
}
|
||||
@ -1000,7 +992,7 @@ void FreqWindow::Recalc()
|
||||
wxYieldIfNeeded();
|
||||
|
||||
mAnalyst->Calculate(alg, windowFunc, mWindowSize, mRate,
|
||||
mData, mDataLen,
|
||||
mData.get(), mDataLen,
|
||||
&mYMin, &mYMax, mProgress);
|
||||
}
|
||||
if (hadFocus) {
|
||||
@ -1202,17 +1194,17 @@ bool SpectrumAnalyst::Calculate(Algorithm alg, int windowFunc,
|
||||
auto half = mWindowSize / 2;
|
||||
mProcessed.resize(mWindowSize);
|
||||
|
||||
float *in = new float[mWindowSize];
|
||||
float *out = new float[mWindowSize];
|
||||
float *out2 = new float[mWindowSize];
|
||||
float *win = new float[mWindowSize];
|
||||
Floats in{ mWindowSize };
|
||||
Floats out{ mWindowSize };
|
||||
Floats out2{ mWindowSize };
|
||||
Floats win{ mWindowSize };
|
||||
|
||||
for (size_t i = 0; i < mWindowSize; i++) {
|
||||
mProcessed[i] = 0.0f;
|
||||
win[i] = 1.0f;
|
||||
}
|
||||
|
||||
WindowFunc(windowFunc, mWindowSize, win);
|
||||
WindowFunc(windowFunc, mWindowSize, win.get());
|
||||
|
||||
// Scale window such that an amplitude of 1.0 in the time domain
|
||||
// shows an amplitude of 0dB in the frequency domain
|
||||
@ -1236,7 +1228,7 @@ bool SpectrumAnalyst::Calculate(Algorithm alg, int windowFunc,
|
||||
|
||||
switch (alg) {
|
||||
case Spectrum:
|
||||
PowerSpectrum(mWindowSize, in, out);
|
||||
PowerSpectrum(mWindowSize, in.get(), out.get());
|
||||
|
||||
for (size_t i = 0; i < half; i++)
|
||||
mProcessed[i] += out[i];
|
||||
@ -1247,7 +1239,7 @@ bool SpectrumAnalyst::Calculate(Algorithm alg, int windowFunc,
|
||||
case EnhancedAutocorrelation:
|
||||
|
||||
// Take FFT
|
||||
RealFFT(mWindowSize, in, out, out2);
|
||||
RealFFT(mWindowSize, in.get(), out.get(), out2.get());
|
||||
// Compute power
|
||||
for (size_t i = 0; i < mWindowSize; i++)
|
||||
in[i] = (out[i] * out[i]) + (out2[i] * out2[i]);
|
||||
@ -1265,7 +1257,7 @@ bool SpectrumAnalyst::Calculate(Algorithm alg, int windowFunc,
|
||||
in[i] = pow(in[i], 1.0f / 3.0f);
|
||||
}
|
||||
// Take FFT
|
||||
RealFFT(mWindowSize, in, out, out2);
|
||||
RealFFT(mWindowSize, in.get(), out.get(), out2.get());
|
||||
|
||||
// Take real part of result
|
||||
for (size_t i = 0; i < half; i++)
|
||||
@ -1273,7 +1265,8 @@ bool SpectrumAnalyst::Calculate(Algorithm alg, int windowFunc,
|
||||
break;
|
||||
|
||||
case Cepstrum:
|
||||
RealFFT(mWindowSize, in, out, out2);
|
||||
RealFFT(mWindowSize, in.get(), out.get(), out2.get());
|
||||
|
||||
// Compute log power
|
||||
// Set a sane lower limit assuming maximum time amplitude of 1.0
|
||||
{
|
||||
@ -1288,7 +1281,7 @@ bool SpectrumAnalyst::Calculate(Algorithm alg, int windowFunc,
|
||||
in[i] = log(power);
|
||||
}
|
||||
// Take IFFT
|
||||
InverseRealFFT(mWindowSize, in, NULL, out);
|
||||
InverseRealFFT(mWindowSize, in.get(), NULL, out.get());
|
||||
|
||||
// Take real part of result
|
||||
for (size_t i = 0; i < half; i++)
|
||||
@ -1407,11 +1400,6 @@ bool SpectrumAnalyst::Calculate(Algorithm alg, int windowFunc,
|
||||
break;
|
||||
}
|
||||
|
||||
delete[]in;
|
||||
delete[]out;
|
||||
delete[]out2;
|
||||
delete[]win;
|
||||
|
||||
if (pYMin)
|
||||
*pYMin = mYMin;
|
||||
if (pYMax)
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include <wx/textctrl.h>
|
||||
#include <wx/utils.h>
|
||||
#include "widgets/Ruler.h"
|
||||
#include "SampleFormat.h"
|
||||
|
||||
class wxStatusBar;
|
||||
class wxButton;
|
||||
@ -198,7 +199,7 @@ private:
|
||||
|
||||
double mRate;
|
||||
size_t mDataLen;
|
||||
float *mData;
|
||||
Floats mData;
|
||||
size_t mWindowSize;
|
||||
|
||||
bool mLogAxis;
|
||||
|
@ -3439,12 +3439,8 @@ void AudacityProject::OnPlaySpeedDec()
|
||||
double AudacityProject::NearestZeroCrossing(double t0)
|
||||
{
|
||||
// Window is 1/100th of a second.
|
||||
int windowSize = (int)(GetRate() / 100);
|
||||
float *dist = new float[windowSize];
|
||||
int i, j;
|
||||
|
||||
for(i=0; i<windowSize; i++)
|
||||
dist[i] = 0.0;
|
||||
auto windowSize = size_t(std::max(1.0, GetRate() / 100));
|
||||
Floats dist{ windowSize, true };
|
||||
|
||||
TrackListIterator iter(GetTracks());
|
||||
Track *track = iter.First();
|
||||
@ -3454,26 +3450,26 @@ double AudacityProject::NearestZeroCrossing(double t0)
|
||||
continue;
|
||||
}
|
||||
WaveTrack *one = (WaveTrack *)track;
|
||||
int oneWindowSize = (int)(one->GetRate() / 100);
|
||||
float *oneDist = new float[oneWindowSize];
|
||||
auto oneWindowSize = size_t(std::max(1.0, one->GetRate() / 100));
|
||||
Floats oneDist{ oneWindowSize };
|
||||
auto s = one->TimeToLongSamples(t0);
|
||||
// fillTwo to ensure that missing values are treated as 2, and hence do not
|
||||
// get used as zero crossings.
|
||||
one->Get((samplePtr)oneDist, floatSample,
|
||||
s - oneWindowSize/2, oneWindowSize, fillTwo);
|
||||
one->Get((samplePtr)oneDist.get(), floatSample,
|
||||
s - (int)oneWindowSize/2, oneWindowSize, fillTwo);
|
||||
|
||||
// Start by penalizing downward motion. We prefer upward
|
||||
// zero crossings.
|
||||
if (oneDist[1] - oneDist[0] < 0)
|
||||
oneDist[0] = oneDist[0]*6 + (oneDist[0] > 0 ? 0.3 : -0.3);
|
||||
for(i=1; i<oneWindowSize; i++)
|
||||
for(size_t i=1; i<oneWindowSize; i++)
|
||||
if (oneDist[i] - oneDist[i-1] < 0)
|
||||
oneDist[i] = oneDist[i]*6 + (oneDist[i] > 0 ? 0.3 : -0.3);
|
||||
|
||||
// Taking the absolute value -- apply a tiny LPF so square waves work.
|
||||
float newVal, oldVal = oneDist[0];
|
||||
oneDist[0] = fabs(.75 * oneDist[0] + .25 * oneDist[1]);
|
||||
for(i=1; i<oneWindowSize-1; i++)
|
||||
for(size_t i=1; i + 1 < oneWindowSize; i++)
|
||||
{
|
||||
newVal = fabs(.25 * oldVal + .5 * oneDist[i] + .25 * oneDist[i+1]);
|
||||
oldVal = oneDist[i];
|
||||
@ -3485,7 +3481,8 @@ double AudacityProject::NearestZeroCrossing(double t0)
|
||||
// TODO: The mixed rate zero crossing code is broken,
|
||||
// if oneWindowSize > windowSize we'll miss out some
|
||||
// samples - so they will still be zero, so we'll use them.
|
||||
for(i=0; i<windowSize; i++) {
|
||||
for(size_t i = 0; i < windowSize; i++) {
|
||||
size_t j;
|
||||
if (windowSize != oneWindowSize)
|
||||
j = i * (oneWindowSize-1) / (windowSize-1);
|
||||
else
|
||||
@ -3493,26 +3490,23 @@ double AudacityProject::NearestZeroCrossing(double t0)
|
||||
|
||||
dist[i] += oneDist[j];
|
||||
// Apply a small penalty for distance from the original endpoint
|
||||
dist[i] += 0.1 * (abs(i - windowSize/2)) / float(windowSize/2);
|
||||
dist[i] += 0.1 * (abs(int(i) - int(windowSize/2))) / float(windowSize/2);
|
||||
}
|
||||
|
||||
delete [] oneDist;
|
||||
track = iter.Next();
|
||||
}
|
||||
|
||||
// Find minimum
|
||||
int argmin = 0;
|
||||
float min = 3.0;
|
||||
for(i=0; i<windowSize; i++) {
|
||||
for(size_t i=0; i<windowSize; i++) {
|
||||
if (dist[i] < min) {
|
||||
argmin = i;
|
||||
min = dist[i];
|
||||
}
|
||||
}
|
||||
|
||||
delete [] dist;
|
||||
|
||||
return t0 + (argmin - windowSize/2)/GetRate();
|
||||
return t0 + (argmin - (int)windowSize/2)/GetRate();
|
||||
}
|
||||
|
||||
void AudacityProject::OnZeroCrossing()
|
||||
|
@ -568,12 +568,12 @@ void MixerTrackCluster::UpdateMeter(const double t0, const double t1)
|
||||
// stored in blockfiles, rather than calculating them, but for now, changing it to use the
|
||||
// original Meter::UpdateDisplay(). New code is below the previous (now commented out).
|
||||
//
|
||||
//const int kFramesPerBuffer = 4;
|
||||
//const size_t kFramesPerBuffer = 4;
|
||||
//float min; // dummy, since it's not shown in meters
|
||||
//float* maxLeft = new float[kFramesPerBuffer];
|
||||
//float* rmsLeft = new float[kFramesPerBuffer];
|
||||
//float* maxRight = new float[kFramesPerBuffer];
|
||||
//float* rmsRight = new float[kFramesPerBuffer];
|
||||
//Floats maxLeft{kFramesPerBuffer};
|
||||
//Floats rmsLeft{kFramesPerBuffer};
|
||||
//Floats maxRight{kFramesPerBuffer};
|
||||
//Floats rmsRight{kFramesPerBuffer};
|
||||
//
|
||||
//#ifdef EXPERIMENTAL_MIDI_OUT
|
||||
// bool bSuccess = (mLeftTrack != NULL);
|
||||
@ -628,10 +628,6 @@ void MixerTrackCluster::UpdateMeter(const double t0, const double t1)
|
||||
// mLeftTrack->TimeToLongSamples(t1 - t0));
|
||||
//}
|
||||
//
|
||||
//delete[] maxLeft;
|
||||
//delete[] rmsLeft;
|
||||
//delete[] maxRight;
|
||||
//delete[] rmsRight;
|
||||
|
||||
auto startSample = (sampleCount)((mLeftTrack->GetRate() * t0) + 0.5);
|
||||
auto scnFrames = (sampleCount)((mLeftTrack->GetRate() * (t1 - t0)) + 0.5);
|
||||
@ -640,22 +636,22 @@ void MixerTrackCluster::UpdateMeter(const double t0, const double t1)
|
||||
// in about 1/20 second (ticks of TrackPanel timer), so this won't overflow
|
||||
auto nFrames = scnFrames.as_size_t();
|
||||
|
||||
float* meterFloatsArray = NULL;
|
||||
float* tempFloatsArray = new float[nFrames];
|
||||
bool bSuccess = mLeftTrack->Get((samplePtr)tempFloatsArray, floatSample, startSample, nFrames);
|
||||
Floats tempFloatsArray{ size_t(nFrames) };
|
||||
decltype(tempFloatsArray) meterFloatsArray;
|
||||
bool bSuccess = mLeftTrack->Get((samplePtr)tempFloatsArray.get(), floatSample, startSample, nFrames);
|
||||
if (bSuccess)
|
||||
{
|
||||
// We always pass a stereo sample array to the meter, as it shows 2 channels.
|
||||
// Mono shows same in both meters.
|
||||
// Since we're not mixing, need to duplicate same signal for "right" channel in mono case.
|
||||
meterFloatsArray = new float[2 * nFrames];
|
||||
meterFloatsArray = Floats{ 2 * nFrames };
|
||||
|
||||
// Interleave for stereo. Left/mono first.
|
||||
for (int index = 0; index < nFrames; index++)
|
||||
meterFloatsArray[2 * index] = tempFloatsArray[index];
|
||||
|
||||
if (mRightTrack)
|
||||
bSuccess = mRightTrack->Get((samplePtr)tempFloatsArray, floatSample, startSample, nFrames);
|
||||
bSuccess = mRightTrack->Get((samplePtr)tempFloatsArray.get(), floatSample, startSample, nFrames);
|
||||
|
||||
if (bSuccess)
|
||||
// Interleave right channel, or duplicate same signal for "right" channel in mono case.
|
||||
@ -686,13 +682,10 @@ void MixerTrackCluster::UpdateMeter(const double t0, const double t1)
|
||||
else if (meterFloatsArray[index] > 1.0)
|
||||
meterFloatsArray[index] = 1.0;
|
||||
|
||||
mMeter->UpdateDisplay(2, nFrames, meterFloatsArray);
|
||||
mMeter->UpdateDisplay(2, nFrames, meterFloatsArray.get());
|
||||
}
|
||||
else
|
||||
this->ResetMeter(false);
|
||||
|
||||
delete[] meterFloatsArray;
|
||||
delete[] tempFloatsArray;
|
||||
}
|
||||
|
||||
// private
|
||||
|
@ -2794,9 +2794,8 @@ wxString PluginManager::ConvertID(const PluginID & ID)
|
||||
if (ID.StartsWith(wxT("base64:")))
|
||||
{
|
||||
wxString id = ID.Mid(7);
|
||||
char *buf = new char[id.Length() / 4 * 3];
|
||||
id = wxString::FromUTF8(buf, b64decode(id, buf));
|
||||
delete [] buf;
|
||||
ArrayOf<char> buf{ id.Length() / 4 * 3 };
|
||||
id = wxString::FromUTF8(buf.get(), b64decode(id, buf.get()));
|
||||
return id;
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ Profiler::~Profiler()
|
||||
{
|
||||
if(mTasks[i]->mNumHits>0)
|
||||
{
|
||||
fprintf(log,"Task: %s\n(begins at line %d in %s)\n\n",mTasks[i]->mDescription,mTasks[i]->mLine,mTasks[i]->mFileName);
|
||||
fprintf(log,"Task: %s\n(begins at line %d in %s)\n\n",mTasks[i]->mDescription.get(), mTasks[i]->mLine, mTasks[i]->mFileName.get());
|
||||
fprintf(log,"Number of times run: %d\n",mTasks[i]->mNumHits);
|
||||
fprintf(log,"Total run time (seconds): %f\n", (double)mTasks[i]->mCumTime/CLOCKS_PER_SEC);
|
||||
fprintf(log,"Average run time (seconds): %f\n",mTasks[i]->ComputeAverageRunTime());
|
||||
@ -91,7 +91,7 @@ TaskProfile* Profiler::GetOrCreateTaskProfile(const char* fileName, int lineNum)
|
||||
{
|
||||
for(int i=0;i<(int)mTasks.size();i++)
|
||||
{
|
||||
if(strcmp(fileName,mTasks[i]->mFileName)==0 && lineNum == mTasks[i]->mLine)
|
||||
if(strcmp(fileName, mTasks[i]->mFileName.get())==0 && lineNum == mTasks[i]->mLine)
|
||||
return mTasks[i].get();
|
||||
}
|
||||
|
||||
@ -104,7 +104,7 @@ TaskProfile* Profiler::GetTaskProfileByDescription(const char* description)
|
||||
{
|
||||
for(int i=0;i<(int)mTasks.size();i++)
|
||||
{
|
||||
if(strcmp(description,mTasks[i]->mDescription)==0)
|
||||
if(strcmp(description, mTasks[i]->mDescription.get())==0)
|
||||
return mTasks[i].get();
|
||||
}
|
||||
|
||||
@ -116,18 +116,12 @@ TaskProfile* Profiler::GetTaskProfileByDescription(const char* description)
|
||||
///Task Profile
|
||||
TaskProfile::TaskProfile()
|
||||
{
|
||||
mFileName = NULL;
|
||||
mCumTime=0;
|
||||
mNumHits=0;
|
||||
}
|
||||
|
||||
TaskProfile::~TaskProfile()
|
||||
{
|
||||
if(mFileName)
|
||||
{
|
||||
delete [] mFileName;
|
||||
delete [] mDescription;
|
||||
}
|
||||
}
|
||||
|
||||
///start the task timer.
|
||||
@ -135,10 +129,10 @@ void TaskProfile::Begin(const char* fileName, int lineNum, const char* taskDescr
|
||||
{
|
||||
if(!mFileName)
|
||||
{
|
||||
mFileName = new char[strlen(fileName)+1];
|
||||
strcpy(mFileName,fileName);
|
||||
mDescription = new char[strlen(taskDescription)+1];
|
||||
strcpy(mDescription,taskDescription);
|
||||
mFileName.reinit( strlen(fileName) + 1 );
|
||||
strcpy(mFileName.get(), fileName);
|
||||
mDescription.reinit( strlen(taskDescription) + 1 );
|
||||
strcpy(mDescription.get(), taskDescription);
|
||||
mLine = lineNum;
|
||||
}
|
||||
|
||||
|
@ -79,9 +79,9 @@ class Profiler
|
||||
|
||||
double ComputeAverageRunTime();
|
||||
|
||||
char* mFileName;
|
||||
ArrayOf<char> mFileName;
|
||||
int mLine;
|
||||
char* mDescription;
|
||||
ArrayOf<char> mDescription;
|
||||
int mNumHits;
|
||||
clock_t mCumTime;
|
||||
clock_t mLastTime;
|
||||
|
@ -383,19 +383,17 @@ public:
|
||||
Size dataSize = 0;
|
||||
GetFlavorDataSize((DragReference)m_currentDrag, theItem, theType, &dataSize);
|
||||
|
||||
Ptr theData = new char[dataSize];
|
||||
GetFlavorData((DragReference)m_currentDrag, theItem, theType, (void*) theData, &dataSize, 0L);
|
||||
ArrayOf<char> theData{ dataSize };
|
||||
GetFlavorData((DragReference)m_currentDrag, theItem, theType, (void*) theData.get(), &dataSize, 0L);
|
||||
|
||||
wxString name;
|
||||
if (theType == kDragPromisedFlavorFindFile) {
|
||||
name = wxMacFSSpec2MacFilename((FSSpec *)theData);
|
||||
name = wxMacFSSpec2MacFilename((FSSpec *)theData.get());
|
||||
}
|
||||
else if (theType == kDragFlavorTypeHFS) {
|
||||
name = wxMacFSSpec2MacFilename(&((HFSFlavor *)theData)->fileSpec);
|
||||
name = wxMacFSSpec2MacFilename(&((HFSFlavor *)theData.get())->fileSpec);
|
||||
}
|
||||
|
||||
delete[] theData;
|
||||
|
||||
if (!firstFileAdded) {
|
||||
// reset file list
|
||||
((wxFileDataObject*)GetDataObject())->SetData(0, "");
|
||||
|
@ -94,9 +94,9 @@ void TableUsage(int iMask)
|
||||
SinCosTable::SinCosTable() :
|
||||
mSinCosTablePow(13)
|
||||
{
|
||||
int tableSize=1<<mSinCosTablePow;
|
||||
mSinCosTable=new SinCosStruct[tableSize];
|
||||
for(int i=0;i<tableSize;i++) {
|
||||
size_t tableSize=1<<mSinCosTablePow;
|
||||
mSinCosTable.reinit(tableSize);
|
||||
for(size_t i=0;i<tableSize;i++) {
|
||||
mSinCosTable[i].mSin=(float)-sin(((float)i)*M_PI/tableSize);
|
||||
mSinCosTable[i].mCos=(float)-cos(((float)i)*M_PI/tableSize);
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
#ifndef __realfftf48x_h
|
||||
#define __realfftf48x_h
|
||||
|
||||
#include "MemoryX.h"
|
||||
|
||||
#define fft_type float
|
||||
|
||||
int SmallRB(int bits, int numberBits);
|
||||
@ -87,9 +89,8 @@ typedef struct {
|
||||
class SinCosTable {
|
||||
public:
|
||||
int mSinCosTablePow;
|
||||
SinCosStruct *mSinCosTable;
|
||||
ArrayOf<SinCosStruct> mSinCosTable;
|
||||
SinCosTable();
|
||||
~SinCosTable(){ delete [] mSinCosTable; };
|
||||
};
|
||||
|
||||
int SmallRB(int bits, int numberBits);
|
||||
|
@ -1308,7 +1308,7 @@ bool Sequence::GetWaveDisplay(float *min, float *max, float *rms, int* bl,
|
||||
// ... unless the mNumSamples ceiling applies, and then there are other defenses
|
||||
const auto s1 =
|
||||
std::min(mNumSamples, std::max(1 + where[len - 1], where[len]));
|
||||
float *temp = new float[mMaxSamples];
|
||||
Floats temp{ mMaxSamples };
|
||||
|
||||
decltype(len) pixel = 0;
|
||||
|
||||
@ -1400,13 +1400,13 @@ bool Sequence::GetWaveDisplay(float *min, float *max, float *rms, int* bl,
|
||||
default:
|
||||
case 1:
|
||||
// Read samples
|
||||
Read((samplePtr)temp, floatSample, seqBlock, startPosition, num);
|
||||
Read((samplePtr)temp.get(), floatSample, seqBlock, startPosition, num);
|
||||
break;
|
||||
case 256:
|
||||
// Read triples
|
||||
//check to see if summary data has been computed
|
||||
if (seqBlock.f->IsSummaryAvailable())
|
||||
seqBlock.f->Read256(temp, startPosition, num);
|
||||
seqBlock.f->Read256(temp.get(), startPosition, num);
|
||||
else
|
||||
//otherwise, mark the display as not yet computed
|
||||
blockStatus = -1 - b;
|
||||
@ -1415,7 +1415,7 @@ bool Sequence::GetWaveDisplay(float *min, float *max, float *rms, int* bl,
|
||||
// Read triples
|
||||
//check to see if summary data has been computed
|
||||
if (seqBlock.f->IsSummaryAvailable())
|
||||
seqBlock.f->Read64K(temp, startPosition, num);
|
||||
seqBlock.f->Read64K(temp.get(), startPosition, num);
|
||||
else
|
||||
//otherwise, mark the display as not yet computed
|
||||
blockStatus = -1 - b;
|
||||
@ -1431,7 +1431,7 @@ bool Sequence::GetWaveDisplay(float *min, float *max, float *rms, int* bl,
|
||||
auto midPosition = ((whereNow - start) / divisor).as_size_t();
|
||||
int diff(midPosition - filePosition);
|
||||
if (diff > 0) {
|
||||
MinMaxSumsq values(temp, diff, divisor);
|
||||
MinMaxSumsq values(temp.get(), diff, divisor);
|
||||
const int lastPixel = pixel - 1;
|
||||
float &lastMin = min[lastPixel];
|
||||
lastMin = std::min(lastMin, values.min);
|
||||
@ -1471,7 +1471,7 @@ bool Sequence::GetWaveDisplay(float *min, float *max, float *rms, int* bl,
|
||||
rmsDenom = (positionX - filePosition);
|
||||
wxASSERT(rmsDenom > 0);
|
||||
const float *const pv =
|
||||
temp + (filePosition - startPosition) * (divisor == 1 ? 1 : 3);
|
||||
temp.get() + (filePosition - startPosition) * (divisor == 1 ? 1 : 3);
|
||||
MinMaxSumsq values(pv, rmsDenom, divisor);
|
||||
|
||||
// Assign results
|
||||
@ -1493,8 +1493,6 @@ bool Sequence::GetWaveDisplay(float *min, float *max, float *rms, int* bl,
|
||||
|
||||
wxASSERT(pixel == len);
|
||||
|
||||
delete[] temp;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -291,10 +291,7 @@ bool SnapManager::SnapToPoints(Track *currentTrack,
|
||||
return true;
|
||||
}
|
||||
|
||||
// indexInThisTrack is ONLY used if count > 0
|
||||
// and is initialised then, so we can 'initialise' it
|
||||
// to anything to keep compiler quiet.
|
||||
size_t indexInThisTrack = left;
|
||||
size_t indexInThisTrack = 0;
|
||||
size_t countInThisTrack = 0;
|
||||
for (i = left; i <= right; ++i)
|
||||
{
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "FFT.h"
|
||||
|
||||
#include "Experimental.h"
|
||||
#include "SampleFormat.h"
|
||||
|
||||
bool ComputeSpectrum(const float * data, size_t width,
|
||||
size_t windowSize,
|
||||
@ -31,15 +32,15 @@ bool ComputeSpectrum(const float * data, size_t width,
|
||||
if (!data || !output)
|
||||
return true;
|
||||
|
||||
float *processed = new float[windowSize];
|
||||
Floats processed{ windowSize };
|
||||
|
||||
for (size_t i = 0; i < windowSize; i++)
|
||||
processed[i] = float(0.0);
|
||||
auto half = windowSize / 2;
|
||||
|
||||
float *in = new float[windowSize];
|
||||
float *out = new float[windowSize];
|
||||
float *out2 = new float[windowSize];
|
||||
Floats in{ windowSize };
|
||||
Floats out{ windowSize };
|
||||
Floats out2{ windowSize };
|
||||
|
||||
size_t start = 0;
|
||||
unsigned windows = 0;
|
||||
@ -47,11 +48,11 @@ bool ComputeSpectrum(const float * data, size_t width,
|
||||
for (size_t i = 0; i < windowSize; i++)
|
||||
in[i] = data[start + i];
|
||||
|
||||
WindowFunc(windowFunc, windowSize, in);
|
||||
WindowFunc(windowFunc, windowSize, in.get());
|
||||
|
||||
if (autocorrelation) {
|
||||
// Take FFT
|
||||
RealFFT(windowSize, in, out, out2);
|
||||
RealFFT(windowSize, in.get(), out.get(), out2.get());
|
||||
// Compute power
|
||||
for (size_t i = 0; i < windowSize; i++)
|
||||
in[i] = (out[i] * out[i]) + (out2[i] * out2[i]);
|
||||
@ -63,10 +64,10 @@ bool ComputeSpectrum(const float * data, size_t width,
|
||||
in[i] = powf(in[i], 1.0f / 3.0f);
|
||||
|
||||
// Take FFT
|
||||
RealFFT(windowSize, in, out, out2);
|
||||
RealFFT(windowSize, in.get(), out.get(), out2.get());
|
||||
}
|
||||
else
|
||||
PowerSpectrum(windowSize, in, out);
|
||||
PowerSpectrum(windowSize, in.get(), out.get());
|
||||
|
||||
// Take real part of result
|
||||
for (size_t i = 0; i < half; i++)
|
||||
@ -120,10 +121,6 @@ bool ComputeSpectrum(const float * data, size_t width,
|
||||
|
||||
for(size_t i = 0; i < half; i++)
|
||||
output[i] = processed[i];
|
||||
delete[]in;
|
||||
delete[]out;
|
||||
delete[]out2;
|
||||
delete[]processed;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -4553,20 +4553,18 @@ void TrackPanel::HandleSampleEditingClick( wxMouseEvent & event )
|
||||
// SMOOTHING_PROPORTION_MAX and at the far bounds is SMOOTHING_PROPORTION_MIN
|
||||
|
||||
//Get the region of samples around the selected point
|
||||
int sampleRegionSize = 1 + 2 * (SMOOTHING_KERNEL_RADIUS + SMOOTHING_BRUSH_RADIUS);
|
||||
float *sampleRegion = new float[sampleRegionSize];
|
||||
float * newSampleRegion = new float[1 + 2 * SMOOTHING_BRUSH_RADIUS];
|
||||
size_t sampleRegionSize = 1 + 2 * (SMOOTHING_KERNEL_RADIUS + SMOOTHING_BRUSH_RADIUS);
|
||||
Floats sampleRegion{ sampleRegionSize };
|
||||
Floats newSampleRegion{ 1 + 2 * (size_t)SMOOTHING_BRUSH_RADIUS };
|
||||
|
||||
//Get a sample from the track to do some tricks on.
|
||||
mDrawingTrack->Get((samplePtr)sampleRegion, floatSample,
|
||||
mDrawingTrack->Get((samplePtr)sampleRegion.get(), floatSample,
|
||||
mDrawingStartSample - SMOOTHING_KERNEL_RADIUS - SMOOTHING_BRUSH_RADIUS,
|
||||
sampleRegionSize);
|
||||
int i, j;
|
||||
|
||||
//Go through each point of the smoothing brush and apply a smoothing operation.
|
||||
for(j = -SMOOTHING_BRUSH_RADIUS; j <= SMOOTHING_BRUSH_RADIUS; j++){
|
||||
for(auto j = -SMOOTHING_BRUSH_RADIUS; j <= SMOOTHING_BRUSH_RADIUS; j++){
|
||||
float sumOfSamples = 0;
|
||||
for (i= -SMOOTHING_KERNEL_RADIUS; i <= SMOOTHING_KERNEL_RADIUS; i++){
|
||||
for (auto i = -SMOOTHING_KERNEL_RADIUS; i <= SMOOTHING_KERNEL_RADIUS; i++){
|
||||
//Go through each point of the smoothing kernel and find the average
|
||||
|
||||
//The average is a weighted average, scaled by a weighting kernel that is simply triangular
|
||||
@ -4591,7 +4589,7 @@ void TrackPanel::HandleSampleEditingClick( wxMouseEvent & event )
|
||||
|
||||
float prob;
|
||||
|
||||
for(j=-SMOOTHING_BRUSH_RADIUS; j <= SMOOTHING_BRUSH_RADIUS; j++){
|
||||
for(auto j = -SMOOTHING_BRUSH_RADIUS; j <= SMOOTHING_BRUSH_RADIUS; j++){
|
||||
|
||||
prob = SMOOTHING_PROPORTION_MAX - (float)abs(j)/SMOOTHING_BRUSH_RADIUS * (SMOOTHING_PROPORTION_MAX - SMOOTHING_PROPORTION_MIN);
|
||||
|
||||
@ -4600,11 +4598,7 @@ void TrackPanel::HandleSampleEditingClick( wxMouseEvent & event )
|
||||
sampleRegion[SMOOTHING_BRUSH_RADIUS + SMOOTHING_KERNEL_RADIUS + j] * (1 - prob);
|
||||
}
|
||||
//Set the sample to the point of the mouse event
|
||||
mDrawingTrack->Set((samplePtr)newSampleRegion, floatSample, mDrawingStartSample - SMOOTHING_BRUSH_RADIUS, 1 + 2 * SMOOTHING_BRUSH_RADIUS);
|
||||
|
||||
//Clean this up right away to avoid a memory leak
|
||||
delete[] sampleRegion;
|
||||
delete[] newSampleRegion;
|
||||
mDrawingTrack->Set((samplePtr)newSampleRegion.get(), floatSample, mDrawingStartSample - SMOOTHING_BRUSH_RADIUS, 1 + 2 * SMOOTHING_BRUSH_RADIUS);
|
||||
|
||||
mDrawingLastDragSampleValue = 0;
|
||||
}
|
||||
|
@ -149,8 +149,9 @@ sampleCount VoiceKey::OnForward (
|
||||
|
||||
//To speed things up, create a local buffer to store things in, to avoid the costly t.Get();
|
||||
//Only go through the first SignalWindowSizeInt samples, and choose the first that trips the key.
|
||||
float *buffer = new float[remaining];
|
||||
t.Get((samplePtr)buffer, floatSample, lastsubthresholdsample, remaining);
|
||||
Floats buffer{ remaining };
|
||||
t.Get((samplePtr)buffer.get(), floatSample,
|
||||
lastsubthresholdsample, remaining);
|
||||
|
||||
|
||||
|
||||
@ -226,7 +227,6 @@ sampleCount VoiceKey::OnForward (
|
||||
}
|
||||
|
||||
//When we get here, i+lastsubthresholdsample is the best guess for where the word starts
|
||||
delete [] buffer;
|
||||
return i + lastsubthresholdsample;
|
||||
}
|
||||
else {
|
||||
@ -299,8 +299,9 @@ sampleCount VoiceKey::OnBackward (
|
||||
|
||||
//To speed things up, create a local buffer to store things in, to avoid the costly t.Get();
|
||||
//Only go through the first mSilentWindowSizeInt samples, and choose the first that trips the key.
|
||||
float *buffer = new float[remaining];
|
||||
t.Get((samplePtr)buffer, floatSample, lastsubthresholdsample-remaining, remaining);
|
||||
Floats buffer{ remaining };
|
||||
t.Get((samplePtr)buffer.get(), floatSample,
|
||||
lastsubthresholdsample - remaining, remaining);
|
||||
|
||||
//Initialize these trend markers atrend and ztrend. They keep track of the
|
||||
//up/down trends at the start and end of the evaluation window.
|
||||
@ -364,7 +365,6 @@ sampleCount VoiceKey::OnBackward (
|
||||
}
|
||||
|
||||
//When we get here, i+lastsubthresholdsample is the best guess for where the word starts
|
||||
delete [] buffer;
|
||||
return lastsubthresholdsample - remaining + i;
|
||||
}
|
||||
else {
|
||||
@ -435,8 +435,9 @@ sampleCount VoiceKey::OffForward (
|
||||
|
||||
//To speed things up, create a local buffer to store things in, to avoid the costly t.Get();
|
||||
//Only go through the first SilentWindowSizeInt samples, and choose the first that trips the key.
|
||||
float *buffer = new float[remaining];
|
||||
t.Get((samplePtr)buffer, floatSample, lastsubthresholdsample, remaining);
|
||||
Floats buffer{ remaining };
|
||||
t.Get((samplePtr)buffer.get(), floatSample,
|
||||
lastsubthresholdsample, remaining);
|
||||
|
||||
//Initialize these trend markers atrend and ztrend. They keep track of the
|
||||
//up/down trends at the start and end of the evaluation window.
|
||||
@ -500,7 +501,6 @@ sampleCount VoiceKey::OffForward (
|
||||
}
|
||||
|
||||
//When we get here, i+lastsubthresholdsample is the best guess for where the word starts
|
||||
delete [] buffer;
|
||||
return i + lastsubthresholdsample;
|
||||
}
|
||||
else {
|
||||
@ -572,8 +572,8 @@ sampleCount VoiceKey::OffBackward (
|
||||
|
||||
//To speed things up, create a local buffer to store things in, to avoid the costly t.Get();
|
||||
//Only go through the first SilentWindowSizeInt samples, and choose the first that trips the key.
|
||||
float *buffer = new float[remaining];
|
||||
t.Get((samplePtr)buffer, floatSample,
|
||||
Floats buffer{ remaining };
|
||||
t.Get((samplePtr)buffer.get(), floatSample,
|
||||
lastsubthresholdsample - remaining, remaining);
|
||||
|
||||
//Initialize these trend markers atrend and ztrend. They keep track of the
|
||||
@ -641,7 +641,6 @@ sampleCount VoiceKey::OffBackward (
|
||||
}
|
||||
|
||||
//When we get here, i+lastsubthresholdsample is the best guess for where the word starts
|
||||
delete [] buffer;
|
||||
return lastsubthresholdsample - remaining + i;
|
||||
}
|
||||
else {
|
||||
@ -849,14 +848,14 @@ double VoiceKey::TestEnergy (
|
||||
auto originalLen = len; //Keep track of the length of block to process (its not the length of t)
|
||||
const auto blockSize = limitSampleBufferSize(
|
||||
t.GetMaxBlockSize(), len); //Determine size of sampling buffer
|
||||
float *buffer = new float[blockSize]; //Get a sampling buffer
|
||||
Floats buffer{ blockSize }; //Get a sampling buffer
|
||||
|
||||
while(len > 0)
|
||||
{
|
||||
//Figure out how much to grab
|
||||
auto block = limitSampleBufferSize ( t.GetBestBlockSize(s), len );
|
||||
|
||||
t.Get((samplePtr)buffer,floatSample, s,block); //grab the block;
|
||||
t.Get((samplePtr)buffer.get(), floatSample, s,block); //grab the block;
|
||||
|
||||
//Now, go through the block and calculate energy
|
||||
for(decltype(block) i = 0; i< block; i++)
|
||||
@ -868,7 +867,6 @@ double VoiceKey::TestEnergy (
|
||||
s += block;
|
||||
}
|
||||
|
||||
delete [] buffer;
|
||||
return sum / originalLen.as_double();
|
||||
}
|
||||
|
||||
@ -894,13 +892,13 @@ double VoiceKey::TestSignChanges(
|
||||
unsigned long signchanges = 1;
|
||||
int currentsign=0;
|
||||
|
||||
float *buffer = new float[blockSize]; //Get a sampling buffer
|
||||
Floats buffer{ blockSize }; //Get a sampling buffer
|
||||
|
||||
while(len > 0) {
|
||||
//Figure out how much to grab
|
||||
auto block = limitSampleBufferSize ( t.GetBestBlockSize(s), len );
|
||||
|
||||
t.Get((samplePtr)buffer,floatSample, s,block); //grab the block;
|
||||
t.Get((samplePtr)buffer.get(), floatSample, s, block); //grab the block;
|
||||
|
||||
if (len == originalLen)
|
||||
{
|
||||
@ -922,7 +920,6 @@ double VoiceKey::TestSignChanges(
|
||||
len -= block;
|
||||
s += block;
|
||||
}
|
||||
delete [] buffer;
|
||||
return (double)signchanges / originalLen.as_double();
|
||||
}
|
||||
|
||||
@ -952,13 +949,13 @@ double VoiceKey::TestDirectionChanges(
|
||||
float lastval=float(0);
|
||||
int lastdirection=1;
|
||||
|
||||
float *buffer = new float[blockSize]; //Get a sampling buffer
|
||||
Floats buffer{ blockSize }; //Get a sampling buffer
|
||||
|
||||
while(len > 0) {
|
||||
//Figure out how much to grab
|
||||
auto block = limitSampleBufferSize ( t.GetBestBlockSize(s), len );
|
||||
|
||||
t.Get((samplePtr)buffer,floatSample, s,block); //grab the block;
|
||||
t.Get((samplePtr)buffer.get(), floatSample, s, block); //grab the block;
|
||||
|
||||
if (len == originalLen) {
|
||||
//The first time through, set stuff up special.
|
||||
@ -980,7 +977,6 @@ double VoiceKey::TestDirectionChanges(
|
||||
len -= block;
|
||||
s += block;
|
||||
}
|
||||
delete [] buffer;
|
||||
return (double)directionchanges/originalLen.as_double();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user