#include <ardour/ardour.h>
#include <ardour/audioengine.h>
+#include <ardour/analyser.h>
#include <ardour/audio_diskstream.h>
#include <ardour/utils.h>
#include <ardour/configuration.h>
{
string newname;
boost::shared_ptr<AudioPlaylist> playlist;
-
+
if (!in_set_state && destructive()) {
return 0;
}
/* if per-track or global rec-enable turned on while the other was already on, we've started recording */
- if ((change & track_rec_enabled) && record_enabled() && (!(change & global_rec_enabled) && can_record) ||
+ if (((change & track_rec_enabled) && record_enabled() && (!(change & global_rec_enabled) && can_record)) ||
((change & global_rec_enabled) && can_record && (!(change & track_rec_enabled) && record_enabled()))) {
/* starting to record: compute first+last frames */
first_recordable_frame = transport_frame + _capture_offset;
+ // cerr << "set FRF = " << transport_frame << " + " << _capture_offset << " = " << first_recordable_frame << endl;
last_recordable_frame = max_frames;
capture_start_frame = transport_frame;
/* was stopped, now rolling (and recording) */
if (_alignment_style == ExistingMaterial) {
- first_recordable_frame += _session.worst_output_latency();
+ //cerr << "A FRF += " << _session.worst_output_latency () << endl;
+ // first_recordable_frame += _session.worst_output_latency();
} else {
- first_recordable_frame += _roll_delay;
+ // cerr << "B FRF += " << _roll_delay<< endl;
+ // first_recordable_frame += _roll_delay;
}
} else {
this is needed.
*/
+ // cerr << "1 FRF += " << _capture_offset << endl;
first_recordable_frame += _capture_offset;
} else {
on the output latency.
*/
+ // cerr << "2 FRF += " << _session.worst_output_latency() << endl;
first_recordable_frame += _session.worst_output_latency();
}
} else {
if (Config->get_punch_in()) {
+ // cerr << "3 FRF += " << _roll_delay << endl;
first_recordable_frame += _roll_delay;
} else {
capture_start_frame -= _roll_delay;
}
- if (_flags & Recordable) {
+ // cerr << _name << " FRF = " << first_recordable_frame << " CSF = " << capture_start_frame << endl;
+
+ if (recordable() && destructive()) {
boost::shared_ptr<ChannelList> c = channels.reader();
for (ChannelList::iterator chan = c->begin(); chan != c->end(); ++chan) {
}
int
-AudioDiskstream::process (nframes_t transport_frame, nframes_t nframes, nframes_t offset, bool can_record, bool rec_monitors_input)
+AudioDiskstream::process (nframes_t transport_frame, nframes_t nframes, bool can_record, bool rec_monitors_input)
{
uint32_t n;
boost::shared_ptr<ChannelList> c = channels.reader();
return 0;
}
+ commit_should_unlock = false;
+
+ if (!_io || !_io->active()) {
+ _processed = true;
+ return 0;
+ }
+
check_record_status (transport_frame, nframes, can_record);
nominally_recording = (can_record && re);
if (!state_lock.trylock()) {
return 1;
}
-
+ commit_should_unlock = true;
adjust_capture_position = 0;
for (chan = c->begin(); chan != c->end(); ++chan) {
if (nominally_recording || (_session.get_record_enabled() && Config->get_punch_in())) {
OverlapType ot;
+ // Safeguard against situations where process() goes haywire when autopunching and last_recordable_frame < first_recordable_frame
+ if (last_recordable_frame < first_recordable_frame) {
+ last_recordable_frame = max_frames;
+
+ }
+
ot = coverage (first_recordable_frame, last_recordable_frame, transport_frame, transport_frame + nframes);
switch (ot) {
/* |--------| recrange
-------------- transrange
*/
- rec_nframes = last_recordable_frame - last_recordable_frame;
+ rec_nframes = last_recordable_frame - first_recordable_frame;
rec_offset = first_recordable_frame - transport_frame;
break;
}
if (nominally_recording || rec_nframes) {
- for (n = 0, chan = c->begin(); chan != c->end(); ++chan, ++n) {
+ uint32_t limit = _io->n_inputs ();
+
+ /* one or more ports could already have been removed from _io, but our
+ channel setup hasn't yet been updated. prevent us from trying to
+ use channels that correspond to missing ports. note that the
+ process callback (from which this is called) is always atomic
+ with respect to port removal/addition.
+ */
+
+ for (n = 0, chan = c->begin(); chan != c->end() && n < limit; ++chan, ++n) {
ChannelInfo* chaninfo (*chan);
rec_offset
*/
- memcpy (chaninfo->current_capture_buffer, _io->input(n)->get_buffer (rec_nframes) + offset + rec_offset, sizeof (Sample) * rec_nframes);
+ memcpy (chaninfo->current_capture_buffer, _io->get_input_buffer (n, rec_nframes) + rec_offset, sizeof (Sample) * rec_nframes);
} else {
goto out;
}
- Sample* buf = _io->input (n)->get_buffer (nframes) + offset;
+ Sample* buf = _io->get_input_buffer (n, nframes);
nframes_t first = chaninfo->capture_vector.len[0];
memcpy (chaninfo->capture_wrap_buffer, buf, sizeof (Sample) * first);
nframes_t total = chaninfo->playback_vector.len[0] + chaninfo->playback_vector.len[1];
if (necessary_samples > total) {
+ cerr << "underrun for " << _name << endl;
DiskUnderrun ();
goto out;
if (rec_nframes == 0 && _actual_speed != 1.0f && _actual_speed != -1.0f) {
uint64_t phase = last_phase;
+ int64_t phi_delta;
nframes_t i = 0;
// Linearly interpolate into the alt buffer
// using 40.24 fixp maths (swh)
+ if (phi != target_phi) {
+ phi_delta = ((int64_t)(target_phi - phi)) / nframes;
+ } else {
+ phi_delta = 0;
+ }
+
for (chan = c->begin(); chan != c->end(); ++chan) {
float fr;
chaninfo->speed_buffer[outsample] =
chaninfo->current_playback_buffer[i] * (1.0f - fr) +
chaninfo->current_playback_buffer[i+1] * fr;
- phase += phi;
+ phase += phi + phi_delta;
}
chaninfo->current_playback_buffer = chaninfo->speed_buffer;
}
- playback_distance = i + 1;
+ playback_distance = i; // + 1;
last_phase = (phase & 0xFFFFFF);
} else {
playback_distance = nframes;
}
+ phi = target_phi;
}
ret = 0;
be called. unlock the state lock.
*/
+ commit_should_unlock = false;
state_lock.unlock();
}
{
bool need_butler = false;
+ if (!_io || !_io->active()) {
+ return false;
+ }
+
if (_actual_speed < 0.0) {
playback_sample -= playback_distance;
} else {
}
if (_slaved) {
- need_butler = c->front()->playback_buf->write_space() >= c->front()->playback_buf->bufsize() / 2;
+ if (_io && _io->active()) {
+ need_butler = c->front()->playback_buf->write_space() >= c->front()->playback_buf->bufsize() / 2;
+ } else {
+ need_butler = false;
+ }
} else {
- need_butler = c->front()->playback_buf->write_space() >= disk_io_chunk_frames
- || c->front()->capture_buf->read_space() >= disk_io_chunk_frames;
+ if (_io && _io->active()) {
+ need_butler = c->front()->playback_buf->write_space() >= disk_io_chunk_frames
+ || c->front()->capture_buf->read_space() >= disk_io_chunk_frames;
+ } else {
+ need_butler = c->front()->capture_buf->read_space() >= disk_io_chunk_frames;
+ }
+ }
+
+ if (commit_should_unlock) {
+ state_lock.unlock();
}
- state_lock.unlock();
_processed = false;
return need_butler;
nframes_t loop_start = 0;
nframes_t loop_length = 0;
nframes_t offset = 0;
+ nframes_t xfade_samples = 0;
+ Sample xfade_buf[128];
Location *loc = 0;
/* XXX we don't currently play loops in reverse. not sure why */
return -1;
}
+ // xfade loop boundary if appropriate
+
+ if (xfade_samples > 0) {
+ // just do a linear xfade for this short bit
+
+ xfade_samples = min(xfade_samples, this_read);
+
+ float delta = 1.0f / xfade_samples;
+ float scale = 0.0f;
+ Sample * tmpbuf = buf+offset;
+
+ for (size_t i=0; i < xfade_samples; ++i) {
+ *tmpbuf = (*tmpbuf * scale) + xfade_buf[i]*(1.0f - scale);
+ ++tmpbuf;
+ scale += delta;
+ }
+
+ xfade_samples = 0;
+ }
+
_read_data_count = _playlist->read_data_count();
if (reversed) {
swap_by_ptr (buf, buf + this_read - 1);
} else {
-
+ start += this_read;
+
/* if we read to the end of the loop, go back to the beginning */
if (reloop) {
+ // read crossfade samples to apply to the next read
+
+ xfade_samples = min((nframes_t) 128, cnt-this_read);
+
+ if (audio_playlist()->read (xfade_buf, mixdown_buffer, gain_buffer, start, xfade_samples, channel) != xfade_samples) {
+ error << string_compose(_("AudioDiskstream %1: cannot read xfade samples %2 from playlist at frame %3"),
+ _id, xfade_samples,start) << endmsg;
+ memset(xfade_buf, 0, xfade_samples * sizeof(Sample)); // just in case
+ }
+
start = loop_start;
- } else {
- start += this_read;
}
}
vector.buf[1] = 0;
boost::shared_ptr<ChannelList> c = channels.reader();
- for (ChannelList::iterator chan = c->begin(); chan != c->end(); ++chan) {
+ int nn = 0;
+ for (ChannelList::iterator chan = c->begin(); chan != c->end(); ++chan, ++nn) {
(*chan)->capture_buf->get_read_vector (&vector);
s->update_header (capture_info.front()->start, when, twhen);
s->set_captured_for (_name);
s->mark_immutable ();
+ if (Config->get_auto_analyse_audio()) {
+ Analyser::queue_source_for_analysis (s, true);
+ }
}
}
capture_start_frame = 0;
}
+void
+AudioDiskstream::transport_looped (nframes_t transport_frame)
+{
+ if (was_recording) {
+ // all we need to do is finish this capture, with modified capture length
+ boost::shared_ptr<ChannelList> c = channels.reader();
+
+ // adjust the capture length knowing that the data will be recorded to disk
+ // only necessary after the first loop where we're recording
+ if (capture_info.size() == 0) {
+ capture_captured += _capture_offset;
+
+ if (_alignment_style == ExistingMaterial) {
+ capture_captured += _session.worst_output_latency();
+ } else {
+ capture_captured += _roll_delay;
+ }
+ }
+
+ finish_capture (true, c);
+
+ // the next region will start recording via the normal mechanism
+ // we'll set the start position to the current transport pos
+ // no latency adjustment or capture offset needs to be made, as that already happened the first time
+ capture_start_frame = transport_frame;
+ first_recordable_frame = transport_frame; // mild lie
+ last_recordable_frame = max_frames;
+ was_recording = true;
+
+ if (recordable() && destructive()) {
+ for (ChannelList::iterator chan = c->begin(); chan != c->end(); ++chan) {
+
+ RingBufferNPT<CaptureTransition>::rw_vector transvec;
+ (*chan)->capture_transition_buf->get_write_vector(&transvec);
+
+ if (transvec.len[0] > 0) {
+ transvec.buf[0]->type = CaptureStart;
+ transvec.buf[0]->capture_val = capture_start_frame;
+ (*chan)->capture_transition_buf->increment_write_ptr(1);
+ }
+ else {
+ // bad!
+ fatal << X_("programming error: capture_transition_buf is full on rec loop! inconceivable!")
+ << endmsg;
+ }
+ }
+ }
+
+ }
+}
+
void
AudioDiskstream::finish_capture (bool rec_monitors_input, boost::shared_ptr<ChannelList> c)
{
RingBufferNPT<CaptureTransition>::rw_vector transvec;
(*chan)->capture_transition_buf->get_write_vector(&transvec);
-
if (transvec.len[0] > 0) {
transvec.buf[0]->type = CaptureEnd;
transvec.buf[0]->capture_val = capture_captured;
{
g_atomic_int_set (&_record_enabled, 0);
boost::shared_ptr<ChannelList> c = channels.reader();
- for (ChannelList::iterator chan = c->begin(); chan != c->end(); ++chan) {
- if (Config->get_monitoring_model() == HardwareMonitoring) {
+ if (Config->get_monitoring_model() == HardwareMonitoring) {
+ for (ChannelList::iterator chan = c->begin(); chan != c->end(); ++chan) {
if ((*chan)->source) {
(*chan)->source->ensure_monitor_input (false);
}
if (nchans > _n_channels) {
add_channel (nchans - _n_channels);
+ IO::MoreOutputs(_n_channels);
} else if (nchans < _n_channels) {
up of the IO that owns this DS (::non_realtime_input_change())
*/
- in_set_state = false;
-
return 0;
}
boost::shared_ptr<ChannelList> c = channels.reader();
uint32_t n;
- if (!recordable()) {
+ if (!_session.writable() || !recordable()) {
return;
}
int
AudioDiskstream::remove_channel_from (boost::shared_ptr<ChannelList> c, uint32_t how_many)
{
- while (--how_many && !c->empty()) {
+ while (how_many-- && !c->empty()) {
delete c->back();
c->pop_back();
}
continue;
}
+ // This protects sessions from errant CapturingSources in stored sessions
+ struct stat sbuf;
+ if (stat (prop->value().c_str(), &sbuf)) {
+ continue;
+ }
+
try {
fs = boost::dynamic_pointer_cast<AudioFileSource> (SourceFactory::createWritable (_session, prop->value(), false, _session.frame_rate()));
}
playback_buf = new RingBufferNPT<Sample> (bufsize);
capture_buf = new RingBufferNPT<Sample> (bufsize);
- capture_transition_buf = new RingBufferNPT<CaptureTransition> (128);
+ capture_transition_buf = new RingBufferNPT<CaptureTransition> (256);
/* touch the ringbuffer buffers, which will cause
them to be mapped into locked physical RAM if