changeset 51:771ae8178180

Make Vamp plugins run
author Chris Cannam
date Mon, 07 Jan 2013 17:25:05 +0000
parents f9c4ec20ff62
children 5f1996de9ef5
files block.yeti fvector.yeti vamp.yeti
diffstat 3 files changed, 62 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/block.yeti	Sun Jan 06 21:56:19 2013 +0000
+++ b/block.yeti	Mon Jan 07 17:25:05 2013 +0000
@@ -12,6 +12,7 @@
 block v = v,
 data b = b,
 vector b = vec.copyOf b,
+floats = vec.floats,
 fromList l = vec.vector l,
 list = vec.list,
 length = vec.length,
@@ -27,6 +28,7 @@
 block is ~double[] -> block,
 data is block -> ~double[],
 vector is block -> ~double[],
+floats is block -> ~float[],
 fromList is list?<number> -> block,
 list is block -> list<number>,
 length is block -> number,
--- a/fvector.yeti	Sun Jan 06 21:56:19 2013 +0000
+++ b/fvector.yeti	Mon Jan 07 17:25:05 2013 +0000
@@ -29,6 +29,14 @@
 length' =
     length . list';
 
+floats a is ~double[] -> ~float[] =
+   (len = length' a;
+    f = new float[len];
+    for [0..len-1] do i:
+        f[i] := a[i];
+    done;
+    f);
+
 equal v1 v2 =
     list' v1 == list' v2;
 
@@ -57,6 +65,7 @@
 vector,
 length = length',
 list = list',
+floats,
 equal,
 copyOf, rangeOf, resizedTo,
 concat,
--- a/vamp.yeti	Sun Jan 06 21:56:19 2013 +0000
+++ b/vamp.yeti	Mon Jan 07 17:25:05 2013 +0000
@@ -3,11 +3,14 @@
 import org.vamp_plugins:
        Plugin, Plugin$InputDomain,
        PluginLoader, PluginLoader$AdapterFlags,
-       ParameterDescriptor, OutputDescriptor;
+       ParameterDescriptor, OutputDescriptor,
+       RealTime;
 
 import java.lang: UnsatisfiedLinkError;
 
 block = load block;
+fr = load framer;
+af = load audiofile;
 
 listPlugins () =
    (try
@@ -73,25 +76,64 @@
     get preferredStepSize () = p#getPreferredStepSize(),
     get minChannelCount () = p#getMinChannelCount(),
     get maxChannelCount () = p#getMaxChannelCount(),
-    initialise channels step hop = p#initialise(channels, step, hop),
+    initialise channels blocksize hop = p#initialise(channels, blocksize, hop),
     reset () = p#reset(),
     get outputs () = map outputDescriptor p#getOutputDescriptors(),
-    processBlock b time =  // Handle only a single channel, for now
-       (ff = new Object[1];
-        ff[0] := block.vector b as ~Object;
-        p#process(ff unsafely_as ~float[][], 0, time)),
+    process floats time is ~float[][] -> ~RealTime -> 'a = p#process(floats, 0, time),
+    dispose () = p#dispose(),
     };
 
 loadPlugin key rate =
     plugin key PluginLoader#getInstance()#loadPlugin(key, rate, PluginLoader$AdapterFlags#ADAPT_ALL);
 
-//process key stream =
-//   (p = loadPlugin key stream.sampleRate;
-//    map p#
+processed { p, sampleRate, hop } frames count =
+    case frames of
+        this::rest:
+            p.process
+                ([block.floats this] as ~float[][])
+                RealTime#frame2RealTime(count, sampleRate)
+            :.
+            \(processed { p, sampleRate, hop } rest (count + hop));
+        _: 
+           (p.dispose ();
+            []);
+    esac;
+
+process key stream =
+   (p = loadPlugin key stream.sampleRate;
+    blockSize = p.preferredBlockSize;
+    hop = p.preferredStepSize;
+    if p.initialise 1 blockSize hop then
+        processed
+            { p, sampleRate = stream.sampleRate, hop } 
+            (fr.frames { framesize = blockSize, hop } stream)
+            0;
+    else
+        p.dispose();
+        [];
+    fi);
+
+processFile key filename =
+   (stream = af.open filename;
+    p = loadPlugin key stream.sampleRate;
+    blockSize = p.preferredBlockSize;
+    hop = p.preferredStepSize;
+    if p.initialise 1 blockSize hop then
+        processed
+            { p, sampleRate = stream.sampleRate, hop } 
+            (fr.frames { framesize = blockSize, hop } stream)
+            0;
+    else
+        p.dispose();
+        stream.close();
+        [];
+    fi);
 
 {
 get pluginKeys = listPlugins,
 loadPlugin,
 categoryOf,
+process,
+processFile,
 }