OSDN Git Service

GPL library! for sound!! ^o^
[proj16/16.git] / src / sountest.c
1 /* Project 16 Source Code~\r
2  * Copyright (C) 2012-2015 sparky4 & pngwen & andrius4669\r
3  *\r
4  * This file is part of Project 16.\r
5  *\r
6  * Project 16 is free software; you can redistribute it and/or modify\r
7  * it under the terms of the GNU General Public License as published by\r
8  * the Free Software Foundation; either version 3 of the License, or\r
9  * (at your option) any later version.\r
10  *\r
11  * Project 16 is distributed in the hope that it will be useful,\r
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14  * GNU General Public License for more details.\r
15  *\r
16  * You should have received a copy of the GNU General Public License\r
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>, or\r
18  * write to the Free Software Foundation, Inc., 51 Franklin Street,\r
19  * Fifth Floor, Boston, MA 02110-1301 USA.\r
20  *\r
21  */
22
23 #include <stdio.h>
24
25 #include "src/lib/16_in.h"
26 //#include "src/lib/16_snd.h"
27 #include "src/lib/doslib/adlib.h"
28 #include "src/lib/doslib/8254.h"                /* 8254 timer */
29
30 static unsigned int musical_scale[18] = {
31         0x1B0,                  /* E */
32         0x1CA,                  /* F */
33         0x1E5,                  /* f# */
34         0x202,                  /* G */
35         0x220,                  /* G# */
36         0x241,                  /* A */
37         0x263,                  /* A# */
38         0x287,                  /* B */
39         0x2AE,                  /* C */
40
41         0x2B0,                  /* E */
42         0x2CA,                  /* F */
43         0x2E5,                  /* f# */
44         0x302,                  /* G */
45         0x320,                  /* G# */
46         0x341,                  /* A */
47         0x363,                  /* A# */
48         0x387,                  /* B */
49         0x3AE,                  /* C */
50 };
51
52 void main(int argc, char near *argv[])\r
53 {
54         word i;
55 //      static FMInstrument testInst =\r
56 //{\r
57 //0x00, 0x01,   /* modulator frequency multiple... 0x20 */\r
58 //0x00, 0x00,   /* modulator frequency level...    0x40 */\r
59 //0xF0, 0xF0,   /* modulator attack/decay...       0x60 */\r
60 //0x73, 0x73,   /* modulator sustain/release...    0x80 */\r
61 //0x03, 0x00,   /* output waveform distortion      0xE0 */\r
62 //0x36,                         /* feedback algorithm and strength 0xC0 */\r
63 //};
64
65         IN_Startup();
66         //FMReset();
67         //FMSetVoice(0, &testInst);
68         if(!init_adlib())
69         {
70                 printf("Cannot init library\n");
71                 exit(-5);
72         }
73
74         if (adlib_fm_voices > 9)
75                 printf("OPL3!\n");
76 //              vga_bios_set_80x50_text();
77
78         memset(adlib_fm,0,sizeof(adlib_fm));
79         memset(&adlib_reg_bd,0,sizeof(adlib_reg_bd));
80         for (i=0;i < adlib_fm_voices;i++) {
81                 struct adlib_fm_operator *f;
82                 f = &adlib_fm[i].mod;
83                 f->ch_a = f->ch_b = f->ch_c = f->ch_d = 1;
84                 f = &adlib_fm[i].car;
85                 f->ch_a = f->ch_b = f->ch_c = f->ch_d = 1;
86         }
87
88         for (i=0;i < /*adlib_fm_voices*/1;i++) {
89                 struct adlib_fm_operator *f;
90
91                 f = &adlib_fm[i].mod;
92                 f->mod_multiple = 1;
93                 f->total_level = 63 - 16;
94                 f->attack_rate = 15;
95                 f->decay_rate = 0;
96                 f->sustain_level = 7;
97                 f->release_rate = 7;
98                 f->f_number = musical_scale[i%18];
99                 f->octave = 4;
100                 f->key_on = 0;
101
102                 f = &adlib_fm[i].car;
103                 f->mod_multiple = 1;
104                 f->total_level = 63 - 16;
105                 f->attack_rate = 15;
106                 f->decay_rate = 0;
107                 f->sustain_level = 7;
108                 f->release_rate = 7;
109                 f->f_number = 0;
110                 f->octave = 0;
111                 f->key_on = 0;
112         }
113
114         adlib_apply_all();
115
116         printf("press Z!  to noise\npress ESC to quit");
117         printf("p");
118         while(!IN_qb(1))
119         {
120                 if(IN_qb(44))
121                 {
122                         printf("e");
123                         adlib_fm[0].mod.key_on = 1;\r
124                         //FMKeyOn(0, 0x106, 4);
125                 }
126                 else
127                 {
128                         adlib_fm[0].mod.key_on = 0;
129                         //FMKeyOff(0);
130                 }
131                 adlib_update_groupA0(0,&adlib_fm[0]);\r
132         }
133         printf("!\n");
134         IN_Shutdown();
135 }