2015-11-27 07:02:41 -03:00
|
|
|
// Super Nintendo SPC music file emulator
|
|
|
|
|
|
|
|
// Game_Music_Emu $vers
|
|
|
|
#ifndef SPC_EMU_H
|
|
|
|
#define SPC_EMU_H
|
|
|
|
|
|
|
|
#include "Music_Emu.h"
|
|
|
|
#include "higan/smp/smp.hpp"
|
|
|
|
#include "Spc_Filter.h"
|
|
|
|
|
|
|
|
#if GME_SPC_FAST_RESAMPLER
|
|
|
|
#include "Upsampler.h"
|
|
|
|
typedef Upsampler Spc_Emu_Resampler;
|
|
|
|
#else
|
|
|
|
#include "Fir_Resampler.h"
|
|
|
|
typedef Fir_Resampler<24> Spc_Emu_Resampler;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
class Spc_Emu : public Music_Emu {
|
|
|
|
public:
|
|
|
|
// The Super Nintendo hardware samples at 32kHz. Other sample rates are
|
|
|
|
// handled by resampling the 32kHz output; emulation accuracy is not affected.
|
|
|
|
enum { native_sample_rate = 32000 };
|
|
|
|
|
|
|
|
// Disables annoying pseudo-surround effect some music uses
|
|
|
|
void disable_surround( bool disable = true ) { smp.dsp.disable_surround( disable ); }
|
|
|
|
|
|
|
|
// Enables gaussian, cubic or sinc interpolation
|
|
|
|
void interpolation_level( int level = 0 ) { smp.dsp.spc_dsp.interpolation_level( level ); }
|
|
|
|
|
2017-03-13 01:10:35 -03:00
|
|
|
// Enables an analog signal simulation filter
|
|
|
|
void enable_filter( bool enable = true ) { _enable_filter = enable; if (enable) filter.clear(); }
|
|
|
|
|
|
|
|
// Enables native echo
|
|
|
|
void enable_echo( bool enable = true ) { smp.dsp.spc_dsp.enable_echo( enable ); }
|
|
|
|
virtual void mute_effects( bool mute ) { enable_echo(!mute); }
|
|
|
|
|
2015-11-27 07:02:41 -03:00
|
|
|
SuperFamicom::SMP const* get_smp() const;
|
|
|
|
SuperFamicom::SMP * get_smp();
|
|
|
|
|
|
|
|
// SPC file header
|
2022-01-03 22:50:07 -03:00
|
|
|
enum { header_size = 0x100 };
|
2015-11-27 07:02:41 -03:00
|
|
|
struct header_t
|
|
|
|
{
|
|
|
|
char tag [35];
|
|
|
|
byte format;
|
|
|
|
byte version;
|
|
|
|
byte pc [ 2];
|
|
|
|
byte a, x, y, psw, sp;
|
|
|
|
byte unused [ 2];
|
|
|
|
char song [32];
|
|
|
|
char game [32];
|
|
|
|
char dumper [16];
|
|
|
|
char comment [32];
|
|
|
|
byte date [11];
|
|
|
|
byte len_secs [ 3];
|
|
|
|
byte fade_msec [ 4];
|
|
|
|
char author [32]; // sometimes first char should be skipped (see official SPC spec)
|
|
|
|
byte mute_mask;
|
|
|
|
byte emulator;
|
|
|
|
byte unused2 [46];
|
|
|
|
};
|
|
|
|
|
2022-01-03 22:50:07 -03:00
|
|
|
// Header for currently loaded file
|
|
|
|
header_t const& header() const { return *(header_t const*) file_data; }
|
2015-11-27 07:02:41 -03:00
|
|
|
|
|
|
|
static gme_type_t static_type() { return gme_spc_type; }
|
2022-01-03 22:50:07 -03:00
|
|
|
|
|
|
|
public:
|
|
|
|
// deprecated
|
|
|
|
using 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* trailer() const; // use track_info()
|
|
|
|
long trailer_size() const;
|
|
|
|
|
2015-11-27 07:02:41 -03:00
|
|
|
// Implementation
|
|
|
|
public:
|
2022-01-03 22:50:07 -03:00
|
|
|
Spc_Emu( gme_type_t );
|
|
|
|
Spc_Emu() : Spc_Emu( gme_spc_type ) {}
|
2015-11-27 07:02:41 -03:00
|
|
|
~Spc_Emu();
|
|
|
|
|
|
|
|
protected:
|
2022-01-03 22:50:07 -03:00
|
|
|
blargg_err_t load_mem_( byte const*, long );
|
|
|
|
blargg_err_t track_info_( track_info_t*, int track ) const;
|
|
|
|
blargg_err_t set_sample_rate_( long );
|
|
|
|
blargg_err_t start_track_( int );
|
|
|
|
blargg_err_t play_( long, sample_t* );
|
|
|
|
blargg_err_t skip_( long );
|
|
|
|
void mute_voices_( int );
|
|
|
|
void set_tempo_( double );
|
|
|
|
void enable_accuracy_( bool );
|
|
|
|
byte const* file_data;
|
|
|
|
long file_size;
|
2015-11-27 07:02:41 -03:00
|
|
|
|
|
|
|
private:
|
|
|
|
Spc_Emu_Resampler resampler;
|
2022-01-03 22:50:07 -03:00
|
|
|
SPC_Filter filter;
|
2015-11-27 07:02:41 -03:00
|
|
|
SuperFamicom::SMP smp;
|
2017-03-13 01:10:35 -03:00
|
|
|
|
|
|
|
bool _enable_filter;
|
2015-11-27 07:02:41 -03:00
|
|
|
|
2022-01-03 22:50:07 -03:00
|
|
|
blargg_err_t play_and_filter( long count, sample_t out [] );
|
2015-11-27 07:02:41 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
inline SuperFamicom::SMP const* Spc_Emu::get_smp() const { return &smp; }
|
|
|
|
inline SuperFamicom::SMP * Spc_Emu::get_smp() { return &smp; }
|
|
|
|
|
|
|
|
#endif
|