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., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 #include <gst/check/gstcheck.h>
24 #include <gst/audio/multichannel.h>
27 bus_handler (GstBus * bus, GstMessage * message, gpointer data)
29 GMainLoop *loop = (GMainLoop *) data;
31 switch (message->type) {
33 g_main_loop_quit (loop);
35 case GST_MESSAGE_WARNING:
36 case GST_MESSAGE_ERROR:{
40 gst_message_parse_error (message, &gerror, &debug);
41 gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug);
42 gst_message_unref (message);
43 g_error_free (gerror);
45 g_main_loop_quit (loop);
57 * audiotestsrc freq=440 num-buffers=100 ! interleave name=i ! wavenc ! filesink location=/tmp/mc.wav \
58 * audiotestsrc freq=880 num-buffers=100 ! i.
61 * http://www.microsoft.com/whdc/device/audio/multichaud.mspx
65 make_n_channel_wav (const gint channels, const GValueArray * arr)
68 GstElement **audiotestsrc, *interleave, *wavenc, *fakesink;
74 audiotestsrc = g_new0 (GstElement *, channels);
76 pipeline = gst_pipeline_new ("pipeline");
77 fail_unless (pipeline != NULL);
79 interleave = gst_element_factory_make ("interleave", NULL);
80 fail_unless (interleave != NULL);
81 g_object_set (interleave, "channel-positions", arr, NULL);
82 gst_bin_add (GST_BIN (pipeline), interleave);
84 wavenc = gst_element_factory_make ("wavenc", NULL);
85 fail_unless (wavenc != NULL);
86 gst_bin_add (GST_BIN (pipeline), wavenc);
87 fail_unless (gst_element_link (interleave, wavenc));
89 fakesink = gst_element_factory_make ("fakesink", NULL);
90 fail_unless (fakesink != NULL);
91 gst_bin_add (GST_BIN (pipeline), fakesink);
92 fail_unless (gst_element_link (wavenc, fakesink));
94 for (i = 0; i < channels; i++) {
95 audiotestsrc[i] = gst_element_factory_make ("audiotestsrc", NULL);
96 fail_unless (audiotestsrc[i] != NULL);
97 g_object_set (G_OBJECT (audiotestsrc[i]), "wave", 0, "freq", 440.0 * i,
98 "num-buffers", 100, NULL);
99 gst_bin_add (GST_BIN (pipeline), audiotestsrc[i]);
100 fail_unless (gst_element_link (audiotestsrc[i], interleave));
103 loop = g_main_loop_new (NULL, TRUE);
104 fail_unless (loop != NULL);
106 bus = gst_element_get_bus (pipeline);
107 fail_unless (bus != NULL);
108 bus_watch = gst_bus_add_watch (bus, bus_handler, loop);
109 gst_object_unref (bus);
111 gst_element_set_state (pipeline, GST_STATE_PLAYING);
112 g_main_loop_run (loop);
113 gst_element_set_state (pipeline, GST_STATE_NULL);
115 gst_object_unref (pipeline);
116 g_free (audiotestsrc);
118 g_main_loop_unref (loop);
119 g_source_remove (bus_watch);
122 GST_START_TEST (test_encode_stereo)
127 arr = g_value_array_new (2);
128 g_value_init (&val, GST_TYPE_AUDIO_CHANNEL_POSITION);
129 g_value_set_enum (&val, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT);
130 g_value_array_append (arr, &val);
131 g_value_reset (&val);
132 g_value_set_enum (&val, GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT);
133 g_value_array_append (arr, &val);
134 g_value_unset (&val);
136 make_n_channel_wav (2, arr);
137 g_value_array_free (arr);
143 GST_START_TEST (test_encode_multichannel)
148 arr = g_value_array_new (6);
149 g_value_init (&val, GST_TYPE_AUDIO_CHANNEL_POSITION);
150 g_value_set_enum (&val, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT);
151 g_value_array_append (arr, &val);
152 g_value_reset (&val);
153 g_value_set_enum (&val, GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT);
154 g_value_array_append (arr, &val);
155 g_value_reset (&val);
156 g_value_set_enum (&val, GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER);
157 g_value_array_append (arr, &val);
158 g_value_reset (&val);
159 g_value_set_enum (&val, GST_AUDIO_CHANNEL_POSITION_LFE);
160 g_value_array_append (arr, &val);
161 g_value_reset (&val);
162 g_value_set_enum (&val, GST_AUDIO_CHANNEL_POSITION_REAR_LEFT);
163 g_value_array_append (arr, &val);
164 g_value_reset (&val);
165 g_value_set_enum (&val, GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT);
166 g_value_array_append (arr, &val);
167 g_value_unset (&val);
169 make_n_channel_wav (6);
178 Suite *s = suite_create ("wavenc");
179 TCase *tc_chain = tcase_create ("general");
181 suite_add_tcase (s, tc_chain);
182 tcase_add_test (tc_chain, test_encode_stereo);
183 /* FIXME: improve wavenc
184 tcase_add_test (tc_chain, test_encode_multichannel);
190 GST_CHECK_MAIN (wavenc);