From: W. Trevor King Date: Fri, 25 Nov 2011 12:52:18 +0000 (-0500) Subject: posts:gstreamer:beep: refactor to create the Beep class. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=491211b9f733917c90d43e7b67eb1a0ff9048e42;p=blog.git posts:gstreamer:beep: refactor to create the Beep class. --- diff --git a/posts/GStreamer/beep.py b/posts/GStreamer/beep.py old mode 100644 new mode 100755 index 172c31c..5260239 --- a/posts/GStreamer/beep.py +++ b/posts/GStreamer/beep.py @@ -1,24 +1,42 @@ -#!/usr/bin/python +#!/usr/bin/env python + +"""Simple GStreamer tone generator. +""" import pygst -pygst.require("0.10") +pygst.require('0.10') import gst import pygtk import gtk -class Main: - def __init__(self): - self.pipeline = gst.Pipeline("mypipeline") +class Beep: + def __init__(self, frequency=440): + self.pipeline = gst.Pipeline('mypipeline') + + self.audiotestsrc = gst.element_factory_make('audiotestsrc', 'audio') + self.audiotestsrc.set_property('freq', frequency) + self.pipeline.add(self.audiotestsrc) + + self.sink = gst.element_factory_make('alsasink', 'sink') + self.pipeline.add(self.sink) + + self.audiotestsrc.link(self.sink) + + self.pipeline.set_state(gst.STATE_PLAYING) + - self.audiotestsrc = gst.element_factory_make("audiotestsrc", "audio") - self.pipeline.add(self.audiotestsrc) +if __name__ == '__main__': + import argparse - self.sink = gst.element_factory_make("alsasink", "sink") - self.pipeline.add(self.sink) + parser = argparse.ArgumentParser(description='Play a pure tone') + parser.add_argument( + '-f', '--frequency', type=float, help='tone frequency in Hz') - self.audiotestsrc.link(self.sink) + args = parser.parse_args() - self.pipeline.set_state(gst.STATE_PLAYING) + frequency = 440 + if args.frequency: + frequency = args.frequency -start=Main() -gtk.main() + start=Beep(frequency=frequency) + gtk.main()