130 OpenBankFile(filename); |
132 OpenBankFile(filename); |
131 return true; |
133 return true; |
132 } |
134 } |
133 |
135 |
134 // Low level sound player |
136 // Low level sound player |
135 static void StartSound(uint sound, uint panning, uint volume) |
137 static void StartSound(uint sound, int panning, uint volume) |
136 { |
138 { |
137 MixerChannel* mc; |
139 MixerChannel* mc; |
|
140 uint left_vol, right_vol; |
138 |
141 |
139 if (volume == 0) return; |
142 if (volume == 0) return; |
140 mc = MxAllocateChannel(_mixer); |
143 mc = MxAllocateChannel(_mixer); |
141 if (mc == NULL) return; |
144 if (mc == NULL) return; |
142 if (!SetBankSource(mc, sound)) return; |
145 if (!SetBankSource(mc, sound)) return; |
143 MxSetChannelVolume(mc, volume << 8, volume << 8); |
146 |
|
147 panning = clamp(panning, -PANNING_LEVELS, PANNING_LEVELS); |
|
148 left_vol = (volume * PANNING_LEVELS) - (volume * panning); |
|
149 right_vol = (volume * PANNING_LEVELS) + (volume * panning); |
|
150 MxSetChannelVolume(mc, left_vol * 128 / PANNING_LEVELS, right_vol * 128 / PANNING_LEVELS); |
144 MxActivateChannel(mc); |
151 MxActivateChannel(mc); |
145 } |
152 } |
146 |
153 |
147 |
154 |
148 static const byte _vol_factor_by_zoom[] = {255, 190, 134}; |
155 static const byte _vol_factor_by_zoom[] = {255, 190, 134}; |
183 const ViewPort* vp = w->viewport; |
190 const ViewPort* vp = w->viewport; |
184 |
191 |
185 if (vp != NULL && |
192 if (vp != NULL && |
186 IS_INSIDE_1D(x, vp->virtual_left, vp->virtual_width) && |
193 IS_INSIDE_1D(x, vp->virtual_left, vp->virtual_width) && |
187 IS_INSIDE_1D(y, vp->virtual_top, vp->virtual_height)) { |
194 IS_INSIDE_1D(y, vp->virtual_top, vp->virtual_height)) { |
188 int left = ((x - vp->virtual_left) >> vp->zoom) + vp->left; |
195 int left = (x - vp->virtual_left); |
189 |
196 |
190 StartSound( |
197 StartSound( |
191 _sound_idx[sound], |
198 _sound_idx[sound], |
192 clamp(left / 71, 0, 8), |
199 left / (vp->virtual_width / ((PANNING_LEVELS << 1) + 1)) - PANNING_LEVELS, |
193 (_sound_base_vol[sound] * msf.effect_vol * _vol_factor_by_zoom[vp->zoom]) >> 15 |
200 (_sound_base_vol[sound] * msf.effect_vol * _vol_factor_by_zoom[vp->zoom]) >> 15 |
194 ); |
201 ); |
195 return; |
202 return; |
196 } |
203 } |
197 } |
204 } |