From 30dc9ccc863caa754fb2c15c9822a5c3570d17a2 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sat, 19 Oct 2024 00:22:21 +0200 Subject: [PATCH] Replace boost::scoped_array --- libs/ardour/ardour/audiosource.h | 3 +-- libs/ardour/ardour/export_channel.h | 8 +++--- libs/ardour/audio_playlist_source.cc | 4 +-- libs/ardour/audio_track.cc | 6 ++--- libs/ardour/audioregion.cc | 12 ++++----- libs/ardour/audiosource.cc | 25 +++++++++---------- libs/ardour/disk_reader.cc | 21 ++++++++-------- libs/ardour/import.cc | 3 +-- .../portaudio/winmmemidi_input_device.h | 3 +-- libs/waveview/wave_view.cc | 6 ++--- 10 files changed, 40 insertions(+), 51 deletions(-) diff --git a/libs/ardour/ardour/audiosource.h b/libs/ardour/ardour/audiosource.h index a92b00fc47..bf6472a81e 100644 --- a/libs/ardour/ardour/audiosource.h +++ b/libs/ardour/ardour/audiosource.h @@ -30,7 +30,6 @@ #include #include -#include #include "ardour/source.h" #include "ardour/ardour.h" @@ -156,7 +155,7 @@ class LIBARDOUR_API AudioSource : virtual public Source, public ARDOUR::AudioRea mutable double _last_scale; mutable off_t _last_map_off; mutable size_t _last_raw_map_length; - mutable boost::scoped_array peak_cache; + mutable std::unique_ptr peak_cache; }; } diff --git a/libs/ardour/ardour/export_channel.h b/libs/ardour/ardour/export_channel.h index e7188e72c8..6867c480ab 100644 --- a/libs/ardour/ardour/export_channel.h +++ b/libs/ardour/ardour/export_channel.h @@ -26,8 +26,6 @@ #include #include -#include - #include "pbd/ringbuffer.h" #include "pbd/signals.h" @@ -103,7 +101,7 @@ public: private: PortSet ports; samplecnt_t _buffer_size; - boost::scoped_array _buffer; + std::unique_ptr _buffer; mutable AudioBuffer _buf; std::list>> _delaylines; }; @@ -182,8 +180,8 @@ private: samplepos_t region_start; samplepos_t position; - boost::scoped_array mixdown_buffer; - boost::scoped_array gain_buffer; + std::unique_ptr mixdown_buffer; + std::unique_ptr gain_buffer; PBD::ScopedConnection export_connection; }; diff --git a/libs/ardour/audio_playlist_source.cc b/libs/ardour/audio_playlist_source.cc index e832dd2db3..caf97f6d32 100644 --- a/libs/ardour/audio_playlist_source.cc +++ b/libs/ardour/audio_playlist_source.cc @@ -138,8 +138,8 @@ AudioPlaylistSource::read_unlocked (Sample* dst, samplepos_t start, samplecnt_t to_zero = 0; } - boost::scoped_array sbuf(new float[to_read]); - boost::scoped_array gbuf(new gain_t[to_read]); + std::unique_ptr sbuf(new float[to_read]); + std::unique_ptr gbuf(new gain_t[to_read]); std::dynamic_pointer_cast(_playlist)->read (dst, sbuf.get(), gbuf.get(), timepos_t (start)+_playlist_offset, timecnt_t (to_read), _playlist_channel); diff --git a/libs/ardour/audio_track.cc b/libs/ardour/audio_track.cc index 6fb2036522..baa1b9ccb3 100644 --- a/libs/ardour/audio_track.cc +++ b/libs/ardour/audio_track.cc @@ -23,8 +23,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include - #include "pbd/enumwriter.h" #include "pbd/error.h" @@ -209,8 +207,8 @@ AudioTrack::export_stuff (BufferSet& buffers, samplepos_t start, samplecnt_t nfr std::shared_ptr endpoint, bool include_endpoint, bool for_export, bool for_freeze, MidiNoteTracker& /* ignored, this is audio */) { - boost::scoped_array gain_buffer (new gain_t[nframes]); - boost::scoped_array mix_buffer (new Sample[nframes]); + std::unique_ptr gain_buffer (new gain_t[nframes]); + std::unique_ptr mix_buffer (new Sample[nframes]); Glib::Threads::RWLock::ReaderLock rlock (_processor_lock); diff --git a/libs/ardour/audioregion.cc b/libs/ardour/audioregion.cc index 4a7e74432e..bbbad9a443 100644 --- a/libs/ardour/audioregion.cc +++ b/libs/ardour/audioregion.cc @@ -29,8 +29,6 @@ #include #include -#include - #include #include @@ -731,8 +729,8 @@ AudioRegion::read_at (Sample* buf, _cache_tail = 0; } - boost::scoped_array gain_array; - boost::scoped_array mixdown_array; + std::unique_ptr gain_array; + std::unique_ptr mixdown_array; bool nofx = false; // apply region fades at the end @@ -2258,9 +2256,9 @@ AudioRegion::get_transients (AnalysisFeatureList& results) AudioIntervalResult AudioRegion::find_silence (Sample threshold, samplecnt_t min_length, samplecnt_t fade_length, InterThreadInfo& itt) const { - samplecnt_t const block_size = 64 * 1024; - boost::scoped_array loudest (new Sample[block_size]); - boost::scoped_array buf (new Sample[block_size]); + constexpr samplecnt_t block_size = 64 * 1024; + std::unique_ptr loudest (new Sample[block_size]); + std::unique_ptr buf (new Sample[block_size]); assert (fade_length >= 0); assert (min_length > 0); diff --git a/libs/ardour/audiosource.cc b/libs/ardour/audiosource.cc index e65b2eecac..8441a9385a 100644 --- a/libs/ardour/audiosource.cc +++ b/libs/ardour/audiosource.cc @@ -359,7 +359,7 @@ AudioSource::read_peaks_with_fpp (PeakData *peaks, samplecnt_t npeaks, samplepos samplecnt_t peak = 0; #if 1 // direct read - boost::scoped_array buf(new Sample[scm]); + std::unique_ptr buf(new Sample[scm]); while (peak < npeaks && cnt > 0) { samplecnt_t samples_read = read_unlocked (buf.get(), start, scm); if (samples_read == 0) { @@ -478,7 +478,7 @@ AudioSource::read_peaks_with_fpp (PeakData *peaks, samplecnt_t npeaks, samplepos both max and min peak values. */ - boost::scoped_array raw_staging(new Sample[cnt]); + std::unique_ptr raw_staging(new Sample[cnt]); if (read_unlocked (raw_staging.get(), start, cnt) != cnt) { error << _("cannot read sample data for unscaled peak computation") << endmsg; @@ -606,7 +606,7 @@ AudioSource::read_peaks_with_fpp (PeakData *peaks, samplecnt_t npeaks, samplepos samplecnt_t start_offset = next_visual_peak_sample - start; peak_cache.reset (new PeakData[npeaks]); - boost::scoped_array staging (new PeakData[chunksize]); + std::unique_ptr staging (new PeakData[chunksize]); char* addr; #ifdef PLATFORM_WINDOWS @@ -669,7 +669,7 @@ AudioSource::read_peaks_with_fpp (PeakData *peaks, samplecnt_t npeaks, samplepos /* add data between start and sample corresponding to map_off */ if (start_offset > 0) { - boost::scoped_array buf(new Sample[start_offset]); + std::unique_ptr buf (new Sample[start_offset]); samplecnt_t samples_read = read_unlocked (buf.get(), start, start_offset); find_peaks (buf.get(), samples_read, &peak_cache[0].min, &peak_cache[0].max); } @@ -678,7 +678,7 @@ AudioSource::read_peaks_with_fpp (PeakData *peaks, samplecnt_t npeaks, samplepos samplecnt_t last_sample_from_peakfile = current_stored_peak * samples_per_file_peak; if (last_sample_from_peakfile < start + cnt && nvisual_peaks > 0) { samplecnt_t to_read = start + cnt - last_sample_from_peakfile; - boost::scoped_array buf(new Sample[to_read]); + std::unique_ptr buf (new Sample[to_read]); samplecnt_t samples_read = read_unlocked (buf.get(), last_sample_from_peakfile, to_read); find_peaks (buf.get(), samples_read, &peak_cache[nvisual_peaks - 1].min, &peak_cache[nvisual_peaks - 1].max); } @@ -715,7 +715,7 @@ AudioSource::read_peaks_with_fpp (PeakData *peaks, samplecnt_t npeaks, samplepos samplecnt_t i = 0; samplecnt_t nvisual_peaks = 0; samplecnt_t chunksize = (samplecnt_t) min (cnt, (samplecnt_t) 4096); - boost::scoped_array raw_staging(new Sample[chunksize]); + std::unique_ptr raw_staging(new Sample[chunksize]); double pixel_pos = start / samples_per_visual_peak; double next_pixel_pos = 1.0 + floor (pixel_pos); @@ -787,7 +787,7 @@ AudioSource::read_peaks_with_fpp (PeakData *peaks, samplecnt_t npeaks, samplepos int AudioSource::build_peaks_from_scratch () { - const samplecnt_t bufsize = 65536; // 256kB per disk read for mono data is about ideal + constexpr samplecnt_t bufsize = 65536; // 256kB per disk read for mono data is about ideal DEBUG_TRACE (DEBUG::Peaks, "Building peaks from scratch\n"); @@ -806,14 +806,14 @@ AudioSource::build_peaks_from_scratch () samplecnt_t cnt = _length.samples(); _peaks_built = false; - boost::scoped_array buf(new Sample[bufsize]); + std::array buf; while (cnt) { samplecnt_t samples_to_read = min (bufsize, cnt); samplecnt_t samples_read; - if ((samples_read = read_unlocked (buf.get(), current_sample, samples_to_read)) != samples_to_read) { + if ((samples_read = read_unlocked (buf.data(), current_sample, samples_to_read)) != samples_to_read) { error << string_compose(_("%1: could not write read raw data for peak computation (%2)"), _name, strerror (errno)) << endmsg; done_with_peakfile_writes (false); goto out; @@ -828,7 +828,7 @@ AudioSource::build_peaks_from_scratch () goto out; } - if (compute_and_write_peaks (buf.get(), current_sample, samples_read, true, false, _FPP)) { + if (compute_and_write_peaks (buf.data(), current_sample, samples_read, true, false, _FPP)) { break; } @@ -934,7 +934,6 @@ AudioSource::compute_and_write_peaks (Sample const * buf, samplecnt_t first_samp samplecnt_t samples_done; const size_t blocksize = (128 * 1024); off_t first_peak_byte; - boost::scoped_array buf2; if (-1 == _peakfile_fd) { if (prepare_for_peakfile_writes ()) { @@ -994,7 +993,7 @@ AudioSource::compute_and_write_peaks (Sample const * buf, samplecnt_t first_samp /* make a new contiguous buffer containing leftovers and the new stuff */ to_do = cnt + peak_leftover_cnt; - buf2.reset(new Sample[to_do]); + std::unique_ptr buf2(new Sample[to_do]); /* the remnants */ memcpy (buf2.get(), peak_leftovers, peak_leftover_cnt * sizeof (Sample)); @@ -1018,7 +1017,7 @@ AudioSource::compute_and_write_peaks (Sample const * buf, samplecnt_t first_samp to_do = cnt; } - boost::scoped_array peakbuf(new PeakData[(to_do/fpp)+1]); + std::unique_ptr peakbuf(new PeakData[(to_do/fpp)+1]); peaks_computed = 0; current_sample = first_sample; samples_done = 0; diff --git a/libs/ardour/disk_reader.cc b/libs/ardour/disk_reader.cc index f04ee305f5..f5c525fad2 100644 --- a/libs/ardour/disk_reader.cc +++ b/libs/ardour/disk_reader.cc @@ -17,8 +17,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include - #include "pbd/enumwriter.h" #include "pbd/memento_command.h" #include "pbd/playback_buffer.h" @@ -723,9 +721,9 @@ DiskReader::overwrite_existing_audio () chunk2_cnt = to_overwrite - chunk1_cnt; } - boost::scoped_array sum_buffer (new Sample[to_overwrite]); - boost::scoped_array mixdown_buffer (new Sample[to_overwrite]); - boost::scoped_array gain_buffer (new float[to_overwrite]); + std::unique_ptr sum_buffer (new Sample[to_overwrite]); + std::unique_ptr mixdown_buffer (new Sample[to_overwrite]); + std::unique_ptr gain_buffer (new float[to_overwrite]); uint32_t n = 0; bool ret = true; samplepos_t start = overwrite_sample; @@ -1136,11 +1134,14 @@ DiskReader::do_refill_with_alloc (bool partial_fill, bool reversed) * samples would be 1M samples. But we might use 16 or 14 bit samples, * in which case 4MB is more samples than that. Therefore size this for * the smallest sample value .. 4MB = 2M samples (16 bit). + * + * Note, we cannot use std::array<> here since stack-size is limited. */ - boost::scoped_array sum_buf (new Sample[2 * 1048576]); - boost::scoped_array mix_buf (new Sample[2 * 1048576]); - boost::scoped_array gain_buf (new float[2 * 1048576]); + constexpr size_t chunksize = 2 * 1048576; + std::unique_ptr sum_buf (new Sample[chunksize]); + std::unique_ptr mix_buf (new Sample[chunksize]); + std::unique_ptr gain_buf (new float[chunksize]); return refill_audio (sum_buf.get (), mix_buf.get (), gain_buf.get (), (partial_fill ? _chunk_samples : 0), reversed); } @@ -1993,8 +1994,8 @@ DiskReader::setup_preloop_buffer () } Location* loc = _loop_location; - boost::scoped_array mix_buf (new Sample[loop_fade_length]); - boost::scoped_array gain_buf (new Sample[loop_fade_length]); + std::unique_ptr mix_buf (new Sample[loop_fade_length]); + std::unique_ptr gain_buf (new Sample[loop_fade_length]); const timepos_t read_start = timepos_t (loc->start_sample () - loop_declick_out.fade_length); const timecnt_t read_cnt = timecnt_t (loop_declick_out.fade_length); diff --git a/libs/ardour/import.cc b/libs/ardour/import.cc index 640aa7ee64..59708955bb 100644 --- a/libs/ardour/import.cc +++ b/libs/ardour/import.cc @@ -40,7 +40,6 @@ #include "pbd/gstdio_compat.h" #include -#include #include #include @@ -267,7 +266,7 @@ write_audio_data_to_new_files (ImportableSource* source, ImportStatus& status, return; } - boost::scoped_array data(new float[nframes * channels]); + std::unique_ptr data(new float[nframes * channels]); vector > channel_data; for (uint32_t n = 0; n < channels; ++n) { diff --git a/libs/backends/portaudio/winmmemidi_input_device.h b/libs/backends/portaudio/winmmemidi_input_device.h index 9dd67cf336..7fd830f7fa 100644 --- a/libs/backends/portaudio/winmmemidi_input_device.h +++ b/libs/backends/portaudio/winmmemidi_input_device.h @@ -27,7 +27,6 @@ #include -#include #include #include @@ -97,7 +96,7 @@ private: // data // can't use unique_ptr yet boost::scoped_ptr > m_midi_buffer; - boost::scoped_array m_sysex_buffer; + std::unique_ptr m_sysex_buffer; }; } diff --git a/libs/waveview/wave_view.cc b/libs/waveview/wave_view.cc index bc97d922c5..b3414ef4e4 100644 --- a/libs/waveview/wave_view.cc +++ b/libs/waveview/wave_view.cc @@ -20,8 +20,6 @@ #include -#include - #include #include @@ -475,7 +473,7 @@ WaveView::draw_image (Cairo::RefPtr& image, PeakData* peaks clip_context->set_antialias (Cairo::ANTIALIAS_NONE); zero_context->set_antialias (Cairo::ANTIALIAS_NONE); - boost::scoped_array tips (new LineTips[n_peaks]); + std::unique_ptr tips (new LineTips[n_peaks]); /* Clip level nominally set to -0.9dBFS to account for inter-sample interpolation possibly clipping (value may be too low). @@ -898,7 +896,7 @@ WaveView::process_draw_request (std::shared_ptr req) assert (n_peaks > 0 && n_peaks < 32767); - boost::scoped_array peaks (new PeakData[n_peaks]); + std::unique_ptr peaks (new PeakData[n_peaks]); /* Note that Region::read_peaks() takes a start position based on an offset into the Region's **SOURCE**, rather than an offset into