29 #include "../idlib/precompiled.h"
175 common->
Printf(
"sound: appended new sound def %d\n", index );
254 if ( !readDemo->
ReadInt( (
int&)dc ) ) {
277 readDemo->
ReadInt( listenerId );
286 common->
Error(
"idSoundWorldLocal::ProcessDemoCommand: bad emitter number" );
304 readDemo->
ReadInt( immediate );
316 readDemo->
ReadInt( listenerId );
337 readDemo->
ReadInt( shaderFlags );
403 amp +=
FindAmplitude( sound, localTime, &listererPosition, SCHANNEL_ANY,
true );
439 ALfloat listenerOrientation[6];
457 int EnvironmentID = -1;
458 idStr defaultStr(
"default" );
472 if ( ( effect ) && ( effect->
data) && ( memcpy( &EnvironmentParameters, effect->
data, effect->
datasize ) ) ) {
474 EnvironmentParameters.
lRoom = -10000;
492 if ( sound && sound->
playing ) {
591 float *mix_p = (
float *)(((
int)mix + 15 ) & ~15);
597 for (
int i = 0;
i < numSpeakers;
i++ ) {
601 float s = mix_p[
j*numSpeakers +
i];
602 if ( s < -32768.0
f ) {
604 }
else if ( s > 32767.0
f ) {
611 fpa[
i]->
Write( outD, MIXBUFFER_SAMPLES*
sizeof(
short) );
636 for ( i = 0; i < 6; i++ ) {
665 int numSamples = rL->
Length()/2;
674 wO->
Write( &info, 12 );
679 wO->
Write( &info, 8 );
688 wO->
Write( &format, 16 );
693 wO->
Write( &info, 8 );
696 for( i = 0; i < numSamples; i++ ) {
732 static const int MAX_PORTAL_TRACE_DEPTH = 10;
742 float fullDist = dist + (soundOrigin -
listenerQU).LengthFast();
743 if ( fullDist < def->distance ) {
750 if ( stackDepth == MAX_PORTAL_TRACE_DEPTH ) {
760 for(
int p = 0;
p < numPortals;
p++ ) {
763 float occlusionDistance = 0;
773 int otherArea = re.
areas[0];
774 if ( re.
areas[0] == soundArea ) {
775 otherArea = re.
areas[1];
780 for ( prev = prevStack ; prev ; prev = prev->
prevStack ) {
801 source = soundOrigin + scale * dir;
806 idVec3 edgeDir = (*(re.
w))[
j].ToVec3() - (*(re.
w))[
i].ToVec3();
811 idVec3 fromVert = source - (*(re.
w))[
j].ToVec3();
813 float d = edgeNormal * fromVert;
819 source -= d * edgeNormal;
830 bool wasClipped =
false;
834 idVec3 v1 = (*(re.
w))[
j].ToVec3() - soundOrigin;
835 idVec3 v2 = (*(re.
w))[
i].ToVec3() - soundOrigin;
842 edgeNormal.
Cross( v1, v2 );
844 idVec3 fromVert = start - soundOrigin;
845 float d1 = edgeNormal * fromVert;
848 fromVert = mid - (*(re.
w))[
j].ToVec3();
849 float d2 = edgeNormal * fromVert;
852 float f = d1 / ( d1 - d2 );
854 idVec3 clipped = start * ( 1.0f -
f ) + mid * f;
867 float f2 = pl.
Distance( soundOrigin );
869 float f = f1 / ( f1 - f2 );
870 source = start * ( 1.0f -
f ) + soundOrigin * f;
872 source = soundOrigin;
876 idVec3 tlen = source - soundOrigin;
879 ResolveOrigin( stackDepth+1, &newStack, otherArea, dist+tlenLength+occlusionDistance, source, def );
892 const int listenerId,
const int gameTime,
const idStr& areaName ) {
894 int current44kHzTime;
1095 int i,
j,
num, currentSoundTime;
1111 savefile->
WriteInt(currentSoundTime);
1121 savefile->
Write( &skip,
sizeof( skip ) );
1206 for (
int m = 0; m < 6; m++)
1220 int i,
num, handle, listenerId, gameTime, channel;
1221 int savedSoundTime, currentSoundTime, soundTimeOffset;
1231 savefile->
ReadInt( listenerId );
1232 savefile->
ReadInt( gameTime );
1234 savefile->
ReadInt( savedSoundTime );
1238 soundTimeOffset = currentSoundTime - savedSoundTime;
1244 PlaceListener( origin, axis, listenerId, gameTime,
"Undefined" );
1258 for ( i = 1; i <
num; i++ ) {
1264 if ( handle != i ) {
1265 common->
Error(
"idSoundWorldLocal::ReadFromSaveGame: index mismatch" );
1291 while ( channel >= 0 ) {
1292 if ( channel > SOUND_MAX_CHANNELS ) {
1293 common->
Error(
"idSoundWorldLocal::ReadFromSaveGame: channel > SOUND_MAX_CHANNELS" );
1377 for (
int m = 0; m < 6; m++)
1422 common->
Warning(
"idSoundWorldLocal::Pause: already paused" );
1438 common->
Warning(
"idSoundWorldLocal::UnPause: not paused" );
1474 if ( !shaderName || !shaderName[0] ) {
1490 localSound->
StartSound( shader, ( channel == -1 ) ? SCHANNEL_ONE : channel , diversity, SSF_GLOBAL );
1504 idMat3 listenerAxis,
float ears[6],
float spatialize ) {
1508 ovec[0] = svec * listenerAxis[0];
1509 ovec[1] = svec * listenerAxis[1];
1510 ovec[2] = svec * listenerAxis[2];
1514 if ( numSpeakers == 6 ) {
1515 static idVec3 speakerVector[6] = {
1523 for (
int i = 0 ;
i < 6 ;
i++ ) {
1528 float dot = ovec * speakerVector[
i];
1571 int current44kHz,
int numSpeakers,
float *finalMixBuffer ) {
1585 if ( sample ==
NULL ) {
1658 float spatialize = 1;
1659 idVec3 spatializedOriginInMeters;
1663 if ( noOcclusion ) {
1674 if ( dlen >= maxd ) {
1676 }
else if ( dlen > mind ) {
1682 }
else if ( mind > 0.0
f ) {
1684 spatialize = dlen / mind;
1706 if ( volume < SND_EPSILON && chan->lastVolume <
SND_EPSILON ) {
1716 float *alignedInputSamples = (
float *) ( ( ( (
int)inputSamples ) + 15 ) & ~15 );
1734 if ( global || omni ) {
1744 #if !defined(MACOS_X)
1761 ALint finishedbuffers;
1778 finishedbuffers = 3;
1782 if ( finishedbuffers == 3 ) {
1787 for ( j = 0; j < finishedbuffers; j++ ) {
1790 if ( alignedInputSamples[
i] < -32768.0
f )
1791 ((
short *)alignedInputSamples)[
i] = -32768;
1792 else if ( alignedInputSamples[
i] > 32767.0
f )
1793 ((
short *)alignedInputSamples)[
i] = 32767;
1801 if ( finishedbuffers ) {
1821 memset( alignedInputSamples, 0,
sizeof( alignedInputSamples[0] ) *
MIXBUFFER_SAMPLES * 2 );
1843 if ( global || omni ) {
1845 for (
int i = 0 ;
i < 6 ;
i++ ) {
1853 for (
int i = 0 ;
i < 6 ;
i++ ) {
1863 for (
int i = 0 ;
i < 6 ;
i++ ) {
1864 if ( !(mask & ( 1 <<
i ) ) ) {
1873 for (
int i = 0 ;
i < 6 ;
i++ ) {
1874 if ( ears[
i] > 1.0
f ) {
1883 for ( j = 0 ; j < 6 ; j++ ) {
1888 if ( numSpeakers == 6 ) {
1902 for ( j = 0 ; j < 6 ; j++ ) {
1931 int activeChannelCount;
1933 float sourceBuffer[AMPLITUDE_SAMPLES];
1934 float sumBuffer[AMPLITUDE_SAMPLES];
1942 if ( listenerPosition ) {
1951 activeChannelCount = 0;
1960 if ( channel != SCHANNEL_ANY && chan->
triggerChannel != channel) {
1964 parms = &chan->
parms;
1971 float shakes = parms->
shakes;
1972 if ( shakesOnly && shakes <= 0.0
f ) {
1979 if ( !listenerPosition ) {
1994 if ( dlen >= maxd ) {
1996 }
else if ( dlen > mind ) {
2006 if ( volume <= 0 ) {
2017 for ( j = 0 ; j < (AMPLITUDE_SAMPLES); j++ ) {
2018 sourceBuffer[
j] = j & 1 ? 32767.0f : -32767.0f;
2021 int offset = (localTime - localTriggerTimes);
2025 if ( amplitudeData ) {
2028 if ( looping ) offset %=
size;
2029 if ( offset < size ) {
2030 for ( j = 0 ; j < (AMPLITUDE_SAMPLES); j++ ) {
2031 sourceBuffer[
j] = j & 1 ? amplitudeData[ ( offset / 512 ) * 2 ] : amplitudeData[ ( offset / 512 ) * 2 + 1 ];
2039 activeChannelCount++;
2040 if ( activeChannelCount == 1 ) {
2042 for( j = 0; j < AMPLITUDE_SAMPLES; j++ ) {
2043 sumBuffer[
j ] = volume * sourceBuffer[
j ];
2047 for( j = 0; j < AMPLITUDE_SAMPLES; j++ ) {
2048 sumBuffer[
j ] += volume * sourceBuffer[
j ];
2053 if ( activeChannelCount == 0 ) {
2057 float high = -32767.0f;
2058 float low = 32767.0f;
2061 for( i = 0; i < (AMPLITUDE_SAMPLES); i++ ) {
2062 float fabval = sumBuffer[
i];
2063 if ( high < fabval ) {
2066 if ( low > fabval ) {
2072 sout = atan( (high - low) / 32767.0
f) /
DEG2RAD(45);
2087 common->
Error(
"idSoundWorldLocal::FadeSoundClasses: bad soundClass %i", soundClass );
idSlowChannel GetSlowChannel(const idSoundChannel *chan)
#define mmioFOURCC(ch0, ch1, ch2, ch3)
#define AL_REFERENCE_DISTANCE
idSoundWorldLocal * currentSoundWorld
virtual int WriteUnsignedChar(const unsigned char value)
idSoundChannel channels[SOUND_MAX_CHANNELS]
virtual idFile * OpenFileRead(const char *relativePath, bool allowCopyFiles=true, const char *gamedir=NULL)=0
static idSampleDecoder * Alloc(void)
virtual int virtual int ReadInt(int &value)
const idSoundShader * soundShader
int ALint
OpenAL 32bit signed integer type.
assert(prefInfo.fullscreenBtn)
virtual const idSoundShader * FindSound(const char *name, bool makeDefault=true)=0
const idVec3 & Normal(void) const
virtual int ReadChar(char &value)
virtual idSoundEmitter * EmitterForIndex(int index)
virtual void DebugArrow(const idVec4 &color, const idVec3 &start, const idVec3 &end, int size, const int lifetime=0)=0
idSoundFade soundClassFade[SOUND_MAX_CLASSES]
void ForegroundUpdate(int currentTime)
idList< idSoundEmitterLocal * > emitters
GLenum GLsizei GLenum format
float GetFloat(void) const
void GatherChannelSamples(int sampleOffset44k, int sampleCount44k, float *dest)
int listenerEnvironmentID
const int MIXBUFFER_SAMPLES
float dB2Scale(const float val) const
GLenum GLenum GLenum GLenum GLenum scale
float Distance(const idVec3 &v) const
#define alSourceUnqueueBuffers
float FindAmplitude(idSoundEmitterLocal *sound, const int localTime, const idVec3 *listenerPosition, const s_channelType channel, bool shakesOnly)
virtual void WriteToSaveGameSoundChannel(idFile *saveGame, idSoundChannel *ch)
virtual void StopWritingDemo(void)
virtual float CurrentShakeAmplitudeForPosition(const int time, const idVec3 &listererPosition)
virtual void ReadFromSaveGame(idFile *savefile)
idFileSystem * fileSystem
static float ClampFloat(float min, float max, float value)
virtual void VPCALL MixSoundTwoSpeakerMono(float *mixBuffer, const float *samples, const int numSamples, const float lastV[2], const float currentV[2])=0
int MillisecondsToSamples(int ms) const
const char * GetName(void) const
virtual int GetSaveGameVersion(void)=0
int GetCurrent44kHzTime(void) const
void DoEnviroSuit(float *samples, int numSamples, int numSpeakers)
virtual int NumPortalsInArea(int areaNum)=0
#define EAXPROPERTYID_EAX_FXSlot0
virtual void FadeSound(const s_channelType channel, float to, float over)=0
static idCVar s_spatializationDecay
void ResolveOrigin(const int stackDepth, const soundPortalTrace_t *prevStack, const int soundArea, const float dist, const idVec3 &soundOrigin, idSoundEmitterLocal *def)
#define AL_SOURCE_RELATIVE
Indicate Source has listener relative coordinates.
ALuint lastopenalStreamingBuffer[3]
idAudioHardware * snd_audio_hw
static idCVar s_slowAttenuate
virtual idSoundEmitter * AllocSoundEmitter(void)
static idCVar s_muteEAXReverb
virtual const idMaterial * FindMaterial(const char *name, bool makeDefault=true)=0
virtual void VPCALL Memset(void *dst, const int val, const int count)=0
void SetSlowChannel(const idSoundChannel *chan, idSlowChannel slow)
idSoundSample * FindSound(const idStr &fname, bool loadOnDemandOnly)
idVec3 Cross(const idVec3 &a) const
virtual void Free(bool immediate)=0
virtual int GetNumberOfSpeakers(void)=0
static idCVar s_useOcclusion
static idCVar s_quadraticFalloff
static idCVar s_playDefaultSound
#define AL_FORMAT_STEREO16
float ALfloat
OpenAL 32bit floating point type.
unsigned ALuint
OpenAL 32bit unsigned integer type.
virtual void ProcessDemoCommand(idDemoFile *readDemo)
virtual void RemoveFile(const char *relativePath)=0
int LengthIn44kHzSamples() const
GLsizei GLsizei GLcharARB * source
virtual void FadeSoundClasses(const int soundClass, const float to, const float over)
bool AddPoint(const idVec3 &v)
virtual void SetSlowmoSpeed(float speed)
GLfloat GLfloat GLfloat v2
void CheckForCompletion(int current44kHzTime)
virtual void SetEnviroSuit(bool active)
void ResetSlowChannel(const idSoundChannel *chan)
virtual void StopAllSounds(void)
virtual int WriteInt(const int value)
const struct soundPortalTrace_s * prevStack
int GetNumPoints(void) const
void Init(idRenderWorld *rw)
void MixLoop(int current44kHz, int numSpeakers, float *finalMixBuffer)
const shaderStage_t * GetStage(const int index) const
virtual void UnPause(void)
static int FtoiFast(float f)
void AddChannelContribution(idSoundEmitterLocal *sound, idSoundChannel *chan, int current44kHz, int numSpeakers, float *finalMixBuffer)
#define alSourceQueueBuffers
virtual int WriteString(const char *string)
idSampleDecoder * decoder
virtual void SetMute(bool mute)
virtual exitPortal_t GetPortal(int areaNum, int portalNum)=0
static idCVar s_constantAmplitude
virtual void VPCALL MixSoundSixSpeakerStereo(float *mixBuffer, const float *samples, const int numSamples, const float lastV[6], const float currentV[6])=0
removeStatus_t removeStatus
virtual void VPCALL MixSoundSixSpeakerMono(float *mixBuffer, const float *samples, const int numSamples, const float lastV[6], const float currentV[6])=0
virtual int ReadVec3(idVec3 &vec)
int GetInteger(void) const
#define AL_BUFFERS_PROCESSED
void CalcEars(int numSpeakers, idVec3 realOrigin, idVec3 listenerPos, idMat3 listenerAxis, float ears[6], float spatialize)
void GetPlane(idVec3 &normal, float &dist) const
ALuint openalStreamingOffset
virtual idFile * OpenFileWrite(const char *relativePath, const char *basePath="fs_savepath")=0
virtual int Read(void *buffer, int len)
virtual void VPCALL MixSoundTwoSpeakerStereo(float *mixBuffer, const float *samples, const int numSamples, const float lastV[2], const float currentV[2])=0
virtual bool IsPaused(void)
idSoundEmitterLocal * AllocLocalSoundEmitter()
virtual void WriteToSaveGameSoundShaderParams(idFile *saveGame, soundShaderParms_t *params)
virtual void StartWritingDemo(idDemoFile *demo)
static idCVar s_drawSounds
static idCVar s_clipVolumes
virtual void DrawText(const char *text, const idVec3 &origin, float scale, const idVec4 &color, const idMat3 &viewAxis, const int align=1, const int lifetime=0, bool depthTest=false)=0
virtual void ModifySound(const s_channelType channel, const soundShaderParms_t *parms)=0
const float DOOM_TO_METERS
static idCVar s_showLevelMeter
bool RayIntersection(const idVec3 &start, const idVec3 &dir, float &scale) const
virtual void Printf(const char *fmt,...) id_attribute((format(printf
idSoundSample * leadinSample
#define AL_ORIENTATION
Specify the current orientation.
virtual int StartSound(const idSoundShader *shader, const s_channelType channel, float diversity=0, int shaderFlags=0, bool allowSlow=true)=0
void AttachSoundChannel(const idSoundChannel *chan)
#define AL_MAX_DISTANCE
Specify the maximum distance.
virtual int ReadBool(bool &value)
virtual ~idSoundWorldLocal(void)
virtual void StopSound(const s_channelType channel)
idDeclManager * declManager
idSoundEmitterLocal * localSound
virtual int StartSound(const idSoundShader *shader, const s_channelType channel, float diversity=0, int shaderFlags=0, bool allowSlow=true)
idSoundSample * entries[SOUND_MAX_LIST_WAVS]
static idCVar s_doorDistanceAdd
static idCVar s_useEAXReverb
EAXSetBufferMode alEAXSetBufferMode
int Append(const type &obj)
idSoundSystemLocal soundSystemLocal
virtual void ClearAllSoundEmitters(void)
static idCVar s_minVolume2
virtual void PlaceListener(const idVec3 &origin, const idMat3 &axis, const int listenerId, const int gameTime, const idStr &areaName)
void GatherChannelSamples(int sampleOffset44k, int sampleCount44k, float *dest) const
virtual void ReadFromSaveGameSoundShaderParams(idFile *saveGame, soundShaderParms_t *params)
virtual void StopSound(const s_channelType channel)=0
virtual int WriteFloat(const float value)
idSoundCache * soundCache
idVec3 GetCenter(void) const
#define EAXPROPERTYID_EAX_Source
virtual void UpdateEmitter(const idVec3 &origin, int listenerId, const soundShaderParms_t *parms)=0
ALuint openalStreamingBuffer[3]
virtual int Write(const void *buffer, int len)
virtual void ReadFromSaveGameSoundChannel(idFile *saveGame, idSoundChannel *ch)
virtual void PlayShaderDirectly(const char *name, int channel=-1)
#define AL_LOOPING
Indicate whether source has to loop infinite.
#define AL_GAIN
Indicate the gain (volume amplification) applied.
float LengthFast(void) const
const char * c_str(void) const
virtual int WriteMat3(const idMat3 &mat)
virtual void SetSlowmo(bool active)
static idCVar s_globalFraction
static idCVar s_subFraction
const char * ReadHashString()
#define AL_BUFFER
Indicate the buffer to provide sound samples.
virtual int ReadString(idStr &string)
float dot(float a[], float b[])
virtual int ReadMat3(idMat3 &mat)
virtual void DebugBounds(const idVec4 &color, const idBounds &bounds, const idVec3 &org=vec3_origin, const int lifetime=0)=0
ALuint AllocOpenALSource(idSoundChannel *chan, bool looping, bool stereo)
virtual int ReadFloat(float &value)
char * va(const char *fmt,...)
virtual int PointInArea(const idVec3 &point) const =0
virtual void CloseFile(idFile *f)=0
waveformatex_t objectInfo
virtual int WriteBool(const bool value)
virtual void AVIClose(void)
virtual void Error(const char *fmt,...) id_attribute((format(printf
static idCVar s_showStartSound
virtual void WriteToSaveGame(idFile *savefile)
virtual void virtual void Warning(const char *fmt,...) id_attribute((format(printf
#define AL_POSITION
Specify the current location in three dimensional space.
const int SOUND_MAX_CLASSES
void Sys_LeaveCriticalSection(int index)
void Sys_EnterCriticalSection(int index)
int sprintf(idStr &string, const char *fmt,...)
idSoundWorldLocal * soundWorld
void Spatialize(idVec3 listenerPos, int listenerArea, idRenderWorld *rw)
virtual int WriteVec3(const idVec3 &vec)
virtual void AVIOpen(const char *path, const char *name)
bool FindEffect(idStr &name, idSoundEffect **effect, int *index)
s_channelType triggerChannel
float FadeDbAt44kHz(int current44kHz)
static idCVar s_singleEmitter
static idCVar s_minVolume6
const int SOUND_MAX_CHANNELS
#define AL_PITCH
Specify the pitch to be applied, either at source, or on mixer results, at listener.
void OffsetSoundTime(int offset44kHz)
GLenum const GLfloat * params
idSIMDProcessor * SIMDProcessor