Skip to content

Commit cef1013

Browse files
committed
Sound quality setting.
1 parent 8878015 commit cef1013

4 files changed

Lines changed: 45 additions & 32 deletions

File tree

src/main.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,11 @@ int my_main (int argc, char** argv)
272272

273273
set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
274274

275-
int digi = settings.get("enable_sound") ? DIGI_AUTODETECT : DIGI_NONE;
275+
const int sound_quality = settings.get("sound_quality");
276+
277+
int digi = sound_quality ? DIGI_AUTODETECT : DIGI_NONE;
278+
279+
MA_freq = 11025 * sound_quality;
276280

277281
if (install_sound(digi, MIDI_NONE, NULL) != 0)
278282
{

src/minial.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818
#define MA_FILTER_HIGH_QUALITY 2
1919

2020
#define MA_FILTER MA_FILTER_LINEAR
21-
#define MA_FREQ 22050
21+
//#define MA_FREQ 22050
2222
#define MA_SAMPLES 1024
2323

24+
int MA_freq = 0;
25+
2426
struct ALCdevice
2527
{
2628
ALuint dummy;
@@ -201,7 +203,10 @@ ALCdevice* alcOpenDevice(const ALCchar *devicename)
201203
floatBuff = new std::vector<float>;
202204
floatBuff->resize(MA_SAMPLES);
203205

204-
stream = play_audio_stream(MA_SAMPLES, 16, FALSE, MA_FREQ, 255, 128);
206+
if (MA_freq)
207+
{
208+
stream = play_audio_stream(MA_SAMPLES, 16, FALSE, MA_freq, 255, 128);
209+
}
205210

206211
#if 0
207212
SDL_AudioSpec as;
@@ -240,8 +245,11 @@ ALCboolean alcCloseDevice(ALCdevice *device)
240245
{
241246
(void)device;
242247
//SDL_CloseAudio();
243-
stop_audio_stream(stream);
244-
stream = 0;
248+
if (stream)
249+
{
250+
stop_audio_stream(stream);
251+
stream = 0;
252+
}
245253

246254
delete sourceMap;
247255
sourceMap = 0;
@@ -312,10 +320,10 @@ void alListenerfv(ALenum param, const ALfloat *values)
312320

313321
void alBufferData(ALuint buffer, ALenum format, const ALvoid *data, ALsizei size, ALsizei freq)
314322
{
315-
if (buffer == 0 || bufferMap == 0 || format != AL_FORMAT_MONO16) return; // only 16-bit mono audio is currently supported
323+
if (buffer == 0 || bufferMap == 0 || format != AL_FORMAT_MONO16 || MA_freq == 0) return; // only 16-bit mono audio is currently supported
316324
SDL_LockAudio();
317325
MA_Buffer& buff = (*bufferMap)[buffer];
318-
buff.pitch = float(freq)/float(MA_FREQ);
326+
buff.pitch = float(freq)/float(MA_freq);
319327
buff.samples.resize(size >> 1);
320328
std::copy((Sint16*)data, ((Sint16*)data) + buff.samples.size(), buff.samples.begin());
321329
SDL_UnlockAudio();

src/minial.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,6 @@ void alSourceRewind(ALuint source);
5656
void alSourceStop(ALuint source);
5757

5858
void MA_periodicStream(void);
59+
extern int MA_freq;
5960

6061
#endif // MINIAL_H

src/settings_dat.cpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,31 @@
99

1010
// name, default, min, max, comment
1111
const Sett_entry_base entry_base[] = {
12-
{"fullscreen", 0, 0, 1, "0 - windowed, 1 - fullscreen"},
13-
{"screen_x", 640, 0, UINT_MAX, "screen resolution"},
14-
{"screen_y", 480, 0, UINT_MAX, ""},
15-
{"vsync", 0, 0, 1, "0 - vsync off, 1 - vsync on"},
16-
{"antialiasing", 0, 0, 0, "0 - off"},
17-
{"hq_textures", 0, 0, 1, "0 - lower details, 1 - higher details"},
18-
{"texture_filter", 0, 0, 1, "0 - bilinear, 1 - trilinear"},
19-
{"mipmaps", 0, 0, 1, "0 - mipmaps off, 1 - mipmaps on"},
20-
{"view_distance", 0, 0, 10, "10 - far (best), 0 - near"},
21-
{"show_fps", 1, 0, 1, "0 - fps counter off, 1 - fps counter on"},
22-
{"enable_sound", 1, 0, 1, "0 - disable, 1 - enable"},
23-
{"sound_volume", 100, 0, 100, "0 - 100"},
24-
{"last_laps", 3, 1, 50, "last session"},
25-
{"last_daytime", 0, 0, 1, "0 - day, 1 - evening"},
26-
{"last_track", 0, 0, UINT_MAX, ""},
27-
{"last_direction", 0, 0, 1, "0 - regular, 1 - reversed"},
28-
{"last_players", 2, 1, 4, ""},
29-
{"last_carsel1", 0, 0, UINT_MAX, ""},
30-
{"last_cartex1", 0, 0, UINT_MAX, ""},
31-
{"last_carsel2", 0, 0, UINT_MAX, ""},
32-
{"last_cartex2", 1, 0, UINT_MAX, ""},
33-
{"last_carsel3", 0, 0, UINT_MAX, ""},
34-
{"last_cartex3", 2, 0, UINT_MAX, ""},
35-
{"last_carsel4", 0, 0, UINT_MAX, ""},
36-
{"last_cartex4", 3, 0, UINT_MAX, ""},
12+
{"fullscreen", 1, 0, 1, "0 - windowed, 1 - fullscreen"},
13+
{"screen_x", 640, 0, UINT_MAX, "screen resolution"},
14+
{"screen_y", 480, 0, UINT_MAX, ""},
15+
{"vsync", 0, 0, 1, "0 - vsync off, 1 - vsync on"},
16+
{"antialiasing", 0, 0, 0, "0 - off"},
17+
{"hq_textures", 0, 0, 1, "0 - lower details, 1 - higher details"},
18+
{"texture_filter", 0, 0, 1, "0 - bilinear, 1 - trilinear"},
19+
{"mipmaps", 0, 0, 1, "0 - mipmaps off, 1 - mipmaps on"},
20+
{"view_distance", 0, 0, 10, "10 - far (best), 0 - near"},
21+
{"show_fps", 1, 0, 1, "0 - fps counter off, 1 - fps counter on"},
22+
{"sound_quality", 2, 0, 2, "0 - off, 1 - low quality, 2 - normal quality"},
23+
{"sound_volume", 100, 0, 100, "0 - 100"},
24+
{"last_laps", 3, 1, 50, "last session"},
25+
{"last_daytime", 0, 0, 1, "0 - day, 1 - evening"},
26+
{"last_track", 0, 0, UINT_MAX, ""},
27+
{"last_direction", 0, 0, 1, "0 - regular, 1 - reversed"},
28+
{"last_players", 2, 1, 4, ""},
29+
{"last_carsel1", 0, 0, UINT_MAX, ""},
30+
{"last_cartex1", 0, 0, UINT_MAX, ""},
31+
{"last_carsel2", 0, 0, UINT_MAX, ""},
32+
{"last_cartex2", 1, 0, UINT_MAX, ""},
33+
{"last_carsel3", 0, 0, UINT_MAX, ""},
34+
{"last_cartex3", 2, 0, UINT_MAX, ""},
35+
{"last_carsel4", 0, 0, UINT_MAX, ""},
36+
{"last_cartex4", 3, 0, UINT_MAX, ""},
3737
};
3838

3939
const char* Settings::controlNames[16] = {

0 commit comments

Comments
 (0)