LMMS
Loading...
Searching...
No Matches
Nes_Vrc6_Apu.h
Go to the documentation of this file.
1// Konami VRC6 sound chip emulator
2
3// Nes_Snd_Emu 0.1.8
4#ifndef NES_VRC6_APU_H
5#define NES_VRC6_APU_H
6
7#include "blargg_common.h"
8#include "Blip_Buffer.h"
9
10struct vrc6_apu_state_t;
11
13public:
14 // See Nes_Apu.h for reference
15 void reset();
16 void volume( double );
17 void treble_eq( blip_eq_t const& );
18 void output( Blip_Buffer* );
19 enum { osc_count = 3 };
20 void osc_output( int index, Blip_Buffer* );
21 void end_frame( blip_time_t );
22 void save_state( vrc6_apu_state_t* ) const;
23 void load_state( vrc6_apu_state_t const& );
24
25 // Oscillator 0 write-only registers are at $9000-$9002
26 // Oscillator 1 write-only registers are at $A000-$A002
27 // Oscillator 2 write-only registers are at $B000-$B002
28 enum { reg_count = 3 };
29 enum { base_addr = 0x9000 };
30 enum { addr_step = 0x1000 };
31 void write_osc( blip_time_t, int osc, int reg, int data );
32
33public:
35 BLARGG_DISABLE_NOTHROW
36private:
37 // noncopyable
40
41 struct Vrc6_Osc
42 {
45 int delay;
47 int phase;
48 int amp; // only used by saw
49
50 int period() const
51 {
52 return (regs [2] & 0x0F) * 0x100L + regs [1] + 1;
53 }
54 };
55
58
61
62 void run_until( blip_time_t );
63 void run_square( Vrc6_Osc& osc, blip_time_t );
64 void run_saw( blip_time_t );
65};
66
75
76inline void Nes_Vrc6_Apu::osc_output( int i, Blip_Buffer* buf )
77{
78 assert( (unsigned) i < osc_count );
79 oscs [i].output = buf;
80}
81
82inline void Nes_Vrc6_Apu::volume( double v )
83{
84 double const factor = 0.0967 * 2;
85 saw_synth.volume( factor / 31 * v );
86 square_synth.volume( factor * 0.5 / 15 * v );
87}
88
90{
91 saw_synth.treble_eq( eq );
92 square_synth.treble_eq( eq );
93}
94
95#endif
blip_long blip_time_t
Definition Blip_Buffer.h:17
assert(0)
Definition Blip_Buffer.h:23
Definition Blip_Buffer.h:191
blip_time_t last_time
Definition Nes_Vrc6_Apu.h:57
void end_frame(blip_time_t)
Definition Nes_Vrc6_Apu.cpp:64
void run_until(blip_time_t)
Definition Nes_Vrc6_Apu.cpp:46
@ base_addr
Definition Nes_Vrc6_Apu.h:29
void osc_output(int index, Blip_Buffer *)
Definition Nes_Vrc6_Apu.h:76
Nes_Vrc6_Apu & operator=(const Nes_Vrc6_Apu &)
void run_saw(blip_time_t)
Definition Nes_Vrc6_Apu.cpp:159
void run_square(Vrc6_Osc &osc, blip_time_t)
Definition Nes_Vrc6_Apu.cpp:105
void output(Blip_Buffer *)
Definition Nes_Vrc6_Apu.cpp:40
Blip_Synth< blip_med_quality, 1 > saw_synth
Definition Nes_Vrc6_Apu.h:59
@ reg_count
Definition Nes_Vrc6_Apu.h:28
void write_osc(blip_time_t, int osc, int reg, int data)
Definition Nes_Vrc6_Apu.cpp:55
Nes_Vrc6_Apu(const Nes_Vrc6_Apu &)
void treble_eq(blip_eq_t const &)
Definition Nes_Vrc6_Apu.h:89
@ osc_count
Definition Nes_Vrc6_Apu.h:19
void save_state(vrc6_apu_state_t *) const
Definition Nes_Vrc6_Apu.cpp:73
@ addr_step
Definition Nes_Vrc6_Apu.h:30
Blip_Synth< blip_good_quality, 1 > square_synth
Definition Nes_Vrc6_Apu.h:60
void load_state(vrc6_apu_state_t const &)
Definition Nes_Vrc6_Apu.cpp:88
Vrc6_Osc oscs[osc_count]
Definition Nes_Vrc6_Apu.h:56
void volume(double)
Definition Nes_Vrc6_Apu.h:82
void reset()
Definition Nes_Vrc6_Apu.cpp:25
Nes_Vrc6_Apu()
Definition Nes_Vrc6_Apu.cpp:18
Definition Blip_Buffer.h:239
unsigned v[N_MAX]
Definition inflate.c:1584
register unsigned i
Definition inflate.c:1575
JSAMPIMAGE data
Definition jpeglib.h:945
unsigned short uint16_t
Definition mid.cpp:99
unsigned char uint8_t
Definition mid.cpp:98
Definition Nes_Vrc6_Apu.h:42
int last_amp
Definition Nes_Vrc6_Apu.h:46
int amp
Definition Nes_Vrc6_Apu.h:48
Blip_Buffer * output
Definition Nes_Vrc6_Apu.h:44
int period() const
Definition Nes_Vrc6_Apu.h:50
int phase
Definition Nes_Vrc6_Apu.h:47
int delay
Definition Nes_Vrc6_Apu.h:45
uint8_t regs[3]
Definition Nes_Vrc6_Apu.h:43
Definition tap_eq.c:71
Definition Nes_Vrc6_Apu.h:68
uint16_t delays[3]
Definition Nes_Vrc6_Apu.h:71
uint8_t regs[3][3]
Definition Nes_Vrc6_Apu.h:69
uint8_t saw_amp
Definition Nes_Vrc6_Apu.h:70
uint8_t unused
Definition Nes_Vrc6_Apu.h:73
uint8_t phases[3]
Definition Nes_Vrc6_Apu.h:72