1
0
Fork 0

(svn r16344) -Codechange: s/FileEntry/SoundEntry/

release/1.0
rubidium 2009-05-17 19:27:50 +00:00
parent ceca68fca7
commit 4a04dfc07c
5 changed files with 64 additions and 65 deletions

View File

@ -2042,11 +2042,11 @@ static ChangeInfoResult SoundEffectChangeInfo(uint sid, int numinfo, int prop, b
if (orig_sound >= ORIGINAL_SAMPLE_COUNT) { if (orig_sound >= ORIGINAL_SAMPLE_COUNT) {
grfmsg(1, "SoundEffectChangeInfo: Original sound %d not defined (max %d)", orig_sound, ORIGINAL_SAMPLE_COUNT); grfmsg(1, "SoundEffectChangeInfo: Original sound %d not defined (max %d)", orig_sound, ORIGINAL_SAMPLE_COUNT);
} else { } else {
FileEntry *newfe = GetSound(sound); SoundEntry *new_sound = GetSound(sound);
FileEntry *oldfe = GetSound(orig_sound); SoundEntry *old_sound = GetSound(orig_sound);
/* Literally copy the data of the new sound over the original */ /* Literally copy the data of the new sound over the original */
*oldfe = *newfe; *old_sound = *new_sound;
} }
} break; } break;
@ -5051,9 +5051,9 @@ static void SkipAct11(byte *buf, size_t len)
static void ImportGRFSound(byte *buf, int len) static void ImportGRFSound(byte *buf, int len)
{ {
const GRFFile *file; const GRFFile *file;
FileEntry *se = AllocateFileEntry(); SoundEntry *sound = AllocateSound();
uint32 grfid = grf_load_dword(&buf); uint32 grfid = grf_load_dword(&buf);
uint16 sound = grf_load_word(&buf); SoundID sound_id = grf_load_word(&buf);
file = GetFileByGRFID(grfid); file = GetFileByGRFID(grfid);
if (file == NULL || file->sound_offset == 0) { if (file == NULL || file->sound_offset == 0) {
@ -5061,18 +5061,18 @@ static void ImportGRFSound(byte *buf, int len)
return; return;
} }
if (file->sound_offset + sound >= GetNumSounds()) { if (file->sound_offset + sound_id >= GetNumSounds()) {
grfmsg(1, "ImportGRFSound: Sound effect %d is invalid", sound); grfmsg(1, "ImportGRFSound: Sound effect %d is invalid", sound_id);
return; 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 */ /* Reset volume and priority, which TTDPatch doesn't copy */
se->volume = 128; sound->volume = 128;
se->priority = 0; sound->priority = 0;
} }
/* 'Action 0xFE' */ /* '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 /* Allocate a sound entry. This is done even if the data is not loaded
* so that the indices used elsewhere are still correct. */ * so that the indices used elsewhere are still correct. */
FileEntry *se = AllocateFileEntry(); SoundEntry *sound = AllocateSound();
if (grf_load_dword(&buf) != BSWAP32('RIFF')) { if (grf_load_dword(&buf) != BSWAP32('RIFF')) {
grfmsg(1, "LoadGRFSound: Missing RIFF header"); grfmsg(1, "LoadGRFSound: Missing RIFF header");
@ -5131,30 +5131,30 @@ static void LoadGRFSound(byte *buf, int len)
grfmsg(1, "LoadGRFSound: Invalid audio format"); grfmsg(1, "LoadGRFSound: Invalid audio format");
return; return;
} }
se->channels = grf_load_word(&buf); sound->channels = grf_load_word(&buf);
se->rate = grf_load_dword(&buf); sound->rate = grf_load_dword(&buf);
grf_load_dword(&buf); grf_load_dword(&buf);
grf_load_word(&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 */ /* Consume any extra bytes */
for (; size > 16; size--) grf_load_byte(&buf); for (; size > 16; size--) grf_load_byte(&buf);
break; break;
case 'atad': // 'data' case 'atad': // 'data'
se->file_size = size; sound->file_size = size;
se->file_offset = FioGetPos() - (len - (buf - buf_start)) + 1; sound->file_offset = FioGetPos() - (len - (buf - buf_start)) + 1;
se->file_slot = _file_index; sound->file_slot = _file_index;
/* Set default volume and priority */ /* Set default volume and priority */
se->volume = 0x80; sound->volume = 0x80;
se->priority = 0; 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; return;
default: default:
se->file_size = 0; sound->file_size = 0;
return; return;
} }
} }

View File

