Updated TODO.
[ahxm.git] / wav.c
blobc6f75b4dd44b3e912d6c585ed69915484ad8dfd3
1 /*
3 Ann Hell Ex Machina - Music Software
4 Copyright (C) 2003 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"
40 #include "preprocessor.h"
41 #include "compiler.h"
43 /*******************
44 Data
45 ********************/
47 /*******************
48 Code
49 ********************/
51 int main(void)
53 float * wave[CHANNELS];
54 float output[CHANNELS];
55 float vol[CHANNELS];
56 double size;
57 int n_channels;
58 FILE * f;
59 int n, m;
60 struct effect e[16];
61 struct ss_ins i[16];
62 struct event * ev;
63 int goon;
64 int frame;
68 char * ptr=preprocess("%examples/example1.ahml");
69 printf("%s\n",ptr);
70 compile("x16-2~0.8,8-4~0.6 c8d#''4/3*6~0.5 x o2e4~0.8o++f");
73 _linear_interpolation=1;
74 _frequency=44100;
75 _master_volume=0.5;
76 _n_channels=4;
78 ss_ins_init(&i[1], 1);
79 load_pat_file(&i[1], "samples/acpiano.pat");
80 load_pat_file(&i[1], "samples/synstr1.pat");
82 /* n_channels=load_wav_file("samples/as-al017.wav", &size, wave); */
83 n_channels=load_wav_file("samples/amen1.wav", &size, wave);
84 printf("n_channels: %d\n", n_channels);
86 ss_ins_init(&i[0], 0);
87 ss_ins_add_layer(&i[0],
88 note_frequency(36), note_frequency(0), note_frequency(127),
89 n_channels, wave, size, 0, size);
92 f=popen("sox -V -t raw -s -r 44100 -c 2 -w - qq.wav","w");
95 if(output_open("default", NULL) < 0)
97 printf("Error: can't init driver\n");
98 return(1);
101 /* 'reverb' with 3 allpass */
103 init_delay(&e, (int)TIME2SAMPLES(20.0 / 1000.0), 0.9, 0, 0, 0, 0);
104 init_delay(&e2, (int)TIME2SAMPLES(36.0 / 1000.0), 0.9, 0, 0, 0, 0);
105 init_delay(&e3, (int)TIME2SAMPLES(39.0 / 1000.0), 0.9, 0, 0, 0, 0);
108 /* init_delay(&e, 44100, 0.9, 150, 0.1, 3.14 / 2, 0); */
110 /* wobble */
112 init_delay(&e4, 1, 1, 1, 4, 3.14 / 2, 0);
115 /* wobble */
116 effect_wobble(&e[0], 0.5, 0);
117 effect_wobble(&e[1], 0.5, 0.25);
119 /* delay */
120 effect_delay(&e[2], 300);
122 /* allpasses in serial (reverb) */
123 effect_allpass(&e[3], (int)TIME2SAMPLES(20.0 / 1000.0), 0.9);
124 effect_allpass(&e[4], (int)TIME2SAMPLES(36.0 / 1000.0), 0.9);
125 effect_allpass(&e[5], (int)TIME2SAMPLES(39.0 / 1000.0), 0.9);
127 effect_allpass(&e[6], (int)TIME2SAMPLES(20.0 / 1000.0), 0.9);
128 effect_allpass(&e[7], (int)TIME2SAMPLES(36.0 / 1000.0), 0.9);
129 effect_allpass(&e[8], (int)TIME2SAMPLES(39.0 / 1000.0), 0.9);
131 /* flanger */
132 effect_flanger(&e[9], 44100, 0.9, 150, 0.1, 0.25);
133 effect_flanger(&e[10], 44100, 0.9, 150, 0.1, 0);
135 /* fader */
136 effect_fader(&e[11], 44100 * 6, 0, 1);
137 #ifdef QQ
138 /* events */
139 event_clear();
141 vol[0]=1.0; vol[1]=1.0; vol[2]=0.0; vol[3]=0.0;
142 ss_ins_set_channel_map(&i[0], 4, vol);
144 /* drum loop */
145 event_note_on(0, 0, 36, 1);
146 event_note_off(441000, 0, 36);
148 /* piano */
149 vol[0]=0.0; vol[1]=0.0; vol[2]=1.0; vol[3]=1.0;
150 ss_ins_set_channel_map(&i[1], 4, vol);
152 event_note_on(44100, 1, 64, 1);
153 event_note_on(44100, 1, 67, 1);
154 event_note_on(44100, 1, 71, 1);
156 event_note_off(44100 * 3, 1, 64);
157 event_note_off(44100 * 3, 1, 67);
158 event_note_off(44100 * 3, 1, 71);
160 event_note_on(44100 * 3, 1, 64, 1);
161 event_note_on(44100 * 3, 1, 66, 1);
162 event_note_on(44100 * 3, 1, 71, 1);
164 event_note_off(44100 * 6, 1, 64);
165 event_note_off(44100 * 6, 1, 66);
166 event_note_off(44100 * 6, 1, 71);
168 event_note_on(44100, 1, 28, 1);
169 event_note_off(44100 * 9, 1, 28);
171 event_sort();
172 #endif
174 event_clear();
175 compile("o3c1*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");
176 event_sort();
178 ev=_events;
180 for(frame=0,goon=1;goon;frame++)
182 if(ev->type == EVENT_END_SONG)
183 break;
185 while(ev->frame == frame)
187 /* processes the event */
188 if(ev->type == EVENT_NOTE_ON)
189 ss_ins_note_on(&i[ev->trk_id],
190 ev->iparam[0],
191 ev->fparam[0],
192 ev->iparam[1]);
193 else
194 if(ev->type == EVENT_NOTE_OFF)
195 ss_ins_note_off(ev->iparam[0]);
196 else
197 if(ev->type == EVENT_DEBUG)
198 printf("debug!\n");
199 else
200 if(ev->type == EVENT_END_SONG)
201 goon=0;
203 ev++;
206 output_init_frame(output);
208 ss_ins_frame(0, output);
209 ss_ins_frame(1, output);
211 #ifdef QQ
212 if(n < TIME2SAMPLES(13))
214 output[0]=process_effect(&e[0], output[0]);
215 output[1]=process_effect(&e[1], output[1]);
217 /* output[1]=process_effect(&e[2], output[1]); */
219 /* output[0]=process_effect(&e[3], output[0]);
220 output[0]=process_effect(&e[4], output[0]);
221 output[0]=process_effect(&e[5], output[0]);
223 output[1]=process_effect(&e[6], output[1]);
224 output[1]=process_effect(&e[7], output[1]);
225 output[1]=process_effect(&e[8], output[1]); */
227 /* output[0]=process_effect(&e[9], output[0]);
228 output[1]=process_effect(&e[10], output[1]); */
230 /* output[0]=process_effect(&e[11], output[0]);
231 output[1]=process_effect(&e[11], output[1]); */
233 #endif
235 output_write(output);
237 /* if(n < TIME2SAMPLES(14))
238 generator_release(&_generators[1]); */
241 output_close();
243 printf("clipped: %d optimal volume: %f\n",
244 _output_clipped, _optimal_volume);
246 return(0);