1 // Sega Genesis/Mega Drive GYM music file emulator 2 // Includes with PCM timing recovery to improve sample quality. 3 4 // Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/ 5 #ifndef GYM_EMU_H 6 #define GYM_EMU_H 7 8 #include "Dual_Resampler.h" 9 #include "Ym2612_Emu.h" 10 #include "Music_Emu.h" 11 #include "Sms_Apu.h" 12 13 class Gym_Emu : public Music_Emu, private Dual_Resampler { 14 public: 15 // GYM file header 16 enum { header_size = 428 }; 17 struct header_t 18 { 19 char tag [4]; 20 char song [32]; 21 char game [32]; 22 char copyright [32]; 23 char emulator [32]; 24 char dumper [32]; 25 char comment [256]; 26 byte loop_start [4]; // in 1/60 seconds, 0 if not looped 27 byte packed [4]; 28 }; 29 30 // Header for currently loaded file header()31 header_t const& header() const { return header_; } 32 static_type()33 static gme_type_t static_type() { return gme_gym_type; } 34 35 public: 36 // deprecated 37 using Music_Emu::load; load(header_t const & h,Data_Reader & in)38 blargg_err_t load( header_t const& h, Data_Reader& in ) // use Remaining_Reader 39 { return load_remaining_( &h, sizeof h, in ); } 40 enum { gym_rate = 60 }; 41 long track_length() const; // use track_info() 42 43 public: 44 Gym_Emu(); 45 ~Gym_Emu(); 46 protected: 47 blargg_err_t load_mem_( byte const*, long ); 48 blargg_err_t track_info_( track_info_t*, int track ) const; 49 blargg_err_t set_sample_rate_( long sample_rate ); 50 blargg_err_t start_track_( int ); 51 blargg_err_t play_( long count, sample_t* ); 52 void mute_voices_( int ); 53 void set_tempo_( double ); 54 int play_frame( blip_time_t blip_time, int sample_count, sample_t* buf ); 55 private: 56 // sequence data begin, loop begin, current position, end 57 const byte* data; 58 const byte* loop_begin; 59 const byte* pos; 60 const byte* data_end; 61 blargg_long loop_remain; // frames remaining until loop beginning has been located 62 header_t header_; 63 double fm_sample_rate; 64 blargg_long clocks_per_frame; 65 void parse_frame(); 66 67 // dac (pcm) 68 int dac_amp; 69 int prev_dac_count; 70 bool dac_enabled; 71 bool dac_muted; 72 void run_dac( int ); 73 74 // sound 75 Blip_Buffer blip_buf; 76 Ym2612_Emu fm; 77 Blip_Synth<blip_med_quality,1> dac_synth; 78 Sms_Apu apu; 79 byte dac_buf [1024]; 80 }; 81 82 #endif 83