-
Notifications
You must be signed in to change notification settings - Fork 8
/
soundsystem.h
176 lines (132 loc) · 3.56 KB
/
soundsystem.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#ifndef _SOUNDSYSTEM_H_
#define _SOUNDSYSTEM_H_
#include "Object.h"
#include "Platform.h"
#include "Sample.h"
#include <windows.h>
#include <windowsx.h>
#include <Mmsystem.h>
//#pragma optimize("", off)
#define MAX_SOUND_BUFFERS 6
#define MAX_SIMULTANEOUS_SAMPLES 4
#define MAX_SIMULTANEOUS_SAMPLES_INC_MOD 8
struct PlayDataStruct
{
CSample* SampleRef; // Pointer to sample object
DWORD Index; // Pointer to where we are up to playing
int Count; // The number of times the sample is to be played.
float Pause; // Delay time.
int PauseRemaining; // Amount of pause time remaining.
// Addiotnal items for mod playback.
int Volume; // Volume for this 'channel'
int Pitch; // Current sample pitch.
int TimeUntilNextNote; // Kind of global property, but then again not.
int CurrentPosition; // Array in to PositionArray, which is in turn an index into PatternArray.
int CurrentNote;
};
// ----
// MOD
// ----
// ----
// There are four simultaneous channels -
// each channel requires 4 bytes of data.
struct NotesStruct
{
DWORD Note[4];
};
// ----
// Each pattern contains 64 NotesStructs.
struct PatternStruct
{
NotesStruct NotesArray[64];
};
struct PopulousInstrumentStruct
{
CSample *SampleRef;
int Frequency;
};
// ----
// This class encapsulates an audio mixer.
// WARNING: THERE CAN ONLY EVER BE ONE INSTANCE OF THIS CLASS.
// Operations based on subsequent object will always fail!!!
class CSoundSystem : public CObject
{
public:
CSoundSystem();
~CSoundSystem();
// ----
// GENERIC
// ----
// ----
bool Init(CPlatform *_PlatformRef, int _Volume);
// ----
int GetSoundSystemID() {return SoundSystemID;}
// ----
bool Process();
// ----
bool SetVolume(int _Volume);
// ----
// SAMPLES
// ----
// ----
bool PlaySample( CSample* _Sound,
int _Channel,
int _Frequency = 100,
int _Count = 1, // negative to loop.
float _Pause = 0.0f);
// ----
// Stop playback of all samples (so that it is safe to
bool StopAllSamples();
// ----
// MUSIC
// ----
// ----
bool LoadMod(CString *_FileName); // Load mod data.
void PlayMod(); // Starts mod playing.
void StopMod(); // Stops the mod playback.
// ----
// I must be a hack as I'm not protected!
bool ModPlaying;
// ----
// This checks wether a channel has finished playing it's data
bool CheckChannel(int ChanNum);
protected:
// ----
// These methods do the hard work...
bool ProcessAudio();
void ProcessMod();
// ----
// Only allow one object.
static int SoundSystemCount;
int SoundSystemID;
// Store old volume level, so we can restore it.
DWORD OldVolume;
bool GotOldVolume;
int MasterVolume;
// Store imported ref.
CPlatform* PlatformRef;
// Device caps.
HWAVEOUT DeviceHandle;
int DeviceID; // Id of the output device we are using.
WAVEOUTCAPS DeviceCaps; // Caps of our chosen device.
// Play queue buffers.
WAVEHDR WaveHeaderArray[MAX_SOUND_BUFFERS];
short* BufferArray[MAX_SOUND_BUFFERS];
int NextBuffer;
// Store playing sample data.
PlayDataStruct PlayData[MAX_SIMULTANEOUS_SAMPLES];
// ----
// MOD
#define MAX_POSITIONS 128
#define NUM_OF_MOD_SAMPLES 31
unsigned char PositionArray[MAX_POSITIONS];
int NumberOfPositions;
int NumberOfPatterns;
PatternStruct PatternArray[MAX_POSITIONS];
CSample *ModSampleArray[NUM_OF_MOD_SAMPLES]; // Mod's have a maximum of 32 samples.
// Store playing mod sample data.
PlayDataStruct ModPlayData[4];
int ModTempo;
};
//#pragma optimize("", on)
#endif