summaryrefslogtreecommitdiff
path: root/sound.c
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2006-09-27 18:17:01 +0000
committerpeter1138 <peter1138@openttd.org>2006-09-27 18:17:01 +0000
commit653e7fa54843b4427908b47d2e7da8ee48071a18 (patch)
tree89f67db5c4825d95a0c5687363b43db1311ffae7 /sound.c
parent3ded010d91a755f3f719d5bfe91cda6d161ef2d0 (diff)
downloadopenttd-653e7fa54843b4427908b47d2e7da8ee48071a18.tar.xz
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
Diffstat (limited to 'sound.c')
-rw-r--r--sound.c40
1 files changed, 26 insertions, 14 deletions
diff --git a/sound.c b/sound.c
index c3eacd685..f8d194c97 100644
--- a/sound.c
+++ b/sound.c
@@ -10,14 +10,7 @@
#include "window.h"
#include "viewport.h"
#include "fileio.h"
-
-typedef struct FileEntry {
- uint32 file_offset;
- uint32 file_size;
- uint16 rate;
- uint8 bits_per_sample;
- uint8 channels;
-} FileEntry;
+#include "newgrf_sound.h"
static uint _file_count;
static FileEntry *_files;
@@ -100,14 +93,19 @@ static void OpenBankFile(const char *filename)
}
}
+uint GetNumOriginalSounds(void)
+{
+ return _file_count;
+}
+
static bool SetBankSource(MixerChannel *mc, uint bank)
{
const FileEntry *fe;
int8 *mem;
uint i;
- if (bank >= _file_count) return false;
- fe = &_files[bank];
+ if (bank >= GetNumSounds()) return false;
+ fe = GetSound(bank);
if (fe->file_size == 0) return false;
@@ -180,6 +178,20 @@ static const byte _sound_idx[] = {
72,
};
+void SndCopyToPool(void)
+{
+ uint i;
+
+ for (i = 0; i < _file_count; i++) {
+ FileEntry *orig = &_files[_sound_idx[i]];
+ FileEntry *fe = AllocateFileEntry();
+
+ memcpy(fe, orig, sizeof(*orig));
+ fe->volume = _sound_base_vol[i];
+ fe->priority = 0;
+ }
+}
+
static void SndPlayScreenCoordFx(SoundFx sound, int x, int y)
{
const Window *w;
@@ -195,9 +207,9 @@ static void SndPlayScreenCoordFx(SoundFx sound, int x, int y)
int left = (x - vp->virtual_left);
StartSound(
- _sound_idx[sound],
+ sound,
left / (vp->virtual_width / ((PANNING_LEVELS << 1) + 1)) - PANNING_LEVELS,
- (_sound_base_vol[sound] * msf.effect_vol * _vol_factor_by_zoom[vp->zoom]) >> 15
+ (GetSound(sound)->volume * msf.effect_vol * _vol_factor_by_zoom[vp->zoom]) >> 15
);
return;
}
@@ -225,8 +237,8 @@ void SndPlayVehicleFx(SoundFx sound, const Vehicle *v)
void SndPlayFx(SoundFx sound)
{
StartSound(
- _sound_idx[sound],
+ sound,
0,
- (_sound_base_vol[sound] * msf.effect_vol) >> 7
+ (GetSound(sound)->volume * msf.effect_vol) >> 7
);
}