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