1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-05 22:28:57 +02:00

Remove naked new[] in: import

This commit is contained in:
Paul Licameli 2016-04-14 12:02:45 -04:00
parent 9bdc7b2cbf
commit 88cac8cd7e
8 changed files with 159 additions and 192 deletions

View File

@ -36,11 +36,6 @@ FormatClassifier::FormatClassifier(const char* filename) :
{
FormatClassT fClass;
// Build buffers
mSigBuffer = new float[cSiglen];
mAuxBuffer = new float[cSiglen];
mRawBuffer = new uint8_t[cSiglen * 8];
// Define the classification classes
fClass.endian = MachineEndianness::Little;
fClass.format = MultiFormatReader::Int8;
@ -71,8 +66,8 @@ FormatClassifier::FormatClassifier(const char* filename) :
mClasses.push_back(fClass);
// Build feature vectors
mMonoFeat = new float[mClasses.size()];
mStereoFeat = new float[mClasses.size()];
mMonoFeat = Floats{ mClasses.size() };
mStereoFeat = Floats{ mClasses.size() };
#ifdef FORMATCLASSIFIER_SIGNAL_DEBUG
// Build a debug writer
@ -95,12 +90,6 @@ FormatClassifier::FormatClassifier(const char* filename) :
FormatClassifier::~FormatClassifier()
{
delete[] mSigBuffer;
delete[] mAuxBuffer;
delete[] mRawBuffer;
delete[] mMonoFeat;
delete[] mStereoFeat;
}
FormatClassifier::FormatClassT FormatClassifier::GetResultFormat()
@ -168,17 +157,17 @@ void FormatClassifier::Run()
// Do some simple preprocessing
// Remove DC offset
float smean = Mean(mSigBuffer, cSiglen);
Sub(mSigBuffer, smean, cSiglen);
float smean = Mean(mSigBuffer.get(), cSiglen);
Sub(mSigBuffer.get(), smean, cSiglen);
// Normalize to +- 1.0
Abs(mSigBuffer, mAuxBuffer, cSiglen);
float smax = Max(mAuxBuffer, cSiglen);
Div(mSigBuffer, smax, cSiglen);
Abs(mSigBuffer.get(), mAuxBuffer.get(), cSiglen);
float smax = Max(mAuxBuffer.get(), cSiglen);
Div(mSigBuffer.get(), smax, cSiglen);
// Now actually fill the feature vector
// Low to high band power ratio
float pLo = mMeter.CalcPower(mSigBuffer, 0.15f, 0.3f);
float pHi = mMeter.CalcPower(mSigBuffer, 0.45f, 0.1f);
float pLo = mMeter.CalcPower(mSigBuffer.get(), 0.15f, 0.3f);
float pHi = mMeter.CalcPower(mSigBuffer.get(), 0.45f, 0.1f);
mMonoFeat[n] = pLo / pHi;
}
@ -193,24 +182,24 @@ void FormatClassifier::Run()
// Do some simple preprocessing
// Remove DC offset
float smean = Mean(mSigBuffer, cSiglen);
Sub(mSigBuffer, smean, cSiglen);
float smean = Mean(mSigBuffer.get(), cSiglen);
Sub(mSigBuffer.get(), smean, cSiglen);
// Normalize to +- 1.0
Abs(mSigBuffer, mAuxBuffer, cSiglen);
float smax = Max(mAuxBuffer, cSiglen);
Div(mSigBuffer, smax, cSiglen);
Abs(mSigBuffer.get(), mAuxBuffer.get(), cSiglen);
float smax = Max(mAuxBuffer.get(), cSiglen);
Div(mSigBuffer.get(), smax, cSiglen);
// Now actually fill the feature vector
// Low to high band power ratio
float pLo = mMeter.CalcPower(mSigBuffer, 0.15f, 0.3f);
float pHi = mMeter.CalcPower(mSigBuffer, 0.45f, 0.1f);
float pLo = mMeter.CalcPower(mSigBuffer.get(), 0.15f, 0.3f);
float pHi = mMeter.CalcPower(mSigBuffer.get(), 0.45f, 0.1f);
mStereoFeat[n] = pLo / pHi;
}
// Get the results
size_t midx, sidx;
float monoMax = Max(mMonoFeat, mClasses.size(), &midx);
float stereoMax = Max(mStereoFeat, mClasses.size(), &sidx);
float monoMax = Max(mMonoFeat.get(), mClasses.size(), &midx);
float stereoMax = Max(mStereoFeat.get(), mClasses.size(), &sidx);
if (monoMax > stereoMax)
{
@ -233,27 +222,27 @@ void FormatClassifier::ReadSignal(FormatClassT format, size_t stride)
mReader.Reset();
// Do a dummy read of 1024 bytes to skip potential header information
mReader.ReadSamples(mRawBuffer, 1024, MultiFormatReader::Uint8, MachineEndianness::Little);
mReader.ReadSamples(mRawBuffer.get(), 1024, MultiFormatReader::Uint8, MachineEndianness::Little);
do
{
actRead = mReader.ReadSamples(mRawBuffer, cSiglen, stride, format.format, format.endian);
actRead = mReader.ReadSamples(mRawBuffer.get(), cSiglen, stride, format.format, format.endian);
if (n == 0)
{
ConvertSamples(mRawBuffer, mSigBuffer, format);
ConvertSamples(mRawBuffer.get(), mSigBuffer.get(), format);
}
else
{
if (actRead == cSiglen)
{
ConvertSamples(mRawBuffer, mAuxBuffer, format);
ConvertSamples(mRawBuffer.get(), mAuxBuffer.get(), format);
// Integrate signals
Add(mSigBuffer, mAuxBuffer, cSiglen);
Add(mSigBuffer.get(), mAuxBuffer.get(), cSiglen);
// Do some dummy reads to break signal coherence
mReader.ReadSamples(mRawBuffer, n + 1, stride, format.format, format.endian);
mReader.ReadSamples(mRawBuffer.get(), n + 1, stride, format.format, format.endian);
}
}

View File

@ -82,12 +82,12 @@ private:
std::unique_ptr<DebugWriter> mpWriter;
#endif
float* mSigBuffer;
float* mAuxBuffer;
uint8_t* mRawBuffer;
Floats mSigBuffer{ cSiglen };
Floats mAuxBuffer{ cSiglen };
ArrayOf<uint8_t> mRawBuffer{ cSiglen * 8 };
float* mMonoFeat;
float* mStereoFeat;
Floats mMonoFeat;
Floats mStereoFeat;
FormatClassT mResultFormat;
unsigned mResultChannels { 0 };

View File

@ -252,7 +252,7 @@ void MyFLACFile::error_callback(FLAC__StreamDecoderErrorStatus WXUNUSED(status))
FLAC__StreamDecoderWriteStatus MyFLACFile::write_callback(const FLAC__Frame *frame,
const FLAC__int32 * const buffer[])
{
short *tmp=new short[frame->header.blocksize];
ArrayOf<short> tmp{ frame->header.blocksize };
auto iter = mFile->mChannels.begin();
for (unsigned int chn=0; chn<mFile->mNumChannels; ++iter, ++chn) {
@ -261,7 +261,7 @@ FLAC__StreamDecoderWriteStatus MyFLACFile::write_callback(const FLAC__Frame *fra
tmp[s]=buffer[chn][s];
}
iter->get()->Append((samplePtr)tmp,
iter->get()->Append((samplePtr)tmp.get(),
int16Sample,
frame->header.blocksize);
}
@ -272,8 +272,6 @@ FLAC__StreamDecoderWriteStatus MyFLACFile::write_callback(const FLAC__Frame *fra
}
}
delete [] tmp;
mFile->mSamplesDone += frame->header.blocksize;
mFile->mUpdateResult = mFile->mProgress->Update((wxULongLong_t) mFile->mSamplesDone, mFile->mNumSamples != 0 ? (wxULongLong_t)mFile->mNumSamples : 1);
@ -452,7 +450,7 @@ ProgressResult FLACImportFileHandle::Import(TrackFactory *trackFactory,
mChannels.resize(mNumChannels);
auto iter = mChannels.begin();
for (int c = 0; c < mNumChannels; ++iter, ++c) {
for (size_t c = 0; c < mNumChannels; ++iter, ++c) {
*iter = trackFactory->NewWaveTrack(mFormat, mSampleRate);
if (mNumChannels == 2) {
@ -500,7 +498,7 @@ ProgressResult FLACImportFileHandle::Import(TrackFactory *trackFactory,
limitSampleBufferSize( maxBlockSize, fileTotalFrames - i );
auto iter = mChannels.begin();
for (int c = 0; c < mNumChannels; ++c, ++iter)
for (size_t c = 0; c < mNumChannels; ++c, ++iter)
iter->get()->AppendCoded(mFilename, i, blockLen, c, ODTask::eODFLAC);
mUpdateResult = mProgress->Update(
@ -540,7 +538,7 @@ ProgressResult FLACImportFileHandle::Import(TrackFactory *trackFactory,
tags->Clear();
size_t cnt = mFile->mComments.GetCount();
for (int c = 0; c < cnt; c++) {
for (size_t c = 0; c < cnt; c++) {
wxString name = mFile->mComments[c].BeforeFirst(wxT('='));
wxString value = mFile->mComments[c].AfterFirst(wxT('='));
if (name.Upper() == wxT("DATE") && !tags->HasTag(TAG_YEAR)) {

View File

@ -86,7 +86,7 @@ extern "C" {
#include "../WaveTrack.h"
#define INPUT_BUFFER_SIZE 65535
#define INPUT_BUFFER_SIZE 65535u
#define PROGRESS_SCALING_FACTOR 100000
/* this is a private structure we can use for whatever we like, and it will get
@ -94,7 +94,7 @@ extern "C" {
* things. */
struct private_data {
wxFile *file; /* the file containing the mp3 data we're feeding the encoder */
unsigned char *inputBuffer;
ArrayOf<unsigned char> inputBuffer{ INPUT_BUFFER_SIZE };
int inputBufferFill; /* amount of data in inputBuffer */
TrackFactory *trackFactory;
TrackHolders channels;
@ -152,7 +152,6 @@ private:
std::unique_ptr<wxFile> mFile;
void *mUserData;
struct private_data mPrivateData;
mad_decoder mDecoder;
};
@ -217,33 +216,31 @@ ProgressResult MP3ImportFileHandle::Import(TrackFactory *trackFactory, TrackHold
/* Prepare decoder data, initialize decoder */
mPrivateData.file = mFile.get();
mPrivateData.inputBuffer = new unsigned char [INPUT_BUFFER_SIZE];
mPrivateData.inputBufferFill = 0;
mPrivateData.progress = mProgress.get();
mPrivateData.updateResult= ProgressResult::Success;
mPrivateData.id3checked = false;
mPrivateData.numChannels = 0;
mPrivateData.trackFactory= trackFactory;
mPrivateData.eof = false;
private_data privateData;
privateData.file = mFile.get();
privateData.inputBufferFill = 0;
privateData.progress = mProgress.get();
privateData.updateResult= ProgressResult::Success;
privateData.id3checked = false;
privateData.numChannels = 0;
privateData.trackFactory= trackFactory;
privateData.eof = false;
mad_decoder_init(&mDecoder, &mPrivateData, input_cb, 0, 0, output_cb, error_cb, 0);
mad_decoder_init(&mDecoder, &privateData, input_cb, 0, 0, output_cb, error_cb, 0);
/* and send the decoder on its way! */
bool res = (mad_decoder_run(&mDecoder, MAD_DECODER_MODE_SYNC) == 0) &&
(mPrivateData.numChannels > 0) &&
!(mPrivateData.updateResult == ProgressResult::Cancelled) &&
!(mPrivateData.updateResult == ProgressResult::Failed);
(privateData.numChannels > 0) &&
!(privateData.updateResult == ProgressResult::Cancelled) &&
!(privateData.updateResult == ProgressResult::Failed);
mad_decoder_finish(&mDecoder);
delete[] mPrivateData.inputBuffer;
if (!res) {
/* failure */
/* printf("failure\n"); */
return (mPrivateData.updateResult);
return (privateData.updateResult);
}
/* success */
@ -251,15 +248,15 @@ ProgressResult MP3ImportFileHandle::Import(TrackFactory *trackFactory, TrackHold
/* copy the WaveTrack pointers into the Track pointer list that
* we are expected to fill */
for(const auto &channel : mPrivateData.channels) {
for(const auto &channel : privateData.channels) {
channel->Flush();
}
outTracks.swap(mPrivateData.channels);
outTracks.swap(privateData.channels);
/* Read in any metadata */
ImportID3(tags);
return mPrivateData.updateResult;
return privateData.updateResult;
}
MP3ImportFileHandle::~MP3ImportFileHandle()
@ -418,8 +415,8 @@ enum mad_flow input_cb(void *_data, struct mad_stream *stream)
#ifdef USE_LIBID3TAG
if (!data->id3checked) {
data->file->Read(data->inputBuffer, ID3_TAG_QUERYSIZE);
int len = id3_tag_query(data->inputBuffer, ID3_TAG_QUERYSIZE);
data->file->Read(data->inputBuffer.get(), ID3_TAG_QUERYSIZE);
int len = id3_tag_query(data->inputBuffer.get(), ID3_TAG_QUERYSIZE);
if (len > 0) {
data->file->Seek(len, wxFromStart);
}
@ -440,14 +437,15 @@ enum mad_flow input_cb(void *_data, struct mad_stream *stream)
* -- Rob Leslie, on the mad-dev mailing list */
int unconsumedBytes;
if (stream->next_frame) {
if(stream->next_frame ) {
/* we must use inputBufferFill instead of INPUT_BUFFER_SIZE here
because the final buffer of the file may be only partially
filled, and we would otherwise be providing too much input
after eof */
unconsumedBytes = data->inputBuffer + data->inputBufferFill
- stream->next_frame;
memmove(data->inputBuffer, stream->next_frame, unconsumedBytes);
unconsumedBytes = data->inputBuffer.get() + data->inputBufferFill
- stream->next_frame;
if (unconsumedBytes > 0)
memmove(data->inputBuffer.get(), stream->next_frame, unconsumedBytes);
}
else
unconsumedBytes = 0;
@ -458,19 +456,19 @@ enum mad_flow input_cb(void *_data, struct mad_stream *stream)
/* supply the requisite MAD_BUFFER_GUARD zero bytes to ensure
the final frame gets decoded properly, then finish */
memset(data->inputBuffer + unconsumedBytes, 0, MAD_BUFFER_GUARD);
memset(data->inputBuffer.get() + unconsumedBytes, 0, MAD_BUFFER_GUARD);
mad_stream_buffer
(stream, data->inputBuffer, MAD_BUFFER_GUARD + unconsumedBytes);
(stream, data->inputBuffer.get(), MAD_BUFFER_GUARD + unconsumedBytes);
data->eof = true; /* so on next call, we will tell mad to stop */
return MAD_FLOW_CONTINUE;
}
off_t read = data->file->Read(data->inputBuffer + unconsumedBytes,
off_t read = data->file->Read(data->inputBuffer.get() + unconsumedBytes,
INPUT_BUFFER_SIZE - unconsumedBytes);
mad_stream_buffer(stream, data->inputBuffer, read + unconsumedBytes);
mad_stream_buffer(stream, data->inputBuffer.get(), read + unconsumedBytes);
data->inputBufferFill = int(read + unconsumedBytes);
@ -486,7 +484,6 @@ enum mad_flow output_cb(void *_data,
{
int samplerate;
struct private_data *data = (struct private_data *)_data;
int smpl;
samplerate= pcm->samplerate;
auto channels = pcm->channels;
@ -526,24 +523,17 @@ enum mad_flow output_cb(void *_data,
* point samples into something we can feed to the WaveTrack. Allocating
* big blocks of data like this isn't a great idea, but it's temporary.
*/
float **channelBuffers = new float* [channels];
for(int chn = 0; chn < channels; chn++)
channelBuffers[chn] = new float [samples];
FloatBuffers channelBuffers{ channels, samples };
for(smpl = 0; smpl < samples; smpl++)
for (size_t smpl = 0; smpl < samples; smpl++)
for(int chn = 0; chn < channels; chn++)
channelBuffers[chn][smpl] = scale(pcm->samples[chn][smpl]);
auto iter = data->channels.begin();
for (int chn = 0; chn < channels; ++iter, ++chn)
iter->get()->Append((samplePtr)channelBuffers[chn],
for (int chn = 0; chn < channels; chn++)
data->channels[chn]->Append((samplePtr)channelBuffers[chn].get(),
floatSample,
samples);
for(int chn = 0; chn < channels; chn++)
delete[] channelBuffers[chn];
delete[] channelBuffers;
return MAD_FLOW_CONTINUE;
}

View File

@ -106,11 +106,11 @@ public:
: ImportFileHandle(filename),
mFile(std::move(file)),
mVorbisFile(std::move(vorbisFile))
, mStreamUsage{ static_cast<size_t>(mVorbisFile->links) }
{
mFormat = (sampleFormat)
gPrefs->Read(wxT("/SamplingRate/DefaultProjectSampleFormat"), floatSample);
mStreamUsage = new int[mVorbisFile->links];
for (int i = 0; i < mVorbisFile->links; i++)
{
wxString strinfo;
@ -153,7 +153,7 @@ private:
std::unique_ptr<wxFFile> mFile;
std::unique_ptr<OggVorbis_File> mVorbisFile;
int *mStreamUsage;
ArrayOf<int> mStreamUsage;
wxArrayString mStreamInfo;
std::list<TrackHolders> mChannels;
@ -243,7 +243,7 @@ ProgressResult OggImportFileHandle::Import(TrackFactory *trackFactory, TrackHold
mChannels.resize(mVorbisFile->links);
int i = -1;
for (auto &link: mChannels)
for (auto &link : mChannels)
{
++i;
@ -259,7 +259,7 @@ ProgressResult OggImportFileHandle::Import(TrackFactory *trackFactory, TrackHold
link.resize(vi->channels);
int c = - 1;
int c = -1;
for (auto &channel : link) {
++c;
@ -267,13 +267,13 @@ ProgressResult OggImportFileHandle::Import(TrackFactory *trackFactory, TrackHold
if (vi->channels == 2) {
switch (c) {
case 0:
channel->SetChannel(Track::LeftChannel);
channel->SetLinked(true);
break;
case 1:
channel->SetChannel(Track::RightChannel);
break;
case 0:
channel->SetChannel(Track::LeftChannel);
channel->SetLinked(true);
break;
case 1:
channel->SetChannel(Track::RightChannel);
break;
}
}
else {
@ -282,88 +282,88 @@ ProgressResult OggImportFileHandle::Import(TrackFactory *trackFactory, TrackHold
}
}
/* The number of bytes to get from the codec in each run */
#define CODEC_TRANSFER_SIZE 4096
/* The number of bytes to get from the codec in each run */
#define CODEC_TRANSFER_SIZE 4096u
/* The number of samples to read between calls to the callback.
* Balance between responsiveness of the GUI and throughput of import. */
/* The number of samples to read between calls to the callback.
* Balance between responsiveness of the GUI and throughput of import. */
#define SAMPLES_PER_CALLBACK 100000
short *mainBuffer = new short[CODEC_TRANSFER_SIZE];
/* determine endianness (clever trick courtesy of Nicholas Devillard,
* (http://www.eso.org/~ndevilla/endian/) */
int testvar = 1, endian;
if(*(char *)&testvar)
endian = 0; // little endian
else
endian = 1; // big endian
/* number of samples currently in each channel's buffer */
auto updateResult = ProgressResult::Success;
long bytesRead = 0;
long samplesRead = 0;
int bitstream = 0;
int samplesSinceLastCallback = 0;
{
ArrayOf<short> mainBuffer{ CODEC_TRANSFER_SIZE };
// You would think that the stream would already be seeked to 0, and
// indeed it is if the file is legit. But I had several ogg files on
// my hard drive that have malformed headers, and this added call
// causes them to be read correctly. Otherwise they have lots of
// zeros inserted at the beginning
ov_pcm_seek(mVorbisFile.get(), 0);
/* determine endianness (clever trick courtesy of Nicholas Devillard,
* (http://www.eso.org/~ndevilla/endian/) */
int testvar = 1, endian;
if (*(char *)&testvar)
endian = 0; // little endian
else
endian = 1; // big endian
do {
/* get data from the decoder */
bytesRead = ov_read(mVorbisFile.get(), (char *) mainBuffer,
CODEC_TRANSFER_SIZE,
endian,
2, // word length (2 for 16 bit samples)
1, // signed
&bitstream);
/* number of samples currently in each channel's buffer */
long samplesRead = 0;
int bitstream = 0;
int samplesSinceLastCallback = 0;
if (bytesRead == OV_HOLE) {
wxFileName ff(mFilename);
wxLogError(wxT("Ogg Vorbis importer: file %s is malformed, ov_read() reported a hole"),
ff.GetFullName().c_str());
/* http://lists.xiph.org/pipermail/vorbis-dev/2001-February/003223.html
* is the justification for doing this - best effort for malformed file,
* hence the message.
*/
continue;
} else if (bytesRead < 0) {
/* Malformed Ogg Vorbis file. */
/* TODO: Return some sort of meaningful error. */
wxLogError(wxT("Ogg Vorbis importer: ov_read() returned error %i"),
bytesRead);
break;
}
// You would think that the stream would already be seeked to 0, and
// indeed it is if the file is legit. But I had several ogg files on
// my hard drive that have malformed headers, and this added call
// causes them to be read correctly. Otherwise they have lots of
// zeros inserted at the beginning
ov_pcm_seek(mVorbisFile.get(), 0);
samplesRead = bytesRead / mVorbisFile->vi[bitstream].channels / sizeof(short);
do {
/* get data from the decoder */
bytesRead = ov_read(mVorbisFile.get(), (char *)mainBuffer.get(),
CODEC_TRANSFER_SIZE,
endian,
2, // word length (2 for 16 bit samples)
1, // signed
&bitstream);
/* give the data to the wavetracks */
auto iter = mChannels.begin();
std::advance(iter, bitstream);
if (mStreamUsage[bitstream] != 0)
{
auto iter2 = iter->begin();
for (int c = 0; c < mVorbisFile->vi[bitstream].channels; ++iter2, ++c)
iter2->get()->Append((char *)(mainBuffer + c),
int16Sample,
samplesRead,
mVorbisFile->vi[bitstream].channels);
}
if (bytesRead == OV_HOLE) {
wxFileName ff(mFilename);
wxLogError(wxT("Ogg Vorbis importer: file %s is malformed, ov_read() reported a hole"),
ff.GetFullName().c_str());
/* http://lists.xiph.org/pipermail/vorbis-dev/2001-February/003223.html
* is the justification for doing this - best effort for malformed file,
* hence the message.
*/
continue;
}
else if (bytesRead < 0) {
/* Malformed Ogg Vorbis file. */
/* TODO: Return some sort of meaningful error. */
wxLogError(wxT("Ogg Vorbis importer: ov_read() returned error %i"),
bytesRead);
break;
}
samplesSinceLastCallback += samplesRead;
if (samplesSinceLastCallback > SAMPLES_PER_CALLBACK) {
updateResult = mProgress->Update(ov_time_tell(mVorbisFile.get()),
ov_time_total(mVorbisFile.get(), bitstream));
samplesSinceLastCallback -= SAMPLES_PER_CALLBACK;
samplesRead = bytesRead / mVorbisFile->vi[bitstream].channels / sizeof(short);
}
} while (updateResult == ProgressResult::Success && bytesRead != 0);
/* give the data to the wavetracks */
auto iter = mChannels.begin();
std::advance(iter, bitstream);
if (mStreamUsage[bitstream] != 0)
{
auto iter2 = iter->begin();
for (int c = 0; c < mVorbisFile->vi[bitstream].channels; ++iter2, ++c)
iter2->get()->Append((char *)(mainBuffer.get() + c),
int16Sample,
samplesRead,
mVorbisFile->vi[bitstream].channels);
}
delete[]mainBuffer;
samplesSinceLastCallback += samplesRead;
if (samplesSinceLastCallback > SAMPLES_PER_CALLBACK) {
updateResult = mProgress->Update(ov_time_tell(mVorbisFile.get()),
ov_time_total(mVorbisFile.get(), bitstream));
samplesSinceLastCallback -= SAMPLES_PER_CALLBACK;
}
} while (updateResult == ProgressResult::Success && bytesRead != 0);
}
auto res = updateResult;
if (bytesRead < 0)
@ -406,7 +406,6 @@ OggImportFileHandle::~OggImportFileHandle()
ov_clear(mVorbisFile.get());
mFile->Detach(); // so that it doesn't try to close the file (ov_clear()
// did that already)
delete[] mStreamUsage;
}
#endif /* USE_LIBVORBIS */

View File

@ -87,7 +87,7 @@ class ImportRawDialog final : public wxDialogWrapper {
wxTextCtrl *mRateText;
int mNumEncodings;
int *mEncodingSubtype;
ArrayOf<int> mEncodingSubtype;
DECLARE_EVENT_TABLE()
};
@ -340,7 +340,7 @@ ImportRawDialog::ImportRawDialog(wxWindow * parent,
num = sf_num_encodings();
mNumEncodings = 0;
mEncodingSubtype = new int[num];
mEncodingSubtype.reinit(static_cast<size_t>(num));
selection = 0;
for (i=0; i<num; i++) {
@ -464,7 +464,6 @@ ImportRawDialog::ImportRawDialog(wxWindow * parent,
ImportRawDialog::~ImportRawDialog()
{
delete[] mEncodingSubtype;
}
void ImportRawDialog::OnOK(wxCommandEvent & WXUNUSED(event))

View File

@ -26,23 +26,14 @@ measurements in subbands or in the entire signal band.
SpecPowerMeter::SpecPowerMeter(size_t sigLen)
: mSigLen(sigLen)
, mSigI{ sigLen, true }
, mSigFR{ sigLen }
, mSigFI{ sigLen }
{
// Init buffers
mSigI = new float[sigLen];
mSigFR = new float[sigLen];
mSigFI = new float[sigLen];
for (int n = 0; n < sigLen; n++)
{
mSigI[n] = 0.0f;
}
}
SpecPowerMeter::~SpecPowerMeter()
{
delete[] mSigI;
delete[] mSigFR;
delete[] mSigFI;
}
float SpecPowerMeter::CalcPower(float* sig, float fc, float bw)
@ -59,10 +50,10 @@ float SpecPowerMeter::CalcPower(float* sig, float fc, float bw)
}
// Calc the FFT
FFT(mSigLen, 0, sig, mSigI, mSigFR, mSigFI);
FFT(mSigLen, 0, sig, mSigI.get(), mSigFR.get(), mSigFI.get());
// Calc the in-band power
pwr = CalcBinPower(mSigFR, mSigFI, loBin, hiBin);
pwr = CalcBinPower(mSigFR.get(), mSigFI.get(), loBin, hiBin);
return pwr;
}

View File

@ -12,14 +12,15 @@
#define __AUDACITY_SPECPOWERMETER_H_
#include <cstddef>
#include "../SampleFormat.h"
class SpecPowerMeter
{
const size_t mSigLen;
float* mSigI;
float* mSigFR;
float* mSigFI;
Floats mSigI;
Floats mSigFR;
Floats mSigFI;
float CalcBinPower(float* sig_f_r, float* sig_f_i, int loBin, int hiBin);
int Freq2Bin(float fc);