From 491211b9f733917c90d43e7b67eb1a0ff9048e42 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 25 Nov 2011 07:52:18 -0500 Subject: [PATCH] posts:gstreamer:beep: refactor to create the Beep class. --- posts/GStreamer/beep.py | 44 +++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 13 deletions(-) mode change 100644 => 100755 posts/GStreamer/beep.py 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() -- 2.26.2