2 Copyright (C) 2000 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
34 #include <glibmm/fileutils.h>
35 #include <glibmm/miscutils.h>
37 #include "pbd/xml++.h"
38 #include "pbd/pthread_utils.h"
40 #include "ardour/audiosource.h"
41 #include "ardour/audio_diskstream.h"
42 #include "ardour/cycle_timer.h"
43 #include "ardour/session.h"
44 #include "ardour/transient_detector.h"
45 #include "ardour/runtime_functions.h"
50 using namespace ARDOUR;
53 Glib::StaticMutex AudioSource::_level_buffer_lock = GLIBMM_STATIC_MUTEX_INIT;
54 vector<boost::shared_ptr<Sample> > AudioSource::_mixdown_buffers;
55 vector<boost::shared_ptr<gain_t> > AudioSource::_gain_buffers;
56 size_t AudioSource::_working_buffers_size = 0;
57 bool AudioSource::_build_missing_peakfiles = false;
59 /** true if we want peakfiles (e.g. if we are displaying a GUI) */
60 bool AudioSource::_build_peakfiles = false;
64 AudioSource::AudioSource (Session& s, string name)
65 : Source (s, DataType::AUDIO, name)
70 _peakfile_descriptor = 0;
72 _write_data_count = 0;
73 peak_leftover_cnt = 0;
74 peak_leftover_size = 0;
78 AudioSource::AudioSource (Session& s, const XMLNode& node)
85 _peakfile_descriptor = 0;
87 _write_data_count = 0;
88 peak_leftover_cnt = 0;
89 peak_leftover_size = 0;
92 if (set_state (node, Stateful::loading_state_version)) {
93 throw failed_constructor();
97 AudioSource::~AudioSource ()
99 /* shouldn't happen but make sure we don't leak file descriptors anyway */
101 if (peak_leftover_cnt) {
102 cerr << "AudioSource destroyed with leftover peak data pending" << endl;
105 delete _peakfile_descriptor;
106 delete [] peak_leftovers;
110 AudioSource::get_state ()
112 XMLNode& node (Source::get_state());
114 if (_captured_for.length()) {
115 node.add_property ("captured-for", _captured_for);
122 AudioSource::set_state (const XMLNode& node, int /*version*/)
124 const XMLProperty* prop;
126 if ((prop = node.property ("captured-for")) != 0) {
127 _captured_for = prop->value();
134 AudioSource::empty () const
140 AudioSource::length (framepos_t /*pos*/) const
146 AudioSource::update_length (framepos_t pos, framecnt_t cnt)
148 if (pos + cnt > _length) {
154 /***********************************************************************
156 ***********************************************************************/
158 /** Checks to see if peaks are ready. If so, we return true. If not, we return false, and
159 * things are set up so that doThisWhenReady is called when the peaks are ready.
160 * A new PBD::ScopedConnection is created for the associated connection and written to
161 * *connect_here_if_not.
163 * @param doThisWhenReady Function to call when peaks are ready (if they are not already).
164 * @param connect_here_if_not Address to write new ScopedConnection to.
165 * @param event_loop Event loop for doThisWhenReady to be called in.
168 AudioSource::peaks_ready (boost::function<void()> doThisWhenReady, ScopedConnection** connect_here_if_not, EventLoop* event_loop) const
171 Glib::Mutex::Lock lm (_peaks_ready_lock);
173 if (!(ret = _peaks_built)) {
174 *connect_here_if_not = new ScopedConnection;
175 PeaksReady.connect (**connect_here_if_not, MISSING_INVALIDATOR, doThisWhenReady, event_loop);
182 AudioSource::touch_peakfile ()
186 if (stat (peakpath.c_str(), &statbuf) != 0 || statbuf.st_size == 0) {
192 tbuf.actime = statbuf.st_atime;
193 tbuf.modtime = time ((time_t) 0);
195 utime (peakpath.c_str(), &tbuf);
199 AudioSource::rename_peakfile (string newpath)
201 /* caller must hold _lock */
203 string oldpath = peakpath;
205 if (Glib::file_test (oldpath, Glib::FILE_TEST_EXISTS)) {
206 if (rename (oldpath.c_str(), newpath.c_str()) != 0) {
207 error << string_compose (_("cannot rename peakfile for %1 from %2 to %3 (%4)"), _name, oldpath, newpath, strerror (errno)) << endmsg;
218 AudioSource::initialize_peakfile (bool newfile, string audio_path)
222 peakpath = peak_path (audio_path);
224 /* if the peak file should be there, but isn't .... */
226 if (!newfile && !Glib::file_test (peakpath.c_str(), Glib::FILE_TEST_EXISTS)) {
227 peakpath = find_broken_peakfile (peakpath, audio_path);
230 if (stat (peakpath.c_str(), &statbuf)) {
231 if (errno != ENOENT) {
232 /* it exists in the peaks dir, but there is some kind of error */
234 error << string_compose(_("AudioSource: cannot stat peakfile \"%1\""), peakpath) << endmsg;
238 /* peakfile does not exist */
240 _peaks_built = false;
244 /* we found it in the peaks dir, so check it out */
246 if (statbuf.st_size == 0 || (statbuf.st_size < (off_t) ((length(_timeline_position) / _FPP) * sizeof (PeakData)))) {
248 _peaks_built = false;
250 // Check if the audio file has changed since the peakfile was built.
251 struct stat stat_file;
252 int err = stat (audio_path.c_str(), &stat_file);
256 /* no audio path - nested source or we can't
257 read it or ... whatever, use the peakfile as-is.
261 _peak_byte_max = statbuf.st_size;
265 /* allow 6 seconds slop on checking peak vs. file times because of various
269 if (stat_file.st_mtime > statbuf.st_mtime && (stat_file.st_mtime - statbuf.st_mtime > 6)) {
270 _peaks_built = false;
274 _peak_byte_max = statbuf.st_size;
280 if (!newfile && !_peaks_built && _build_missing_peakfiles && _build_peakfiles) {
281 build_peaks_from_scratch ();
288 AudioSource::read (Sample *dst, framepos_t start, framecnt_t cnt, int /*channel*/) const
290 Glib::Mutex::Lock lm (_lock);
291 return read_unlocked (dst, start, cnt);
295 AudioSource::write (Sample *dst, framecnt_t cnt)
297 Glib::Mutex::Lock lm (_lock);
298 /* any write makes the fill not removable */
299 _flags = Flag (_flags & ~Removable);
300 return write_unlocked (dst, cnt);
304 AudioSource::read_peaks (PeakData *peaks, framecnt_t npeaks, framepos_t start, framecnt_t cnt, double samples_per_visual_peak) const
306 return read_peaks_with_fpp (peaks, npeaks, start, cnt, samples_per_visual_peak, _FPP);
309 /** @param peaks Buffer to write peak data.
310 * @param npeaks Number of peaks to write.
314 AudioSource::read_peaks_with_fpp (PeakData *peaks, framecnt_t npeaks, framepos_t start, framecnt_t cnt,
315 double samples_per_visual_peak, framecnt_t samples_per_file_peak) const
317 Glib::Mutex::Lock lm (_lock);
319 double expected_peaks;
320 PeakData::PeakDatum xmax;
321 PeakData::PeakDatum xmin;
324 framecnt_t zero_fill = 0;
326 PeakData* staging = 0;
327 Sample* raw_staging = 0;
329 FdFileDescriptor* peakfile_descriptor = new FdFileDescriptor (peakpath, false, 0664);
330 int peakfile_fd = -1;
332 expected_peaks = (cnt / (double) samples_per_file_peak);
333 scale = npeaks/expected_peaks;
335 #undef DEBUG_READ_PEAKS
336 #ifdef DEBUG_READ_PEAKS
337 cerr << "======>RP: npeaks = " << npeaks
338 << " start = " << start
340 << " len = " << _length
341 << " samples_per_visual_peak =" << samples_per_visual_peak
342 << " expected was " << expected_peaks << " ... scale = " << scale
343 << " PD ptr = " << peaks
348 /* fix for near-end-of-file conditions */
350 if (cnt > _length - start) {
351 // cerr << "too close to end @ " << _length << " given " << start << " + " << cnt << endl;
352 cnt = _length - start;
353 framecnt_t old = npeaks;
354 npeaks = min ((framecnt_t) floor (cnt / samples_per_visual_peak), npeaks);
355 zero_fill = old - npeaks;
358 // cerr << "actual npeaks = " << npeaks << " zf = " << zero_fill << endl;
362 #ifdef DEBUG_READ_PEAKS
363 cerr << "RAW DATA\n";
365 /* no scaling at all, just get the sample data and duplicate it for
366 both max and min peak values.
369 Sample* raw_staging = new Sample[cnt];
371 if (read_unlocked (raw_staging, start, cnt) != cnt) {
372 error << _("cannot read sample data for unscaled peak computation") << endmsg;
376 for (framecnt_t i = 0; i < npeaks; ++i) {
377 peaks[i].max = raw_staging[i];
378 peaks[i].min = raw_staging[i];
381 delete peakfile_descriptor;
382 delete [] raw_staging;
388 off_t first_peak_byte = (start / samples_per_file_peak) * sizeof (PeakData);
390 /* open, read, close */
392 if ((peakfile_fd = peakfile_descriptor->allocate ()) < 0) {
393 error << string_compose(_("AudioSource: cannot open peakpath (a) \"%1\" (%2)"), peakpath, strerror (errno)) << endmsg;
394 delete peakfile_descriptor;
398 #ifdef DEBUG_READ_PEAKS
399 cerr << "DIRECT PEAKS\n";
402 nread = ::pread (peakfile_fd, peaks, sizeof (PeakData)* npeaks, first_peak_byte);
403 delete peakfile_descriptor;
405 if (nread != sizeof (PeakData) * npeaks) {
406 cerr << "AudioSource["
408 << "]: cannot read peaks from peakfile! (read only "
418 delete peakfile_descriptor;
423 memset (&peaks[npeaks], 0, sizeof (PeakData) * zero_fill);
426 delete peakfile_descriptor;
435 #ifdef DEBUG_READ_PEAKS
436 cerr << "DOWNSAMPLE\n";
440 - more frames-per-peak (lower resolution) than the peakfile, or to put it another way,
441 - less peaks than the peakfile holds for the same range
443 So, read a block into a staging area, and then downsample from there.
445 to avoid confusion, I'll refer to the requested peaks as visual_peaks and the peakfile peaks as stored_peaks
448 const framecnt_t chunksize = (framecnt_t) min (expected_peaks, 65536.0);
450 staging = new PeakData[chunksize];
452 /* compute the rounded up frame position */
454 framepos_t current_frame = start;
455 framepos_t current_stored_peak = (framepos_t) ceil (current_frame / (double) samples_per_file_peak);
456 framepos_t next_visual_peak = (framepos_t) ceil (current_frame / samples_per_visual_peak);
457 double next_visual_peak_frame = next_visual_peak * samples_per_visual_peak;
458 framepos_t stored_peak_before_next_visual_peak = (framepos_t) next_visual_peak_frame / samples_per_file_peak;
459 framecnt_t nvisual_peaks = 0;
460 framecnt_t stored_peaks_read = 0;
463 /* handle the case where the initial visual peak is on a pixel boundary */
465 current_stored_peak = min (current_stored_peak, stored_peak_before_next_visual_peak);
467 /* open ... close during out: handling */
469 if ((peakfile_fd = peakfile_descriptor->allocate ()) < 0) {
470 error << string_compose(_("AudioSource: cannot open peakpath (b) \"%1\" (%2)"), peakpath, strerror (errno)) << endmsg;
471 delete peakfile_descriptor;
476 while (nvisual_peaks < npeaks) {
478 if (i == stored_peaks_read) {
480 uint32_t start_byte = current_stored_peak * sizeof(PeakData);
481 tnp = min ((framecnt_t)(_length/samples_per_file_peak - current_stored_peak), (framecnt_t) expected_peaks);
482 to_read = min (chunksize, tnp);
484 #ifdef DEBUG_READ_PEAKS
485 cerr << "read " << sizeof (PeakData) * to_read << " from peakfile @ " << start_byte << endl;
488 if ((nread = ::pread (peakfile_fd, staging, sizeof (PeakData) * to_read, start_byte))
489 != sizeof (PeakData) * to_read) {
491 off_t fend = lseek (peakfile_fd, 0, SEEK_END);
493 cerr << "AudioSource["
495 << "]: cannot read peak data from peakfile ("
496 << (nread / sizeof(PeakData))
497 << " peaks instead of "
502 << " at start_byte = " << start_byte
503 << " _length = " << _length << " versus len = " << fend
504 << " expected maxpeaks = " << (_length - current_frame)/samples_per_file_peak
505 << " npeaks was " << npeaks
511 stored_peaks_read = nread / sizeof(PeakData);
517 while ((i < stored_peaks_read) && (current_stored_peak <= stored_peak_before_next_visual_peak)) {
519 xmax = max (xmax, staging[i].max);
520 xmin = min (xmin, staging[i].min);
522 ++current_stored_peak;
526 peaks[nvisual_peaks].max = xmax;
527 peaks[nvisual_peaks].min = xmin;
531 //next_visual_peak_frame = min ((next_visual_peak * samples_per_visual_peak), (next_visual_peak_frame+samples_per_visual_peak) );
532 next_visual_peak_frame = min ((double) start+cnt, (next_visual_peak_frame+samples_per_visual_peak) );
533 stored_peak_before_next_visual_peak = (uint32_t) next_visual_peak_frame / samples_per_file_peak;
537 memset (&peaks[npeaks], 0, sizeof (PeakData) * zero_fill);
544 #ifdef DEBUG_READ_PEAKS
545 cerr << "UPSAMPLE\n";
549 - less frames-per-peak (more resolution)
550 - more peaks than stored in the Peakfile
552 So, fetch data from the raw source, and generate peak
556 framecnt_t frames_read = 0;
557 framepos_t current_frame = start;
559 framecnt_t nvisual_peaks = 0;
560 framecnt_t chunksize = (framecnt_t) min (cnt, (framecnt_t) 4096);
561 raw_staging = new Sample[chunksize];
563 framepos_t frame_pos = start;
564 double pixel_pos = floor (frame_pos / samples_per_visual_peak);
565 double next_pixel_pos = ceil (frame_pos / samples_per_visual_peak);
566 double pixels_per_frame = 1.0 / samples_per_visual_peak;
571 while (nvisual_peaks < npeaks) {
573 if (i == frames_read) {
575 to_read = min (chunksize, (framecnt_t)(_length - current_frame));
577 if (current_frame >= _length) {
579 /* hmm, error condition - we've reached the end of the file
580 without generating all the peak data. cook up a zero-filled
581 data buffer and then use it. this is simpler than
582 adjusting zero_fill and npeaks and then breaking out of
586 memset (raw_staging, 0, sizeof (Sample) * chunksize);
590 to_read = min (chunksize, (_length - current_frame));
593 if ((frames_read = read_unlocked (raw_staging, current_frame, to_read)) == 0) {
594 error << string_compose(_("AudioSource[%1]: peak read - cannot read %2 samples at offset %3 of %4 (%5)"),
595 _name, to_read, current_frame, _length, strerror (errno))
604 xmax = max (xmax, raw_staging[i]);
605 xmin = min (xmin, raw_staging[i]);
608 pixel_pos += pixels_per_frame;
610 if (pixel_pos >= next_pixel_pos) {
612 peaks[nvisual_peaks].max = xmax;
613 peaks[nvisual_peaks].min = xmin;
618 next_pixel_pos = ceil (pixel_pos + 0.5);
623 memset (&peaks[npeaks], 0, sizeof (PeakData) * zero_fill);
630 delete peakfile_descriptor;
633 delete [] raw_staging;
635 #ifdef DEBUG_READ_PEAKS
642 #undef DEBUG_PEAK_BUILD
645 AudioSource::build_peaks_from_scratch ()
649 const framecnt_t bufsize = 65536; // 256kB per disk read for mono data is about ideal
654 /* hold lock while building peaks */
656 Glib::Mutex::Lock lp (_lock);
658 if (prepare_for_peakfile_writes ()) {
662 framecnt_t current_frame = 0;
663 framecnt_t cnt = _length;
665 _peaks_built = false;
666 buf = new Sample[bufsize];
670 framecnt_t frames_to_read = min (bufsize, cnt);
671 framecnt_t frames_read;
674 if ((frames_read = read_unlocked (buf, current_frame, frames_to_read)) != frames_to_read) {
675 error << string_compose(_("%1: could not write read raw data for peak computation (%2)"), _name, strerror (errno)) << endmsg;
676 done_with_peakfile_writes (false);
680 if (compute_and_write_peaks (buf, current_frame, frames_read, true, false, _FPP)) {
684 current_frame += frames_read;
693 done_with_peakfile_writes ((cnt == 0));
701 unlink (peakpath.c_str());
710 AudioSource::prepare_for_peakfile_writes ()
712 _peakfile_descriptor = new FdFileDescriptor (peakpath, true, 0664);
713 if ((_peakfile_fd = _peakfile_descriptor->allocate()) < 0) {
714 error << string_compose(_("AudioSource: cannot open peakpath (c) \"%1\" (%2)"), peakpath, strerror (errno)) << endmsg;
721 AudioSource::done_with_peakfile_writes (bool done)
723 if (peak_leftover_cnt) {
724 compute_and_write_peaks (0, 0, 0, true, false, _FPP);
728 Glib::Mutex::Lock lm (_peaks_ready_lock);
730 PeaksReady (); /* EMIT SIGNAL */
733 delete _peakfile_descriptor;
734 _peakfile_descriptor = 0;
737 /** @param first_frame Offset from the source start of the first frame to process */
739 AudioSource::compute_and_write_peaks (Sample* buf, framecnt_t first_frame, framecnt_t cnt,
740 bool force, bool intermediate_peaks_ready)
742 return compute_and_write_peaks (buf, first_frame, cnt, force, intermediate_peaks_ready, _FPP);
746 AudioSource::compute_and_write_peaks (Sample* buf, framecnt_t first_frame, framecnt_t cnt,
747 bool force, bool intermediate_peaks_ready, framecnt_t fpp)
751 uint32_t peaks_computed;
752 PeakData* peakbuf = 0;
754 framepos_t current_frame;
755 framecnt_t frames_done;
756 const size_t blocksize = (128 * 1024);
757 off_t first_peak_byte;
759 if (_peakfile_descriptor == 0) {
760 prepare_for_peakfile_writes ();
764 if (peak_leftover_cnt) {
766 if (first_frame != peak_leftover_frame + peak_leftover_cnt) {
768 /* uh-oh, ::seek() since the last ::compute_and_write_peaks(),
769 and we have leftovers. flush a single peak (since the leftovers
770 never represent more than that, and restart.
775 x.min = peak_leftovers[0];
776 x.max = peak_leftovers[0];
778 off_t byte = (peak_leftover_frame / fpp) * sizeof (PeakData);
780 if (::pwrite (_peakfile_fd, &x, sizeof (PeakData), byte) != sizeof (PeakData)) {
781 error << string_compose(_("%1: could not write peak file data (%2)"), _name, strerror (errno)) << endmsg;
785 _peak_byte_max = max (_peak_byte_max, (off_t) (byte + sizeof(PeakData)));
788 Glib::Mutex::Lock lm (_peaks_ready_lock);
789 PeakRangeReady (peak_leftover_frame, peak_leftover_cnt); /* EMIT SIGNAL */
790 if (intermediate_peaks_ready) {
791 PeaksReady (); /* EMIT SIGNAL */
795 /* left overs are done */
797 peak_leftover_cnt = 0;
801 /* else ... had leftovers, but they immediately preceed the new data, so just
802 merge them and compute.
805 /* make a new contiguous buffer containing leftovers and the new stuff */
807 to_do = cnt + peak_leftover_cnt;
808 buf2 = new Sample[to_do];
811 memcpy (buf2, peak_leftovers, peak_leftover_cnt * sizeof (Sample));
814 memcpy (buf2+peak_leftover_cnt, buf, cnt * sizeof (Sample));
816 /* no more leftovers */
817 peak_leftover_cnt = 0;
819 /* use the temporary buffer */
822 /* make sure that when we write into the peakfile, we startup where we left off */
824 first_frame = peak_leftover_frame;
830 peakbuf = new PeakData[(to_do/fpp)+1];
832 current_frame = first_frame;
837 /* if some frames were passed in (i.e. we're not flushing leftovers)
838 and there are less than fpp to do, save them till
842 if (force && (to_do < fpp)) {
843 /* keep the left overs around for next time */
845 if (peak_leftover_size < to_do) {
846 delete [] peak_leftovers;
847 peak_leftovers = new Sample[to_do];
848 peak_leftover_size = to_do;
850 memcpy (peak_leftovers, buf, to_do * sizeof (Sample));
851 peak_leftover_cnt = to_do;
852 peak_leftover_frame = current_frame;
859 framecnt_t this_time = min (fpp, to_do);
861 peakbuf[peaks_computed].max = buf[0];
862 peakbuf[peaks_computed].min = buf[0];
864 ARDOUR::find_peaks (buf+1, this_time-1, &peakbuf[peaks_computed].min, &peakbuf[peaks_computed].max);
869 frames_done += this_time;
870 current_frame += this_time;
873 first_peak_byte = (first_frame / fpp) * sizeof (PeakData);
875 if (can_truncate_peaks()) {
877 /* on some filesystems (ext3, at least) this helps to reduce fragmentation of
878 the peakfiles. its not guaranteed to do so, and even on ext3 (as of december 2006)
879 it does not cause single-extent allocation even for peakfiles of
880 less than BLOCKSIZE bytes. only call ftruncate if we'll make the file larger.
883 off_t endpos = lseek (_peakfile_fd, 0, SEEK_END);
884 off_t target_length = blocksize * ((first_peak_byte + blocksize + 1) / blocksize);
886 if (endpos < target_length) {
887 (void) ftruncate (_peakfile_fd, target_length);
888 /* error doesn't actually matter though, so continue on without testing */
892 if (::pwrite (_peakfile_fd, peakbuf, sizeof (PeakData) * peaks_computed, first_peak_byte) != (ssize_t) (sizeof (PeakData) * peaks_computed)) {
893 error << string_compose(_("%1: could not write peak file data (%2)"), _name, strerror (errno)) << endmsg;
897 _peak_byte_max = max (_peak_byte_max, (off_t) (first_peak_byte + sizeof(PeakData)*peaks_computed));
900 Glib::Mutex::Lock lm (_peaks_ready_lock);
901 PeakRangeReady (first_frame, frames_done); /* EMIT SIGNAL */
902 if (intermediate_peaks_ready) {
903 PeaksReady (); /* EMIT SIGNAL */
917 AudioSource::truncate_peakfile ()
919 if (_peakfile_descriptor == 0) {
920 error << string_compose (_("programming error: %1"), "AudioSource::truncate_peakfile() called without open peakfile descriptor")
925 /* truncate the peakfile down to its natural length if necessary */
927 off_t end = lseek (_peakfile_fd, 0, SEEK_END);
929 if (end > _peak_byte_max) {
930 (void) ftruncate (_peakfile_fd, _peak_byte_max);
935 AudioSource::available_peaks (double zoom_factor) const
937 if (zoom_factor < _FPP) {
938 return length(_timeline_position); // peak data will come from the audio file
941 /* peak data comes from peakfile, but the filesize might not represent
942 the valid data due to ftruncate optimizations, so use _peak_byte_max state.
943 XXX - there might be some atomicity issues here, we should probably add a lock,
944 but _peak_byte_max only monotonically increases after initialization.
947 off_t end = _peak_byte_max;
949 return (end/sizeof(PeakData)) * _FPP;
953 AudioSource::dec_read_data_count (framecnt_t cnt)
955 uint32_t val = cnt * sizeof (Sample);
957 if (val < _read_data_count) {
958 _read_data_count -= val;
960 _read_data_count = 0;
965 AudioSource::mark_streaming_write_completed ()
967 Glib::Mutex::Lock lm (_peaks_ready_lock);
970 PeaksReady (); /* EMIT SIGNAL */
975 AudioSource::allocate_working_buffers (framecnt_t framerate)
977 Glib::Mutex::Lock lm (_level_buffer_lock);
980 /* Note: we don't need any buffers allocated until
981 a level 1 audiosource is created, at which
982 time we'll call ::ensure_buffers_for_level()
983 with the right value and do the right thing.
986 if (!_mixdown_buffers.empty()) {
987 ensure_buffers_for_level_locked ( _mixdown_buffers.size(), framerate);
992 AudioSource::ensure_buffers_for_level (uint32_t level, framecnt_t frame_rate)
994 Glib::Mutex::Lock lm (_level_buffer_lock);
995 ensure_buffers_for_level_locked (level, frame_rate);
999 AudioSource::ensure_buffers_for_level_locked (uint32_t level, framecnt_t frame_rate)
1001 framecnt_t nframes = (framecnt_t) floor (Config->get_audio_playback_buffer_seconds() * frame_rate);
1003 _mixdown_buffers.clear ();
1004 _gain_buffers.clear ();
1006 while (_mixdown_buffers.size() < level) {
1007 _mixdown_buffers.push_back (boost::shared_ptr<Sample> (new Sample[nframes]));
1008 _gain_buffers.push_back (boost::shared_ptr<gain_t> (new gain_t[nframes]));