Commit graph

63 commits

Author SHA1 Message Date
Daniel Gibson
5f346c7355 Add s_alReverbGain CVar to reduce intensity of reverb effects, fix #365
It can be set to a value between 0.0 and 1.0.
1.0 sounds like it did before introducing this cvar; as many people
found the the effect way to strong, I made 0.5 the default value
2021-04-27 20:08:59 +02:00
Daniel Gibson
954ff88759 Properly pause sounds when entering menu, fixes #330
Otherwise especially looped sounds continue playing while the menu
is open, especially noticeable when opening the menu while firing
the chaingun (the whirring sound continues playing).
2021-04-27 20:08:59 +02:00
Daniel Gibson
1b61053c53 idSoundSample::Load() uses s_decompressionLimit for oggs again
The code to decompress OGG files directly on load if they're shorter
than s_decompressionLimit seconds (usually 6) accidentally got broken
when removing the non-OpenAL soundbackends:
`if ( objectInfo.wFormatTag == WAVE_FORMAT_TAG_OGG )` slipped into the
`if ( objectInfo.wFormatTag == WAVE_FORMAT_TAG_PCM )` block - obviously
both can't be true at the same time so the OGG case was never executed.
Now it's in its own block again. I put it into a {} scope so it doesn't
have to be re-indented (=> more useful with git blame)
2021-04-27 20:08:59 +02:00
Daniel Gibson
1c13fe2d39 Use stb_vorbis instead of libogg and libvorbis(file)
Seems to work; note that idWaveFile is only ever used in idSoundSample::Load()

