This repository has been archived by the owner on Nov 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNESSOUND.H
executable file
·122 lines (96 loc) · 2.2 KB
/
NESSOUND.H
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#ifndef _NESSOUND_
#define _NESSOUND_
#include "types.h"
#include "uutimer.h"
struct controlreg1
{
byte playbackrate:4;
byte envelopefixed:1;
byte holdnote:1;
byte dutycycle:2;
};
struct controlreg2
{
byte freqrange:3;
byte freqselect:1; //0:low -> high 1:high to low
byte freqchangespeed:3;
byte freqvariable:1; //0=fixed freq 1=variable freq
};
struct frequencyreg
{
unsigned short x;
short getfreq() {return x&0x7FF;}
byte gettime() {return x>>11;}
};
class neschannel
{
friend class nessound;
protected:
union
{
byte r[4]; //individual byte registers
struct
{
controlreg1 cr1;
controlreg2 cr2;
frequencyreg fr;
} sr;
};
byte enabled; //is the channel enabled?
byte noteon; //is the note on?
int dur; //duration of note left (in samples)
int freq; //frequency (correct)
int K; //freq counter increment
int deltaK; //change in freq counter over time
int count; //frequency counter (period is 0x10000)
short vol; //current 16-bit volume
public:
void setenable(byte x);
void reset();
void startnote();
void stopnote();
void setdeltaK();
neschannel() {reset();}
void write(byte a,byte d);
virtual void mix8(short *b,int nums) {}
virtual void mix16(short *b,int nums) {}
virtual void setvolume() {}
virtual void print(int x,int y);
};
class squarewave:public neschannel
{
public:
virtual void mix16(short *b,int nums);
virtual void setvolume();
};
class trianglewave:public neschannel
{
public:
virtual void mix16(short *b,int nums);
virtual void setvolume();
};
//------------------
class nessound
{
neschannel *ch[5]; //5 channels
public:
byte enablebits;
void write(byte a,byte d);
void setenable(byte d); //set sound enables
void reset();
void print();
nessound();
~nessound();
//mixing buffer
static short mixingbuf[4096];
//called periodically to do mixing
void update(int nums);
void mix(int nums); //mixes nums bytes and outputs it
void mix16(short *buf, int nums); //16 bit mixing
};
extern nessound *ns;
extern byte soundenabled; //is sound enabled ?
void disablesound();
void enablesound();
void togglesound();
#endif