1 
2 // Konami VRC7 sound chip emulator
3 
4 // Nes_Snd_Emu 0.1.7. Copyright (C) 2003-2005 Shay Green. GNU LGPL license.
5 
6 #ifndef NES_VRC7_H
7 #define NES_VRC7_H
8 
9 #include "emu2413_state.h"
10 
11 struct vrc7_snapshot_t;
12 
13 class Nes_Vrc7 {
14 public:
15 	Nes_Vrc7();
16 	~Nes_Vrc7();
17 
18 	// See Nes_Apu.h for reference
19 	void reset();
20 	void volume( double );
21 	void treble_eq( blip_eq_t const& );
22 	void output( Blip_Buffer* );
23 	enum { osc_count = 6 };
24 	void osc_output( int index, Blip_Buffer* );
25 	void end_frame( nes_time_t );
26 	void save_snapshot(vrc7_snapshot_t*);
27 	void load_snapshot(vrc7_snapshot_t &, int dataSize);
28 	void update_last_amp();
29 
30 	void write_reg( int reg );
31 	void write_data( nes_time_t, int data );
32 
33 private:
34 	// noncopyable
35 	Nes_Vrc7( const Nes_Vrc7& );
36 	Nes_Vrc7& operator = ( const Nes_Vrc7& );
37 
38 	struct Vrc7_Osc
39 	{
40 		uint8_t regs [3];
41 		Blip_Buffer* output;
42 		int last_amp;
43 	};
44 
45 	void * opll;
46 	nes_time_t last_time;
47 
48 	Blip_Synth<blip_med_quality,2048*2> synth; // DB2LIN_AMP_BITS == 11, * 2
49 	int count;
50 	Vrc7_Osc oscs [osc_count];
51 
52 	void run_until( nes_time_t );
53 };
54 
55 struct vrc7_snapshot_t
56 {
57 	uint8_t latch;
58 	uint8_t inst [8];
59 	uint8_t regs [6] [3];
60 	uint8_t count;
61 	int internal_opl_state_size;
62 	OPLL_STATE internal_opl_state;
63 };
64 BOOST_STATIC_ASSERT( sizeof (vrc7_snapshot_t) == 28 + 440 + 4 );
65 
osc_output(int i,Blip_Buffer * buf)66 inline void Nes_Vrc7::osc_output( int i, Blip_Buffer* buf )
67 {
68 	oscs [i].output = buf;
69 }
70 
71 #endif
72