The checkpoint variables in wav files have been deleted, as offsets
[ahxm.git] / wav.c
bloba0f0fc2d784281c0e9f1e94f3f36e1964e84b485
1 /*
3 Ann Hell Ex Machina - Music Software
4 Copyright (C) 2003/2005 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 "ss_core.h"
34 #include "ss_output.h"
36 /*******************
37 Data
38 ********************/
40 /* defined in compiler.y */
41 int compile(char * code);
42 int compile_file(char * file);
44 /*******************
45 Code
46 ********************/
48 int main(int argc, char * argv[])
50 char * ahs_file="examples/example2.ahs";
52 #if 0
53 float * wave[CHANNELS];
54 float output[CHANNELS];
55 float vol[CHANNELS];
56 int s_rate;
57 double size;
58 int n_channels;
59 FILE * f;
60 int n, m;
61 struct effect e[16];
62 struct ss_ins i[16];
63 int goon;
64 int frame;
65 struct ss_wave w;
66 union event1 e1;
67 union event2 * e2;
68 #endif
69 #if 0
71 event1_clear();
73 e1.note.type=EV1_NOTE;
74 e1.note.time=0;
75 e1.note.trk_id=1;
76 e1.note.note=60;
77 e1.note.len=1.0;
78 e1.note.vol=1.0;
80 new_event1(&e1);
82 e1.note.note=63;
83 new_event1(&e1);
85 e1.note.note=67;
86 new_event1(&e1);
88 e1.note.type=EV1_NOTE;
89 e1.note.time=1.0;
90 e1.note.note=60;
92 new_event1(&e1);
94 e1.note.note=65;
95 new_event1(&e1);
97 e1.note.note=68;
98 new_event1(&e1);
100 e1.note.type=EV1_NOTE;
101 e1.note.time=2.0;
102 e1.note.note=60;
104 new_event1(&e1);
106 e1.note.note=63;
107 new_event1(&e1);
109 e1.note.note=67;
110 new_event1(&e1);
112 e1.note.type=EV1_NOTE;
113 e1.note.time=3.0;
114 e1.note.note=60;
116 new_event1(&e1);
118 e1.note.note=65;
119 new_event1(&e1);
121 e1.note.note=68;
122 new_event1(&e1);
124 e1.tempo.type=EV1_TEMPO;
125 e1.tempo.time=0;
126 e1.tempo.trk_id=-1;
127 e1.tempo.tempo=60.0;
129 new_event1(&e1);
131 e1.tempo.time=2;
132 e1.tempo.tempo=120.0;
133 new_event1(&e1);
135 e1.meter.type=EV1_METER;
136 e1.meter.time=0;
137 e1.meter.trk_id=-1;
138 e1.meter.num=4;
139 e1.meter.den=4;
141 new_event1(&e1);
142 #endif
145 char * ptr=preprocess("%examples/example1.ahml");
146 printf("%s\n",ptr);
147 compile("x16-2~0.8,8-4~0.6 c8d#''4/3*6~0.5 x o2e4~0.8o++f");
150 ss_interpolation=3;
151 ss_frequency=44100;
152 ss_master_volume=0.5;
153 ss_nchannels=4;
154 #if 0
155 ss_ins_init(&i[1], 1);
156 load_pat_file(&i[1], "samples/acpiano.pat");
157 ss_ins_init(&i[2], 2);
158 /* load_pat_file(&i[2], "samples/synstr1.pat"); */
159 load_pat_file(&i[2], "samples/flute.pat");
161 /* n_channels=load_wav_file("samples/as-al017.wav", &size, wave); */
162 /* n_channels=load_wav_file("samples/amen1.wav", &size, &s_rate, wave);
163 printf("n_channels: %d\n", n_channels); */
165 load_wav_file(&w, "samples/amen1.wav");
167 printf("tempo: %lf\n", tempo_from_wave(&w, 60, 1));
169 ss_ins_init(&i[0], 0);
170 /* ss_ins_add_layer(&i[0],
171 note_frequency(36), note_frequency(0), note_frequency(127),
172 n_channels, wave, size, s_rate, 0, size); */
173 ss_ins_add_layer(&i[0], &w);
174 #endif
177 f=popen("sox -V -t raw -s -r 44100 -c 2 -w - qq.wav","w");
180 if(ss_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);
199 #if 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 #endif
223 #if 0
224 /* events */
225 event_clear();
227 vol[0]=1.0; vol[1]=1.0; vol[2]=0.0; vol[3]=0.0;
228 ss_ins_set_channel_map(&i[0], 4, vol);
230 /* drum loop */
231 event_note_on(0, 0, 36, 1);
232 event_note_off(441000, 0, 36);
234 /* piano */
235 vol[0]=0.0; vol[1]=0.0; vol[2]=1.0; vol[3]=1.0;
236 ss_ins_set_channel_map(&i[1], 4, vol);
238 event_note_on(44100, 1, 64, 1);
239 event_note_on(44100, 1, 67, 1);
240 event_note_on(44100, 1, 71, 1);
242 event_note_off(44100 * 3, 1, 64);
243 event_note_off(44100 * 3, 1, 67);
244 event_note_off(44100 * 3, 1, 71);
246 event_note_on(44100 * 3, 1, 64, 1);
247 event_note_on(44100 * 3, 1, 66, 1);
248 event_note_on(44100 * 3, 1, 71, 1);
250 event_note_off(44100 * 6, 1, 64);
251 event_note_off(44100 * 6, 1, 66);
252 event_note_off(44100 * 6, 1, 71);
254 event_note_on(44100, 1, 28, 1);
255 event_note_off(44100 * 9, 1, 28);
257 event_sort();
258 #endif
260 #if 0
261 /* 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 "); */
262 if(compile("{ pat 'samples/acpiano.pat' echo 0 1s 0.5\n/* broken\ncomment */ echo 1 1.5s 0.3 }\n z1 v1 <c;e&;g>|<c;e&;g#>|<c;f;g#>|<d;f;g>\n\\\n{ wav 'samples/amen1.wav' c5 c0 g10\nflanger 0 1s 0.9 3ms 0.1 0.5 flanger 1 1s 0.9 3ms 0.1 0 }\no5 c1*4"))
264 exit(0);
266 #endif
268 if(argc > 1)
269 ahs_file=argv[1];
271 if(compile_file(ahs_file))
273 exit(0);
276 /* event1_to_event2();*/
277 /* generate_ss_song();*/
279 ss_song_render();
280 /* midi_song_play();*/
281 #if 0
282 e2=_events_2;
284 for(frame=0,goon=1;goon;frame++)
286 if(e2->generic.type == EV2_END)
287 break;
289 while(e2->generic.frame == frame)
291 if(e2->generic.type == EV2_NOTE_ON)
292 ss_ins_note_on(&i[e2->note_on.trk_id],
293 e2->note_on.note,
294 e2->note_on.vol,
295 e2->note_on.note_id);
296 else
297 if(e2->generic.type == EV2_NOTE_OFF)
298 ss_ins_note_off(&i[e2->note_off.trk_id],
299 e2->note_off.note_id);
300 else
301 if(e2->generic.type == EV2_END)
302 goon=0;
304 e2++;
307 ss_output_init_frame(output);
309 ss_ins_frame(&i[0], output);
310 ss_ins_frame(&i[1], output);
311 ss_ins_frame(&i[2], output);
313 #if 0
314 if(n < TIME2SAMPLES(13))
316 output[0]=process_effect(&e[0], output[0]);
317 output[1]=process_effect(&e[1], output[1]);
319 /* output[1]=process_effect(&e[2], output[1]); */
321 /* output[0]=process_effect(&e[3], output[0]);
322 output[0]=process_effect(&e[4], output[0]);
323 output[0]=process_effect(&e[5], output[0]);
325 output[1]=process_effect(&e[6], output[1]);
326 output[1]=process_effect(&e[7], output[1]);
327 output[1]=process_effect(&e[8], output[1]); */
329 /* output[0]=process_effect(&e[9], output[0]);
330 output[1]=process_effect(&e[10], output[1]); */
332 /* output[0]=process_effect(&e[11], output[0]);
333 output[1]=process_effect(&e[11], output[1]); */
335 #endif
337 ss_output_write(output);
339 /* if(n < TIME2SAMPLES(14))
340 generator_release(&_generators[1]); */
342 #endif
343 ss_output_close();
345 printf("clipped: %d optimal volume: %f\n",
346 ss_output_clipped, ss_optimal_volume);
348 return(0);