From f40bfc9267b13b54e6379dfe7539447662879d24 Mon Sep 17 00:00:00 2001 From: Sean Bartell Date: Sat, 25 Jun 2011 21:32:25 -0400 Subject: Add codecs to librbcodec. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Id7f4717d51ed02d67cb9f9cb3c0ada4a81843f97 Reviewed-on: http://gerrit.rockbox.org/137 Reviewed-by: Nils Wallménius Tested-by: Nils Wallménius --- lib/rbcodec/codecs/libgme/nes_namco_apu.h | 71 +++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 lib/rbcodec/codecs/libgme/nes_namco_apu.h (limited to 'lib/rbcodec/codecs/libgme/nes_namco_apu.h') diff --git a/lib/rbcodec/codecs/libgme/nes_namco_apu.h b/lib/rbcodec/codecs/libgme/nes_namco_apu.h new file mode 100644 index 0000000000..c428c894c3 --- /dev/null +++ b/lib/rbcodec/codecs/libgme/nes_namco_apu.h @@ -0,0 +1,71 @@ +// Namco 106 sound chip emulator + +// Nes_Snd_Emu 0.1.8 +#ifndef NES_NAMCO_APU_H +#define NES_NAMCO_APU_H + +#include "blargg_common.h" +#include "blip_buffer.h" + +struct namco_state_t; + +enum { namco_osc_count = 8 }; +enum { namco_addr_reg_addr = 0xF800 }; +enum { namco_data_reg_addr = 0x4800 }; +enum { namco_reg_count = 0x80 }; + +struct Namco_Osc { + int delay; + struct Blip_Buffer* output; + short last_amp; + short wave_pos; +}; + +struct Nes_Namco_Apu { + struct Namco_Osc oscs [namco_osc_count]; + + blip_time_t last_time; + int addr_reg; + + uint8_t reg [namco_reg_count]; + + struct Blip_Synth synth; +}; + +// See Nes_Apu.h for reference. +void Namco_init( struct Nes_Namco_Apu* this ); +void Namco_output( struct Nes_Namco_Apu* this, struct Blip_Buffer* ); + +void Namco_reset( struct Nes_Namco_Apu* this ); +void Namco_end_frame( struct Nes_Namco_Apu* this, blip_time_t ); + +static inline uint8_t* namco_access( struct Nes_Namco_Apu* this ) +{ + int addr = this->addr_reg & 0x7F; + if ( this->addr_reg & 0x80 ) + this->addr_reg = (addr + 1) | 0x80; + return &this->reg [addr]; +} + +static inline void Namco_volume( struct Nes_Namco_Apu* this, int v ) { Synth_volume( &this->synth, v / 10 / namco_osc_count / 15 ); } + +// Write-only address register is at 0xF800 +static inline void Namco_write_addr( struct Nes_Namco_Apu* this, int v ) { this->addr_reg = v; } + +static inline int Namco_read_data( struct Nes_Namco_Apu* this ) { return *namco_access( this ); } + +static inline void Namco_osc_output( struct Nes_Namco_Apu* this, int i, struct Blip_Buffer* buf ) +{ + assert( (unsigned) i < namco_osc_count ); + this->oscs [i].output = buf; +} + +// Read/write data register is at 0x4800 +void Namco_run_until( struct Nes_Namco_Apu* this, blip_time_t ); +static inline void Namco_write_data( struct Nes_Namco_Apu* this, blip_time_t time, int data ) +{ + Namco_run_until( this, time ); + *namco_access( this ) = data; +} + +#endif -- cgit v1.2.3