1 /* GSequencer - Advanced GTK Sequencer
2  * Copyright (C) 2005-2020 Joël Krähemann
3  *
4  * This file is part of GSequencer.
5  *
6  * GSequencer is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * GSequencer 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
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with GSequencer.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include <glib.h>
21 #include <glib-object.h>
22 
23 #include <CUnit/CUnit.h>
24 #include <CUnit/Automated.h>
25 #include <CUnit/Basic.h>
26 
27 #include <ags/libags.h>
28 #include <ags/libags-audio.h>
29 
30 #include <math.h>
31 
32 int ags_fx_peak_audio_signal_test_init_suite();
33 int ags_fx_peak_audio_signal_test_clean_suite();
34 
35 void ags_fx_peak_audio_signal_test_new();
36 void ags_fx_peak_audio_signal_test_run_inter();
37 
38 AgsApplicationContext *application_context;
39 
40 /* The suite initialization function.
41  * Opens the temporary file used by the tests.
42  * Returns zero on success, non-zero otherwise.
43  */
44 int
ags_fx_peak_audio_signal_test_init_suite()45 ags_fx_peak_audio_signal_test_init_suite()
46 {
47   application_context = ags_audio_application_context_new();
48 
49   ags_application_context_prepare(application_context);
50   ags_application_context_setup(application_context);
51 
52   return(0);
53 }
54 
55 /* The suite cleanup function.
56  * Closes the temporary file used by the tests.
57  * Returns zero on success, non-zero otherwise.
58  */
59 int
ags_fx_peak_audio_signal_test_clean_suite()60 ags_fx_peak_audio_signal_test_clean_suite()
61 {
62   return(0);
63 }
64 
65 void
ags_fx_peak_audio_signal_test_new()66 ags_fx_peak_audio_signal_test_new()
67 {
68   AgsAudioSignal *audio_signal;
69   AgsFxPeakAudioSignal *fx_peak_audio_signal;
70 
71   audio_signal = g_object_new(AGS_TYPE_AUDIO_SIGNAL,
72 			      NULL);
73 
74   fx_peak_audio_signal = ags_fx_peak_audio_signal_new(audio_signal);
75 
76   CU_ASSERT(fx_peak_audio_signal != NULL);
77   CU_ASSERT(AGS_RECALL_AUDIO_SIGNAL(fx_peak_audio_signal)->source == audio_signal);
78 }
79 
80 void
ags_fx_peak_audio_signal_test_run_inter()81 ags_fx_peak_audio_signal_test_run_inter()
82 {
83   AgsAudio *audio;
84   AgsChannel *channel;
85   AgsRecycling *recycling;
86   AgsAudioSignal *audio_signal;
87   AgsRecallContainer *recall_container;
88   AgsFxPeakAudio *fx_peak_audio;
89   AgsFxPeakAudioProcessor *fx_peak_audio_processor;
90   AgsFxPeakChannel *fx_peak_channel;
91   AgsFxPeakChannelProcessor *fx_peak_channel_processor;
92   AgsFxPeakRecycling *fx_peak_recycling;
93   AgsFxPeakAudioSignal *fx_peak_audio_signal;
94 
95   /* audio */
96   audio = g_object_new(AGS_TYPE_AUDIO,
97 		       NULL);
98 
99   recall_container = ags_recall_container_new();
100   ags_audio_add_recall_container(audio,
101 				 recall_container);
102 
103   fx_peak_audio = ags_fx_peak_audio_new(audio);
104   ags_recall_set_sound_scope(fx_peak_audio, AGS_SOUND_SCOPE_PLAYBACK);
105   ags_recall_container_add(recall_container,
106 			   fx_peak_audio);
107 
108   CU_ASSERT(fx_peak_audio != NULL);
109 
110   /* audio processor */
111   fx_peak_audio_processor = ags_fx_peak_audio_processor_new(audio);
112   ags_recall_set_sound_scope(fx_peak_audio_processor, AGS_SOUND_SCOPE_PLAYBACK);
113 
114   g_object_set(fx_peak_audio_processor,
115 	       "recall-audio", fx_peak_audio,
116 	       NULL);
117 
118   ags_recall_container_add(recall_container,
119 			   fx_peak_audio_processor);
120 
121   CU_ASSERT(fx_peak_audio_processor != NULL);
122 
123   /* channel */
124   channel = g_object_new(AGS_TYPE_CHANNEL,
125 			 NULL);
126 
127   ags_channel_add_recall_container(channel,
128 				   recall_container);
129 
130   fx_peak_channel = ags_fx_peak_channel_new(channel);
131   ags_recall_set_sound_scope(fx_peak_channel, AGS_SOUND_SCOPE_PLAYBACK);
132 
133   g_object_set(fx_peak_channel,
134 	       "recall-audio", fx_peak_audio,
135 	       NULL);
136 
137   ags_recall_container_add(recall_container,
138 			   fx_peak_channel);
139 
140   CU_ASSERT(fx_peak_channel != NULL);
141 
142   /* channel processor */
143   fx_peak_channel_processor = ags_fx_peak_channel_processor_new(channel);
144   ags_recall_set_sound_scope(fx_peak_channel_processor, AGS_SOUND_SCOPE_PLAYBACK);
145 
146   g_object_set(fx_peak_channel_processor,
147 	       "recall-audio", fx_peak_audio,
148 	       "recall-channel", fx_peak_channel,
149 	       NULL);
150 
151   ags_recall_container_add(recall_container,
152 			   fx_peak_channel_processor);
153 
154   CU_ASSERT(fx_peak_channel_processor != NULL);
155 
156   /* recycling */
157   recycling = g_object_new(AGS_TYPE_RECYCLING,
158 			   NULL);
159 
160   fx_peak_recycling = ags_fx_peak_recycling_new(recycling);
161   ags_recall_set_sound_scope(fx_peak_recycling, AGS_SOUND_SCOPE_PLAYBACK);
162 
163   ags_recall_add_child(fx_peak_channel_processor,
164 		       fx_peak_recycling);
165 
166   CU_ASSERT(fx_peak_recycling != NULL);
167 
168   /* audio signal */
169   audio_signal = g_object_new(AGS_TYPE_AUDIO_SIGNAL,
170 			      NULL);
171 
172   ags_audio_signal_stream_resize(audio_signal,
173 				 3);
174   audio_signal->stream_current = audio_signal->stream;
175 
176   fx_peak_audio_signal = ags_fx_peak_audio_signal_new(audio_signal);
177   ags_recall_set_sound_scope(fx_peak_audio_signal, AGS_SOUND_SCOPE_PLAYBACK);
178 
179   ags_recall_add_child(fx_peak_recycling,
180 		       fx_peak_audio_signal);
181 
182   CU_ASSERT(fx_peak_audio_signal != NULL);
183 
184   /* run inter - attempt #0 */
185   ags_recall_run_inter(fx_peak_audio_signal);
186 
187   /* run inter - attempt #1 */
188   audio_signal->stream_current = NULL;
189 
190   ags_recall_run_inter(fx_peak_audio_signal);
191 }
192 
193 int
main(int argc,char ** argv)194 main(int argc, char **argv)
195 {
196   CU_pSuite pSuite = NULL;
197 
198   putenv("LC_ALL=C");
199   putenv("LANG=C");
200 
201   putenv("LADSPA_PATH=\"\"");
202   putenv("DSSI_PATH=\"\"");
203   putenv("LV2_PATH=\"\"");
204 
205   /* initialize the CUnit test registry */
206   if(CUE_SUCCESS != CU_initialize_registry()){
207     return CU_get_error();
208   }
209 
210   /* add a suite to the registry */
211   pSuite = CU_add_suite("AgsFxPeakAudioSignalTest", ags_fx_peak_audio_signal_test_init_suite, ags_fx_peak_audio_signal_test_clean_suite);
212 
213   if(pSuite == NULL){
214     CU_cleanup_registry();
215 
216     return CU_get_error();
217   }
218 
219   /* add the tests to the suite */
220   if((CU_add_test(pSuite, "test of AgsFxPeakAudioSignal new", ags_fx_peak_audio_signal_test_new) == NULL) ||
221      (CU_add_test(pSuite, "test of AgsFxPeakAudioSignal run inter", ags_fx_peak_audio_signal_test_run_inter) == NULL)){
222     CU_cleanup_registry();
223 
224     return CU_get_error();
225   }
226 
227   /* Run all tests using the CUnit Basic interface */
228   CU_basic_set_mode(CU_BRM_VERBOSE);
229   CU_basic_run_tests();
230 
231   CU_cleanup_registry();
232 
233   return(CU_get_error());
234 }
235