summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-05-17 19:27:50 +0000
committerrubidium <rubidium@openttd.org>2009-05-17 19:27:50 +0000
commit4a04dfc07c916cff565de54e527402a7c082b8ed (patch)
tree095bcafec29558ac8ac8df748beb40e0677b9e28
parentceca68fca7bbd15674b88e908d5ebc7dab439bb7 (diff)
downloadopenttd-4a04dfc07c916cff565de54e527402a7c082b8ed.tar.xz
(svn r16344) -Codechange: s/FileEntry/SoundEntry/
-rw-r--r--src/newgrf.cpp44
-rw-r--r--src/newgrf_sound.cpp14
-rw-r--r--src/newgrf_sound.h4
-rw-r--r--src/sound.cpp65
-rw-r--r--src/sound_type.h2
5 files changed, 64 insertions, 65 deletions
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index 10529b189..b39635342 100644
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -2042,11 +2042,11 @@ static ChangeInfoResult SoundEffectChangeInfo(uint sid, int numinfo, int prop, b
if (orig_sound >= ORIGINAL_SAMPLE_COUNT) {
grfmsg(1, "SoundEffectChangeInfo: Original sound %d not defined (max %d)", orig_sound, ORIGINAL_SAMPLE_COUNT);
} else {
- FileEntry *newfe = GetSound(sound);
- FileEntry *oldfe = GetSound(orig_sound);
+ SoundEntry *new_sound = GetSound(sound);
+ SoundEntry *old_sound = GetSound(orig_sound);
/* Literally copy the data of the new sound over the original */
- *oldfe = *newfe;
+ *old_sound = *new_sound;
}
} break;
@@ -5051,9 +5051,9 @@ static void SkipAct11(byte *buf, size_t len)
static void ImportGRFSound(byte *buf, int len)
{
const GRFFile *file;
- FileEntry *se = AllocateFileEntry();
+ SoundEntry *sound = AllocateSound();
uint32 grfid = grf_load_dword(&buf);
- uint16 sound = grf_load_word(&buf);
+ SoundID sound_id = grf_load_word(&buf);
file = GetFileByGRFID(grfid);
if (file == NULL || file->sound_offset == 0) {
@@ -5061,18 +5061,18 @@ static void ImportGRFSound(byte *buf, int len)
return;
}
- if (file->sound_offset + sound >= GetNumSounds()) {
- grfmsg(1, "ImportGRFSound: Sound effect %d is invalid", sound);
+ if (file->sound_offset + sound_id >= GetNumSounds()) {
+ grfmsg(1, "ImportGRFSound: Sound effect %d is invalid", sound_id);
return;
}
- grfmsg(2, "ImportGRFSound: Copying sound %d (%d) from file %X", sound, file->sound_offset + sound, grfid);
+ grfmsg(2, "ImportGRFSound: Copying sound %d (%d) from file %X", sound_id, file->sound_offset + sound_id, grfid);
- *se = *GetSound(file->sound_offset + sound);
+ *sound = *GetSound(file->sound_offset + sound_id);
/* Reset volume and priority, which TTDPatch doesn't copy */
- se->volume = 128;
- se->priority = 0;
+ sound->volume = 128;
+ sound->priority = 0;
}
/* 'Action 0xFE' */
@@ -5105,7 +5105,7 @@ static void LoadGRFSound(byte *buf, int len)
/* Allocate a sound entry. This is done even if the data is not loaded
* so that the indices used elsewhere are still correct. */
- FileEntry *se = AllocateFileEntry();
+ SoundEntry *sound = AllocateSound();
if (grf_load_dword(&buf) != BSWAP32('RIFF')) {
grfmsg(1, "LoadGRFSound: Missing RIFF header");
@@ -5131,30 +5131,30 @@ static void LoadGRFSound(byte *buf, int len)
grfmsg(1, "LoadGRFSound: Invalid audio format");
return;
}
- se->channels = grf_load_word(&buf);
- se->rate = grf_load_dword(&buf);
+ sound->channels = grf_load_word(&buf);
+ sound->rate = grf_load_dword(&buf);
grf_load_dword(&buf);
grf_load_word(&buf);
- se->bits_per_sample = grf_load_word(&buf);
+ sound->bits_per_sample = grf_load_word(&buf);
/* Consume any extra bytes */
for (; size > 16; size--) grf_load_byte(&buf);
break;
case 'atad': // 'data'
- se->file_size = size;
- se->file_offset = FioGetPos() - (len - (buf - buf_start)) + 1;
- se->file_slot = _file_index;
+ sound->file_size = size;
+ sound->file_offset = FioGetPos() - (len - (buf - buf_start)) + 1;
+ sound->file_slot = _file_index;
/* Set default volume and priority */
- se->volume = 0x80;
- se->priority = 0;
+ sound->volume = 0x80;
+ sound->priority = 0;
- grfmsg(2, "LoadGRFSound: channels %u, sample rate %u, bits per sample %u, length %u", se->channels, se->rate, se->bits_per_sample, size);
+ grfmsg(2, "LoadGRFSound: channels %u, sample rate %u, bits per sample %u, length %u", sound->channels, sound->rate, sound->bits_per_sample, size);
return;
default:
- se->file_size = 0;
+ sound->file_size = 0;
return;
}
}
diff --git a/src/newgrf_sound.cpp b/src/newgrf_sound.cpp
index 1ea568f32..249ea03ba 100644
--- a/src/newgrf_sound.cpp
+++ b/src/newgrf_sound.cpp
@@ -10,11 +10,11 @@
#include "sound_func.h"
static uint _sound_count = 0;
-STATIC_OLD_POOL(SoundInternal, FileEntry, 3, 1000, NULL, NULL)
+STATIC_OLD_POOL(SoundInternal, SoundEntry, 3, 1000, NULL, NULL)
-/* Allocate a new FileEntry */
-FileEntry *AllocateFileEntry()
+/* Allocate a new Sound */
+SoundEntry *AllocateSound()
{
if (_sound_count == GetSoundInternalPoolSize()) {
if (!_SoundInternal_pool.AddBlockToPool()) return NULL;
@@ -34,7 +34,7 @@ void InitializeSoundPool()
}
-FileEntry *GetSound(SoundID index)
+SoundEntry *GetSound(SoundID index)
{
if (index >= GetNumSounds()) return NULL;
return GetSoundInternal(index);
@@ -62,16 +62,16 @@ bool PlayVehicleSound(const Vehicle *v, VehicleSoundEvent event)
if (callback == CALLBACK_FAILED) return false;
if (callback >= ORIGINAL_SAMPLE_COUNT) callback += file->sound_offset - ORIGINAL_SAMPLE_COUNT;
- if (callback < GetNumSounds()) SndPlayVehicleFx((SoundFx)callback, v);
+ if (callback < GetNumSounds()) SndPlayVehicleFx(callback, v);
return true;
}
-bool PlayTileSound(const GRFFile *file, uint16 sound_id, TileIndex tile)
+bool PlayTileSound(const GRFFile *file, SoundID sound_id, TileIndex tile)
{
if (sound_id >= ORIGINAL_SAMPLE_COUNT) sound_id += file->sound_offset - ORIGINAL_SAMPLE_COUNT;
if (sound_id < GetNumSounds()) {
- SndPlayTileFx((SoundFx)sound_id, tile);
+ SndPlayTileFx(sound_id, tile);
return true;
}
return false;
diff --git a/src/newgrf_sound.h b/src/newgrf_sound.h
index 7def7b280..d95691adc 100644
--- a/src/newgrf_sound.h
+++ b/src/newgrf_sound.h
@@ -21,9 +21,9 @@ enum VehicleSoundEvent {
};
-FileEntry *AllocateFileEntry();
+SoundEntry *AllocateSound();
void InitializeSoundPool();
-FileEntry *GetSound(SoundID sound_id);
+SoundEntry *GetSound(SoundID sound_id);
uint GetNumSounds();
bool PlayVehicleSound(const Vehicle *v, VehicleSoundEvent event);
bool PlayTileSound(const struct GRFFile *file, SoundID sound_id, TileIndex tile);
diff --git a/src/sound.cpp b/src/sound.cpp
index 55024f84c..104ff9e10 100644
--- a/src/sound.cpp
+++ b/src/sound.cpp
@@ -13,7 +13,7 @@
#include "vehicle_base.h"
#include "debug.h"
-static FileEntry _original_sounds[ORIGINAL_SAMPLE_COUNT];
+static SoundEntry _original_sounds[ORIGINAL_SAMPLE_COUNT];
MusicFileSettings msf;
/* Number of levels of panning per side */
@@ -45,10 +45,10 @@ static void OpenBankFile(const char *filename)
}
for (uint i = 0; i != ORIGINAL_SAMPLE_COUNT; i++) {
- FileEntry *fe = &_original_sounds[i];
+ SoundEntry *sound = &_original_sounds[i];
char name[255];
- FioSeekTo(fe->file_offset, SEEK_SET);
+ FioSeekTo(sound->file_offset, SEEK_SET);
/* Check for special case, see else case */
FioReadBlock(name, FioReadByte()); // Read the name of the sound
@@ -62,20 +62,20 @@ static void OpenBankFile(const char *filename)
if (tag == ' tmf') {
FioReadWord(); // wFormatTag
- fe->channels = FioReadWord(); // wChannels
+ sound->channels = FioReadWord(); // wChannels
FioReadDword(); // samples per second
- fe->rate = 11025; // seems like all samples should be played at this rate.
+ sound->rate = 11025; // seems like all samples should be played at this rate.
FioReadDword(); // avg bytes per second
FioReadWord(); // alignment
- fe->bits_per_sample = FioReadByte(); // bits per sample
+ sound->bits_per_sample = FioReadByte(); // bits per sample
FioSeekTo(size - (2 + 2 + 4 + 4 + 2 + 1), SEEK_CUR);
} else if (tag == 'atad') {
- fe->file_size = size;
- fe->file_slot = SOUND_SLOT;
- fe->file_offset = FioGetPos();
+ sound->file_size = size;
+ sound->file_slot = SOUND_SLOT;
+ sound->file_offset = FioGetPos();
break;
} else {
- fe->file_size = 0;
+ sound->file_size = 0;
break;
}
}
@@ -85,33 +85,33 @@ static void OpenBankFile(const char *filename)
* (name in sample.cat is "Corrupt sound")
* It's no RIFF file, but raw PCM data
*/
- fe->channels = 1;
- fe->rate = 11025;
- fe->bits_per_sample = 8;
- fe->file_slot = SOUND_SLOT;
- fe->file_offset = FioGetPos();
+ sound->channels = 1;
+ sound->rate = 11025;
+ sound->bits_per_sample = 8;
+ sound->file_slot = SOUND_SLOT;
+ sound->file_offset = FioGetPos();
}
}
}
-static bool SetBankSource(MixerChannel *mc, const FileEntry *fe)
+static bool SetBankSource(MixerChannel *mc, const SoundEntry *sound)
{
- assert(fe != NULL);
+ assert(sound != NULL);
- if (fe->file_size == 0) return false;
+ if (sound->file_size == 0) return false;
- int8 *mem = MallocT<int8>(fe->file_size);
+ int8 *mem = MallocT<int8>(sound->file_size);
- FioSeekToFile(fe->file_slot, fe->file_offset);
- FioReadBlock(mem, fe->file_size);
+ FioSeekToFile(sound->file_slot, sound->file_offset);
+ FioReadBlock(mem, sound->file_size);
- for (uint i = 0; i != fe->file_size; i++) {
+ for (uint i = 0; i != sound->file_size; i++) {
mem[i] += -128; // Convert unsigned sound data to signed
}
- assert(fe->bits_per_sample == 8 && fe->channels == 1 && fe->file_size != 0 && fe->rate != 0);
+ assert(sound->bits_per_sample == 8 && sound->channels == 1 && sound->file_size != 0 && sound->rate != 0);
- MxSetChannelRawSrc(mc, mem, fe->file_size, fe->rate, MX_AUTOFREE);
+ MxSetChannelRawSrc(mc, mem, sound->file_size, sound->rate, MX_AUTOFREE);
return true;
}
@@ -127,16 +127,16 @@ static void StartSound(SoundID sound_id, int panning, uint volume)
{
if (volume == 0) return;
- const FileEntry *fe = GetSound(sound_id);
- if (fe == NULL) return;
+ const SoundEntry *sound = GetSound(sound_id);
+ if (sound == NULL) return;
MixerChannel *mc = MxAllocateChannel();
if (mc == NULL) return;
- if (!SetBankSource(mc, fe)) return;
+ if (!SetBankSource(mc, sound)) return;
/* Apply the sound effect's own volume. */
- volume = (fe->volume * volume) / 128;
+ volume = (sound->volume * volume) / 128;
panning = Clamp(panning, -PANNING_LEVELS, PANNING_LEVELS);
uint left_vol = (volume * PANNING_LEVELS) - (volume * panning);
@@ -178,11 +178,10 @@ static const byte _sound_idx[] = {
void SndCopyToPool()
{
for (uint i = 0; i < ORIGINAL_SAMPLE_COUNT; i++) {
- FileEntry *fe = AllocateFileEntry();
-
- *fe = _original_sounds[_sound_idx[i]];
- fe->volume = _sound_base_vol[i];
- fe->priority = 0;
+ SoundEntry *sound = AllocateSound();
+ *sound = _original_sounds[_sound_idx[i]];
+ sound->volume = _sound_base_vol[i];
+ sound->priority = 0;
}
}
diff --git a/src/sound_type.h b/src/sound_type.h
index 63e9986fc..2ff349030 100644
--- a/src/sound_type.h
+++ b/src/sound_type.h
@@ -15,7 +15,7 @@ struct MusicFileSettings {
bool shuffle;
};
-struct FileEntry {
+struct SoundEntry {
uint8 file_slot;
size_t file_offset;
size_t file_size;