- Separated low level sound code from all high level dependencies.

SVN r1228 (trunk)
This commit is contained in:
Christoph Oelckers 2008-09-15 18:18:04 +00:00
parent 5d9483b632
commit d1f8518a79
10 changed files with 203 additions and 152 deletions

View file

@ -1,4 +1,7 @@
September 15, 2008 (Changes by Graf Zahl)
- Separated low level sound code from all high level dependencies.
- Separated low level sound channel class from high level class which now
is just a subclass of the low level class.
- Moved some more high level sound logic out of FMODSoundRenderer:
The rolloff and channel ended callbacks now call functions in s_sound.cpp
instead of working on the data itself and GSnd->StopSound has been replaced

View file

@ -538,7 +538,7 @@ void S_UnloadSound (sfxinfo_t *sfx)
//
//==========================================================================
FSoundChan *S_GetChannel(void *syschan)
FISoundChannel *S_GetChannel(void *syschan)
{
FSoundChan *chan;
@ -1007,19 +1007,27 @@ static FSoundChan *S_StartSound(AActor *actor, const sector_t *sec, const FPolyO
{
chan = NULL;
}
else if (attenuation > 0)
else
{
SoundListener listener;
S_SetListener(listener, players[consoleplayer].camera);
chan = GSnd->StartSound3D (sfx->data, &listener, volume, rolloff, attenuation, pitch, basepriority, pos, vel, channel, chanflags, NULL);
}
else
{
chan = GSnd->StartSound (sfx->data, volume, pitch, chanflags, NULL);
int startflags = 0;
if (chanflags & CHAN_LOOP) startflags |= SNDF_LOOP;
if (chanflags & CHAN_AREA) startflags |= SNDF_AREA;
if (chanflags & (CHAN_UI|CHAN_NOPAUSE)) startflags |= SNDF_NOPAUSE;
if (attenuation > 0)
{
SoundListener listener;
S_SetListener(listener, players[consoleplayer].camera);
chan = (FSoundChan*)GSnd->StartSound3D (sfx->data, &listener, volume, rolloff, attenuation, pitch, basepriority, pos, vel, channel, startflags, NULL);
}
else
{
chan = (FSoundChan*)GSnd->StartSound (sfx->data, volume, pitch, startflags, NULL);
}
}
if (chan == NULL && (chanflags & CHAN_LOOP))
{
chan = S_GetChannel(NULL);
chan = (FSoundChan*)S_GetChannel(NULL);
chanflags |= CHAN_EVICTED;
}
if (attenuation > 0)
@ -1083,6 +1091,15 @@ void S_RestartSound(FSoundChan *chan)
return;
}
int oldflags = chan->ChanFlags;
int startflags = 0;
if (chan->ChanFlags & CHAN_LOOP) startflags |= SNDF_LOOP;
if (chan->ChanFlags & CHAN_AREA) startflags |= SNDF_AREA;
if (chan->ChanFlags & (CHAN_UI|CHAN_NOPAUSE)) startflags |= SNDF_NOPAUSE;
if (chan->ChanFlags & CHAN_ABSTIME) startflags |= SNDF_ABSTIME;
chan->ChanFlags &= ~(CHAN_EVICTED|CHAN_ABSTIME);
if (chan->ChanFlags & CHAN_IS3D)
{
FVector3 pos, vel;
@ -1099,17 +1116,16 @@ void S_RestartSound(FSoundChan *chan)
SoundListener listener;
S_SetListener(listener, players[consoleplayer].camera);
ochan = GSnd->StartSound3D(sfx->data, &listener, chan->Volume, &chan->Rolloff, chan->DistanceScale, chan->Pitch,
chan->Priority, pos, vel, chan->EntChannel, chan->ChanFlags, chan);
ochan = (FSoundChan*)GSnd->StartSound3D(sfx->data, &listener, chan->Volume, &chan->Rolloff, chan->DistanceScale, chan->Pitch,
chan->Priority, pos, vel, chan->EntChannel, startflags, chan);
}
else
{
ochan = GSnd->StartSound(sfx->data, chan->Volume, chan->Pitch, chan->ChanFlags, chan);
ochan = (FSoundChan*)GSnd->StartSound(sfx->data, chan->Volume, chan->Pitch, startflags, chan);
}
assert(ochan == NULL || ochan == chan);
if (ochan != NULL)
{
ochan->ChanFlags &= ~CHAN_EVICTED;
// When called from the savegame loader, the actor's SoundChans
// flags will be cleared. During normal gameplay, they should still
// be set.
@ -1118,6 +1134,7 @@ void S_RestartSound(FSoundChan *chan)
if (ochan->Actor != NULL) ochan->Actor->SoundChans |= 1 << ochan->EntChannel;
}
}
else chan->ChanFlags = oldflags;
}
//==========================================================================
@ -1699,7 +1716,7 @@ void S_UpdateSounds (AActor *listenactor)
if ((chan->ChanFlags & (CHAN_EVICTED | CHAN_IS3D)) == CHAN_IS3D)
{
CalcPosVel(chan, &pos, &vel);
GSnd->UpdateSoundParams3D(&listener, chan, pos, vel);
GSnd->UpdateSoundParams3D(&listener, chan, !!(chan->ChanFlags & CHAN_AREA), pos, vel);
}
chan->ChanFlags &= ~CHAN_JUSTSTARTED;
}
@ -1803,8 +1820,9 @@ float S_GetRolloff(FRolloffInfo *rolloff, float distance)
//
//==========================================================================
void S_ChannelEnded(FSoundChan *schan)
void S_ChannelEnded(FISoundChannel *ichan)
{
FSoundChan *schan = static_cast<FSoundChan*>(ichan);
bool evicted;
if (schan != NULL)
@ -1981,7 +1999,7 @@ void S_SerializeSounds(FArchive &arc)
count = arc.ReadCount();
for (unsigned int i = 0; i < count; ++i)
{
chan = S_GetChannel(NULL);
chan = (FSoundChan*)S_GetChannel(NULL);
arc << *chan;
// Sounds always start out evicted when restored from a save.
chan->ChanFlags |= CHAN_EVICTED | CHAN_ABSTIME;

View file

@ -22,26 +22,11 @@
#define __S_SOUND__
#include "doomtype.h"
#include "i_soundinternal.h"
class AActor;
class FScanner;
// Default rolloff information.
struct FRolloffInfo
{
int RolloffType;
float MinDistance;
union { float MaxDistance; float RolloffFactor; };
};
struct SoundHandle
{
void *data;
bool isValid() const { return data != NULL; }
void Clear() { data = NULL; }
};
//
// SoundFX struct.
//
@ -178,18 +163,14 @@ extern int S_SoundCurveSize;
// Information about one playing sound.
struct sector_t;
struct FPolyObj;
struct FSoundChan
struct FSoundChan : public FISoundChannel
{
void *SysChannel;// Channel information from the system interface.
FSoundChan *NextChan; // Next channel in this list.
FSoundChan **PrevChan; // Previous channel in this list.
sfxinfo_t *SfxInfo; // Sound information.
FRolloffInfo Rolloff; // Rolloff parameters (do not necessarily come from SfxInfo!)
QWORD_UNION StartTime; // Sound start time in DSP clocks.
FSoundID SoundID; // Sound ID of playing sound.
FSoundID OrgID; // Sound ID of sound used to start this channel.
float Volume;
float DistanceScale;
int ChanFlags;
SWORD Pitch; // Pitch variation.
BYTE EntChannel; // Actor's sound channel.
@ -206,7 +187,6 @@ struct FSoundChan
};
extern FSoundChan *Channels;
FSoundChan *S_GetChannel(void *syschan);
void S_ReturnChannel(FSoundChan *chan);
void S_EvictAllChannels();
@ -371,64 +351,6 @@ unsigned int S_GetMSLength(FSoundID sound);
// Modelled after Hexen's noise cheat.
void S_NoiseDebug ();
// For convenience, this structure matches FMOD_REVERB_PROPERTIES.
// Since I can't very well #include system-specific stuff in the
// main game files, I duplicate it here.
struct REVERB_PROPERTIES
{
int Instance;
int Environment;
float EnvSize;
float EnvDiffusion;
int Room;
int RoomHF;
int RoomLF;
float DecayTime;
float DecayHFRatio;
float DecayLFRatio;
int Reflections;
float ReflectionsDelay;
float ReflectionsPan0;
float ReflectionsPan1;
float ReflectionsPan2;
int Reverb;
float ReverbDelay;
float ReverbPan0;
float ReverbPan1;
float ReverbPan2;
float EchoTime;
float EchoDepth;
float ModulationTime;
float ModulationDepth;
float AirAbsorptionHF;
float HFReference;
float LFReference;
float RoomRolloffFactor;
float Diffusion;
float Density;
unsigned int Flags;
};
#define REVERB_FLAGS_DECAYTIMESCALE 0x00000001
#define REVERB_FLAGS_REFLECTIONSSCALE 0x00000002
#define REVERB_FLAGS_REFLECTIONSDELAYSCALE 0x00000004
#define REVERB_FLAGS_REVERBSCALE 0x00000008
#define REVERB_FLAGS_REVERBDELAYSCALE 0x00000010
#define REVERB_FLAGS_DECAYHFLIMIT 0x00000020
#define REVERB_FLAGS_ECHOTIMESCALE 0x00000040
#define REVERB_FLAGS_MODULATIONTIMESCALE 0x00000080
struct ReverbContainer
{
ReverbContainer *Next;
const char *Name;
WORD ID;
bool Builtin;
bool Modified;
REVERB_PROPERTIES Properties;
bool SoftwareWater;
};
extern ReverbContainer *Environments;
extern ReverbContainer *DefaultEnvironments[26];

View file

@ -49,7 +49,6 @@ extern HWND Window;
#include "fmodsound.h"
#include "c_cvars.h"
#include "i_system.h"
#include "w_wad.h"
#include "i_music.h"
#include "v_text.h"
#include "v_video.h"
@ -1328,7 +1327,7 @@ SoundStream *FMODSoundRenderer::OpenStream(const char *filename_or_data, int fla
//
//==========================================================================
FSoundChan *FMODSoundRenderer::StartSound(SoundHandle sfx, float vol, int pitch, int chanflags, FSoundChan *reuse_chan)
FISoundChannel *FMODSoundRenderer::StartSound(SoundHandle sfx, float vol, int pitch, int flags, FISoundChannel *reuse_chan)
{
FMOD_RESULT result;
FMOD_MODE mode;
@ -1356,18 +1355,18 @@ FSoundChan *FMODSoundRenderer::StartSound(SoundHandle sfx, float vol, int pitch,
mode = FMOD_SOFTWARE;
}
mode = (mode & ~FMOD_3D) | FMOD_2D;
if (chanflags & CHAN_LOOP)
if (flags & SNDF_LOOP)
{
mode = (mode & ~FMOD_LOOP_OFF) | FMOD_LOOP_NORMAL;
}
chan->setMode(mode);
chan->setChannelGroup((chanflags & (CHAN_UI | CHAN_NOPAUSE)) ? SfxGroup : PausableSfx);
chan->setChannelGroup((flags & SNDF_NOPAUSE) ? SfxGroup : PausableSfx);
if (freq != 0)
{
chan->setFrequency(freq);
}
chan->setVolume(vol);
HandleChannelDelay(chan, reuse_chan, freq);
HandleChannelDelay(chan, reuse_chan, !!(flags & SNDF_ABSTIME), freq);
chan->setPaused(false);
return CommonChannelSetup(chan, reuse_chan);
}
@ -1384,10 +1383,10 @@ FSoundChan *FMODSoundRenderer::StartSound(SoundHandle sfx, float vol, int pitch,
CVAR(Float, snd_3dspread, 180, 0)
FSoundChan *FMODSoundRenderer::StartSound3D(SoundHandle sfx, SoundListener *listener, float vol,
FISoundChannel *FMODSoundRenderer::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, FSoundChan *reuse_chan)
int channum, int flags, FISoundChannel *reuse_chan)
{
FMOD_RESULT result;
FMOD_MODE mode;
@ -1443,13 +1442,13 @@ FSoundChan *FMODSoundRenderer::StartSound3D(SoundHandle sfx, SoundListener *list
{
mode = FMOD_3D | FMOD_SOFTWARE;
}
if (chanflags & CHAN_LOOP)
if (flags & SNDF_LOOP)
{
mode = (mode & ~FMOD_LOOP_OFF) | FMOD_LOOP_NORMAL;
}
mode = SetChanHeadSettings(listener, chan, pos, channum, chanflags, mode);
mode = SetChanHeadSettings(listener, chan, pos, !!(flags & SNDF_AREA), mode);
chan->setMode(mode);
chan->setChannelGroup((chanflags & (CHAN_UI | CHAN_NOPAUSE)) ? SfxGroup : PausableSfx);
chan->setChannelGroup((flags & SNDF_NOPAUSE) ? SfxGroup : PausableSfx);
if (freq != 0)
{
@ -1461,9 +1460,9 @@ FSoundChan *FMODSoundRenderer::StartSound3D(SoundHandle sfx, SoundListener *list
chan->set3DAttributes((FMOD_VECTOR *)&pos[0], (FMOD_VECTOR *)&vel[0]);
chan->set3DSpread(snd_3dspread);
}
HandleChannelDelay(chan, reuse_chan, freq);
HandleChannelDelay(chan, reuse_chan, !!(flags & SNDF_ABSTIME), freq);
chan->setPaused(false);
FSoundChan *schan = CommonChannelSetup(chan, reuse_chan);
FISoundChannel *schan = CommonChannelSetup(chan, reuse_chan);
schan->Rolloff = *rolloff;
return schan;
}
@ -1482,7 +1481,7 @@ FSoundChan *FMODSoundRenderer::StartSound3D(SoundHandle sfx, SoundListener *list
//
//==========================================================================
void FMODSoundRenderer::HandleChannelDelay(FMOD::Channel *chan, FSoundChan *reuse_chan, float freq) const
void FMODSoundRenderer::HandleChannelDelay(FMOD::Channel *chan, FISoundChannel *reuse_chan, bool abstime, float freq) const
{
if (reuse_chan != NULL)
{ // Sound is being restarted, so seek it to the position
@ -1490,9 +1489,9 @@ void FMODSoundRenderer::HandleChannelDelay(FMOD::Channel *chan, FSoundChan *reus
QWORD_UNION nowtime;
chan->getDelay(FMOD_DELAYTYPE_DSPCLOCK_START, &nowtime.Hi, &nowtime.Lo);
// If CHAN_ABSTIME is set, the sound is being restored, and
// If abstime is set, the sound is being restored, and
// the channel's start time is actually its seek position.
if (reuse_chan->ChanFlags & CHAN_ABSTIME)
if (abstime)
{
unsigned int seekpos = reuse_chan->StartTime.Lo;
if (seekpos > 0)
@ -1500,7 +1499,6 @@ void FMODSoundRenderer::HandleChannelDelay(FMOD::Channel *chan, FSoundChan *reus
chan->setPosition(seekpos, FMOD_TIMEUNIT_PCM);
}
reuse_chan->StartTime.AsOne = QWORD(nowtime.AsOne - seekpos * OutputRate / freq);
reuse_chan->ChanFlags &= ~CHAN_ABSTIME;
}
else
{
@ -1528,7 +1526,7 @@ void FMODSoundRenderer::HandleChannelDelay(FMOD::Channel *chan, FSoundChan *reus
//==========================================================================
FMOD_MODE FMODSoundRenderer::SetChanHeadSettings(SoundListener *listener, FMOD::Channel *chan,
const FVector3 &pos, int channum, int chanflags,
const FVector3 &pos, bool areasound,
FMOD_MODE oldmode) const
{
if (!listener->valid)
@ -1539,7 +1537,7 @@ FMOD_MODE FMODSoundRenderer::SetChanHeadSettings(SoundListener *listener, FMOD::
cpos = listener->position;
if (chanflags & CHAN_AREA)
if (areasound)
{
float level, old_level;
@ -1589,14 +1587,13 @@ FMOD_MODE FMODSoundRenderer::SetChanHeadSettings(SoundListener *listener, FMOD::
//
//==========================================================================
FSoundChan *FMODSoundRenderer::CommonChannelSetup(FMOD::Channel *chan, FSoundChan *reuse_chan) const
FISoundChannel *FMODSoundRenderer::CommonChannelSetup(FMOD::Channel *chan, FISoundChannel *reuse_chan) const
{
FSoundChan *schan;
FISoundChannel *schan;
if (reuse_chan != NULL)
{
schan = reuse_chan;
schan->ChanFlags &= ~CHAN_EVICTED;
schan->SysChannel = chan;
}
else
@ -1616,7 +1613,7 @@ FSoundChan *FMODSoundRenderer::CommonChannelSetup(FMOD::Channel *chan, FSoundCha
//
//==========================================================================
void FMODSoundRenderer::StopChannel(FSoundChan *chan)
void FMODSoundRenderer::StopChannel(FISoundChannel *chan)
{
if (chan != NULL && chan->SysChannel != NULL)
{
@ -1632,7 +1629,7 @@ void FMODSoundRenderer::StopChannel(FSoundChan *chan)
//
//==========================================================================
unsigned int FMODSoundRenderer::GetPosition(FSoundChan *chan)
unsigned int FMODSoundRenderer::GetPosition(FISoundChannel *chan)
{
unsigned int pos;
@ -1697,7 +1694,7 @@ void FMODSoundRenderer::SetInactive(bool inactive)
//
//==========================================================================
void FMODSoundRenderer::UpdateSoundParams3D(SoundListener *listener, FSoundChan *chan, const FVector3 &pos, const FVector3 &vel)
void FMODSoundRenderer::UpdateSoundParams3D(SoundListener *listener, FISoundChannel *chan, bool areasound, const FVector3 &pos, const FVector3 &vel)
{
if (chan == NULL || chan->SysChannel == NULL)
return;
@ -1709,7 +1706,7 @@ void FMODSoundRenderer::UpdateSoundParams3D(SoundListener *listener, FSoundChan
{
oldmode = FMOD_3D | FMOD_SOFTWARE;
}
mode = SetChanHeadSettings(listener, fchan, pos, chan->EntChannel, chan->ChanFlags, oldmode);
mode = SetChanHeadSettings(listener, fchan, pos, areasound, oldmode);
if (mode != oldmode)
{ // Only set the mode if it changed.
fchan->setMode(mode);
@ -2017,7 +2014,7 @@ FMOD_RESULT F_CALLBACK FMODSoundRenderer::ChannelEndCallback
{
assert(type == FMOD_CHANNEL_CALLBACKTYPE_END);
FMOD::Channel *chan = (FMOD::Channel *)channel;
FSoundChan *schan;
FISoundChannel *schan;
if (chan->getUserData((void **)&schan) == FMOD_OK && schan != NULL)
{
@ -2038,7 +2035,7 @@ FMOD_RESULT F_CALLBACK FMODSoundRenderer::ChannelEndCallback
float F_CALLBACK FMODSoundRenderer::RolloffCallback(FMOD_CHANNEL *channel, float distance)
{
FMOD::Channel *chan = (FMOD::Channel *)channel;
FSoundChan *schan;
FISoundChannel *schan;
if (GRolloff != NULL)
{

View file

@ -27,14 +27,14 @@ public:
void StopStream (SoundStream *stream);
// Starts a sound.
FSoundChan *StartSound (SoundHandle sfx, float vol, int pitch, int chanflags, FSoundChan *reuse_chan);
FSoundChan *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, FSoundChan *reuse_chan);
FISoundChannel *StartSound (SoundHandle sfx, float vol, int pitch, int chanflags, FISoundChannel *reuse_chan);
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);
// Stops a sound channel.
void StopChannel (FSoundChan *chan);
void StopChannel (FISoundChannel *chan);
// Returns position of sound on this channel, in samples.
unsigned int GetPosition(FSoundChan *chan);
unsigned int GetPosition(FISoundChannel *chan);
// Synchronizes following sound startups.
void Sync (bool sync);
@ -46,7 +46,7 @@ public:
void SetInactive (bool inactive);
// Updates the position of a sound channel.
void UpdateSoundParams3D (SoundListener *listener, FSoundChan *chan, const FVector3 &pos, const FVector3 &vel);
void UpdateSoundParams3D (SoundListener *listener, FISoundChannel *chan, bool areasound, const FVector3 &pos, const FVector3 &vel);
void UpdateListener (SoundListener *listener);
void UpdateSounds ();
@ -69,9 +69,9 @@ private:
(FMOD_CHANNEL *channel, FMOD_CHANNEL_CALLBACKTYPE type, int cmd, unsigned int data1, unsigned int data2);
static float F_CALLBACK RolloffCallback(FMOD_CHANNEL *channel, float distance);
void HandleChannelDelay(FMOD::Channel *chan, FSoundChan *reuse_chan, float freq) const;
FSoundChan *CommonChannelSetup(FMOD::Channel *chan, FSoundChan *reuse_chan) const;
FMOD_MODE SetChanHeadSettings(SoundListener *listener, FMOD::Channel *chan, const FVector3 &pos, int channum, int chanflags, FMOD_MODE oldmode) const;
void HandleChannelDelay(FMOD::Channel *chan, FISoundChannel *reuse_chan, bool abstime, float freq) const;
FISoundChannel *CommonChannelSetup(FMOD::Channel *chan, FISoundChannel *reuse_chan) const;
FMOD_MODE SetChanHeadSettings(SoundListener *listener, FMOD::Channel *chan, const FVector3 &pos, bool areasound, FMOD_MODE oldmode) const;
bool Init ();
void Shutdown ();

View file

@ -65,6 +65,7 @@ extern void ChildSigHandler (int signum);
#include "c_dispatch.h"
#include "i_system.h"
#include "i_sound.h"
#include "s_sound.h"
#include "m_swap.h"
#include "i_cd.h"
#include "tempfiles.h"

View file

@ -145,7 +145,7 @@ public:
{
return 11025; // Lies!
}
void StopChannel(FSoundChan *chan)
void StopChannel(FISoundChannel *chan)
{
}
@ -160,17 +160,17 @@ public:
}
// Starts a sound. (No, not really.)
FSoundChan *StartSound (SoundHandle sfx, float vol, int pitch, int chanflags, FSoundChan *reuse_chan)
FISoundChannel *StartSound (SoundHandle sfx, float vol, int pitch, int chanflags, FISoundChannel *reuse_chan)
{
return NULL;
}
FSoundChan *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, FSoundChan *reuse_chan)
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)
{
return NULL;
}
// Returns position of sound on this channel, in samples.
unsigned int GetPosition(FSoundChan *chan)
unsigned int GetPosition(FISoundChannel *chan)
{
return 0;
}
@ -191,7 +191,7 @@ public:
}
// Updates the volume, separation, and pitch of a sound channel.
void UpdateSoundParams3D (SoundListener *listener, FSoundChan *chan, const FVector3 &pos, const FVector3 &vel)
void UpdateSoundParams3D (SoundListener *listener, FISoundChannel *chan, bool areasound, const FVector3 &pos, const FVector3 &vel)
{
}

View file

@ -35,8 +35,8 @@
#ifndef __I_SOUND__
#define __I_SOUND__
#include "s_sound.h"
#include "vectors.h"
#include "doomtype.h"
#include "i_soundinternal.h"
enum ECodecType
{
@ -44,14 +44,12 @@ enum ECodecType
CODEC_Vorbis,
};
struct SoundListener
enum EStartSoundFlags
{
FVector3 position;
FVector3 velocity;
float angle;
bool underwater;
bool valid;
ReverbContainer *Environment;
SNDF_LOOP=1,
SNDF_NOPAUSE=2,
SNDF_AREA=4,
SNDF_ABSTIME=8
};
class SoundStream
@ -104,14 +102,14 @@ public:
virtual SoundStream *OpenStream (const char *filename, int flags, int offset, int length) = 0;
// Starts a sound.
virtual FSoundChan *StartSound (SoundHandle sfx, float vol, int pitch, int chanflags, FSoundChan *reuse_chan) = 0;
virtual FSoundChan *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, FSoundChan *reuse_chan) = 0;
virtual FISoundChannel *StartSound (SoundHandle sfx, float vol, int pitch, int chanflags, FISoundChannel *reuse_chan) = 0;
virtual 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) = 0;
// Stops a sound channel.
virtual void StopChannel (FSoundChan *chan) = 0;
virtual void StopChannel (FISoundChannel *chan) = 0;
// Returns position of sound on this channel, in samples.
virtual unsigned int GetPosition(FSoundChan *chan) = 0;
virtual unsigned int GetPosition(FISoundChannel *chan) = 0;
// Synchronizes following sound startups.
virtual void Sync (bool sync) = 0;
@ -123,7 +121,7 @@ public:
virtual void SetInactive(bool inactive) = 0;
// Updates the volume, separation, and pitch of a sound channel.
virtual void UpdateSoundParams3D (SoundListener *listener, FSoundChan *chan, const FVector3 &pos, const FVector3 &vel) = 0;
virtual void UpdateSoundParams3D (SoundListener *listener, FISoundChannel *chan, bool areasound, const FVector3 &pos, const FVector3 &vel) = 0;
virtual void UpdateListener (SoundListener *) = 0;
virtual void UpdateSounds () = 0;
@ -142,6 +140,10 @@ extern SoundRenderer *GSnd;
void I_InitSound ();
void I_ShutdownSound ();
void S_ChannelEnded(FSoundChan *schan);
void S_ChannelEnded(FISoundChannel *schan);
float S_GetRolloff(FRolloffInfo *rolloff, float distance);
FISoundChannel *S_GetChannel(void *syschan);
extern ReverbContainer *DefaultEnvironments[26];
#endif

104
src/sound/i_soundinternal.h Normal file
View file

@ -0,0 +1,104 @@
#ifndef __SNDINT_H
#define __SNDINT_H
#include "basictypes.h"
// For convenience, this structure matches FMOD_REVERB_PROPERTIES.
// Since I can't very well #include system-specific stuff in the
// main game files, I duplicate it here.
struct REVERB_PROPERTIES
{
int Instance;
int Environment;
float EnvSize;
float EnvDiffusion;
int Room;
int RoomHF;
int RoomLF;
float DecayTime;
float DecayHFRatio;
float DecayLFRatio;
int Reflections;
float ReflectionsDelay;
float ReflectionsPan0;
float ReflectionsPan1;
float ReflectionsPan2;
int Reverb;
float ReverbDelay;
float ReverbPan0;
float ReverbPan1;
float ReverbPan2;
float EchoTime;
float EchoDepth;
float ModulationTime;
float ModulationDepth;
float AirAbsorptionHF;
float HFReference;
float LFReference;
float RoomRolloffFactor;
float Diffusion;
float Density;
unsigned int Flags;
};
#define REVERB_FLAGS_DECAYTIMESCALE 0x00000001
#define REVERB_FLAGS_REFLECTIONSSCALE 0x00000002
#define REVERB_FLAGS_REFLECTIONSDELAYSCALE 0x00000004
#define REVERB_FLAGS_REVERBSCALE 0x00000008
#define REVERB_FLAGS_REVERBDELAYSCALE 0x00000010
#define REVERB_FLAGS_DECAYHFLIMIT 0x00000020
#define REVERB_FLAGS_ECHOTIMESCALE 0x00000040
#define REVERB_FLAGS_MODULATIONTIMESCALE 0x00000080
struct ReverbContainer
{
ReverbContainer *Next;
const char *Name;
WORD ID;
bool Builtin;
bool Modified;
REVERB_PROPERTIES Properties;
bool SoftwareWater;
};
struct SoundListener
{
FVector3 position;
FVector3 velocity;
float angle;
bool underwater;
bool valid;
ReverbContainer *Environment;
};
// Default rolloff information.
struct FRolloffInfo
{
int RolloffType;
float MinDistance;
union { float MaxDistance; float RolloffFactor; };
};
struct SoundHandle
{
void *data;
bool isValid() const { return data != NULL; }
void Clear() { data = NULL; }
};
struct FISoundChannel
{
void *SysChannel; // Channel information from the system interface.
QWORD_UNION StartTime; // Sound start time in DSP clocks.
// The sound interface doesn't use these directly but it needs to pass them to a
// callback that can't be passed a sound channel pointer
FRolloffInfo Rolloff;
float DistanceScale;
};
#endif

View file

@ -4129,6 +4129,10 @@
RelativePath="src\sound\i_sound.h"
>
</File>
<File
RelativePath=".\src\sound\i_soundinternal.h"
>
</File>
<File
RelativePath="src\sound\music_cd.cpp"
>