1 // Common aspects of emulators which use Blip_Buffer for sound output
2 
3 // Game_Music_Emu $vers
4 #ifndef CLASSIC_EMU_H
5 #define CLASSIC_EMU_H
6 
7 #include "blargg_common.h"
8 #include "Blip_Buffer.h"
9 #include "Music_Emu.h"
10 
11 class Classic_Emu : public Music_Emu {
12 protected:
13 // Derived interface
14 
15 	// Advertises type of sound on each voice, so Effects_Buffer can better choose
16 	// what effect to apply (pan, echo, surround). Constant can have value added so
17 	// that voices of the same type can be spread around the stereo sound space.
18 	enum { wave_type = 0x100, noise_type = 0x200, mixed_type = wave_type | noise_type };
set_voice_types(int const types[])19 	void set_voice_types( int const types [] )          { voice_types = types; }
20 
21 	// Sets up Blip_Buffers after loading file
22 	blargg_err_t setup_buffer( int clock_rate );
23 
24 	// Clock rate of Blip_buffers
clock_rate()25 	int  clock_rate() const                             { return clock_rate_; }
26 
27 	// Changes clock rate of Blip_Buffers (experimental)
28 	void change_clock_rate( int );
29 
30 // Overrides should do the indicated task
31 
32 	// Set Blip_Buffer(s) voice outputs to, or mute voice if pointer is NULL
33 	virtual void set_voice( int index, Blip_Buffer* center,
34 			Blip_Buffer* left, Blip_Buffer* right )                     BLARGG_PURE( ; )
35 
36 	// Update equalization
37 	virtual void update_eq( blip_eq_t const& )                          BLARGG_PURE( ; )
38 
39 	// Start track
40 	virtual blargg_err_t start_track_( int track )                      BLARGG_PURE( ; )
41 
42 	// Run for at most msec or time_io clocks, then set time_io to number of clocks
43 	// actually run for. After returning, Blip_Buffers have time frame of time_io clocks
44 	// ended.
45 	virtual blargg_err_t run_clocks( blip_time_t& time_io, int msec )   BLARGG_PURE( ; )
46 
47 // Internal
48 public:
49 	Classic_Emu();
50 	~Classic_Emu();
51 	virtual void set_buffer( Multi_Buffer* );
52 
53 protected:
54 	virtual blargg_err_t set_sample_rate_( int sample_rate );
55 	virtual void mute_voices_( int );
56 	virtual void set_equalizer_( equalizer_t const& );
57 	virtual blargg_err_t play_( int, sample_t [] );
58 
59 private:
60 	Multi_Buffer* buf;
61 	Multi_Buffer* stereo_buffer; // NULL if using custom buffer
62 	int clock_rate_;
63 	unsigned buf_changed_count;
64 	int const* voice_types;
65 };
66 
set_buffer(Multi_Buffer * new_buf)67 inline void Classic_Emu::set_buffer( Multi_Buffer* new_buf )
68 {
69 	assert( !buf && new_buf );
70 	buf = new_buf;
71 }
72 
set_voice(int,Blip_Buffer *,Blip_Buffer *,Blip_Buffer *)73 inline void Classic_Emu::set_voice( int, Blip_Buffer*, Blip_Buffer*, Blip_Buffer* ) { }
74 
update_eq(blip_eq_t const &)75 inline void Classic_Emu::update_eq( blip_eq_t const& )                              { }
76 
run_clocks(blip_time_t &,int)77 inline blargg_err_t Classic_Emu::run_clocks( blip_time_t&, int )                    { return blargg_ok; }
78 
79 #endif
80