2011-08-07 20:01:04 +00:00
|
|
|
// Turbo Grafx 16 (PC Engine) PSG sound chip emulator
|
|
|
|
|
|
|
|
// Game_Music_Emu 0.5.2
|
|
|
|
#ifndef HES_APU_H
|
|
|
|
#define HES_APU_H
|
|
|
|
|
|
|
|
#include "blargg_common.h"
|
2011-08-31 19:19:49 +00:00
|
|
|
#include "blargg_source.h"
|
2011-08-07 20:01:04 +00:00
|
|
|
#include "blip_buffer.h"
|
|
|
|
|
|
|
|
enum { amp_range = 0x8000 };
|
2011-08-31 19:19:49 +00:00
|
|
|
enum { osc_count = 6 }; // 0 <= chan < osc_count
|
|
|
|
|
|
|
|
// Registers are at io_addr to io_addr+io_size-1
|
|
|
|
enum { apu_io_addr = 0x0800 };
|
|
|
|
enum { apu_io_size = 10 };
|
2011-08-07 20:01:04 +00:00
|
|
|
|
|
|
|
struct Hes_Osc
|
|
|
|
{
|
2011-08-31 19:19:49 +00:00
|
|
|
byte wave [32];
|
|
|
|
int delay;
|
|
|
|
int period;
|
|
|
|
int phase;
|
|
|
|
|
|
|
|
int noise_delay;
|
|
|
|
byte noise;
|
|
|
|
unsigned lfsr;
|
|
|
|
|
|
|
|
byte control;
|
|
|
|
byte balance;
|
|
|
|
byte dac;
|
2011-08-07 20:01:04 +00:00
|
|
|
short volume [2];
|
|
|
|
int last_amp [2];
|
|
|
|
|
2011-08-31 19:19:49 +00:00
|
|
|
blip_time_t last_time;
|
|
|
|
struct Blip_Buffer* output [2];
|
|
|
|
struct Blip_Buffer* outputs [3];
|
2011-08-07 20:01:04 +00:00
|
|
|
};
|
|
|
|
|
2011-08-13 16:41:14 +00:00
|
|
|
void Osc_run_until( struct Hes_Osc* this, struct Blip_Synth* synth, blip_time_t );
|
2011-08-07 20:01:04 +00:00
|
|
|
|
|
|
|
struct Hes_Apu {
|
|
|
|
|
|
|
|
int latch;
|
|
|
|
int balance;
|
|
|
|
struct Blip_Synth synth;
|
2011-08-31 19:19:49 +00:00
|
|
|
struct Hes_Osc oscs [osc_count];
|
2011-08-07 20:01:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Init HES apu sound chip
|
|
|
|
void Apu_init( struct Hes_Apu* this );
|
|
|
|
|
|
|
|
// Reset HES apu couns chip
|
|
|
|
void Apu_reset( struct Hes_Apu* this );
|
|
|
|
|
2011-08-13 16:41:14 +00:00
|
|
|
void Apu_osc_output( struct Hes_Apu* this, int index, struct Blip_Buffer* center, struct Blip_Buffer* left, struct Blip_Buffer* right );
|
2011-08-31 19:19:49 +00:00
|
|
|
|
|
|
|
// Emulates to time t, then writes data to addr
|
2011-08-13 16:41:14 +00:00
|
|
|
void Apu_write_data( struct Hes_Apu* this, blip_time_t, int addr, int data );
|
2011-08-31 19:19:49 +00:00
|
|
|
|
|
|
|
// Emulates to time t, then subtracts t from the current time.
|
|
|
|
// OK if previous write call had time slightly after t.
|
2011-08-13 16:41:14 +00:00
|
|
|
void Apu_end_frame( struct Hes_Apu* this, blip_time_t );
|
2011-08-07 20:01:04 +00:00
|
|
|
|
2011-08-11 06:18:39 +00:00
|
|
|
static inline void Apu_volume( struct Hes_Apu* this, int v ) { Synth_volume( &this->synth, (v*9)/5 / osc_count / amp_range ); }
|
2011-08-07 20:01:04 +00:00
|
|
|
#endif
|