3 Ann Hell Ex Machina - Music Software
4 Copyright (C) 2003/2004 Angel Ortega <angel@triptico.com>
6 wav.c - Code for testing the libraries
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 http://www.triptico.com
40 #include "preprocessor.h"
53 float * wave
[CHANNELS
];
54 float output
[CHANNELS
];
72 e1
.note
.type
=EV1_NOTE
;
87 e1
.note
.type
=EV1_NOTE
;
99 e1
.note
.type
=EV1_NOTE
;
111 e1
.note
.type
=EV1_NOTE
;
123 e1
.tempo
.type
=EV1_TEMPO
;
131 e1
.tempo
.tempo
=120.0;
134 e1
.measure
.type
=EV1_MEASURE
;
136 e1
.measure
.trk_id
=-1;
144 char * ptr=preprocess("%examples/example1.ahml");
146 compile("x16-2~0.8,8-4~0.6 c8d#''4/3*6~0.5 x o2e4~0.8o++f");
154 ss_ins_init(&i
[1], 1);
155 load_pat_file(&i
[1], "samples/acpiano.pat");
156 ss_ins_init(&i
[2], 2);
157 /* load_pat_file(&i[2], "samples/synstr1.pat"); */
158 load_pat_file(&i
[2], "samples/flute.pat");
160 /* n_channels=load_wav_file("samples/as-al017.wav", &size, wave); */
161 /* n_channels=load_wav_file("samples/amen1.wav", &size, &s_rate, wave);
162 printf("n_channels: %d\n", n_channels); */
164 load_wav_file(&w
, "samples/amen1.wav");
166 printf("tempo: %lf\n", tempo_from_wave(&w
, 60, 4));
168 ss_ins_init(&i
[0], 0);
169 /* ss_ins_add_layer(&i[0],
170 note_frequency(36), note_frequency(0), note_frequency(127),
171 n_channels, wave, size, s_rate, 0, size); */
172 ss_ins_add_layer(&i
[0], &w
);
175 f=popen("sox -V -t raw -s -r 44100 -c 2 -w - qq.wav","w");
178 if(output_open("default", NULL
) < 0)
180 printf("Error: can't init driver\n");
184 /* 'reverb' with 3 allpass */
186 init_delay(&e, (int)TIME2SAMPLES(20.0 / 1000.0), 0.9, 0, 0, 0, 0);
187 init_delay(&e2, (int)TIME2SAMPLES(36.0 / 1000.0), 0.9, 0, 0, 0, 0);
188 init_delay(&e3, (int)TIME2SAMPLES(39.0 / 1000.0), 0.9, 0, 0, 0, 0);
191 /* init_delay(&e, 44100, 0.9, 150, 0.1, 3.14 / 2, 0); */
195 init_delay(&e4, 1, 1, 1, 4, 3.14 / 2, 0);
199 effect_wobble(&e
[0], 0.5, 0);
200 effect_wobble(&e
[1], 0.5, 0.25);
203 effect_delay(&e
[2], 300);
205 /* allpasses in serial (reverb) */
206 effect_allpass(&e
[3], (int)TIME2SAMPLES(20.0 / 1000.0), 0.9);
207 effect_allpass(&e
[4], (int)TIME2SAMPLES(36.0 / 1000.0), 0.9);
208 effect_allpass(&e
[5], (int)TIME2SAMPLES(39.0 / 1000.0), 0.9);
210 effect_allpass(&e
[6], (int)TIME2SAMPLES(20.0 / 1000.0), 0.9);
211 effect_allpass(&e
[7], (int)TIME2SAMPLES(36.0 / 1000.0), 0.9);
212 effect_allpass(&e
[8], (int)TIME2SAMPLES(39.0 / 1000.0), 0.9);
215 effect_flanger(&e
[9], 44100, 0.9, 150, 0.1, 0.25);
216 effect_flanger(&e
[10], 44100, 0.9, 150, 0.1, 0);
219 effect_fader(&e
[11], 44100 * 6, 0, 1);
224 vol
[0]=1.0; vol
[1]=1.0; vol
[2]=0.0; vol
[3]=0.0;
225 ss_ins_set_channel_map(&i
[0], 4, vol
);
228 event_note_on(0, 0, 36, 1);
229 event_note_off(441000, 0, 36);
232 vol
[0]=0.0; vol
[1]=0.0; vol
[2]=1.0; vol
[3]=1.0;
233 ss_ins_set_channel_map(&i
[1], 4, vol
);
235 event_note_on(44100, 1, 64, 1);
236 event_note_on(44100, 1, 67, 1);
237 event_note_on(44100, 1, 71, 1);
239 event_note_off(44100 * 3, 1, 64);
240 event_note_off(44100 * 3, 1, 67);
241 event_note_off(44100 * 3, 1, 71);
243 event_note_on(44100 * 3, 1, 64, 1);
244 event_note_on(44100 * 3, 1, 66, 1);
245 event_note_on(44100 * 3, 1, 71, 1);
247 event_note_off(44100 * 6, 1, 64);
248 event_note_off(44100 * 6, 1, 66);
249 event_note_off(44100 * 6, 1, 71);
251 event_note_on(44100, 1, 28, 1);
252 event_note_off(44100 * 9, 1, 28);
258 compile("T81.67 o5c1*10 \\ z1s0.5 t-1 x4~0.6,2~0.3,2.~0.2 <c;e-;g><c;e-;g#>|<c;f;g#><d;f;g> s0.8z8 c'gb-c'b-gfg| \\ t-1 o6s1 c1*3.5 b,2 c1*4 ");
264 for(frame
=0,goon
=1;goon
;frame
++)
266 if(e2
->generic
.type
== EV2_END
)
269 while(e2
->generic
.frame
== frame
)
271 if(e2
->generic
.type
== EV2_NOTE_ON
)
272 ss_ins_note_on(&i
[e2
->note_on
.trk_id
],
275 e2
->note_on
.note_id
);
277 if(e2
->generic
.type
== EV2_NOTE_OFF
)
278 ss_ins_note_off(e2
->note_off
.note_id
);
280 if(e2
->generic
.type
== EV2_END
)
286 output_init_frame(output
);
288 ss_ins_frame(0, output
);
289 ss_ins_frame(1, output
);
290 ss_ins_frame(2, output
);
293 if(n
< TIME2SAMPLES(13))
295 output
[0]=process_effect(&e
[0], output
[0]);
296 output
[1]=process_effect(&e
[1], output
[1]);
298 /* output[1]=process_effect(&e[2], output[1]); */
300 /* output[0]=process_effect(&e[3], output[0]);
301 output[0]=process_effect(&e[4], output[0]);
302 output[0]=process_effect(&e[5], output[0]);
304 output[1]=process_effect(&e[6], output[1]);
305 output[1]=process_effect(&e[7], output[1]);
306 output[1]=process_effect(&e[8], output[1]); */
308 /* output[0]=process_effect(&e[9], output[0]);
309 output[1]=process_effect(&e[10], output[1]); */
311 /* output[0]=process_effect(&e[11], output[0]);
312 output[1]=process_effect(&e[11], output[1]); */
316 output_write(output
);
318 /* if(n < TIME2SAMPLES(14))
319 generator_release(&_generators[1]); */
324 printf("clipped: %d optimal volume: %f\n",
325 _output_clipped
, _optimal_volume
);