OSDN Git Service

[General] Convert sourcecode's CRLF format: DOS(WINDOWS) to Unix, to apply patches...
[csp-qt/common_source_project-fm7.git] / source / src / vm / scv / sound.h
1 /*
2         EPOCH Super Cassette Vision Emulator 'eSCV'
3
4         Author : Takeda.Toshiya
5         Date   : 2006.08.21 -
6
7         [ uPD1771C ]
8 */
9
10 #ifndef _SOUND_H_
11 #define _SOUND_H_
12
13 #include "../vm.h"
14 #include "../../emu.h"
15 #include "../device.h"
16
17 #define SOUND_CLOCK  1522400.0
18 #define NOISE_CLOCK      760.0
19 #define SQUARE_CLOCK  174000.0
20
21 #define PCM_PERIOD 120000
22
23 #define MAX_TONE   24000
24 #define MAX_NOISE  16000
25 #define MAX_SQUARE  8000
26 #define MAX_PCM    20000
27
28 #define MAX_PARAM 0x8000
29
30 class SOUND : public DEVICE
31 {
32 private:
33         DEVICE* d_cpu;
34         
35         // sound gen
36         typedef struct {
37                 int count;
38                 int diff;
39                 int period;
40                 int timbre;
41                 int volume;
42                 int output;
43                 int ptr;
44         } channel_t;
45         struct channel_t tone;
46         struct channel_t noise;
47         struct channel_t square1;
48         struct channel_t square2;
49         struct channel_t square3;
50         struct channel_t pcm;
51         void clear_channel(channel_t *ch);
52         
53         int pcm_table[MAX_PARAM * 8];
54         uint32 cmd_addr;
55         int pcm_len;
56         
57         int volume_table[32];
58         int detune_table[32];
59         
60         // command buffer
61         int param_cnt, param_ptr, register_id;
62         uint8 params[MAX_PARAM];
63         
64         void process_pcm(uint8 data);
65         void process_cmd();
66         
67 public:
68         SOUND(VM* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu) {}
69         ~SOUND() {}
70         
71         // common functions
72         void reset();
73         void write_data8(uint32 addr, uint32 data);
74         void write_io8(uint32 addr, uint32 data);
75         void event_callback(int event_id, int err);
76         void mix(int32* buffer, int cnt);
77         void save_state(FILEIO* state_fio);
78         bool load_state(FILEIO* state_fio);
79         
80         // unique functions
81         void set_context_cpu(DEVICE* device)
82         {
83                 d_cpu = device;
84         }
85         void init(int rate);
86 };
87
88 #endif
89