1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-10 09:01:13 +02:00

Remove naked new[] in: export

This commit is contained in:
Paul Licameli 2016-04-14 11:56:09 -04:00
parent ea05fac870
commit 9bdc7b2cbf
6 changed files with 25 additions and 42 deletions

View File

@ -996,23 +996,20 @@ ExportMixerPanel::ExportMixerPanel( MixerSpec *mixerSpec,
wxArrayString trackNames,wxWindow *parent, wxWindowID id, wxArrayString trackNames,wxWindow *parent, wxWindowID id,
const wxPoint& pos, const wxSize& size): const wxPoint& pos, const wxSize& size):
wxPanelWrapper(parent, id, pos, size) wxPanelWrapper(parent, id, pos, size)
, mMixerSpec{mixerSpec}
, mChannelRects{ mMixerSpec->GetMaxNumChannels() }
, mTrackRects{ mMixerSpec->GetNumTracks() }
{ {
mBitmap = NULL; mBitmap = NULL;
mWidth = 0; mWidth = 0;
mHeight = 0; mHeight = 0;
mMixerSpec = mixerSpec;
mSelectedTrack = mSelectedChannel = -1; mSelectedTrack = mSelectedChannel = -1;
mTrackRects = new wxRect[ mMixerSpec->GetNumTracks() ];
mChannelRects = new wxRect[ mMixerSpec->GetMaxNumChannels() ];
mTrackNames = trackNames; mTrackNames = trackNames;
} }
ExportMixerPanel::~ExportMixerPanel() ExportMixerPanel::~ExportMixerPanel()
{ {
delete[] mTrackRects;
delete[] mChannelRects;
} }
//set the font on memDC such that text can fit in specified width and height //set the font on memDC such that text can fit in specified width and height

View File

@ -234,8 +234,8 @@ private:
int mWidth; int mWidth;
int mHeight; int mHeight;
MixerSpec *mMixerSpec; MixerSpec *mMixerSpec;
wxRect *mChannelRects; ArrayOf<wxRect> mChannelRects;
wxRect *mTrackRects; ArrayOf<wxRect> mTrackRects;
int mSelectedTrack, mSelectedChannel; int mSelectedTrack, mSelectedChannel;
wxArrayString mTrackNames; wxArrayString mTrackNames;
int mBoxWidth, mChannelHeight, mTrackHeight; int mBoxWidth, mChannelHeight, mTrackHeight;

View File

@ -139,7 +139,7 @@ bool ExportFLACOptions::TransferDataFromWindow()
// ExportFLAC Class // ExportFLAC Class
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
#define SAMPLES_PER_RUN 8192 #define SAMPLES_PER_RUN 8192u
/* FLACPP_API_VERSION_CURRENT is 6 for libFLAC++ from flac-1.1.3 (see <FLAC++/export.h>) */ /* FLACPP_API_VERSION_CURRENT is 6 for libFLAC++ from flac-1.1.3 (see <FLAC++/export.h>) */
#if !defined FLACPP_API_VERSION_CURRENT || FLACPP_API_VERSION_CURRENT < 6 #if !defined FLACPP_API_VERSION_CURRENT || FLACPP_API_VERSION_CURRENT < 6
@ -311,11 +311,7 @@ ProgressResult ExportFLAC::Export(AudacityProject *project,
numChannels, SAMPLES_PER_RUN, false, numChannels, SAMPLES_PER_RUN, false,
rate, format, true, mixerSpec); rate, format, true, mixerSpec);
int i; ArraysOf<FLAC__int32> tmpsmplbuf{ numChannels, SAMPLES_PER_RUN, true };
FLAC__int32 **tmpsmplbuf = new FLAC__int32*[numChannels];
for (i = 0; i < numChannels; i++) {
tmpsmplbuf[i] = (FLAC__int32 *) calloc(SAMPLES_PER_RUN, sizeof(FLAC__int32));
}
{ {
ProgressDialog progress(wxFileName(fName).GetName(), ProgressDialog progress(wxFileName(fName).GetName(),
@ -329,7 +325,7 @@ ProgressResult ExportFLAC::Export(AudacityProject *project,
break; break;
} }
else { else {
for (i = 0; i < numChannels; i++) { for (size_t i = 0; i < numChannels; i++) {
samplePtr mixed = mixer->GetBuffer(i); samplePtr mixed = mixer->GetBuffer(i);
if (format == int24Sample) { if (format == int24Sample) {
for (decltype(samplesThisRun) j = 0; j < samplesThisRun; j++) { for (decltype(samplesThisRun) j = 0; j < samplesThisRun; j++) {
@ -342,7 +338,7 @@ ProgressResult ExportFLAC::Export(AudacityProject *project,
} }
} }
} }
encoder.process(tmpsmplbuf, samplesThisRun); encoder.process(reinterpret_cast<const FLAC__int32**>(tmpsmplbuf.get()), samplesThisRun);
} }
updateResult = progress.Update(mixer->MixGetCurrentTime() - t0, t1 - t0); updateResult = progress.Update(mixer->MixGetCurrentTime() - t0, t1 - t0);
} }
@ -350,12 +346,6 @@ ProgressResult ExportFLAC::Export(AudacityProject *project,
encoder.finish(); encoder.finish();
} }
for (i = 0; i < numChannels; i++) {
free(tmpsmplbuf[i]);
}
delete[] tmpsmplbuf;
return updateResult; return updateResult;
} }

View File

