1
// Private oscillators used by Nes_Apu
7
#include "blargg_common.h"
8
#include "Blip_Buffer.h"
14
unsigned char regs [4];
17
int length_counter;// length counter (0 if unused by oscillator)
18
int delay; // delay until next (potential) transition
19
int last_amp; // last amplitude oscillator was outputting
21
void clock_length( int halt_mask );
23
return (regs [3] & 7) * 0x100 + (regs [2] & 0xFF);
29
int update_amp( int amp ) {
30
int delta = amp - last_amp;
36
struct Nes_Envelope : Nes_Osc
41
void clock_envelope();
51
struct Nes_Square : Nes_Envelope
53
enum { negate_flag = 0x08 };
54
enum { shift_mask = 0x07 };
55
enum { phase_range = 8 };
59
typedef Blip_Synth<blip_good_quality,1> Synth;
60
Synth const& synth; // shared between squares
62
Nes_Square( Synth const* s ) : synth( *s ) { }
64
void clock_sweep( int adjust );
65
void run( nes_time_t, nes_time_t );
68
Nes_Envelope::reset();
70
nes_time_t maintain_phase( nes_time_t time, nes_time_t end_time,
71
nes_time_t timer_period );
75
struct Nes_Triangle : Nes_Osc
77
enum { phase_range = 16 };
80
Blip_Synth<blip_med_quality,1> synth;
83
void run( nes_time_t, nes_time_t );
84
void clock_linear_counter();
90
nes_time_t maintain_phase( nes_time_t time, nes_time_t end_time,
91
nes_time_t timer_period );
95
struct Nes_Noise : Nes_Envelope
98
Blip_Synth<blip_med_quality,1> synth;
100
void run( nes_time_t, nes_time_t );
103
Nes_Envelope::reset();
108
struct Nes_Dmc : Nes_Osc
110
int address; // address of next byte to read
112
//int length_counter; // bytes remaining to play (already defined in Nes_Osc)
119
enum { loop_flag = 0x40 };
129
int (*prg_reader)( void*, nes_addr_t ); // needs to be initialized to prg read function
130
void* prg_reader_data;
134
Blip_Synth<blip_med_quality,1> synth;
137
void write_register( int, int );
138
void run( nes_time_t, nes_time_t );
141
void reload_sample();
143
int count_reads( nes_time_t, nes_time_t* ) const;
144
nes_time_t next_read_time() const;