5 * Copyright (C) <2010> Stefan Kost <ensonic@users.sf.net>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
23 /* FIXME 0.11: suppress warnings for deprecated API such as GValueArray
24 * with newer GLib versions (>= 2.31.0) */
25 #define GLIB_DISABLE_DEPRECATION_WARNINGS
27 #include <gst/check/gstcheck.h>
28 #include <gst/audio/audio.h>
29 #include <gst/audio/audio-enumtypes.h>
32 bus_handler (GstBus * bus, GstMessage * message, gpointer data)
34 GMainLoop *loop = (GMainLoop *) data;
36 switch (message->type) {
38 g_main_loop_quit (loop);
40 case GST_MESSAGE_WARNING:
41 case GST_MESSAGE_ERROR:{
45 gst_message_parse_error (message, &gerror, &debug);
46 gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug);
47 gst_message_unref (message);
48 g_error_free (gerror);
50 g_main_loop_quit (loop);
62 * audiotestsrc freq=440 num-buffers=100 ! interleave name=i ! audioconvert ! wavenc ! filesink location=/tmp/mc.wav \
63 * audiotestsrc freq=880 num-buffers=100 ! i.
66 * http://www.microsoft.com/whdc/device/audio/multichaud.mspx
70 make_n_channel_wav (const gint channels, const GValueArray * arr)
73 GstElement **audiotestsrc, *interleave, *wavenc, *conv, *fakesink;
79 audiotestsrc = g_new0 (GstElement *, channels);
81 pipeline = gst_pipeline_new ("pipeline");
82 fail_unless (pipeline != NULL);
84 interleave = gst_element_factory_make ("interleave", NULL);
85 fail_unless (interleave != NULL);
86 g_object_set (interleave, "channel-positions", arr, NULL);
87 gst_bin_add (GST_BIN (pipeline), interleave);
89 if (G_BYTE_ORDER == G_BIG_ENDIAN) {
90 /* we're not here to test orc; audioconvert misbehaves on ppc32 */
91 g_setenv ("ORC_CODE", "backup", 1);
92 conv = gst_element_factory_make ("audioconvert", NULL);
94 conv = gst_element_factory_make ("identity", NULL);
96 fail_unless (conv != NULL);
97 gst_bin_add (GST_BIN (pipeline), conv);
98 fail_unless (gst_element_link (interleave, conv));
100 wavenc = gst_element_factory_make ("wavenc", NULL);
101 fail_unless (wavenc != NULL);
102 gst_bin_add (GST_BIN (pipeline), wavenc);
103 fail_unless (gst_element_link (conv, wavenc));
105 fakesink = gst_element_factory_make ("fakesink", NULL);
106 fail_unless (fakesink != NULL);
107 gst_bin_add (GST_BIN (pipeline), fakesink);
108 fail_unless (gst_element_link (wavenc, fakesink));
110 for (i = 0; i < channels; i++) {
111 audiotestsrc[i] = gst_element_factory_make ("audiotestsrc", NULL);
112 fail_unless (audiotestsrc[i] != NULL);
113 g_object_set (G_OBJECT (audiotestsrc[i]), "wave", 0, "freq",
114 440.0 * (i + 1), "num-buffers", 100, NULL);
115 gst_bin_add (GST_BIN (pipeline), audiotestsrc[i]);
116 fail_unless (gst_element_link (audiotestsrc[i], interleave));
119 loop = g_main_loop_new (NULL, TRUE);
120 fail_unless (loop != NULL);
122 bus = gst_element_get_bus (pipeline);
123 fail_unless (bus != NULL);
124 bus_watch = gst_bus_add_watch (bus, bus_handler, loop);
125 gst_object_unref (bus);
127 gst_element_set_state (pipeline, GST_STATE_PLAYING);
128 g_main_loop_run (loop);
129 gst_element_set_state (pipeline, GST_STATE_NULL);
131 gst_object_unref (pipeline);
132 g_free (audiotestsrc);
134 g_main_loop_unref (loop);
135 g_source_remove (bus_watch);
138 GST_START_TEST (test_encode_stereo)
143 arr = g_value_array_new (2);
144 g_value_init (&val, GST_TYPE_AUDIO_CHANNEL_POSITION);
145 g_value_set_enum (&val, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT);
146 g_value_array_append (arr, &val);
147 g_value_reset (&val);
148 g_value_set_enum (&val, GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT);
149 g_value_array_append (arr, &val);
150 g_value_unset (&val);
152 make_n_channel_wav (2, arr);
153 g_value_array_free (arr);
159 GST_START_TEST (test_encode_multichannel)
164 arr = g_value_array_new (6);
165 g_value_init (&val, GST_TYPE_AUDIO_CHANNEL_POSITION);
166 g_value_set_enum (&val, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT);
167 g_value_array_append (arr, &val);
168 g_value_reset (&val);
169 g_value_set_enum (&val, GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT);
170 g_value_array_append (arr, &val);
171 g_value_reset (&val);
172 g_value_set_enum (&val, GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER);
173 g_value_array_append (arr, &val);
174 g_value_reset (&val);
175 g_value_set_enum (&val, GST_AUDIO_CHANNEL_POSITION_LFE);
176 g_value_array_append (arr, &val);
177 g_value_reset (&val);
178 g_value_set_enum (&val, GST_AUDIO_CHANNEL_POSITION_REAR_LEFT);
179 g_value_array_append (arr, &val);
180 g_value_reset (&val);
181 g_value_set_enum (&val, GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT);
182 g_value_array_append (arr, &val);
183 g_value_unset (&val);
185 make_n_channel_wav (6);
194 Suite *s = suite_create ("wavenc");
195 TCase *tc_chain = tcase_create ("general");
197 suite_add_tcase (s, tc_chain);
198 tcase_add_test (tc_chain, test_encode_stereo);
199 /* FIXME: improve wavenc
200 tcase_add_test (tc_chain, test_encode_multichannel);
206 GST_CHECK_MAIN (wavenc);