21 #define SET_TYPE "sounds" 
   28 static void OpenBankFile(
const char *filename)
 
   30   memset(_original_sounds, 0, 
sizeof(_original_sounds));
 
   33   if (filename == NULL) 
return;
 
   40   bool new_format = 
HasBit(count, 31);
 
   49     DEBUG(misc, 6, 
"Incorrect number of sounds in '%s', ignoring.", filename);
 
   69     if (new_format || strcmp(name, 
"Corrupt sound") != 0) {
 
   81           if (!new_format) sound->rate = 11025;   
 
   85           FioSeekTo(size - (2 + 2 + 4 + 4 + 2 + 1), SEEK_CUR);
 
   86         } 
else if (tag == 
'atad') {
 
   87           sound->file_size = size;
 
  104       sound->bits_per_sample = 8;
 
  113   assert(sound != NULL);
 
  116   if (sound->file_size == 0 || sound->file_size > ((
size_t)-1) - 2) 
return false;
 
  118   int8 *mem = MallocT<int8>(sound->file_size + 2);
 
  121   mem[sound->file_size    ] = 0;
 
  122   mem[sound->file_size + 1] = 0;
 
  128   if (sound->bits_per_sample == 8) {
 
  129     for (uint i = 0; i != sound->file_size; i++) {
 
  134 #if TTD_ENDIAN == TTD_BIG_ENDIAN 
  135   if (sound->bits_per_sample == 16) {
 
  136     uint num_samples = sound->file_size / 2;
 
  137     int16 *samples = (int16 *)mem;
 
  138     for (uint i = 0; i < num_samples; i++) {
 
  139       samples[i] = 
BSWAP16(samples[i]);
 
  144   assert(sound->bits_per_sample == 8 || sound->bits_per_sample == 16);
 
  145   assert(sound->channels == 1);
 
  146   assert(sound->file_size != 0 && sound->rate != 0);
 
  148   MxSetChannelRawSrc(mc, mem, sound->file_size, sound->rate, sound->bits_per_sample == 16);
 
  153 void InitializeSound()
 
  155   DEBUG(misc, 1, 
"Loading sound effects...");
 
  160 static void StartSound(SoundID sound_id, 
float pan, uint volume)
 
  162   if (volume == 0) 
return;
 
  165   if (sound == NULL) 
return;
 
  168   if (sound->rate == 0 && sound->file_slot != 0) {
 
  171       sound->file_slot = 0;
 
  177   if (sound->rate == 0) 
return;
 
  180   if (mc == NULL) 
return;
 
  182   if (!SetBankSource(mc, sound)) 
return;
 
  185   volume = sound->volume * volume;
 
  188   MxActivateChannel(mc);
 
  192 static const byte _vol_factor_by_zoom[] = {255, 255, 255, 190, 134, 87};
 
  195 static const byte _sound_base_vol[] = {
 
  196   128,  90, 128, 128, 128, 128, 128, 128,
 
  197   128,  90,  90, 128, 128, 128, 128, 128,
 
  198   128, 128, 128,  80, 128, 128, 128, 128,
 
  199   128, 128, 128, 128, 128, 128, 128, 128,
 
  200   128, 128,  90,  90,  90, 128,  90, 128,
 
  201   128,  90, 128, 128, 128,  90, 128, 128,
 
  202   128, 128, 128, 128,  90, 128, 128, 128,
 
  203   128,  90, 128, 128, 128, 128, 128, 128,
 
  204   128, 128,  90,  90,  90, 128, 128, 128,
 
  208 static const byte _sound_idx[] = {
 
  209    2,  3,  4,  5,  6,  7,  8,  9,
 
  210   10, 11, 12, 13, 14, 15, 16, 17,
 
  211   18, 19, 20, 21, 22, 23, 24, 25,
 
  212   26, 27, 28, 29, 30, 31, 32, 33,
 
  213   34, 35, 36, 37, 38, 39, 40,  0,
 
  214    1, 41, 42, 43, 44, 45, 46, 47,
 
  215   48, 49, 50, 51, 52, 53, 54, 55,
 
  216   56, 57, 58, 59, 60, 61, 62, 63,
 
  217   64, 65, 66, 67, 68, 69, 70, 71,
 
  225     sound[i] = _original_sounds[_sound_idx[i]];
 
  226     sound[i].volume = _sound_base_vol[i];
 
  227     sound[i].priority = 0;
 
  244   FOR_ALL_WINDOWS_FROM_BACK(w) {
 
  252       float panning = (float)screen_x / width;
 
  264 void SndPlayTileFx(SoundID sound, 
TileIndex tile)
 
  269   int z = (y < 0 ? 0 : GetSlopePixelZ(x, y));
 
  276 void SndPlayVehicleFx(SoundID sound, 
const Vehicle *v)
 
  284 void SndPlayFx(SoundID sound)
 
  295 template <
class T, 
size_t Tnum_files, 
bool Tsearch_in_tars>
 
  298 template <
class Tbase_set>
 
  304 template <
class Tbase_set>
 
  309   const Tbase_set *best = NULL;
 
  312     if (c->GetNumMissing() != 0) 
continue;
 
  315         (best->fallback && !c->fallback) ||
 
  316         best->valid_files < c->valid_files ||
 
  317         (best->valid_files == c->valid_files &&
 
  318           (best->shortname == c->shortname && best->version < c->version))) {