Ticket #8124: Dig_mixer_patch.diff

File Dig_mixer_patch.diff, 2.2 KB (added by SF/arisme, 18 years ago)

Patch for "bad play sound in stream(wrap around)" in The Dig

Line 
1diff -u -r1.26 mixer.cpp
2--- mixer.cpp 10 Nov 2002 17:01:51 -0000 1.26
3+++ mixer.cpp 12 Nov 2002 23:59:42 -0000
4@@ -578,6 +578,13 @@
5 mix_signed_stereo_16, mix_unsigned_stereo_16
6 };
7
8+static int16 mixer_element_size[] = {
9+ 1, 1,
10+ 2, 2,
11+ 2, 2,
12+ 4, 4
13+};
14+
15 void SoundMixer::ChannelRaw::mix(int16 * data, uint len) {
16 byte *s, *s_org = NULL;
17 uint32 fp_pos;
18@@ -648,12 +655,14 @@
19 delete this;
20 }
21
22+#define WARP_WORKAROUND 50000
23+
24 SoundMixer::ChannelStream::ChannelStream(SoundMixer * mixer, void * sound, uint
2532 size, uint rate,
26
27byte flags, int32 timeout, int32 buffer_size) {
28 _mixer = mixer;
29 _flags = flags;
30 _bufferSize = buffer_size;
31- _ptr = (byte *)malloc(_bufferSize);
32+ _ptr = (byte *)malloc(_bufferSize + WARP_WORKAROUND);
33 memcpy(_ptr, sound, size);
34 _endOfData = _ptr + size;
35 _endOfBuffer = _ptr + _bufferSize;
36@@ -722,7 +731,23 @@
37 if (_pos < end_of_data) {
38 mixer_helper_table[_flags & 0x07] (data, &len, &_pos, &fp_pos, f
39p_speed, vol_tab, end_of_data, (_flags & FLAG_REVERSE_STEREO) ? true : false);
40 } else {
41- mixer_helper_table[_flags & 0x07] (data, &len, &_pos, &fp_pos, f
42p_speed, vol_tab, _endOfBuffer, (_flags & FLAG_REVERSE_STEREO) ? true : false);
43+ int wrap_offset = 0;
44+
45+ // see if we will wrap
46+ if (_pos + (mixer_element_size[_flags & 0x07] * len) > _endOfBuf
47fer) {
48+ wrap_offset = _pos + (mixer_element_size[_flags & 0x07]
49* len) - _endOfBuffer;
50+ debug(9, "using wrap workaround for %d bytes", wrap_offs
51et);
52+ memcpy(_endOfBuffer, _ptr, wrap_offset);
53+ }
54+
55+
56+ mixer_helper_table[_flags & 0x07] (data, &len, &_pos, &fp_pos, f
57p_speed, vol_tab, _endOfBuffer + wrap_offset, (_flags & FLAG_REVERSE_STEREO) ? t
58rue : false);
59+
60+ // recover from wrap
61+ if (wrap_offset)
62+ _pos = _ptr + wrap_offset;
63+
64+ // shouldn't happen anymore
65 if (len != 0) {
66 //FIXME: what is wrong ?
67 warning("bad play sound in stream(wrap around)");