diff Plugins/Input/console/Vgm_Emu_Impl.h @ 493:c04dff121e1d trunk

[svn] hostile merge, phase 2: reimport based on new plugin code
author nenolod
date Tue, 24 Jan 2006 20:19:01 -0800
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Plugins/Input/console/Vgm_Emu_Impl.h	Tue Jan 24 20:19:01 2006 -0800
@@ -0,0 +1,74 @@
+
+// Game_Music_Emu 0.3.0
+
+#ifndef VGM_EMU_IMPL_H
+#define VGM_EMU_IMPL_H
+
+#include "Dual_Resampler.h"
+#include "Classic_Emu.h"
+#include "Ym2413_Emu.h"
+#include "Ym2612_Emu.h"
+#include "Sms_Apu.h"
+
+template<class Emu>
+class Ym_Emu : public Emu {
+protected:
+	int last_time;
+	short* out;
+	enum { disabled_time = -1 };
+public:
+	Ym_Emu()                        : last_time( disabled_time ), out( NULL ) { }
+	void enable( bool b )           { last_time = b ? 0 : disabled_time; }
+	bool enabled() const            { return last_time != disabled_time; }
+	void begin_frame( short* p );
+	int run_until( int time );
+};
+
+class Vgm_Emu_Impl : public Classic_Emu, private Dual_Resampler {
+public:
+	typedef Classic_Emu::sample_t sample_t;
+	typedef BOOST::uint8_t byte;
+	
+protected:
+	enum { stereo = 2 };
+	
+	typedef int vgm_time_t;
+	
+	enum { fm_time_bits = 12 };
+	typedef int fm_time_t;
+	long fm_time_offset;
+	int fm_time_factor;
+	fm_time_t to_fm_time( vgm_time_t ) const;
+	
+	enum { blip_time_bits = 12 };
+	int blip_time_factor;
+	blip_time_t to_blip_time( vgm_time_t ) const;
+	
+	byte const* data;
+	byte const* loop_begin;
+	byte const* data_end;
+	void update_fm_rates( long* ym2413_rate, long* ym2612_rate ) const;
+	
+	vgm_time_t vgm_time;
+	byte const* pos;
+	blip_time_t run_commands( vgm_time_t );
+	int play_frame( blip_time_t blip_time, int sample_count, sample_t* buf );
+	
+	byte const* pcm_data;
+	byte const* pcm_pos;
+	int dac_amp;
+	int dac_disabled; // -1 if disabled
+	void write_pcm( vgm_time_t, int amp );
+	
+	Ym_Emu<Ym2612_Emu> ym2612;
+	Ym_Emu<Ym2413_Emu> ym2413;
+	
+	Blip_Buffer blip_buf;
+	Sms_Apu psg;
+	Blip_Synth<blip_med_quality,1> dac_synth;
+	
+	friend class Vgm_Emu;
+};
+
+#endif
+