changeset 575:af8ecd7866cd

Max 0.5 in impulse train
author Chris Cannam
date Tue, 20 May 2014 13:36:40 +0100
parents f00a2134b1fa
children f0da2404108c
files src/may/stream/test/test_waves.yeti src/may/stream/waves.yeti
diffstat 2 files changed, 6 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/may/stream/test/test_waves.yeti	Tue May 20 13:36:32 2014 +0100
+++ b/src/may/stream/test/test_waves.yeti	Tue May 20 13:36:40 2014 +0100
@@ -36,7 +36,7 @@
         compare str.sampleRate 8 and
         compare str.available (Infinite ()) and
         compare str.finished? false and
-        compareApprox epsilon (vec.list (mat.getRow 0 (str.read 9))) [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ] and
+        compareApprox epsilon (vec.list (mat.getRow 0 (str.read 9))) [ 0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5 ] and
         compare str.position 9
 ),
 
@@ -49,7 +49,7 @@
         compare str.sampleRate 10 and
         compare str.available (Infinite ()) and
         compare str.finished? false and
-        compareApprox epsilon (vec.list (mat.getRow 0 (str.read 11))) [ 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0 ] and
+        compareApprox epsilon (vec.list (mat.getRow 0 (str.read 11))) [ 0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0, 0 ] and
         compare str.position 11
 ),
 
@@ -66,7 +66,7 @@
         compare str.available (Infinite ()) and
         compare str.finished? false and
         compareApprox epsilon (vec.list (mat.getRow 0 (str.read 14)))
-            [ 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0 ] and
+            [ 0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0 ] and
         compare str.position 14
 */
 ),
--- a/src/may/stream/waves.yeti	Tue May 20 13:36:32 2014 +0100
+++ b/src/may/stream/waves.yeti	Tue May 20 13:36:40 2014 +0100
@@ -54,7 +54,8 @@
 // Bandlimited impulse train: produce naive pulse train at a frequency
 // that is an integer fraction of the sample rate (so as to have exact
 // sample locations), then resample so as to place the impulses at the
-// requested frequency
+// requested frequency. The maximum sample is 0.5 rather than 1 to
+// avoid clipping in further manipulation.
 impulseTrain sampleRate freq =
     if freq > sampleRate/2 then
         failWith "Can't generate impulse train with frequency > half the sample rate (\(freq) > \(sampleRate)/2)"
@@ -62,7 +63,7 @@
         naiveTrain f =
            (spacing = int (sampleRate / f);
             generated sampleRate
-                do n: if n % spacing == 0 then 1 else 0 fi done);
+                do n: if n % spacing == 0 then 0.5 else 0 fi done);
         ratio = sampleRate / freq;
         if ratio == int ratio then
             naiveTrain freq