summaryrefslogtreecommitdiff
path: root/lib/rbcodec/codecs/libgme/gb_apu.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rbcodec/codecs/libgme/gb_apu.h')
-rw-r--r--lib/rbcodec/codecs/libgme/gb_apu.h85
1 files changed, 85 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/libgme/gb_apu.h b/lib/rbcodec/codecs/libgme/gb_apu.h
new file mode 100644
index 0000000000..69307b9840
--- /dev/null
+++ b/lib/rbcodec/codecs/libgme/gb_apu.h
@@ -0,0 +1,85 @@
1// Nintendo Game Boy sound hardware emulator with save state support
2
3// Gb_Snd_Emu 0.1.4
4#ifndef GB_APU_H
5#define GB_APU_H
6
7#include "gb_oscs.h"
8
9// Clock rate sound hardware runs at
10enum { clock_rate = 4194304 * GB_APU_OVERCLOCK };
11
12// Registers are at io_addr to io_addr+io_size-1
13enum { io_addr = 0xFF10 };
14enum { io_size = 0x30 };
15enum { regs_size = io_size + 0x10 };
16
17enum gb_mode_t {
18 mode_dmg, // Game Boy monochrome
19 mode_cgb, // Game Boy Color
20 mode_agb // Game Boy Advance
21};
22
23// 0: Square 1, 1: Square 2, 2: Wave, 3: Noise
24enum { osc_count = 4 }; // 0 <= chan < osc_count
25
26struct Gb_Apu {
27 struct Gb_Osc* oscs [osc_count];
28 blip_time_t last_time; // time sound emulator has been run to
29 blip_time_t frame_period; // clocks between each frame sequencer step
30 int volume_;
31 bool reduce_clicks_;
32
33 struct Gb_Square square1;
34 struct Gb_Square square2;
35 struct Gb_Wave wave;
36 struct Gb_Noise noise;
37 blip_time_t frame_time; // time of next frame sequencer action
38 int frame_phase; // phase of next frame sequencer step
39
40 uint8_t regs [regs_size];// last values written to registers
41
42 // large objects after everything else
43 struct Blip_Synth synth;
44};
45
46// Basics
47
48// Initializes apu
49void Apu_init( struct Gb_Apu* this );
50
51// Emulates to time t, then writes data to addr
52void Apu_write_register( struct Gb_Apu* this, blip_time_t t, int addr, int data );
53
54// Emulates to time t, then subtracts t from the current time.
55// OK if previous write call had time slightly after t.
56void Apu_end_frame( struct Gb_Apu* this,blip_time_t t );
57
58// More features
59
60// Emulates to time t, then reads from addr
61int Apu_read_register( struct Gb_Apu* this, blip_time_t t, int addr );
62
63// Resets hardware to state after power, BEFORE boot ROM runs. Mode selects
64// sound hardware. If agb_wave is true, enables AGB's extra wave features.
65void Apu_reset( struct Gb_Apu* this, enum gb_mode_t mode, bool agb_wave );
66
67// Same as set_output(), but for a particular channel
68void Apu_set_output( struct Gb_Apu* this, int chan, struct Blip_Buffer* center,
69 struct Blip_Buffer* left, struct Blip_Buffer* right );
70
71// Sets overall volume, where 1.0 is normal
72void Apu_volume( struct Gb_Apu* this, int v );
73
74// If true, reduces clicking by disabling DAC biasing. Note that this reduces
75// emulation accuracy, since the clicks are authentic.
76void Apu_reduce_clicks( struct Gb_Apu* this, bool reduce );
77
78// Sets frame sequencer rate, where 1.0 is normal. Meant for adjusting the
79// tempo in a music player.
80void Apu_set_tempo( struct Gb_Apu* this, int t );
81
82
83void write_osc( struct Gb_Apu* this, int reg, int old_data, int data );
84
85#endif