PageRenderTime 14ms CodeModel.GetById 9ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/gme/Sms_Apu.h

http://game-music-emu.googlecode.com/
C++ Header | 75 lines | 40 code | 18 blank | 17 comment | 0 complexity | 200e36e3fff9aaf574f260ec632dd11d MD5 | raw file
 1// Sega Master System SN76489 PSG sound chip emulator
 2
 3// Sms_Snd_Emu 0.1.4
 4#ifndef SMS_APU_H
 5#define SMS_APU_H
 6
 7#include "Sms_Oscs.h"
 8
 9class Sms_Apu {
10public:
11	// Set overall volume of all oscillators, where 1.0 is full volume
12	void volume( double );
13	
14	// Set treble equalization
15	void treble_eq( const blip_eq_t& );
16	
17	// Outputs can be assigned to a single buffer for mono output, or to three
18	// buffers for stereo output (using Stereo_Buffer to do the mixing).
19	
20	// Assign all oscillator outputs to specified buffer(s). If buffer
21	// is NULL, silences all oscillators.
22	void output( Blip_Buffer* mono );
23	void output( Blip_Buffer* center, Blip_Buffer* left, Blip_Buffer* right );
24	
25	// Assign single oscillator output to buffer(s). Valid indicies are 0 to 3,
26	// which refer to Square 1, Square 2, Square 3, and Noise. If buffer is NULL,
27	// silences oscillator.
28	enum { osc_count = 4 };
29	void osc_output( int index, Blip_Buffer* mono );
30	void osc_output( int index, Blip_Buffer* center, Blip_Buffer* left, Blip_Buffer* right );
31	
32	// Reset oscillators and internal state
33	void reset( unsigned noise_feedback = 0, int noise_width = 0 );
34	
35	// Write GameGear left/right assignment byte
36	void write_ggstereo( blip_time_t, int );
37	
38	// Write to data port
39	void write_data( blip_time_t, int );
40	
41	// Run all oscillators up to specified time, end current frame, then
42	// start a new frame at time 0.
43	void end_frame( blip_time_t );
44
45public:
46	Sms_Apu();
47	~Sms_Apu();
48private:
49	// noncopyable
50	Sms_Apu( const Sms_Apu& );
51	Sms_Apu& operator = ( const Sms_Apu& );
52	
53	Sms_Osc*    oscs [osc_count];
54	Sms_Square  squares [3];
55	Sms_Square::Synth square_synth; // used by squares
56	blip_time_t last_time;
57	int         latch;
58	Sms_Noise   noise;
59	unsigned    noise_feedback;
60	unsigned    looped_feedback;
61	
62	void run_until( blip_time_t );
63};
64
65struct sms_apu_state_t
66{
67	unsigned char regs [8] [2];
68	unsigned char latch;
69};
70
71inline void Sms_Apu::output( Blip_Buffer* b ) { output( b, b, b ); }
72
73inline void Sms_Apu::osc_output( int i, Blip_Buffer* b ) { osc_output( i, b, b, b ); }
74
75#endif