2006-02-24 04:48:15 +00:00
|
|
|
/*
|
|
|
|
** i_sound.cpp
|
2008-03-21 05:13:59 +00:00
|
|
|
** Stubs for sound interfaces.
|
2006-02-24 04:48:15 +00:00
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
2006-06-11 01:37:00 +00:00
|
|
|
** Copyright 1998-2006 Randy Heit
|
2006-02-24 04:48:15 +00:00
|
|
|
** All rights reserved.
|
|
|
|
**
|
|
|
|
** Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions
|
|
|
|
** are met:
|
|
|
|
**
|
|
|
|
** 1. Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in the
|
|
|
|
** documentation and/or other materials provided with the distribution.
|
|
|
|
** 3. The name of the author may not be used to endorse or promote products
|
|
|
|
** derived from this software without specific prior written permission.
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#include <windows.h>
|
|
|
|
#include <mmsystem.h>
|
|
|
|
#include "resource.h"
|
|
|
|
extern HWND Window;
|
|
|
|
extern HINSTANCE g_hInst;
|
2006-09-14 00:17:10 +00:00
|
|
|
#define USE_WINDOWS_DWORD
|
2006-02-24 04:48:15 +00:00
|
|
|
#else
|
|
|
|
#define FALSE 0
|
|
|
|
#define TRUE 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
2014-06-20 05:40:45 +00:00
|
|
|
#include <memory>
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
#include "doomtype.h"
|
|
|
|
#include <math.h>
|
|
|
|
|
2015-04-25 10:25:10 +00:00
|
|
|
#include "except.h"
|
2006-02-24 04:48:15 +00:00
|
|
|
#include "fmodsound.h"
|
2010-08-13 07:07:26 +00:00
|
|
|
#include "oalsound.h"
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2014-06-20 06:03:13 +00:00
|
|
|
#include "mpg123_decoder.h"
|
|
|
|
#include "sndfile_decoder.h"
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
#include "m_swap.h"
|
|
|
|
#include "stats.h"
|
|
|
|
#include "files.h"
|
|
|
|
#include "c_cvars.h"
|
|
|
|
#include "c_dispatch.h"
|
|
|
|
#include "i_system.h"
|
|
|
|
#include "i_sound.h"
|
|
|
|
#include "i_music.h"
|
|
|
|
#include "m_argv.h"
|
|
|
|
#include "m_misc.h"
|
|
|
|
#include "w_wad.h"
|
|
|
|
#include "i_video.h"
|
|
|
|
#include "s_sound.h"
|
- The garbage collector is now run one last time just before exiting the game.
- Removed movie volume from the sound menu and renamed some of the other
options to give the MIDI device name more room to display itself.
- Moved the midi device selection into the main sound menu.
- Added FMOD as MIDI device -1, to replace the MIDI mapper. This is still the
default device. By default, it uses exactly the same DLS instruments as the
Microsoft GS Wavetable Synth. If you have another set DLS level 1 patch set
you want to use, set the snd_midipatchfile cvar to specify where it should
load the instruments from.
- Changed the ProduceMIDI function to store its output into a TArray<BYTE>.
An overloaded version wraps around it to continue to supply file-writing
support for external Timidity++ usage.
- Added an FMOD credits banner to comply with their non-commercial license.
- Reimplemented the snd_buffersize cvar for the FMOD Ex sound system. Rather
than a time in ms, this is now the length in samples of the DSP buffer.
Also added the snd_buffercount cvar to offer complete control over the
call to FMOD::System::setDSPBufferSize(). Note that with any snd_samplerate
below about 44kHz, you will need to set snd_buffersize to avoid long
latencies.
- Reimplemented the snd_output cvar for the FMOD Ex sound system.
- Changed snd_samplerate default to 0. This now means to use the default
sample rate.
- Made snd_output, snd_output_format, snd_speakermode, snd_resampler, and
snd_hrtf available through the menu.
- Split the HRTF effect selection into its own cvar: snd_hrtf.
- Removed 96000 Hz option from the menu. It's still available through the
cvar, if desired.
- Fixed: If Windows sound init failed, retry with DirectSound. (Apparently,
WASAPI doesn't work with more than two speakers and PCM-Float output at the
same time.)
- Fixed: Area sounds only played from the front speakers once you got within
the 2D panning area.
SVN r854 (trunk)
2008-03-26 04:27:07 +00:00
|
|
|
#include "v_text.h"
|
2006-02-24 04:48:15 +00:00
|
|
|
#include "gi.h"
|
|
|
|
|
|
|
|
#include "doomdef.h"
|
|
|
|
|
|
|
|
EXTERN_CVAR (Float, snd_sfxvolume)
|
- The garbage collector is now run one last time just before exiting the game.
- Removed movie volume from the sound menu and renamed some of the other
options to give the MIDI device name more room to display itself.
- Moved the midi device selection into the main sound menu.
- Added FMOD as MIDI device -1, to replace the MIDI mapper. This is still the
default device. By default, it uses exactly the same DLS instruments as the
Microsoft GS Wavetable Synth. If you have another set DLS level 1 patch set
you want to use, set the snd_midipatchfile cvar to specify where it should
load the instruments from.
- Changed the ProduceMIDI function to store its output into a TArray<BYTE>.
An overloaded version wraps around it to continue to supply file-writing
support for external Timidity++ usage.
- Added an FMOD credits banner to comply with their non-commercial license.
- Reimplemented the snd_buffersize cvar for the FMOD Ex sound system. Rather
than a time in ms, this is now the length in samples of the DSP buffer.
Also added the snd_buffercount cvar to offer complete control over the
call to FMOD::System::setDSPBufferSize(). Note that with any snd_samplerate
below about 44kHz, you will need to set snd_buffersize to avoid long
latencies.
- Reimplemented the snd_output cvar for the FMOD Ex sound system.
- Changed snd_samplerate default to 0. This now means to use the default
sample rate.
- Made snd_output, snd_output_format, snd_speakermode, snd_resampler, and
snd_hrtf available through the menu.
- Split the HRTF effect selection into its own cvar: snd_hrtf.
- Removed 96000 Hz option from the menu. It's still available through the
cvar, if desired.
- Fixed: If Windows sound init failed, retry with DirectSound. (Apparently,
WASAPI doesn't work with more than two speakers and PCM-Float output at the
same time.)
- Fixed: Area sounds only played from the front speakers once you got within
the 2D panning area.
SVN r854 (trunk)
2008-03-26 04:27:07 +00:00
|
|
|
CVAR (Int, snd_samplerate, 0, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
|
2006-02-24 04:48:15 +00:00
|
|
|
CVAR (Int, snd_buffersize, 0, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
|
|
|
|
CVAR (String, snd_output, "default", CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
|
|
|
|
|
2010-08-13 07:07:26 +00:00
|
|
|
#ifndef NO_FMOD
|
|
|
|
CVAR (String, snd_backend, "fmod", CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
|
|
|
|
#elif !defined(NO_OPENAL)
|
|
|
|
CVAR (String, snd_backend, "openal", CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
|
|
|
|
#else
|
|
|
|
CVAR (String, snd_backend, "null", CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
|
|
|
|
#endif
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
// killough 2/21/98: optionally use varying pitched sounds
|
|
|
|
CVAR (Bool, snd_pitched, false, CVAR_ARCHIVE)
|
|
|
|
|
|
|
|
SoundRenderer *GSnd;
|
2010-10-05 22:35:59 +00:00
|
|
|
bool nosound;
|
2010-08-28 13:36:41 +00:00
|
|
|
bool nosfx;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2008-09-09 20:49:53 +00:00
|
|
|
void I_CloseSound ();
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// SFX API
|
|
|
|
//
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// CVAR snd_sfxvolume
|
|
|
|
//
|
|
|
|
// Maximum volume of a sound effect.
|
|
|
|
//==========================================================================
|
|
|
|
|
2008-03-28 03:19:18 +00:00
|
|
|
CUSTOM_CVAR (Float, snd_sfxvolume, 1.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG|CVAR_NOINITCALL)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
if (self < 0.f)
|
|
|
|
self = 0.f;
|
|
|
|
else if (self > 1.f)
|
|
|
|
self = 1.f;
|
|
|
|
else if (GSnd != NULL)
|
|
|
|
{
|
|
|
|
GSnd->SetSfxVolume (self);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-01 01:28:22 +00:00
|
|
|
class NullSoundRenderer : public SoundRenderer
|
|
|
|
{
|
|
|
|
public:
|
2008-09-09 20:49:53 +00:00
|
|
|
virtual bool IsNull() { return true; }
|
2008-07-01 01:28:22 +00:00
|
|
|
void SetSfxVolume (float volume)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void SetMusicVolume (float volume)
|
|
|
|
{
|
|
|
|
}
|
2008-09-09 20:49:53 +00:00
|
|
|
SoundHandle LoadSound(BYTE *sfxdata, int length)
|
2008-07-01 01:28:22 +00:00
|
|
|
{
|
2008-09-09 20:49:53 +00:00
|
|
|
SoundHandle retval = { NULL };
|
|
|
|
return retval;
|
|
|
|
}
|
2010-10-05 22:31:22 +00:00
|
|
|
SoundHandle LoadSoundRaw(BYTE *sfxdata, int length, int frequency, int channels, int bits, int loopstart, int loopend)
|
2008-09-09 20:49:53 +00:00
|
|
|
{
|
|
|
|
SoundHandle retval = { NULL };
|
|
|
|
return retval;
|
2008-07-01 01:28:22 +00:00
|
|
|
}
|
2008-09-09 20:49:53 +00:00
|
|
|
void UnloadSound (SoundHandle sfx)
|
2008-07-01 01:28:22 +00:00
|
|
|
{
|
|
|
|
}
|
2008-09-09 20:49:53 +00:00
|
|
|
unsigned int GetMSLength(SoundHandle sfx)
|
2008-07-01 01:28:22 +00:00
|
|
|
{
|
|
|
|
// Return something that isn't 0. This is only used by some
|
|
|
|
// ambient sounds to specify a default minimum period.
|
|
|
|
return 250;
|
|
|
|
}
|
2008-09-15 16:02:05 +00:00
|
|
|
unsigned int GetSampleLength(SoundHandle sfx)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2008-07-01 01:28:22 +00:00
|
|
|
float GetOutputRate()
|
|
|
|
{
|
|
|
|
return 11025; // Lies!
|
|
|
|
}
|
2008-09-15 18:18:04 +00:00
|
|
|
void StopChannel(FISoundChannel *chan)
|
2008-09-15 16:02:05 +00:00
|
|
|
{
|
|
|
|
}
|
2013-06-01 17:46:50 +00:00
|
|
|
void ChannelVolume(FISoundChannel *, float)
|
|
|
|
{
|
|
|
|
}
|
2008-07-01 01:28:22 +00:00
|
|
|
|
|
|
|
// Streaming sounds.
|
|
|
|
SoundStream *CreateStream (SoundStreamCallback callback, int buffbytes, int flags, int samplerate, void *userdata)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-06-25 11:25:36 +00:00
|
|
|
SoundStream *OpenStream (std::auto_ptr<FileReader> reader, int flags)
|
2008-07-01 01:28:22 +00:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-11-18 04:45:20 +00:00
|
|
|
// Starts a sound.
|
2008-09-15 18:18:04 +00:00
|
|
|
FISoundChannel *StartSound (SoundHandle sfx, float vol, int pitch, int chanflags, FISoundChannel *reuse_chan)
|
2008-07-01 01:28:22 +00:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-09-15 18:18:04 +00:00
|
|
|
FISoundChannel *StartSound3D (SoundHandle sfx, SoundListener *listener, float vol, FRolloffInfo *rolloff, float distscale, int pitch, int priority, const FVector3 &pos, const FVector3 &vel, int channum, int chanflags, FISoundChannel *reuse_chan)
|
2008-07-01 01:28:22 +00:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-11-18 04:45:20 +00:00
|
|
|
// Marks a channel's start time without actually playing it.
|
|
|
|
void MarkStartTime (FISoundChannel *chan)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-07-01 01:28:22 +00:00
|
|
|
// Returns position of sound on this channel, in samples.
|
2008-09-15 18:18:04 +00:00
|
|
|
unsigned int GetPosition(FISoundChannel *chan)
|
2008-07-01 01:28:22 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-11-04 02:07:39 +00:00
|
|
|
// Gets a channel's audibility (real volume).
|
|
|
|
float GetAudibility(FISoundChannel *chan)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-07-01 01:28:22 +00:00
|
|
|
// Synchronizes following sound startups.
|
|
|
|
void Sync (bool sync)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pauses or resumes all sound effect channels.
|
2008-07-05 03:32:44 +00:00
|
|
|
void SetSfxPaused (bool paused, int slot)
|
2008-07-01 01:28:22 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pauses or resumes *every* channel, including environmental reverb.
|
2012-08-10 03:49:50 +00:00
|
|
|
void SetInactive(SoundRenderer::EInactiveState inactive)
|
2008-07-01 01:28:22 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// Updates the volume, separation, and pitch of a sound channel.
|
2008-09-15 18:18:04 +00:00
|
|
|
void UpdateSoundParams3D (SoundListener *listener, FISoundChannel *chan, bool areasound, const FVector3 &pos, const FVector3 &vel)
|
2008-07-01 01:28:22 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-09-06 11:07:27 +00:00
|
|
|
void UpdateListener (SoundListener *)
|
2008-07-01 01:28:22 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
void UpdateSounds ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsValid ()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
void PrintStatus ()
|
|
|
|
{
|
|
|
|
Printf("Null sound module active.\n");
|
|
|
|
}
|
|
|
|
void PrintDriversList ()
|
|
|
|
{
|
|
|
|
Printf("Null sound module uses no drivers.\n");
|
|
|
|
}
|
|
|
|
FString GatherStats ()
|
|
|
|
{
|
|
|
|
return "Null sound module has no stats.";
|
|
|
|
}
|
|
|
|
};
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
void I_InitSound ()
|
|
|
|
{
|
|
|
|
/* Get command line options: */
|
2010-10-05 22:35:59 +00:00
|
|
|
nosound = !!Args->CheckParm ("-nosound");
|
2010-08-28 13:36:41 +00:00
|
|
|
nosfx = !!Args->CheckParm ("-nosfx");
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
if (nosound)
|
|
|
|
{
|
2008-07-01 01:28:22 +00:00
|
|
|
GSnd = new NullSoundRenderer;
|
2006-02-24 04:48:15 +00:00
|
|
|
I_InitMusic ();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-08-13 07:07:26 +00:00
|
|
|
if(stricmp(snd_backend, "null") == 0)
|
|
|
|
GSnd = new NullSoundRenderer;
|
|
|
|
#ifndef NO_FMOD
|
|
|
|
else if(stricmp(snd_backend, "fmod") == 0)
|
|
|
|
GSnd = new FMODSoundRenderer;
|
|
|
|
#endif
|
|
|
|
#ifndef NO_OPENAL
|
|
|
|
else if(stricmp(snd_backend, "openal") == 0)
|
|
|
|
GSnd = new OpenALSoundRenderer;
|
|
|
|
#endif
|
|
|
|
if (!GSnd || !GSnd->IsValid ())
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-09-09 20:49:53 +00:00
|
|
|
I_CloseSound();
|
2008-07-01 01:28:22 +00:00
|
|
|
GSnd = new NullSoundRenderer;
|
- The garbage collector is now run one last time just before exiting the game.
- Removed movie volume from the sound menu and renamed some of the other
options to give the MIDI device name more room to display itself.
- Moved the midi device selection into the main sound menu.
- Added FMOD as MIDI device -1, to replace the MIDI mapper. This is still the
default device. By default, it uses exactly the same DLS instruments as the
Microsoft GS Wavetable Synth. If you have another set DLS level 1 patch set
you want to use, set the snd_midipatchfile cvar to specify where it should
load the instruments from.
- Changed the ProduceMIDI function to store its output into a TArray<BYTE>.
An overloaded version wraps around it to continue to supply file-writing
support for external Timidity++ usage.
- Added an FMOD credits banner to comply with their non-commercial license.
- Reimplemented the snd_buffersize cvar for the FMOD Ex sound system. Rather
than a time in ms, this is now the length in samples of the DSP buffer.
Also added the snd_buffercount cvar to offer complete control over the
call to FMOD::System::setDSPBufferSize(). Note that with any snd_samplerate
below about 44kHz, you will need to set snd_buffersize to avoid long
latencies.
- Reimplemented the snd_output cvar for the FMOD Ex sound system.
- Changed snd_samplerate default to 0. This now means to use the default
sample rate.
- Made snd_output, snd_output_format, snd_speakermode, snd_resampler, and
snd_hrtf available through the menu.
- Split the HRTF effect selection into its own cvar: snd_hrtf.
- Removed 96000 Hz option from the menu. It's still available through the
cvar, if desired.
- Fixed: If Windows sound init failed, retry with DirectSound. (Apparently,
WASAPI doesn't work with more than two speakers and PCM-Float output at the
same time.)
- Fixed: Area sounds only played from the front speakers once you got within
the 2D panning area.
SVN r854 (trunk)
2008-03-26 04:27:07 +00:00
|
|
|
Printf (TEXTCOLOR_RED"Sound init failed. Using nosound.\n");
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
I_InitMusic ();
|
|
|
|
snd_sfxvolume.Callback ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-09 20:49:53 +00:00
|
|
|
void I_CloseSound ()
|
|
|
|
{
|
|
|
|
// Free all loaded samples
|
|
|
|
for (unsigned i = 0; i < S_sfx.Size(); i++)
|
|
|
|
{
|
|
|
|
S_UnloadSound(&S_sfx[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
delete GSnd;
|
|
|
|
GSnd = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void I_ShutdownSound()
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
if (GSnd != NULL)
|
|
|
|
{
|
2008-09-09 20:49:53 +00:00
|
|
|
S_StopAllChannels();
|
|
|
|
I_CloseSound();
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-28 08:25:25 +00:00
|
|
|
const char *GetSampleTypeName(enum SampleType type)
|
|
|
|
{
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case SampleType_UInt8: return "Unsigned 8-bit";
|
|
|
|
case SampleType_Int16: return "Signed 16-bit";
|
|
|
|
}
|
|
|
|
return "(invalid sample type)";
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *GetChannelConfigName(enum ChannelConfig chan)
|
|
|
|
{
|
|
|
|
switch(chan)
|
|
|
|
{
|
|
|
|
case ChannelConfig_Mono: return "Mono";
|
|
|
|
case ChannelConfig_Stereo: return "Stereo";
|
|
|
|
}
|
|
|
|
return "(invalid channel config)";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
CCMD (snd_status)
|
|
|
|
{
|
2008-07-01 01:28:22 +00:00
|
|
|
GSnd->PrintStatus ();
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CCMD (snd_reset)
|
|
|
|
{
|
- The sound code now handles restarting looping sounds itself. As far as
the rest of the game is concerned, these sounds will never stop once they
have been started until they are explicitly stopped. If they are evicted
from their channels, the sound code will restart them as soon as possible.
This means that instead of this:
if (!S_IsActorPlayingSomething(actor, CHAN_WEAPON, -1))
{
S_Sound(actor, CHAN_WEAPON|CHAN_LOOP, soundid, 1, ATTN_NORM);
}
The following is now just as effective:
S_Sound(actor, CHAN_WEAPON|CHAN_LOOP, soundid, 1, ATTN_NORM);
There are also a couple of other ramifications presented by this change:
* The full state of the sound system (sans music) is now stored in save
games. Any sounds that were playing when you saved will still be
playing when you load. (Try saving while Korax is making a speech in
Hexen to hear it.)
* Using snd_reset will also preserve any playing sounds.
* Movie playback is disabled, probably forever. I did not want to
update the MovieDisable/ResumeSound stuff for the new eviction
tracking code. A properly updated movie player will use the VMR,
which doesn't need these functions, since it would pipe the sound
straight through the sound system like everything else, so I decided
to dump them now, which leaves the movie player in a totally unworkable
state.
June 26, 2008
- Changed S_Sound() to take the same floating point attenuation that the
internal S_StartSound() uses. Now ambient sounds can use the public
S_Sound() interface.
- Fixed: S_RelinkSound() compared the points of the channels against the
from actor's point, rather than checking the channels' mover.
- Changed Strife's animated doors so that their sounds originate from the
interior of the sector making them and not from the entire vertical height
of the map.
SVN r1055 (trunk)
2008-06-29 04:19:38 +00:00
|
|
|
I_ShutdownMusic();
|
|
|
|
S_EvictAllChannels();
|
2008-09-09 20:49:53 +00:00
|
|
|
I_CloseSound();
|
- The sound code now handles restarting looping sounds itself. As far as
the rest of the game is concerned, these sounds will never stop once they
have been started until they are explicitly stopped. If they are evicted
from their channels, the sound code will restart them as soon as possible.
This means that instead of this:
if (!S_IsActorPlayingSomething(actor, CHAN_WEAPON, -1))
{
S_Sound(actor, CHAN_WEAPON|CHAN_LOOP, soundid, 1, ATTN_NORM);
}
The following is now just as effective:
S_Sound(actor, CHAN_WEAPON|CHAN_LOOP, soundid, 1, ATTN_NORM);
There are also a couple of other ramifications presented by this change:
* The full state of the sound system (sans music) is now stored in save
games. Any sounds that were playing when you saved will still be
playing when you load. (Try saving while Korax is making a speech in
Hexen to hear it.)
* Using snd_reset will also preserve any playing sounds.
* Movie playback is disabled, probably forever. I did not want to
update the MovieDisable/ResumeSound stuff for the new eviction
tracking code. A properly updated movie player will use the VMR,
which doesn't need these functions, since it would pipe the sound
straight through the sound system like everything else, so I decided
to dump them now, which leaves the movie player in a totally unworkable
state.
June 26, 2008
- Changed S_Sound() to take the same floating point attenuation that the
internal S_StartSound() uses. Now ambient sounds can use the public
S_Sound() interface.
- Fixed: S_RelinkSound() compared the points of the channels against the
from actor's point, rather than checking the channels' mover.
- Changed Strife's animated doors so that their sounds originate from the
interior of the sector making them and not from the entire vertical height
of the map.
SVN r1055 (trunk)
2008-06-29 04:19:38 +00:00
|
|
|
I_InitSound();
|
|
|
|
S_RestartMusic();
|
|
|
|
S_RestoreEvictedChannels();
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CCMD (snd_listdrivers)
|
|
|
|
{
|
2008-07-01 01:28:22 +00:00
|
|
|
GSnd->PrintDriversList ();
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
2006-09-14 00:02:31 +00:00
|
|
|
ADD_STAT (sound)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-07-01 01:28:22 +00:00
|
|
|
return GSnd->GatherStats ();
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SoundRenderer::SoundRenderer ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SoundRenderer::~SoundRenderer ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-09-14 00:02:31 +00:00
|
|
|
FString SoundRenderer::GatherStats ()
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2006-09-14 00:02:31 +00:00
|
|
|
return "No stats for this sound renderer.";
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
2014-06-20 05:40:45 +00:00
|
|
|
short *SoundRenderer::DecodeSample(int outlen, const void *coded, int sizebytes, ECodecType ctype)
|
2008-05-29 23:33:07 +00:00
|
|
|
{
|
2014-06-25 11:25:36 +00:00
|
|
|
MemoryReader reader((const char*)coded, sizebytes);
|
2014-06-20 05:40:45 +00:00
|
|
|
short *samples = (short*)calloc(1, outlen);
|
|
|
|
ChannelConfig chans;
|
|
|
|
SampleType type;
|
|
|
|
int srate;
|
|
|
|
|
2014-06-25 11:25:36 +00:00
|
|
|
std::auto_ptr<SoundDecoder> decoder(CreateDecoder(&reader));
|
2014-06-20 05:40:45 +00:00
|
|
|
if(!decoder.get()) return samples;
|
|
|
|
|
|
|
|
decoder->getInfo(&srate, &chans, &type);
|
|
|
|
if(chans != ChannelConfig_Mono || type != SampleType_Int16)
|
|
|
|
{
|
|
|
|
DPrintf("Sample is not 16-bit mono\n");
|
|
|
|
return samples;
|
|
|
|
}
|
|
|
|
|
|
|
|
decoder->read((char*)samples, outlen);
|
|
|
|
return samples;
|
2008-05-29 23:33:07 +00:00
|
|
|
}
|
|
|
|
|
2008-04-11 04:59:23 +00:00
|
|
|
void SoundRenderer::DrawWaveDebug(int mode)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
SoundStream::~SoundStream ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-08-03 03:54:48 +00:00
|
|
|
bool SoundStream::SetPosition(unsigned int pos)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SoundStream::SetOrder(int order)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
VERY IMPORTANT NOTE FOR ANYBODY BUILDING FROM THE TRUNK: This commit adds support
for FMOD Ex while at the same time removing support for FMOD 3. Be sure to update
your SDKs. GCC users, be sure to do a "make cleandep && make clean" before
building, or you will likely get inexplicable errors.
- Fixed: If you wanted to make cleandep with MinGW, you had to specifically
specify Makefile.mingw as the makefile to use.
- Added a normalizer to the OPL synth. It helped bring up the volume a little,
but not nearly as much as I would have liked.
- Removed MIDI Mapper references. It doesn't work with the stream API, and
it doesn't really exist on NT kernels, either.
- Reworked music volume: Except for MIDI, all music volume is controlled
through GSnd and not at the individual song level.
- Removed the mididevice global variable.
- Removed snd_midivolume. Now that all music uses a linear volume scale,
there's no need for two separate music volume controls.
- Increased snd_samplerate default up to 48000.
- Added snd_format, defaulting to "PCM-16".
- Added snd_speakermode, defaulting to "Auto".
- Replaced snd_fpu with snd_resampler, defaulting to "Linear".
- Bumped the snd_channels default up from a pitiful 12 to 32.
- Changed snd_3d default to true. The new cvar snd_hw3d determines if
hardware 3D support is used and default to false.
- Removed the libFLAC source, since FMOD Ex has native FLAC support.
- Removed the altsound code, since it was terribly gimped in comparison to
the FMOD code. It's original purpose was to have been as a springboard for
writing a non-FMOD sound system for Unix-y systems, but that never
happened.
- Finished preliminary FMOD Ex support.
SVN r789 (trunk)
2008-03-09 03:13:49 +00:00
|
|
|
return false;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
- The garbage collector is now run one last time just before exiting the game.
- Removed movie volume from the sound menu and renamed some of the other
options to give the MIDI device name more room to display itself.
- Moved the midi device selection into the main sound menu.
- Added FMOD as MIDI device -1, to replace the MIDI mapper. This is still the
default device. By default, it uses exactly the same DLS instruments as the
Microsoft GS Wavetable Synth. If you have another set DLS level 1 patch set
you want to use, set the snd_midipatchfile cvar to specify where it should
load the instruments from.
- Changed the ProduceMIDI function to store its output into a TArray<BYTE>.
An overloaded version wraps around it to continue to supply file-writing
support for external Timidity++ usage.
- Added an FMOD credits banner to comply with their non-commercial license.
- Reimplemented the snd_buffersize cvar for the FMOD Ex sound system. Rather
than a time in ms, this is now the length in samples of the DSP buffer.
Also added the snd_buffercount cvar to offer complete control over the
call to FMOD::System::setDSPBufferSize(). Note that with any snd_samplerate
below about 44kHz, you will need to set snd_buffersize to avoid long
latencies.
- Reimplemented the snd_output cvar for the FMOD Ex sound system.
- Changed snd_samplerate default to 0. This now means to use the default
sample rate.
- Made snd_output, snd_output_format, snd_speakermode, snd_resampler, and
snd_hrtf available through the menu.
- Split the HRTF effect selection into its own cvar: snd_hrtf.
- Removed 96000 Hz option from the menu. It's still available through the
cvar, if desired.
- Fixed: If Windows sound init failed, retry with DirectSound. (Apparently,
WASAPI doesn't work with more than two speakers and PCM-Float output at the
same time.)
- Fixed: Area sounds only played from the front speakers once you got within
the 2D panning area.
SVN r854 (trunk)
2008-03-26 04:27:07 +00:00
|
|
|
|
|
|
|
FString SoundStream::GetStats()
|
|
|
|
{
|
|
|
|
return "No stream stats available.";
|
|
|
|
}
|
2010-10-05 22:31:22 +00:00
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// SoundRenderer :: LoadSoundVoc
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
SoundHandle SoundRenderer::LoadSoundVoc(BYTE *sfxdata, int length)
|
|
|
|
{
|
|
|
|
BYTE * data = NULL;
|
|
|
|
int len, frequency, channels, bits, loopstart, loopend;
|
|
|
|
len = frequency = channels = bits = 0;
|
|
|
|
loopstart = loopend = -1;
|
|
|
|
do if (length > 26)
|
|
|
|
{
|
|
|
|
// First pass to parse data and validate the file
|
|
|
|
if (strncmp ((const char *)sfxdata, "Creative Voice File", 19))
|
|
|
|
break;
|
|
|
|
int i = 26, blocktype = 0, blocksize = 0, codec = -1;
|
|
|
|
bool noextra = true, okay = true;
|
|
|
|
while (i < length)
|
|
|
|
{
|
|
|
|
// Read block header
|
|
|
|
blocktype = sfxdata[i];
|
|
|
|
if (blocktype == 0)
|
|
|
|
break;
|
|
|
|
blocksize = sfxdata[i+1] + (sfxdata[i+2]<<8) + (sfxdata[i+3]<<16);
|
|
|
|
i += 4;
|
|
|
|
if (i + blocksize > length)
|
|
|
|
{
|
|
|
|
okay = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read block data
|
|
|
|
switch (blocktype)
|
|
|
|
{
|
|
|
|
case 1: // Sound data
|
|
|
|
if (noextra && (codec == -1 || codec == sfxdata[i+1]))
|
|
|
|
{
|
|
|
|
frequency = 1000000/(256 - sfxdata[i]);
|
|
|
|
channels = 1;
|
|
|
|
codec = sfxdata[i+1];
|
|
|
|
if (codec == 0)
|
|
|
|
bits = 8;
|
|
|
|
else if (codec == 4)
|
|
|
|
bits = -16;
|
|
|
|
else okay = false;
|
|
|
|
len += blocksize - 2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2: // Sound data continuation
|
|
|
|
if (codec == -1)
|
|
|
|
okay = false;
|
|
|
|
len += blocksize;
|
|
|
|
break;
|
|
|
|
case 3: // Silence
|
|
|
|
if (frequency == 1000000/(256 - sfxdata[i+2]))
|
|
|
|
{
|
|
|
|
int silength = 1 + sfxdata[i] + (sfxdata[i+1]<<8);
|
|
|
|
if (codec == 0) // 8-bit unsigned PCM
|
|
|
|
len += silength;
|
|
|
|
else if (codec == 4) // 16-bit signed PCM
|
|
|
|
len += silength<<1;
|
|
|
|
else okay = false;
|
|
|
|
} else okay = false;
|
|
|
|
break;
|
|
|
|
case 4: // Mark (ignored)
|
|
|
|
case 5: // Text (ignored)
|
|
|
|
break;
|
|
|
|
case 6: // Repeat start
|
|
|
|
loopstart = len;
|
|
|
|
break;
|
|
|
|
case 7: // Repeat end
|
|
|
|
loopend = len;
|
|
|
|
if (loopend < loopstart)
|
|
|
|
okay = false;
|
|
|
|
break;
|
|
|
|
case 8: // Extra info
|
|
|
|
noextra = false;
|
|
|
|
if (codec == -1)
|
|
|
|
{
|
|
|
|
codec = sfxdata[i+2];
|
|
|
|
channels = 1+sfxdata[i+3];
|
|
|
|
frequency = 256000000/(channels * (65536 - (sfxdata[i]+(sfxdata[i+1]<<8))));
|
|
|
|
} else okay = false;
|
|
|
|
break;
|
|
|
|
case 9: // Sound data in new format
|
|
|
|
if (codec == -1)
|
|
|
|
{
|
|
|
|
frequency = sfxdata[i] + (sfxdata[i+1]<<8) + (sfxdata[i+2]<<16) + (sfxdata[i+3]<<24);
|
|
|
|
bits = sfxdata[i+4];
|
|
|
|
channels = sfxdata[i+5];
|
|
|
|
codec = sfxdata[i+6] + (sfxdata[i+7]<<8);
|
|
|
|
if (codec == 0)
|
|
|
|
bits = 8;
|
|
|
|
else if (codec == 4)
|
|
|
|
bits = -16;
|
|
|
|
else okay = false;
|
|
|
|
len += blocksize - 12;
|
|
|
|
} else okay = false;
|
|
|
|
break;
|
|
|
|
default: // Unknown block type
|
|
|
|
okay = false;
|
|
|
|
DPrintf ("Unknown VOC block type %i\n", blocktype);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Move to next block
|
|
|
|
i += blocksize;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Second pass to write the data
|
|
|
|
if (okay)
|
|
|
|
{
|
|
|
|
data = new BYTE[len];
|
|
|
|
i = 26;
|
|
|
|
int j = 0;
|
|
|
|
while (i < length)
|
|
|
|
{
|
|
|
|
// Read block header again
|
|
|
|
blocktype = sfxdata[i];
|
|
|
|
if (blocktype == 0) break;
|
|
|
|
blocksize = sfxdata[i+1] + (sfxdata[i+2]<<8) + (sfxdata[i+3]<<16);
|
|
|
|
i += 4;
|
|
|
|
switch (blocktype)
|
|
|
|
{
|
|
|
|
case 1: memcpy(data+j, sfxdata+i+2, blocksize-2 ); j += blocksize-2; break;
|
|
|
|
case 2: memcpy(data+j, sfxdata+i, blocksize ); j += blocksize; break;
|
|
|
|
case 9: memcpy(data+j, sfxdata+i+12, blocksize-12); j += blocksize-12; break;
|
|
|
|
case 3:
|
|
|
|
{
|
|
|
|
int silength = 1 + sfxdata[i] + (sfxdata[i+1]<<8);
|
|
|
|
if (bits == 8)
|
|
|
|
{
|
|
|
|
memset(data+j, 128, silength);
|
|
|
|
j += silength;
|
|
|
|
}
|
|
|
|
else if (bits == -16)
|
|
|
|
{
|
|
|
|
memset(data+j, 0, silength<<1);
|
|
|
|
j += silength<<1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
2014-09-15 09:32:40 +00:00
|
|
|
i += blocksize;
|
2010-10-05 22:31:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} while (false);
|
|
|
|
SoundHandle retval = LoadSoundRaw(data, len, frequency, channels, bits, loopstart, loopend);
|
|
|
|
if (data) delete[] data;
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2014-06-25 11:25:36 +00:00
|
|
|
SoundStream *SoundRenderer::OpenStream(const char *url, int flags)
|
2014-06-19 08:00:46 +00:00
|
|
|
{
|
2014-06-25 11:25:36 +00:00
|
|
|
return 0;
|
2014-06-19 11:13:42 +00:00
|
|
|
}
|
|
|
|
|
2014-06-25 11:25:36 +00:00
|
|
|
SoundDecoder *SoundRenderer::CreateDecoder(FileReader *reader)
|
2014-06-19 11:13:42 +00:00
|
|
|
{
|
|
|
|
SoundDecoder *decoder = NULL;
|
2014-06-25 11:25:36 +00:00
|
|
|
int pos = reader->Tell();
|
|
|
|
|
2014-06-20 03:14:16 +00:00
|
|
|
#ifdef HAVE_MPG123
|
2015-04-25 10:25:10 +00:00
|
|
|
decoder = new MPG123Decoder;
|
|
|
|
if (decoder->open(reader))
|
|
|
|
return decoder;
|
|
|
|
reader->Seek(pos, SEEK_SET);
|
2014-06-20 05:46:46 +00:00
|
|
|
|
2015-04-25 10:25:10 +00:00
|
|
|
delete decoder;
|
|
|
|
decoder = NULL;
|
2014-06-20 03:14:16 +00:00
|
|
|
#endif
|
2014-06-19 11:13:42 +00:00
|
|
|
#ifdef HAVE_SNDFILE
|
2015-04-25 10:25:10 +00:00
|
|
|
decoder = new SndFileDecoder;
|
|
|
|
if (decoder->open(reader))
|
|
|
|
return decoder;
|
|
|
|
reader->Seek(pos, SEEK_SET);
|
2014-06-20 05:46:46 +00:00
|
|
|
|
2015-04-25 10:25:10 +00:00
|
|
|
delete decoder;
|
|
|
|
decoder = NULL;
|
2014-06-19 11:13:42 +00:00
|
|
|
#endif
|
|
|
|
return decoder;
|
2014-06-19 08:00:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Default readAll implementation, for decoders that can't do anything better
|
2014-06-28 04:51:05 +00:00
|
|
|
TArray<char> SoundDecoder::readAll()
|
2014-06-19 08:00:46 +00:00
|
|
|
{
|
2014-06-28 04:51:05 +00:00
|
|
|
TArray<char> output;
|
2014-06-19 08:00:46 +00:00
|
|
|
size_t total = 0;
|
|
|
|
size_t got;
|
|
|
|
|
2014-06-28 04:51:05 +00:00
|
|
|
output.Resize(total+32768);
|
|
|
|
while((got=read(&output[total], output.Size()-total)) > 0)
|
2014-06-19 08:00:46 +00:00
|
|
|
{
|
|
|
|
total += got;
|
2014-06-28 04:51:05 +00:00
|
|
|
output.Resize(total*2);
|
2014-06-19 08:00:46 +00:00
|
|
|
}
|
2014-06-28 04:51:05 +00:00
|
|
|
output.Resize(total);
|
2014-06-19 08:00:46 +00:00
|
|
|
return output;
|
|
|
|
}
|