@ -251,12 +251,12 @@ ProgressResult ExportMP2::Export(AudacityProject *project,
// Values taken from the twolame simple encoder sample // Values taken from the twolame simple encoder sample
const int pcmBufferSize = 9216 / 2; // number of samples const int pcmBufferSize = 9216 / 2; // number of samples
const int mp2BufferSize = 16384; // bytes const size_t mp2BufferSize = 16384u; // bytes
// We allocate a buffer which is twice as big as the // We allocate a buffer which is twice as big as the
// input buffer, which should always be enough. // input buffer, which should always be enough.
// We have to multiply by 4 because one sample is 2 bytes wide! // We have to multiply by 4 because one sample is 2 bytes wide!
unsigned char* mp2Buffer = new unsigned char[mp2BufferSize]; ArrayOf<unsigned char> mp2Buffer{ mp2BufferSize };
const WaveTrackConstArray waveTracks = const WaveTrackConstArray waveTracks =
tracks->GetWaveTrackConstArray(selectionOnly, false); tracks->GetWaveTrackConstArray(selectionOnly, false);
@ -285,10 +285,10 @@ ProgressResult ExportMP2::Export(AudacityProject *project,
encodeOptions, encodeOptions,
pcmBuffer, pcmBuffer,
pcmNumSamples, pcmNumSamples,
mp2Buffer, mp2Buffer.get(),
mp2BufferSize); mp2BufferSize);
outFile.Write(mp2Buffer, mp2BufferNumBytes); outFile.Write(mp2Buffer.get(), mp2BufferNumBytes);
updateResult = progress.Update(mixer->MixGetCurrentTime() - t0, t1 - t0); updateResult = progress.Update(mixer->MixGetCurrentTime() - t0, t1 - t0);
} }
@ -296,16 +296,14 @@ ProgressResult ExportMP2::Export(AudacityProject *project,
int mp2BufferNumBytes = twolame_encode_flush( int mp2BufferNumBytes = twolame_encode_flush(
encodeOptions, encodeOptions,
mp2Buffer, mp2Buffer.get(),
mp2BufferSize); mp2BufferSize);
if (mp2BufferNumBytes > 0) if (mp2BufferNumBytes > 0)
outFile.Write(mp2Buffer, mp2BufferNumBytes); outFile.Write(mp2Buffer.get(), mp2BufferNumBytes);
twolame_close(&encodeOptions); twolame_close(&encodeOptions);
delete[] mp2Buffer;
/* Write ID3 tag if it was supposed to be at the end of the file */ /* Write ID3 tag if it was supposed to be at the end of the file */
if (id3len && endOfFile) if (id3len && endOfFile)

View File

@ -1808,8 +1808,8 @@ ProgressResult ExportMP3::Export(AudacityProject *project,
auto updateResult = ProgressResult::Success; auto updateResult = ProgressResult::Success;
long bytes; long bytes;
int bufferSize = exporter.GetOutBufferSize(); size_t bufferSize = std::max(0, exporter.GetOutBufferSize());
unsigned char *buffer = new unsigned char[bufferSize]; ArrayOf<unsigned char> buffer{ bufferSize };
wxASSERT(buffer); wxASSERT(buffer);
const WaveTrackConstArray waveTracks = const WaveTrackConstArray waveTracks =
@ -1854,18 +1854,18 @@ ProgressResult ExportMP3::Export(AudacityProject *project,
if (blockLen < inSamples) { if (blockLen < inSamples) {
if (channels > 1) { if (channels > 1) {
bytes = exporter.EncodeRemainder(mixed, blockLen, buffer); bytes = exporter.EncodeRemainder(mixed, blockLen, buffer.get());
} }
else { else {
bytes = exporter.EncodeRemainderMono(mixed, blockLen, buffer); bytes = exporter.EncodeRemainderMono(mixed, blockLen, buffer.get());
} }
} }
else { else {
if (channels > 1) { if (channels > 1) {
bytes = exporter.EncodeBuffer(mixed, buffer); bytes = exporter.EncodeBuffer(mixed, buffer.get());
} }
else { else {
bytes = exporter.EncodeBufferMono(mixed, buffer); bytes = exporter.EncodeBufferMono(mixed, buffer.get());
} }
} }
@ -1876,16 +1876,16 @@ ProgressResult ExportMP3::Export(AudacityProject *project,
break; break;
} }
outFile.Write(buffer, bytes); outFile.Write(buffer.get(), bytes);
updateResult = progress.Update(mixer->MixGetCurrentTime() - t0, t1 - t0); updateResult = progress.Update(mixer->MixGetCurrentTime() - t0, t1 - t0);
} }
} }
bytes = exporter.FinishStream(buffer); bytes = exporter.FinishStream(buffer.get());
if (bytes) { if (bytes) {
outFile.Write(buffer, bytes); outFile.Write(buffer.get(), bytes);
} }
// Write ID3 tag if it was supposed to be at the end of the file // Write ID3 tag if it was supposed to be at the end of the file
@ -1908,8 +1908,6 @@ ProgressResult ExportMP3::Export(AudacityProject *project,
// Close the file // Close the file
outFile.Close(); outFile.Close();
delete [] buffer;
return updateResult; return updateResult;
} }

View File

@ -263,7 +263,7 @@ ProgressResult ExportOGG::Export(AudacityProject *project,
} }
else { else {
for (int i = 0; i < numChannels; i++) { for (size_t i = 0; i < numChannels; i++) {
float *temp = (float *)mixer->GetBuffer(i); float *temp = (float *)mixer->GetBuffer(i);
memcpy(vorbis_buffer[i], temp, sizeof(float)*SAMPLES_PER_RUN); memcpy(vorbis_buffer[i], temp, sizeof(float)*SAMPLES_PER_RUN);
} }