Macro qtTrIdx() replaced by tr() and QT_TRANSLATE_NOOP()
[mafwsubrenderer] / gst-plugins-base-subtitles0.10 / tests / old / testsuite / alsa / formats.c
1 /*
2  * Copyright (C) 2003 Benjamin Otte <in7y118@public.uni-hamburg.de>
3  *
4  * formats.c: Tests the different formats on alsasink
5  *
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.
10  *
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.
15  *
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.
19  */
20
21 #include "sinesrc.h"
22
23 GstElement *pipeline;
24 gint channels = 1;
25 gboolean sign = FALSE;
26 gint endianness = G_LITTLE_ENDIAN;
27 gint depth = 8;
28 gint width = 8;
29
30 #define NUMBER_OF_INT_TESTS 28
31 #define NUMBER_OF_FLOAT_TESTS 2
32 #define NUMBER_OF_LAW_TESTS 2
33
34 gint last = 0;
35 gint counter = 0;
36
37 static void create_pipeline (void);
38
39
40 static void
41 pre_get_func (SineSrc * src)
42 {
43   counter++;
44 };
45
46 static void
47 create_pipeline (void)
48 {
49   GstElement *src;
50   SineSrc *sinesrc;
51   GstElement *alsasink;
52
53   pipeline = gst_pipeline_new ("pipeline");
54   src = sinesrc_new ();
55   alsasink = gst_element_factory_make ("alsasink", "alsasink");
56
57   gst_bin_add_many (GST_BIN (pipeline), src, alsasink, NULL);
58   gst_element_link (src, alsasink);
59
60   /* prepare our sinesrc */
61   sinesrc = (SineSrc *) src;
62   sinesrc->pre_get_func = pre_get_func;
63   sinesrc->newcaps = TRUE;
64   /* int tests */
65   if (last < NUMBER_OF_INT_TESTS) {
66     sinesrc->type = SINE_SRC_INT;
67     sinesrc->sign = ((last % 2) == 0) ? TRUE : FALSE;
68     sinesrc->endianness =
69         ((last / 2) % 2 == 0) ? G_LITTLE_ENDIAN : G_BIG_ENDIAN;
70     switch ((last / 4) % 8) {
71       case 0:
72         sinesrc->depth = 8;
73         sinesrc->width = 8;
74         break;
75       case 1:
76         sinesrc->depth = 16;
77         sinesrc->width = 16;
78         break;
79       case 2:
80         sinesrc->depth = 24;
81         sinesrc->width = 32;
82         break;
83       case 3:
84         sinesrc->depth = 32;
85         sinesrc->width = 32;
86         break;
87         /* nomore tests below until i know what 24bit width means to alsa wrt endianness */
88       case 4:
89         sinesrc->depth = 24;
90         sinesrc->width = 24;
91         break;
92       case 5:
93         sinesrc->depth = 20;
94         sinesrc->width = 24;
95         break;
96       case 6:
97         sinesrc->depth = 18;
98         sinesrc->width = 24;
99         break;
100       case 7:
101         /* not used yet */
102         sinesrc->depth = 8;
103         sinesrc->width = 8;
104         break;
105       default:
106         g_assert_not_reached ();
107     }
108
109     g_print ("Setting format to: format:     \"int\"\n"
110         "                   sign:       %s\n"
111         "                   endianness: %d\n"
112         "                   width:      %d\n"
113         "                   depth:      %d\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;
118
119     sinesrc->type = SINE_SRC_FLOAT;
120     switch (temp) {
121       case 0:
122         sinesrc->width = 32;
123         break;
124       case 1:
125         sinesrc->width = 64;
126         break;
127       default:
128         g_assert_not_reached ();
129     }
130     g_print ("Setting format to float width %d\n", sinesrc->width);
131   } else if (last <
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;
134     GstElement *law;
135
136     sinesrc->type = SINE_SRC_INT;
137     sinesrc->sign = TRUE;
138     sinesrc->endianness = G_BYTE_ORDER;
139     sinesrc->depth = 16;
140     sinesrc->width = 16;
141
142     if (temp == 0) {
143       law = gst_element_factory_make ("mulawenc", "mulaw");
144     } else {
145       law = gst_element_factory_make ("alawenc", "alaw");
146     }
147     g_assert (law);
148     gst_element_unlink (src, alsasink);
149     gst_bin_add (GST_BIN (pipeline), law);
150     gst_element_link_many (src, law, alsasink, NULL);
151     if (temp == 0) {
152       g_print ("Setting format to: format:     \"MU law\"\n");
153     } else {
154       g_print ("Setting format to: format:     \"A law\"\n");
155     }
156   } else {
157     g_print ("All formats work like a charm.\n");
158     exit (0);
159   }
160   gst_element_set_state (pipeline, GST_STATE_PLAYING);
161 }
162
163 gint
164 main (gint argc, gchar * argv[])
165 {
166   gst_init (&argc, &argv);
167
168   g_print ("\n"
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");
172   create_pipeline ();
173
174   while (pipeline) {
175     gst_bin_iterate (GST_BIN (pipeline));
176     if ((counter / 200) > last) {
177       last = counter / 200;
178       gst_object_unref (pipeline);
179       create_pipeline ();
180     }
181   }
182
183   return 0;
184 }