Mercurial > audlegacy
comparison Plugins/Input/console/Gb_Apu.h @ 491:7c5e886205ef trunk
[svn] New code drop from blargg. Needs some work.
author | chainsaw |
---|---|
date | Tue, 24 Jan 2006 19:10:07 -0800 |
parents | 252843aac42f |
children |
comparison
equal
deleted
inserted
replaced
490:025c253845a3 | 491:7c5e886205ef |
---|---|
1 | 1 |
2 // Nintendo Game Boy PAPU sound chip emulator | 2 // Nintendo Game Boy PAPU sound chip emulator |
3 | 3 |
4 // Gb_Snd_Emu 0.1.3. Copyright (C) 2003-2005 Shay Green. GNU LGPL license. | 4 // Gb_Snd_Emu 0.1.4 |
5 | 5 |
6 #ifndef GB_APU_H | 6 #ifndef GB_APU_H |
7 #define GB_APU_H | 7 #define GB_APU_H |
8 | 8 |
9 typedef long gb_time_t; // clock cycle count | 9 typedef long gb_time_t; // clock cycle count |
10 typedef unsigned gb_addr_t; // 16-bit address | 10 typedef unsigned gb_addr_t; // 16-bit address |
11 | 11 |
12 #include "Gb_Oscs.h" | 12 #include "Gb_Oscs.h" |
13 | 13 |
14 class Gb_Apu { | 14 class Gb_Apu { |
15 public: | 15 public: |
16 Gb_Apu(); | |
17 ~Gb_Apu(); | |
18 | 16 |
19 // Overall volume of all oscillators, where 1.0 is full volume. | 17 // Set overall volume of all oscillators, where 1.0 is full volume |
20 void volume( double ); | 18 void volume( double ); |
21 | 19 |
22 // Treble equalization (see notes.txt). | 20 // Set treble equalization |
23 void treble_eq( const blip_eq_t& ); | 21 void treble_eq( const blip_eq_t& ); |
24 | 22 |
25 // Reset oscillators and internal state. | 23 // Outputs can be assigned to a single buffer for mono output, or to three |
26 void reset(); | 24 // buffers for stereo output (using Stereo_Buffer to do the mixing). |
27 | 25 |
28 // Assign all oscillator outputs to specified buffer(s). If buffer | 26 // Assign all oscillator outputs to specified buffer(s). If buffer |
29 // is NULL, silence all oscillators. | 27 // is NULL, silences all oscillators. |
30 void output( Blip_Buffer* mono ); | 28 void output( Blip_Buffer* mono ); |
31 void output( Blip_Buffer* center, Blip_Buffer* left, Blip_Buffer* right ); | 29 void output( Blip_Buffer* center, Blip_Buffer* left, Blip_Buffer* right ); |
32 | 30 |
33 // Assign oscillator output to buffer(s). Valid indicies are 0 to | 31 // Assign single oscillator output to buffer(s). Valid indicies are 0 to 3, |
34 // osc_count - 1, which refer to Square 1, Square 2, Wave, and | 32 // which refer to Square 1, Square 2, Wave, and Noise. If buffer is NULL, |
35 // Noise, respectively. If buffer is NULL, silence oscillator. | 33 // silences oscillator. |
36 enum { osc_count = 4 }; | 34 enum { osc_count = 4 }; |
37 void osc_output( int index, Blip_Buffer* mono ); | 35 void osc_output( int index, Blip_Buffer* mono ); |
38 void osc_output( int index, Blip_Buffer* center, Blip_Buffer* left, Blip_Buffer* right ); | 36 void osc_output( int index, Blip_Buffer* center, Blip_Buffer* left, Blip_Buffer* right ); |
39 | 37 |
38 // Reset oscillators and internal state | |
39 void reset(); | |
40 | |
40 // Reads and writes at addr must satisfy start_addr <= addr <= end_addr | 41 // Reads and writes at addr must satisfy start_addr <= addr <= end_addr |
41 enum { start_addr = 0xff10 }; | 42 enum { start_addr = 0xFF10 }; |
42 enum { end_addr = 0xff3f }; | 43 enum { end_addr = 0xFF3f }; |
43 enum { register_count = end_addr - start_addr + 1 }; | 44 enum { register_count = end_addr - start_addr + 1 }; |
44 | 45 |
45 // Write 'data' to address at specified time. Previous writes and reads | 46 // Write 'data' to address at specified time |
46 // within the current frame must not have specified a later time. | |
47 void write_register( gb_time_t, gb_addr_t, int data ); | 47 void write_register( gb_time_t, gb_addr_t, int data ); |
48 | 48 |
49 // Read from address at specified time. Previous writes and reads within | 49 // Read from address at specified time |
50 // the current frame must not have specified a later time. | |
51 int read_register( gb_time_t, gb_addr_t ); | 50 int read_register( gb_time_t, gb_addr_t ); |
52 | 51 |
53 // Run all oscillators up to specified time, end current time frame, then | 52 // Run all oscillators up to specified time, end current time frame, then |
54 // start a new frame at time 0. Return true if any oscillators added | 53 // start a new frame at time 0. Returns true if any oscillators added |
55 // sound to one of the left/right buffers, false if they only added | 54 // sound to one of the left/right buffers, false if they only added |
56 // to the center buffer. | 55 // to the center buffer. |
57 bool end_frame( gb_time_t ); | 56 bool end_frame( gb_time_t ); |
58 | 57 |
59 static void begin_debug_log(); | 58 public: |
59 Gb_Apu(); | |
60 ~Gb_Apu(); | |
60 private: | 61 private: |
61 // noncopyable | 62 // noncopyable |
62 Gb_Apu( const Gb_Apu& ); | 63 Gb_Apu( const Gb_Apu& ); |
63 Gb_Apu& operator = ( const Gb_Apu& ); | 64 Gb_Apu& operator = ( const Gb_Apu& ); |
64 | 65 |
65 Gb_Osc* oscs [osc_count]; | 66 Gb_Osc* oscs [osc_count]; |
66 gb_time_t next_frame_time; | 67 gb_time_t next_frame_time; |
67 gb_time_t last_time; | 68 gb_time_t last_time; |
69 double volume_unit; | |
68 int frame_count; | 70 int frame_count; |
69 bool stereo_found; | 71 bool stereo_found; |
70 | 72 |
71 Gb_Square square1; | 73 Gb_Square square1; |
72 Gb_Square square2; | 74 Gb_Square square2; |
73 Gb_Wave wave; | 75 Gb_Wave wave; |
74 Gb_Noise noise; | 76 Gb_Noise noise; |
75 Gb_Square::Synth square_synth; // shared between squares | |
76 BOOST::uint8_t regs [register_count]; | 77 BOOST::uint8_t regs [register_count]; |
78 Gb_Square::Synth square_synth; // used by squares | |
79 Gb_Wave::Synth other_synth; // used by wave and noise | |
77 | 80 |
81 void update_volume(); | |
78 void run_until( gb_time_t ); | 82 void run_until( gb_time_t ); |
79 friend class Gb_Apu_Reflector; | 83 void write_osc( int index, int reg, int data ); |
80 }; | 84 }; |
81 | 85 |
82 inline void Gb_Apu::output( Blip_Buffer* mono ) { | 86 inline void Gb_Apu::output( Blip_Buffer* b ) { output( b, b, b ); } |
83 output( mono, NULL, NULL ); | |
84 } | |
85 | 87 |
86 inline void Gb_Apu::osc_output( int index, Blip_Buffer* mono ) { | 88 inline void Gb_Apu::osc_output( int i, Blip_Buffer* b ) { osc_output( i, b, b, b ); } |
87 osc_output( index, mono, NULL, NULL ); | 89 |
88 } | 90 inline void Gb_Apu::volume( double vol ) |
91 { | |
92 volume_unit = 0.60 / osc_count / 15 /*steps*/ / 2 /*?*/ / 8 /*master vol range*/ * vol; | |
93 update_volume(); | |
94 } | |
89 | 95 |
90 #endif | 96 #endif |
91 | 97 |