@ -10,11 +10,11 @@
#include "sound_func.h" #include "sound_func.h"
static uint _sound_count = 0; 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 */ /* Allocate a new Sound */
FileEntry *AllocateFileEntry() SoundEntry *AllocateSound()
{ {
if (_sound_count == GetSoundInternalPoolSize()) { if (_sound_count == GetSoundInternalPoolSize()) {
if (!_SoundInternal_pool.AddBlockToPool()) return NULL; 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; if (index >= GetNumSounds()) return NULL;
return GetSoundInternal(index); return GetSoundInternal(index);
@ -62,16 +62,16 @@ bool PlayVehicleSound(const Vehicle *v, VehicleSoundEvent event)
if (callback == CALLBACK_FAILED) return false; if (callback == CALLBACK_FAILED) return false;
if (callback >= ORIGINAL_SAMPLE_COUNT) callback += file->sound_offset - ORIGINAL_SAMPLE_COUNT; 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; 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 >= ORIGINAL_SAMPLE_COUNT) sound_id += file->sound_offset - ORIGINAL_SAMPLE_COUNT;
if (sound_id < GetNumSounds()) { if (sound_id < GetNumSounds()) {
SndPlayTileFx((SoundFx)sound_id, tile); SndPlayTileFx(sound_id, tile);
return true; return true;
} }
return false; return false;

View File

@ -21,9 +21,9 @@ enum VehicleSoundEvent {
}; };
FileEntry *AllocateFileEntry(); SoundEntry *AllocateSound();
void InitializeSoundPool(); void InitializeSoundPool();
FileEntry *GetSound(SoundID sound_id); SoundEntry *GetSound(SoundID sound_id);
uint GetNumSounds(); uint GetNumSounds();
bool PlayVehicleSound(const Vehicle *v, VehicleSoundEvent event); bool PlayVehicleSound(const Vehicle *v, VehicleSoundEvent event);
bool PlayTileSound(const struct GRFFile *file, SoundID sound_id, TileIndex tile); bool PlayTileSound(const struct GRFFile *file, SoundID sound_id, TileIndex tile);

View File

@ -13,7 +13,7 @@
#include "vehicle_base.h" #include "vehicle_base.h"
#include "debug.h" #include "debug.h"
static FileEntry _original_sounds[ORIGINAL_SAMPLE_COUNT]; static SoundEntry _original_sounds[ORIGINAL_SAMPLE_COUNT];
MusicFileSettings msf; MusicFileSettings msf;
/* Number of levels of panning per side */ /* 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++) { for (uint i = 0; i != ORIGINAL_SAMPLE_COUNT; i++) {
FileEntry *fe = &_original_sounds[i]; SoundEntry *sound = &_original_sounds[i];
char name[255]; char name[255];
FioSeekTo(fe->file_offset, SEEK_SET); FioSeekTo(sound->file_offset, SEEK_SET);
/* Check for special case, see else case */ /* Check for special case, see else case */
FioReadBlock(name, FioReadByte()); // Read the name of the sound FioReadBlock(name, FioReadByte()); // Read the name of the sound
@ -62,20 +62,20 @@ static void OpenBankFile(const char *filename)
if (tag == ' tmf') { if (tag == ' tmf') {
FioReadWord(); // wFormatTag FioReadWord(); // wFormatTag
fe->channels = FioReadWord(); // wChannels sound->channels = FioReadWord(); // wChannels
FioReadDword(); // samples per second 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 FioReadDword(); // avg bytes per second
FioReadWord(); // alignment 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); FioSeekTo(size - (2 + 2 + 4 + 4 + 2 + 1), SEEK_CUR);
} else if (tag == 'atad') { } else if (tag == 'atad') {
fe->file_size = size; sound->file_size = size;
fe->file_slot = SOUND_SLOT; sound->file_slot = SOUND_SLOT;
fe->file_offset = FioGetPos(); sound->file_offset = FioGetPos();
break; break;
} else { } else {
fe->file_size = 0; sound->file_size = 0;
break; break;
} }
} }
@ -85,33 +85,33 @@ static void OpenBankFile(const char *filename)
* (name in sample.cat is "Corrupt sound") * (name in sample.cat is "Corrupt sound")
* It's no RIFF file, but raw PCM data * It's no RIFF file, but raw PCM data
*/ */
fe->channels = 1; sound->channels = 1;
fe->rate = 11025; sound->rate = 11025;
fe->bits_per_sample = 8; sound->bits_per_sample = 8;
fe->file_slot = SOUND_SLOT; sound->file_slot = SOUND_SLOT;
fe->file_offset = FioGetPos(); 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); FioSeekToFile(sound->file_slot, sound->file_offset);
FioReadBlock(mem, fe->file_size); 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 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; return true;
} }
@ -127,16 +127,16 @@ static void StartSound(SoundID sound_id, int panning, uint volume)
{ {
if (volume == 0) return; if (volume == 0) return;
const FileEntry *fe = GetSound(sound_id); const SoundEntry *sound = GetSound(sound_id);
if (fe == NULL) return; if (sound == NULL) return;
MixerChannel *mc = MxAllocateChannel(); MixerChannel *mc = MxAllocateChannel();
if (mc == NULL) return; if (mc == NULL) return;
if (!SetBankSource(mc, fe)) return; if (!SetBankSource(mc, sound)) return;
/* Apply the sound effect's own volume. */ /* Apply the sound effect's own volume. */
volume = (fe->volume * volume) / 128; volume = (sound->volume * volume) / 128;
panning = Clamp(panning, -PANNING_LEVELS, PANNING_LEVELS); panning = Clamp(panning, -PANNING_LEVELS, PANNING_LEVELS);
uint left_vol = (volume * PANNING_LEVELS) - (volume * panning); uint left_vol = (volume * PANNING_LEVELS) - (volume * panning);
@ -178,11 +178,10 @@ static const byte _sound_idx[] = {
void SndCopyToPool() void SndCopyToPool()
{ {
for (uint i = 0; i < ORIGINAL_SAMPLE_COUNT; i++) { for (uint i = 0; i < ORIGINAL_SAMPLE_COUNT; i++) {
FileEntry *fe = AllocateFileEntry(); SoundEntry *sound = AllocateSound();
*sound = _original_sounds[_sound_idx[i]];
*fe = _original_sounds[_sound_idx[i]]; sound->volume = _sound_base_vol[i];
fe->volume = _sound_base_vol[i]; sound->priority = 0;
fe->priority = 0;
} }
} }

View File

@ -15,7 +15,7 @@ struct MusicFileSettings {
bool shuffle; bool shuffle;
}; };
struct FileEntry { struct SoundEntry {
uint8 file_slot; uint8 file_slot;
size_t file_offset; size_t file_offset;
size_t file_size; size_t file_size;