mirror of
https://github.com/nzp-team/glquake.git
synced 2024-11-10 06:31:35 +00:00
Match sound between 3DS and PSP
This commit is contained in:
parent
a8215c6dbe
commit
4cc71152de
2 changed files with 112 additions and 172 deletions
217
source/snd_dma.c
217
source/snd_dma.c
|
@ -21,12 +21,16 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
|
||||
#include "quakedef.h"
|
||||
|
||||
void S_Play(void);
|
||||
void S_PlayVol(void);
|
||||
void S_SoundList(void);
|
||||
|
||||
|
||||
void S_Play_f(void);
|
||||
void S_PlayVol_f(void);
|
||||
void S_SoundList_f(void);
|
||||
void S_Update_();
|
||||
void S_StopAllSounds(qboolean clear);
|
||||
void S_StopAllSoundsC(void);
|
||||
void S_StopAllSoundsC_f(void);
|
||||
void S_VolumeDown_f (void); // Baker 3.60 - from JoeQuake 0.15
|
||||
void S_VolumeUp_f (void); // Baker 3.60 - from JoeQuake 0.15
|
||||
|
||||
// =======================================================================
|
||||
// Internal sound data & structures
|
||||
|
@ -47,13 +51,12 @@ vec3_t listener_origin;
|
|||
vec3_t listener_forward;
|
||||
vec3_t listener_right;
|
||||
vec3_t listener_up;
|
||||
vec_t sound_nominal_clip_dist=1000.0;
|
||||
vec_t sound_nominal_clip_dist=1500.0; // JPG - changed this from 1000 to 15000 (I'm 99% sure that's what it was in 1.06)
|
||||
|
||||
int soundtime; // sample PAIRS
|
||||
int paintedtime; // sample PAIRS
|
||||
|
||||
|
||||
#define MAX_SFX 512
|
||||
sfx_t *known_sfx; // hunk allocated [MAX_SFX]
|
||||
int num_sfx;
|
||||
|
||||
|
@ -65,29 +68,26 @@ int desired_bits = 16;
|
|||
int sound_started=0;
|
||||
|
||||
cvar_t bgmvolume = {"bgmvolume", "1", true};
|
||||
cvar_t bgmtype = {"bgmtype", "cd", true}; // cd or none
|
||||
cvar_t volume = {"volume", "0.7", true};
|
||||
|
||||
cvar_t nosound = {"nosound", "0"};
|
||||
cvar_t precache = {"precache", "1"};
|
||||
cvar_t loadas8bit = {"loadas8bit", "0"};
|
||||
cvar_t bgmbuffer = {"bgmbuffer", "4096"};
|
||||
cvar_t ambient_level = {"ambient_level", "0.3"};
|
||||
cvar_t ambient_level = {"ambient_level", "0.3", true}; // Baker 3.60 - Save to config
|
||||
cvar_t ambient_fade = {"ambient_fade", "100"};
|
||||
cvar_t snd_noextraupdate = {"snd_noextraupdate", "0"};
|
||||
cvar_t snd_show = {"snd_show", "0"};
|
||||
cvar_t _snd_mixahead = {"_snd_mixahead", "0.1", true};
|
||||
|
||||
|
||||
// ====================================================================
|
||||
// User-setable variables
|
||||
// ====================================================================
|
||||
|
||||
|
||||
//
|
||||
// Fake dma is a synchronous faking of the DMA progress used for
|
||||
// isolating performance in the renderer. The fakedma_updates is
|
||||
// number of times S_Update() is called per second.
|
||||
//
|
||||
|
||||
qboolean fakedma = false;
|
||||
int fakedma_updates = 15;
|
||||
|
@ -139,13 +139,9 @@ void S_Startup (void)
|
|||
|
||||
if (!fakedma)
|
||||
{
|
||||
rc = SNDDMA_Init();
|
||||
|
||||
if (!rc)
|
||||
if (!(rc = SNDDMA_Init()))
|
||||
{
|
||||
#ifndef _WIN32
|
||||
Con_Printf("S_Startup: SNDDMA_Init failed.\n");
|
||||
#endif
|
||||
sound_started = 0;
|
||||
return;
|
||||
}
|
||||
|
@ -160,22 +156,24 @@ void S_Startup (void)
|
|||
S_Init
|
||||
================
|
||||
*/
|
||||
void CDAudioSetVolume (void);
|
||||
void S_Init (void)
|
||||
{
|
||||
|
||||
Con_Printf("\nSound Initialization\n");
|
||||
|
||||
if (COM_CheckParm("-nosound"))
|
||||
return;
|
||||
|
||||
Con_Printf("\nSound Initialization\n");
|
||||
|
||||
if (COM_CheckParm("-simsound"))
|
||||
fakedma = true;
|
||||
|
||||
Cmd_AddCommand("play", S_Play);
|
||||
Cmd_AddCommand("playvol", S_PlayVol);
|
||||
Cmd_AddCommand("stopsound", S_StopAllSoundsC);
|
||||
Cmd_AddCommand("soundlist", S_SoundList);
|
||||
Cmd_AddCommand("play", S_Play_f);
|
||||
Cmd_AddCommand("playvol", S_PlayVol_f);
|
||||
Cmd_AddCommand("stopsound", S_StopAllSoundsC_f);
|
||||
Cmd_AddCommand("soundlist", S_SoundList_f);
|
||||
Cmd_AddCommand("soundinfo", S_SoundInfo_f);
|
||||
Cmd_AddCommand ("volumedown", S_VolumeDown_f); // Baker 3.60 - from JoeQuake 0.15
|
||||
Cmd_AddCommand ("volumeup", S_VolumeUp_f); // Baker 3.60 - from JoeQuake 0.15
|
||||
|
||||
Cvar_RegisterVariable(&nosound);
|
||||
Cvar_RegisterVariable(&volume);
|
||||
|
@ -189,14 +187,13 @@ void S_Init (void)
|
|||
Cvar_RegisterVariable(&snd_show);
|
||||
Cvar_RegisterVariable(&_snd_mixahead);
|
||||
|
||||
if (host_parms.memsize < 0x800000)
|
||||
//if (host_parms.memsize < 0x800000)
|
||||
{
|
||||
Cvar_Set ("loadas8bit", "1");
|
||||
Con_Printf ("loading all sounds as 8bit\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
snd_initialized = true;
|
||||
|
||||
S_Startup ();
|
||||
|
@ -223,16 +220,13 @@ void S_Init (void)
|
|||
shm->buffer = Hunk_AllocName(1<<16, "shmbuf");
|
||||
}
|
||||
|
||||
Con_Printf ("Sound sampling rate: %i\n", shm->speed);
|
||||
Con_Printf ("Sound sampling rate: %i Hz\n", shm->speed);
|
||||
|
||||
// provides a tick sound until washed clean
|
||||
|
||||
// if (shm->buffer)
|
||||
// shm->buffer[4] = shm->buffer[5] = 0x7f; // force a pop for debugging
|
||||
|
||||
//ambient_sfx[AMBIENT_WATER] = S_PrecacheSound ("ambience/water1.wav");
|
||||
//ambient_sfx[AMBIENT_SKY] = S_PrecacheSound ("ambience/wind2.wav");
|
||||
|
||||
S_StopAllSounds (true);
|
||||
}
|
||||
|
||||
|
@ -243,7 +237,6 @@ void S_Init (void)
|
|||
|
||||
void S_Shutdown(void)
|
||||
{
|
||||
|
||||
if (!sound_started)
|
||||
return;
|
||||
|
||||
|
@ -254,10 +247,8 @@ void S_Shutdown(void)
|
|||
sound_started = 0;
|
||||
|
||||
if (!fakedma)
|
||||
{
|
||||
SNDDMA_Shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// =======================================================================
|
||||
|
@ -278,15 +269,13 @@ sfx_t *S_FindName (char *name)
|
|||
if (!name)
|
||||
Sys_Error ("S_FindName: NULL\n");
|
||||
|
||||
if (Q_strlen(name) >= MAX_QPATH)
|
||||
if (strlen(name) >= MAX_QPATH)
|
||||
Sys_Error ("Sound name too long: %s", name);
|
||||
|
||||
// see if already loaded
|
||||
for (i=0 ; i < num_sfx ; i++)
|
||||
if (!strcmp(known_sfx[i].name, name))
|
||||
{
|
||||
return &known_sfx[i];
|
||||
}
|
||||
|
||||
if (num_sfx == MAX_SFX)
|
||||
Sys_Error ("S_FindName: out of sfx_t");
|
||||
|
@ -361,7 +350,7 @@ channel_t *SND_PickChannel(int entnum, int entchannel)
|
|||
if (entchannel != 0 // channel 0 never overrides
|
||||
&& channels[ch_idx].entnum == entnum
|
||||
&& (channels[ch_idx].entchannel == entchannel || entchannel == -1) )
|
||||
{ // allways override sound from same entity
|
||||
{ // always override sound from same entity
|
||||
first_to_die = ch_idx;
|
||||
break;
|
||||
}
|
||||
|
@ -426,9 +415,7 @@ float SND_InverseSpatializationRScaleLUT[126] = {
|
|||
1.2961481396815726f, 1.301921656629154f, 1.3076696830622025f, 1.3133925536563702f,
|
||||
1.3190905958272925f, 1.3247641299491775f, 1.3304134695650076f, 1.3360389215887394f,
|
||||
1.3416407864998743f, 1.3472193585307484f, 1.3527749258468689f, 1.358307770720613f,
|
||||
1.363818169698586f, 1.3693063937629157f, 1.3747727084867525f, 1.3802173741842267f,
|
||||
1.3856406460551023f, 1.391042774324356f, 1.3964240043768947f, 1.4017845768876191f,
|
||||
1.4071247279470294f, 1.412444689182554f
|
||||
1.363818169698586f, 1.3693063937629157f
|
||||
};
|
||||
|
||||
float SND_InverseSpatializationLScaleLUT[126] = {
|
||||
|
@ -463,15 +450,13 @@ float SND_InverseSpatializationLScaleLUT[126] = {
|
|||
0.5656854249492369f, 0.5522680508593619f, 0.5385164807134492f, 0.5244044240850745f,
|
||||
0.5099019513592772f, 0.4949747468305819f, 0.4795831523312705f, 0.46368092477478373f,
|
||||
0.4472135954999564f, 0.4301162633521297f, 0.41231056256176435f, 0.39370039370058874f,
|
||||
0.3741657386773922f, 0.35355339059327173f, 0.3316624790355378f, 0.30822070014844644f,
|
||||
0.2828427124746164f, 0.2549509756796363f, 0.2236067977499756f, 0.187082869338693f,
|
||||
0.14142135623730406f, 0.07071067811864379f
|
||||
0.3741657386773922f, 0.35355339059327173f
|
||||
};
|
||||
|
||||
void SND_Spatialize(channel_t *ch)
|
||||
{
|
||||
vec_t dot;
|
||||
vec_t ldist, rdist, dist;
|
||||
vec_t dist;
|
||||
vec_t lscale, rscale, scale;
|
||||
vec3_t source_vec;
|
||||
sfx_t *snd;
|
||||
|
@ -552,8 +537,7 @@ void S_StartSound(int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float f
|
|||
return; // not audible at all
|
||||
|
||||
// new channel
|
||||
sc = S_LoadSound (sfx);
|
||||
if (!sc)
|
||||
if (!(sc = S_LoadSound (sfx)))
|
||||
{
|
||||
target_chan->sfx = NULL;
|
||||
return; // couldn't load the sound's data
|
||||
|
@ -579,7 +563,6 @@ void S_StartSound(int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float f
|
|||
target_chan->end -= skip;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -589,8 +572,7 @@ void S_StopSound(int entnum, int entchannel)
|
|||
|
||||
for (i=0 ; i<MAX_DYNAMIC_CHANNELS ; i++)
|
||||
{
|
||||
if (channels[i].entnum == entnum
|
||||
&& channels[i].entchannel == entchannel)
|
||||
if (channels[i].entnum == entnum && channels[i].entchannel == entchannel)
|
||||
{
|
||||
channels[i].end = 0;
|
||||
channels[i].sfx = NULL;
|
||||
|
@ -612,13 +594,13 @@ void S_StopAllSounds(qboolean clear)
|
|||
if (channels[i].sfx)
|
||||
channels[i].sfx = NULL;
|
||||
|
||||
Q_memset(channels, 0, MAX_CHANNELS * sizeof(channel_t));
|
||||
memset(channels, 0, MAX_CHANNELS * sizeof(channel_t));
|
||||
|
||||
if (clear)
|
||||
S_ClearBuffer ();
|
||||
}
|
||||
|
||||
void S_StopAllSoundsC (void)
|
||||
void S_StopAllSoundsC_f (void)
|
||||
{
|
||||
S_StopAllSounds (true);
|
||||
}
|
||||
|
@ -627,11 +609,7 @@ void S_ClearBuffer (void)
|
|||
{
|
||||
int clear;
|
||||
|
||||
#ifdef _WIN32
|
||||
if (!sound_started || !shm || (!shm->buffer && !pDSBuf))
|
||||
#else
|
||||
if (!sound_started || !shm || !shm->buffer)
|
||||
#endif
|
||||
return;
|
||||
|
||||
if (shm->samplebits == 8)
|
||||
|
@ -639,42 +617,8 @@ void S_ClearBuffer (void)
|
|||
else
|
||||
clear = 0;
|
||||
|
||||
#ifdef _WIN32
|
||||
if (pDSBuf)
|
||||
{
|
||||
DWORD dwSize;
|
||||
DWORD *pData;
|
||||
int reps;
|
||||
HRESULT hresult;
|
||||
|
||||
reps = 0;
|
||||
|
||||
while ((hresult = pDSBuf->lpVtbl->Lock(pDSBuf, 0, gSndBufSize, &pData, &dwSize, NULL, NULL, 0)) != DS_OK)
|
||||
{
|
||||
if (hresult != DSERR_BUFFERLOST)
|
||||
{
|
||||
Con_Printf ("S_ClearBuffer: DS::Lock Sound Buffer Failed\n");
|
||||
S_Shutdown ();
|
||||
return;
|
||||
}
|
||||
|
||||
if (++reps > 10000)
|
||||
{
|
||||
Con_Printf ("S_ClearBuffer: DS: couldn't restore buffer\n");
|
||||
S_Shutdown ();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Q_memset(pData, clear, shm->samples * shm->samplebits/8);
|
||||
|
||||
pDSBuf->lpVtbl->Unlock(pDSBuf, pData, dwSize, NULL, 0);
|
||||
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
Q_memset(shm->buffer, clear, shm->samples * shm->samplebits/8);
|
||||
memset(shm->buffer, clear, shm->samples * shm->samplebits/8);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -701,8 +645,7 @@ void S_StaticSound (sfx_t *sfx, vec3_t origin, float vol, float attenuation)
|
|||
ss = &channels[total_channels];
|
||||
total_channels++;
|
||||
|
||||
sc = S_LoadSound (sfx);
|
||||
if (!sc)
|
||||
if (!(sc = S_LoadSound (sfx)))
|
||||
return;
|
||||
|
||||
if (sc->loopstart == -1)
|
||||
|
@ -849,13 +792,9 @@ void S_Update(vec3_t origin, vec3_t forward, vec3_t right, vec3_t up)
|
|||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// debugging output
|
||||
//
|
||||
if (snd_show.value)
|
||||
{
|
||||
total = 0;
|
||||
|
@ -881,16 +820,13 @@ void GetSoundtime(void)
|
|||
static int oldsamplepos;
|
||||
int fullsamples;
|
||||
|
||||
|
||||
fullsamples = shm->samples / shm->channels;
|
||||
|
||||
// it is possible to miscount buffers if it has wrapped twice between
|
||||
// calls to S_Update. Oh well.
|
||||
#ifdef __sun__
|
||||
soundtime = SNDDMA_GetSamples();
|
||||
#else
|
||||
samplepos = SNDDMA_GetDMAPos();
|
||||
|
||||
|
||||
if (samplepos < oldsamplepos)
|
||||
{
|
||||
buffers++; // buffer wrapped
|
||||
|
@ -905,18 +841,13 @@ void GetSoundtime(void)
|
|||
oldsamplepos = samplepos;
|
||||
|
||||
soundtime = buffers*fullsamples + samplepos/shm->channels;
|
||||
#endif
|
||||
}
|
||||
|
||||
void S_ExtraUpdate (void)
|
||||
{
|
||||
|
||||
#ifdef _WIN32
|
||||
IN_Accumulate ();
|
||||
#endif
|
||||
|
||||
if (snd_noextraupdate.value)
|
||||
return; // don't pollute timings
|
||||
|
||||
S_Update_();
|
||||
}
|
||||
|
||||
|
@ -938,31 +869,14 @@ void S_Update_(void)
|
|||
paintedtime = soundtime;
|
||||
}
|
||||
|
||||
//OutputDebugString(va("paintedtime: %i, soundtime: %i\n", paintedtime, soundtime));
|
||||
|
||||
// mix ahead of current position
|
||||
endtime = soundtime + _snd_mixahead.value * shm->speed;
|
||||
samps = shm->samples >> (shm->channels-1);
|
||||
if (endtime - soundtime > samps)
|
||||
endtime = soundtime + samps;
|
||||
|
||||
#ifdef _WIN32
|
||||
// if the buffer was lost or stopped, restore it and/or restart it
|
||||
{
|
||||
DWORD dwStatus;
|
||||
|
||||
if (pDSBuf)
|
||||
{
|
||||
if (pDSBuf->lpVtbl->GetStatus (pDSBuf, &dwStatus) != DD_OK)
|
||||
Con_Printf ("Couldn't get sound buffer status\n");
|
||||
|
||||
if (dwStatus & DSBSTATUS_BUFFERLOST)
|
||||
pDSBuf->lpVtbl->Restore (pDSBuf);
|
||||
|
||||
if (!(dwStatus & DSBSTATUS_PLAYING))
|
||||
pDSBuf->lpVtbl->Play(pDSBuf, 0, 0, DSBPLAY_LOOPING);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
S_PaintChannels (endtime);
|
||||
|
||||
SNDDMA_Submit ();
|
||||
|
@ -976,7 +890,7 @@ console functions
|
|||
===============================================================================
|
||||
*/
|
||||
|
||||
void S_Play(void)
|
||||
void S_Play_f(void)
|
||||
{
|
||||
static int hash=345;
|
||||
int i;
|
||||
|
@ -986,20 +900,20 @@ void S_Play(void)
|
|||
i = 1;
|
||||
while (i<Cmd_Argc())
|
||||
{
|
||||
if (!Q_strrchr(Cmd_Argv(i), '.'))
|
||||
if (!strrchr(Cmd_Argv(i), '.'))
|
||||
{
|
||||
Q_strcpy(name, Cmd_Argv(i));
|
||||
Q_strcat(name, ".wav");
|
||||
strcpy(name, Cmd_Argv(i));
|
||||
strlcat (name, ".wav", sizeof(name));
|
||||
}
|
||||
else
|
||||
Q_strcpy(name, Cmd_Argv(i));
|
||||
strcpy(name, Cmd_Argv(i));
|
||||
sfx = S_PrecacheSound(name);
|
||||
S_StartSound(hash++, 0, sfx, listener_origin, 1.0, 1.0);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void S_PlayVol(void)
|
||||
void S_PlayVol_f(void)
|
||||
{
|
||||
static int hash=543;
|
||||
int i;
|
||||
|
@ -1007,24 +921,30 @@ void S_PlayVol(void)
|
|||
char name[256];
|
||||
sfx_t *sfx;
|
||||
|
||||
if (Cmd_Argc() != 2)
|
||||
{
|
||||
Con_Printf ("Usage: playvol <filename>\n");
|
||||
return;
|
||||
}
|
||||
|
||||
i = 1;
|
||||
while (i<Cmd_Argc())
|
||||
{
|
||||
if (!Q_strrchr(Cmd_Argv(i), '.'))
|
||||
if (!strrchr(Cmd_Argv(i), '.'))
|
||||
{
|
||||
Q_strcpy(name, Cmd_Argv(i));
|
||||
Q_strcat(name, ".wav");
|
||||
strcpy(name, Cmd_Argv(i));
|
||||
strlcat (name, ".wav", sizeof(name));
|
||||
}
|
||||
else
|
||||
Q_strcpy(name, Cmd_Argv(i));
|
||||
strcpy(name, Cmd_Argv(i));
|
||||
sfx = S_PrecacheSound(name);
|
||||
vol = Q_atof(Cmd_Argv(i+1));
|
||||
vol = atof(Cmd_Argv(i+1));
|
||||
S_StartSound(hash++, 0, sfx, listener_origin, vol, 1.0);
|
||||
i+=2;
|
||||
}
|
||||
}
|
||||
|
||||
void S_SoundList(void)
|
||||
void S_SoundList_f(void)
|
||||
{
|
||||
int i;
|
||||
sfx_t *sfx;
|
||||
|
@ -1034,8 +954,7 @@ void S_SoundList(void)
|
|||
total = 0;
|
||||
for (sfx=known_sfx, i=0 ; i<num_sfx ; i++, sfx++)
|
||||
{
|
||||
sc = Cache_Check (&sfx->cache);
|
||||
if (!sc)
|
||||
if (!(sc = Cache_Check (&sfx->cache)))
|
||||
continue;
|
||||
size = sc->length*sc->width*(sc->stereo+1);
|
||||
total += size;
|
||||
|
@ -1048,6 +967,25 @@ void S_SoundList(void)
|
|||
Con_Printf ("Total resident: %i\n", total);
|
||||
}
|
||||
|
||||
qboolean volume_changed;
|
||||
|
||||
void S_VolumeDown_f (void)
|
||||
{
|
||||
//S_LocalSound ("misc/menu3.wav");
|
||||
volume.value -= 0.1;
|
||||
volume.value = bound(0, volume.value, 1);
|
||||
//Cvar_SetValueByRef (&volume, volume.value);
|
||||
volume_changed = true;
|
||||
}
|
||||
|
||||
void S_VolumeUp_f (void)
|
||||
{
|
||||
//S_LocalSound ("misc/menu3.wav");
|
||||
volume.value += 0.1;
|
||||
volume.value = bound(0, volume.value, 1);
|
||||
//Cvar_SetValueByRef (&volume, volume.value);
|
||||
volume_changed = true;
|
||||
}
|
||||
|
||||
void S_LocalSound (char *sound)
|
||||
{
|
||||
|
@ -1058,8 +996,7 @@ void S_LocalSound (char *sound)
|
|||
if (!sound_started)
|
||||
return;
|
||||
|
||||
sfx = S_PrecacheSound (sound);
|
||||
if (!sfx)
|
||||
if (!(sfx = S_PrecacheSound (sound)))
|
||||
{
|
||||
Con_Printf ("S_LocalSound: can't cache %s\n", sound);
|
||||
return;
|
||||
|
|
|
@ -127,6 +127,8 @@ void SNDDMA_Shutdown(void);
|
|||
#define MAX_CHANNELS 128
|
||||
#define MAX_DYNAMIC_CHANNELS 8
|
||||
|
||||
#define MAX_SFX 512
|
||||
|
||||
|
||||
extern channel_t channels[MAX_CHANNELS];
|
||||
// 0 to MAX_DYNAMIC_CHANNELS-1 = normal entity sounds
|
||||
|
@ -154,6 +156,7 @@ extern vec_t sound_nominal_clip_dist;
|
|||
|
||||
extern cvar_t loadas8bit;
|
||||
extern cvar_t bgmvolume;
|
||||
extern cvar_t bgmtype;
|
||||
extern cvar_t volume;
|
||||
|
||||
extern qboolean snd_initialized;
|
||||
|
|
Loading…
Reference in a new issue