Flangers are starting to sound like flangers.
[ahxm.git] / wav.c
blob8002f056a61c6c77d3fa11adf5ee0fc01097e227
1 /*
3 wav.c
5 Copyright (C) 2003 Angel Ortega <angel@triptico.com>
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 http://www.triptico.com
25 #include "config.h"
27 #include <stdio.h>
28 #include <string.h>
29 #include <stdlib.h>
30 #include <math.h>
32 #include "core.h"
33 #include "input.h"
34 #include "output.h"
35 #include "generator.h"
36 #include "effect.h"
37 #include "instrument.h"
39 /*******************
40 Data
41 ********************/
43 struct channel
45 int * wave;
46 double vol;
47 double dvol;
51 #define NUM_GENERATORS 64
52 struct generator _generators[NUM_GENERATORS];
55 /*******************
56 Code
57 ********************/
59 extern double _note_frequency[128];
61 int main(void)
63 int * ls;
64 int * rs;
65 int size;
66 FILE * f;
67 int n, m;
68 struct effect_delay e;
69 struct instrument i;
71 _linear_interpolation=1;
72 _frequency=44100;
74 memset(_generators, '\0', sizeof(_generators));
75 build_note_frequencies();
77 load_pat_file("samples/acpiano.pat");
78 /* load_pat_file("/cdrom/orchhit.pat"); */
79 /* return(0); */
81 load_wav_file("samples/amen1.wav", &size, &ls, &rs);
83 init_instrument(&i);
84 add_instrument_layer(&i, 36, 0, 128, ls, rs,
85 size, 0, size, 44100 / 3);
87 instrument_play_note(&i, 36-12, 1, 1);
89 /* generator_portamento(&i.generators[0], 44100 * 2,
90 _note_frequency[36-10] / _note_frequency[36]); */
92 /* instrument_play_note(&i, 39, 1, 1); */
95 load_wav_file("samples/amen1.wav", &size, &ls, &rs);
97 generator_play(&_generators[0], ls, rs, size, 1, 0, size, 0.2, 1, 4410);
99 load_wav_file("samples/01c1.wav", &size, &ls, &rs);
100 generator_play(&_generators[1], ls, rs, size,
101 _note_freq[24] / _note_freq[36], 0, size, 1, 1, 44100 / 3);
103 load_wav_file("samples/05c3.wav", &size, &ls, &rs);
105 generator_play(&_generators[2], ls, rs, size,
106 _note_freq[36] / _note_freq[36], 0, size, 0.5, 0.5, 0);
108 generator_play(&_generators[3], ls, rs, size,
109 _note_freq[39] / _note_freq[36], 0, size, 0.5, 0.5, 0);
111 generator_play(&_generators[4], ls, rs, size,
112 _note_freq[43] / _note_freq[36], 0, size, 0.5, 0.5, 0);
114 load_wav_file("samples/as-al017.wav", &size, &ls, &rs);
115 generator_play(&_generators[5], ls, rs, size, 1, 0, size, 2, 2, 0);
118 f=popen("sox -V -t raw -s -r 44100 -c 2 -w - qq.wav","w");
121 if(output_open("oss", "/dev/dsp") < 0)
123 printf("Error: can't init driver\n");
124 return(1);
127 /* init_delay(&e, (int)TIME2SAMPLES(20.0 / 1000.0), 0.1); */
128 init_delay(&e, 44100, 0.1);
130 for(n=TIME2SAMPLES(15);n > 0;n--)
132 int l,r;
134 l=r=0;
136 for(m=0;m < NUM_GENERATORS;m++)
137 generator(&_generators[m], &l, &r);
139 generate_instrument(&i, &l, &r);
141 if(n < TIME2SAMPLES(13))
142 process_flanger(&e, &l, &r);
144 output_write(l, r);
146 /* if(n < TIME2SAMPLES(14))
147 generator_release(&_generators[1]); */
150 output_close();
152 return(0);