As stb_vorbis doesn't support custom callbacks for reading, I feed it
the full .ogg files as a buffer. Shouldn't make much of a difference
though - either the whole file is decoded on load anyway (so the buffer
is freed after decoding, or it's streamed, but in that case the old code
also kept the whole ogg file in memory by using idFily_Memory.

I also added warning messages in places where calls to stb_vorbis_*()
can fail, where there were none in the equivalent libvorbis code.
2021-04-27 20:08:59 +02:00
Daniel Gibson
1ae268a20e Fix stb_vorbis failing to load .ogg files without comments
fix taken from https://github.com/nothings/stb/pull/1095
2021-04-27 20:08:59 +02:00
Daniel Gibson
c1c8de214a Add stb_vorbis so it can replace libogg/vorbis(file)
from https://github.com/nothings/stb/

renamed it from .c to .h so build systems don't get confused.
2021-04-27 20:08:59 +02:00
Daniel Gibson
13ac657ebf Make deleting listenerSlot in idSoundWorldLocal::Shutdown() work
the problem was that the sources were still associated to it, because
they get deleted after the listenerSlot: the sources get freed in
idSoundSystemLocal::Shutdown() which is called by
idCommonLocal::ShutdownGame() in line 3217,
while the listenerSlot is deleted via idSessionLocal::Shutdown()
-> delete sw/rw -> idSoundWorldLocal::~idSoundWorldLocal()
-> idSoundWorldLocal::Shutdown() - and idSessionLocal::Shutdown() is
called in idCommonLocal::ShutdownGame() line 3211, before the other.

I'm not gonna mess with the order of deleting things in ShutdownGame(),
but it's sufficient to unassociate the effect slot from the source
when destroying the emitters in idSoundWorldLocal::Shutdown(),
by adding a call for that to idSoundChannel::ALStop() - and destroying
the emitters before deleting listenerSlot.

Before this fix, with ALSOFT_LOGLEVEL=3 you got the following warning:
  (WW) Error generated on context 0x5578fce2a280, code 0xa004,
  "Deleting in-use effect slot 1"
Thanks for openal-soft's KittyCat for pointing this out!
2021-04-12 19:17:12 +02:00
Turo Lamminen
cbd59321a8 Fix uninitialized members in idSoundWorldLocal 2021-04-12 19:13:39 +02:00
Boris I. Bendovsky
fa51007a6f Calculate EFX occlusion as in Creative's EFX-Util 2021-01-15 17:57:39 +01:00
Boris I. Bendovsky
432b86fdeb Calculate EFX density as in EFX-Util 2021-01-15 17:57:17 +01:00
Daniel Gibson
504b572ae4 Update sounds at ~60Hz instead of ~10Hz, fixes #141
For some reason sounds were only updated/started about every 100ms,
which could lead to delays of up to around 100ms after a sound gets
started (with idSoundEmitterLocal::StartSound()) until OpenAL is finally
told to play the sound.
Also, the actual delay drifted over time between 1ms and 100ms, as the
sound ticks weren't a fixed multiple of the (16ms) gameticks - and the
sound updates didn't even happen at the regular 92-94ms intervals they
should because they run in the async thread which only updates every
16ms...
Because of this, the machine gun and other rapid firing weapons sounded
like they shot in bursts or left out shots occasionally, even though
they don't.
Anyway, now sound is updated every 16ms in the async thread so delays
are <= 16ms and hopefully less noticeable.

You can still get the old behavior with com_asyncSound 2 if you want.
2020-07-12 04:43:53 +02:00
Daniel Gibson
e6f3713169 OpenAL: Try to reset disconnected devices, fixes #209
OpenAL devices can disconnect, and with some luck they're back after
a few seconds. This especially seems to happen with Intels Windows GPU
driver and display-audio when switching the resolution or enabling
fullscreen, see #209
Now a disconnect is detected and we try to reset the device for 20
seconds, hoping it comes back. This needs at least openal-soft 1.17.0
to build and 1.20.0 or newer to actually work.

Also added missing stub functions in openal_stub.cpp (used by dedicated
server so it doesn't have to link libopenal)
2020-06-01 22:13:41 +02:00
Daniel Gibson
964efa191d Disable sound if initializing OpenAL failed, fixes #292
idSoundSystemLocal::Init() didn't consider the case that opening the
default device (alcOpenDevice(NULL)) could fail, but this can happen if no
audio devices exist (or all are disabled or they're sleeping bluetooth
headphones or whatever).
Starting a map failed then with
  ERROR: idSoundCache: error generating OpenAL hardware buffer
Now this and "s_noSound 1" are handled the same and one can play.
2020-06-01 22:13:41 +02:00
Daniel Gibson
5919717d05 Fix looping .wav sounds with leadin, fixes #291
If the main sound in a shader was a .wav
(soundShader->entries[0]->hardwareBuffer == true), only that sound was
played (and looped with AL_LOOPING), even if a leadin was configured.
If the main sound was an .ogg it worked.
Not it should always work.
2020-06-01 22:13:41 +02:00
Corey O'Connor
636c3a0b54 ignore errors unloading OpenAL data. mitigates #178 2020-01-30 01:08:10 +01:00
Yamagi Burmeister
4a6327d87a Fix entering the menu or saving the game stopping some sounds.
If an OpenAL source runs out of samples it transisions into state
AL_STOPPED. That happens if we're entering the menu (which switches
to another soundworld) and when saving the game (because the game
blocks for some milliseconds). Work around this by adding a new
field 'stopped' to the channel state and use that to determine if
a sound was stopped. And not AL_STOPPED like before.
2018-08-19 16:58:44 +02:00
Daniel Gibson
3c01757d27 Scale down volume of all sounds, fixes #179
so even with many loud sounds the overall volume isn't reduced by
OpenAL - apparently OpenAL scales down all sounds temporarily if the
mixed result would be too loud or sth like that.
Just sending all sounds to OpenAL with a lower volume prevents that from
happening (just set your system speaker volume a bit higher if needed).
This problem was especially noticable when shooting at metal walls with
the shotgun (each pellet produces an impact sound so it gets kinda loud)
2018-02-12 03:31:34 +01:00
Daniel Gibson
ebac192352 Don't Shut down the game with Error() if OpenAL buffer commands fail
based on a Patch from https://github.com/PROPHESSOR, see
https://github.com/dhewm/dhewm3/pull/184
(I added a common->Warning() as a compromise between common->Error()
 and just ignoring the error)
2018-02-12 03:31:34 +01:00
Daniel Gibson
6ba1b71fb1 Change default values for some video and sound (EAX) CVars
* r_mode defaults to 5 (1024x768), I think that's more sane than 640x480
* r_fullscreen defaults to 0 (=> windowed mode) because fullscreen in
  the wrong resolution sucks.. let people do their initial configuration
  in windowed mode
* r_swapInterval defaults to 1 (=> VSync active by default) because that
  makes the game feel more smooth and most PCs should be able to 60fps
  in this 11years old game anyway

* s_useEAXReverb defaults to 1 (=> use EAX/EFX effects by default),
  because OpenAL-soft supports them on all platforms/hardware and if
  for some reason the used OpenAL implementation doesn't support it,
  it's deactivated automatically anyway.

All these things can be configured in the Options Menu.
2015-09-29 21:14:45 +02:00
Daniel Gibson
1de6ab0d50 Fix some compiler warnings (wrong types, superfluous checks, printf-fuckup) 2015-09-27 18:12:16 +02:00
bibendovsky
351f5dc94f Fixed screen twitches with "shakes" sound shader
Caused by inaccuracies in the precached amplitude data in the OpenAL
backend, see https://github.com/dhewm/dhewm3/pull/71 for more details.

Video sample (not mine):
http://www.youtube.com/watch?v=ZUohifAbPW0
The "twitches" can also be observed right at the beginning of the
mars_city2 map.
2013-06-11 23:58:20 +02:00
Daniel Gibson
105fdb0624 Fix dedicated server for Windows
* the OpenAL function definitions mustn't include __declspec(dllimport)
  => fixed by pretending to compile OpenAL statically
* glimp.cpp shouldn't be used in dedicated-only mode (as it was already
  the case on Linux and OSX)
  => No special handling for ID_DEDICATED needed in glimp.cpp, as it's not
   used anyway
