diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2019-12-06 14:21:40 -0700 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2019-12-07 10:30:38 -0700 |
commit | 238cc8ed5f65d6adceb672e09ab11357150ae47d (patch) | |
tree | ec5ec68494ae6ca96206d37ca85e22a40098a3c8 /libs/ardour/disk_io.cc | |
parent | 1008ac20ffcf4a88420c5c5a9a0b2396cca04f20 (diff) |
functional double buffering when using DiskReader::overwrite_existing_buffers
Diffstat (limited to 'libs/ardour/disk_io.cc')
-rw-r--r-- | libs/ardour/disk_io.cc | 59 |
1 files changed, 25 insertions, 34 deletions
diff --git a/libs/ardour/disk_io.cc b/libs/ardour/disk_io.cc index 9ac0d58750..d6d076099e 100644 --- a/libs/ardour/disk_io.cc +++ b/libs/ardour/disk_io.cc @@ -55,6 +55,9 @@ DiskIOProcessor::DiskIOProcessor (Session& s, string const & str, Flag f) , in_set_state (false) , playback_sample (0) , _need_butler (false) + , _switch_rbuf (false) + , process_rbuf (0) + , other_rbuf (1) , channels (new ChannelList) , _midi_buf (0) , _samples_written_to_ringbuffer (0) @@ -324,64 +327,52 @@ DiskIOProcessor::use_playlist (DataType dt, boost::shared_ptr<Playlist> playlist } DiskIOProcessor::ChannelInfo::ChannelInfo (samplecnt_t bufsize) - : _process_rbuf (0) - , _switch_rbuf (0) - , wbuf (0) + : wbuf (0) , capture_transition_buf (0) , curr_capture_cnt (0) { - _rbuf[0] = 0; - _rbuf[1] = 0; + rbuf[0] = 0; + rbuf[1] = 0; } DiskIOProcessor::ChannelInfo::~ChannelInfo () { - delete _rbuf[0]; - delete _rbuf[1]; + delete rbuf[0]; + delete rbuf[1]; delete wbuf; delete capture_transition_buf; - _rbuf[0] = 0; - _rbuf[1] = 0; + rbuf[0] = 0; + rbuf[1] = 0; wbuf = 0; capture_transition_buf = 0; } -PlaybackBuffer<Sample>* -DiskIOProcessor::ChannelInfo::process_rbuf() -{ - return _rbuf[g_atomic_int_get (&_process_rbuf)]; -} - -PlaybackBuffer<Sample>* -DiskIOProcessor::ChannelInfo::other_rbuf() +void +DiskIOProcessor::queue_switch_rbuf () { - return _rbuf[!g_atomic_int_get (&_process_rbuf)]; + /* must hold _rbuf_lock */ + _switch_rbuf = true; } void -DiskIOProcessor::ChannelInfo::maybe_switch_rbuf () +DiskIOProcessor::switch_rbufs () { - if (!g_atomic_int_get (&_switch_rbuf)) { - return; - } + /* must hold _rbuf_lock */ + assert (_switch_rbuf); - while (true) { - gint current_process_rbuf = g_atomic_int_get (&_process_rbuf); + std::swap (process_rbuf, other_rbuf); - if (g_atomic_int_compare_and_exchange (&_process_rbuf, current_process_rbuf, !_process_rbuf)) { - g_atomic_int_set (&_switch_rbuf, 0); - break; - } + boost::shared_ptr<ChannelList> c = channels.reader(); + + for (ChannelList::iterator chan = c->begin(); chan != c->end(); ++chan) { + (*chan)->rbuf[other_rbuf]->reset (); + cerr << name() << " after switch/reset, other has " << (*chan)->rbuf[other_rbuf]->write_space() << " of " << (*chan)->rbuf[other_rbuf]->bufsize() << endl; } -} -void -DiskIOProcessor::ChannelInfo::queue_switch_rbuf () -{ - g_atomic_int_set (&_switch_rbuf, 1); + _switch_rbuf = false; + cerr << "switched, pbuf now " << process_rbuf << " size " << c->front()->rbuf[process_rbuf]->bufsize() << " other " << other_rbuf << " size " << c->front()->rbuf[other_rbuf]->bufsize() << endl; } - void DiskIOProcessor::drop_track () { |