initial
This commit is contained in:
61
engine/audio/public/ivoicecodec.h
Normal file
61
engine/audio/public/ivoicecodec.h
Normal file
@@ -0,0 +1,61 @@
|
||||
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose: Define the IVoiceCodec interface.
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef IVOICECODEC_H
|
||||
#define IVOICECODEC_H
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "interface.h"
|
||||
|
||||
|
||||
#define BYTES_PER_SAMPLE 2
|
||||
|
||||
|
||||
// This interface is for voice codecs to implement.
|
||||
|
||||
// Codecs are guaranteed to be called with the exact output from Compress into Decompress (ie:
|
||||
// data won't be stuck together and sent to Decompress).
|
||||
|
||||
// Decompress is not guaranteed to be called in any specific order relative to Compress, but
|
||||
// Codecs maintain state between calls, so it is best to call Compress with consecutive voice data
|
||||
// and decompress likewise. If you call it out of order, it will sound wierd.
|
||||
|
||||
// In the same vein, calling Decompress twice with the same data is a bad idea since the state will be
|
||||
// expecting the next block of data, not the same block.
|
||||
|
||||
class IVoiceCodec
|
||||
{
|
||||
protected:
|
||||
virtual ~IVoiceCodec() {}
|
||||
|
||||
public:
|
||||
// Initialize the object. The uncompressed format is always 8-bit signed mono.
|
||||
virtual bool Init( int quality )=0;
|
||||
|
||||
// Use this to delete the object.
|
||||
virtual void Release()=0;
|
||||
|
||||
|
||||
// Compress the voice data.
|
||||
// pUncompressed - 16-bit signed mono voice data.
|
||||
// maxCompressedBytes - The length of the pCompressed buffer. Don't exceed this.
|
||||
// bFinal - Set to true on the last call to Compress (the user stopped talking).
|
||||
// Some codecs like big block sizes and will hang onto data you give them in Compress calls.
|
||||
// When you call with bFinal, the codec will give you compressed data no matter what.
|
||||
// Return the number of bytes you filled into pCompressed.
|
||||
virtual int Compress(const char *pUncompressed, int nSamples, char *pCompressed, int maxCompressedBytes, bool bFinal)=0;
|
||||
|
||||
// Decompress voice data. pUncompressed is 16-bit signed mono.
|
||||
virtual int Decompress(const char *pCompressed, int compressedBytes, char *pUncompressed, int maxUncompressedBytes)=0;
|
||||
|
||||
// Some codecs maintain state between Compress and Decompress calls. This should clear that state.
|
||||
virtual bool ResetState()=0;
|
||||
};
|
||||
|
||||
|
||||
#endif // IVOICECODEC_H
|
||||
40
engine/audio/public/ivoicerecord.h
Normal file
40
engine/audio/public/ivoicerecord.h
Normal file
@@ -0,0 +1,40 @@
|
||||
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef IVOICERECORD_H
|
||||
#define IVOICERECORD_H
|
||||
#pragma once
|
||||
|
||||
|
||||
// This is the voice recording interface. It provides 16-bit signed mono data from
|
||||
// a mic at some sample rate.
|
||||
abstract_class IVoiceRecord
|
||||
{
|
||||
protected:
|
||||
|
||||
virtual ~IVoiceRecord() {}
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Use this to delete the object.
|
||||
virtual void Release()=0;
|
||||
|
||||
// Start/stop capturing.
|
||||
virtual bool RecordStart() = 0;
|
||||
virtual void RecordStop() = 0;
|
||||
|
||||
// Idle processing.
|
||||
virtual void Idle()=0;
|
||||
|
||||
// Get the most recent N samples. If nSamplesWanted is less than the number of
|
||||
// available samples, it discards the first samples and gives you the last ones.
|
||||
virtual int GetRecordedData(short *pOut, int nSamplesWanted)=0;
|
||||
};
|
||||
|
||||
|
||||
#endif // IVOICERECORD_H
|
||||
555
engine/audio/public/snd_audio_source.h
Normal file
555
engine/audio/public/snd_audio_source.h
Normal file
@@ -0,0 +1,555 @@
|
||||
//========= Copyright 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $Workfile: $
|
||||
// $Date: $
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// $Log: $
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef SND_AUDIO_SOURCE_H
|
||||
#define SND_AUDIO_SOURCE_H
|
||||
#pragma once
|
||||
|
||||
#if !defined( _GAMECONSOLE )
|
||||
#define MP3_SUPPORT 1
|
||||
#endif
|
||||
|
||||
#define AUDIOSOURCE_COPYBUF_SIZE 4096
|
||||
|
||||
struct channel_t;
|
||||
class CSentence;
|
||||
class CSfxTable;
|
||||
|
||||
class CAudioSource;
|
||||
class IAudioDevice;
|
||||
class CUtlBuffer;
|
||||
|
||||
#include "tier0/vprof.h"
|
||||
#include "utlhandletable.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: This is an instance of an audio source.
|
||||
// Mixers are attached to channels and reference an audio source.
|
||||
// Mixers are specific to the sample format and source format.
|
||||
// Mixers are never re-used, so they can track instance data like
|
||||
// sample position, fractional sample, stream cache, faders, etc.
|
||||
//-----------------------------------------------------------------------------
|
||||
abstract_class CAudioMixer
|
||||
{
|
||||
public:
|
||||
virtual ~CAudioMixer( void ) {}
|
||||
|
||||
// return number of samples mixed
|
||||
virtual int MixDataToDevice( channel_t *pChannel, int sampleCount, int outputRate, int outputOffset ) = 0;
|
||||
virtual int SkipSamples( channel_t *pChannel, int sampleCount, int outputRate, int outputOffset ) = 0;
|
||||
virtual bool ShouldContinueMixing( void ) = 0;
|
||||
|
||||
virtual CAudioSource *GetSource( void ) = 0;
|
||||
|
||||
// get the current position (next sample to be mixed)
|
||||
virtual int GetSamplePosition( void ) = 0;
|
||||
|
||||
// Allow the mixer to modulate pitch and volume.
|
||||
// returns a floating point modulator
|
||||
virtual float ModifyPitch( float pitch ) = 0;
|
||||
virtual float GetVolumeScale( void ) = 0;
|
||||
|
||||
// NOTE: Playback is optimized for linear streaming. These calls will usually cost performance
|
||||
// It is currently optimal to call them before any playback starts, but some audio sources may not
|
||||
// guarantee this. Also, some mixers may choose to ignore these calls for internal reasons (none do currently).
|
||||
|
||||
virtual bool IsSetSampleStartSupported() const = 0;
|
||||
|
||||
// Move the current position to newPosition
|
||||
// BUGBUG: THIS CALL DOES NOT SUPPORT MOVING BACKWARD, ONLY FORWARD!!!
|
||||
virtual void SetSampleStart( int newPosition ) = 0;
|
||||
|
||||
// End playback at newEndPosition
|
||||
virtual void SetSampleEnd( int newEndPosition ) = 0;
|
||||
|
||||
// How many samples to skip before commencing actual data reading ( to allow sub-frametime sound
|
||||
// offsets and avoid synchronizing sounds to various 100 msec clock intervals throughout the
|
||||
// engine and game code)
|
||||
virtual void SetStartupDelaySamples( int delaySamples ) = 0;
|
||||
virtual int GetMixSampleSize() = 0;
|
||||
|
||||
// Certain async loaded sounds lazilly load into memory in the background, use this to determine
|
||||
// if the sound is ready for mixing
|
||||
virtual bool IsReadyToMix() = 0;
|
||||
|
||||
// NOTE: The "saved" position can be different than the "sample" position
|
||||
// NOTE: Allows mixer to save file offsets, loop info, etc
|
||||
virtual int GetPositionForSave() = 0;
|
||||
virtual void SetPositionFromSaved( int savedPosition ) = 0;
|
||||
};
|
||||
|
||||
inline int CalcSampleSize( int bitsPerSample, int channels )
|
||||
{
|
||||
return (bitsPerSample >> 3) * channels;
|
||||
}
|
||||
|
||||
#include "UtlCachedFileData.h"
|
||||
|
||||
class CSentence;
|
||||
class CSfxTable;
|
||||
class CAudioSourceCachedInfo : public IBaseCacheInfo
|
||||
{
|
||||
public:
|
||||
CAudioSourceCachedInfo();
|
||||
CAudioSourceCachedInfo( const CAudioSourceCachedInfo& src );
|
||||
|
||||
virtual ~CAudioSourceCachedInfo();
|
||||
|
||||
CAudioSourceCachedInfo& operator =( const CAudioSourceCachedInfo& src );
|
||||
|
||||
void Clear();
|
||||
void RemoveData();
|
||||
|
||||
virtual void Save( CUtlBuffer& buf );
|
||||
virtual void Restore( CUtlBuffer& buf );
|
||||
virtual void Rebuild( char const *filename );
|
||||
|
||||
// A hack, but will work okay
|
||||
static int s_CurrentType;
|
||||
static CSfxTable *s_pSfx;
|
||||
static bool s_bIsPrecacheSound;
|
||||
|
||||
inline int Type() const
|
||||
{
|
||||
return info.m_Type;
|
||||
}
|
||||
void SetType( int type )
|
||||
{
|
||||
info.m_Type = type;
|
||||
}
|
||||
|
||||
inline int Bits() const
|
||||
{
|
||||
return info.m_bits;
|
||||
}
|
||||
void SetBits( int bits )
|
||||
{
|
||||
info.m_bits = bits;
|
||||
}
|
||||
|
||||
inline int Channels() const
|
||||
{
|
||||
return info.m_channels;
|
||||
}
|
||||
void SetChannels( int channels )
|
||||
{
|
||||
info.m_channels = channels;
|
||||
}
|
||||
|
||||
inline int SampleSize() const
|
||||
{
|
||||
return info.m_sampleSize;
|
||||
}
|
||||
void SetSampleSize( int size )
|
||||
{
|
||||
info.m_sampleSize = size;
|
||||
}
|
||||
|
||||
inline int Format() const
|
||||
{
|
||||
return info.m_format;
|
||||
}
|
||||
void SetFormat( int format )
|
||||
{
|
||||
info.m_format = format;
|
||||
}
|
||||
|
||||
inline int SampleRate() const
|
||||
{
|
||||
return info.m_rate;
|
||||
}
|
||||
void SetSampleRate( int rate )
|
||||
{
|
||||
info.m_rate = rate;
|
||||
}
|
||||
|
||||
inline int CachedDataSize() const
|
||||
{
|
||||
return (int)m_usCachedDataSize;
|
||||
}
|
||||
|
||||
void SetCachedDataSize( int size )
|
||||
{
|
||||
m_usCachedDataSize = (unsigned short)size;
|
||||
}
|
||||
|
||||
inline const byte *CachedData() const
|
||||
{
|
||||
return m_pCachedData;
|
||||
}
|
||||
|
||||
void SetCachedData( const byte *data )
|
||||
{
|
||||
m_pCachedData = ( byte * )data;
|
||||
flags.m_bCachedData = ( data != NULL ) ? true : false;
|
||||
}
|
||||
|
||||
inline int HeaderSize() const
|
||||
{
|
||||
return (int)m_usHeaderSize;
|
||||
}
|
||||
|
||||
void SetHeaderSize( int size )
|
||||
{
|
||||
m_usHeaderSize = (unsigned short)size;
|
||||
}
|
||||
|
||||
inline const byte *HeaderData() const
|
||||
{
|
||||
return m_pHeader;
|
||||
}
|
||||
|
||||
void SetHeaderData( const byte *data )
|
||||
{
|
||||
m_pHeader = ( byte * )data;
|
||||
flags.m_bHeader = ( data != NULL ) ? true : false;
|
||||
}
|
||||
|
||||
inline int LoopStart() const
|
||||
{
|
||||
return m_loopStart;
|
||||
}
|
||||
void SetLoopStart( int start )
|
||||
{
|
||||
m_loopStart = start;
|
||||
}
|
||||
|
||||
inline int SampleCount() const
|
||||
{
|
||||
return m_sampleCount;
|
||||
}
|
||||
|
||||
void SetSampleCount( int count )
|
||||
{
|
||||
m_sampleCount = count;
|
||||
}
|
||||
inline int DataStart() const
|
||||
{
|
||||
return m_dataStart;
|
||||
}
|
||||
void SetDataStart( int start )
|
||||
{
|
||||
m_dataStart = start;
|
||||
}
|
||||
inline int DataSize() const
|
||||
{
|
||||
return m_dataSize;
|
||||
}
|
||||
void SetDataSize( int size )
|
||||
{
|
||||
m_dataSize = size;
|
||||
}
|
||||
inline CSentence *Sentence() const
|
||||
{
|
||||
return m_pSentence;
|
||||
}
|
||||
void SetSentence( CSentence *sentence )
|
||||
{
|
||||
m_pSentence = sentence;
|
||||
flags.m_bSentence = ( sentence != NULL ) ? true : false;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
union
|
||||
{
|
||||
unsigned int infolong;
|
||||
struct
|
||||
{
|
||||
unsigned int m_Type : 2; // 0 1 2 or 3
|
||||
unsigned int m_bits : 5; // 0 to 31
|
||||
unsigned int m_channels : 2; // 1 or 2
|
||||
unsigned int m_sampleSize : 3; // 1 2 or 4
|
||||
unsigned int m_format : 2; // 1 == PCM, 2 == ADPCM
|
||||
unsigned int m_rate : 17; // 0 to 64 K
|
||||
} info;
|
||||
};
|
||||
|
||||
union
|
||||
{
|
||||
byte flagsbyte;
|
||||
struct
|
||||
{
|
||||
bool m_bSentence : 1;
|
||||
bool m_bCachedData : 1;
|
||||
bool m_bHeader : 1;
|
||||
} flags;
|
||||
};
|
||||
|
||||
int m_loopStart;
|
||||
int m_sampleCount;
|
||||
int m_dataStart; // offset of wave data chunk
|
||||
int m_dataSize; // size of wave data chunk
|
||||
|
||||
unsigned short m_usCachedDataSize;
|
||||
unsigned short m_usHeaderSize;
|
||||
|
||||
CSentence *m_pSentence;
|
||||
byte *m_pCachedData;
|
||||
byte *m_pHeader;
|
||||
};
|
||||
|
||||
class IAudioSourceCache
|
||||
{
|
||||
public:
|
||||
virtual bool Init( unsigned int memSize ) = 0;
|
||||
virtual void Shutdown() = 0;
|
||||
virtual void LevelInit( char const *mapname ) = 0;
|
||||
virtual void LevelShutdown() = 0;
|
||||
|
||||
virtual CAudioSourceCachedInfo *GetInfo( int audiosourcetype, bool soundisprecached, CSfxTable *sfx ) = 0;
|
||||
virtual CAudioSourceCachedInfo *GetInfoByName( const char *soundName ) = 0;
|
||||
virtual void RebuildCacheEntry( int audiosourcetype, bool soundisprecached, CSfxTable *sfx ) = 0;
|
||||
};
|
||||
|
||||
extern IAudioSourceCache *audiosourcecache;
|
||||
|
||||
typedef UtlHandle_t WaveCacheHandle_t;
|
||||
enum
|
||||
{
|
||||
// purposely 0
|
||||
INVALID_WAVECACHE_HANDLE = (UtlHandle_t)0
|
||||
};
|
||||
|
||||
typedef int StreamHandle_t;
|
||||
enum
|
||||
{
|
||||
INVALID_STREAM_HANDLE = (StreamHandle_t)~0
|
||||
};
|
||||
|
||||
typedef int BufferHandle_t;
|
||||
enum
|
||||
{
|
||||
INVALID_BUFFER_HANDLE = (BufferHandle_t)~0
|
||||
};
|
||||
|
||||
typedef unsigned int streamFlags_t;
|
||||
enum
|
||||
{
|
||||
STREAMED_FROMDVD = 0x00000001, // stream buffers are compliant to dvd sectors
|
||||
STREAMED_SINGLEPLAY = 0x00000002, // non recurring data, buffers don't need to persist and can be recycled
|
||||
STREAMED_QUEUEDLOAD = 0x00000004, // hint the streamer to load using the queued loader system
|
||||
STREAMED_TRANSIENT = 0x00000008, // hint the streamer to pool memory buffers according to dynamic nature
|
||||
};
|
||||
|
||||
enum SoundError
|
||||
{
|
||||
SE_NO_STREAM_BUFFER = -1000,
|
||||
SE_FILE_NOT_FOUND,
|
||||
SE_CANT_GET_NAME,
|
||||
SE_SKIPPED,
|
||||
SE_NO_SOURCE_SETUP,
|
||||
SE_CANT_CREATE_MIXER,
|
||||
|
||||
// Avoid 0 on purpose, to avoid ambiguity on the meaning
|
||||
|
||||
SE_OK = 1,
|
||||
};
|
||||
|
||||
abstract_class IAsyncWavDataCache
|
||||
{
|
||||
public:
|
||||
virtual bool Init( unsigned int memSize ) = 0;
|
||||
virtual void Shutdown() = 0;
|
||||
|
||||
// implementation that treats file as monolithic
|
||||
virtual WaveCacheHandle_t AsyncLoadCache( char const *filename, int datasize, int startpos, bool bIsPrefetch = false ) = 0;
|
||||
virtual void PrefetchCache( char const *filename, int datasize, int startpos ) = 0;
|
||||
virtual bool CopyDataIntoMemory( char const *filename, int datasize, int startpos, void *buffer, int bufsize, int copystartpos, int bytestocopy, bool *pbPostProcessed ) = 0;
|
||||
virtual bool CopyDataIntoMemory( WaveCacheHandle_t& handle, char const *filename, int datasize, int startpos, void *buffer, int bufsize, int copystartpos, int bytestocopy, bool *pbPostProcessed ) = 0;
|
||||
virtual bool IsDataLoadCompleted( WaveCacheHandle_t handle, bool *pIsValid, bool *pIsMissing = NULL ) = 0;
|
||||
virtual void RestartDataLoad( WaveCacheHandle_t *pHandle, const char *pFilename, int dataSize, int startpos ) = 0;
|
||||
virtual bool GetDataPointer( WaveCacheHandle_t& handle, char const *filename, int datasize, int startpos, void **pData, int copystartpos, bool *pbPostProcessed ) = 0;
|
||||
virtual void SetPostProcessed( WaveCacheHandle_t handle, bool proc ) = 0;
|
||||
virtual void Unload( WaveCacheHandle_t handle ) = 0;
|
||||
|
||||
// alternate multi-buffer streaming implementation
|
||||
virtual StreamHandle_t OpenStreamedLoad( char const *pFileName, int dataSize, int dataStart, int startPos, int loopPos, int bufferSize, int numBuffers, streamFlags_t flags, SoundError &soundError ) = 0;
|
||||
virtual void CloseStreamedLoad( StreamHandle_t hStream ) = 0;
|
||||
virtual int CopyStreamedDataIntoMemory( StreamHandle_t hStream, void *pBuffer, int buffSize, int copyStartPos, int bytesToCopy ) = 0;
|
||||
virtual bool IsStreamedDataReady( StreamHandle_t hStream ) = 0;
|
||||
virtual void MarkBufferDiscarded( BufferHandle_t hBuffer ) = 0;
|
||||
virtual void *GetStreamedDataPointer( StreamHandle_t hStream, bool bSync ) = 0;
|
||||
virtual bool IsDataLoadInProgress( WaveCacheHandle_t handle ) = 0;
|
||||
|
||||
virtual void Flush( bool bTearDownStaticPool = false ) = 0;
|
||||
|
||||
// This can get called by some implementation when a more accurate loop position has been found later in the process.
|
||||
// For example, the initial loop can be the position in bytes in decompressed samples.
|
||||
// But later, while the sound is being decompressed, a more accurate loop can be set based on the position in the compressed samples.
|
||||
virtual void UpdateLoopPosition( StreamHandle_t hStream, int nLoopPosition ) = 0;
|
||||
};
|
||||
|
||||
extern IAsyncWavDataCache *wavedatacache;
|
||||
|
||||
struct CAudioSourceCachedInfoHandle_t
|
||||
{
|
||||
CAudioSourceCachedInfoHandle_t() :
|
||||
info( NULL ),
|
||||
m_FlushCount( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
CAudioSourceCachedInfo *info;
|
||||
unsigned int m_FlushCount;
|
||||
|
||||
inline CAudioSourceCachedInfo *Get( int audiosourcetype, bool soundisprecached, CSfxTable *sfx, int *pcacheddatasize )
|
||||
{
|
||||
VPROF("CAudioSourceCachedInfoHandle_t::Get");
|
||||
|
||||
if ( m_FlushCount != s_nCurrentFlushCount )
|
||||
{
|
||||
// Reacquire
|
||||
info = audiosourcecache->GetInfo( audiosourcetype, soundisprecached, sfx );
|
||||
|
||||
if ( pcacheddatasize && info )
|
||||
{
|
||||
*pcacheddatasize = info->CachedDataSize();
|
||||
}
|
||||
|
||||
// Tag as current
|
||||
m_FlushCount = s_nCurrentFlushCount;
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
inline bool IsValid()
|
||||
{
|
||||
return !!( m_FlushCount == s_nCurrentFlushCount );
|
||||
}
|
||||
|
||||
inline CAudioSourceCachedInfo *FastGet()
|
||||
{
|
||||
VPROF("CAudioSourceCachedInfoHandle_t::FastGet");
|
||||
|
||||
if ( m_FlushCount != s_nCurrentFlushCount )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
static void InvalidateCache();
|
||||
static unsigned int s_nCurrentFlushCount;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: A source is an abstraction for a stream, cached file, or procedural
|
||||
// source of audio.
|
||||
//-----------------------------------------------------------------------------
|
||||
abstract_class CAudioSource
|
||||
{
|
||||
public:
|
||||
enum
|
||||
{
|
||||
AUDIO_SOURCE_UNK = 0,
|
||||
AUDIO_SOURCE_WAV,
|
||||
AUDIO_SOURCE_MP3,
|
||||
AUDIO_SOURCE_VOICE,
|
||||
|
||||
AUDIO_SOURCE_MAXTYPE,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
AUDIO_NOT_LOADED = 0,
|
||||
AUDIO_IS_LOADED,
|
||||
AUDIO_LOADING,
|
||||
AUDIO_ERROR_LOADING,
|
||||
};
|
||||
|
||||
virtual ~CAudioSource( void ) {}
|
||||
|
||||
// Create an instance (mixer) of this audio source
|
||||
virtual CAudioMixer *CreateMixer( int initialStreamPosition, int skipInitialSamples, bool bUpdateDelayForChoreo, SoundError &soundError, struct hrtf_info_t *pHRTFPos ) = 0;
|
||||
|
||||
// Serialization for caching
|
||||
virtual int GetType( void ) = 0;
|
||||
virtual void GetCacheData( CAudioSourceCachedInfo *info ) = 0;
|
||||
|
||||
// Provide samples for the mixer. You can point pData at your own data, or if you prefer to copy the data,
|
||||
// you can copy it into copyBuf and set pData to copyBuf.
|
||||
virtual int GetOutputData( void **pData, int64 samplePosition, int sampleCount, char copyBuf[AUDIOSOURCE_COPYBUF_SIZE] ) = 0;
|
||||
|
||||
virtual int SampleRate( void ) = 0;
|
||||
|
||||
// Returns true if the source is a voice source.
|
||||
// This affects the voice_overdrive behavior (all sounds get quieter when
|
||||
// someone is speaking).
|
||||
virtual bool IsVoiceSource() = 0;
|
||||
|
||||
// Returns true if this sound comes from player voice chat
|
||||
virtual bool IsPlayerVoice() {return true;}
|
||||
|
||||
// Sample size is in bytes. It will not be accurate for compressed audio. This is a best estimate.
|
||||
// The compressed audio mixers understand this, but in general do not assume that SampleSize() * SampleCount() = filesize
|
||||
// or even that SampleSize() is 100% accurate due to compression.
|
||||
virtual int SampleSize( void ) = 0;
|
||||
|
||||
// Total number of samples in this source. NOTE: Some sources are infinite (mic input), they should return
|
||||
// a count equal to one second of audio at their current rate.
|
||||
virtual int SampleCount( void ) = 0;
|
||||
|
||||
virtual int Format( void ) = 0;
|
||||
virtual int DataSize( void ) = 0;
|
||||
|
||||
virtual bool IsLooped( void ) = 0;
|
||||
virtual bool IsStereoWav( void ) = 0;
|
||||
virtual bool IsStreaming( void ) = 0;
|
||||
virtual int GetCacheStatus( void ) = 0;
|
||||
int IsCached( void ) { return GetCacheStatus() == AUDIO_IS_LOADED ? true : false; }
|
||||
virtual void CacheLoad( void ) = 0;
|
||||
virtual void CacheUnload( void ) = 0;
|
||||
virtual CSentence *GetSentence( void ) = 0;
|
||||
virtual int GetQuality( void ) = 0;
|
||||
|
||||
// these are used to find good splice/loop points.
|
||||
// If not implementing these, simply return sample
|
||||
virtual int ZeroCrossingBefore( int sample ) = 0;
|
||||
virtual int ZeroCrossingAfter( int sample ) = 0;
|
||||
|
||||
// mixer's references
|
||||
virtual void ReferenceAdd( CAudioMixer *pMixer ) = 0;
|
||||
virtual void ReferenceRemove( CAudioMixer *pMixer ) = 0;
|
||||
|
||||
// check reference count, return true if nothing is referencing this
|
||||
virtual bool CanDelete( void ) = 0;
|
||||
|
||||
virtual void Prefetch() = 0;
|
||||
|
||||
virtual bool IsAsyncLoad() = 0;
|
||||
|
||||
// Make sure our data is rebuilt into the per-level cache
|
||||
virtual void CheckAudioSourceCache() = 0;
|
||||
|
||||
virtual char const *GetFileName(char *pBuf, size_t bufLen) = 0;
|
||||
|
||||
virtual void SetPlayOnce( bool ) = 0;
|
||||
virtual bool IsPlayOnce() = 0;
|
||||
|
||||
// Used to identify a word that is part of a sentence mixing operation
|
||||
virtual void SetSentenceWord( bool bIsWord ) = 0;
|
||||
virtual bool IsSentenceWord() = 0;
|
||||
|
||||
virtual int SampleToStreamPosition( int samplePosition ) = 0;
|
||||
virtual int StreamToSamplePosition( int streamPosition ) = 0;
|
||||
};
|
||||
|
||||
// Fast method for determining duration of .wav/.mp3, exposed to server as well
|
||||
extern float AudioSource_GetSoundDuration( char const *pName );
|
||||
|
||||
// uses wave file cached in memory already
|
||||
extern float AudioSource_GetSoundDuration( CSfxTable *pSfx );
|
||||
|
||||
#endif // SND_AUDIO_SOURCE_H
|
||||
114
engine/audio/public/snd_device.h
Normal file
114
engine/audio/public/snd_device.h
Normal file
@@ -0,0 +1,114 @@
|
||||
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose: This abstracts the various hardware dependent implementations of sound
|
||||
// At the time of this writing there are Windows WAVEOUT, Direct Sound,
|
||||
// and Null implementations.
|
||||
//
|
||||
//=====================================================================================//
|
||||
|
||||
#ifndef SND_DEVICE_H
|
||||
#define SND_DEVICE_H
|
||||
#pragma once
|
||||
|
||||
#include "snd_fixedint.h"
|
||||
#include "snd_mix_buf.h"
|
||||
|
||||
// sound engine rate defines
|
||||
#if 0 // def _PS3
|
||||
#define SOUND_DMA_SPEED 48000 // hardware playback rate
|
||||
#else
|
||||
#define SOUND_DMA_SPEED 44100 // hardware playback rate
|
||||
#endif
|
||||
|
||||
#define SOUND_11k 11025 // 11khz sample rate
|
||||
#define SOUND_22k 22050 // 22khz sample rate
|
||||
#define SOUND_44k 44100 // 44khz sample rate
|
||||
#define SOUND_ALL_RATES 1 // mix all sample rates
|
||||
|
||||
#define SOUND_MIX_WET 0 // mix only samples that don't have channel set to 'dry' or 'speaker' (default)
|
||||
#define SOUND_MIX_DRY 1 // mix only samples with channel set to 'dry' (ie: music)
|
||||
#define SOUND_MIX_SPEAKER 2 // mix only samples with channel set to 'speaker'
|
||||
|
||||
#define SOUND_BUSS_ROOM (1<<0) // mix samples using channel dspmix value (based on distance from player)
|
||||
#define SOUND_BUSS_FACING (1<<1) // mix samples using channel dspface value (source facing)
|
||||
#define SOUND_BUSS_FACINGAWAY (1<<2) // mix samples using 1-dspface
|
||||
#define SOUND_BUSS_SPEAKER (1<<3) // mix ch->bspeaker samples in mono to speaker buffer
|
||||
#define SOUND_BUSS_DRY (1<<4) // mix ch->bdry samples into dry buffer
|
||||
|
||||
class Vector;
|
||||
struct channel_t;
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#define USE_AUDIO_DEVICE_V1 1
|
||||
#endif
|
||||
|
||||
#if USE_AUDIO_DEVICE_V1
|
||||
// General interface to an audio device
|
||||
abstract_class IAudioDevice
|
||||
{
|
||||
public:
|
||||
virtual ~IAudioDevice() {}
|
||||
|
||||
// Detect the sound hardware and create a compatible device
|
||||
// NOTE: This should NEVER fail. There is a function called Audio_GetNullDevice
|
||||
// which will create a "null" device that makes no sound. If we can't create a real
|
||||
// sound device, this will return a device of that type. All of the interface
|
||||
// functions can be called on the null device, but it will not, of course, make sound.
|
||||
static IAudioDevice *AutoDetectInit();
|
||||
|
||||
// This initializes the sound hardware. true on success, false on failure
|
||||
virtual bool Init( void ) = 0;
|
||||
// This releases all sound hardware
|
||||
virtual void Shutdown( void ) = 0;
|
||||
// stop outputting sound, but be ready to resume on UnPause
|
||||
virtual void Pause( void ) = 0;
|
||||
// return to normal operation after a Pause()
|
||||
virtual void UnPause( void ) = 0;
|
||||
|
||||
// Called before painting channels, must calculated the endtime and return it (once per frame)
|
||||
virtual int64 PaintBegin( float, int64 soundtime, int64 paintedtime ) = 0;
|
||||
virtual void PaintEnd() {}
|
||||
|
||||
// replaces SNDDMA_GetDMAPos, gets the output sample position for tracking
|
||||
virtual int GetOutputPosition( void ) = 0;
|
||||
|
||||
// Fill the output buffer with silence (e.g. during pause)
|
||||
virtual void ClearBuffer( void ) = 0;
|
||||
|
||||
virtual void TransferSamples( int end ) = 0;
|
||||
|
||||
// device parameters
|
||||
virtual int DeviceSampleCount( void ) = 0; // Total samples in buffer
|
||||
|
||||
inline const char *Name() { return m_pName; }
|
||||
inline int ChannelCount() { return m_nChannels; }
|
||||
inline int BitsPerSample() { return m_nSampleBits; }
|
||||
inline int SampleRate() { return m_nSampleRate; }
|
||||
|
||||
virtual bool IsSurround() { return m_nChannels > 2 ? true : false; }
|
||||
virtual bool IsSurroundCenter() { return m_nChannels > 4 ? true : false; }
|
||||
inline bool IsActive() { return m_bIsActive; }
|
||||
inline bool IsHeadphone() { return m_bIsHeadphone; } // mixing makes some choices differently for stereo vs headphones, expose that here.
|
||||
|
||||
inline int DeviceSampleBytes() { return BitsPerSample() / 8; }
|
||||
|
||||
protected:
|
||||
// NOTE: Derived classes MUST initialize these before returning a device from a factory
|
||||
const char *m_pName;
|
||||
int m_nChannels;
|
||||
int m_nSampleBits;
|
||||
int m_nSampleRate;
|
||||
bool m_bIsActive;
|
||||
bool m_bIsHeadphone;
|
||||
};
|
||||
|
||||
extern IAudioDevice *Audio_GetNullDevice( void );
|
||||
#else
|
||||
#include "soundsystem/lowlevel.h"
|
||||
inline IAudioDevice2 *Audio_GetNullDevice()
|
||||
{
|
||||
return Audio_CreateNullDevice();
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // SND_DEVICE_H
|
||||
16
engine/audio/public/snd_io.h
Normal file
16
engine/audio/public/snd_io.h
Normal file
@@ -0,0 +1,16 @@
|
||||
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef SND_IO_H
|
||||
#define SND_IO_H
|
||||
#pragma once
|
||||
|
||||
class IFileReadBinary;
|
||||
|
||||
extern IFileReadBinary *g_pSndIO;
|
||||
|
||||
#endif // SND_IO_H
|
||||
332
engine/audio/public/sound.h
Normal file
332
engine/audio/public/sound.h
Normal file
@@ -0,0 +1,332 @@
|
||||
//===== Copyright 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose: client sound i/o functions
|
||||
//
|
||||
//===========================================================================//
|
||||
#ifndef SOUND_H
|
||||
#define SOUND_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "basetypes.h"
|
||||
#include "datamap.h"
|
||||
#include "mathlib/vector.h"
|
||||
#include "mathlib/mathlib.h"
|
||||
#include "tier1/strtools.h"
|
||||
#include "soundflags.h"
|
||||
#include "utlvector.h"
|
||||
#include "engine/SndInfo.h"
|
||||
#include "cdll_int.h"
|
||||
#include "SoundEmitterSystem/isoundemittersystembase.h"
|
||||
|
||||
DECLARE_LOGGING_CHANNEL( LOG_SOUND_OPERATOR_SYSTEM );
|
||||
|
||||
#define MAX_SFX 2048
|
||||
|
||||
#define AUDIOSOURCE_CACHE_ROOTDIR "maps/soundcache"
|
||||
|
||||
class CSfxTable;
|
||||
enum soundlevel_t;
|
||||
struct SoundInfo_t;
|
||||
struct AudioState_t;
|
||||
struct channel_t;
|
||||
class IFileList;
|
||||
|
||||
void S_Init (void);
|
||||
void S_Shutdown (void);
|
||||
bool S_IsInitted();
|
||||
|
||||
void S_StopAllSounds(bool clear);
|
||||
bool S_GetPreventSound( void );
|
||||
|
||||
#if !USE_AUDIO_DEVICE_V1
|
||||
struct audio_device_description_t;
|
||||
void S_GetAudioDeviceList( CUtlVector<audio_device_description_t> &audioList );
|
||||
#endif
|
||||
|
||||
class CAudioState
|
||||
{
|
||||
public:
|
||||
CAudioState() {}
|
||||
|
||||
bool IsAnyPlayerUnderwater() const;
|
||||
|
||||
AudioState_t &GetPerUser( int nSlot = -1 );
|
||||
const AudioState_t &GetPerUser( int nSlot = -1 ) const;
|
||||
private:
|
||||
|
||||
AudioState_t m_PerUser[ MAX_SPLITSCREEN_CLIENTS ];
|
||||
};
|
||||
|
||||
void S_Update( const CAudioState *pAudioState );
|
||||
void S_ExtraUpdate (void);
|
||||
void S_ClearBuffer (void);
|
||||
void S_BlockSound (void);
|
||||
void S_UnblockSound (void);
|
||||
void S_UpdateWindowFocus( bool bWindowHasFocus );
|
||||
float S_GetMasterVolume( void );
|
||||
void S_SoundFade( float percent, float holdtime, float intime, float outtime );
|
||||
void S_OnLoadScreen(bool value);
|
||||
void S_EnableThreadedMixing( bool bEnable );
|
||||
void S_EnableMusic( bool bEnable );
|
||||
|
||||
void S_PreventSound(bool bSetting);
|
||||
|
||||
struct StartSoundParams_t
|
||||
{
|
||||
StartSoundParams_t() :
|
||||
m_nSoundScriptHash( SOUNDEMITTER_INVALID_HASH ),
|
||||
m_pSoundEntryName( NULL ),
|
||||
staticsound( false ),
|
||||
userdata( 0 ),
|
||||
soundsource( 0 ),
|
||||
entchannel( CHAN_AUTO ),
|
||||
pSfx( 0 ),
|
||||
bUpdatePositions( true ),
|
||||
fvol( 1.0f ),
|
||||
soundlevel( SNDLVL_NORM ),
|
||||
flags( SND_NOFLAGS ),
|
||||
pitch( PITCH_NORM ),
|
||||
fromserver( false ),
|
||||
delay( 0.0f ),
|
||||
speakerentity( -1 ),
|
||||
bToolSound( false ),
|
||||
initialStreamPosition( 0 ),
|
||||
skipInitialSamples( 0 ),
|
||||
m_nQueuedGUID( UNINT_GUID ),
|
||||
m_bIsScriptHandle( false ),
|
||||
m_pOperatorsKV( NULL ),
|
||||
opStackElapsedTime( 0.0f ),
|
||||
opStackElapsedStopTime( 0.0f ),
|
||||
m_bDelayedStart( false ),
|
||||
m_bInEyeSound( false ),
|
||||
m_bHRTFFollowEntity( false ),
|
||||
m_bHRTFBilinear( false ),
|
||||
m_bHRTFLock( false )
|
||||
{
|
||||
origin.Init();
|
||||
direction.Init();
|
||||
}
|
||||
void Copy( StartSoundParams_t &destParams )
|
||||
{
|
||||
destParams.userdata = userdata;
|
||||
destParams.soundsource = soundsource;
|
||||
destParams.entchannel = entchannel;
|
||||
destParams.pSfx = pSfx;
|
||||
VectorCopy( origin, destParams.origin );
|
||||
VectorCopy( direction, destParams.direction );
|
||||
destParams.fvol = fvol;
|
||||
destParams.soundlevel = soundlevel;
|
||||
destParams.flags = flags;
|
||||
destParams.pitch = pitch;
|
||||
destParams.delay = delay;
|
||||
destParams.speakerentity = speakerentity;
|
||||
destParams.initialStreamPosition = initialStreamPosition;
|
||||
destParams.skipInitialSamples = skipInitialSamples;
|
||||
destParams.m_nQueuedGUID = m_nQueuedGUID;
|
||||
destParams.m_nSoundScriptHash = m_nSoundScriptHash;
|
||||
destParams.m_pSoundEntryName = m_pSoundEntryName;
|
||||
destParams.m_pOperatorsKV = m_pOperatorsKV;
|
||||
destParams.opStackElapsedTime = opStackElapsedTime;
|
||||
destParams.opStackElapsedStopTime = opStackElapsedStopTime;
|
||||
destParams.staticsound = staticsound;
|
||||
destParams.bUpdatePositions = bUpdatePositions;
|
||||
destParams.fromserver = fromserver;
|
||||
destParams.bToolSound = bToolSound;
|
||||
destParams.m_bIsScriptHandle = m_bIsScriptHandle;
|
||||
destParams.m_bDelayedStart = m_bDelayedStart;
|
||||
destParams.m_bInEyeSound = m_bInEyeSound;
|
||||
destParams.m_bHRTFFollowEntity = m_bHRTFFollowEntity;
|
||||
destParams.m_bHRTFBilinear = m_bHRTFBilinear;
|
||||
destParams.m_bHRTFLock = m_bHRTFLock;
|
||||
}
|
||||
void CopyNewFromParams( StartSoundParams_t &destParams )
|
||||
{
|
||||
destParams.userdata = userdata;
|
||||
// destParams.soundsource = soundsource;
|
||||
// destParams.entchannel = entchannel;
|
||||
destParams.pSfx = pSfx;
|
||||
VectorCopy( origin, destParams.origin );
|
||||
VectorCopy( direction,destParams.direction );
|
||||
destParams.fvol = fvol;
|
||||
destParams.soundlevel = soundlevel;
|
||||
destParams.flags = flags;
|
||||
destParams.pitch = pitch;
|
||||
destParams.delay = delay;
|
||||
destParams.speakerentity = speakerentity;
|
||||
// destParams.initialStreamPosition = initialStreamPosition;
|
||||
// destParams.skipInitialSamples = skipInitialSamples;
|
||||
// destParams.m_nQueuedGUID = m_nQueuedGUID;
|
||||
// destParams.m_nSoundScriptHash = m_nSoundScriptHash;
|
||||
// destParams.m_pSoundEntryName = m_pSoundEntryName;
|
||||
// destParams.m_pOperatorsKV = m_pOperatorsKV;
|
||||
// destParams.opStackElapsedTime = opStackElapsedTime;
|
||||
// destParams.opStackElapsedStopTime = opStackElapsedStopTime;
|
||||
destParams.staticsound = staticsound;
|
||||
destParams.bUpdatePositions = bUpdatePositions;
|
||||
destParams.fromserver = fromserver;
|
||||
destParams.bToolSound = bToolSound;
|
||||
destParams.m_bIsScriptHandle =m_bIsScriptHandle;
|
||||
destParams.m_bInEyeSound = m_bInEyeSound;
|
||||
destParams.m_bHRTFFollowEntity = m_bHRTFFollowEntity;
|
||||
destParams.m_bHRTFBilinear = m_bHRTFBilinear;
|
||||
destParams.m_bHRTFLock = m_bHRTFLock;
|
||||
|
||||
/* destParams.m_bDelayedStart = m_bDelayedStart;*/
|
||||
}
|
||||
int userdata;
|
||||
int soundsource;
|
||||
int entchannel;
|
||||
CSfxTable *pSfx;
|
||||
Vector origin;
|
||||
Vector direction;
|
||||
float fvol;
|
||||
soundlevel_t soundlevel;
|
||||
int flags;
|
||||
int pitch;
|
||||
float delay;
|
||||
int speakerentity;
|
||||
int initialStreamPosition;
|
||||
int skipInitialSamples;
|
||||
int m_nQueuedGUID;
|
||||
HSOUNDSCRIPTHASH m_nSoundScriptHash;
|
||||
const char *m_pSoundEntryName;
|
||||
KeyValues *m_pOperatorsKV;
|
||||
float opStackElapsedTime;
|
||||
float opStackElapsedStopTime;
|
||||
|
||||
bool staticsound : 1;
|
||||
bool bUpdatePositions : 1;
|
||||
bool fromserver : 1;
|
||||
bool bToolSound : 1;
|
||||
bool m_bIsScriptHandle : 1;
|
||||
bool m_bDelayedStart : 1;
|
||||
bool m_bInEyeSound : 1;
|
||||
bool m_bHRTFFollowEntity : 1;
|
||||
bool m_bHRTFBilinear : 1;
|
||||
bool m_bHRTFLock : 1;
|
||||
|
||||
static const int UNINT_GUID = -1;
|
||||
static const int GENERATE_GUID = -2; // Generate GUID regardless of the other vol and pitch flags.
|
||||
};
|
||||
|
||||
int S_StartSoundEntry( StartSoundParams_t &pStartParams, int nSeed, bool bFromQueue = false );
|
||||
int S_StartSound( StartSoundParams_t& params );
|
||||
void S_StopSound ( int entnum, int entchannel );
|
||||
enum clocksync_index_t
|
||||
{
|
||||
CLOCK_SYNC_CLIENT = 0,
|
||||
CLOCK_SYNC_SERVER,
|
||||
NUM_CLOCK_SYNCS
|
||||
};
|
||||
|
||||
extern float S_ComputeDelayForSoundtime( float soundtime, clocksync_index_t syncIndex );
|
||||
|
||||
|
||||
void S_StopSoundByGuid( int guid, bool bForceSync = false );
|
||||
float S_SoundDuration( channel_t * pChannel );
|
||||
float S_SoundDurationByGuid( int guid );
|
||||
int S_GetGuidForLastSoundEmitted();
|
||||
bool S_IsSoundStillPlaying( int guid );
|
||||
bool S_GetSoundChannelVolume( const char* sound, float &flVolumeLeft, float &flVolumeRight );
|
||||
void S_GetActiveSounds( CUtlVector< SndInfo_t >& sndlist );
|
||||
void S_SetVolumeByGuid( int guid, float fvol );
|
||||
float S_GetElapsedTime( const channel_t * pChannel );
|
||||
float S_GetElapsedTimeByGuid( int guid );
|
||||
bool S_IsLoopingSoundByGuid( int guid );
|
||||
void S_ReloadSound( const char *pSample );
|
||||
float S_GetMono16Samples( const char *pszName, CUtlVector< short >& sampleList );
|
||||
|
||||
CSfxTable *S_DummySfx( const char *name );
|
||||
CSfxTable *S_PrecacheSound (const char *sample );
|
||||
void S_PrefetchSound( char const *name, bool bPlayOnce );
|
||||
void S_MarkUISound( CSfxTable *pSfx );
|
||||
void S_ReloadFilesInList( IFileList *pFilesToReload );
|
||||
|
||||
vec_t S_GetNominalClipDist();
|
||||
|
||||
extern bool TestSoundChar(const char *pch, char c);
|
||||
extern char *PSkipSoundChars(const char *pch);
|
||||
|
||||
#include "soundchars.h"
|
||||
|
||||
// for recording movies
|
||||
void SND_MovieStart( void );
|
||||
void SND_MovieEnd( void );
|
||||
|
||||
//-------------------------------------
|
||||
|
||||
int S_GetCurrentStaticSounds( SoundInfo_t *pResult, int nSizeResult, int entchannel );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
float S_GetGainFromSoundLevel( soundlevel_t soundlevel, vec_t dist );
|
||||
|
||||
struct musicsave_t
|
||||
{
|
||||
DECLARE_SIMPLE_DATADESC();
|
||||
|
||||
char songname[ 128 ];
|
||||
int sampleposition;
|
||||
short master_volume;
|
||||
};
|
||||
|
||||
void S_GetCurrentlyPlayingMusic( CUtlVector< musicsave_t >& list );
|
||||
void S_RestartSong( const musicsave_t *song );
|
||||
|
||||
struct channelsave
|
||||
{
|
||||
DECLARE_SIMPLE_DATADESC();
|
||||
|
||||
char soundName[64];
|
||||
Vector origin;
|
||||
soundlevel_t soundLevel;
|
||||
int soundSource;
|
||||
int entChannel;
|
||||
int pitch;
|
||||
float opStackElapsedTime;
|
||||
float opStackElapsedStopTime;
|
||||
short masterVolume;
|
||||
};
|
||||
|
||||
typedef CUtlVector< channelsave > ChannelSaveVector;
|
||||
|
||||
void S_GetActiveSaveRestoreChannels( ChannelSaveVector& channelSaves );
|
||||
void S_RestartChannel( channelsave const& channelSave );
|
||||
|
||||
|
||||
bool S_DSPGetCurrentDASRoomNew(void);
|
||||
bool S_DSPGetCurrentDASRoomChanged(void);
|
||||
bool S_DSPGetCurrentDASRoomSkyAbove(void);
|
||||
float S_DSPGetCurrentDASRoomSkyPercent(void);
|
||||
|
||||
enum setmixer_t
|
||||
{
|
||||
MIXER_SET = 0,
|
||||
MIXER_MULT
|
||||
};
|
||||
|
||||
void S_SetMixGroupOfCurrentMixer( const char *szgroupname, const char *szparam, float val, int setMixerType );
|
||||
int S_GetMixGroupIndex( const char *pMixGroupName );
|
||||
int S_GetMixLayerIndex(const char *szmixlayername);
|
||||
void S_SetMixLayerLevel(int index, float level);
|
||||
void S_SetMixLayerTriggerFactor( const char *pMixLayerName, const char *pMixGroupName, float flFactor );
|
||||
void S_SetMixLayerTriggerFactor( int nMixLayerIndex, int nMixGroupIndex, float flFactor );
|
||||
|
||||
// global pitch scale
|
||||
void S_SoundSetPitchScale( float flPitchScale );
|
||||
float S_SoundGetPitchScale( void );
|
||||
|
||||
bool S_SOSSetOpvarFloat( const char *pOpVarName, float flValue );
|
||||
bool S_SOSGetOpvarFloat( const char *pOpVarName, float &flValue );
|
||||
|
||||
void S_ValidateSoundCache( char const *pchWavFile );
|
||||
|
||||
#if defined( _GAMECONSOLE )
|
||||
void S_UnloadSound( const char *pName );
|
||||
#endif
|
||||
|
||||
void S_PurgeSoundsDueToLanguageChange();
|
||||
|
||||
#endif // SOUND_H
|
||||
135
engine/audio/public/soundservice.h
Normal file
135
engine/audio/public/soundservice.h
Normal file
@@ -0,0 +1,135 @@
|
||||
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose: Applicaton-level hooks for clients of the audio subsystem
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef SOUNDSERVICE_H
|
||||
#define SOUNDSERVICE_H
|
||||
|
||||
#if defined( _WIN32 )
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
class Vector;
|
||||
class QAngle;
|
||||
class CAudioSource;
|
||||
typedef int SoundSource;
|
||||
struct SpatializationInfo_t;
|
||||
typedef void *FileNameHandle_t;
|
||||
struct StartSoundParams_t;
|
||||
|
||||
#include "cdll_int.h"
|
||||
#include "utlrbtree.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Services required by the audio system to function, this facade
|
||||
// defines the bridge between the audio code and higher level
|
||||
// systems.
|
||||
//
|
||||
// Note that some of these currently suggest that certain
|
||||
// functionality would like to exist at a deeper layer so
|
||||
// systems like audio can take advantage of them
|
||||
// diectly (toml 05-02-02)
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
abstract_class ISoundServices
|
||||
{
|
||||
public:
|
||||
//---------------------------------
|
||||
// Allocate a block of memory that will be automatically
|
||||
// cleaned up on level change
|
||||
//---------------------------------
|
||||
virtual void *LevelAlloc( int nBytes, const char *pszTag ) = 0;
|
||||
|
||||
//---------------------------------
|
||||
// Notification that someone called S_ExtraUpdate()
|
||||
//---------------------------------
|
||||
virtual void OnExtraUpdate() = 0;
|
||||
|
||||
//---------------------------------
|
||||
// Return false if the entity doesn't exist or is out of the PVS, in which case the sound shouldn't be heard.
|
||||
//---------------------------------
|
||||
virtual bool GetSoundSpatialization( int entIndex, SpatializationInfo_t& info ) = 0;
|
||||
|
||||
//---------------------------------
|
||||
// This is the client's clock, which follows the servers and thus isn't 100% smooth all the time (it is in single player)
|
||||
//---------------------------------
|
||||
virtual float GetClientTime() = 0;
|
||||
|
||||
//---------------------------------
|
||||
// This is the engine's filtered timer, it's pretty smooth all the time
|
||||
//---------------------------------
|
||||
virtual float GetHostTime() = 0;
|
||||
|
||||
//---------------------------------
|
||||
//---------------------------------
|
||||
virtual int GetViewEntity( int nSlot ) = 0;
|
||||
|
||||
//---------------------------------
|
||||
//---------------------------------
|
||||
virtual float GetHostFrametime() = 0;
|
||||
virtual void SetSoundFrametime( float realDt, float hostDt ) = 0;
|
||||
|
||||
//---------------------------------
|
||||
//---------------------------------
|
||||
virtual int GetServerCount() = 0;
|
||||
|
||||
//---------------------------------
|
||||
//---------------------------------
|
||||
virtual bool IsPlayer( SoundSource source ) = 0;
|
||||
|
||||
// -1 if local player not spectating anyone, otherwise the index of the player being spectated
|
||||
virtual int GetSpectatorTarget( ClientDLLObserverMode_t *pObserverMode ) = 0;
|
||||
|
||||
//---------------------------------
|
||||
//---------------------------------
|
||||
virtual void OnChangeVoiceStatus( int entity, int iSsSlot, bool status) = 0;
|
||||
|
||||
// returns false if the player can't hear the other client due to game rules (eg. the other team)
|
||||
virtual bool GetPlayerAudible( int iPlayerIndex ) = 0;
|
||||
|
||||
// Is the player fully connected (don't do DSP processing if not)
|
||||
virtual bool IsConnected() = 0;
|
||||
|
||||
// Calls into client .dll with list of close caption tokens to construct a caption out of
|
||||
virtual void EmitSentenceCloseCaption( char const *tokenstream ) = 0;
|
||||
// Calls into client .dll with list of close caption tokens to construct a caption out of
|
||||
virtual void EmitCloseCaption( char const *captionname, float duration ) = 0;
|
||||
|
||||
virtual char const *GetGameDir() = 0;
|
||||
|
||||
// If the game is paused, certain audio will pause, too (anything with phoneme/sentence data for now)
|
||||
virtual bool IsGamePaused() = 0;
|
||||
|
||||
// restarts the sound system externally
|
||||
virtual void RestartSoundSystem() = 0;
|
||||
|
||||
virtual void GetAllSoundFilesReferencedInReslists( CUtlRBTree< FileNameHandle_t, int >& list ) = 0;
|
||||
virtual void GetAllManifestFiles( CUtlRBTree< FileNameHandle_t, int >& list ) = 0;
|
||||
virtual void GetAllSoundFilesInManifest( CUtlRBTree< FileNameHandle_t, int >& list, char const *manifestfile ) = 0;
|
||||
|
||||
virtual void CacheBuildingStart() = 0;
|
||||
virtual void CacheBuildingUpdateProgress( float percent, char const *cachefile ) = 0;
|
||||
virtual void CacheBuildingFinish() = 0;
|
||||
|
||||
// For building sound cache manifests
|
||||
virtual int GetPrecachedSoundCount() = 0;
|
||||
virtual char const *GetPrecachedSound( int index ) = 0;
|
||||
|
||||
virtual void OnSoundStarted( int guid, StartSoundParams_t& params, char const *soundname ) = 0;
|
||||
virtual void OnSoundStopped( int guid, int soundsource, int channel, char const *soundname ) = 0;
|
||||
|
||||
virtual bool GetToolSpatialization( int iUserData, int guid, SpatializationInfo_t& info ) = 0;
|
||||
|
||||
virtual char const *GetUILanguage() = 0;
|
||||
};
|
||||
|
||||
//-------------------------------------
|
||||
|
||||
extern ISoundServices *g_pSoundServices;
|
||||
|
||||
//=============================================================================
|
||||
|
||||
#endif // SOUNDSERVICE_H
|
||||
147
engine/audio/public/voice.h
Normal file
147
engine/audio/public/voice.h
Normal file
@@ -0,0 +1,147 @@
|
||||
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef VOICE_H
|
||||
#define VOICE_H
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "ivoicetweak.h"
|
||||
|
||||
|
||||
/*! @defgroup Voice Voice
|
||||
Defines the engine's interface to the voice code.
|
||||
@{
|
||||
*/
|
||||
|
||||
|
||||
#define VOICE_OUTPUT_SAMPLE_RATE 22050 // Sample rate that we feed to the mixer for celt codec.
|
||||
#define VOICE_OUTPUT_SAMPLE_RATE_SPEEX 11025 // Sample rate that we feed to the mixer for speex codec.
|
||||
|
||||
|
||||
//! Returned on error from certain voice functions.
|
||||
#define VOICE_CHANNEL_ERROR -1
|
||||
#define VOICE_CHANNEL_IN_TWEAK_MODE -2 // Returned by AssignChannel if currently in tweak mode (not an error).
|
||||
|
||||
#define VOICE_CURRENT_VERSION 3
|
||||
|
||||
|
||||
//! Initialize the voice code.
|
||||
bool Voice_Init(const char *pCodec, int iVersion );
|
||||
|
||||
//! Force Initialization with default codec.
|
||||
void Voice_ForceInit();
|
||||
|
||||
//! Shutdown the voice code.
|
||||
void Voice_Deinit();
|
||||
|
||||
//! Returns true if the client has voice enabled
|
||||
bool Voice_Enabled( void );
|
||||
|
||||
//! Returns true if the client has voice enabled for casters
|
||||
bool Voice_CasterEnabled( uint32 uCasterAccountID );
|
||||
|
||||
//! Set account ID of caster ( 0 = no caster )
|
||||
void Voice_SetCaster( uint32 uCasterAccountID );
|
||||
|
||||
//! Returns true if the client has voice system enabled
|
||||
bool Voice_SystemEnabled( void );
|
||||
|
||||
|
||||
//! Returns true if the user can hear themself speak.
|
||||
bool Voice_GetLoopback();
|
||||
|
||||
|
||||
//! This is called periodically by the engine when the server acks the local player talking.
|
||||
//! This tells the client DLL that the local player is talking and fades after about 200ms.
|
||||
void Voice_LocalPlayerTalkingAck( int iSsSlot );
|
||||
|
||||
|
||||
//! Call every frame to update the voice stuff.
|
||||
bool Voice_Idle(float frametime);
|
||||
|
||||
|
||||
//! Returns true if mic input is currently being recorded.
|
||||
bool Voice_IsRecording();
|
||||
|
||||
//! Begin recording input from the mic.
|
||||
bool Voice_RecordStart(
|
||||
//! Filename to store incoming mic data, or NULL if none.
|
||||
const char *pUncompressedFile,
|
||||
|
||||
//! Filename to store the output of compression and decompressiong with the codec, or NULL if none.
|
||||
const char *pDecompressedFile,
|
||||
|
||||
//! If this is non-null, the voice manager will use this file for input instead of the mic.
|
||||
const char *pMicInputFile
|
||||
);
|
||||
|
||||
//! Stop recording from the mic.
|
||||
bool Voice_RecordStop();
|
||||
|
||||
enum VoiceFormat_t
|
||||
{
|
||||
VoiceFormat_Steam,
|
||||
VoiceFormat_Engine
|
||||
};
|
||||
|
||||
//! Get the most recent N bytes of compressed data. If nCount is less than the number of
|
||||
//! available bytes, it discards the first bytes and gives you the last ones.
|
||||
//! Set bFinal to true on the last call to this (it will flush out any stored voice data).
|
||||
//!
|
||||
//! pnOutSectionNumber can return a 'section number", which is simply a number that will
|
||||
//! increment every time there is a new contiguous block of non-silence.
|
||||
//!
|
||||
//! pnOutSequenceNumber is a compressed byte offset of the data, within the current section.
|
||||
//! this is a TCP-style sequence number, so it actually refers to the byte offset PLUS
|
||||
//! the length of the returned packet.
|
||||
//!
|
||||
//! pnOutUncompressedSampleOffset will return an "absolute" timestamp corresponding to the
|
||||
//! start of the packet, with a precision of VOICE_OUTPUT_SAMPLE_RATE.
|
||||
int Voice_GetCompressedData(char *pchData, int nCount, bool bFinal, VoiceFormat_t *pOutFormat = NULL, uint8 *pnOutSectionNumber = NULL, uint32 *pnOutSectionSequenceNumber = NULL, uint32 *pnOutUncompressedSampleOffset = NULL );
|
||||
|
||||
|
||||
//! Pass incoming data from the server into here.
|
||||
//! The data should have been compressed and gotten through a Voice_GetCompressedData call.
|
||||
void Voice_AddIncomingData(
|
||||
//! Channel index.
|
||||
int nChannel,
|
||||
//! Compressed data to add to the channel.
|
||||
const char *pchData,
|
||||
//! Number of bytes in pchData.
|
||||
int nCount,
|
||||
//! A number that changes whenever we get a new non-silence section of audio. Used to handle silence and deal with resetting the codec internal state
|
||||
uint8 nSectionNumber,
|
||||
//! Byte offset of compressed data, within the current sequence. Used to handle missing packets. For historical reasons, this should include the current packet compressed size. (It is actually the byte offset of the packet to follow.)
|
||||
uint32 nSectionSequenceNumber,
|
||||
//! Uncompressed timestamp. Used to handle silence and dropped packets properly
|
||||
uint32 nUncompressedSampleOffset,
|
||||
//! Use Steam or engine voice data format
|
||||
VoiceFormat_t format
|
||||
);
|
||||
|
||||
#define VOICE_TIME_PADDING 0.2f // Time between receiving the first voice packet and actually starting
|
||||
// to play the sound. This accounts for frametime differences on the clients
|
||||
// and the server.
|
||||
|
||||
|
||||
//! Call this to reserve a voice channel for the specified entity to talk into.
|
||||
//! \return A channel index for use with Voice_AddIncomingData or VOICE_CHANNEL_ERROR on error.
|
||||
int Voice_AssignChannel(int nEntity, bool bProximity, bool bCaster = false, float timePadding = VOICE_TIME_PADDING );
|
||||
|
||||
//! Call this to get the channel index that the specified entity is talking into.
|
||||
//! \return A channel index for use with Voice_AddIncomingData or VOICE_CHANNEL_ERROR if the entity isn't talking.
|
||||
int Voice_GetChannel(int nEntity);
|
||||
|
||||
#if !defined( NO_VOICE )
|
||||
extern IVoiceTweak g_VoiceTweakAPI;
|
||||
#endif
|
||||
|
||||
/*! @} */
|
||||
|
||||
|
||||
#endif // VOICE_H
|
||||
46
engine/audio/public/vox.h
Normal file
46
engine/audio/public/vox.h
Normal file
@@ -0,0 +1,46 @@
|
||||
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $Workfile: $
|
||||
// $Date: $
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// $Log: $
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef VOX_H
|
||||
#define VOX_H
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct sfxcache_t;
|
||||
struct channel_t;
|
||||
|
||||
class CUtlSymbol;
|
||||
|
||||
extern void VOX_Init( void );
|
||||
extern void VOX_Shutdown( void );
|
||||
extern void VOX_ReadSentenceFile( const char *psentenceFileName );
|
||||
extern int VOX_SentenceCount( void );
|
||||
extern void VOX_LoadSound( channel_t *pchan, const char *psz );
|
||||
// UNDONE: Improve the interface of this call, it returns sentence data AND the sentence index
|
||||
extern char *VOX_LookupString( const char *pSentenceName, int *psentencenum, bool *pbEmitCaption = NULL, CUtlSymbol *pCaptionSymbol = NULL, float * pflDuration = NULL );
|
||||
extern void VOX_PrecacheSentenceGroup( class IEngineSound *pSoundSystem, const char *pGroupName, const char *pPathOverride = NULL );
|
||||
extern const char *VOX_SentenceNameFromIndex( int sentencenum );
|
||||
extern float VOX_SentenceLength( int sentence_num );
|
||||
extern const char *VOX_GroupNameFromIndex( int groupIndex );
|
||||
extern int VOX_GroupIndexFromName( const char *pGroupName );
|
||||
extern int VOX_GroupPick( int isentenceg, char *szfound, int strLen );
|
||||
extern int VOX_GroupPickSequential( int isentenceg, char *szfound, int szfoundLen, int ipick, int freset );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // VOX_H
|
||||
Reference in New Issue
Block a user