merge AudioDiskstream playback code into DiskReader

This commit is contained in:
Paul Davis 2017-03-06 12:47:46 +01:00
parent 46366541b1
commit c05cfe3328
5 changed files with 1208 additions and 121 deletions

View File

@ -30,131 +30,93 @@ namespace ARDOUR {
class Session;
class Route;
class Location;
class LIBARDOUR_API DiskIOProcessor : public Processor
{
public:
enum Flag {
Recordable = 0x1,
Hidden = 0x2,
Destructive = 0x4,
NonLayered = 0x8
};
static const std::string state_node_name;
DiskIOProcessor(Session&, const std::string& name);
void run (BufferSet& /*bufs*/, framepos_t /*start_frame*/, framepos_t /*end_frame*/, double speed, pframes_t /*nframes*/, bool /*result_required*/) {}
void silence (framecnt_t /*nframes*/, framepos_t /*start_frame*/) {}
bool configure_io (ChanCount in, ChanCount out);
bool can_support_io_configuration (const ChanCount& in, ChanCount& out) = 0;
ChanCount input_streams () const { return _configured_input; }
ChanCount output_streams() const { return _configured_output; }
virtual void realtime_handle_transport_stopped () {}
virtual void realtime_locate () {}
/* note: derived classes should implement state(), NOT get_state(), to allow
us to merge C++ inheritance and XML lack-of-inheritance reasonably
smoothly.
*/
virtual XMLNode& state (bool full);
XMLNode& get_state (void);
int set_state (const XMLNode&, int version);
static framecnt_t disk_read_frames() { return disk_read_chunk_frames; }
static framecnt_t disk_write_frames() { return disk_write_chunk_frames; }
static void set_disk_read_chunk_frames (framecnt_t n) { disk_read_chunk_frames = n; }
static void set_disk_write_chunk_frames (framecnt_t n) { disk_write_chunk_frames = n; }
static framecnt_t default_disk_read_chunk_frames ();
static framecnt_t default_disk_write_chunk_frames ();
DiskIOProcessor (Session&, const std::string& name, Flag f);
static void set_buffering_parameters (BufferingPreset bp);
protected:
static framecnt_t disk_read_chunk_frames;
static framecnt_t disk_write_chunk_frames;
/** @return A number between 0 and 1, where 0 indicates that the playback buffer
* is dry (ie the disk subsystem could not keep up) and 1 indicates that the
* buffer is full.
*/
virtual float playback_buffer_load() const = 0;
virtual float capture_buffer_load() const = 0;
void set_flag (Flag f) { _flags = Flag (_flags | f); }
void unset_flag (Flag f) { _flags = Flag (_flags & ~f); }
bool hidden() const { return _flags & Hidden; }
bool recordable() const { return _flags & Recordable; }
bool non_layered() const { return _flags & NonLayered; }
bool reversed() const { return _actual_speed < 0.0f; }
double speed() const { return _visible_speed; }
ChanCount n_channels() { return _n_channels; }
void non_realtime_set_speed ();
bool realtime_set_speed (double sp, bool global);
virtual void punch_in() {}
virtual void punch_out() {}
virtual float buffer_load() const = 0;
bool slaved() const { return _slaved; }
void set_slaved(bool yn) { _slaved = yn; }
int set_loop (Location *loc);
PBD::Signal1<void,Location *> LoopSet;
PBD::Signal0<void> SpeedChanged;
PBD::Signal0<void> ReverseChanged;
int set_state (const XMLNode&, int version);
protected:
friend class Auditioner;
virtual int seek (framepos_t which_sample, bool complete_refill = false) = 0;
protected:
Flag _flags;
uint32_t i_am_the_modifier;
Track* _track;
ChanCount _n_channels;
double _visible_speed;
double _actual_speed;
double _speed;
double _target_speed;
/* items needed for speed change logic */
bool _buffer_reallocation_required;
bool _seek_required;
bool _slaved;
Location* loop_location;
double _speed;
double _target_speed;
bool in_set_state;
framecnt_t wrap_buffer_size;
framecnt_t speed_buffer_size;
Glib::Threads::Mutex state_lock;
Flag _flags;
static bool get_buffering_presets (BufferingPreset bp,
framecnt_t& read_chunk_size,
framecnt_t& read_buffer_size,
framecnt_t& write_chunk_size,
framecnt_t& write_buffer_size);
virtual void allocate_temporary_buffers () = 0;
};
class LIBARDOUR_API DiskReader : public DiskIOProcessor
{
public:
DiskReader (Session&, std::string const & name);
~DiskReader ();
private:
boost::shared_ptr<Playlist> _playlist;
framepos_t overwrite_frame;
off_t overwrite_offset;
bool _pending_overwrite;
bool overwrite_queued;
IOChange input_change_pending;
framecnt_t wrap_buffer_size;
framecnt_t speed_buffer_size;
double _speed;
double _target_speed;
/** The next frame position that we should be reading from in our playlist */
framepos_t file_frame;
framepos_t playback_sample;
PBD::ScopedConnectionList playlist_connections;
PBD::ScopedConnection ic_connection;
};
class LIBARDOUR_API DiskWriter : public DiskIOProcessor
{
public:
DiskWriter (Session&, std::string const & name);
~DiskWriter ();
private:
std::vector<CaptureInfo*> capture_info;
mutable Glib::Threads::Mutex capture_info_lock;
double _visible_speed;
double _actual_speed;
/* items needed for speed change logic */
bool _buffer_reallocation_required;
bool _seek_required;
/** Start of currently running capture in session frames */
framepos_t capture_start_frame;
framecnt_t capture_captured;
bool was_recording;
framecnt_t adjust_capture_position;
framecnt_t _capture_offset;
framepos_t first_recordable_frame;
framepos_t last_recordable_frame;
int last_possibly_recording;
AlignStyle _alignment_style;
AlignChoice _alignment_choice;
framecnt_t wrap_buffer_size;
framecnt_t speed_buffer_size;
std::string _write_source_name;
PBD::ScopedConnection ic_connection;
};
} // namespace ARDOUR
#endif /* __ardour_processor_h__ */
#endif /* __ardour_disk_io_h__ */

