LMMS
Loading...
Searching...
No Matches
Nes_Oscs.h
Go to the documentation of this file.
1// Private oscillators used by Nes_Apu
2
3// Nes_Snd_Emu 0.1.8
4#ifndef NES_OSCS_H
5#define NES_OSCS_H
6
7#include "blargg_common.h"
8#include "Blip_Buffer.h"
9
10class Nes_Apu;
11
12struct Nes_Osc
13{
14 unsigned char regs [4];
15 bool reg_written [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
20
21 void clock_length( int halt_mask );
22 int period() const {
23 return (regs [3] & 7) * 0x100 + (regs [2] & 0xFF);
24 }
25 void reset() {
26 delay = 0;
27 last_amp = 0;
28 }
29 int update_amp( int amp ) {
30 int delta = amp - last_amp;
31 last_amp = amp;
32 return delta;
33 }
34};
35
37{
40
41 void clock_envelope();
42 int volume() const;
43 void reset() {
44 envelope = 0;
45 env_delay = 0;
47 }
48};
49
50// Nes_Square
52{
53 enum { negate_flag = 0x08 };
54 enum { shift_mask = 0x07 };
55 enum { phase_range = 8 };
56 int phase;
58
60 Synth const& synth; // shared between squares
61
62 Nes_Square( Synth const* s ) : synth( *s ) { }
63
64 void clock_sweep( int adjust );
65 void run( nes_time_t, nes_time_t );
66 void reset() {
67 sweep_delay = 0;
69 }
71 nes_time_t timer_period );
72};
73
74// Nes_Triangle
76{
77 enum { phase_range = 16 };
78 int phase;
81
82 int calc_amp() const;
83 void run( nes_time_t, nes_time_t );
85 void reset() {
87 phase = 1;
89 }
91 nes_time_t timer_period );
92};
93
94// Nes_Noise
96{
97 int noise;
99
100 void run( nes_time_t, nes_time_t );
101 void reset() {
102 noise = 1 << 14;
104 }
105};
106
107// Nes_Dmc
109{
110 int address; // address of next byte to read
112 //int length_counter; // bytes remaining to play (already defined in Nes_Osc)
113 int buf;
115 int bits;
118
119 enum { loop_flag = 0x40 };
120
121 int dac;
122
128
129 int (*prg_reader)( void*, nes_addr_t ); // needs to be initialized to prg read function
131
133
135
136 void start();
137 void write_register( int, int );
138 void run( nes_time_t, nes_time_t );
139 void recalc_irq();
140 void fill_buffer();
141 void reload_sample();
142 void reset();
143 int count_reads( nes_time_t, nes_time_t* ) const;
145};
146
147#endif
blargg_long nes_time_t
Definition Nes_Apu.h:9
unsigned nes_addr_t
Definition Nes_Apu.h:10
Definition Blip_Buffer.h:23
Definition Blip_Buffer.h:191
Definition Nes_Apu.h:17
unsigned s
Definition inflate.c:1555
Definition Nes_Oscs.h:109
bool irq_enabled
Definition Nes_Oscs.h:124
bool buf_full
Definition Nes_Oscs.h:116
int count_reads(nes_time_t, nes_time_t *) const
Definition Nes_Oscs.cpp:293
void recalc_irq()
Definition Nes_Oscs.cpp:281
int buf
Definition Nes_Oscs.h:113
int(* prg_reader)(void *, nes_addr_t)
Definition Nes_Oscs.h:129
Nes_Apu * apu
Definition Nes_Oscs.h:132
Blip_Synth< blip_med_quality, 1 > synth
Definition Nes_Oscs.h:134
void run(nes_time_t, nes_time_t)
Definition Nes_Oscs.cpp:399
void write_register(int, int)
Definition Nes_Oscs.cpp:347
bool silence
Definition Nes_Oscs.h:117
nes_time_t next_irq
Definition Nes_Oscs.h:123
bool irq_flag
Definition Nes_Oscs.h:125
bool pal_mode
Definition Nes_Oscs.h:126
int bits_remain
Definition Nes_Oscs.h:114
int address
Definition Nes_Oscs.h:110
void fill_buffer()
Definition Nes_Oscs.cpp:376
void reset()
Definition Nes_Oscs.cpp:264
void start()
Definition Nes_Oscs.cpp:369
int bits
Definition Nes_Oscs.h:115
bool nonlinear
Definition Nes_Oscs.h:127
int dac
Definition Nes_Oscs.h:121
void * prg_reader_data
Definition Nes_Oscs.h:130
void reload_sample()
Definition Nes_Oscs.cpp:329
nes_time_t next_read_time() const
Definition Nes_Apu.h:169
int period
Definition Nes_Oscs.h:111
@ loop_flag
Definition Nes_Oscs.h:119
Definition Nes_Oscs.h:37
void reset()
Definition Nes_Oscs.h:43
int env_delay
Definition Nes_Oscs.h:39
void clock_envelope()
Definition Nes_Oscs.cpp:26
int volume() const
Definition Nes_Oscs.cpp:41
int envelope
Definition Nes_Oscs.h:38
Definition Nes_Oscs.h:96
int noise
Definition Nes_Oscs.h:97
void reset()
Definition Nes_Oscs.h:101
void run(nes_time_t, nes_time_t)
Definition Nes_Oscs.cpp:478
Blip_Synth< blip_med_quality, 1 > synth
Definition Nes_Oscs.h:98
Definition Nes_Oscs.h:13
int last_amp
Definition Nes_Oscs.h:19
int delay
Definition Nes_Oscs.h:18
unsigned char regs[4]
Definition Nes_Oscs.h:14
int update_amp(int amp)
Definition Nes_Oscs.h:29
bool reg_written[4]
Definition Nes_Oscs.h:15
void clock_length(int halt_mask)
Definition Nes_Oscs.cpp:20
void reset()
Definition Nes_Oscs.h:25
Blip_Buffer * output
Definition Nes_Oscs.h:16
int length_counter
Definition Nes_Oscs.h:17
int period() const
Definition Nes_Oscs.h:22
@ phase_range
Definition Nes_Oscs.h:55
Blip_Synth< blip_good_quality, 1 > Synth
Definition Nes_Oscs.h:59
int phase
Definition Nes_Oscs.h:56
void run(nes_time_t, nes_time_t)
Definition Nes_Oscs.cpp:95
nes_time_t maintain_phase(nes_time_t time, nes_time_t end_time, nes_time_t timer_period)
Definition Nes_Oscs.cpp:82
void clock_sweep(int adjust)
Definition Nes_Oscs.cpp:48
Synth const & synth
Definition Nes_Oscs.h:60
@ shift_mask
Definition Nes_Oscs.h:54
@ negate_flag
Definition Nes_Oscs.h:53
int sweep_delay
Definition Nes_Oscs.h:57
void reset()
Definition Nes_Oscs.h:66
Nes_Square(Synth const *s)
Definition Nes_Oscs.h:62
Definition Nes_Oscs.h:76
nes_time_t maintain_phase(nes_time_t time, nes_time_t end_time, nes_time_t timer_period)
Definition Nes_Oscs.cpp:190
int calc_amp() const
Definition Nes_Oscs.cpp:181
Blip_Synth< blip_med_quality, 1 > synth
Definition Nes_Oscs.h:80
int linear_counter
Definition Nes_Oscs.h:79
void run(nes_time_t, nes_time_t)
Definition Nes_Oscs.cpp:204
void clock_linear_counter()
Definition Nes_Oscs.cpp:170
int phase
Definition Nes_Oscs.h:78
void reset()
Definition Nes_Oscs.h:85
@ phase_range
Definition Nes_Oscs.h:77
typedef int(UZ_EXP MsgFn)()