2nd part of FS#12176. Tempo setting migrated to fixed point for libgme.
[kugel-rb.git] / apps / codecs / libgme / gb_apu.h
blob028be29d7c40e00b6df15a25c4044a87bcb4ee8a
1 // Nintendo Game Boy sound hardware emulator with save state support
3 // Gb_Snd_Emu 0.1.4
4 #ifndef GB_APU_H
5 #define GB_APU_H
7 #include "gb_oscs.h"
9 // Clock rate sound hardware runs at
10 enum { clock_rate = 4194304 * GB_APU_OVERCLOCK };
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 };
17 enum gb_mode_t {
18 mode_dmg, // Game Boy monochrome
19 mode_cgb, // Game Boy Color
20 mode_agb // Game Boy Advance
23 // 0: Square 1, 1: Square 2, 2: Wave, 3: Noise
24 enum { osc_count = 4 }; // 0 <= chan < osc_count
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 double volume_;
31 bool reduce_clicks_;
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
40 uint8_t regs [regs_size];// last values written to registers
42 // large objects after everything else
43 struct Blip_Synth synth;
46 // Basics
48 // Initializes apu
49 void Apu_init( struct Gb_Apu* this );
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 ) ICODE_ATTR;
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 ) ICODE_ATTR;
58 // More features
60 // Emulates to time t, then reads from addr
61 int Apu_read_register( struct Gb_Apu* this, blip_time_t t, int addr ) ICODE_ATTR;
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 );
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 );
71 // Sets overall volume, where 1.0 is normal
72 void Apu_volume( struct Gb_Apu* this, double v );
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 );
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 );
83 void write_osc( struct Gb_Apu* this, int reg, int old_data, int data ) ICODE_ATTR;
85 #endif