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_fme7_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_fme7_apu.h')
-rw-r--r-- | lib/rbcodec/codecs/libgme/nes_fme7_apu.h | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/libgme/nes_fme7_apu.h b/lib/rbcodec/codecs/libgme/nes_fme7_apu.h new file mode 100644 index 0000000000..c0eac4c765 --- /dev/null +++ b/lib/rbcodec/codecs/libgme/nes_fme7_apu.h | |||
@@ -0,0 +1,90 @@ | |||
1 | // Sunsoft FME-7 sound emulator | ||
2 | |||
3 | // Game_Music_Emu 0.6-pre | ||
4 | #ifndef NES_FME7_APU_H | ||
5 | #define NES_FME7_APU_H | ||
6 | |||
7 | #include "blargg_common.h" | ||
8 | #include "blip_buffer.h" | ||
9 | |||
10 | enum { fme7_reg_count = 14 }; | ||
11 | |||
12 | // Mask and addresses of registers | ||
13 | enum { fme7_addr_mask = 0xE000 }; | ||
14 | enum { fme7_data_addr = 0xE000 }; | ||
15 | enum { fme7_latch_addr = 0xC000 }; | ||
16 | enum { fme7_osc_count = 3 }; | ||
17 | |||
18 | enum { amp_range = 192 }; // can be any value; this gives best error/quality tradeoff | ||
19 | |||
20 | struct osc_t { | ||
21 | struct Blip_Buffer* output; | ||
22 | int last_amp; | ||
23 | }; | ||
24 | |||
25 | // static unsigned char const amp_table [16]; | ||
26 | |||
27 | struct Nes_Fme7_Apu { | ||
28 | // fme7 apu state | ||
29 | uint8_t regs [fme7_reg_count]; | ||
30 | uint8_t phases [3]; // 0 or 1 | ||
31 | uint8_t latch; | ||
32 | uint16_t delays [3]; // a, b, c | ||
33 | |||
34 | struct osc_t oscs [fme7_osc_count]; | ||
35 | blip_time_t last_time; | ||
36 | |||
37 | struct Blip_Synth synth; | ||
38 | }; | ||
39 | |||
40 | // See Nes_Apu.h for reference | ||
41 | void Fme7_init( struct Nes_Fme7_Apu* this ); | ||
42 | void Fme7_reset( struct Nes_Fme7_Apu* this ); | ||
43 | |||
44 | static inline void Fme7_volume( struct Nes_Fme7_Apu* this, int v ) | ||
45 | { | ||
46 | Synth_volume( &this->synth, (v/2 - (v*3)/25) / amp_range ); // to do: fine-tune | ||
47 | } | ||
48 | |||
49 | static inline void Fme7_osc_output( struct Nes_Fme7_Apu* this, int i, struct Blip_Buffer* buf ) | ||
50 | { | ||
51 | assert( (unsigned) i < fme7_osc_count ); | ||
52 | this->oscs [i].output = buf; | ||
53 | } | ||
54 | |||
55 | static inline void Fme7_output( struct Nes_Fme7_Apu* this, struct Blip_Buffer* buf ) | ||
56 | { | ||
57 | int i; | ||
58 | for ( i = 0; i < fme7_osc_count; i++ ) | ||
59 | Fme7_osc_output( this, i, buf ); | ||
60 | } | ||
61 | |||
62 | // (addr & addr_mask) == latch_addr | ||
63 | static inline void Fme7_write_latch( struct Nes_Fme7_Apu* this, int data ) { this->latch = data; } | ||
64 | |||
65 | // (addr & addr_mask) == data_addr | ||
66 | void Fme7_run_until( struct Nes_Fme7_Apu* this, blip_time_t end_time ); | ||
67 | static inline void Fme7_write_data( struct Nes_Fme7_Apu* this, blip_time_t time, int data ) | ||
68 | { | ||
69 | if ( (unsigned) this->latch >= fme7_reg_count ) | ||
70 | { | ||
71 | #ifdef debug_printf | ||
72 | debug_printf( "FME7 write to %02X (past end of sound registers)\n", (int) latch ); | ||
73 | #endif | ||
74 | return; | ||
75 | } | ||
76 | |||
77 | Fme7_run_until( this, time ); | ||
78 | this->regs [this->latch] = data; | ||
79 | } | ||
80 | |||
81 | static inline void Fme7_end_frame( struct Nes_Fme7_Apu* this, blip_time_t time ) | ||
82 | { | ||
83 | if ( time > this->last_time ) | ||
84 | Fme7_run_until( this, time ); | ||
85 | |||
86 | assert( this->last_time >= time ); | ||
87 | this->last_time -= time; | ||
88 | } | ||
89 | |||
90 | #endif | ||