Mercurial > audlegacy
annotate Plugins/Input/console/Nes_Fme7_Apu.h @ 1740:1cd9aa465ea7 trunk
[svn] - export main.h API
author | nenolod |
---|---|
date | Mon, 18 Sep 2006 02:30:57 -0700 |
parents | c04dff121e1d |
children |
rev | line source |
---|---|
493
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
1 |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
2 // Sunsoft FME-7 sound emulator |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
3 |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
4 // Game_Music_Emu 0.3.0 |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
5 |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
6 #ifndef NES_FME7_APU_H |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
7 #define NES_FME7_APU_H |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
8 |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
9 #include "blargg_common.h" |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
10 #include "Blip_Buffer.h" |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
11 |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
12 struct fme7_snapshot_t |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
13 { |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
14 enum { reg_count = 14 }; |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
15 BOOST::uint8_t regs [reg_count]; |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
16 BOOST::uint8_t phases [3]; // 0 or 1 |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
17 BOOST::uint8_t latch; |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
18 BOOST::uint16_t delays [3]; // a, b, c |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
19 }; |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
20 BOOST_STATIC_ASSERT( sizeof (fme7_snapshot_t) == 24 ); |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
21 |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
22 class Nes_Fme7_Apu : private fme7_snapshot_t { |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
23 public: |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
24 Nes_Fme7_Apu(); |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
25 |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
26 // See Nes_Apu.h for reference |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
27 void reset(); |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
28 void volume( double ); |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
29 void treble_eq( blip_eq_t const& ); |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
30 void output( Blip_Buffer* ); |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
31 enum { osc_count = 3 }; |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
32 void osc_output( int index, Blip_Buffer* ); |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
33 void end_frame( blip_time_t ); |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
34 void save_snapshot( fme7_snapshot_t* ) const; |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
35 void load_snapshot( fme7_snapshot_t const& ); |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
36 |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
37 // Mask and addresses of registers |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
38 enum { addr_mask = 0xe000 }; |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
39 enum { data_addr = 0xe000 }; |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
40 enum { latch_addr = 0xc000 }; |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
41 |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
42 // (addr & addr_mask) == latch_addr |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
43 void write_latch( int ); |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
44 |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
45 // (addr & addr_mask) == data_addr |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
46 void write_data( blip_time_t, int data ); |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
47 |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
48 // End of public interface |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
49 private: |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
50 // noncopyable |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
51 Nes_Fme7_Apu( const Nes_Fme7_Apu& ); |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
52 Nes_Fme7_Apu& operator = ( const Nes_Fme7_Apu& ); |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
53 |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
54 static unsigned char amp_table [16]; |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
55 |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
56 struct { |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
57 Blip_Buffer* output; |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
58 int last_amp; |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
59 } oscs [osc_count]; |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
60 blip_time_t last_time; |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
61 |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
62 enum { amp_range = 192 }; // can be any value; this gives best error/quality tradeoff |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
63 Blip_Synth<blip_good_quality,1> synth; |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
64 |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
65 void run_until( blip_time_t ); |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
66 }; |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
67 |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
68 inline void Nes_Fme7_Apu::volume( double v ) |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
69 { |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
70 synth.volume( 0.38 / amp_range * v ); // to do: fine-tune |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
71 } |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
72 |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
73 inline void Nes_Fme7_Apu::treble_eq( blip_eq_t const& eq ) |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
74 { |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
75 synth.treble_eq( eq ); |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
76 } |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
77 |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
78 inline void Nes_Fme7_Apu::osc_output( int i, Blip_Buffer* buf ) |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
79 { |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
80 assert( (unsigned) i < osc_count ); |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
81 oscs [i].output = buf; |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
82 } |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
83 |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
84 inline void Nes_Fme7_Apu::output( Blip_Buffer* buf ) |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
85 { |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
86 for ( int i = 0; i < osc_count; i++ ) |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
87 osc_output( i, buf ); |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
88 } |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
89 |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
90 inline Nes_Fme7_Apu::Nes_Fme7_Apu() |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
91 { |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
92 output( NULL ); |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
93 volume( 1.0 ); |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
94 reset(); |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
95 } |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
96 |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
97 inline void Nes_Fme7_Apu::write_latch( int data ) { latch = data; } |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
98 |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
99 inline void Nes_Fme7_Apu::write_data( blip_time_t time, int data ) |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
100 { |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
101 if ( (unsigned) latch >= reg_count ) |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
102 { |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
103 #ifdef dprintf |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
104 dprintf( "FME7 write to %02X (past end of sound registers)\n", (int) latch ); |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
105 #endif |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
106 return; |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
107 } |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
108 |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
109 run_until( time ); |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
110 regs [latch] = data; |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
111 } |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
112 |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
113 inline void Nes_Fme7_Apu::end_frame( blip_time_t time ) |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
114 { |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
115 if ( time > last_time ) |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
116 run_until( time ); |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
117 |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
118 assert( last_time >= time ); |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
119 last_time -= time; |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
120 } |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
121 |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
122 inline void Nes_Fme7_Apu::save_snapshot( fme7_snapshot_t* out ) const |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
123 { |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
124 *out = *this; |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
125 } |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
126 |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
127 inline void Nes_Fme7_Apu::load_snapshot( fme7_snapshot_t const& in ) |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
128 { |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
129 reset(); |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
130 fme7_snapshot_t* state = this; |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
131 *state = in; |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
132 } |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
133 |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
134 #endif |
c04dff121e1d
[svn] hostile merge, phase 2: reimport based on new plugin code
nenolod
parents:
diff
changeset
|
135 |