Ticket #7905: multiple_sound_sfx_patch

File multiple_sound_sfx_patch, 3.0 KB (added by SF/japj, 20 years ago)

multiple sound fx patch

Line 
1Index: sdl.cpp
2===================================================================
3RCS file: /cvsroot/scummvm/scummvm/sdl.cpp,v
4retrieving revision 1.16
5diff -u -r1.16 sdl.cpp
6--- sdl.cpp 2001/11/06 20:00:47 1.16
7+++ sdl.cpp 2001/11/09 18:44:58
8@@ -466,6 +466,17 @@
9 #define BUFFER_SIZE (8192)
10 #define BITS_PER_SAMPLE 16
11
12+#define MAX_SFX 16
13+
14+struct {
15+ //bool _playing;
16+ void *_sfx_sound;
17+ uint32 _sfx_pos;
18+ uint32 _sfx_size;
19+ uint32 _sfx_fp_speed;
20+ uint32 _sfx_fp_pos;
21+} _sfx_sounds[MAX_SFX];
22+
23 static void *_sfx_sound;
24 static uint32 _sfx_pos;
25 static uint32 _sfx_size;
26@@ -478,6 +489,35 @@
27 }
28
29 void playSfxSound(void *sound, uint32 size, uint rate) {
30+
31+ int sfx_pos=0;
32+ while (sfx_pos<MAX_SFX)
33+ {
34+ if (!_sfx_sounds[sfx_pos]._sfx_size)
35+ {
36+ if (_sfx_sounds[sfx_pos]._sfx_sound)
37+ free(_sfx_sounds[sfx_pos]._sfx_sound);
38+ break;
39+ }
40+ sfx_pos++;
41+ }
42+
43+ if (sfx_pos<MAX_SFX)
44+ {
45+ _sfx_sounds[sfx_pos]._sfx_sound = sound;
46+ _sfx_sounds[sfx_pos]._sfx_pos = 0;
47+ _sfx_sounds[sfx_pos]._sfx_fp_speed = (1<<16) * rate / 22050;
48+ _sfx_sounds[sfx_pos]._sfx_fp_pos = 0;
49+
50+ while (size&0xFFFF0000) size>>=1, rate>>=1;
51+ _sfx_sounds[sfx_pos]._sfx_size = size * 22050 / rate;
52+ //_sfx_sounds[sfx_pos]._playing=true;
53+ }
54+ else
55+ {
56+ warning("playSFXSound trying to play more sfx then MAX_SFX");
57+ }
58+/*
59 if (_sfx_sound) {
60 free(_sfx_sound);
61 }
62@@ -489,6 +529,7 @@
63
64 while (size&0xFFFF0000) size>>=1, rate>>=1;
65 _sfx_size = size * 22050 / rate;
66+*/
67 }
68
69 void mix_sound(int16 *data, uint32 len) {
70@@ -496,6 +537,37 @@
71 int i;
72 uint32 fp_pos, fp_speed;
73
74+ if (!data) return;
75+
76+ for (int cur_sfx=0;cur_sfx<MAX_SFX;cur_sfx++)
77+ {
78+ if (_sfx_sounds[cur_sfx]._sfx_size)
79+ {
80+ int16 *mix_data=data;
81+ uint32 mix_len=len;
82+ if (mix_len > _sfx_sounds[cur_sfx]._sfx_size)
83+ mix_len = _sfx_sounds[cur_sfx]._sfx_size;
84+
85+ _sfx_sounds[cur_sfx]._sfx_size -= mix_len;
86+
87+ s = (int8*)_sfx_sounds[cur_sfx]._sfx_sound + _sfx_sounds[cur_sfx]._sfx_pos;
88+ fp_pos = _sfx_sounds[cur_sfx]._sfx_fp_pos;
89+ fp_speed = _sfx_sounds[cur_sfx]._sfx_fp_speed;
90+
91+ do {
92+ fp_pos += fp_speed;
93+ *mix_data++ += (*s<<6);
94+ s += fp_pos >> 16;
95+ fp_pos &= 0x0000FFFF;
96+ } while (--mix_len);
97+
98+ _sfx_sounds[cur_sfx]._sfx_pos = s - (int8*)_sfx_sounds[cur_sfx]._sfx_sound;
99+ _sfx_sounds[cur_sfx]._sfx_fp_speed = fp_speed;
100+ _sfx_sounds[cur_sfx]._sfx_fp_pos = fp_pos;
101+ }
102+ }
103+
104+/*
105 if (!_sfx_size)
106 return;
107 if (len > _sfx_size)
108@@ -516,6 +588,7 @@
109 _sfx_pos = s - (int8*)_sfx_sound;
110 _sfx_fp_speed = fp_speed;
111 _sfx_fp_pos = fp_pos;
112+*/
113 }
114
115 void fill_sound(void *userdata, Uint8 *stream, int len) {
116@@ -542,6 +615,10 @@
117
118 sprintf(buf, "ScummVM - %s", gameName = s->getGameName());
119 free(gameName);
120+ for (int i=0;i<MAX_SFX;i++)
121+ {
122+ _sfx_sounds[i]._sfx_size=0;
123+ }
124
125 desired.freq = SAMPLES_PER_SEC;
126 desired.format = AUDIO_S16SYS;