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/nes_vrc6_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/nes_vrc6_apu.h')
-rw-r--r-- | lib/rbcodec/codecs/libgme/nes_vrc6_apu.h | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/libgme/nes_vrc6_apu.h b/lib/rbcodec/codecs/libgme/nes_vrc6_apu.h new file mode 100644 index 0000000000..57b8a42a79 --- /dev/null +++ b/lib/rbcodec/codecs/libgme/nes_vrc6_apu.h | |||
@@ -0,0 +1,62 @@ | |||
1 | // Konami VRC6 sound chip emulator | ||
2 | |||
3 | // Nes_Snd_Emu 0.2.0-pre | ||
4 | #ifndef NES_VRC6_APU_H | ||
5 | #define NES_VRC6_APU_H | ||
6 | |||
7 | #include "blargg_common.h" | ||
8 | #include "blip_buffer.h" | ||
9 | |||
10 | enum { vrc6_osc_count = 3 }; | ||
11 | enum { vrc6_reg_count = 3 }; | ||
12 | enum { vrc6_base_addr = 0x9000 }; | ||
13 | enum { vrc6_addr_step = 0x1000 }; | ||
14 | |||
15 | struct Vrc6_Osc | ||
16 | { | ||
17 | uint8_t regs [3]; | ||
18 | struct Blip_Buffer* output; | ||
19 | int delay; | ||
20 | int last_amp; | ||
21 | int phase; | ||
22 | int amp; // only used by saw | ||
23 | }; | ||
24 | |||
25 | static inline int Vrc6_osc_period( struct Vrc6_Osc* this ) | ||
26 | { | ||
27 | return (this->regs [2] & 0x0F) * 0x100 + this->regs [1] + 1; | ||
28 | } | ||
29 | |||
30 | struct Nes_Vrc6_Apu { | ||
31 | struct Vrc6_Osc oscs [vrc6_osc_count]; | ||
32 | blip_time_t last_time; | ||
33 | |||
34 | struct Blip_Synth saw_synth; | ||
35 | struct Blip_Synth square_synth; | ||
36 | }; | ||
37 | |||
38 | // See Nes_Apu.h for reference | ||
39 | void Vrc6_init( struct Nes_Vrc6_Apu* this ); | ||
40 | void Vrc6_reset( struct Nes_Vrc6_Apu* this ); | ||
41 | void Vrc6_output( struct Nes_Vrc6_Apu* this, struct Blip_Buffer* ); | ||
42 | void Vrc6_end_frame( struct Nes_Vrc6_Apu* this, blip_time_t ); | ||
43 | |||
44 | // Oscillator 0 write-only registers are at $9000-$9002 | ||
45 | // Oscillator 1 write-only registers are at $A000-$A002 | ||
46 | // Oscillator 2 write-only registers are at $B000-$B002 | ||
47 | void Vrc6_write_osc( struct Nes_Vrc6_Apu* this, blip_time_t, int osc, int reg, int data ); | ||
48 | |||
49 | static inline void Vrc6_osc_output( struct Nes_Vrc6_Apu* this, int i, struct Blip_Buffer* buf ) | ||
50 | { | ||
51 | assert( (unsigned) i < vrc6_osc_count ); | ||
52 | this->oscs [i].output = buf; | ||
53 | } | ||
54 | |||
55 | static inline void Vrc6_volume( struct Nes_Vrc6_Apu* this, int v ) | ||
56 | { | ||
57 | long long const factor = (long long)(FP_ONE_VOLUME * 0.0967 * 2); | ||
58 | Synth_volume( &this->saw_synth, (int)(v * factor / 31 / FP_ONE_VOLUME) ); | ||
59 | Synth_volume( &this->square_synth, (int)(v * factor / 2 / 15 / FP_ONE_VOLUME) ); | ||
60 | } | ||
61 | |||
62 | #endif | ||