Fix the web port's numerous audio issues.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5681 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
parent
a92778fdbe
commit
b332742d6f
5 changed files with 65 additions and 12 deletions
25
build_wip.sh
25
build_wip.sh
|
@ -60,6 +60,10 @@ do
|
||||||
echo " -r VER Specifies the SVN revision to update to"
|
echo " -r VER Specifies the SVN revision to update to"
|
||||||
echo " -j THREADS Specifies how many jobs to make with"
|
echo " -j THREADS Specifies how many jobs to make with"
|
||||||
echo " --help This text"
|
echo " --help This text"
|
||||||
|
echo " --noupdate Don't do svn updates"
|
||||||
|
echo " --unclean Don't do make clean, for faster rebuilds"
|
||||||
|
echo " --web Build web target (excluding all others)"
|
||||||
|
echo " --droid Build android target (excluding others)"
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
-build|--build)
|
-build|--build)
|
||||||
|
@ -69,6 +73,27 @@ do
|
||||||
--noupdate)
|
--noupdate)
|
||||||
NOUPDATE="y"
|
NOUPDATE="y"
|
||||||
;;
|
;;
|
||||||
|
--unclean)
|
||||||
|
BUILD_CLEAN="n"
|
||||||
|
;;
|
||||||
|
--web)
|
||||||
|
BUILD_LINUXx86="n"
|
||||||
|
BUILD_LINUXx64="n"
|
||||||
|
BUILD_LINUXarmhf="n"
|
||||||
|
BUILD_WIN32="n"
|
||||||
|
BUILD_WIN64="n"
|
||||||
|
BUILD_ANDROID="n"
|
||||||
|
BUILD_WEB="y"
|
||||||
|
;;
|
||||||
|
--droid)
|
||||||
|
BUILD_LINUXx86="n"
|
||||||
|
BUILD_LINUXx64="n"
|
||||||
|
BUILD_LINUXarmhf="n"
|
||||||
|
BUILD_WIN32="n"
|
||||||
|
BUILD_WIN64="n"
|
||||||
|
BUILD_ANDROID="y"
|
||||||
|
BUILD_WEB="n"
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Unknown option $1"
|
echo "Unknown option $1"
|
||||||
;;
|
;;
|
||||||
|
|
|
@ -527,7 +527,7 @@ static qboolean OpenAL_LoadCache(oalinfo_t *oali, unsigned int *bufptr, sfxcache
|
||||||
float *tmp = malloc(size);
|
float *tmp = malloc(size);
|
||||||
float *src = (float*)sc->data;
|
float *src = (float*)sc->data;
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < (size>>1); i++)
|
for (i = 0; i < (size>>2); i++)
|
||||||
{
|
{
|
||||||
tmp[i] = src[i]*volume; //signed. oversaturation isn't my problem
|
tmp[i] = src[i]*volume; //signed. oversaturation isn't my problem
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,7 +84,14 @@ cvar_t precache = CVARAF( "s_precache", "1",
|
||||||
"precache", 0);
|
"precache", 0);
|
||||||
cvar_t loadas8bit = CVARAFD( "s_loadas8bit", "0",
|
cvar_t loadas8bit = CVARAFD( "s_loadas8bit", "0",
|
||||||
"loadas8bit", CVAR_ARCHIVE,
|
"loadas8bit", CVAR_ARCHIVE,
|
||||||
"Downsample sounds on load as lower quality 8-bit sound.");
|
"Downsample sounds on load as lower quality 8-bit sound, to save memory.");
|
||||||
|
#ifdef FTE_TARGET_WEB
|
||||||
|
cvar_t snd_loadasstereo = CVARD( "snd_loadasstereo", "1",
|
||||||
|
"Force mono sounds to load as if stereo ones, to waste memory. Used to work around stupid browser bugs.");
|
||||||
|
#else
|
||||||
|
cvar_t snd_loadasstereo = CVARD( "snd_loadasstereo", "0",
|
||||||
|
"Force mono sounds to load as if stereo ones, to waste memory. Not normally useful.");
|
||||||
|
#endif
|
||||||
cvar_t ambient_level = CVARAFD( "s_ambientlevel", "0.3",
|
cvar_t ambient_level = CVARAFD( "s_ambientlevel", "0.3",
|
||||||
"ambient_level", CVAR_ARCHIVE,
|
"ambient_level", CVAR_ARCHIVE,
|
||||||
"This controls the volume levels of automatic area-based sounds (like water or sky), and is quite annoying. If you're playing deathmatch you'll definitely want this OFF.");
|
"This controls the volume levels of automatic area-based sounds (like water or sky), and is quite annoying. If you're playing deathmatch you'll definitely want this OFF.");
|
||||||
|
@ -2294,6 +2301,7 @@ void S_Init (void)
|
||||||
Cvar_Register(&volume, "Sound controls");
|
Cvar_Register(&volume, "Sound controls");
|
||||||
Cvar_Register(&precache, "Sound controls");
|
Cvar_Register(&precache, "Sound controls");
|
||||||
Cvar_Register(&loadas8bit, "Sound controls");
|
Cvar_Register(&loadas8bit, "Sound controls");
|
||||||
|
Cvar_Register(&snd_loadasstereo, "Sound controls");
|
||||||
Cvar_Register(&bgmvolume, "Sound controls");
|
Cvar_Register(&bgmvolume, "Sound controls");
|
||||||
Cvar_Register(&snd_nominaldistance, "Sound controls");
|
Cvar_Register(&snd_nominaldistance, "Sound controls");
|
||||||
Cvar_Register(&ambient_level, "Sound controls");
|
Cvar_Register(&ambient_level, "Sound controls");
|
||||||
|
|
|
@ -559,6 +559,7 @@ ResampleSfx
|
||||||
static qboolean ResampleSfx (sfx_t *sfx, int inrate, int inchannels, int inwidth, int insamps, int inloopstart, qbyte *data)
|
static qboolean ResampleSfx (sfx_t *sfx, int inrate, int inchannels, int inwidth, int insamps, int inloopstart, qbyte *data)
|
||||||
{
|
{
|
||||||
extern cvar_t snd_linearresample;
|
extern cvar_t snd_linearresample;
|
||||||
|
extern cvar_t snd_loadasstereo;
|
||||||
double scale;
|
double scale;
|
||||||
sfxcache_t *sc;
|
sfxcache_t *sc;
|
||||||
int outsamps;
|
int outsamps;
|
||||||
|
@ -575,7 +576,7 @@ static qboolean ResampleSfx (sfx_t *sfx, int inrate, int inchannels, int inwidth
|
||||||
outwidth = inwidth;
|
outwidth = inwidth;
|
||||||
len = outsamps * outwidth * inchannels;
|
len = outsamps * outwidth * inchannels;
|
||||||
|
|
||||||
sfx->decoder.buf = sc = BZ_Malloc(len + sizeof(sfxcache_t));
|
sfx->decoder.buf = sc = BZ_Malloc(sizeof(sfxcache_t) + len);
|
||||||
if (!sc)
|
if (!sc)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
@ -603,6 +604,25 @@ static qboolean ResampleSfx (sfx_t *sfx, int inrate, int inchannels, int inwidth
|
||||||
sc->numchannels,
|
sc->numchannels,
|
||||||
snd_linearresample.ival);
|
snd_linearresample.ival);
|
||||||
|
|
||||||
|
if (inchannels == 1 && snd_loadasstereo.ival)
|
||||||
|
{ //I'm implementing this to work around what looks like a firefox bug, where mono buffers don't get played (but stereo works just fine despite all the spacialisation issues associated with that).
|
||||||
|
sfxcache_t *nc = sfx->decoder.buf = BZ_Malloc(sizeof(sfxcache_t) + len*2);
|
||||||
|
*nc = *sc;
|
||||||
|
nc->data = (qbyte*)(nc+1);
|
||||||
|
SND_ResampleStream (sc->data,
|
||||||
|
sc->speed,
|
||||||
|
sc->width,
|
||||||
|
sc->numchannels,
|
||||||
|
outsamps,
|
||||||
|
nc->data,
|
||||||
|
nc->speed*2,
|
||||||
|
nc->width,
|
||||||
|
nc->numchannels,
|
||||||
|
false);
|
||||||
|
nc->numchannels *= 2;
|
||||||
|
BZ_Free(sc);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1083,27 +1083,28 @@ console.log("onerror: " + _url);
|
||||||
|
|
||||||
emscriptenfte_al_loadaudiofile : function(buf, dataptr, datasize)
|
emscriptenfte_al_loadaudiofile : function(buf, dataptr, datasize)
|
||||||
{
|
{
|
||||||
var ctx = AL.currentContext || AL.currentCtx;
|
var ctx = AL;
|
||||||
//match emscripten's openal support.
|
//match emscripten's openal support.
|
||||||
if (!buf)
|
if (!buf)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var albuf = ctx.buffers[buf];
|
var albuf = AL.buffers[buf];
|
||||||
ctx.buffers[buf] = null; //alIsBuffer will report it as invalid now
|
AL.buffers[buf] = null; //alIsBuffer will report it as invalid now
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//its async, so it needs its own copy of an arraybuffer
|
//its async, so it needs its own copy of an arraybuffer, not just a view.
|
||||||
var abuf = new ArrayBuffer(datasize);
|
var abuf = new ArrayBuffer(datasize);
|
||||||
Uint8Array(abuf).set(HEAPU8.subarray(dataptr, dataptr+datasize));
|
var rbuf = new Uint8Array(abuf);
|
||||||
AL.currentContext.ctx.decodeAudioData(abuf,
|
rbuf.set(HEAPU8.subarray(dataptr, dataptr+datasize));
|
||||||
|
AL.currentCtx.audioCtx.decodeAudioData(abuf,
|
||||||
function(buffer)
|
function(buffer)
|
||||||
{
|
{
|
||||||
//Warning: This depends upon emscripten's specific implementation of alBufferData
|
//Warning: This depends upon emscripten's specific implementation of alBufferData
|
||||||
albuf.bytesPerSample = 2;
|
albuf.bytesPerSample = 2;
|
||||||
albuf.channels = 1;
|
albuf.channels = 1;
|
||||||
albuf.length = 1;
|
albuf.length = buffer.length;
|
||||||
albuf.frequency = 11025;
|
albuf.frequency = buffer.sampleRate;
|
||||||
albuf.audioBuf = buffer;
|
albuf.audioBuf = buffer;
|
||||||
|
|
||||||
ctx.buffers[buf] = albuf; //and its valid again!
|
ctx.buffers[buf] = albuf; //and its valid again!
|
||||||
|
@ -1121,7 +1122,6 @@ console.log("onerror: " + _url);
|
||||||
console.log(e);
|
console.log(e);
|
||||||
ctx.buffers[buf] = albuf;
|
ctx.buffers[buf] = albuf;
|
||||||
}
|
}
|
||||||
return id;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
emscriptenfte_gl_loadtexturefile : function(texid, widthptr, heightptr, dataptr, datasize, fname)
|
emscriptenfte_gl_loadtexturefile : function(texid, widthptr, heightptr, dataptr, datasize, fname)
|
||||||
|
|
Loading…
Reference in a new issue