summaryrefslogtreecommitdiff
path: root/libs/ardour
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2020-04-07 16:20:53 +0200
committerRobin Gareus <robin@gareus.org>2020-04-07 16:20:53 +0200
commit2377927fc16221e8805b152b1759c869fe3f7aa5 (patch)
treeed4da739315d4dabe5d40b1c776f8dccfbd2c812 /libs/ardour
parent91a213427e934df02049c238683da55cbee1f467 (diff)
NO-OP: whitespace
Diffstat (limited to 'libs/ardour')
-rw-r--r--libs/ardour/disk_reader.cc926
1 files changed, 443 insertions, 483 deletions
diff --git a/libs/ardour/disk_reader.cc b/libs/ardour/disk_reader.cc
index 0799dd6fae..abd6b7b4e3 100644
--- a/libs/ardour/disk_reader.cc
+++ b/libs/ardour/disk_reader.cc
@@ -26,14 +26,14 @@
#include "evoral/Range.h"
#include "ardour/amp.h"
+#include "ardour/audio_buffer.h"
#include "ardour/audioengine.h"
#include "ardour/audioplaylist.h"
-#include "ardour/audio_buffer.h"
#include "ardour/butler.h"
#include "ardour/debug.h"
#include "ardour/disk_reader.h"
-#include "ardour/midi_ring_buffer.h"
#include "ardour/midi_playlist.h"
+#include "ardour/midi_ring_buffer.h"
#include "ardour/midi_track.h"
#include "ardour/pannable.h"
#include "ardour/playlist.h"
@@ -47,17 +47,17 @@ using namespace ARDOUR;
using namespace PBD;
using namespace std;
-ARDOUR::samplecnt_t DiskReader::_chunk_samples = default_chunk_samples ();
-PBD::Signal0<void> DiskReader::Underrun;
-Sample* DiskReader::_sum_buffer = 0;
-Sample* DiskReader::_mixdown_buffer = 0;
-gain_t* DiskReader::_gain_buffer = 0;
-gint DiskReader::_no_disk_output (0);
+ARDOUR::samplecnt_t DiskReader::_chunk_samples = default_chunk_samples ();
+PBD::Signal0<void> DiskReader::Underrun;
+Sample* DiskReader::_sum_buffer = 0;
+Sample* DiskReader::_mixdown_buffer = 0;
+gain_t* DiskReader::_gain_buffer = 0;
+gint DiskReader::_no_disk_output (0);
DiskReader::Declicker DiskReader::loop_declick_in;
DiskReader::Declicker DiskReader::loop_declick_out;
-samplecnt_t DiskReader::loop_fade_length (0);
+samplecnt_t DiskReader::loop_fade_length (0);
-DiskReader::DiskReader (Session& s, string const & str, DiskIOProcessor::Flag f)
+DiskReader::DiskReader (Session& s, string const& str, DiskIOProcessor::Flag f)
: DiskIOProcessor (s, str, f)
, overwrite_sample (0)
, run_must_resolve (false)
@@ -65,7 +65,7 @@ DiskReader::DiskReader (Session& s, string const & str, DiskIOProcessor::Flag f)
, _declick_offs (0)
{
file_sample[DataType::AUDIO] = 0;
- file_sample[DataType::MIDI] = 0;
+ file_sample[DataType::MIDI] = 0;
g_atomic_int_set (&_pending_overwrite, 0);
}
@@ -77,11 +77,12 @@ DiskReader::~DiskReader ()
void
DiskReader::ReaderChannelInfo::resize (samplecnt_t bufsize)
{
- delete rbuf; rbuf = 0;
+ delete rbuf;
+ rbuf = 0;
rbuf = new PlaybackBuffer<Sample> (bufsize);
/* touch memory to lock it */
- memset (rbuf->buffer(), 0, sizeof (Sample) * rbuf->bufsize());
+ memset (rbuf->buffer (), 0, sizeof (Sample) * rbuf->bufsize ());
}
void
@@ -92,8 +93,8 @@ DiskReader::ReaderChannelInfo::resize_preloop (samplecnt_t bufsize)
}
if (bufsize > pre_loop_buffer_size) {
- delete [] pre_loop_buffer;
- pre_loop_buffer = new Sample[bufsize];
+ delete[] pre_loop_buffer;
+ pre_loop_buffer = new Sample[bufsize];
pre_loop_buffer_size = bufsize;
}
}
@@ -102,48 +103,48 @@ int
DiskReader::add_channel_to (boost::shared_ptr<ChannelList> c, uint32_t how_many)
{
while (how_many--) {
- c->push_back (new ReaderChannelInfo (_session.butler()->audio_playback_buffer_size(), loop_fade_length));
+ c->push_back (new ReaderChannelInfo (_session.butler ()->audio_playback_buffer_size (), loop_fade_length));
DEBUG_TRACE (DEBUG::DiskIO, string_compose ("%1: new reader channel, write space = %2 read = %3\n",
- name(),
- c->back()->rbuf->write_space(),
- c->back()->rbuf->read_space()));
+ name (),
+ c->back ()->rbuf->write_space (),
+ c->back ()->rbuf->read_space ()));
}
return 0;
}
void
-DiskReader::allocate_working_buffers()
+DiskReader::allocate_working_buffers ()
{
/* with varifill buffer refilling, we compute the read size in bytes (to optimize
for disk i/o bandwidth) and then convert back into samples. These buffers
need to reflect the maximum size we could use, which is 4MB reads, or 2M samples
using 16 bit samples.
*/
- _sum_buffer = new Sample[2*1048576];
- _mixdown_buffer = new Sample[2*1048576];
- _gain_buffer = new gain_t[2*1048576];
+ _sum_buffer = new Sample[2 * 1048576];
+ _mixdown_buffer = new Sample[2 * 1048576];
+ _gain_buffer = new gain_t[2 * 1048576];
}
void
-DiskReader::free_working_buffers()
+DiskReader::free_working_buffers ()
{
- delete [] _sum_buffer;
- delete [] _mixdown_buffer;
- delete [] _gain_buffer;
+ delete[] _sum_buffer;
+ delete[] _mixdown_buffer;
+ delete[] _gain_buffer;
_sum_buffer = 0;
_mixdown_buffer = 0;
_gain_buffer = 0;
}
samplecnt_t
-DiskReader::default_chunk_samples()
+DiskReader::default_chunk_samples ()
{
return 65536;
}
bool
-DiskReader::set_name (string const & str)
+DiskReader::set_name (string const& str)
{
string my_name = X_("player:");
my_name += str;
@@ -159,7 +160,7 @@ XMLNode&
DiskReader::state ()
{
XMLNode& node (DiskIOProcessor::state ());
- node.set_property(X_("type"), X_("diskreader"));
+ node.set_property (X_("type"), X_("diskreader"));
return node;
}
@@ -187,8 +188,8 @@ void
DiskReader::realtime_locate (bool for_loop_end)
{
if (!for_loop_end) {
- boost::shared_ptr<MidiTrack> mt = boost::dynamic_pointer_cast<MidiTrack>(_track);
- _tracker.resolve_notes (mt->immediate_events(), 0);
+ boost::shared_ptr<MidiTrack> mt = boost::dynamic_pointer_cast<MidiTrack> (_track);
+ _tracker.resolve_notes (mt->immediate_events (), 0);
}
}
@@ -196,33 +197,33 @@ float
DiskReader::buffer_load () const
{
/* Note: for MIDI it's not trivial to differentiate the following two cases:
+ *
+ * 1. The playback buffer is empty because the system has run out of time to fill it.
+ * 2. The playback buffer is empty because there is no more data on the playlist.
+ *
+ * If we use a simple buffer load computation, we will report that the MIDI diskstream
+ * cannot keep up when #2 happens, when in fact it can. Since MIDI data rates
+ * are so low compared to audio, just use the audio value here.
+ */
- 1. The playback buffer is empty because the system has run out of time to fill it.
- 2. The playback buffer is empty because there is no more data on the playlist.
-
- If we use a simple buffer load computation, we will report that the MIDI diskstream
- cannot keep up when #2 happens, when in fact it can. Since MIDI data rates
- are so low compared to audio, just use the audio value here.
- */
-
- boost::shared_ptr<ChannelList> c = channels.reader();
+ boost::shared_ptr<ChannelList> c = channels.reader ();
if (c->empty ()) {
/* no channels, so no buffers, so completely full and ready to playback, sir! */
return 1.0;
}
- PBD::PlaybackBuffer<Sample>* b = c->front()->rbuf;
- return (float) ((double) b->read_space() / (double) b->bufsize());
+ PBD::PlaybackBuffer<Sample>* b = c->front ()->rbuf;
+ return (float)((double)b->read_space () / (double)b->bufsize ());
}
void
DiskReader::adjust_buffering ()
{
- boost::shared_ptr<ChannelList> c = channels.reader();
+ boost::shared_ptr<ChannelList> c = channels.reader ();
- for (ChannelList::iterator chan = c->begin(); chan != c->end(); ++chan) {
- (*chan)->resize (_session.butler()->audio_playback_buffer_size());
+ for (ChannelList::iterator chan = c->begin (); chan != c->end (); ++chan) {
+ (*chan)->resize (_session.butler ()->audio_playback_buffer_size ());
}
}
@@ -259,11 +260,11 @@ DiskReader::use_playlist (DataType dt, boost::shared_ptr<Playlist> playlist)
void
DiskReader::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_sample, double speed, pframes_t nframes, bool result_required)
{
- uint32_t n;
- boost::shared_ptr<ChannelList> c = channels.reader();
- ChannelList::iterator chan;
- sampleoffset_t disk_samples_to_consume;
- MonitorState ms = _track->monitoring_state ();
+ uint32_t n;
+ boost::shared_ptr<ChannelList> c = channels.reader ();
+ ChannelList::iterator chan;
+ sampleoffset_t disk_samples_to_consume;
+ MonitorState ms = _track->monitoring_state ();
if (_active) {
if (!_pending_active) {
@@ -279,37 +280,33 @@ DiskReader::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_samp
}
const gain_t target_gain = ((speed == 0.0) || ((ms & MonitoringDisk) == 0)) ? 0.0 : 1.0;
- bool declick_out = (_declick_amp.gain() != target_gain) && target_gain == 0.0;
-
- if (!_session.cfg ()->get_use_transport_fades () || (_session.exporting () && ! _session.realtime_export ())) {
+ bool declick_out = (_declick_amp.gain () != target_gain) && target_gain == 0.0;
+ if (!_session.cfg ()->get_use_transport_fades () || (_session.exporting () && !_session.realtime_export ())) {
/* no transport fades or exporting - no declick out logic */
_declick_amp.set_gain (target_gain);
declick_out = false;
} else {
-
/* using transport fades and not exporting - declick login in effect */
if (ms == MonitoringDisk) {
-
/* Only monitoring from disk, so if we've finished a
* declick (for stop/locate), do not accidentally pass
* any data from disk to our outputs.
*/
- if ((target_gain == 0.0) && (_declick_amp.gain() == target_gain)) {
+ if ((target_gain == 0.0) && (_declick_amp.gain () == target_gain)) {
/* we were heading for zero (declick out for
- stop), and we've reached there. Done.
- */
+ * stop), and we've reached there. Done. */
return;
}
}
}
- BufferSet& scratch_bufs (_session.get_scratch_buffers (bufs.count()));
- const bool still_locating = _session.global_locate_pending();
+ BufferSet& scratch_bufs (_session.get_scratch_buffers (bufs.count ()));
+ const bool still_locating = _session.global_locate_pending ();
assert (speed == -1 || speed == 0 || speed == 1);
@@ -319,7 +316,7 @@ DiskReader::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_samp
disk_samples_to_consume = nframes;
}
- if (c->empty() || !_playlists[DataType::AUDIO]) {
+ if (c->empty () || !_playlists[DataType::AUDIO]) {
/* do nothing with audio */
goto midi;
}
@@ -337,11 +334,10 @@ DiskReader::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_samp
}
if (!result_required || ((ms & MonitoringDisk) == 0) || still_locating || _no_disk_output) {
-
/* no need for actual disk data, just advance read pointer */
if (!still_locating || _no_disk_output) {
- for (ChannelList::iterator chan = c->begin(); chan != c->end(); ++chan) {
+ for (ChannelList::iterator chan = c->begin (); chan != c->end (); ++chan) {
assert ((*chan)->rbuf);
(*chan)->rbuf->increment_read_ptr (disk_samples_to_consume);
}
@@ -354,34 +350,32 @@ DiskReader::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_samp
}
} else {
-
/* we need audio data from disk */
- size_t n_buffers = bufs.count().n_audio();
- size_t n_chans = c->size();
+ size_t n_buffers = bufs.count ().n_audio ();
+ size_t n_chans = c->size ();
gain_t scaling;
if (n_chans > n_buffers) {
- scaling = ((float) n_buffers) / n_chans;
+ scaling = ((float)n_buffers) / n_chans;
} else {
scaling = 1.0;
}
- const float initial_declick_gain = _declick_amp.gain ();
- const sampleoffset_t declick_offs = _declick_offs;
-
- for (n = 0, chan = c->begin(); chan != c->end(); ++chan, ++n) {
+ const float initial_declick_gain = _declick_amp.gain ();
+ const sampleoffset_t declick_offs = _declick_offs;
+ for (n = 0, chan = c->begin (); chan != c->end (); ++chan, ++n) {
ChannelInfo* chaninfo (*chan);
AudioBuffer& output (bufs.get_audio (n % n_buffers));
- AudioBuffer& disk_buf ((ms & MonitoringInput) ? scratch_bufs.get_audio(n) : output);
+ AudioBuffer& disk_buf ((ms & MonitoringInput) ? scratch_bufs.get_audio (n) : output);
if (start_sample != playback_sample && target_gain != 0) {
- samplepos_t ss = start_sample;
- Location* loc = _loop_location;
+ samplepos_t ss = start_sample;
+ Location* loc = _loop_location;
if (loc) {
- Evoral::Range<samplepos_t> loop_range (loc->start(), loc->end() - 1);
+ Evoral::Range<samplepos_t> loop_range (loc->start (), loc->end () - 1);
ss = loop_range.squish (playback_sample);
}
if (can_internal_playback_seek (ss - playback_sample)) {
@@ -395,30 +389,28 @@ DiskReader::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_samp
_declick_amp.set_gain (initial_declick_gain);
if (!declick_out) {
-
- const samplecnt_t available = chaninfo->rbuf->read (disk_buf.data(), disk_samples_to_consume);
+ const samplecnt_t available = chaninfo->rbuf->read (disk_buf.data (), disk_samples_to_consume);
if (disk_samples_to_consume > available) {
cerr << "underrun for " << _name << " Available samples: " << available << " required: " << disk_samples_to_consume << endl;
- DEBUG_TRACE (DEBUG::Butler, string_compose ("%1 underrun in %2, total space = %3 vs %4\n", DEBUG_THREAD_SELF, name(), available, disk_samples_to_consume));
+ DEBUG_TRACE (DEBUG::Butler, string_compose ("%1 underrun in %2, total space = %3 vs %4\n", DEBUG_THREAD_SELF, name (), available, disk_samples_to_consume));
Underrun ();
return;
}
- } else if (_declick_amp.gain() != target_gain) {
-
+ } else if (_declick_amp.gain () != target_gain) {
assert (target_gain == 0);
/* note that this is a non-committing read: it
- retrieves data from the ringbuffer but does not
- advance the read pointer. As a result,
- subsequent calls (as we declick) need to
- pass in an offset describing where to read
- from. We maintain _declick_offs across calls
- to ::run()
- */
+ * retrieves data from the ringbuffer but does not
+ * advance the read pointer. As a result,
+ * subsequent calls (as we declick) need to
+ * pass in an offset describing where to read
+ * from. We maintain _declick_offs across calls
+ * to ::run()
+ */
- const samplecnt_t total = chaninfo->rbuf->read (disk_buf.data(), nframes, false, declick_offs);
+ const samplecnt_t total = chaninfo->rbuf->read (disk_buf.data (), nframes, false, declick_offs);
if (n == 0) {
_declick_offs += total;
@@ -427,28 +419,24 @@ DiskReader::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_samp
_declick_amp.apply_gain (disk_buf, nframes, target_gain);
- /* _declick_amp is now left with the correct gain after
- * processing nframes
- */
+ /* _declick_amp is now left with the correct gain after processing nframes */
Amp::apply_simple_gain (disk_buf, nframes, scaling);
if (ms & MonitoringInput) {
/* mix the disk signal into the input signal (already in bufs) */
- mix_buffers_no_gain (output.data(), disk_buf.data(), nframes);
+ mix_buffers_no_gain (output.data (), disk_buf.data (), nframes);
}
}
}
-
- midi:
+midi:
/* MIDI data handling */
- const bool no_playlist_modification_pending = !(pending_overwrite() & PlaylistModified);
-
- if (bufs.count().n_midi()) {
+ const bool no_playlist_modification_pending = !(pending_overwrite () & PlaylistModified);
+ if (bufs.count ().n_midi ()) {
MidiBuffer& dst (bufs.get_midi (0));
if (run_must_resolve) {
@@ -456,7 +444,7 @@ DiskReader::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_samp
run_must_resolve = false;
}
- if (!_no_disk_output && !declick_in_progress() && (ms & MonitoringDisk) && !still_locating && no_playlist_modification_pending && speed) {
+ if (!_no_disk_output && !declick_in_progress () && (ms & MonitoringDisk) && !still_locating && no_playlist_modification_pending && speed) {
get_midi_playback (dst, start_sample, end_sample, ms, scratch_bufs, speed, disk_samples_to_consume);
}
}
@@ -464,7 +452,6 @@ DiskReader::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_samp
/* decide if we need the butler */
if (!still_locating && no_playlist_modification_pending) {
-
bool butler_required = false;
if (speed < 0.0) {
@@ -475,20 +462,20 @@ DiskReader::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_samp
Location* loc = _loop_location;
if (loc) {
- Evoral::Range<samplepos_t> loop_range (loc->start(), loc->end() - 1);
+ Evoral::Range<samplepos_t> loop_range (loc->start (), loc->end () - 1);
playback_sample = loop_range.squish (playback_sample);
}
if (_playlists[DataType::AUDIO]) {
- if (!c->empty()) {
+ if (!c->empty ()) {
if (_slaved) {
- if (c->front()->rbuf->write_space() >= c->front()->rbuf->bufsize() / 2) {
- DEBUG_TRACE (DEBUG::Butler, string_compose ("%1: slaved, write space = %2 of %3\n", name(), c->front()->rbuf->write_space(), c->front()->rbuf->bufsize()));
+ if (c->front ()->rbuf->write_space () >= c->front ()->rbuf->bufsize () / 2) {
+ DEBUG_TRACE (DEBUG::Butler, string_compose ("%1: slaved, write space = %2 of %3\n", name (), c->front ()->rbuf->write_space (), c->front ()->rbuf->bufsize ()));
butler_required = true;
}
} else {
- if ((samplecnt_t) c->front()->rbuf->write_space() >= _chunk_samples) {
- DEBUG_TRACE (DEBUG::Butler, string_compose ("%1: write space = %2 of %3\n", name(), c->front()->rbuf->write_space(),
+ if ((samplecnt_t)c->front ()->rbuf->write_space () >= _chunk_samples) {
+ DEBUG_TRACE (DEBUG::Butler, string_compose ("%1: write space = %2 of %3\n", name (), c->front ()->rbuf->write_space (),
_chunk_samples));
butler_required = true;
}
@@ -504,17 +491,17 @@ DiskReader::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_samp
}
if (_need_butler) {
- DEBUG_TRACE (DEBUG::Butler, string_compose ("%1 reader run, needs butler = %2\n", name(), _need_butler));
+ DEBUG_TRACE (DEBUG::Butler, string_compose ("%1 reader run, needs butler = %2\n", name (), _need_butler));
}
}
bool
DiskReader::declick_in_progress () const
{
- if (!_session.cfg()->get_use_transport_fades () || (_session.exporting () && ! _session.realtime_export ())) {
+ if (!_session.cfg ()->get_use_transport_fades () || (_session.exporting () && !_session.realtime_export ())) {
return false;
}
- return (_declick_amp.gain() != 0); // declick-out
+ return (_declick_amp.gain () != 0); // declick-out
}
bool
@@ -531,54 +518,50 @@ DiskReader::set_pending_overwrite (OverwriteReason why)
/* called from audio thread, so we can use the read ptr and playback sample as we wish */
if (!c->empty ()) {
-
- const samplecnt_t reserved_size = c->front()->rbuf->reserved_size();
- const samplecnt_t bufsize = c->front()->rbuf->bufsize ();
+ const samplecnt_t reserved_size = c->front ()->rbuf->reserved_size ();
+ const samplecnt_t bufsize = c->front ()->rbuf->bufsize ();
overwrite_sample = playback_sample - reserved_size;
- overwrite_offset = c->front()->rbuf->read_ptr();
+ overwrite_offset = c->front ()->rbuf->read_ptr ();
if (overwrite_offset > reserved_size) {
-
/*
- |----------------------------------------------------------------------|
- ^ ^
- RRRRRRRRRRRRRRRRoverwrite_offset (old read_ptr)
- |<- second ->|<------------------ first chunk ------------------------>|
-
- Fill the the end of the buffer ("first chunk"), above
+ * |----------------------------------------------------------------------|
+ * ^ ^
+ * RRRRRRRRRRRRRRRRoverwrite_offset (old read_ptr)
+ * |<- second ->|<------------------ first chunk ------------------------>|
+ *
+ * Fill the the end of the buffer ("first chunk"), above
*/
overwrite_offset -= reserved_size;
} else {
-
/*
- |----------------------------------------------------------------------|
- RRRRRRRRE^ RRRRRRRRR
- overwrite_offset (old read_ptr)
- |< second chunk >|<first>|
-
- Fill the end of the buffer ("R1R1R1" aka "first" above)
- */
+ * |----------------------------------------------------------------------|
+ * RRRRRRRRE^ RRRRRRRRR
+ * overwrite_offset (old read_ptr)
+ * |< second chunk >|<first>|
+ *
+ * Fill the end of the buffer ("R1R1R1" aka "first" above)
+ */
overwrite_offset = bufsize - (reserved_size - overwrite_offset);
}
}
- if (why & (LoopChanged|PlaylistModified|PlaylistChanged)) {
+ if (why & (LoopChanged | PlaylistModified | PlaylistChanged)) {
run_must_resolve = true;
}
while (true) {
OverwriteReason current = OverwriteReason (g_atomic_int_get (&_pending_overwrite));
- OverwriteReason next = OverwriteReason (current | why);
+ OverwriteReason next = OverwriteReason (current | why);
if (g_atomic_int_compare_and_exchange (&_pending_overwrite, current, next)) {
break;
}
}
-
}
bool
@@ -638,8 +621,7 @@ DiskReader::overwrite_existing_audio ()
* simply replace the contents of the buffer.
*/
-
- boost::shared_ptr<ChannelList> c = channels.reader();
+ boost::shared_ptr<ChannelList> c = channels.reader ();
if (c->empty ()) {
return true;
@@ -651,10 +633,10 @@ DiskReader::overwrite_existing_audio ()
samplecnt_t chunk1_cnt;
samplecnt_t chunk2_cnt;
- const samplecnt_t bufsize = c->front()->rbuf->bufsize ();
+ const samplecnt_t bufsize = c->front ()->rbuf->bufsize ();
chunk1_offset = overwrite_offset;
- chunk1_cnt = bufsize - overwrite_offset;
+ chunk1_cnt = bufsize - overwrite_offset;
if (chunk1_cnt == bufsize) {
chunk1_cnt--;
@@ -667,28 +649,27 @@ DiskReader::overwrite_existing_audio ()
assert (chunk1_cnt + chunk2_cnt == bufsize - 1);
boost::scoped_array<Sample> mixdown_buffer (new Sample[bufsize]);
- boost::scoped_array<float> gain_buffer (new float[bufsize]);
- uint32_t n = 0;
- bool ret = true;
-
- for (ChannelList::iterator chan = c->begin(); chan != c->end(); ++chan, ++n) {
+ boost::scoped_array<float> gain_buffer (new float[bufsize]);
+ uint32_t n = 0;
+ bool ret = true;
+ for (ChannelList::iterator chan = c->begin (); chan != c->end (); ++chan, ++n) {
samplepos_t start = overwrite_sample;
- Sample* buf = (*chan)->rbuf->buffer();
+ Sample* buf = (*chan)->rbuf->buffer ();
ReaderChannelInfo* rci = dynamic_cast<ReaderChannelInfo*> (*chan);
if (chunk1_cnt) {
- if (audio_read (buf + chunk1_offset, mixdown_buffer.get(), gain_buffer.get(), start, chunk1_cnt, rci, n, reversed) != chunk1_cnt) {
- error << string_compose(_("DiskReader %1: when overwriting(1), cannot read %2 from playlist at sample %3"), id(), chunk1_cnt, overwrite_sample) << endmsg;
+ if (audio_read (buf + chunk1_offset, mixdown_buffer.get (), gain_buffer.get (), start, chunk1_cnt, rci, n, reversed) != chunk1_cnt) {
+ error << string_compose (_("DiskReader %1: when overwriting(1), cannot read %2 from playlist at sample %3"), id (), chunk1_cnt, overwrite_sample) << endmsg;
ret = false;
continue;
}
}
if (chunk2_cnt) {
- if (audio_read (buf, mixdown_buffer.get(), gain_buffer.get(), start, chunk2_cnt, rci, n, reversed) != chunk2_cnt) {
- error << string_compose(_("DiskReader %1: when overwriting(2), cannot read %2 from playlist at sample %3"), id(), chunk2_cnt, overwrite_sample) << endmsg;
+ if (audio_read (buf, mixdown_buffer.get (), gain_buffer.get (), start, chunk2_cnt, rci, n, reversed) != chunk2_cnt) {
+ error << string_compose (_("DiskReader %1: when overwriting(2), cannot read %2 from playlist at sample %3"), id (), chunk2_cnt, overwrite_sample) << endmsg;
ret = false;
}
}
@@ -703,17 +684,17 @@ DiskReader::overwrite_existing_midi ()
RTMidiBuffer* mbuf = rt_midibuffer ();
if (mbuf) {
- boost::shared_ptr<MidiTrack> mt = boost::dynamic_pointer_cast<MidiTrack>(_track);
- MidiChannelFilter* filter = mt ? &mt->playback_filter() : 0;
+ boost::shared_ptr<MidiTrack> mt = boost::dynamic_pointer_cast<MidiTrack> (_track);
+ MidiChannelFilter* filter = mt ? &mt->playback_filter () : 0;
PBD::Timing minsert;
- minsert.start();
+ minsert.start ();
- midi_playlist()->render (filter);
+ midi_playlist ()->render (filter);
- minsert.update();
- assert (midi_playlist()->rendered());
- cerr << "Reading " << name() << " took " << minsert.elapsed() << " microseconds, final size = " << midi_playlist()->rendered()->size() << endl;
+ minsert.update ();
+ assert (midi_playlist ()->rendered ());
+ cerr << "Reading " << name () << " took " << minsert.elapsed () << " microseconds, final size = " << midi_playlist ()->rendered ()->size () << endl;
}
return true;
@@ -724,17 +705,17 @@ DiskReader::overwrite_existing_buffers ()
{
/* called from butler thread */
- DEBUG_TRACE (DEBUG::DiskIO, string_compose ("%1 overwriting existing buffers at %2 (because %3%4%5\n", owner()->name(), overwrite_sample, std::hex, g_atomic_int_get (&_pending_overwrite), std::dec));
+ DEBUG_TRACE (DEBUG::DiskIO, string_compose ("%1 overwriting existing buffers at %2 (because %3%4%5\n", owner ()->name (), overwrite_sample, std::hex, g_atomic_int_get (&_pending_overwrite), std::dec));
bool ret = true;
- if (g_atomic_int_get (&_pending_overwrite) & (PlaylistModified|LoopDisabled|LoopChanged|PlaylistChanged)) {
+ if (g_atomic_int_get (&_pending_overwrite) & (PlaylistModified | LoopDisabled | LoopChanged | PlaylistChanged)) {
if (_playlists[DataType::AUDIO] && !overwrite_existing_audio ()) {
ret = false;
}
}
- if (g_atomic_int_get (&_pending_overwrite) & (PlaylistModified|PlaylistChanged)) {
+ if (g_atomic_int_get (&_pending_overwrite) & (PlaylistModified | PlaylistChanged)) {
if (_playlists[DataType::MIDI] && !overwrite_existing_midi ()) {
ret = false;
}
@@ -751,12 +732,13 @@ DiskReader::seek (samplepos_t sample, bool complete_refill)
/* called via non_realtime_locate() from butler thread */
int ret = -1;
+
const bool read_reversed = !_session.transport_will_roll_forwards ();
- const bool read_loop = (bool) _loop_location;
+ const bool read_loop = (bool)_loop_location;
- boost::shared_ptr<ChannelList> c = channels.reader();
+ boost::shared_ptr<ChannelList> c = channels.reader ();
- if (c->empty()) {
+ if (c->empty ()) {
return 0;
}
@@ -769,12 +751,11 @@ DiskReader::seek (samplepos_t sample, bool complete_refill)
*/
if ((_last_read_reversed.value_or (read_reversed) == read_reversed) && (_last_read_loop.value_or (read_loop) == read_loop)) {
-
if (sample == playback_sample && !complete_refill) {
return 0;
}
- if (abs (sample - playback_sample) < (c->front()->rbuf->reserved_size() / 6)) {
+ if (abs (sample - playback_sample) < (c->front ()->rbuf->reserved_size () / 6)) {
/* we're close enough. Note: this is a heuristic */
return 0;
}
@@ -782,7 +763,7 @@ DiskReader::seek (samplepos_t sample, bool complete_refill)
g_atomic_int_set (&_pending_overwrite, 0);
- DEBUG_TRACE (DEBUG::DiskIO, string_compose ("DiskReader::seek %1 %2 -> %3 refill=%4\n", owner()->name().c_str(), playback_sample, sample, complete_refill));
+ DEBUG_TRACE (DEBUG::DiskIO, string_compose ("DiskReader::seek %1 %2 -> %3 refill=%4\n", owner ()->name ().c_str (), playback_sample, sample, complete_refill));
const samplecnt_t distance = sample - playback_sample;
if (!complete_refill && can_internal_playback_seek (distance)) {
@@ -790,26 +771,25 @@ DiskReader::seek (samplepos_t sample, bool complete_refill)
return 0;
}
- for (ChannelList::iterator chan = c->begin(); chan != c->end(); ++chan) {
+ for (ChannelList::iterator chan = c->begin (); chan != c->end (); ++chan) {
(*chan)->rbuf->reset ();
- assert ((*chan)->rbuf->reserved_size() == 0);
+ assert ((*chan)->rbuf->reserved_size () == 0);
}
/* move the intended read target, so that after the refill is done,
- the intended read target is "reservation" from the start of the
- playback buffer. Then increment the read ptr, so that we can
- potentially do an internal seek backwards of up "reservation"
- samples.
- */
+ * the intended read target is "reservation" from the start of the
+ * playback buffer. Then increment the read ptr, so that we can
+ * potentially do an internal seek backwards of up "reservation"
+ * samples.
+ */
- samplecnt_t shift = sample > c->front()->rbuf->reservation_size() ? c->front()->rbuf->reservation_size() : sample;
+ samplecnt_t shift = sample > c->front ()->rbuf->reservation_size () ? c->front ()->rbuf->reservation_size () : sample;
// shift = 0;
if (read_reversed) {
/* reading in reverse, so start at a later sample, and read
- "backwards" from there.
- */
+ * "backwards" from there. */
shift = -shift;
}
@@ -817,24 +797,21 @@ DiskReader::seek (samplepos_t sample, bool complete_refill)
sample -= shift;
- playback_sample = sample;
+ playback_sample = sample;
file_sample[DataType::AUDIO] = sample;
- file_sample[DataType::MIDI] = sample;
+ file_sample[DataType::MIDI] = sample;
if (complete_refill) {
/* call _do_refill() to refill the entire buffer, using
- the largest reads possible.
- */
- while ((ret = do_refill_with_alloc (false, read_reversed)) > 0) ;
+ * the largest reads possible. */
+ while ((ret = do_refill_with_alloc (false, read_reversed)) > 0)
+ ;
} else {
- /* call _do_refill() to refill just one chunk, and then
- return.
- */
+ /* call _do_refill() to refill just one chunk, and then return. */
ret = do_refill_with_alloc (true, read_reversed);
}
if (shift) {
-
/* now tell everyone where we really are, leaving the
* "reserved" data represented by "shift" available in the
* buffer for backwards-internal-seek
@@ -849,7 +826,7 @@ DiskReader::seek (samplepos_t sample, bool complete_refill)
shift = abs (shift);
- for (ChannelList::iterator chan = c->begin(); chan != c->end(); ++chan) {
+ for (ChannelList::iterator chan = c->begin (); chan != c->end (); ++chan) {
(*chan)->rbuf->increment_read_ptr (shift);
}
}
@@ -862,10 +839,10 @@ DiskReader::can_internal_playback_seek (sampleoffset_t distance)
{
/* 1. Audio */
- ChannelList::iterator chan;
- boost::shared_ptr<ChannelList> c = channels.reader();
+ ChannelList::iterator chan;
+ boost::shared_ptr<ChannelList> c = channels.reader ();
- for (chan = c->begin(); chan != c->end(); ++chan) {
+ for (chan = c->begin (); chan != c->end (); ++chan) {
if (!(*chan)->rbuf->can_seek (distance)) {
return false;
}
@@ -885,9 +862,9 @@ DiskReader::internal_playback_seek (sampleoffset_t distance)
sampleoffset_t off = distance;
- ChannelList::iterator chan;
- boost::shared_ptr<ChannelList> c = channels.reader();
- for (chan = c->begin(); chan != c->end(); ++chan) {
+ ChannelList::iterator chan;
+ boost::shared_ptr<ChannelList> c = channels.reader ();
+ for (chan = c->begin (); chan != c->end (); ++chan) {
if (distance < 0) {
off = 0 - (sampleoffset_t) (*chan)->rbuf->decrement_read_ptr (::llabs (distance));
} else {
@@ -898,13 +875,13 @@ DiskReader::internal_playback_seek (sampleoffset_t distance)
playback_sample += off;
}
-static
-void swap_by_ptr (Sample *first, Sample *last)
+static void
+swap_by_ptr (Sample* first, Sample* last)
{
while (first < last) {
Sample tmp = *first;
- *first++ = *last;
- *last-- = tmp;
+ *first++ = *last;
+ *last-- = tmp;
}
}
@@ -916,26 +893,25 @@ void swap_by_ptr (Sample *first, Sample *last)
* @param reversed true if we are running backwards, otherwise false.
*/
samplecnt_t
-DiskReader::audio_read (Sample* sum_buffer,
- Sample* mixdown_buffer,
- float* gain_buffer,
- samplepos_t& start,
- samplecnt_t cnt,
+DiskReader::audio_read (Sample* sum_buffer,
+ Sample* mixdown_buffer,
+ float* gain_buffer,
+ samplepos_t& start,
+ samplecnt_t cnt,
ReaderChannelInfo* rci,
- int channel,
- bool reversed)
+ int channel,
+ bool reversed)
{
- samplecnt_t this_read = 0;
- bool reloop = false;
- samplepos_t loop_end = 0;
- samplepos_t loop_start = 0;
- Location *loc = 0;
- const samplecnt_t rcnt = cnt;
+ samplecnt_t this_read = 0;
+ bool reloop = false;
+ samplepos_t loop_end = 0;
+ samplepos_t loop_start = 0;
+ Location* loc = 0;
+ const samplecnt_t rcnt = cnt;
/* XXX we don't currently play loops in reverse. not sure why */
if (!reversed) {
-
samplecnt_t loop_length = 0;
/* Make the use of a Location atomic for this read operation.
@@ -947,19 +923,18 @@ DiskReader::audio_read (Sample* sum_buffer,
*/
if ((loc = _loop_location) != 0) {
- loop_start = loc->start();
- loop_end = loc->end();
+ loop_start = loc->start ();
+ loop_end = loc->end ();
loop_length = loop_end - loop_start;
}
- /* if we are looping, ensure that the first sample we read is at the correct
- position within the loop.
+ /* if we are looping, ensure that the first sample we read is at the
+ * correct position within the loop.
*/
if (loc && start >= loop_end) {
start = loop_start + ((start - loop_start) % loop_length);
}
-
}
if (reversed) {
@@ -967,18 +942,16 @@ DiskReader::audio_read (Sample* sum_buffer,
}
/* We need this while loop in case we hit a loop boundary, in which case our read from
- the playlist must be split into more than one section.
- */
+ * the playlist must be split into more than one section. */
while (cnt) {
-
/* take any loop into account. we can't read past the end of the loop. */
if (loc && (loop_end - start < cnt)) {
this_read = loop_end - start;
- reloop = true;
+ reloop = true;
} else {
- reloop = false;
+ reloop = false;
this_read = cnt;
}
@@ -993,37 +966,34 @@ DiskReader::audio_read (Sample* sum_buffer,
* useful after the return from AudioPlayback::read()
*/
- if (audio_playlist()->read (sum_buffer, mixdown_buffer, gain_buffer, start, this_read, channel) != this_read) {
- error << string_compose(_("DiskReader %1: cannot read %2 from playlist at sample %3"), id(), this_read, start) << endmsg;
+ if (audio_playlist ()->read (sum_buffer, mixdown_buffer, gain_buffer, start, this_read, channel) != this_read) {
+ error << string_compose (_("DiskReader %1: cannot read %2 from playlist at sample %3"), id (), this_read, start) << endmsg;
return 0;
}
if (loc) {
-
/* Looping: do something (maybe) about the loop boundaries */
- switch (Config->get_loop_fade_choice()) {
- case NoLoopFade:
- break;
- case BothLoopFade:
- loop_declick_in.run (sum_buffer, start, start + this_read);
- loop_declick_out.run (sum_buffer, start, start + this_read);
- break;
- case EndLoopFade:
- loop_declick_out.run (sum_buffer, start, start + this_read);
- break;
- case XFadeLoop:
- maybe_xfade_loop (sum_buffer, start, start + this_read, rci);
- break;
+ switch (Config->get_loop_fade_choice ()) {
+ case NoLoopFade:
+ break;
+ case BothLoopFade:
+ loop_declick_in.run (sum_buffer, start, start + this_read);
+ loop_declick_out.run (sum_buffer, start, start + this_read);
+ break;
+ case EndLoopFade:
+ loop_declick_out.run (sum_buffer, start, start + this_read);
+ break;
+ case XFadeLoop:
+ maybe_xfade_loop (sum_buffer, start, start + this_read, rci);
+ break;
}
}
if (reversed) {
-
swap_by_ptr (sum_buffer, sum_buffer + this_read - 1);
} else {
-
/* if we read to the end of the loop, go back to the beginning */
if (reloop) {
@@ -1038,7 +1008,7 @@ DiskReader::audio_read (Sample* sum_buffer,
}
_last_read_reversed = reversed;
- _last_read_loop = (bool) loc;
+ _last_read_loop = (bool)loc;
return rcnt;
}
@@ -1054,37 +1024,36 @@ int
DiskReader::do_refill_with_alloc (bool partial_fill, bool reversed)
{
/* We limit disk reads to at most 4MB chunks, which with floating point
- 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).
- */
+ * 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).
+ */
- boost::scoped_array<Sample> sum_buf (new Sample[2*1048576]);
- boost::scoped_array<Sample> mix_buf (new Sample[2*1048576]);
- boost::scoped_array<float> gain_buf (new float[2*1048576]);
+ boost::scoped_array<Sample> sum_buf (new Sample[2 * 1048576]);
+ boost::scoped_array<Sample> mix_buf (new Sample[2 * 1048576]);
+ boost::scoped_array<float> gain_buf (new float[2 * 1048576]);
- return refill_audio (sum_buf.get(), mix_buf.get(), gain_buf.get(), (partial_fill ? _chunk_samples : 0), reversed);
+ return refill_audio (sum_buf.get (), mix_buf.get (), gain_buf.get (), (partial_fill ? _chunk_samples : 0), reversed);
}
int
DiskReader::refill (Sample* sum_buffer, Sample* mixdown_buffer, float* gain_buffer, samplecnt_t fill_level, bool reversed)
{
/* NOTE: Audio refill MUST come first so that in contexts where ONLY it
- is called, _last_read_reversed is set correctly.
- */
+ * is called, _last_read_reversed is set correctly.
+ */
if (refill_audio (sum_buffer, mixdown_buffer, gain_buffer, fill_level, reversed)) {
return -1;
}
- if (rt_midibuffer() && (reversed != rt_midibuffer()->reversed())) {
- rt_midibuffer()->reverse ();
+ if (rt_midibuffer () && (reversed != rt_midibuffer ()->reversed ())) {
+ rt_midibuffer ()->reverse ();
}
return 0;
}
-
/** Get some more data from disk and put it in our channels' bufs,
* if there is suitable space in them.
*
@@ -1101,29 +1070,29 @@ DiskReader::refill_audio (Sample* sum_buffer, Sample* mixdown_buffer, float* gai
useless redundant I/O.
*/
- if (_session.loading()) {
+ if (_session.loading ()) {
return 0;
}
- int32_t ret = 0;
- samplecnt_t zero_fill;
- uint32_t chan_n;
- ChannelList::iterator i;
- boost::shared_ptr<ChannelList> c = channels.reader();
+ int32_t ret = 0;
+ samplecnt_t zero_fill;
+ uint32_t chan_n;
+ ChannelList::iterator i;
+ boost::shared_ptr<ChannelList> c = channels.reader ();
_last_read_reversed = reversed;
- if (c->empty()) {
+ if (c->empty ()) {
return 0;
}
- assert(mixdown_buffer);
- assert(gain_buffer);
+ assert (mixdown_buffer);
+ assert (gain_buffer);
- samplecnt_t total_space = c->front()->rbuf->write_space();
+ samplecnt_t total_space = c->front ()->rbuf->write_space ();
if (total_space == 0) {
- DEBUG_TRACE (DEBUG::DiskIO, string_compose ("%1: no space to refill\n", name()));
+ DEBUG_TRACE (DEBUG::DiskIO, string_compose ("%1: no space to refill\n", name ()));
/* nowhere to write to */
return 0;
}
@@ -1138,27 +1107,27 @@ DiskReader::refill_audio (Sample* sum_buffer, Sample* mixdown_buffer, float* gai
}
/* if we're running close to normal speed and there isn't enough
- space to do disk_read_chunk_samples of I/O, then don't bother.
-
- at higher speeds, just do it because the sync between butler
- and audio thread may not be good enough.
-
- Note: it is a design assumption that disk_read_chunk_samples is smaller
- than the playback buffer size, so this check should never trip when
- the playback buffer is empty.
- */
+ * space to do disk_read_chunk_samples of I/O, then don't bother.
+ *
+ * at higher speeds, just do it because the sync between butler
+ * and audio thread may not be good enough.
+ *
+ * Note: it is a design assumption that disk_read_chunk_samples is smaller
+ * than the playback buffer size, so this check should never trip when
+ * the playback buffer is empty.
+ */
- DEBUG_TRACE (DEBUG::DiskIO, string_compose ("%1: space to refill %2 vs. chunk %3 (speed = %4)\n", name(), total_space, _chunk_samples, _session.transport_speed()));
- if ((total_space < _chunk_samples) && fabs (_session.transport_speed()) < 2.0f) {
+ DEBUG_TRACE (DEBUG::DiskIO, string_compose ("%1: space to refill %2 vs. chunk %3 (speed = %4)\n", name (), total_space, _chunk_samples, _session.transport_speed ()));
+ if ((total_space < _chunk_samples) && fabs (_session.transport_speed ()) < 2.0f) {
return 0;
}
/* when slaved, don't try to get too close to the read pointer. this
- leaves space for the buffer reversal to have something useful to
- work with.
- */
+ * leaves space for the buffer reversal to have something useful to
+ * work with.
+ */
- if (_slaved && total_space < (samplecnt_t) (c->front()->rbuf->bufsize() / 2)) {
+ if (_slaved && total_space < (samplecnt_t) (c->front ()->rbuf->bufsize () / 2)) {
DEBUG_TRACE (DEBUG::DiskIO, string_compose ("%1: not enough to refill while slaved\n", this));
return 0;
}
@@ -1166,10 +1135,9 @@ DiskReader::refill_audio (Sample* sum_buffer, Sample* mixdown_buffer, float* gai
samplepos_t fsa = file_sample[DataType::AUDIO];
if (reversed) {
-
if (fsa == 0) {
/* at start: nothing to do but fill with silence */
- for (chan_n = 0, i = c->begin(); i != c->end(); ++i, ++chan_n) {
+ for (chan_n = 0, i = c->begin (); i != c->end (); ++i, ++chan_n) {
ChannelInfo* chan (*i);
chan->rbuf->write_zero (chan->rbuf->write_space ());
}
@@ -1178,17 +1146,16 @@ DiskReader::refill_audio (Sample* sum_buffer, Sample* mixdown_buffer, float* gai
if (fsa < total_space) {
/* too close to the start: read what we can, and then zero fill the rest */
- zero_fill = total_space - fsa;
+ zero_fill = total_space - fsa;
total_space = fsa;
} else {
zero_fill = 0;
}
} else {
-
if (fsa == max_samplepos) {
/* at end: nothing to do but fill with silence */
- for (chan_n = 0, i = c->begin(); i != c->end(); ++i, ++chan_n) {
+ for (chan_n = 0, i = c->begin (); i != c->end (); ++i, ++chan_n) {
ChannelInfo* chan (*i);
chan->rbuf->write_zero (chan->rbuf->write_space ());
}
@@ -1197,7 +1164,7 @@ DiskReader::refill_audio (Sample* sum_buffer, Sample* mixdown_buffer, float* gai
if (fsa > max_samplepos - total_space) {
/* to close to the end: read what we can, and zero fill the rest */
- zero_fill = total_space - (max_samplepos - fsa);
+ zero_fill = total_space - (max_samplepos - fsa);
total_space = max_samplepos - fsa;
} else {
@@ -1206,8 +1173,8 @@ DiskReader::refill_audio (Sample* sum_buffer, Sample* mixdown_buffer, float* gai
}
/* total_space is in samples. We want to optimize read sizes in various sizes using bytes */
- const size_t bits_per_sample = format_data_width (_session.config.get_native_file_data_format());
- size_t total_bytes = total_space * bits_per_sample / 8;
+ const size_t bits_per_sample = format_data_width (_session.config.get_native_file_data_format ());
+ size_t total_bytes = total_space * bits_per_sample / 8;
/* chunk size range is 256kB to 4MB. Bigger is faster in terms of MB/sec, but bigger chunk size always takes longer */
size_t byte_size_for_read = max ((size_t) (256 * 1024), min ((size_t) (4 * 1048576), total_bytes));
@@ -1219,15 +1186,16 @@ DiskReader::refill_audio (Sample* sum_buffer, Sample* mixdown_buffer, float* gai
/* now back to samples */
samplecnt_t samples_to_read = byte_size_for_read / (bits_per_sample / 8);
- DEBUG_TRACE (DEBUG::DiskIO, string_compose ("%1: will refill %2 channels with %3 samples\n", name(), c->size(), total_space));
+ DEBUG_TRACE (DEBUG::DiskIO, string_compose ("%1: will refill %2 channels with %3 samples\n", name (), c->size (), total_space));
samplepos_t file_sample_tmp = fsa;
- // int64_t before = g_get_monotonic_time ();
- // int64_t elapsed;
-
- for (chan_n = 0, i = c->begin(); i != c->end(); ++i, ++chan_n) {
+#if 0
+ int64_t before = g_get_monotonic_time ();
+ int64_t elapsed;
+#endif
+ for (chan_n = 0, i = c->begin (); i != c->end (); ++i, ++chan_n) {
ChannelInfo* chan (*i);
/* we want all channels to read from the same position, but
@@ -1236,32 +1204,30 @@ DiskReader::refill_audio (Sample* sum_buffer, Sample* mixdown_buffer, float* gai
*/
file_sample_tmp = fsa;
- samplecnt_t ts = total_space;
+ samplecnt_t ts = total_space;
- samplecnt_t to_read = min (ts, (samplecnt_t) chan->rbuf->write_space ());
- to_read = min (to_read, samples_to_read);
+ samplecnt_t to_read = min (ts, (samplecnt_t)chan->rbuf->write_space ());
+ to_read = min (to_read, samples_to_read);
assert (to_read >= 0);
// cerr << owner()->name() << " to-read: " << to_read << endl;
if (to_read) {
ReaderChannelInfo* rci = dynamic_cast<ReaderChannelInfo*> (chan);
- samplecnt_t nread;
+ samplecnt_t nread;
if (!_playlists[DataType::AUDIO]) {
-
chan->rbuf->write_zero (to_read);
} else {
-
if ((nread = audio_read (sum_buffer, mixdown_buffer, gain_buffer, file_sample_tmp, to_read, rci, chan_n, reversed)) != to_read) {
- error << string_compose(_("DiskReader %1: when refilling, cannot read %2 from playlist at sample %3"), name(), to_read, fsa) << endmsg;
+ error << string_compose (_("DiskReader %1: when refilling, cannot read %2 from playlist at sample %3"), name (), to_read, fsa) << endmsg;
ret = -1;
goto out;
}
if (chan->rbuf->write (sum_buffer, nread) != nread) {
- error << string_compose(_("DiskReader %1: when refilling, cannot write %2 into buffer"), name(), nread) << endmsg;
+ error << string_compose (_("DiskReader %1: when refilling, cannot write %2 into buffer"), name (), nread) << endmsg;
ret = -1;
}
}
@@ -1275,20 +1241,22 @@ DiskReader::refill_audio (Sample* sum_buffer, Sample* mixdown_buffer, float* gai
}
}
- // elapsed = g_get_monotonic_time () - before;
- // cerr << '\t' << name() << ": bandwidth = " << (byte_size_for_read / 1048576.0) / (elapsed/1000000.0) << "MB/sec\n";
+#if 0
+ elapsed = g_get_monotonic_time () - before;
+ cerr << '\t' << name() << ": bandwidth = " << (byte_size_for_read / 1048576.0) / (elapsed/1000000.0) << "MB/sec\n";
+#endif
file_sample[DataType::AUDIO] = file_sample_tmp;
assert (file_sample[DataType::AUDIO] >= 0);
ret = ((total_space - samples_to_read) > _chunk_samples);
- out:
+out:
return ret;
}
void
-DiskReader::playlist_ranges_moved (list< Evoral::RangeMove<samplepos_t> > const & movements_samples, bool from_undo_or_shift)
+DiskReader::playlist_ranges_moved (list<Evoral::RangeMove<samplepos_t>> const& movements_samples, bool from_undo_or_shift)
{
/* If we're coming from an undo, it will have handled
* automation undo (it must, since automation-follows-regions
@@ -1307,67 +1275,64 @@ DiskReader::playlist_ranges_moved (list< Evoral::RangeMove<samplepos_t> > const
return;
}
- list< Evoral::RangeMove<double> > movements;
+ list<Evoral::RangeMove<double>> movements;
- for (list< Evoral::RangeMove<samplepos_t> >::const_iterator i = movements_samples.begin();
- i != movements_samples.end();
+ for (list<Evoral::RangeMove<samplepos_t>>::const_iterator i = movements_samples.begin ();
+ i != movements_samples.end ();
++i) {
-
- movements.push_back(Evoral::RangeMove<double>(i->from, i->length, i->to));
+ movements.push_back (Evoral::RangeMove<double> (i->from, i->length, i->to));
}
/* move panner automation */
- boost::shared_ptr<Pannable> pannable = _track->pannable();
- Evoral::ControlSet::Controls& c (pannable->controls());
-
- for (Evoral::ControlSet::Controls::iterator ci = c.begin(); ci != c.end(); ++ci) {
- boost::shared_ptr<AutomationControl> ac = boost::dynamic_pointer_cast<AutomationControl>(ci->second);
- if (!ac) {
- continue;
- }
- boost::shared_ptr<AutomationList> alist = ac->alist();
- if (!alist->size()) {
+ boost::shared_ptr<Pannable> pannable = _track->pannable ();
+ Evoral::ControlSet::Controls& c (pannable->controls ());
+
+ for (Evoral::ControlSet::Controls::iterator ci = c.begin (); ci != c.end (); ++ci) {
+ boost::shared_ptr<AutomationControl> ac = boost::dynamic_pointer_cast<AutomationControl> (ci->second);
+ if (!ac) {
+ continue;
+ }
+ boost::shared_ptr<AutomationList> alist = ac->alist ();
+ if (!alist->size ()) {
continue;
}
- XMLNode & before = alist->get_state ();
- bool const things_moved = alist->move_ranges (movements);
- if (things_moved) {
- _session.add_command (new MementoCommand<AutomationList> (
- *alist.get(), &before, &alist->get_state ()));
- }
- }
+ XMLNode& before = alist->get_state ();
+ bool const things_moved = alist->move_ranges (movements);
+ if (things_moved) {
+ _session.add_command (new MementoCommand<AutomationList> (
+ *alist.get (), &before, &alist->get_state ()));
+ }
+ }
/* move processor automation */
- _track->foreach_processor (boost::bind (&DiskReader::move_processor_automation, this, _1, movements_samples));
+ _track->foreach_processor (boost::bind (&DiskReader::move_processor_automation, this, _1, movements_samples));
}
void
-DiskReader::move_processor_automation (boost::weak_ptr<Processor> p, list< Evoral::RangeMove<samplepos_t> > const & movements_samples)
+DiskReader::move_processor_automation (boost::weak_ptr<Processor> p, list<Evoral::RangeMove<samplepos_t>> const& movements_samples)
{
boost::shared_ptr<Processor> processor (p.lock ());
if (!processor) {
return;
}
- list< Evoral::RangeMove<double> > movements;
- for (list< Evoral::RangeMove<samplepos_t> >::const_iterator i = movements_samples.begin(); i != movements_samples.end(); ++i) {
- movements.push_back(Evoral::RangeMove<double>(i->from, i->length, i->to));
+ list<Evoral::RangeMove<double>> movements;
+ for (list<Evoral::RangeMove<samplepos_t>>::const_iterator i = movements_samples.begin (); i != movements_samples.end (); ++i) {
+ movements.push_back (Evoral::RangeMove<double> (i->from, i->length, i->to));
}
set<Evoral::Parameter> const a = processor->what_can_be_automated ();
for (set<Evoral::Parameter>::const_iterator i = a.begin (); i != a.end (); ++i) {
- boost::shared_ptr<AutomationList> al = processor->automation_control(*i)->alist();
- if (!al->size()) {
+ boost::shared_ptr<AutomationList> al = processor->automation_control (*i)->alist ();
+ if (!al->size ()) {
continue;
}
- XMLNode & before = al->get_state ();
+ XMLNode& before = al->get_state ();
bool const things_moved = al->move_ranges (movements);
if (things_moved) {
_session.add_command (
- new MementoCommand<AutomationList> (
- *al.get(), &before, &al->get_state ()
- )
- );
+ new MementoCommand<AutomationList> (
+ *al.get (), &before, &al->get_state ()));
}
}
}
@@ -1390,9 +1355,9 @@ DiskReader::resolve_tracker (Evoral::EventSink<samplepos_t>& buffer, samplepos_t
void
DiskReader::get_midi_playback (MidiBuffer& dst, samplepos_t start_sample, samplepos_t end_sample, MonitorState ms, BufferSet& scratch_bufs, double speed, samplecnt_t disk_samples_to_consume)
{
- RTMidiBuffer* rtmb = rt_midibuffer();
+ RTMidiBuffer* rtmb = rt_midibuffer ();
- if (!rtmb || (rtmb->size() == 0)) {
+ if (!rtmb || (rtmb->size () == 0)) {
/* no data to read, so do nothing */
return;
}
@@ -1401,11 +1366,11 @@ DiskReader::get_midi_playback (MidiBuffer& dst, samplepos_t start_sample, sample
if (ms & MonitoringInput) {
/* data from disk needs to be *merged* not written into the
- dst, because it may contain input data that we want to
- monitor. Since RTMidiBuffer currently (Oct 2019) has no
- suitable method, put the disk data into a scratch buffer and
- then merge later.
- */
+ * dst, because it may contain input data that we want to
+ * monitor. Since RTMidiBuffer currently (Oct 2019) has no
+ * suitable method, put the disk data into a scratch buffer and
+ * then merge later.
+ */
target = &scratch_bufs.get_midi (0);
} else {
@@ -1417,31 +1382,27 @@ DiskReader::get_midi_playback (MidiBuffer& dst, samplepos_t start_sample, sample
}
if (!_no_disk_output) {
-
const samplecnt_t nframes = abs (end_sample - start_sample);
if (ms & MonitoringDisk) {
-
- /* disk data needed
- */
+ /* disk data needed */
Location* loc = _loop_location;
if (loc) {
/* Evoral::Range has inclusive range semantics. Ugh. Hence the -1 */
- const Evoral::Range<samplepos_t> loop_range (loc->start(), loc->end() - 1);
- samplepos_t effective_start = start_sample;
- samplecnt_t cnt = nframes;
- sampleoffset_t offset = 0;
+ const Evoral::Range<samplepos_t> loop_range (loc->start (), loc->end () - 1);
+ samplepos_t effective_start = start_sample;
+ samplecnt_t cnt = nframes;
+ sampleoffset_t offset = 0;
- DEBUG_TRACE (DEBUG::MidiDiskIO, string_compose ("LOOP read, loop is %1..%2 range is %3..%4 nf %5\n", loc->start(), loc->end(), start_sample, end_sample, nframes));
+ DEBUG_TRACE (DEBUG::MidiDiskIO, string_compose ("LOOP read, loop is %1..%2 range is %3..%4 nf %5\n", loc->start (), loc->end (), start_sample, end_sample, nframes));
do {
-
samplepos_t effective_end;
effective_start = loop_range.squish (effective_start);
- effective_end = min (effective_start + cnt, loc->end());
+ effective_end = min (effective_start + cnt, loc->end ());
assert (effective_end > effective_start);
const samplecnt_t this_read = effective_end - effective_start;
@@ -1474,9 +1435,9 @@ DiskReader::get_midi_playback (MidiBuffer& dst, samplepos_t start_sample, sample
if (ms & MonitoringInput) {
/* merges data from disk (in "target", which is a scratch
- buffer in this case) into the actual destination buffer
- (which holds existing input data).
- */
+ * buffer in this case) into the actual destination buffer
+ * (which holds existing input data).
+ */
dst.merge_from (*target, nframes);
}
}
@@ -1506,13 +1467,13 @@ void
DiskReader::dec_no_disk_output ()
{
/* this is called unconditionally when things happen that ought to end
- a period of "no disk output". It's OK for that to happen when there
- was no corresponding call to ::inc_no_disk_output(), but we must
- stop the value from becoming negative.
- */
+ * a period of "no disk output". It's OK for that to happen when there
+ * was no corresponding call to ::inc_no_disk_output(), but we must
+ * stop the value from becoming negative.
+ */
do {
- gint v = g_atomic_int_get (&_no_disk_output);
+ gint v = g_atomic_int_get (&_no_disk_output);
if (v > 0) {
if (g_atomic_int_compare_and_exchange (&_no_disk_output, v, v - 1)) {
break;
@@ -1549,12 +1510,12 @@ DiskReader::DeclickAmp::apply_gain (AudioBuffer& buf, samplecnt_t n_samples, con
return;
}
- const float a = _a;
+ const float a = _a;
Sample* const buffer = buf.data ();
const int max_nproc = 16;
- uint32_t remain = n_samples;
- uint32_t offset = buffer_offset;
+ uint32_t remain = n_samples;
+ uint32_t offset = buffer_offset;
while (remain > 0) {
uint32_t n_proc = remain > max_nproc ? max_nproc : remain;
@@ -1582,22 +1543,22 @@ DiskReader::DeclickAmp::apply_gain (AudioBuffer& buf, samplecnt_t n_samples, con
}
DiskReader::Declicker::Declicker ()
- : fade_start (0)
- , fade_end (0)
- , fade_length (0)
- , vec (0)
+ : fade_start (0)
+ , fade_end (0)
+ , fade_length (0)
+ , vec (0)
{
}
DiskReader::Declicker::~Declicker ()
{
- delete [] vec;
+ delete[] vec;
}
void
DiskReader::Declicker::alloc (samplecnt_t sr, bool fadein)
{
- delete [] vec;
+ delete[] vec;
vec = new Sample[loop_fade_length];
const float a = 1024.0f / sr;
@@ -1634,7 +1595,7 @@ DiskReader::Declicker::reset (samplepos_t loop_start, samplepos_t loop_end, bool
{
if (loop_start == loop_end) {
fade_start = 0;
- fade_end = 0;
+ fade_end = 0;
return;
}
@@ -1642,18 +1603,17 @@ DiskReader::Declicker::reset (samplepos_t loop_start, samplepos_t loop_end, bool
if (fadein) {
fade_start = loop_start;
- fade_end = loop_start + fade_length;
+ fade_end = loop_start + fade_length;
} else {
fade_start = loop_end - fade_length;
- fade_end = loop_end;
+ fade_end = loop_end;
}
-
}
void
DiskReader::Declicker::run (Sample* buf, samplepos_t read_start, samplepos_t read_end)
{
- samplecnt_t n; /* how many samples to process */
+ samplecnt_t n; /* how many samples to process */
sampleoffset_t bo; /* offset into buffer */
sampleoffset_t vo; /* offset into gain vector */
@@ -1661,60 +1621,61 @@ DiskReader::Declicker::run (Sample* buf, samplepos_t read_start, samplepos_t rea
return;
}
- /* Determine how the read range overlaps with the fade range, so we can determine which part of the fade gain vector
- to apply to which part of the buffer.
- */
+ /* Determine how the read range overlaps with the fade range, so we can determine
+ * which part of the fade gain vector to apply to which part of the buffer.
+ *
+ * see also DiskReader::maybe_xfade_loop()
+ */
switch (Evoral::coverage (fade_start, fade_end, read_start, read_end)) {
-
- case Evoral::OverlapInternal:
- /* note: start and end points cannot coincide (see evoral/Range.h)
- *
- * read range is entirely within fade range
- */
- bo = 0;
- vo = read_start - fade_start;
- n = read_end - read_start;
- break;
-
- case Evoral::OverlapExternal:
- /* read range extends on either side of fade range
- *
- * External allows coincidental start & end points, so check for that
- */
- if (fade_start == read_start && fade_end == read_end) {
- /* fade entire read ... this is SO unlikely ! */
+ case Evoral::OverlapInternal:
+ /* note: start and end points cannot coincide (see evoral/Range.h)
+ *
+ * read range is entirely within fade range
+ */
bo = 0;
+ vo = read_start - fade_start;
+ n = read_end - read_start;
+ break;
+
+ case Evoral::OverlapExternal:
+ /* read range extends on either side of fade range
+ *
+ * External allows coincidental start & end points, so check for that
+ */
+ if (fade_start == read_start && fade_end == read_end) {
+ /* fade entire read ... this is SO unlikely ! */
+ bo = 0;
+ vo = 0;
+ n = fade_end - fade_start;
+ } else {
+ bo = fade_start - read_start;
+ vo = 0;
+ n = fade_end - fade_start;
+ }
+ break;
+
+ case Evoral::OverlapStart:
+ /* read range starts before and ends within fade or at same end as fade */
+ n = fade_end - read_start;
vo = 0;
- n = fade_end - fade_start;
- } else {
bo = fade_start - read_start;
- vo = 0;
- n = fade_end - fade_start;
- }
- break;
-
- case Evoral::OverlapStart:
- /* read range starts before and ends within fade or at same end as fade */
- n = fade_end - read_start;
- vo = 0;
- bo = fade_start - read_start;
- break;
-
- case Evoral::OverlapEnd:
- /* read range starts within fade range, but possibly at it's end, so check */
- if (read_start == fade_end) {
- /* nothing to do */
- return;
- }
- bo = 0;
- vo = read_start - fade_start;
- n = fade_end - read_start;
- break;
+ break;
- case Evoral::OverlapNone:
- /* no overlap ... nothing to do */
- return;
+ case Evoral::OverlapEnd:
+ /* read range starts within fade range, but possibly at it's end, so check */
+ if (read_start == fade_end) {
+ /* nothing to do */
+ return;
+ }
+ bo = 0;
+ vo = read_start - fade_start;
+ n = fade_end - read_start;
+ break;
+
+ case Evoral::OverlapNone:
+ /* no overlap ... nothing to do */
+ return;
}
Sample* b = &buf[bo];
@@ -1728,71 +1689,72 @@ DiskReader::Declicker::run (Sample* buf, samplepos_t read_start, samplepos_t rea
void
DiskReader::maybe_xfade_loop (Sample* buf, samplepos_t read_start, samplepos_t read_end, ReaderChannelInfo* chan)
{
- samplecnt_t n; /* how many samples to process */
+ samplecnt_t n; /* how many samples to process */
sampleoffset_t bo; /* offset into buffer */
sampleoffset_t vo; /* offset into gain vector */
const samplepos_t fade_start = loop_declick_out.fade_start;
- const samplepos_t fade_end = loop_declick_out.fade_end;
+ const samplepos_t fade_end = loop_declick_out.fade_end;
if (fade_start == fade_end) {
return;
}
- /* Determine how the read range overlaps with the fade range, so we can determine which part of the fade gain vector
- to apply to which part of the buffer.
- */
+ /* Determine how the read range overlaps with the fade range, so we can determine
+ * which part of the fade gain vector to apply to which part of the buffer.
+ *
+ * see also DiskReader::Declicker::run()
+ */
switch (Evoral::coverage (fade_start, fade_end, read_start, read_end)) {
-
- case Evoral::OverlapInternal:
- /* note: start and end points cannot coincide (see evoral/Range.h)
- *
- * read range is entirely within fade range
- */
- bo = 0;
- vo = read_start - fade_start;
- n = read_end - read_start;
- break;
-
- case Evoral::OverlapExternal:
- /* read range extends on either side of fade range
- *
- * External allows coincidental start & end points, so check for that
- */
- if (fade_start == read_start && fade_end == read_end) {
- /* fade entire read ... this is SO unlikely ! */
+ case Evoral::OverlapInternal:
+ /* note: start and end points cannot coincide (see evoral/Range.h)
+ *
+ * read range is entirely within fade range
+ */
bo = 0;
+ vo = read_start - fade_start;
+ n = read_end - read_start;
+ break;
+
+ case Evoral::OverlapExternal:
+ /* read range extends on either side of fade range
+ *
+ * External allows coincidental start & end points, so check for that
+ */
+ if (fade_start == read_start && fade_end == read_end) {
+ /* fade entire read ... this is SO unlikely ! */
+ bo = 0;
+ vo = 0;
+ n = fade_end - fade_start;
+ } else {
+ bo = fade_start - read_start;
+ vo = 0;
+ n = fade_end - fade_start;
+ }
+ break;
+
+ case Evoral::OverlapStart:
+ /* read range starts before and ends within fade or at same end as fade */
+ n = fade_end - read_start;
vo = 0;
- n = fade_end - fade_start;
- } else {
bo = fade_start - read_start;
- vo = 0;
- n = fade_end - fade_start;
- }
- break;
-
- case Evoral::OverlapStart:
- /* read range starts before and ends within fade or at same end as fade */
- n = fade_end - read_start;
- vo = 0;
- bo = fade_start - read_start;
- break;
-
- case Evoral::OverlapEnd:
- /* read range starts within fade range, but possibly at it's end, so check */
- if (read_start == fade_end) {
- /* nothing to do */
- return;
- }
- bo = 0;
- vo = read_start - fade_start;
- n = fade_end - read_start;
- break;
+ break;
- case Evoral::OverlapNone:
- /* no overlap ... nothing to do */
- return;
+ case Evoral::OverlapEnd:
+ /* read range starts within fade range, but possibly at it's end, so check */
+ if (read_start == fade_end) {
+ /* nothing to do */
+ return;
+ }
+ bo = 0;
+ vo = read_start - fade_start;
+ n = fade_end - read_start;
+ break;
+
+ case Evoral::OverlapNone:
+ /* no overlap ... nothing to do */
+ return;
}
Sample* b = &buf[bo]; /* data to be faded out */
@@ -1821,7 +1783,7 @@ DiskReader::rt_midibuffer ()
return 0;
}
- return mpl->rendered();
+ return mpl->rendered ();
}
void
@@ -1838,8 +1800,8 @@ void
DiskReader::reset_loop_declick (Location* loc, samplecnt_t sr)
{
if (loc) {
- loop_declick_in.reset (loc->start(), loc->end(), true, sr);
- loop_declick_out.reset (loc->start(), loc->end(), false, sr);
+ loop_declick_in.reset (loc->start (), loc->end (), true, sr);
+ loop_declick_out.reset (loc->start (), loc->end (), false, sr);
} else {
loop_declick_in.reset (0, 0, true, sr);
loop_declick_out.reset (0, 0, false, sr);
@@ -1865,29 +1827,27 @@ DiskReader::reload_loop ()
return;
}
- boost::shared_ptr<ChannelList> c = channels.reader();
+ boost::shared_ptr<ChannelList> c = channels.reader ();
- if (c->empty() || !_playlists[DataType::AUDIO]) {
+ if (c->empty () || !_playlists[DataType::AUDIO]) {
return;
}
- Location* loc = _loop_location;
- boost::scoped_array<Sample> mix_buf (new Sample [loop_fade_length]);
- boost::scoped_array<Sample> gain_buf (new Sample [loop_fade_length]);
+ Location* loc = _loop_location;
+ boost::scoped_array<Sample> mix_buf (new Sample[loop_fade_length]);
+ boost::scoped_array<Sample> gain_buf (new Sample[loop_fade_length]);
uint32_t channel = 0;
- for (ChannelList::iterator chan = c->begin(); chan != c->end(); ++chan, ++channel) {
-
+ for (ChannelList::iterator chan = c->begin (); chan != c->end (); ++chan, ++channel) {
ReaderChannelInfo* rci = dynamic_cast<ReaderChannelInfo*> (*chan);
rci->resize_preloop (loop_fade_length);
- if (loc->start() > loop_fade_length) {
- audio_playlist()->read (rci->pre_loop_buffer, mix_buf.get(), gain_buf.get(), loc->start() - loop_declick_out.fade_length, loop_declick_out.fade_length, channel);
+ if (loc->start () > loop_fade_length) {
+ audio_playlist ()->read (rci->pre_loop_buffer, mix_buf.get (), gain_buf.get (), loc->start () - loop_declick_out.fade_length, loop_declick_out.fade_length, channel);
} else {
memset (rci->pre_loop_buffer, 0, sizeof (Sample) * loop_fade_length);
}
-
}
}