70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
Mix_AllocateChannels(MAXCHAN);
#else
if (FSOUND_GetVersion() < FMOD_VERSION)
fatal("old FMOD dll");
if (!FSOUND_Init(SOUNDFREQ, MAXCHAN, FSOUND_INIT_GLOBALFOCUS)) {
conoutf(@"sound init failed (FMOD): %d", FSOUND_GetError());
nosound = true;
};
#endif
};
void
music(char *name)
{
if (nosound)
return;
stopsound();
if (soundvol && musicvol) {
string sn;
strcpy_s(sn, "packages/");
strcat_s(sn, name);
#ifdef USE_MIXER
if (mod = Mix_LoadMUS(path(sn))) {
Mix_PlayMusic(mod, -1);
Mix_VolumeMusic((musicvol * MAXVOL) / 255);
};
#else
if (mod = FMUSIC_LoadSong(path(sn))) {
FMUSIC_PlaySong(mod);
FMUSIC_SetMasterVolume(mod, musicvol);
} else if (stream = FSOUND_Stream_Open(
path(sn), FSOUND_LOOP_NORMAL, 0, 0)) {
int chan = FSOUND_Stream_Play(FSOUND_FREE, stream);
if (chan >= 0) {
FSOUND_SetVolume(
chan, (musicvol * MAXVOL) / 255);
FSOUND_SetPaused(chan, false);
};
} else {
conoutf(@"could not play music: %s", sn);
};
#endif
};
}
COMMAND(music, ARG_1CSTR)
#ifdef USE_MIXER
vector<Mix_Chunk *> samples;
#else
vector<FSOUND_SAMPLE *> samples;
#endif
cvector snames;
int
registersound(char *name)
{
loopv(snames) if (strcmp(snames[i], name) == 0) return i;
snames.add(newstring(name));
samples.add(NULL);
return samples.length() - 1;
};
COMMAND(registersound, ARG_1EST)
void
cleansound()
{
if (nosound)
return;
|
<
>
<
|
>
|
>
|
|
|
|
|
|
<
>
|
|
|
|
|
>
|
|
|
|
|
<
>
|
|
<
>
<
|
|
>
|
<
|
|
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
Mix_AllocateChannels(MAXCHAN);
#else
if (FSOUND_GetVersion() < FMOD_VERSION)
fatal("old FMOD dll");
if (!FSOUND_Init(SOUNDFREQ, MAXCHAN, FSOUND_INIT_GLOBALFOCUS)) {
conoutf(@"sound init failed (FMOD): %d", FSOUND_GetError());
nosound = true;
}
#endif
}
void
music(OFString *name)
{
if (nosound)
return;
stopsound();
if (soundvol && musicvol) {
@autoreleasepool {
string sn;
strcpy_s(sn, "packages/");
strcat_s(sn, name.UTF8String);
#ifdef USE_MIXER
if (mod = Mix_LoadMUS(path(sn))) {
Mix_PlayMusic(mod, -1);
Mix_VolumeMusic((musicvol * MAXVOL) / 255);
}
#else
if (mod = FMUSIC_LoadSong(path(sn))) {
FMUSIC_PlaySong(mod);
FMUSIC_SetMasterVolume(mod, musicvol);
} else if (stream = FSOUND_Stream_Open(
path(sn), FSOUND_LOOP_NORMAL, 0, 0)) {
int chan =
FSOUND_Stream_Play(FSOUND_FREE, stream);
if (chan >= 0) {
FSOUND_SetVolume(
chan, (musicvol * MAXVOL) / 255);
FSOUND_SetPaused(chan, false);
}
} else {
conoutf(@"could not play music: %s", sn);
}
#endif
}
}
}
COMMAND(music, ARG_1STR)
#ifdef USE_MIXER
vector<Mix_Chunk *> samples;
#else
vector<FSOUND_SAMPLE *> samples;
#endif
cvector snames;
int
registersound(char *name)
{
loopv(snames) if (strcmp(snames[i], name) == 0) return i;
snames.add(newstring(name));
samples.add(NULL);
return samples.length() - 1;
}
COMMAND(registersound, ARG_1EST)
void
cleansound()
{
if (nosound)
return;
|
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
vol -= (int)(dist * 3 * soundvol /
255); // simple mono distance attenuation
if (stereo && (v.x != 0 || v.y != 0)) {
float yaw = -atan2(v.x, v.y) -
player1->yaw *
(PI / 180.0f); // relative angle of
// sound along X-Y axis
pan = int(
255.9f *
(0.5 * sin(yaw) +
0.5f)); // range is from 0 (left) to 255 (right)
};
};
vol = (vol * MAXVOL) / 255;
#ifdef USE_MIXER
Mix_Volume(chan, vol);
Mix_SetPanning(chan, 255 - pan, pan);
#else
|
<
<
|
|
>
|
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
vol -= (int)(dist * 3 * soundvol /
255); // simple mono distance attenuation
if (stereo && (v.x != 0 || v.y != 0)) {
float yaw = -atan2(v.x, v.y) -
player1->yaw *
(PI / 180.0f); // relative angle of
// sound along X-Y axis
pan = int(255.9f * (0.5 * sin(yaw) +
0.5f)); // range is from 0 (left)
// to 255 (right)
};
};
vol = (vol * MAXVOL) / 255;
#ifdef USE_MIXER
Mix_Volume(chan, vol);
Mix_SetPanning(chan, 255 - pan, pan);
#else
|
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
|
return;
if (lastmillis == lastsoundmillis)
soundsatonce++;
else
soundsatonce = 1;
lastsoundmillis = lastmillis;
if (soundsatonce > 5)
return; // avoid bursts of sounds with heavy packetloss and in
// sp
if (n < 0 || n >= samples.length()) {
conoutf(@"unregistered sound: %d", n);
return;
};
if (!samples[n]) {
sprintf_sd(buf)("packages/sounds/%s.wav", snames[n]);
|
|
|
|
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
|
return;
if (lastmillis == lastsoundmillis)
soundsatonce++;
else
soundsatonce = 1;
lastsoundmillis = lastmillis;
if (soundsatonce > 5)
return; // avoid bursts of sounds with heavy packetloss
// and in sp
if (n < 0 || n >= samples.length()) {
conoutf(@"unregistered sound: %d", n);
return;
};
if (!samples[n]) {
sprintf_sd(buf)("packages/sounds/%s.wav", snames[n]);
|