OSDN Git Service

[VM] Apply VM_TEMPLATE to all VMs.
[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         channel_t tone;
46         channel_t noise;
47         channel_t square1;
48         channel_t square2;
49         channel_t square3;
50         channel_t pcm;
51         void clear_channel(channel_t *ch);
52         
53         int pcm_table[MAX_PARAM * 8];
54         uint32_t cmd_addr;
55         int pcm_len;
56         
57         int volume_table[32];
58         int detune_table[32];
59         
60         int psg_volume_l, psg_volume_r;
61         int pcm_volume_l, pcm_volume_r;
62         
63         // command buffer
64         int param_cnt, param_ptr, register_id;
65         uint8_t params[MAX_PARAM];
66         
67         void process_pcm(uint8_t data);
68         void process_cmd();
69         
70 public:
71         SOUND(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu)
72         {
73                 set_device_name(_T("Sound"));
74         }
75         ~SOUND() {}
76         
77         // common functions
78         void reset();
79         void write_data8(uint32_t addr, uint32_t data);
80         void write_io8(uint32_t addr, uint32_t data);
81         void event_callback(int event_id, int err);
82         void mix(int32_t* buffer, int cnt);
83         void set_volume(int ch, int decibel_l, int decibel_r);
84         void decl_state();
85         void save_state(FILEIO* state_fio);
86         bool load_state(FILEIO* state_fio);
87         
88         // unique functions
89         void set_context_cpu(DEVICE* device)
90         {
91                 d_cpu = device;
92         }
93         void initialize_sound(int rate);
94 };
95
96 #endif
97