1 /* GStreamer Editing Services
2 * Copyright (C) 2010 Brandon Lewis <brandon.lewis@collabora.co.uk>
3 * 2010 Nokia Corporation
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
22 * SECTION:gesaudiotestsource
23 * @title: GESAudioTestSource
24 * @short_description: produce a simple test waveform or silence
26 * Outputs a test audio stream using audiotestsrc. The default property values
27 * output silence. Useful for testing pipelines, or to fill gaps in an audio
34 #include "ges-internal.h"
35 #include "ges-track-element.h"
36 #include "ges-audio-test-source.h"
38 #define DEFAULT_VOLUME 1.0
40 struct _GESAudioTestSourcePrivate
51 G_DEFINE_TYPE_WITH_PRIVATE (GESAudioTestSource, ges_audio_test_source,
52 GES_TYPE_AUDIO_SOURCE);
54 static void ges_audio_test_source_get_property (GObject * object, guint
55 property_id, GValue * value, GParamSpec * pspec);
57 static void ges_audio_test_source_set_property (GObject * object, guint
58 property_id, const GValue * value, GParamSpec * pspec);
60 static GstElement *ges_audio_test_source_create_source (GESTrackElement * self);
63 ges_audio_test_source_class_init (GESAudioTestSourceClass * klass)
65 GObjectClass *object_class = G_OBJECT_CLASS (klass);
66 GESAudioSourceClass *source_class = GES_AUDIO_SOURCE_CLASS (klass);
68 object_class->get_property = ges_audio_test_source_get_property;
69 object_class->set_property = ges_audio_test_source_set_property;
71 source_class->create_source = ges_audio_test_source_create_source;
75 ges_audio_test_source_init (GESAudioTestSource * self)
77 self->priv = ges_audio_test_source_get_instance_private (self);
78 self->priv->freq = 440;
79 self->priv->volume = DEFAULT_VOLUME;
83 ges_audio_test_source_get_property (GObject * object,
84 guint property_id, GValue * value, GParamSpec * pspec)
86 switch (property_id) {
88 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
93 ges_audio_test_source_set_property (GObject * object,
94 guint property_id, const GValue * value, GParamSpec * pspec)
96 switch (property_id) {
98 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
103 ges_audio_test_source_create_source (GESTrackElement * trksrc)
105 GESAudioTestSource *self;
107 const gchar *props[] = { "volume", "freq", NULL };
109 self = (GESAudioTestSource *) trksrc;
110 ret = gst_element_factory_make ("audiotestsrc", NULL);
111 g_object_set (ret, "volume", (gdouble) self->priv->volume, "freq", (gdouble)
112 self->priv->freq, NULL);
114 ges_track_element_add_children_props (trksrc, ret, NULL, NULL, props);
120 * ges_audio_test_source_set_freq:
121 * @self: a #GESAudioTestSource
122 * @freq: The frequency you want to apply on @self
124 * Lets you set the frequency applied on the track element
127 ges_audio_test_source_set_freq (GESAudioTestSource * self, gdouble freq)
129 GstElement *element =
130 ges_track_element_get_element (GES_TRACK_ELEMENT (self));
132 self->priv->freq = freq;
136 g_value_init (&val, G_TYPE_DOUBLE);
137 g_value_set_double (&val, freq);
138 ges_track_element_set_child_property (GES_TRACK_ELEMENT (self), "freq",
144 * ges_audio_test_source_set_volume:
145 * @self: a #GESAudioTestSource
146 * @volume: The volume you want to apply on @self
148 * Sets the volume of the test audio signal.
151 ges_audio_test_source_set_volume (GESAudioTestSource * self, gdouble volume)
153 GstElement *element =
154 ges_track_element_get_element (GES_TRACK_ELEMENT (self));
156 self->priv->volume = volume;
160 g_value_init (&val, G_TYPE_DOUBLE);
161 g_value_set_double (&val, volume);
162 ges_track_element_set_child_property (GES_TRACK_ELEMENT (self), "volume",
168 * ges_audio_test_source_get_freq:
169 * @self: a #GESAudioTestSource
171 * Get the current frequency of @self.
173 * Returns: The current frequency of @self.
176 ges_audio_test_source_get_freq (GESAudioTestSource * self)
180 ges_track_element_get_child_property (GES_TRACK_ELEMENT (self), "freq", &val);
181 return g_value_get_double (&val);
185 * ges_audio_test_source_get_volume:
186 * @self: a #GESAudioTestSource
188 * Get the current volume of @self.
190 * Returns: The current volume of @self
193 ges_audio_test_source_get_volume (GESAudioTestSource * self)
197 ges_track_element_get_child_property (GES_TRACK_ELEMENT (self), "volume",
199 return g_value_get_double (&val);
202 /* Creates a new #GESAudioTestSource.
204 * Returns: (transfer floating) (nullable): The newly created #GESAudioTestSource.
207 ges_audio_test_source_new (void)
209 GESAudioTestSource *res;
210 GESAsset *asset = ges_asset_request (GES_TYPE_AUDIO_TEST_SOURCE, NULL, NULL);
212 res = GES_AUDIO_TEST_SOURCE (ges_asset_extract (asset, NULL));
213 gst_object_unref (asset);