nframes_t wrap_buffer_size;
nframes_t speed_buffer_size;
- uint64_t last_phase;
- uint64_t phi;
- uint64_t target_phi;
+ uint64_t last_phase;
+
+ /// diskstream speed in 40.24 fixed point math
+ uint64_t phi;
+
+ /// target diskstream speed in 40.24 fixed point math
+ uint64_t target_phi;
nframes_t file_frame;
nframes_t playback_sample;
Type type;
Action action;
- nframes_t action_frame;
- nframes_t target_frame;
- float speed;
+ nframes_t action_frame;
+ nframes_t target_frame;
+ double speed;
union {
void* ptr;
list<AudioRange> audio_range;
list<MusicRange> music_range;
- Event(Type t, Action a, nframes_t when, nframes_t where, float spd, bool yn = false)
+ Event(Type t, Action a, nframes_t when, nframes_t where, double spd, bool yn = false)
: type (t),
action (a),
action_frame (when),
void set_session_end (nframes_t end) { end_location->set_start(end); _end_location_is_free = false; }
void use_rf_shuttle_speed ();
void allow_auto_play (bool yn);
- void request_transport_speed (float speed);
+ void request_transport_speed (double speed);
void request_overwrite_buffer (Diskstream*);
- void request_diskstream_speed (Diskstream&, float speed);
+ void request_diskstream_speed (Diskstream&, double speed);
void request_input_change_handling ();
bool locate_pending() const { return static_cast<bool>(post_transport_work&PostTransportLocate); }
void request_slave_source (SlaveSource);
bool synced_to_jack() const { return Config->get_slave_source() == JACK; }
- float transport_speed() const { return _transport_speed; }
+ double transport_speed() const { return _transport_speed; }
bool transport_stopped() const { return _transport_speed == 0.0f; }
bool transport_rolling() const { return _transport_speed != 0.0f; }
Location* start_location;
Slave* _slave;
bool _silent;
- volatile float _transport_speed;
- float _last_transport_speed;
+ volatile double _transport_speed;
+ double _last_transport_speed;
bool auto_play_legal;
nframes_t _last_slave_transport_frame;
nframes_t maximum_output_latency;
void locate (nframes_t, bool with_roll, bool with_flush, bool with_loop=false);
void start_locate (nframes_t, bool with_roll, bool with_flush, bool with_loop=false);
void force_locate (nframes_t frame, bool with_roll = false);
- void set_diskstream_speed (Diskstream*, float speed);
- void set_transport_speed (float speed, bool abort = false);
+ void set_diskstream_speed (Diskstream*, double speed);
+ void set_transport_speed (double speed, bool abort = false);
void stop_transport (bool abort = false);
void start_transport ();
void realtime_stop (bool abort);
* @param position - The transport position requested
* @return - The return value is currently ignored (see Session::follow_slave)
*/
- virtual bool speed_and_position (float& speed, nframes_t& position) = 0;
+ virtual bool speed_and_position (double& speed, nframes_t& position) = 0;
/**
* reports to ARDOUR whether the Slave is currently synced to its external
~MTC_Slave ();
void rebind (MIDI::Port&);
- bool speed_and_position (float&, nframes_t&);
+ bool speed_and_position (double&, nframes_t&);
bool locked() const;
bool ok() const;
nframes_t last_inbound_frame; /* when we got it; audio clocked */
MIDI::byte last_mtc_fps_byte;
- float mtc_speed;
+ double mtc_speed;
nframes_t first_mtc_frame;
nframes_t first_mtc_time;
static const int32_t accumulator_size = 128;
- float accumulator[accumulator_size];
+ double accumulator[accumulator_size];
int32_t accumulator_index;
bool have_first_accumulated_speed;
~MIDIClock_Slave ();
void rebind (MIDI::Port&);
- bool speed_and_position (float&, nframes_t&);
+ bool speed_and_position (double&, nframes_t&);
bool locked() const;
bool ok() const;
ADAT_Slave () {}
~ADAT_Slave () {}
- bool speed_and_position (float& speed, nframes_t& pos) {
+ bool speed_and_position (double& speed, nframes_t& pos) {
speed = 0;
pos = 0;
return false;
JACK_Slave (jack_client_t*);
~JACK_Slave ();
- bool speed_and_position (float& speed, nframes_t& pos);
+ bool speed_and_position (double& speed, nframes_t& pos);
bool starting() const { return _starting; }
bool locked() const;
private:
jack_client_t* jack;
- float speed;
+ double speed;
bool _starting;
};
nframes_t i = 0;
// Linearly interpolate into the alt buffer
- // using 40.24 fixp maths (swh)
-
+ // using 40.24 fixp maths
+ //
+ // Fixedpoint is just an integer with an implied scaling factor.
+ // In 40.24 the scaling factor is 2^24 = 16777216,
+ // so a value of 10*2^24 (in integer space) is equivalent to 10.0.
+ //
+ // The advantage is that addition and modulus [like x = (x + y) % 2^40]
+ // has no rounding errors and no drift, and just requires a single integer add.
+ // (swh)
+
+ // phi = fixed point speed
if (phi != target_phi) {
phi_delta = ((int64_t)(target_phi - phi)) / nframes;
} else {
for (chan = c->begin(); chan != c->end(); ++chan) {
- float fr;
+ Sample fractional_part;
ChannelInfo* chaninfo (*chan);
i = 0;
for (nframes_t outsample = 0; outsample < nframes; ++outsample) {
i = phase >> 24;
- fr = (phase & 0xFFFFFF) / 16777216.0f;
+ fractional_part = (phase & 0xFFFFFF) / 16777216.0f;
chaninfo->speed_buffer[outsample] =
- chaninfo->current_playback_buffer[i] * (1.0f - fr) +
- chaninfo->current_playback_buffer[i+1] * fr;
+ chaninfo->current_playback_buffer[i] * (1.0f - fractional_part) +
+ chaninfo->current_playback_buffer[i+1] * fractional_part;
phase += phi + phi_delta;
}
wrap_buffer_size = 0;
speed_buffer_size = 0;
last_phase = 0;
+ // speed = 1 in 40.24 fixed point math
phi = (uint64_t) (0x1000000);
target_phi = phi;
file_frame = 0;
JACK_Slave::JACK_Slave (jack_client_t* j)
: jack (j)
{
- float x;
+ double x;
nframes_t p;
/* call this to initialize things */
speed_and_position (x, p);
}
bool
-JACK_Slave::speed_and_position (float& sp, nframes_t& position)
+JACK_Slave::speed_and_position (double& sp, nframes_t& position)
{
jack_position_t pos;
jack_transport_state_t state;
// calculate loop error
// we use session.transport_frame() instead of t1 here
- // because t1 is used to calculate the transport speed, and since this
- // is float, the loop will compensate for accumulating rounding errors
+ // because t1 is used to calculate the transport speed,
+ // so the loop will compensate for accumulating rounding errors
e = (double(last_position) - double(session.transport_frame()))
/ double(session.frame_rate());
}
bool
-MIDIClock_Slave::speed_and_position (float& speed, nframes_t& pos)
+MIDIClock_Slave::speed_and_position (double& speed, nframes_t& pos)
{
if (!_started || _starting) {
speed = 0.0;
}
// calculate speed
- double speed_double = ((t1 - t0) * session.frame_rate()) / one_ppqn_in_frames;
- speed = float(speed_double);
+ speed = ((t1 - t0) * session.frame_rate()) / one_ppqn_in_frames;
// calculate position
if (engine_now > last_timestamp) {
// we are in between MIDI clock messages
// so we interpolate position according to speed
nframes_t elapsed = engine_now - last_timestamp;
- pos = nframes_t (last_position + double(elapsed) * speed_double);
+ pos = nframes_t (last_position + double(elapsed) * speed);
} else {
// A new MIDI clock message has arrived this cycle
pos = last_position;
}
bool
-MTC_Slave::speed_and_position (float& speed, nframes_t& pos)
+MTC_Slave::speed_and_position (double& speed, nframes_t& pos)
{
nframes_t now = session.engine().frame_time();
SafeTime last;
nframes_t frame_rate;
nframes_t elapsed;
- float speed_now;
+ double speed_now;
read_current (&last);
frame_rate = session.frame_rate();
- speed_now = (float) ((last.position - first_mtc_frame) / (double) (now - first_mtc_time));
+ speed_now = (double) ((last.position - first_mtc_frame) / (double) (now - first_mtc_time));
accumulator[accumulator_index++] = speed_now;
}
if (have_first_accumulated_speed) {
- float total = 0;
+ double total = 0;
for (int32_t i = 0; i < accumulator_size; ++i) {
total += accumulator[i];
bool
Session::follow_slave (nframes_t nframes, nframes_t offset)
{
- float slave_speed;
+ double slave_speed;
nframes_t slave_transport_frame;
nframes_t this_delta;
int dir;
}
void
-Session::request_transport_speed (float speed)
+Session::request_transport_speed (double speed)
{
Event* ev = new Event (Event::SetTransportSpeed, Event::Add, Event::Immediate, 0, speed);
queue_event (ev);
}
void
-Session::request_diskstream_speed (Diskstream& ds, float speed)
+Session::request_diskstream_speed (Diskstream& ds, double speed)
{
Event* ev = new Event (Event::SetDiskstreamSpeed, Event::Add, Event::Immediate, 0, speed);
ev->set_ptr (&ds);
{
if (synced_to_jack()) {
- float sp;
+ double sp;
nframes_t pos;
_slave->speed_and_position (sp, pos);
* @param abort
*/
void
-Session::set_transport_speed (float speed, bool abort)
+Session::set_transport_speed (double speed, bool abort)
{
if (_transport_speed == speed) {
return;
}
if (speed > 0) {
- speed = min (8.0f, speed);
+ speed = min (8.0, speed);
} else if (speed < 0) {
- speed = max (-8.0f, speed);
+ speed = max (-8.0, speed);
}
if (transport_rolling() && speed == 0.0) {
return;
}
- if (speed > 0.0f && _transport_frame == current_end_frame()) {
+ if (speed > 0.0 && _transport_frame == current_end_frame()) {
return;
}
- if (speed < 0.0f && _transport_frame == 0) {
+ if (speed < 0.0 && _transport_frame == 0) {
return;
}
before the last stop, then we have to do extra work.
*/
- if ((_transport_speed && speed * _transport_speed < 0.0f) || (_last_transport_speed * speed < 0.0f) || (_last_transport_speed == 0.0f && speed < 0.0f)) {
+ if ((_transport_speed && speed * _transport_speed < 0.0) || (_last_transport_speed * speed < 0.0) || (_last_transport_speed == 0.0f && speed < 0.0f)) {
post_transport_work = PostTransportWork (post_transport_work | PostTransportReverse);
last_stop_frame = _transport_frame;
}
}
void
-Session::set_diskstream_speed (Diskstream* stream, float speed)
+Session::set_diskstream_speed (Diskstream* stream, double speed)
{
if (stream->realtime_set_speed (speed, false)) {
post_transport_work = PostTransportWork (post_transport_work | PostTransportSpeed);
}
void
-BasicUI::set_transport_speed (float speed)
+BasicUI::set_transport_speed (double speed)
{
session->request_transport_speed (speed);
}
-float
+double
BasicUI::get_transport_speed ()
{
return session->transport_speed ();
void ffwd ();
void transport_stop ();
void transport_play (bool jump_back = true);
- void set_transport_speed (float speed);
- float get_transport_speed ();
+ void set_transport_speed (double speed);
+ double get_transport_speed ();
jack_nframes_t transport_frame ();
void locate (jack_nframes_t frame, bool play = false);