@@ -79,127 +79,159 @@ int main(int argc, char** argcv)
79
79
printf ("%.*s\n" , (int ) (s -> end - s -> start ), s -> start );
80
80
}
81
81
82
- //-------------------------------------------------------------------------
83
- printf ("test: playing a 440 hz tone\n" );
84
- ls_Node osc = ls -> node_create (ls , osc1_s , Oscillator_s );
85
- ls_Pin osc_out = ls -> node_indexed_output (ls , osc , 0 );
86
- ls_Pin osc_freq = ls -> node_parameter (ls , osc , frequency_s );
87
- ls_Pin osc_detune = ls -> node_parameter (ls , osc , detune_s );
88
-
89
- ls_Node dest = ls -> device_node (ls );
90
- ls_Pin dest_in = ls -> node_indexed_input (ls , dest , 0 );
91
- ls_Connection osc_to_dest ;
92
-
93
- osc_to_dest = ls -> connect_output_to_input (ls , dest_in , osc_out );
94
- ls -> node_start (ls , osc , (ls_Seconds ) { 0.f });
95
- demo_sleep (ls , 0.5 );
96
- //-------------------------------------------------------------------------
97
- printf ("test: disconnect the oscillator (silence)\n" );
98
-
99
- ls -> disconnect (ls , osc_to_dest );
100
-
101
- demo_sleep (ls , 0.5f );
102
- //-------------------------------------------------------------------------
103
- printf ("test: reconnect the oscillator, play at 220Hz\n" );
104
-
105
- ls -> set_float (ls , osc_freq , 220.f );
106
- osc_to_dest = ls -> connect_output_to_input (ls , dest_in , osc_out );
107
- ls -> node_start (ls , osc , (ls_Seconds ) { 0.f });
108
-
109
- demo_sleep (ls , 0.5f );
110
- //-------------------------------------------------------------------------
111
- printf ("test: delete the oscillator while it's running (silence)\n" );
112
-
113
- ls -> node_delete (ls , osc );
114
-
115
- demo_sleep (ls , 0.5 );
116
- //-------------------------------------------------------------------------
117
- printf ("test: create and play an oscillator at 880\n" );
118
-
119
- osc = ls -> node_create (ls , osc2_s , Oscillator_s );
120
- osc_out = ls -> node_indexed_output (ls , osc , 0 );
121
- osc_freq = ls -> node_parameter (ls , osc , frequency_s );
122
- osc_detune = ls -> node_parameter (ls , osc , detune_s );
123
-
124
- ls -> set_float (ls , osc_freq , 880.f );
125
- osc_to_dest = ls -> connect_output_to_input (ls , dest_in , osc_out );
126
- ls -> node_start (ls , osc , (ls_Seconds ) { 0.f });
127
-
128
- demo_sleep (ls , 0.5f );
129
- //-------------------------------------------------------------------------
130
- printf ("test: modulate the oscillator at 440\n" );
82
+ ls_Node dest = ls -> destination_node (ls );
83
+ ls_InputPin dest_in = ls -> node_indexed_input (ls , dest , 0 );
131
84
132
- ls_Node lfo = ls -> node_create (ls , osc3_s , Oscillator_s );
133
- ls_Pin lfo_freq = ls -> node_parameter (ls , lfo , frequency_s );
134
- ls_Pin lfo_ampl = ls -> node_parameter (ls , lfo , amplitude_s );
135
- ls_Pin lfo_out = ls -> node_indexed_output (ls , lfo , 0 );
136
-
137
- ls -> set_float (ls , lfo_freq , 2.f );
138
- ls -> set_float (ls , lfo_ampl , 10.f );
139
- ls -> set_float (ls , osc_freq , 440.f );
140
-
141
- ls_Connection lfo_to_osc = ls -> connect_output_to_input (ls , osc_detune , lfo_out );
142
- ls -> node_start (ls , lfo , (ls_Seconds ) { 0.f });
143
-
144
- demo_sleep (ls , 2.f );
145
85
//-------------------------------------------------------------------------
146
- printf ("test: disconnect modulated oscillator\n" );
147
-
148
- ls -> disconnect (ls , lfo_to_osc );
149
-
150
- demo_sleep (ls , 0.5f );
86
+ if (false)
87
+ {
88
+ printf ("test: playing a 440 hz tone\n" );
89
+ ls_Node osc = ls -> node_create (ls , osc1_s , Oscillator_s );
90
+ ls_OutputPin osc_out = ls -> node_indexed_output (ls , osc , 0 );
91
+ ls_InputPin osc_freq = ls -> node_parameter (ls , osc , frequency_s );
92
+ ls_InputPin osc_detune = ls -> node_parameter (ls , osc , detune_s );
93
+
94
+ ls_Connection osc_to_dest ;
95
+
96
+ osc_to_dest = ls -> connect (ls , dest_in , osc_out );
97
+ ls -> node_start (ls , osc , (ls_Seconds ) { 0.f });
98
+ demo_sleep (ls , 0.5 );
99
+
100
+ printf ("test: disconnect the oscillator (silence)\n" );
101
+
102
+ ls -> disconnect (ls , osc_to_dest );
103
+
104
+ demo_sleep (ls , 0.5f );
105
+
106
+ printf ("test: reconnect the oscillator, play at 220Hz\n" );
107
+
108
+ ls -> set_float (ls , osc_freq , 220.f );
109
+ osc_to_dest = ls -> connect (ls , dest_in , osc_out );
110
+ ls -> node_start (ls , osc , (ls_Seconds ) { 0.f });
111
+
112
+ demo_sleep (ls , 0.5f );
113
+
114
+ printf ("test: delete the oscillator while it's running (silence)\n" );
115
+
116
+ ls -> node_delete (ls , osc );
117
+
118
+ demo_sleep (ls , 0.5 );
119
+ }
151
120
//-------------------------------------------------------------------------
152
- printf ("test: disconnect oscillator\n" );
153
-
154
- ls -> disconnect (ls , osc_to_dest );
155
-
156
- demo_sleep (ls , 0.5f );
121
+ if (false)
122
+ {
123
+ printf ("test: create and play an oscillator at 880\n" );
124
+
125
+ ls_Node osc = ls -> node_create (ls , osc2_s , Oscillator_s );
126
+ ls_OutputPin osc_out = ls -> node_indexed_output (ls , osc , 0 );
127
+ ls_InputPin osc_freq = ls -> node_parameter (ls , osc , frequency_s );
128
+ ls_InputPin osc_detune = ls -> node_parameter (ls , osc , detune_s );
129
+
130
+ ls -> set_float (ls , osc_freq , 880.f );
131
+ ls_Connection osc_to_dest = ls -> connect (ls , dest_in , osc_out );
132
+ ls -> node_start (ls , osc , (ls_Seconds ) { 0.f });
133
+
134
+ demo_sleep (ls , 0.5f );
135
+ //-------------------------------------------------------------------------
136
+ printf ("test: modulate the oscillator at 440\n" );
137
+
138
+ ls_Node lfo = ls -> node_create (ls , osc3_s , Oscillator_s );
139
+ ls_InputPin lfo_freq = ls -> node_parameter (ls , lfo , frequency_s );
140
+ ls_InputPin lfo_ampl = ls -> node_parameter (ls , lfo , amplitude_s );
141
+ ls_OutputPin lfo_out = ls -> node_indexed_output (ls , lfo , 0 );
142
+
143
+ ls -> set_float (ls , lfo_freq , 2.f );
144
+ ls -> set_float (ls , lfo_ampl , 20.f );
145
+ ls -> set_float (ls , osc_freq , 440.f );
146
+
147
+ ls_Connection lfo_to_osc = ls -> connect (ls , osc_detune , lfo_out );
148
+ ls -> node_start (ls , lfo , (ls_Seconds ) { 0.f });
149
+
150
+ demo_sleep (ls , 2.f );
151
+ //-------------------------------------------------------------------------
152
+ printf ("test: disconnect modulated oscillator\n" );
153
+
154
+ ls -> disconnect (ls , lfo_to_osc );
155
+
156
+ demo_sleep (ls , 0.5f );
157
+ //-------------------------------------------------------------------------
158
+ printf ("test: disconnect oscillator\n" );
159
+
160
+ ls -> disconnect (ls , osc_to_dest );
161
+
162
+ demo_sleep (ls , 0.5f );
163
+ }
157
164
//-------------------------------------------------------------------------
158
- printf ("test: play a file, wait for end\n" );
159
-
160
- char buff [1024 ];
161
- sprintf (buff , "%ssamples/mono-music-clip.wav" , asset_base );
162
- ls_BusData musicClip = ls -> bus_create_from_file (ls , buff , false);
163
- ls_Node sampledAudio = ls -> node_create (ls , san_s , SampledAudio_s );
164
- ls_Pin src = ls -> node_setting (ls , sampledAudio , sourceBus_s );
165
- ls_Pin sa_out = ls -> node_indexed_output (ls , sampledAudio , 0 );
166
165
167
- if (musicClip . id != ls_BusData_empty . id )
166
+ if (true )
168
167
{
169
- ls_Connection connection3 = ls -> connect_output_to_input (ls , dest_in , sa_out );
170
- ls -> set_bus (ls , src , musicClip );
171
- ls -> node_start (ls , sampledAudio , (ls_Seconds ) { 0.f });
172
- ls -> node_set_on_ended (ls , sampledAudio , san_on_ended );
173
-
174
- demo_sleep (ls , 20 );
175
- printf ("ended %s\n" , ended_via_flag ? "properly via flag" : "improperly by timeout" );
176
- ls -> disconnect (ls , connection3 );
168
+ printf ("test: play a file, wait for end\n" );
169
+ char buff [1024 ];
170
+ snprintf (buff , sizeof (buff ), "%ssamples/mono-music-clip.wav" , asset_base );
171
+ ls_BusData musicClip = ls -> bus_create_from_file (ls , buff , false);
172
+ if (musicClip .id != ls_BusData_empty .id )
173
+ {
174
+ ls_Node sampledAudio ;
175
+ ls_InputPin sampledAudio_srcBus ;
176
+ ls_OutputPin sa_out ;
177
+ ls_Connection connection3 ;
178
+
179
+ sampledAudio = ls -> node_create (ls , san_s , SampledAudio_s );
180
+ sampledAudio_srcBus = ls -> node_setting (ls , sampledAudio , sourceBus_s );
181
+ sa_out = ls -> node_indexed_output (ls , sampledAudio , 0 );
182
+ connection3 = ls -> connect (ls , dest_in , sa_out );
183
+
184
+ if (connection3 .id != ls_Connection_empty .id ) {
185
+ ls -> node_diagnose (ls , sampledAudio );
186
+ ls -> set_bus (ls , sampledAudio_srcBus , musicClip );
187
+ ls -> node_start (ls , sampledAudio , (ls_Seconds ) { 0.f });
188
+ ls -> node_set_on_ended (ls , sampledAudio , san_on_ended );
189
+
190
+ demo_sleep (ls , 1 );
191
+ printf ("scheduled state %s\n" , ls -> node_scheduled_state_name (ls , sampledAudio ));
192
+ demo_sleep (ls , 5 );
193
+ ls -> disconnect (ls , connection3 );
194
+
195
+ printf (" ended %s\n" , ended_via_flag ? "properly via flag" : "improperly by timeout" );
196
+ }
197
+ else {
198
+ printf (" Couldn't connect the sampled audio to the destination\n" );
199
+ }
200
+ }
177
201
}
178
202
179
203
//-------------------------------------------------------------------------
180
- printf ("test: stereo panning\n" );
181
-
182
- sprintf (buff , "%ssamples/trainrolling.wav" , asset_base );
183
- ls_BusData trainClip = ls -> bus_create_from_file (ls , buff , false);
184
- ls -> set_bus (ls , src , trainClip );
185
-
204
+ if (true)
186
205
{
187
- ls_Node stPanner = ls -> node_create (ls , stpan_s , StereoPanner_s );
188
- ls_Pin stPanner_out = ls -> node_indexed_output (ls , stPanner , 0 );
189
- ls_Pin stPanner_in = ls -> node_indexed_input (ls , stPanner , 0 );
190
- ls_Connection connection3 = ls -> connect_output_to_input (ls , dest_in , stPanner_out );
191
- ls_Connection connection4 = ls -> connect_output_to_input (ls , stPanner_in , sa_out );
192
- ls -> node_schedule (ls , sampledAudio , (ls_Seconds ) { 0.f }, -1 ); // -1 to loop forever
193
- ls_Pin pan_param = ls -> node_parameter (ls , stPanner , pan_s );
194
- float seconds = 4.f ;
195
- float half = seconds * 0.5f ;
196
- for (float i = 0 ; i < seconds ; i += 0.01f ) {
197
- float x = (i - half ) / half ;
198
- ls -> set_float (ls , pan_param , x );
199
- thrd_sleep (& (struct timespec ) {
200
- .tv_sec = 0 ,
201
- .tv_nsec = (long )(1000000000.f * 0.01f )
202
- }, NULL );
206
+ printf ("test: stereo panning\n" );
207
+ char buff [1024 ];
208
+ sprintf (buff , "%ssamples/trainrolling.wav" , asset_base );
209
+ ls_BusData trainClip = ls -> bus_create_from_file (ls , buff , false);
210
+ if (trainClip .id != ls_BusData_empty .id )
211
+ {
212
+ ls_Node sampledAudio = ls -> node_create (ls , san_s , SampledAudio_s );
213
+ ls_InputPin src = ls -> node_setting (ls , sampledAudio , sourceBus_s );
214
+ ls_OutputPin sa_out = ls -> node_indexed_output (ls , sampledAudio , 0 );
215
+ ls -> set_bus (ls , src , trainClip );
216
+
217
+ ls_Node stPanner = ls -> node_create (ls , stpan_s , StereoPanner_s );
218
+ ls_OutputPin stPanner_out = ls -> node_indexed_output (ls , stPanner , 0 );
219
+ ls_InputPin stPanner_in = ls -> node_indexed_input (ls , stPanner , 0 );
220
+ ls_Connection connection3 = ls -> connect (ls , dest_in , stPanner_out );
221
+ ls_Connection connection4 = ls -> connect (ls , stPanner_in , sa_out );
222
+ ls -> node_schedule (ls , sampledAudio , (ls_Seconds ) { 0.f }, -1 ); // -1 to loop forever
223
+ ls_InputPin pan_param = ls -> node_parameter (ls , stPanner , pan_s );
224
+
225
+ float seconds = 4.f ;
226
+ float half = seconds * 0.5f ;
227
+ for (float i = 0 ; i < seconds ; i += 0.01f ) {
228
+ float x = (i - half ) / half ;
229
+ ls -> set_float (ls , pan_param , x );
230
+ thrd_sleep (& (struct timespec ) {
231
+ .tv_sec = 0 ,
232
+ .tv_nsec = (long )(1000000000.f * 0.01f )
233
+ }, NULL );
234
+ }
203
235
}
204
236
}
205
237
0 commit comments