Mercurial > audlegacy-plugins
comparison src/console/Ay_Apu.h @ 316:fb513e10174e trunk
[svn] - merge libconsole-blargg into mainline libconsole:
+ obsoletes plugins-ugly:sapplug
author | nenolod |
---|---|
date | Thu, 30 Nov 2006 19:54:33 -0800 |
parents | |
children | 986f098da058 |
comparison
equal
deleted
inserted
replaced
315:2294f3a6f136 | 316:fb513e10174e |
---|---|
1 // AY-3-8910 sound chip emulator | |
2 | |
3 // Game_Music_Emu 0.5.1 | |
4 #ifndef AY_APU_H | |
5 #define AY_APU_H | |
6 | |
7 #include "blargg_common.h" | |
8 #include "Blip_Buffer.h" | |
9 | |
10 class Ay_Apu { | |
11 public: | |
12 // Set buffer to generate all sound into, or disable sound if NULL | |
13 void output( Blip_Buffer* ); | |
14 | |
15 // Reset sound chip | |
16 void reset(); | |
17 | |
18 // Write to register at specified time | |
19 void write( blip_time_t time, int addr, int data ); | |
20 | |
21 // Run sound to specified time, end current time frame, then start a new | |
22 // time frame at time 0. Time frames have no effect on emulation and each | |
23 // can be whatever length is convenient. | |
24 void end_frame( blip_time_t length ); | |
25 | |
26 // Additional features | |
27 | |
28 // Set sound output of specific oscillator to buffer, where index is | |
29 // 0, 1, or 2. If buffer is NULL, the specified oscillator is muted. | |
30 enum { osc_count = 3 }; | |
31 void osc_output( int index, Blip_Buffer* ); | |
32 | |
33 // Set overall volume (default is 1.0) | |
34 void volume( double ); | |
35 | |
36 // Set treble equalization (see documentation) | |
37 void treble_eq( blip_eq_t const& ); | |
38 | |
39 public: | |
40 Ay_Apu(); | |
41 typedef unsigned char byte; | |
42 private: | |
43 struct osc_t | |
44 { | |
45 blip_time_t period; | |
46 blip_time_t delay; | |
47 short last_amp; | |
48 short phase; | |
49 Blip_Buffer* output; | |
50 } oscs [osc_count]; | |
51 blip_time_t last_time; | |
52 byte latch; | |
53 byte regs [16]; | |
54 | |
55 struct { | |
56 blip_time_t delay; | |
57 blargg_ulong lfsr; | |
58 } noise; | |
59 | |
60 struct { | |
61 blip_time_t delay; | |
62 byte const* wave; | |
63 int pos; | |
64 byte modes [8] [48]; // values already passed through volume table | |
65 } env; | |
66 | |
67 void run_until( blip_time_t ); | |
68 void write_data_( int addr, int data ); | |
69 public: | |
70 enum { amp_range = 255 }; | |
71 Blip_Synth<blip_good_quality,1> synth_; | |
72 }; | |
73 | |
74 inline void Ay_Apu::volume( double v ) { synth_.volume( 0.7 / osc_count / amp_range * v ); } | |
75 | |
76 inline void Ay_Apu::treble_eq( blip_eq_t const& eq ) { synth_.treble_eq( eq ); } | |
77 | |
78 inline void Ay_Apu::write( blip_time_t time, int addr, int data ) | |
79 { | |
80 run_until( time ); | |
81 write_data_( addr, data ); | |
82 } | |
83 | |
84 inline void Ay_Apu::osc_output( int i, Blip_Buffer* buf ) | |
85 { | |
86 assert( (unsigned) i < osc_count ); | |
87 oscs [i].output = buf; | |
88 } | |
89 | |
90 inline void Ay_Apu::output( Blip_Buffer* buf ) | |
91 { | |
92 osc_output( 0, buf ); | |
93 osc_output( 1, buf ); | |
94 osc_output( 2, buf ); | |
95 } | |
96 | |
97 inline void Ay_Apu::end_frame( blip_time_t time ) | |
98 { | |
99 if ( time > last_time ) | |
100 run_until( time ); | |
101 | |
102 assert( last_time >= time ); | |
103 last_time -= time; | |
104 } | |
105 | |
106 #endif |