src/sound.cpp
branchNewGRF_ports
changeset 6872 1c4a4a609f85
parent 6871 5a9dc001e1ad
child 6877 889301acc299
equal deleted inserted replaced
6871:5a9dc001e1ad 6872:1c4a4a609f85
     2 
     2 
     3 /** @file sound.cpp */
     3 /** @file sound.cpp */
     4 
     4 
     5 #include "stdafx.h"
     5 #include "stdafx.h"
     6 #include "openttd.h"
     6 #include "openttd.h"
     7 #include "functions.h"
       
     8 #include "landscape.h"
     7 #include "landscape.h"
     9 #include "map.h"
       
    10 #include "mixer.h"
     8 #include "mixer.h"
    11 #include "sound.h"
     9 #include "sound_func.h"
    12 #include "vehicle.h"
       
    13 #include "window.h"
       
    14 #include "viewport.h"
       
    15 #include "fileio.h"
    10 #include "fileio.h"
    16 #include "newgrf_sound.h"
    11 #include "newgrf_sound.h"
    17 #include "helpers.hpp"
       
    18 #include "fios.h"
    12 #include "fios.h"
       
    13 #include "window_gui.h"
       
    14 #include "core/alloc_func.hpp"
       
    15 #include "map_func.h"
       
    16 #include "vehicle_base.h"
    19 
    17 
    20 static uint _file_count;
    18 static uint _file_count;
    21 static FileEntry *_files;
    19 static FileEntry *_files;
       
    20 MusicFileSettings msf;
    22 
    21 
    23 // Number of levels of panning per side
    22 // Number of levels of panning per side
    24 #define PANNING_LEVELS 16
    23 #define PANNING_LEVELS 16
    25 
    24 
    26 
    25 
   155 	MxActivateChannel(mc);
   154 	MxActivateChannel(mc);
   156 }
   155 }
   157 
   156 
   158 
   157 
   159 static const byte _vol_factor_by_zoom[] = {255, 190, 134, 87};
   158 static const byte _vol_factor_by_zoom[] = {255, 190, 134, 87};
   160 assert_compile(lengthof(_vol_factor_by_zoom) == ZOOM_LVL_END);
   159 assert_compile(lengthof(_vol_factor_by_zoom) == ZOOM_LVL_END - ZOOM_LVL_BEGIN);
   161 
   160 
   162 static const byte _sound_base_vol[] = {
   161 static const byte _sound_base_vol[] = {
   163 	128,  90, 128, 128, 128, 128, 128, 128,
   162 	128,  90, 128, 128, 128, 128, 128, 128,
   164 	128,  90,  90, 128, 128, 128, 128, 128,
   163 	128,  90,  90, 128, 128, 128, 128, 128,
   165 	128, 128, 128,  80, 128, 128, 128, 128,
   164 	128, 128, 128,  80, 128, 128, 128, 128,
   214 			int left = (x - vp->virtual_left);
   213 			int left = (x - vp->virtual_left);
   215 
   214 
   216 			StartSound(
   215 			StartSound(
   217 				sound,
   216 				sound,
   218 				left / max(1, vp->virtual_width / ((PANNING_LEVELS << 1) + 1)) - PANNING_LEVELS,
   217 				left / max(1, vp->virtual_width / ((PANNING_LEVELS << 1) + 1)) - PANNING_LEVELS,
   219 				(GetSound(sound)->volume * msf.effect_vol * _vol_factor_by_zoom[vp->zoom]) >> 15
   218 				(GetSound(sound)->volume * msf.effect_vol * _vol_factor_by_zoom[vp->zoom - ZOOM_LVL_BEGIN]) >> 15
   220 			);
   219 			);
   221 			return;
   220 			return;
   222 		}
   221 		}
   223 	}
   222 	}
   224 
   223