Debian Codegraph @

src/engine/platform/sound/c140_c219.h

raw
1 /*
2
3 ============================================================================
4
5 MODIFIED Namco C140/C219 sound emulator - MODIFIED VERSION
6 by cam900
7
8 MODIFICATION by tildearrow - adds muting function AND VGM banking
9 THIS IS NOT THE ORIGINAL VERSION - you can find the original one in
10 commit 72d04777c013988ed8cf6da27c62a9d784a59dff
11
12 This file is licensed under zlib license.
13
14 ============================================================================
15
16 zlib License
17
18 (C) 2023-present cam900 and contributors
19
20 This software is provided 'as-is', without any express or implied
21 warranty. In no event will the authors be held liable for any damages
22 arising from the use of this software.
23
24 Permission is granted to anyone to use this software for any purpose,
25 including commercial applications, and to alter it and redistribute it
26 freely, subject to the following restrictions:
27
28 1. The origin of this software must not be misrepresented; you must not
29 claim that you wrote the original software. If you use this software
30 in a product, an acknowledgment in the product documentation would be
31 appreciated but is not required.
32 2. Altered source versions must be plainly marked as such, and must not be
33 misrepresented as being the original software.
34 3. This notice may not be removed or altered from any source distribution.
35
36 ============================================================================
37
38 TODO:
39 - unknown registers (Bit 6 of control register, etc)
40 - Internal timer
41
42 */
43
44 #ifndef _C140_C219_EMU_H
45 #define _C140_C219_EMU_H
46
47 #include <stdbool.h>
48
49 #ifdef __cplusplus
50 extern "C"
51 {
52 #endif
53
54 struct c140_voice_t
55 {
56 bool muted; // muted - can be set by user
57 bool busy; // busy flag
58 bool keyon; // key on flag
59 unsigned short freq; // sample frequency
60 unsigned char bank; // sample bank
61 unsigned int start_addr; // sample start address
62 unsigned int loop_addr; // sample loop address
63 unsigned int end_addr; // sample end address
64 int lvol, rvol; // left/right volume
65 bool noise; // noise flag
66 bool inv_lout; // invert left output flag
67 bool inv_sign; // invert sign bit flag
68 bool compressed; // compressed sample flag
69 bool loop; // loop flag
70 unsigned int addr; // sample address
71 int frac; // frequency counter (.16 fixed point)
72 int lout, rout; // left/right output
73 };
74
75 struct c140_t
76 {
77 struct c140_voice_t voice[24];
78 signed int lout, rout;
79 signed short mulaw[256];
80 signed short *sample_mem;
81 unsigned char bank_type;
82 };
83
84 struct c219_t
85 {
86 struct c140_voice_t voice[16];
87 signed int lout, rout;
88 signed short mulaw[256];
89 unsigned short lfsr;
90 unsigned char bank[4];
91 signed char *sample_mem;
92 };
93
94 void c140_tick(struct c140_t *c140, const int cycle);
95
96 void c219_tick(struct c219_t *c219, const int cycle);
97
98 void c140_voice_tick(struct c140_t *c140, const unsigned char v, const int cycle);
99
100 void c219_voice_tick(struct c219_t *c219, const unsigned char v, const int cycle);
101
102 void c140_keyon(struct c140_voice_t *c140_voice);
103
104 void c219_keyon(struct c140_voice_t *c140_voice);
105
106 void c140_write(struct c140_t *c140, const unsigned short addr, const unsigned char data);
107
108 void c219_write(struct c219_t *c219, const unsigned short addr, const unsigned char data);
109
110 void c140_bank_type(struct c140_t *c140, unsigned char type);
111
112 void c140_init(struct c140_t *c140);
113
114 void c219_init(struct c219_t *c219);
115
116 void c140_reset(struct c140_t *c140);
117
118 void c219_reset(struct c219_t *c219);
119
120 #ifdef __cplusplus
121 } // extern "C"
122 #endif
123
124 #endif // _C140_C219_EMU_H