~ubuntu-branches/ubuntu/lucid/pitivi/lucid

« back to all changes in this revision

Viewing changes to pitivi/elements/arraysink.py

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2009-05-27 14:22:49 UTC
  • mfrom: (1.2.1 upstream) (3.1.13 experimental)
  • Revision ID: james.westby@ubuntu.com-20090527142249-tj0qnkc37320ylml
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# PiTiVi , Non-linear video editor
 
2
#
 
3
#       pitivi/elements/arraysink.py
 
4
#
 
5
# Copyright (c) 2005, Edward Hervey <bilboed@bilboed.com>
 
6
#
 
7
# This program is free software; you can redistribute it and/or
 
8
# modify it under the terms of the GNU Lesser General Public
 
9
# License as published by the Free Software Foundation; either
 
10
# version 2.1 of the License, or (at your option) any later version.
 
11
#
 
12
# This program is distributed in the hope that it will be useful,
 
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
# Lesser General Public License for more details.
 
16
#
 
17
# You should have received a copy of the GNU Lesser General Public
 
18
# License along with this program; if not, write to the
 
19
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
20
# Boston, MA 02111-1307, USA.
 
21
"""
 
22
Stores audio samples in an array for plotting waveforms
 
23
"""
 
24
 
 
25
import gobject
 
26
gobject.threads_init()
 
27
import gst
 
28
import gtk
 
29
import array
 
30
 
 
31
class ArraySink(gst.BaseSink):
 
32
 
 
33
    """
 
34
    Stores audio samples in a numeric array of floats.
 
35
    """
 
36
    caps = gst.Caps(
 
37
        "audio/x-raw-float, width=(int) 32, "
 
38
        "endianness = (int) LITTLE_ENDIAN, "
 
39
        "channels = (int) 1, "
 
40
        "rate = (int) [1, 96000]"
 
41
    )
 
42
 
 
43
    __gsttemplates__ = (
 
44
        gst.PadTemplate(
 
45
            "sink",
 
46
            gst.PAD_SINK,
 
47
            gst.PAD_ALWAYS,
 
48
            caps
 
49
       ),
 
50
    )
 
51
 
 
52
    def __init__(self):
 
53
        gst.BaseSink.__init__(self)
 
54
        self.props.sync = False
 
55
        self.rate = 0
 
56
        self.duration = 0L
 
57
        self.reset()
 
58
 
 
59
    def reset(self):
 
60
        self.samples = array.array('f')
 
61
 
 
62
    def do_set_caps(self, caps):
 
63
        if not caps[0].get_name() == "audio/x-raw-float":
 
64
            return False
 
65
        self.rate = caps[0]["rate"]
 
66
        return True
 
67
 
 
68
    def do_render(self, buf):
 
69
        self.samples.fromstring(buf[:buf.size])
 
70
        self.duration += buf.duration
 
71
        return gst.FLOW_OK
 
72
 
 
73
    def do_preroll(self, buf):
 
74
        return self.do_render(buf)
 
75
 
 
76
gobject.type_register(ArraySink)