|
71 | 71 | //e6y
|
72 | 72 | #include "e6y.h"
|
73 | 73 |
|
| 74 | +#include "dsda/ambient.h" |
74 | 75 | #include "dsda/settings.h"
|
75 | 76 |
|
76 | 77 | static dboolean registered_non_rw = false;
|
@@ -195,7 +196,7 @@ static Uint8 *ConvertAudioFormat(void **data, SDL_AudioSpec *sample, Uint32 *len
|
195 | 196 | typedef struct snd_data_s
|
196 | 197 | {
|
197 | 198 | int sfxid;
|
198 |
| - const unsigned char *data; |
| 199 | + unsigned char *data; |
199 | 200 | int samplelen;
|
200 | 201 | int samplerate;
|
201 | 202 | struct snd_data_s *next;
|
@@ -264,6 +265,58 @@ static snd_data_t *GetSndData(int sfxid, const unsigned char *data, size_t len)
|
264 | 265 | return target;
|
265 | 266 | }
|
266 | 267 |
|
| 268 | +#define FADETIME 1000 // microseconds |
| 269 | + |
| 270 | +static void FadeInOutMono16(short *data, int len, int rate) |
| 271 | +{ |
| 272 | + const int fadelen = rate * FADETIME / 1000000; |
| 273 | + int i; |
| 274 | + |
| 275 | + if (len < fadelen) |
| 276 | + return; |
| 277 | + |
| 278 | + if (data[0] != 0) |
| 279 | + { |
| 280 | + for (i = 0; i < fadelen; i++) |
| 281 | + { |
| 282 | + data[i] = data[i] * i / fadelen; |
| 283 | + } |
| 284 | + } |
| 285 | + |
| 286 | + if (data[len - 1] != 0) |
| 287 | + { |
| 288 | + for (i = 0; i < fadelen; i++) |
| 289 | + { |
| 290 | + data[len - 1 - i] = data[len - 1 - i] * i / fadelen; |
| 291 | + } |
| 292 | + } |
| 293 | +} |
| 294 | + |
| 295 | +static void FadeInOutMono8(byte *data, int len, int rate) |
| 296 | +{ |
| 297 | + const int fadelen = rate * FADETIME / 1000000; |
| 298 | + int i; |
| 299 | + |
| 300 | + if (len < fadelen) |
| 301 | + return; |
| 302 | + |
| 303 | + if (data[0] != 128) |
| 304 | + { |
| 305 | + for (i = 0; i < fadelen; i++) |
| 306 | + { |
| 307 | + data[i] = (data[i] - 128) * i / fadelen + 128; |
| 308 | + } |
| 309 | + } |
| 310 | + |
| 311 | + if (data[len - 1] != 128) |
| 312 | + { |
| 313 | + for (i = 0; i < fadelen; i++) |
| 314 | + { |
| 315 | + data[len - 1 - i] = (data[len - 1 - i] - 128) * i / fadelen + 128; |
| 316 | + } |
| 317 | + } |
| 318 | +} |
| 319 | + |
267 | 320 | #define DMXHDRSIZE 8
|
268 | 321 | #define DMXPADSIZE 16
|
269 | 322 |
|
@@ -301,8 +354,29 @@ void I_CacheSounds(void)
|
301 | 354 | const byte *data = W_LumpByNum(lump);
|
302 | 355 | int len = W_LumpLength(lump);
|
303 | 356 |
|
304 |
| - if (!IsDMXSound(data, len)) |
305 |
| - GetSndData(id, data, len); |
| 357 | + if (IsDMXSound(data, len)) |
| 358 | + { |
| 359 | + int dmx_len = GetDMXLength(data); |
| 360 | + |
| 361 | + if (IsValidDMXSound(dmx_len, len) && !dsda_IsLoopingAmbientSFX(id)) |
| 362 | + { |
| 363 | + const int dmx_rate = GetDMXSampleRate(data); |
| 364 | + byte *dmx_data = W_GetModifiableLumpData(lump); |
| 365 | + dmx_data = &dmx_data[DMXHDRSIZE + DMXPADSIZE]; |
| 366 | + dmx_len -= DMXPADSIZE * 2; |
| 367 | + FadeInOutMono8(dmx_data, dmx_len, dmx_rate); |
| 368 | + } |
| 369 | + } |
| 370 | + else |
| 371 | + { |
| 372 | + snd_data_t *snd_data = GetSndData(id, data, len); |
| 373 | + |
| 374 | + if (snd_data && !dsda_IsLoopingAmbientSFX(id)) |
| 375 | + { |
| 376 | + len = snd_data->samplelen / sizeof(short); |
| 377 | + FadeInOutMono16((short *)snd_data->data, len, snd_data->samplerate); |
| 378 | + } |
| 379 | + } |
306 | 380 | }
|
307 | 381 | }
|
308 | 382 | }
|
|
0 commit comments