changeset 162:073641eba879

Start on stream filters
author Chris Cannam
date Wed, 01 May 2013 16:20:07 +0100
parents 38938ca5db0c
children 3fbaa25aad89
files yetilab/stream/audiofile.yeti yetilab/stream/filter.yeti yetilab/stream/streamtype.yeti yetilab/stream/syntheticstream.yeti yetilab/vamp/test/test_vamp.yeti
diffstat 5 files changed, 73 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/yetilab/stream/audiofile.yeti	Wed May 01 13:40:03 2013 +0100
+++ b/yetilab/stream/audiofile.yeti	Wed May 01 16:20:07 2013 +0100
@@ -1,6 +1,8 @@
 
 module yetilab.stream.audiofile;
 
+load yetilab.stream.streamtype;
+
 import javax.sound.sampled:
      AudioSystem, AudioInputStream, AudioFormat, AudioFormat$Encoding,
      UnsupportedAudioFileException;
@@ -90,7 +92,7 @@
 close' { aistream is ~AudioInputStream } =
     aistream#close();
 
-open name is string -> 'a = 
+open name is string -> stream = 
    (f = new File(name);
     aistream = AudioSystem#getAudioInputStream(f);
     format = aistream#getFormat();
@@ -107,5 +109,7 @@
 
 {
     open
-}
+} as {
+    open is string -> stream
+} 
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/yetilab/stream/filter.yeti	Wed May 01 16:20:07 2013 +0100
@@ -0,0 +1,34 @@
+
+module yetilab.stream.filter;
+
+mat = load yetilab.matrix.matrix;
+
+load yetilab.stream.streamtype;
+
+truncatedTo nsamples s =
+    {
+        get position () = s.position,
+        get channels () = s.channels, 
+        get sampleRate () = s.sampleRate,
+        get available () = Known (nsamples - s.position),
+        get finished? () = not (nsamples > s.position),
+        read count =
+            if nsamples > s.position + count then
+                s.read count;
+            elif nsamples > s.position then
+                s.read (nsamples - s.position)
+            else
+                mat.zeroMatrix { columns = 0, rows = s.channels }
+            fi,
+        close = s.close,
+    };
+
+{
+    truncatedTo, 
+} as {
+    truncatedTo is number -> stream -> stream
+}
+
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/yetilab/stream/streamtype.yeti	Wed May 01 16:20:07 2013 +0100
@@ -0,0 +1,16 @@
+
+module yetilab.stream.streamtype;
+
+typedef stream =
+    {
+        position is number,
+        channels is number,
+        sampleRate is number,
+        available is Known number | Unknown () | Infinite (),
+        finished? is boolean,
+        read is number -> 'a, // actually a matrix
+        close is () -> (),
+    };
+
+();
+
--- a/yetilab/stream/syntheticstream.yeti	Wed May 01 13:40:03 2013 +0100
+++ b/yetilab/stream/syntheticstream.yeti	Wed May 01 16:20:07 2013 +0100
@@ -5,6 +5,8 @@
 vec = load yetilab.block.fvector;
 block = load yetilab.block.block;
 
+load yetilab.stream.streamtype;
+
 generated sampleRate generator =
    (// generator takes time in seconds as arg, returns number in -1,+1 range
     var position = 0;
@@ -51,6 +53,18 @@
     });
 
 {
-    generated, precalculated, sinusoid, whiteNoise, silent,
+    generated, 
+    precalculated, 
+    sinusoid, 
+    whiteNoise, 
+    silent,
+} as {
+    generated is number -> (number -> number) -> stream, 
+    precalculated is number -> 'a -> stream, //!!! 'a is block 
+    sinusoid is number -> number -> stream, 
+    whiteNoise is number -> stream,
+    silent is number -> stream,
 }
 
+
+
--- a/yetilab/vamp/test/test_vamp.yeti	Wed May 01 13:40:03 2013 +0100
+++ b/yetilab/vamp/test/test_vamp.yeti	Wed May 01 16:20:07 2013 +0100
@@ -2,6 +2,7 @@
 
 v = load yetilab.vamp.vamp;
 synthetic = load yetilab.stream.syntheticstream;
+filter = load yetilab.stream.filter;
 mat = load yetilab.matrix.matrix;
 
 { compare, compareUsing } = load yetilab.test.test;
@@ -10,7 +11,7 @@
 
 rate = 44100;
 
-testStream () = synthetic.whiteNoise rate;
+testStream () = filter.truncatedTo (rate * 30) (synthetic.whiteNoise rate);
 
 processTest output = 
     v.processStreamStructured testPluginKey output (testStream ());