Skip to content

Commit 459175b

Browse files
committed
Further GUS optimization.
1 parent 933dcfb commit 459175b

6 files changed

Lines changed: 44 additions & 77 deletions

File tree

src/Makefile.djgpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#ARCH = -march=i386 -mtune=i486
22
ARCH =
33
CFLAGS = \
4-
-DM_PI=3.14159265358979323846 \
54
-I./q2dos/dos/3rdparty/include \
65
-I./djgpp/jpeg \
76
-I./djgpp/libpng \

src/gamemng.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ void Gamemng::set_far(int far1)
268268
void Gamemng::init_sound()
269269
{
270270
p_sound_crash = new Sound_crash;
271-
p_sound_crash->init(p_sound_game_static.p_hit_stream); // nulové *p_audiodevice je ošéfované uvnitř
271+
p_sound_crash->init(p_sound_game_static.p_hit_stream, p_sound_game_static.p_hit_sample); // nulové *p_audiodevice je ošéfované uvnitř
272272
}
273273

274274
void Gamemng::unset_scissor()

src/minial_gus.cpp

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -123,44 +123,13 @@ void MinialGUS::GenSources(ALsizei n, ALuint* sources)
123123
}
124124
}
125125
}
126-
127-
/*
128-
generateStuff(n, sources, sourceMap, sourceCounter);
129-
130-
for (int i = 0; i != n; ++i)
131-
{
132-
MA_GUS_Source& src = (sourceMap)[sources[i]];
133-
bool mapped = false;
134-
for (int j = 0; j != m_gusVoices; ++j)
135-
{
136-
if (gusVoiceMap[j] == 0)
137-
{
138-
src.gusVoice = j;
139-
gusVoiceMap[j] = 1;
140-
mapped = true;
141-
break;
142-
}
143-
}
144-
if (!mapped)
145-
{
146-
printf("unmapped voice!\n");
147-
}
148-
}
149-
*/
150126
}
151127
void MinialGUS::GenBuffers(ALsizei n, ALuint* buffers)
152128
{
153129
generateStuff(n, buffers, bufferMap, bufferCounter);
154130
}
155131
void MinialGUS::DeleteSources(ALsizei n, const ALuint* sources)
156132
{
157-
/*for (int i = 0; i != n; ++i)
158-
{
159-
MA_GUS_Source& src = (sourceMap)[sources[i]];
160-
gusVoiceMap[src.gusVoice] = 0;
161-
}
162-
deleteStuff(n, sources, sourceMap);*/
163-
164133
for (ALsizei i = 0; i != n; ++i)
165134
{
166135
if (sources[i] > 0 && sources[i] <= (ALuint)m_gusVoices)

src/minial_sb.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,22 +95,26 @@ void MinialSB::ma_callback(void* userdata, Uint8* stream, int len)
9595
(*floatBuff)[i] += buff.samples[src.pos] * src.gain;
9696
#endif
9797
#if MA_FILTER == MA_FILTER_LINEAR
98-
uint32_t ipos0 = src.pos;
99-
uint32_t ipos1 = ipos0 + 1;
100-
Sint16 smp0 = buff.samples[ipos0];
101-
Sint16 smp1 = 0;
102-
if (ipos1 >= buff.samples.size())
98+
if (src.gain > 0.f && m_listenerGain > 0.f)
10399
{
104-
if (src.looping)
100+
uint32_t ipos0 = src.pos;
101+
uint32_t ipos1 = ipos0 + 1;
102+
Sint16 smp0 = buff.samples[ipos0];
103+
Sint16 smp1 = 0;
104+
if (ipos1 >= buff.samples.size())
105105
{
106-
smp1 = buff.samples[0];
106+
if (src.looping)
107+
{
108+
smp1 = buff.samples[0];
109+
}
107110
}
111+
else
112+
{
113+
smp1 = buff.samples[ipos1];
114+
}
115+
(floatBuff)[i] +=
116+
(float(smp0) + (float(smp1) - float(smp0)) * (src.pos - ipos0)) * src.gain;
108117
}
109-
else
110-
{
111-
smp1 = buff.samples[ipos1];
112-
}
113-
(floatBuff)[i] += (float(smp0) + (float(smp1) - float(smp0)) * (src.pos - ipos0)) * src.gain;
114118
#endif
115119
#if MA_FILTER == MA_FILTER_HIGH_QUALITY
116120
#error "Hight quality audio filter is currently not implemented"

src/soundmng.cpp

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ void Sound_game_static::playSoundTest(float gain)
3636
{
3737
alSourceStop(p_hit_stream[0]);
3838
alSourceRewind(p_hit_stream[0]);
39+
alSourcei(p_hit_stream[0], AL_BUFFER, p_hit_sample[0]);
3940
alSourcef(p_hit_stream[0], AL_GAIN, 1.0);
4041
alSourcef(p_hit_stream[0], AL_PITCH, 1.0);
4142
alListenerf(AL_GAIN, gain);
@@ -66,12 +67,10 @@ void Sound_game_static::init()
6667
for (unsigned int i = 0; i != 4; ++i) {
6768
p_skid_stream[i] = createSource(p_skid_sample);
6869
}
69-
for (int j = 0; j != 2; ++j)
70-
for (int i = 0; i != hitStreamCount/2; ++i) {
71-
p_hit_stream[i+j*(hitStreamCount/2)] = createSource(p_hit_sample[j]);
72-
}
73-
74-
//p_test_stream = createSource(p_hit_sample[0]);
70+
for (int i = 0; i != hitStreamCount; ++i)
71+
{
72+
p_hit_stream[i] = createSource(0);
73+
}
7574
}
7675

7776
void Sound_game_static::load(unsigned int i, ALbuffer engine0_sample, ALbuffer engine1_sample)
@@ -106,7 +105,6 @@ static constexpr float engine1_volume0 = 0.75f;
106105

107106
void Sound_car::frame(float deltaT, int engine_state /*0 - nultý, 1 - první, 2 - první potichu*/, float engine_pitch, const float velocity[2])
108107
{
109-
//
110108
p_time += deltaT;
111109
if (p_time >= p_T) p_time = 0.f; else return;
112110
if (!p_engine_on && engine_state == 2)
@@ -216,9 +214,10 @@ void Sound_car::init(ALsource stream_engine, ALbuffer sample_idle, ALbuffer samp
216214
p_engine_on = 0;
217215
}
218216

219-
void Sound_crash::init(ALsource* stream_hit) // load zvuků
217+
void Sound_crash::init(const ALsource* stream_hit, const ALbuffer* sample_hit) // load zvuků
220218
{
221-
p_hit_stream = stream_hit;
219+
p_hit_streams = stream_hit;
220+
p_hit_samples = sample_hit;
222221
}
223222

224223
void Sound_crash::play(float c_j) // přehraje zvuk nárazu
@@ -228,17 +227,19 @@ void Sound_crash::play(float c_j) // přehraje zvuk nárazu
228227
if (volume > 1.f) volume = 1.f;
229228
if (volume < 0.f) volume = 0.f;
230229
static const int sampleIndexer[6] = {0, 1, 0, 1, 0, 1};
231-
int sample_sel =sampleIndexer[randn1(5)];
232-
int stream_sel = p_fronta_pos[sample_sel]++;
233-
p_fronta_pos[sample_sel] %= p_width;
234-
int sel = stream_sel+sample_sel*p_width;
230+
int sample_sel = sampleIndexer[randn1(5)];
231+
232+
ALuint stream = p_hit_streams[p_currentStream];
235233

236-
alSourceStop(p_hit_stream[sel]);
237-
alSourceRewind(p_hit_stream[sel]);
238-
alSourcef(p_hit_stream[sel], AL_GAIN, volume);
234+
alSourceStop(stream);
235+
alSourceRewind(stream);
236+
alSourcei(stream, AL_BUFFER, p_hit_samples[sample_sel]);
237+
alSourcef(stream, AL_GAIN, volume);
239238

240239
float pitch_min = 0.88;
241240
float pitch = pitch_min+randn1(int((1.f-pitch_min)*2.f*1000.f))*0.001;
242-
alSourcef(p_hit_stream[sel], AL_PITCH, pitch);
243-
alSourcePlay(p_hit_stream[sel]);
241+
alSourcef(stream, AL_PITCH, pitch);
242+
alSourcePlay(stream);
243+
244+
p_currentStream = (p_currentStream + 1) % Sound_game_static::hitStreamCount;
244245
}

src/soundmng.h

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ typedef ALuint ALsource;
3131

3232
class Sound_game_static {
3333
public:
34-
static constexpr int hitStreamCount = 6;
34+
static constexpr int hitStreamCount = 5;
35+
static constexpr int hitSampleCount = 2;
3536
Sound_game_static() {
3637
for (int i = 0; i != 4; ++i)
3738
{
@@ -71,7 +72,7 @@ class Sound_game_static {
7172
ALsource p_hit_stream[hitStreamCount];
7273

7374
ALbuffer p_skid_sample;
74-
ALbuffer p_hit_sample[2];
75+
ALbuffer p_hit_sample[hitSampleCount];
7576

7677
//ALsource p_laprecord_stream;
7778
//ALbuffer p_laprecord_sample;
@@ -110,21 +111,14 @@ class Sound_car {
110111

111112
class Sound_crash {
112113
public:
113-
Sound_crash() { p_sz_samples = 2; p_width = 3; p_hit_stream = 0; p_fronta_pos[0] = 0; p_fronta_pos[1] = 0; }
114+
Sound_crash() { p_hit_streams = 0; p_hit_samples = 0; p_currentStream = 0; }
114115
~Sound_crash() {
115116
}
116-
void init(ALsource* stream_hit); // load zvuků
117+
void init(const ALsource* stream_hit, const ALbuffer* sample_hit); // load zvuků
117118
void play(float c_j); // přehraje zvuk nárazu
118-
int p_sz_samples;
119-
int p_width; // šířka fronty
120-
ALsource* p_hit_stream;
121-
int p_fronta_pos[10]; // stačí 2
122-
123-
// n = 3
124-
// f = 5
125-
// samply[n]
126-
// fronty[f*n]
127-
// fronty_i[n]
119+
const ALsource* p_hit_streams;
120+
const ALbuffer* p_hit_samples;
121+
ALuint p_currentStream;
128122
};
129123

130124
#endif

0 commit comments

Comments
 (0)