Mercurial > audlegacy-plugins
diff src/console/Vgm_Emu.h @ 316:fb513e10174e trunk
[svn] - merge libconsole-blargg into mainline libconsole:
+ obsoletes plugins-ugly:sapplug
author | nenolod |
---|---|
date | Thu, 30 Nov 2006 19:54:33 -0800 |
parents | 3da1b8942b8b |
children | 986f098da058 |
line wrap: on
line diff
--- a/src/console/Vgm_Emu.h Wed Nov 29 14:42:11 2006 -0800 +++ b/src/console/Vgm_Emu.h Thu Nov 30 19:54:33 2006 -0800 @@ -1,12 +1,9 @@ - -// Multi-format VGM music emulator with support for SMS PSG and Mega Drive FM +// Sega Master System/Mark III, Sega Genesis/Mega Drive, BBC Micro VGM music file emulator -// Game_Music_Emu 0.3.0 - +// Game_Music_Emu 0.5.1 #ifndef VGM_EMU_H #define VGM_EMU_H -#include "abstract_file.h" #include "Vgm_Emu_Impl.h" // Emulates VGM music using SN76489/SN76496 PSG, YM2612, and YM2413 FM sound chips. @@ -16,10 +13,13 @@ // YM2413 sound chip emulator. I can provide one I've modified to work with the library. class Vgm_Emu : public Vgm_Emu_Impl { public: + // True if custom buffer and custom equalization are supported + // TODO: move into Music_Emu and rename to something like supports_custom_buffer() + bool is_classic_emu() const { return !uses_fm; } - // Oversample runs FM chips at higher than normal rate. Tempo adjusts speed of - // music, but not pitch. - Vgm_Emu( bool oversample = true, double tempo = 1.0 ); + // Disable running FM chips at higher than normal rate. Will result in slightly + // more aliasing of high notes. + void disable_oversampling( bool disable = true ) { disable_oversampling_ = disable; } // VGM header format struct header_t @@ -41,78 +41,44 @@ byte ym2151_rate [4]; byte data_offset [4]; byte unused2 [8]; - - enum { track_count = 1 }; // one track per file - enum { time_rate = 44100 }; // all times specified at this rate - - // track information is in gd3 data - enum { game = 0 }; - enum { song = 0 }; - enum { author = 0 }; - enum { copyright = 0 }; }; - BOOST_STATIC_ASSERT( sizeof (header_t) == 64 ); - - // Load VGM data - blargg_err_t load( Data_Reader& ); + BOOST_STATIC_ASSERT( sizeof (header_t) == 0x40 ); - // Load VGM using already-loaded header and remaining data - blargg_err_t load( header_t const&, Data_Reader& ); - - // Load VGM using pointer to file data. Keeps pointer to data. - blargg_err_t load( void const* data, long size ); + // Header for currently loaded file + header_t const& header() const { return *(header_t const*) data; } - // Header for currently loaded VGM - header_t const& header() const { return header_; } - - // Pointer to gd3 data, or NULL if none. Optionally returns size of data. - // Checks for GD3 header and that version is less than 2.0. - byte const* gd3_data( int* size_out = NULL ) const; - - // to do: find better name for this - // True if Classic_Emu operations are supported - bool is_classic_emu() const { return !uses_fm; } + static gme_type_t static_type() { return gme_vgm_type; } public: - ~Vgm_Emu(); - blargg_err_t set_sample_rate( long sample_rate ); - void start_track( int ); - void mute_voices( int mask ); - const char** voice_names() const; - void play( long count, sample_t* ); + // deprecated + Music_Emu::load; + blargg_err_t load( header_t const& h, Data_Reader& in ) // use Remaining_Reader + { return load_remaining_( &h, sizeof h, in ); } + byte const* gd3_data( int* size_out = 0 ) const; // use track_info() + public: - // deprecated - int track_length( const byte** end_out = NULL, int* remain_out = NULL ) const - { - return (header().track_duration [3]*0x1000000L + - header().track_duration [2]*0x0010000L + - header().track_duration [1]*0x0000100L + - header().track_duration [0]) / header_t::time_rate; - } + Vgm_Emu(); + ~Vgm_Emu(); protected: - // Classic_Emu + blargg_err_t track_info_( track_info_t*, int track ) const; + blargg_err_t load_mem_( byte const*, long ); + blargg_err_t set_sample_rate_( long sample_rate ); + blargg_err_t start_track_( int ); + blargg_err_t play_( long count, sample_t* ); + blargg_err_t run_clocks( blip_time_t&, int ); + void set_tempo_( double ); + void mute_voices_( int mask ); void set_voice( int, Blip_Buffer*, Blip_Buffer*, Blip_Buffer* ); void update_eq( blip_eq_t const& ); - blip_time_t run( int, bool* ); private: - header_t header_; - blargg_vector<byte> mem; + // removed; use disable_oversampling() and set_tempo() instead + Vgm_Emu( bool oversample, double tempo = 1.0 ); + double fm_rate; + long psg_rate; long vgm_rate; - bool oversample; + bool disable_oversampling_; bool uses_fm; - - blargg_err_t init_( long sample_rate ); - blargg_err_t load_( const header_t&, void const* data, long size ); blargg_err_t setup_fm(); - void unload(); }; -inline blargg_err_t Vgm_Emu::load( void const* data, long size ) -{ - unload(); - return load_( *(header_t*) data, (char*) data + sizeof (header_t), - size - sizeof (header_t) ); -} - #endif -