-#!/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()