[nama] Fixing latency

Hello,
A few hours of digging and head scratching yielded this modest patch
which gets latency compensation working properly again. I tested briefly
and the numbers look good AFAICT. Remember that inserts aren't supported
yet (but you can add a delay equivalent to jack_period/sample_rate on
the dry arm of the insert for now) and that you need to use the -Q
option to enable latency compensation.

Cheers,
S.M.
-- 
diff --git a/src/Initializations.p b/src/Initializations.p
index eeeb226..0a54b68 100644
--- a/src/Initializations.p
+++ b/src/Initializations.p
@@ -143,8 +143,8 @@ sub definitions {
                latency_op_set                                  => sub
                        {
                                my $id = shift;
-                               my $frames = shift();
-                               
modify_effect($id,1,undef,$frames/$config->{sample_rate})
+                               my $delay = shift();
+                               modify_effect($id,2,undef,$delay)
                        },
        }, '::Config';
 
diff --git a/src/Latency.p b/src/Latency.p
index e533d98..baa42fe 100644
--- a/src/Latency.p
+++ b/src/Latency.p
@@ -19,14 +19,14 @@ sub set_latency_compensation {
        my $track = shift;
        my $delay = shift || 0;
        my $id = $track->latency_op;
-       $config->{latency_op_set}->($id, $delay);
+       $config->{latency_op_set}->($id, frames_to_secs($delay));
        $id;
 }
 sub add_latency_controller {
        my $track = shift;
        my $delay = shift;
        my $p = {};
-       $p->{values} = [$delay, 2];
+       $p->{values} = [2, frames_to_secs($delay)];
        $p->{type} = $config->{latency_op};
        $p->{cop_id} = $track->latency_op if $track->latency_op;
        $p->{before} = $track->ops->[0];
@@ -159,7 +159,7 @@ sub track_latency {
 
 }
 sub track_ops_latency {
-       # LADSPA plugins return latency in milliseconds
+       # LADSPA plugins return latency in frames
        my $track = shift;
        my $total = 0;;
        map { $total += op_latency($_) } $track->fancy_ops;
@@ -228,8 +228,8 @@ sub sibling_latency {
        return $max
 }
 sub loop_device_latency { 
-       # results in milliseconds
-       $engine->{buffersize} / $config->{sample_rate} * 1000 
+       # results in frames
+       $engine->{buffersize}; 
 }
 
 sub op_latency {
@@ -263,4 +263,10 @@ sub get_live_param { # for effect, not controller
        eval_iam("copp-select $param");
        eval_iam("copp-get")
 }
+
+sub frames_to_secs { # One time conversion for delay op
+       my $frames = shift;
+       $frames / $config->{sample_rate};
+}
+
 1;

Other related posts: