diff --git a/src/export/Export.cpp b/src/export/Export.cpp index af5b1d868..7d488a191 100644 --- a/src/export/Export.cpp +++ b/src/export/Export.cpp @@ -996,23 +996,20 @@ ExportMixerPanel::ExportMixerPanel( MixerSpec *mixerSpec, wxArrayString trackNames,wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size): wxPanelWrapper(parent, id, pos, size) + , mMixerSpec{mixerSpec} + , mChannelRects{ mMixerSpec->GetMaxNumChannels() } + , mTrackRects{ mMixerSpec->GetNumTracks() } { mBitmap = NULL; mWidth = 0; mHeight = 0; - mMixerSpec = mixerSpec; mSelectedTrack = mSelectedChannel = -1; - mTrackRects = new wxRect[ mMixerSpec->GetNumTracks() ]; - mChannelRects = new wxRect[ mMixerSpec->GetMaxNumChannels() ]; - mTrackNames = trackNames; } ExportMixerPanel::~ExportMixerPanel() { - delete[] mTrackRects; - delete[] mChannelRects; } //set the font on memDC such that text can fit in specified width and height diff --git a/src/export/Export.h b/src/export/Export.h index 2ff3a0c06..3100d9ebe 100644 --- a/src/export/Export.h +++ b/src/export/Export.h @@ -234,8 +234,8 @@ private: int mWidth; int mHeight; MixerSpec *mMixerSpec; - wxRect *mChannelRects; - wxRect *mTrackRects; + ArrayOf mChannelRects; + ArrayOf mTrackRects; int mSelectedTrack, mSelectedChannel; wxArrayString mTrackNames; int mBoxWidth, mChannelHeight, mTrackHeight; diff --git a/src/export/ExportFLAC.cpp b/src/export/ExportFLAC.cpp index 5ca032b0a..f3ad2397f 100644 --- a/src/export/ExportFLAC.cpp +++ b/src/export/ExportFLAC.cpp @@ -139,7 +139,7 @@ bool ExportFLACOptions::TransferDataFromWindow() // 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 ) */ #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, rate, format, true, mixerSpec); - int i; - FLAC__int32 **tmpsmplbuf = new FLAC__int32*[numChannels]; - for (i = 0; i < numChannels; i++) { - tmpsmplbuf[i] = (FLAC__int32 *) calloc(SAMPLES_PER_RUN, sizeof(FLAC__int32)); - } + ArraysOf tmpsmplbuf{ numChannels, SAMPLES_PER_RUN, true }; { ProgressDialog progress(wxFileName(fName).GetName(), @@ -329,7 +325,7 @@ ProgressResult ExportFLAC::Export(AudacityProject *project, break; } else { - for (i = 0; i < numChannels; i++) { + for (size_t i = 0; i < numChannels; i++) { samplePtr mixed = mixer->GetBuffer(i); if (format == int24Sample) { 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(tmpsmplbuf.get()), samplesThisRun); } updateResult = progress.Update(mixer->MixGetCurrentTime() - t0, t1 - t0); } @@ -350,12 +346,6 @@ ProgressResult ExportFLAC::Export(AudacityProject *project, encoder.finish(); } - for (i = 0; i < numChannels; i++) { - free(tmpsmplbuf[i]); - } - - delete[] tmpsmplbuf; - return updateResult; } diff --git a/src/export/ExportMP2.cpp b/src/export/ExportMP2.cpp index 690036458..0ab49220b 100644 --- a/src/export/ExportMP2.cpp +++ b/src/export/ExportMP2.cpp @@ -251,12 +251,12 @@ ProgressResult ExportMP2::Export(AudacityProject *project, // Values taken from the twolame simple encoder sample 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 // input buffer, which should always be enough. // We have to multiply by 4 because one sample is 2 bytes wide! - unsigned char* mp2Buffer = new unsigned char[mp2BufferSize]; + ArrayOf mp2Buffer{ mp2BufferSize }; const WaveTrackConstArray waveTracks = tracks->GetWaveTrackConstArray(selectionOnly, false); @@ -285,10 +285,10 @@ ProgressResult ExportMP2::Export(AudacityProject *project, encodeOptions, pcmBuffer, pcmNumSamples, - mp2Buffer, + mp2Buffer.get(), mp2BufferSize); - outFile.Write(mp2Buffer, mp2BufferNumBytes); + outFile.Write(mp2Buffer.get(), mp2BufferNumBytes); updateResult = progress.Update(mixer->MixGetCurrentTime() - t0, t1 - t0); } @@ -296,16 +296,14 @@ ProgressResult ExportMP2::Export(AudacityProject *project, int mp2BufferNumBytes = twolame_encode_flush( encodeOptions, - mp2Buffer, + mp2Buffer.get(), mp2BufferSize); if (mp2BufferNumBytes > 0) - outFile.Write(mp2Buffer, mp2BufferNumBytes); + outFile.Write(mp2Buffer.get(), mp2BufferNumBytes); twolame_close(&encodeOptions); - delete[] mp2Buffer; - /* Write ID3 tag if it was supposed to be at the end of the file */ if (id3len && endOfFile) diff --git a/src/export/ExportMP3.cpp b/src/export/ExportMP3.cpp index f5caecc51..a95d6f63e 100644 --- a/src/export/ExportMP3.cpp +++ b/src/export/ExportMP3.cpp @@ -1808,8 +1808,8 @@ ProgressResult ExportMP3::Export(AudacityProject *project, auto updateResult = ProgressResult::Success; long bytes; - int bufferSize = exporter.GetOutBufferSize(); - unsigned char *buffer = new unsigned char[bufferSize]; + size_t bufferSize = std::max(0, exporter.GetOutBufferSize()); + ArrayOf buffer{ bufferSize }; wxASSERT(buffer); const WaveTrackConstArray waveTracks = @@ -1854,18 +1854,18 @@ ProgressResult ExportMP3::Export(AudacityProject *project, if (blockLen < inSamples) { if (channels > 1) { - bytes = exporter.EncodeRemainder(mixed, blockLen, buffer); + bytes = exporter.EncodeRemainder(mixed, blockLen, buffer.get()); } else { - bytes = exporter.EncodeRemainderMono(mixed, blockLen, buffer); + bytes = exporter.EncodeRemainderMono(mixed, blockLen, buffer.get()); } } else { if (channels > 1) { - bytes = exporter.EncodeBuffer(mixed, buffer); + bytes = exporter.EncodeBuffer(mixed, buffer.get()); } else { - bytes = exporter.EncodeBufferMono(mixed, buffer); + bytes = exporter.EncodeBufferMono(mixed, buffer.get()); } } @@ -1876,16 +1876,16 @@ ProgressResult ExportMP3::Export(AudacityProject *project, break; } - outFile.Write(buffer, bytes); + outFile.Write(buffer.get(), bytes); updateResult = progress.Update(mixer->MixGetCurrentTime() - t0, t1 - t0); } } - bytes = exporter.FinishStream(buffer); + bytes = exporter.FinishStream(buffer.get()); 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 @@ -1908,8 +1908,6 @@ ProgressResult ExportMP3::Export(AudacityProject *project, // Close the file outFile.Close(); - delete [] buffer; - return updateResult; } diff --git a/src/export/ExportOGG.cpp b/src/export/ExportOGG.cpp index 0577ae311..f8859d02d 100644 --- a/src/export/ExportOGG.cpp +++ b/src/export/ExportOGG.cpp @@ -263,7 +263,7 @@ ProgressResult ExportOGG::Export(AudacityProject *project, } else { - for (int i = 0; i < numChannels; i++) { + for (size_t i = 0; i < numChannels; i++) { float *temp = (float *)mixer->GetBuffer(i); memcpy(vorbis_buffer[i], temp, sizeof(float)*SAMPLES_PER_RUN); }