Small fixes.
[ahxm.git] / wav.c
blob8e276ccbd53b6c72368bd572134663af8128e792
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 int main(void)
61 int * ls;
62 int * rs;
63 int size;
64 FILE * f;
65 int n, m;
66 struct effect_delay e;
67 struct instrument i;
69 _linear_interpolation=1;
70 _frequency=44100;
72 memset(_generators, '\0', sizeof(_generators));
73 build_note_frequencies();
75 load_pat_file("samples/acpiano.pat");
76 /* load_pat_file("/cdrom/orchhit.pat"); */
77 /* return(0); */
79 load_wav_file("samples/01c1.wav", &size, &ls, &rs);
81 init_instrument(&i);
82 add_instrument_layer(&i, 36, 0, 128, ls, rs,
83 size, 0, size, 44100 / 3);
85 instrument_play_note(&i, 36, 1, 1);
86 /* instrument_play_note(&i, 39, 1, 1); */
89 load_wav_file("samples/amen1.wav", &size, &ls, &rs);
91 generator_play(&_generators[0], ls, rs, size, 1, 0, size, 0.2, 1, 4410);
93 load_wav_file("samples/01c1.wav", &size, &ls, &rs);
94 generator_play(&_generators[1], ls, rs, size,
95 _note_freq[24] / _note_freq[36], 0, size, 1, 1, 44100 / 3);
97 load_wav_file("samples/05c3.wav", &size, &ls, &rs);
99 generator_play(&_generators[2], ls, rs, size,
100 _note_freq[36] / _note_freq[36], 0, size, 0.5, 0.5, 0);
102 generator_play(&_generators[3], ls, rs, size,
103 _note_freq[39] / _note_freq[36], 0, size, 0.5, 0.5, 0);
105 generator_play(&_generators[4], ls, rs, size,
106 _note_freq[43] / _note_freq[36], 0, size, 0.5, 0.5, 0);
108 load_wav_file("samples/as-al017.wav", &size, &ls, &rs);
109 generator_play(&_generators[5], ls, rs, size, 1, 0, size, 2, 2, 0);
112 f=popen("sox -V -t raw -s -r 44100 -c 2 -w - qq.wav","w");
115 if(output_open("oss", "/dev/dsp") < 0)
117 printf("Error: can't init driver\n");
118 return(1);
121 /* init_delay(&e, 44100 / 10, 0); */
122 init_delay(&e, (int)TIME2SAMPLES(18.0 / 1000.0), 0.1);
124 for(n=TIME2SAMPLES(15);n > 0;n--)
126 int l,r;
128 l=r=0;
130 for(m=0;m < NUM_GENERATORS;m++)
131 generator(&_generators[m], &l, &r);
133 generate_instrument(&i, &l, &r);
135 if(n < TIME2SAMPLES(13))
136 process_reverb(&e, &l, &r);
138 output_write(l, r);
140 /* if(n < TIME2SAMPLES(14))
141 generator_release(&_generators[1]); */
144 output_close();
146 return(0);