diff --git a/src/export/Export.cpp b/src/export/Export.cpp index 98bc88bcf..92cdc69f9 100644 --- a/src/export/Export.cpp +++ b/src/export/Export.cpp @@ -237,7 +237,7 @@ wxWindow *ExportPlugin::OptionsCreate(wxWindow *parent, int WXUNUSED(format)) } //Create a mixer by computing the time warp factor -Mixer* ExportPlugin::CreateMixer(const WaveTrackConstArray &inputTracks, +std::unique_ptr ExportPlugin::CreateMixer(const WaveTrackConstArray &inputTracks, const TimeTrack *timeTrack, double startTime, double stopTime, int numOutChannels, int outBufferSize, bool outInterleaved, @@ -245,7 +245,7 @@ Mixer* ExportPlugin::CreateMixer(const WaveTrackConstArray &inputTracks, bool highQuality, MixerSpec *mixerSpec) { // MB: the stop time should not be warped, this was a bug. - return new Mixer(inputTracks, + return std::make_unique(inputTracks, Mixer::WarpOptions(timeTrack), startTime, stopTime, numOutChannels, outBufferSize, outInterleaved, diff --git a/src/export/Export.h b/src/export/Export.h index 02150580c..3244366ee 100644 --- a/src/export/Export.h +++ b/src/export/Export.h @@ -116,7 +116,7 @@ public: int subformat = 0) = 0; protected: - Mixer* CreateMixer(const WaveTrackConstArray &inputTracks, + std::unique_ptr CreateMixer(const WaveTrackConstArray &inputTracks, const TimeTrack *timeTrack, double startTime, double stopTime, int numOutChannels, int outBufferSize, bool outInterleaved, diff --git a/src/export/ExportCL.cpp b/src/export/ExportCL.cpp index eb95fd011..77b99d2ed 100644 --- a/src/export/ExportCL.cpp +++ b/src/export/ExportCL.cpp @@ -416,7 +416,7 @@ int ExportCL::Export(AudacityProject *project, const TrackList *tracks = project->GetTracks(); const WaveTrackConstArray waveTracks = tracks->GetWaveTrackConstArray(selectionOnly, false); - Mixer *mixer = CreateMixer( + auto mixer = CreateMixer( waveTracks, tracks->GetTimeTrack(), t0, @@ -520,9 +520,6 @@ int ExportCL::Export(AudacityProject *project, dlg.ShowModal(); } - // Clean up - delete mixer; - return updateResult; } diff --git a/src/export/ExportFFmpeg.cpp b/src/export/ExportFFmpeg.cpp index 49cd4625e..0cd942cf0 100644 --- a/src/export/ExportFFmpeg.cpp +++ b/src/export/ExportFFmpeg.cpp @@ -831,7 +831,7 @@ int ExportFFmpeg::Export(AudacityProject *project, int pcmBufferSize = 1024; const WaveTrackConstArray waveTracks = tracks->GetWaveTrackConstArray(selectionOnly, false); - Mixer *mixer = CreateMixer(waveTracks, + auto mixer = CreateMixer(waveTracks, tracks->GetTimeTrack(), t0, t1, channels, pcmBufferSize, true, @@ -858,8 +858,6 @@ int ExportFFmpeg::Export(AudacityProject *project, } } - delete mixer; - Finalize(); return updateResult; diff --git a/src/export/ExportFLAC.cpp b/src/export/ExportFLAC.cpp index 266e47f7b..980f6d135 100644 --- a/src/export/ExportFLAC.cpp +++ b/src/export/ExportFLAC.cpp @@ -305,7 +305,7 @@ int ExportFLAC::Export(AudacityProject *project, const WaveTrackConstArray waveTracks = tracks->GetWaveTrackConstArray(selectionOnly, false); - Mixer *mixer = CreateMixer(waveTracks, + auto mixer = CreateMixer(waveTracks, tracks->GetTimeTrack(), t0, t1, numChannels, SAMPLES_PER_RUN, false, @@ -353,7 +353,6 @@ int ExportFLAC::Export(AudacityProject *project, for (i = 0; i < numChannels; i++) { free(tmpsmplbuf[i]); } - delete mixer; delete[] tmpsmplbuf; diff --git a/src/export/ExportMP2.cpp b/src/export/ExportMP2.cpp index 37a8c1dfd..47230f9d8 100644 --- a/src/export/ExportMP2.cpp +++ b/src/export/ExportMP2.cpp @@ -204,9 +204,9 @@ ExportMP2::ExportMP2() } int ExportMP2::Export(AudacityProject *project, - int channels, const wxString &fName, - bool selectionOnly, double t0, double t1, MixerSpec *mixerSpec, const Tags *metadata, - int WXUNUSED(subformat)) + int channels, const wxString &fName, + bool selectionOnly, double t0, double t1, MixerSpec *mixerSpec, const Tags *metadata, + int WXUNUSED(subformat)) { bool stereo = (channels == 2); long bitrate = gPrefs->Read(wxT("/FileFormats/MP2Bitrate"), 160); @@ -221,7 +221,7 @@ int ExportMP2::Export(AudacityProject *project, twolame_set_in_samplerate(encodeOptions, (int)(rate + 0.5)); twolame_set_out_samplerate(encodeOptions, (int)(rate + 0.5)); twolame_set_bitrate(encodeOptions, bitrate); - twolame_set_num_channels(encodeOptions, stereo ? 2:1); + twolame_set_num_channels(encodeOptions, stereo ? 2 : 1); if (twolame_init_params(encodeOptions) != 0) { @@ -247,11 +247,11 @@ int ExportMP2::Export(AudacityProject *project, bool endOfFile; id3len = AddTags(project, &id3buffer, &endOfFile, metadata); if (id3len && !endOfFile) - outFile.Write(id3buffer, id3len); + outFile.Write(id3buffer, id3len); // Values taken from the twolame simple encoder sample const int pcmBufferSize = 9216 / 2; // number of samples - const int mp2BufferSize = 16384 ; // bytes + const int mp2BufferSize = 16384; // bytes // We allocate a buffer which is twice as big as the // input buffer, which should always be enough. @@ -260,14 +260,14 @@ int ExportMP2::Export(AudacityProject *project, const WaveTrackConstArray waveTracks = tracks->GetWaveTrackConstArray(selectionOnly, false); - Mixer *mixer = CreateMixer(waveTracks, - tracks->GetTimeTrack(), - t0, t1, - stereo? 2: 1, pcmBufferSize, true, - rate, int16Sample, true, mixerSpec); - int updateResult = eProgressSuccess; { + auto mixer = CreateMixer(waveTracks, + tracks->GetTimeTrack(), + t0, t1, + stereo ? 2 : 1, pcmBufferSize, true, + rate, int16Sample, true, mixerSpec); + ProgressDialog progress(wxFileName(fName).GetName(), selectionOnly ? wxString::Format(_("Exporting selected audio at %ld kbps"), bitrate) : @@ -294,8 +294,6 @@ int ExportMP2::Export(AudacityProject *project, } } - delete mixer; - int mp2BufferNumBytes = twolame_encode_flush( encodeOptions, mp2Buffer, diff --git a/src/export/ExportMP3.cpp b/src/export/ExportMP3.cpp index f353293f7..da32274fb 100644 --- a/src/export/ExportMP3.cpp +++ b/src/export/ExportMP3.cpp @@ -1788,33 +1788,33 @@ int ExportMP3::Export(AudacityProject *project, const WaveTrackConstArray waveTracks = tracks->GetWaveTrackConstArray(selectionOnly, false); - Mixer *mixer = CreateMixer(waveTracks, - tracks->GetTimeTrack(), - t0, t1, - channels, inSamples, true, - rate, int16Sample, true, mixerSpec); - - wxString title; - if (rmode == MODE_SET) { - title.Printf(selectionOnly ? - _("Exporting selected audio with %s preset") : - _("Exporting entire file with %s preset"), - FindName(setRates, WXSIZEOF(setRates), brate).c_str()); - } - else if (rmode == MODE_VBR) { - title.Printf(selectionOnly ? - _("Exporting selected audio with VBR quality %s") : - _("Exporting entire file with VBR quality %s"), - FindName(varRates, WXSIZEOF(varRates), brate).c_str()); - } - else { - title.Printf(selectionOnly ? - _("Exporting selected audio at %d Kbps") : - _("Exporting entire file at %d Kbps"), - brate); - } - { + auto mixer = CreateMixer(waveTracks, + tracks->GetTimeTrack(), + t0, t1, + channels, inSamples, true, + rate, int16Sample, true, mixerSpec); + + wxString title; + if (rmode == MODE_SET) { + title.Printf(selectionOnly ? + _("Exporting selected audio with %s preset") : + _("Exporting entire file with %s preset"), + FindName(setRates, WXSIZEOF(setRates), brate).c_str()); + } + else if (rmode == MODE_VBR) { + title.Printf(selectionOnly ? + _("Exporting selected audio with VBR quality %s") : + _("Exporting entire file with VBR quality %s"), + FindName(varRates, WXSIZEOF(varRates), brate).c_str()); + } + else { + title.Printf(selectionOnly ? + _("Exporting selected audio at %d Kbps") : + _("Exporting entire file at %d Kbps"), + brate); + } + ProgressDialog progress(wxFileName(fName).GetName(), title); while (updateResult == eProgressSuccess) { @@ -1856,8 +1856,6 @@ int ExportMP3::Export(AudacityProject *project, } } - delete mixer; - bytes = exporter.FinishStream(buffer); if (bytes) { diff --git a/src/export/ExportOGG.cpp b/src/export/ExportOGG.cpp index 01078c5a0..8a7bf5c72 100644 --- a/src/export/ExportOGG.cpp +++ b/src/export/ExportOGG.cpp @@ -241,13 +241,13 @@ int ExportOGG::Export(AudacityProject *project, const WaveTrackConstArray waveTracks = tracks->GetWaveTrackConstArray(selectionOnly, false); - Mixer *mixer = CreateMixer(waveTracks, - tracks->GetTimeTrack(), - t0, t1, - numChannels, SAMPLES_PER_RUN, false, - rate, floatSample, true, mixerSpec); - { + auto mixer = CreateMixer(waveTracks, + tracks->GetTimeTrack(), + t0, t1, + numChannels, SAMPLES_PER_RUN, false, + rate, floatSample, true, mixerSpec); + ProgressDialog progress(wxFileName(fName).GetName(), selectionOnly ? _("Exporting the selected audio as Ogg Vorbis") : @@ -313,8 +313,6 @@ int ExportOGG::Export(AudacityProject *project, } } - delete mixer; - ogg_stream_clear(&stream); vorbis_block_clear(&block); diff --git a/src/export/ExportPCM.cpp b/src/export/ExportPCM.cpp index 2780f47b5..eeed30405 100644 --- a/src/export/ExportPCM.cpp +++ b/src/export/ExportPCM.cpp @@ -480,13 +480,13 @@ int ExportPCM::Export(AudacityProject *project, const WaveTrackConstArray waveTracks = tracks->GetWaveTrackConstArray(selectionOnly, false); - Mixer *mixer = CreateMixer(waveTracks, - tracks->GetTimeTrack(), - t0, t1, - info.channels, maxBlockLen, true, - rate, format, true, mixerSpec); - { + auto mixer = CreateMixer(waveTracks, + tracks->GetTimeTrack(), + t0, t1, + info.channels, maxBlockLen, true, + rate, format, true, mixerSpec); + ProgressDialog progress(wxFileName(fName).GetName(), selectionOnly ? wxString::Format(_("Exporting the selected audio as %s"), @@ -515,11 +515,11 @@ int ExportPCM::Export(AudacityProject *project, sf_error_str(sf, buffer2, 1000); wxMessageBox(wxString::Format( /* i18n-hint: %s will be the error message from libsndfile, which - * is usually something unhelpful (and untranslated) like "system - * error" */ - _("Error while writing %s file (disk full?).\nLibsndfile says \"%s\""), - formatStr.c_str(), - wxString::FromAscii(buffer2).c_str())); + * is usually something unhelpful (and untranslated) like "system + * error" */ + _("Error while writing %s file (disk full?).\nLibsndfile says \"%s\""), + formatStr.c_str(), + wxString::FromAscii(buffer2).c_str())); break; } @@ -527,8 +527,6 @@ int ExportPCM::Export(AudacityProject *project, } } - delete mixer; - // Install the WAV metata in a "LIST" chunk at the end of the file if ((sf_format & SF_FORMAT_TYPEMASK) == SF_FORMAT_WAV || (sf_format & SF_FORMAT_TYPEMASK) == SF_FORMAT_WAVEX) {