X-Git-Url: http://git.maemo.org/git/?p=demorecorder;a=blobdiff_plain;f=src%2FInputBin.vala;fp=src%2FInputBin.vala;h=c93836296466e77a4d2717431ad021165f74cacc;hp=0000000000000000000000000000000000000000;hb=804630a4e0d41b182d8540f2aec69cf25ca0acfd;hpb=753fb925588aeeacdd74a163672acf2bf362a99e diff --git a/src/InputBin.vala b/src/InputBin.vala new file mode 100644 index 0000000..c938362 --- /dev/null +++ b/src/InputBin.vala @@ -0,0 +1,177 @@ +/* Demo Recorder for MAEMO 5 +* Copyright (C) 2010 Dru Moore +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2, +* or (at your option) any later version, as published by the Free +* Software Foundation +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details +* +* You should have received a copy of the GNU General Public +* License along with this program; if not, write to the +* Free Software Foundation, Inc., +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ +namespace IdWorks { + +public class InputBin : Gst.Bin { + + Gst.Element src; + Gst.Element converter; + Gst.Element pregain; + Gst.Element dynamics; + Gst.Element volume; + Gst.GhostPad src_pad; + Gst.GhostPad sink_pad; + + public InputBin(string name) { + this.set_name(name); + construct_pipeline(SettingsStructures.RecordingSettings()); + } + public InputBin.with_settings(string name, SettingsStructures.RecordingSettings settings) { + this.name = name; + construct_pipeline(settings); + } + + private string get_source_device(string name) { + switch (name) { + case "Microphone": + return "source.hw0"; + case "Monitor": + return "sink.hw0.monitor"; + case "Bluetooth": + return "source.hw1"; + default: + return "source.hw0"; + } + } + private string get_source_name(string device) { + switch (device) { + case "source.hw0": + return "Microphone"; + case "sink.hw0.monitor": + return "Monitor"; + case "source.hw1": + return "Bluetooth"; + default: + return "Microphone"; + } + } + + private void construct_pipeline(SettingsStructures.RecordingSettings settings) { + + this.src = Gst.ElementFactory.make("pulsesrc", "capture"); + this.src.set_property("device", get_source_device(settings.source)); //"source.hw0"); /// TODO + this.add(this.src); + + this.converter = Gst.ElementFactory.make("audioconvert", "converter"); + this.add(this.converter); + + this.pregain = Gst.ElementFactory.make("volume", "pregain"); + this.pregain.set_property("volume", settings.pregain); + this.add(this.pregain); + + this.dynamics = Gst.ElementFactory.make("audiodynamic", "dynamics"); + this.add(this.dynamics); + this.dynamics.set_property("mode", settings.dynamics.mode); // compressor or expander + this.dynamics.set_property("characteristics", settings.dynamics.characteristics); // hard-knee or soft-knee + this.dynamics.set_property("threshold", settings.dynamics.threshold); // [0, 1] + this.dynamics.set_property("ratio", settings.dynamics.ratio); // >= 0 + + this.volume = Gst.ElementFactory.make("volume", "volume"); + this.volume.set_property("volume", settings.volume); + this.add(this.volume); + + this.src.link(converter); + this.converter.link(pregain); + this.pregain.link(dynamics); + this.dynamics.link(volume); + + sink_pad = new Gst.GhostPad("sink", src.get_static_pad("sink")); + this.add_pad(sink_pad); + src_pad = new Gst.GhostPad("src", volume.get_static_pad("src")); + this.add_pad(src_pad); + } + + public new Gst.PadTemplate get_pad_template(string name) { + switch (name) { + case "src": + return this.volume.get_pad_template("src"); + case "sink": + return this.src.get_pad_template("sink"); + default: + return base.get_pad_template(name); + } + } + + public void set_dynamics(string mode, string characteristics, double threshold, double ratio) { + this.dynamics.set_property("mode", mode); // compressor or expander + this.dynamics.set_property("characteristics", characteristics); // hard-knee or soft-knee + this.dynamics.set_property("threshold", threshold); // [0, 1] + this.dynamics.set_property("ratio", ratio); // >= 0 + } + public void set_dynamics_mode(string mode) { + this.dynamics.set_property("mode", mode); // compressor or expander + } + public void set_dynamics_characteristics(string characteristics) { + this.dynamics.set_property("characteristics", characteristics); // hard-knee or soft-knee + } + public void set_dynamics_threshold(double threshold) { + this.dynamics.set_property("threshold", threshold); // [0, 1] + } + public void set_dynamics_ratio(double ratio) { + this.dynamics.set_property("ratio", ratio); // >= 0 + } + + public void set_source(string name) { + Gst.State state; + Gst.ClockTime time = Gst.util_get_timestamp (); + this.get_state (out state, null, time); + this.set_state(Gst.State.NULL); + this.src.set_property("device", get_source_device(name)); + this.set_state(state); + } + public string get_source() { + GLib.Value val = 0; + this.src.get_property("device", ref val); + return get_source_name(val.get_string()); + } + + public void set_pregain(double val) + requires (val >= 0.0 && val <= 10.0) { + this.pregain.set_property("volume", val); + } + public double get_pregain() + ensures (result >= 0.0 && result <= 10.0) { + GLib.Value val = 0; + this.pregain.get_property("volume", ref val); + return val.get_double(); + } + + public void set_volume(double val) + requires (val >= 0.0 && val <= 10.0) { + this.volume.set_property("volume", val); + } + public double get_volume() + ensures (result >= 0.0 && result <= 10.0) { + GLib.Value val = 0; + this.volume.get_property("volume", ref val); + return val.get_double(); + } + + public void set_mute(bool val) { + this.volume.set_property("mute", val); + } + public bool get_mute() { + GLib.Value val = 0; + this.volume.get_property("mute", ref val); + return val.get_boolean(); + } + + +} + +} \ No newline at end of file