diff options
author | Sean Bartell <wingedtachikoma@gmail.com> | 2011-06-25 21:32:25 -0400 |
---|---|---|
committer | Nils Wallménius <nils@rockbox.org> | 2012-04-25 22:13:20 +0200 |
commit | f40bfc9267b13b54e6379dfe7539447662879d24 (patch) | |
tree | 9b20069d5e62809ff434061ad730096836f916f2 /lib/rbcodec/codecs/libgme/gb_apu.h | |
parent | a0009907de7a0107d49040d8a180f140e2eff299 (diff) | |
download | rockbox-f40bfc9267b13b54e6379dfe7539447662879d24.tar.gz rockbox-f40bfc9267b13b54e6379dfe7539447662879d24.zip |
Add codecs to librbcodec.
Change-Id: Id7f4717d51ed02d67cb9f9cb3c0ada4a81843f97
Reviewed-on: http://gerrit.rockbox.org/137
Reviewed-by: Nils Wallménius <nils@rockbox.org>
Tested-by: Nils Wallménius <nils@rockbox.org>
Diffstat (limited to 'lib/rbcodec/codecs/libgme/gb_apu.h')
-rw-r--r-- | lib/rbcodec/codecs/libgme/gb_apu.h | 85 |
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 | ||
10 | enum { clock_rate = 4194304 * GB_APU_OVERCLOCK }; | ||
11 | |||
12 | // Registers are at io_addr to io_addr+io_size-1 | ||
13 | enum { io_addr = 0xFF10 }; | ||
14 | enum { io_size = 0x30 }; | ||
15 | enum { regs_size = io_size + 0x10 }; | ||
16 | |||
17 | enum 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 | ||
24 | enum { osc_count = 4 }; // 0 <= chan < osc_count | ||
25 | |||
26 | struct 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 | ||
49 | void Apu_init( struct Gb_Apu* this ); | ||
50 | |||
51 | // Emulates to time t, then writes data to addr | ||
52 | void 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. | ||
56 | void 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 | ||
61 | int 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. | ||
65 | void 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 | ||
68 | void 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 | ||
72 | void 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. | ||
76 | void 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. | ||
80 | void Apu_set_tempo( struct Gb_Apu* this, int t ); | ||
81 | |||
82 | |||
83 | void write_osc( struct Gb_Apu* this, int reg, int old_data, int data ); | ||
84 | |||
85 | #endif | ||