[pitivi] previewer.py: use the min-max waveform generation algorithm, speeding up drawing and improving accur



commit cde9d8906adb3844ece9b37c95af940a19adfee5
Author: Brandon Lewis <brandon_lewis berkeley edu>
Date:   Wed Jul 29 16:46:38 2009 -0700

    previewer.py: use the min-max waveform generation algorithm, speeding up drawing and improving accuracy
    previewer.py: combine resampling and rendering loops

 pitivi/ui/previewer.py |   30 ++++++++++++++++--------------
 1 files changed, 16 insertions(+), 14 deletions(-)
---
diff --git a/pitivi/ui/previewer.py b/pitivi/ui/previewer.py
index e4160a2..dc8d6aa 100644
--- a/pitivi/ui/previewer.py
+++ b/pitivi/ui/previewer.py
@@ -475,21 +475,23 @@ class RandomAccessAudioPreviewer(RandomAccessPreviewer):
         cr.rectangle(0, 0, self.base_width, self.theight)
         cr.fill()
 
-        # resample for improved speed
-        stride = 100
-        samples = [max(samples[i:i + stride]) for i in
-            xrange(0, len(samples), stride)]
-        scale = float(self.base_width) / len(samples)
-
-        # generate points
+        # find the samples-per-pixel ratio
+        spp = len(samples) / self.base_width
+
+        # plot points from min to max over a given hunk
+        i = 0
+        x= 0
+        while i < len(samples):
+            slice = samples[i:i + spp]
+            min_ = min(slice)
+            max_ = max(slice)
+            cr.move_to(x, hscale - (min_ * hscale))
+            cr.line_to(x, hscale - (max_ * hscale))
+            i += spp
+            x += 1
+
+        # Draw!
         cr.set_source_rgba(0, 0, 0, 1.0)
-
-        cr.move_to(0, hscale)
-        for x, y in enumerate(samples):
-            x = x * scale
-            y = hscale - (y * hscale)
-            cr.line_to(x, y)
-
         cr.stroke()
 
     def _thumbForTime(self, cr, time, x, y):



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]