Added .cvsignore.
[ahxm.git] / wav.c
blob14aec6530a09f84555ef258af87f964ad924f5cc
1 /*
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
26 #include "config.h"
28 #include <stdio.h>
29 #include <string.h>
30 #include <stdlib.h>
31 #include <math.h>
33 #include "core.h"
34 #include "output.h"
35 #include "ss_gen.h"
36 #include "effect.h"
37 #include "ss_ins.h"
38 #include "input.h"
39 #include "event.h"
41 /*******************
42 Data
43 ********************/
45 /* defined in compiler.y */
46 int compile(char * code);
48 /*******************
49 Code
50 ********************/
52 int main(void)
54 float * wave[CHANNELS];
55 float output[CHANNELS];
56 float vol[CHANNELS];
57 int s_rate;
58 double size;
59 int n_channels;
60 FILE * f;
61 int n, m;
62 struct effect e[16];
63 struct ss_ins i[16];
64 int goon;
65 int frame;
66 struct ss_wave w;
68 union event1 e1;
69 union event2 * e2;
70 #ifdef QQ
72 event1_clear();
74 e1.note.type=EV1_NOTE;
75 e1.note.time=0;
76 e1.note.trk_id=1;
77 e1.note.note=60;
78 e1.note.len=1.0;
79 e1.note.vol=1.0;
81 new_event1(&e1);
83 e1.note.note=63;
84 new_event1(&e1);
86 e1.note.note=67;
87 new_event1(&e1);
89 e1.note.type=EV1_NOTE;
90 e1.note.time=1.0;
91 e1.note.note=60;
93 new_event1(&e1);
95 e1.note.note=65;
96 new_event1(&e1);
98 e1.note.note=68;
99 new_event1(&e1);
101 e1.note.type=EV1_NOTE;
102 e1.note.time=2.0;
103 e1.note.note=60;
105 new_event1(&e1);
107 e1.note.note=63;
108 new_event1(&e1);
110 e1.note.note=67;
111 new_event1(&e1);
113 e1.note.type=EV1_NOTE;
114 e1.note.time=3.0;
115 e1.note.note=60;
117 new_event1(&e1);
119 e1.note.note=65;
120 new_event1(&e1);
122 e1.note.note=68;
123 new_event1(&e1);
125 e1.tempo.type=EV1_TEMPO;
126 e1.tempo.time=0;
127 e1.tempo.trk_id=-1;
128 e1.tempo.tempo=60.0;
130 new_event1(&e1);
132 e1.tempo.time=2;
133 e1.tempo.tempo=120.0;
134 new_event1(&e1);
136 e1.meter.type=EV1_METER;
137 e1.meter.time=0;
138 e1.meter.trk_id=-1;
139 e1.meter.num=4;
140 e1.meter.den=4;
142 new_event1(&e1);
143 #endif
146 char * ptr=preprocess("%examples/example1.ahml");
147 printf("%s\n",ptr);
148 compile("x16-2~0.8,8-4~0.6 c8d#''4/3*6~0.5 x o2e4~0.8o++f");
151 _interpolation=3;
152 _frequency=44100;
153 _master_volume=0.5;
154 _n_channels=4;
156 ss_ins_init(&i[1], 1);
157 load_pat_file(&i[1], "samples/acpiano.pat");
158 ss_ins_init(&i[2], 2);
159 /* load_pat_file(&i[2], "samples/synstr1.pat"); */
160 load_pat_file(&i[2], "samples/flute.pat");
162 /* n_channels=load_wav_file("samples/as-al017.wav", &size, wave); */
163 /* n_channels=load_wav_file("samples/amen1.wav", &size, &s_rate, wave);
164 printf("n_channels: %d\n", n_channels); */
166 load_wav_file(&w, "samples/amen1.wav");
168 printf("tempo: %lf\n", tempo_from_wave(&w, 60, 4));
170 ss_ins_init(&i[0], 0);
171 /* ss_ins_add_layer(&i[0],
172 note_frequency(36), note_frequency(0), note_frequency(127),
173 n_channels, wave, size, s_rate, 0, size); */
174 ss_ins_add_layer(&i[0], &w);
177 f=popen("sox -V -t raw -s -r 44100 -c 2 -w - qq.wav","w");
180 if(output_open("default", NULL) < 0)
182 printf("Error: can't init driver\n");
183 return(1);
186 /* 'reverb' with 3 allpass */
188 init_delay(&e, (int)TIME2SAMPLES(20.0 / 1000.0), 0.9, 0, 0, 0, 0);
189 init_delay(&e2, (int)TIME2SAMPLES(36.0 / 1000.0), 0.9, 0, 0, 0, 0);
190 init_delay(&e3, (int)TIME2SAMPLES(39.0 / 1000.0), 0.9, 0, 0, 0, 0);
193 /* init_delay(&e, 44100, 0.9, 150, 0.1, 3.14 / 2, 0); */
195 /* wobble */
197 init_delay(&e4, 1, 1, 1, 4, 3.14 / 2, 0);
200 /* wobble */
201 effect_wobble(&e[0], 0.5, 0);
202 effect_wobble(&e[1], 0.5, 0.25);
204 /* delay */
205 effect_delay(&e[2], 300);
207 /* allpasses in serial (reverb) */
208 effect_allpass(&e[3], (int)TIME2SAMPLES(20.0 / 1000.0), 0.9);
209 effect_allpass(&e[4], (int)TIME2SAMPLES(36.0 / 1000.0), 0.9);
210 effect_allpass(&e[5], (int)TIME2SAMPLES(39.0 / 1000.0), 0.9);
212 effect_allpass(&e[6], (int)TIME2SAMPLES(20.0 / 1000.0), 0.9);
213 effect_allpass(&e[7], (int)TIME2SAMPLES(36.0 / 1000.0), 0.9);
214 effect_allpass(&e[8], (int)TIME2SAMPLES(39.0 / 1000.0), 0.9);
216 /* flanger */
217 effect_flanger(&e[9], 44100, 0.9, 150, 0.1, 0.25);
218 effect_flanger(&e[10], 44100, 0.9, 150, 0.1, 0);
220 /* fader */
221 effect_fader(&e[11], 44100 * 6, 0, 1);
222 #ifdef QQ
223 /* events */
224 event_clear();
226 vol[0]=1.0; vol[1]=1.0; vol[2]=0.0; vol[3]=0.0;
227 ss_ins_set_channel_map(&i[0], 4, vol);
229 /* drum loop */
230 event_note_on(0, 0, 36, 1);
231 event_note_off(441000, 0, 36);
233 /* piano */
234 vol[0]=0.0; vol[1]=0.0; vol[2]=1.0; vol[3]=1.0;
235 ss_ins_set_channel_map(&i[1], 4, vol);
237 event_note_on(44100, 1, 64, 1);
238 event_note_on(44100, 1, 67, 1);
239 event_note_on(44100, 1, 71, 1);
241 event_note_off(44100 * 3, 1, 64);
242 event_note_off(44100 * 3, 1, 67);
243 event_note_off(44100 * 3, 1, 71);
245 event_note_on(44100 * 3, 1, 64, 1);
246 event_note_on(44100 * 3, 1, 66, 1);
247 event_note_on(44100 * 3, 1, 71, 1);
249 event_note_off(44100 * 6, 1, 64);
250 event_note_off(44100 * 6, 1, 66);
251 event_note_off(44100 * 6, 1, 71);
253 event_note_on(44100, 1, 28, 1);
254 event_note_off(44100 * 9, 1, 28);
256 event_sort();
257 #endif
259 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 ");
261 event1_to_event2();
263 e2=_events_2;
265 for(frame=0,goon=1;goon;frame++)
267 if(e2->generic.type == EV2_END)
268 break;
270 while(e2->generic.frame == frame)
272 if(e2->generic.type == EV2_NOTE_ON)
273 ss_ins_note_on(&i[e2->note_on.trk_id],
274 e2->note_on.note,
275 e2->note_on.vol,
276 e2->note_on.note_id);
277 else
278 if(e2->generic.type == EV2_NOTE_OFF)
279 ss_ins_note_off(&i[e2->note_off.trk_id],
280 e2->note_off.note_id);
281 else
282 if(e2->generic.type == EV2_END)
283 goon=0;
285 e2++;
288 output_init_frame(output);
290 ss_ins_frame(&i[0], output);
291 ss_ins_frame(&i[1], output);
292 ss_ins_frame(&i[2], output);
294 #ifdef QQ
295 if(n < TIME2SAMPLES(13))
297 output[0]=process_effect(&e[0], output[0]);
298 output[1]=process_effect(&e[1], output[1]);
300 /* output[1]=process_effect(&e[2], output[1]); */
302 /* output[0]=process_effect(&e[3], output[0]);
303 output[0]=process_effect(&e[4], output[0]);
304 output[0]=process_effect(&e[5], output[0]);
306 output[1]=process_effect(&e[6], output[1]);
307 output[1]=process_effect(&e[7], output[1]);
308 output[1]=process_effect(&e[8], output[1]); */
310 /* output[0]=process_effect(&e[9], output[0]);
311 output[1]=process_effect(&e[10], output[1]); */
313 /* output[0]=process_effect(&e[11], output[0]);
314 output[1]=process_effect(&e[11], output[1]); */
316 #endif
318 output_write(output);
320 /* if(n < TIME2SAMPLES(14))
321 generator_release(&_generators[1]); */
324 output_close();
326 printf("clipped: %d optimal volume: %f\n",
327 _output_clipped, _optimal_volume);
329 return(0);