2 * Copyright (C) 2003 Benjamin Otte <in7y118@public.uni-hamburg.de>
4 * formats.c: Tests the different formats on alsasink
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this library; if not, write to the Free
18 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 gboolean sign = FALSE;
26 gint endianness = G_LITTLE_ENDIAN;
30 #define NUMBER_OF_INT_TESTS 28
31 #define NUMBER_OF_FLOAT_TESTS 2
32 #define NUMBER_OF_LAW_TESTS 2
37 static void create_pipeline (void);
41 pre_get_func (SineSrc * src)
47 create_pipeline (void)
53 pipeline = gst_pipeline_new ("pipeline");
55 alsasink = gst_element_factory_make ("alsasink", "alsasink");
57 gst_bin_add_many (GST_BIN (pipeline), src, alsasink, NULL);
58 gst_element_link (src, alsasink);
60 /* prepare our sinesrc */
61 sinesrc = (SineSrc *) src;
62 sinesrc->pre_get_func = pre_get_func;
63 sinesrc->newcaps = TRUE;
65 if (last < NUMBER_OF_INT_TESTS) {
66 sinesrc->type = SINE_SRC_INT;
67 sinesrc->sign = ((last % 2) == 0) ? TRUE : FALSE;
69 ((last / 2) % 2 == 0) ? G_LITTLE_ENDIAN : G_BIG_ENDIAN;
70 switch ((last / 4) % 8) {
87 /* nomore tests below until i know what 24bit width means to alsa wrt endianness */
106 g_assert_not_reached ();
109 g_print ("Setting format to: format: \"int\"\n"
114 sinesrc->sign ? "TRUE" : "FALSE", sinesrc->endianness,
115 sinesrc->width, sinesrc->depth);
116 } else if (last < NUMBER_OF_INT_TESTS + NUMBER_OF_FLOAT_TESTS) {
117 gint temp = last - NUMBER_OF_INT_TESTS;
119 sinesrc->type = SINE_SRC_FLOAT;
128 g_assert_not_reached ();
130 g_print ("Setting format to float width %d\n", sinesrc->width);
132 NUMBER_OF_INT_TESTS + NUMBER_OF_FLOAT_TESTS + NUMBER_OF_LAW_TESTS) {
133 gint temp = last - NUMBER_OF_INT_TESTS - NUMBER_OF_FLOAT_TESTS;
136 sinesrc->type = SINE_SRC_INT;
137 sinesrc->sign = TRUE;
138 sinesrc->endianness = G_BYTE_ORDER;
143 law = gst_element_factory_make ("mulawenc", "mulaw");
145 law = gst_element_factory_make ("alawenc", "alaw");
148 gst_element_unlink (src, alsasink);
149 gst_bin_add (GST_BIN (pipeline), law);
150 gst_element_link_many (src, law, alsasink, NULL);
152 g_print ("Setting format to: format: \"MU law\"\n");
154 g_print ("Setting format to: format: \"A law\"\n");
157 g_print ("All formats work like a charm.\n");
160 gst_element_set_state (pipeline, GST_STATE_PLAYING);
164 main (gint argc, gchar * argv[])
166 gst_init (&argc, &argv);
169 "This test will test the various formats ALSA and GStreamer support.\n"
170 "You will hear a short sine tone on your default ALSA soundcard for every\n"
171 "format tested. They should all sound the same (incl. volume).\n" "\n");
175 gst_bin_iterate (GST_BIN (pipeline));
176 if ((counter / 200) > last) {
177 last = counter / 200;
178 gst_object_unref (pipeline);