* add APIENTRY to every gl function in stub_gl.cpp for compatibility
  with windows headers and MSVC
* remove GL/gl.h #include from win_local.h as it's not needed
* in qgl.h, when building dedicated server for windows, redefine WINGDIAPI
  to nothing for SDL_opengl.h #include to get rid off __declspec(dllimport)
  by using #pragma push_macro and pop_macro, because our stub is no dll.

Fixes https://github.com/dhewm/dhewm3/issues/39
2012-11-12 20:18:00 +01:00
dhewg
2a3d07e174 More logging cleanup 2012-07-20 00:12:55 +02:00
dhewg
626de63ff5 Cleanup OpenAL logging 2012-07-20 00:12:53 +02:00
dhewg
5e05c5b031 Get rid of s_libOpenAL and s_useOpenAL
Both unused.
2012-07-20 00:12:52 +02:00
dhewg
49c4d028a5 s/LittleLong/LittleInt/ to match the return type 2012-06-28 13:02:47 +02:00
Daniel Gibson
0d27bfe7b9 Remove usage of long type from idlib/
Apart from some minor stuff, this changes the signature of some methods
of Parser and Token classes and of the (unused) Random2 class.
That no problem though, because the calling code uses normal ints
anyway.
2012-06-28 13:02:45 +02:00
Daniel Gibson
56873e1fec Fix memleak in snd_cache.cpp (from Harry Jeffery)
This fix is stolen from https://bugzilla.icculus.org/show_bug.cgi?id=5345
2012-05-13 02:31:37 +02:00
dhewg
668802f09a Cleanup OpenAL includes
We use OpenAL Soft on all platforms.
2012-01-14 20:43:50 +01:00
dhewg
b5c66c088c Get rid of ID_OPENAL
This is always required for clients.
2012-01-14 15:02:26 +01:00
dhewg
3e07208cae New CVar s_device to choose the audio device to use 2012-01-11 22:52:05 +01:00
dhewg
35bd70ea46 Improve environment suit sfx
Set AL_LOWPASS_GAIN like EAX did under the hood.
Set the same filter via AL_DIRECT_FILTER on sources.

This should bring the overall sfx closer to EAX:
<kaan_> it sounds awesome

