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
40 #include "preprocessor.h"
53 float * wave
[CHANNELS
];
54 float output
[CHANNELS
];
68 char * ptr=preprocess("%examples/example1.ahml");
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;
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");
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); */
112 init_delay(&e4, 1, 1, 1, 4, 3.14 / 2, 0);
116 effect_wobble(&e
[0], 0.5, 0);
117 effect_wobble(&e
[1], 0.5, 0.25);
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);
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);
136 effect_fader(&e
[11], 44100 * 6, 0, 1);
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
);
145 event_note_on(0, 0, 36, 1);
146 event_note_off(441000, 0, 36);
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);
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");
180 for(frame
=0,goon
=1;goon
;frame
++)
182 if(ev
->type
== EVENT_END_SONG
)
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
],
194 if(ev
->type
== EVENT_NOTE_OFF
)
195 ss_ins_note_off(ev
->iparam
[0]);
197 if(ev
->type
== EVENT_DEBUG
)
200 if(ev
->type
== EVENT_END_SONG
)
206 output_init_frame(output
);
208 ss_ins_frame(0, output
);
209 ss_ins_frame(1, output
);
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]); */
235 output_write(output
);
237 /* if(n < TIME2SAMPLES(14))
238 generator_release(&_generators[1]); */
243 printf("clipped: %d optimal volume: %f\n",
244 _output_clipped
, _optimal_volume
);