1 /* Decibel Meter for MAEMO 5
2 * Copyright (C) 2010 Dru Moore <usr@dru-id.co.uk>
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2,
5 * or (at your option) any later version, as published by the Free
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details
13 * You should have received a copy of the GNU General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 public class InputBin : Gst.Bin {
23 Gst.Element converter;
26 Gst.GhostPad sink_pad;
28 public InputBin(string name) {
30 construct_pipeline("Microphone", 1.0);
32 public InputBin.with_settings(string name, string source, double volume) {
34 construct_pipeline(source, volume);
37 private string get_source_device(string name) {
42 return "sink.hw0.monitor";
49 private string get_source_name(string device) {
53 case "sink.hw0.monitor":
62 private void construct_pipeline(string source, double volume) {
64 this.src = Gst.ElementFactory.make("pulsesrc", "capture");
65 this.src.set_property("device", get_source_device(source)); //"source.hw0"); /// TODO
68 this.converter = Gst.ElementFactory.make("audioconvert", "converter");
69 this.add(this.converter);
71 this.volume = Gst.ElementFactory.make("volume", "volume");
72 this.volume.set_property("volume", volume);
73 this.add(this.volume);
75 this.src.link(converter);
76 this.converter.link(this.volume);
78 this.sink_pad = new Gst.GhostPad("sink", this.src.get_static_pad("sink"));
79 this.add_pad(sink_pad);
80 this.src_pad = new Gst.GhostPad("src", this.volume.get_static_pad("src"));
81 this.add_pad(src_pad);
84 public new Gst.PadTemplate get_pad_template(string name) {
87 return this.volume.get_pad_template("src");
89 return this.src.get_pad_template("sink");
91 return base.get_pad_template(name);
95 public void set_source(string name) {
97 Gst.ClockTime time = Gst.util_get_timestamp ();
98 this.get_state (out state, null, time);
99 this.set_state(Gst.State.NULL);
100 this.src.set_property("device", get_source_device(name));
101 this.set_state(state);
103 public string get_source() {
105 this.src.get_property("device", ref val);
106 return get_source_name(val.get_string());
109 public void set_volume(double val)
110 requires (val >= 0.0 && val <= 10.0) {
111 this.volume.set_property("volume", val);
113 public double get_volume()
114 ensures (result >= 0.0 && result <= 10.0) {
116 this.volume.get_property("volume", ref val);
117 return val.get_double();
120 public void set_mute(bool val) {
121 this.volume.set_property("mute", val);
123 public bool get_mute() {
125 this.volume.get_property("mute", ref val);
126 return val.get_boolean();