[pitivi] arraysink.py, previewer.py: support multi-channel audio



commit c7aee49410693faf738128ebc59b1d4c6ddc200e
Author: Brandon Lewis <brandon_lewis berkeley edu>
Date:   Thu Sep 24 13:05:35 2009 -0700

    arraysink.py, previewer.py: support multi-channel audio

 pitivi/elements/arraysink.py |    4 ++-
 pitivi/ui/previewer.py       |   45 +++++++++++++++++++++++++----------------
 2 files changed, 30 insertions(+), 19 deletions(-)
---
diff --git a/pitivi/elements/arraysink.py b/pitivi/elements/arraysink.py
index 0858064..36be007 100644
--- a/pitivi/elements/arraysink.py
+++ b/pitivi/elements/arraysink.py
@@ -36,7 +36,7 @@ class ArraySink(gst.BaseSink):
     caps = gst.Caps(
         "audio/x-raw-float, width=(int) 32, "
         "endianness = (int) LITTLE_ENDIAN, "
-        "channels = (int) 1, "
+        "channels = (int) [1, 6],"
         "rate = (int) [1, 96000]"
     )
 
@@ -53,6 +53,7 @@ class ArraySink(gst.BaseSink):
         gst.BaseSink.__init__(self)
         self.props.sync = False
         self.rate = 0
+        self.channels = 0
         self.duration = 0L
         self.reset()
 
@@ -63,6 +64,7 @@ class ArraySink(gst.BaseSink):
         if not caps[0].get_name() == "audio/x-raw-float":
             return False
         self.rate = caps[0]["rate"]
+        self.channels = caps[0]["channels"]
         return True
 
     def do_render(self, buf):
diff --git a/pitivi/ui/previewer.py b/pitivi/ui/previewer.py
index dc8d6aa..b56e887 100644
--- a/pitivi/ui/previewer.py
+++ b/pitivi/ui/previewer.py
@@ -458,37 +458,46 @@ class RandomAccessAudioPreviewer(RandomAccessPreviewer):
         surface = cairo.ImageSurface(cairo.FORMAT_A8,
             self.base_width, self.theight)
         cr = cairo.Context(surface)
-        self._plotWaveform(cr, self.audioSink.samples)
+        self._plotWaveform(cr)
         self.audioSink.reset()
         gobject.idle_add(self._finishThumbnail, surface, self._audio_cur)
 
-    def _plotWaveform(self, cr, samples):
-        hscale = 25
+    def _plotWaveform(self, cr):
+        # clear background
+        cr.set_source_rgba(1, 1, 1, 0.0)
+        cr.rectangle(0, 0, self.base_width, self.theight)
+        cr.fill()
+
+        samples = self.audioSink.samples
+
         if not samples:
             cr.move_to(0, hscale)
             cr.line_to(self.twidth, hscale)
             cr.stroke()
             return
 
-        # clear background
-        cr.set_source_rgba(1, 1, 1, 0.0)
-        cr.rectangle(0, 0, self.base_width, self.theight)
-        cr.fill()
-
         # find the samples-per-pixel ratio
         spp = len(samples) / self.base_width
+        channels = self.audioSink.channels
+        stride = spp * channels
+        hscale = self.theight / (2 * channels)
 
         # 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
+        chan = 0
+        y = hscale
+        while chan < channels:
+            i = chan
+            x = 0
+            while i < len(samples):
+                slice = samples[i:i + stride:channels]
+                min_ = min(slice)
+                max_ = max(slice)
+                cr.move_to(x, y - (min_ * hscale))
+                cr.line_to(x, y - (max_ * hscale))
+                i += spp
+                x += 1
+            y += 2 * hscale
+            chan += 1
 
         # Draw!
         cr.set_source_rgba(0, 0, 0, 1.0)



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