2019-05-29 01:54:47 +02:00
|
|
|
|
|
|
|
#include "game.h"
|
|
|
|
#include "resource.h"
|
2022-03-12 23:53:43 +01:00
|
|
|
#include "mixer.h"
|
2019-05-29 01:54:47 +02:00
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
#define MAX_SOUNDS 11
|
|
|
|
|
|
|
|
static const uint16_t sound_sizes_tbl[] = {
|
|
|
|
0x188E, 0x1C80, 0x235E, 0x19E6, 0x0AB2, 0x0912, 0x0000, 0x35D2,
|
|
|
|
0x06C4, 0x1C86, 0x0E2E
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *trk_names_tbl[] = {
|
|
|
|
"PRES.TRK",
|
|
|
|
"CODE.TRK",
|
|
|
|
"CARTE.TRK",
|
|
|
|
"PRESENTA.TRK",
|
|
|
|
"GLACE.TRK",
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
"MINES.TRK",
|
|
|
|
"MYSTERY.TRK",
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
"MONSTER.TRK",
|
|
|
|
"FINAL.TRK",
|
|
|
|
"BRAVO.TRK",
|
|
|
|
"KOOL.TRK",
|
|
|
|
"BOULA.TRK"
|
|
|
|
};
|
|
|
|
|
2019-06-02 02:21:03 +02:00
|
|
|
static int _music_num;
|
2019-05-29 01:54:47 +02:00
|
|
|
|
|
|
|
static uint16_t sound_offsets_tbl[MAX_SOUNDS];
|
|
|
|
|
|
|
|
void sound_init() {
|
|
|
|
uint16_t offset = 0;
|
|
|
|
for (int i = 0; i < MAX_SOUNDS; ++i) {
|
|
|
|
sound_offsets_tbl[i] = offset;
|
|
|
|
offset += sound_sizes_tbl[i];
|
|
|
|
}
|
2019-06-02 02:21:03 +02:00
|
|
|
_music_num = -1;
|
2019-05-29 01:54:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void sound_fini() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void play_sound(int num) {
|
|
|
|
assert(num < MAX_SOUNDS);
|
2022-03-12 23:53:43 +01:00
|
|
|
print_debug(DBG_SOUND, "play_sound %d", num);
|
2019-05-29 01:54:47 +02:00
|
|
|
if (!g_res.samples) { /* no SAMPLE. file with demo */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const int sample_offset = sound_offsets_tbl[num];
|
|
|
|
const int sample_size = sound_sizes_tbl[num];
|
2022-03-12 23:53:43 +01:00
|
|
|
print_debug(DBG_SOUND, "sample num %d offset 0x%x size %d", num, sample_offset, sample_size);
|
2019-05-29 01:54:47 +02:00
|
|
|
if (sample_size == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2022-03-12 23:53:43 +01:00
|
|
|
g_mix.play_sound(g_res.samples + sample_offset, sample_size, 8000, 0);
|
2019-05-29 01:54:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void play_music(int num) {
|
|
|
|
if (g_res.dos_demo) { /* no .TRK files with demo */
|
|
|
|
return;
|
|
|
|
}
|
2019-06-02 02:21:03 +02:00
|
|
|
if (_music_num == num) {
|
|
|
|
return;
|
|
|
|
}
|
2019-05-29 01:54:47 +02:00
|
|
|
const char *filename = trk_names_tbl[num];
|
|
|
|
if (filename) {
|
2022-03-12 23:53:43 +01:00
|
|
|
print_debug(DBG_SOUND, "play_music '%s'", filename);
|
2019-05-29 01:54:47 +02:00
|
|
|
uint8_t *data = load_file(filename);
|
|
|
|
if (data) {
|
2022-03-12 23:53:43 +01:00
|
|
|
g_mix.play_music(data, g_uncompressed_size);
|
2019-05-29 01:54:47 +02:00
|
|
|
free(data);
|
2019-06-02 02:21:03 +02:00
|
|
|
_music_num = num;
|
2019-05-29 01:54:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|