All infos provided by KittyCat from #openal.
2012-01-11 19:29:35 +01:00
dhewg
16958d070b Fix [record|play|time]Demo for x86_64
These are still fragile due to restored stale pointers (!).
But at least the vanilla demos can now be used to check for
performance regressions.
2012-01-10 22:54:01 +01:00
dhewg
d8acc43aca Port the D3XP environment suit effect to EFX
Use a AL_LOWPASS_GAINHF filter to muffle sfx.
2012-01-10 17:45:37 +01:00
dhewg
8ea0f8f0d5 Clamp EFX reverb effect values
The values might be slightly out of range due to the scale
conversion. Clamp them so OpenAL doesn't refuse them.
2012-01-10 17:45:37 +01:00
dhewg
bdbee3543c Cleanup EFX code
Add error checking.
Add debug printf()s, enable via EFX_VERBOSE.
2012-01-10 17:45:37 +01:00
dhewg
b8f9829255 Use the correct unit when passing values for EFX
The gain values are expressed as millibels in the .efx files
and need to be converted to normalized floating points.
Get the EAX4 EAXREVERBFLAGS_DECAYHFLIMIT from the "flags" token
and set AL_EAXREVERB_DECAY_HFLIMIT accordingly.

All infos provided by KittyCat from #openal, many thanks!
2012-01-09 00:52:30 +01:00
dhewg
ece2adbdcd Port EAX to EFX
First attempt at porting the EAX reverb code to EFX.
This only works when the ALC_EXT_EFX extension is supported by
the OpenAL vendor (which is not the case for the OSX supplied
framework, use OpenAL soft instead).

The current stable version of OpenAL Soft (v1.13 as of this
writing) can barely handle this additional workload, current
master is highly recommended when using this feature.
2012-01-08 22:04:56 +01:00
spiral
468b266860 Remove hard-wired -framework OpenAL
We already link to OPENAL_LIBRARY further down.

Log some debug OpenAL info, mainly so OSX users can check they are not
using Apple's OpenAL. OpenAL Soft is recommended as it fixes many
issues.

I specify it as follows:

cmake -DOPENAL_LIBRARY=/usr/local/lib/libopenal.dylib -DOPENAL_INCLUDE_DIR=/usr/local/include -GXcode ../neo/

(because FindOpenAL.cmake prefers the /System frameworks)
2012-01-08 12:24:45 +01:00
spiral
13bab7a7e5 Remove MWERKS stuff 2011-12-23 13:04:21 +01:00
dhewg
736ec20d4d Untangle the epic precompiled.h mess
Don't include the lazy precompiled.h everywhere, only what's
required for the compilation unit.
platform.h needs to be included instead to provide all essential
defines and types.
All includes use the relative path to the neo or the game
specific root.
Move all idlib related includes from idlib/Lib.h to precompiled.h.
precompiled.h still exists for the MFC stuff in tools/.
Add some missing header guards.
2011-12-19 23:21:47 +01:00
dhewg
b62b033b88 Get rid of all idAudioHardware implementations 2011-12-14 18:37:03 +01:00
dhewg
18f9793732 Get rid of the intenal useOpenAL
Useless now, there is only OpenAL.
2011-12-14 18:24:06 +01:00
dhewg
93e5345fbc Don't use any idAudioHardware implementations
OpenAL for everyone.
2011-12-14 18:24:06 +01:00
dhewg
4e26e1ac6f Don't use idAudioHardware to get the speaker count
Use the CVar s_numberOfSpeakers for that, its already stored
in there.
Add the same (!= 2 && !=6) check as in the audio backends since
the mixer is limited to these 2 values.
2011-12-14 18:24:05 +01:00
dhewg
66141935f5 Use OpenAL per default
Deprecate s_libOpenAL and s_useOpenAL for compability and don't
access them anymore.
2011-12-14 18:24:05 +01:00
dhewg
9df3383b61 Remove Sys_LoadOpenAL() and Sys_FreeOpenAL()
This is not required anymore, all binaries on all platforms
either link against OpenAL or use the stub.
2011-12-14 18:23:49 +01:00
dhewg
3e25cc751a Always link the win32 binary against OpenAL
Just as with OSX and Linux.
2011-12-14 18:20:31 +01:00
dhewg
f6fa194044 Don't load EAX sound effects when EAX is disabled 2011-12-11 18:28:18 +01:00
dhewg
db65f7a61d Use system OpenAL 2011-12-11 17:07:13 +01:00