Mark compilation.
[ahxm.git] / wav.c
blobc0b67b62e3bd7ed0592d809288584f7be1ba5b0d
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 "generator.h"
36 #include "effect.h"
37 #include "instrument.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 extern double _note_frequency[128];
53 int main(void)
55 float * wave[CHANNELS];
56 float output[CHANNELS];
57 float vol[CHANNELS];
58 double size;
59 int n_channels;
60 FILE * f;
61 int n, m;
62 struct effect e[16];
63 struct instrument i[16];
64 struct event * ev;
65 int goon;
68 char * ptr=preprocess("%examples/example1.ahml");
69 printf("%s\n",ptr);
70 compile("$100:qq l16l0 c8d#''4/3*6~0.5 o2e4~0.8o++f");
73 _linear_interpolation=1;
74 _frequency=44100;
75 _master_volume=0.5;
76 _n_channels=4;
78 build_note_frequencies();
80 init_instrument(&i[1]);
81 load_pat_file(&i[1], "samples/acpiano.pat");
83 /* n_channels=load_wav_file("samples/as-al017.wav", &size, wave); */
84 n_channels=load_wav_file("samples/amen1.wav", &size, wave);
85 printf("n_channels: %d\n", n_channels);
87 init_instrument(&i[0]);
88 add_instrument_layer(&i[0], 36, 0, 128,
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);
138 /* events */
139 event_clear();
141 vol[0]=1.0; vol[1]=1.0; vol[2]=0.0; vol[3]=0.0;
142 instrument_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 instrument_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_end_song(44100 * 11);
173 event_sort();
175 ev=_events;
177 for(n=0,goon=1;goon;n++)
179 while(ev->frame == n)
181 /* processes the event */
182 if(ev->type == EVENT_NOTE_ON)
183 instrument_play_note(&i[ev->instrk],
184 ev->iparam[0], ev->fparam[0]);
185 else
186 if(ev->type == EVENT_NOTE_OFF)
187 instrument_release_note(&i[ev->instrk], ev->iparam[0]);
188 else
189 if(ev->type == EVENT_DEBUG)
190 printf("debug!\n");
191 else
192 if(ev->type == EVENT_END_SONG)
193 goon=0;
195 ev++;
198 output_init_frame(output);
200 generate_instrument(&i[0], output);
201 generate_instrument(&i[1], output);
203 #ifdef QQ
204 if(n < TIME2SAMPLES(13))
206 output[0]=process_effect(&e[0], output[0]);
207 output[1]=process_effect(&e[1], output[1]);
209 /* output[1]=process_effect(&e[2], output[1]); */
211 /* output[0]=process_effect(&e[3], output[0]);
212 output[0]=process_effect(&e[4], output[0]);
213 output[0]=process_effect(&e[5], output[0]);
215 output[1]=process_effect(&e[6], output[1]);
216 output[1]=process_effect(&e[7], output[1]);
217 output[1]=process_effect(&e[8], output[1]); */
219 /* output[0]=process_effect(&e[9], output[0]);
220 output[1]=process_effect(&e[10], output[1]); */
222 /* output[0]=process_effect(&e[11], output[0]);
223 output[1]=process_effect(&e[11], output[1]); */
225 #endif
227 output_write(output);
229 /* if(n < TIME2SAMPLES(14))
230 generator_release(&_generators[1]); */
233 output_close();
235 printf("clipped: %d optimal volume: %f\n",
236 _output_clipped, _optimal_volume);
238 return(0);