View File

@ -20,7 +20,11 @@
#ifndef __ardour_disk_reader_h__
#define __ardour_disk_reader_h__
#include "pbd/ringbufferNPT.h"
#include "pbd/rcu.h"
#include "ardour/disk_io.h"
#include "ardour/interpolation.h"
namespace ARDOUR
{
@ -42,13 +46,14 @@ class LIBARDOUR_API DiskReader : public DiskIOProcessor
static void set_chunk_frames (framecnt_t n) { _chunk_frames = n; }
void run (BufferSet& /*bufs*/, framepos_t /*start_frame*/, framepos_t /*end_frame*/, double speed, pframes_t /*nframes*/, bool /*result_required*/);
void silence (framecnt_t /*nframes*/, framepos_t /*start_frame*/);
int set_block_size (pframes_t);
bool configure_io (ChanCount in, ChanCount out);
bool can_support_io_configuration (const ChanCount& in, ChanCount& out) = 0;
ChanCount input_streams () const;
ChanCount output_streams() const;
void realtime_handle_transport_stopped ();
void realtime_locate ();
void non_realtime_locate (framepos_t);
int overwrite_existing_buffers ();
void set_pending_overwrite (bool yn);
framecnt_t roll_delay() const { return _roll_delay; }
void set_roll_delay (framecnt_t);
@ -63,8 +68,8 @@ class LIBARDOUR_API DiskReader : public DiskIOProcessor
virtual void playlist_modified ();
virtual int use_playlist (boost::shared_ptr<Playlist>);
virtual int use_new_playlist () = 0;
virtual int use_copy_playlist () = 0;
virtual int use_new_playlist ();
virtual int use_copy_playlist ();
PBD::Signal0<void> PlaylistChanged;
PBD::Signal0<void> AlignmentStyleChanged;
@ -73,29 +78,48 @@ class LIBARDOUR_API DiskReader : public DiskIOProcessor
void move_processor_automation (boost::weak_ptr<Processor>, std::list<Evoral::RangeMove<framepos_t> > const &);
/* called by the Butler in a non-realtime context */
int do_refill () {
return _do_refill (_mixdown_buffer, _gain_buffer, 0);
}
/** For non-butler contexts (allocates temporary working buffers)
*
* This accessible method has a default argument; derived classes
* must inherit the virtual method that we call which does NOT
* have a default argument, to avoid complications with inheritance
*/
int do_refill_with_alloc(bool partial_fill = true) {
int do_refill_with_alloc (bool partial_fill = true) {
return _do_refill_with_alloc (partial_fill);
}
bool pending_overwrite () const { return _pending_overwrite; }
virtual int find_and_use_playlist (std::string const &) = 0;
virtual int find_and_use_playlist (std::string const &);
// Working buffers for do_refill (butler thread)
static void allocate_working_buffers();
static void free_working_buffers();
void adjust_buffering ();
int can_internal_playback_seek (framecnt_t distance);
int seek (framepos_t frame, bool complete_refill = false);
int add_channel (uint32_t how_many);
int remove_channel (uint32_t how_many);
PBD::Signal0<void> Underrun;
protected:
virtual int do_refill () = 0;
boost::shared_ptr<Playlist> _playlist;
virtual void playlist_changed (const PBD::PropertyChange&);
virtual void playlist_deleted (boost::weak_ptr<Playlist>);
virtual void playlist_ranges_moved (std::list< Evoral::RangeMove<framepos_t> > const &, bool);
private:
typedef std::map<DataType,boost::shared_ptr<Playlist> > Playlists;
@ -113,12 +137,61 @@ class LIBARDOUR_API DiskReader : public DiskIOProcessor
framecnt_t speed_buffer_size;
framepos_t file_frame;
framepos_t playback_sample;
MonitorChoice _monitoring_choice;
PBD::ScopedConnectionList playlist_connections;
virtual int _do_refill_with_alloc (bool partial_fill);
static framecnt_t _chunk_frames;
/** Information about one of our channels */
struct ChannelInfo : public boost::noncopyable {
ChannelInfo (framecnt_t buffer_size,
framecnt_t speed_buffer_size,
framecnt_t wrap_buffer_size);
~ChannelInfo ();
Sample *wrap_buffer;
Sample *speed_buffer;
Sample *current_buffer;
/** A ringbuffer for data to be played back, written to in the
butler thread, read from in the process thread.
*/
PBD::RingBufferNPT<Sample> *buf;
Sample* scrub_buffer;
Sample* scrub_forward_buffer;
Sample* scrub_reverse_buffer;
PBD::RingBufferNPT<Sample>::rw_vector read_vector;
void resize (framecnt_t);
};
typedef std::vector<ChannelInfo*> ChannelList;
SerializedRCUManager<ChannelList> channels;
CubicInterpolation interpolation;
int read (Sample* buf, Sample* mixdown_buffer, float* gain_buffer,
framepos_t& start, framecnt_t cnt,
int channel, bool reversed);
static Sample* _mixdown_buffer;
static gain_t* _gain_buffer;
int _do_refill (Sample *mixdown_buffer, float *gain_buffer, framecnt_t fill_level);
int add_channel_to (boost::shared_ptr<ChannelList>, uint32_t how_many);
int remove_channel_from (boost::shared_ptr<ChannelList>, uint32_t how_many);
int internal_playback_seek (framecnt_t distance);
frameoffset_t calculate_playback_distance (pframes_t);
void allocate_temporary_buffers();
};
} // namespace

View File

@ -2101,8 +2101,9 @@ AudioDiskstream::set_block_size (pframes_t /*nframes*/)
boost::shared_ptr<ChannelList> c = channels.reader();
for (ChannelList::iterator chan = c->begin(); chan != c->end(); ++chan) {
if ((*chan)->speed_buffer)
if ((*chan)->speed_buffer) {
delete [] (*chan)->speed_buffer;
}
(*chan)->speed_buffer = new Sample[speed_buffer_size];
}
}

File diff suppressed because it is too large Load Diff

View File

@ -67,6 +67,9 @@ libardour_sources = [
'delayline.cc',
'delivery.cc',
'directory_names.cc',
'disk_io.cc',
'disk_reader.cc',
'disk_writer.cc',
'diskstream.cc',
'dsp_filter.cc',
'ebur128_analysis.cc',