Merge branch 'master' into windows

This commit is contained in:
HappyDOGE
2022-07-27 12:58:56 +03:00
3089 changed files with 38639 additions and 844820 deletions
+3 -3
View File
@@ -1962,7 +1962,7 @@ public:
{
int m_channelNum;
int m_vol; // max volume of sound. -1 means "do not cull, ever, do not even do the math"
unsigned int m_nameHash; // a unique id for a sound file
uintp m_nameHash; // a unique id for a sound file
};
protected:
sChannelVolData m_channelInfo[MAX_CHANNELS];
@@ -1994,7 +1994,7 @@ void CChannelCullList::Initialize( CChannelList &list )
{
m_channelInfo[i].m_vol = ChannelLoudestCurVolume(ch);
AssertMsg(m_channelInfo[i].m_vol >= 0, "Sound channel has a negative volume?");
m_channelInfo[i].m_nameHash = (unsigned int) ch->sfx;
m_channelInfo[i].m_nameHash = (uintp) ch->sfx;
}
else
{
@@ -2029,7 +2029,7 @@ void CChannelCullList::Initialize( CChannelList &list )
++j )
{
// j steps through the sorted list until we find ourselves:
if (m_channelInfo[j].m_nameHash == (unsigned int)(ch->sfx))
if (m_channelInfo[j].m_nameHash == (uintp)(ch->sfx))
{
// that's another channel playing this sound but louder than me
++howManyLouder;
+2 -2
View File
@@ -93,7 +93,7 @@ CAudioSourceMP3::CAudioSourceMP3( CSfxTable *pSfx )
m_dataStart = 0;
int file = g_pSndIO->open( pSfx->GetFileName() );
intp file = g_pSndIO->open( pSfx->GetFileName() );
if ( file != -1 )
{
m_dataSize = g_pSndIO->size( file );
@@ -239,7 +239,7 @@ void CAudioSourceMP3::GetCacheData( CAudioSourceCachedInfo *info )
info->SetSampleRate( m_sampleRate );
info->SetDataStart( 0 );
int file = g_pSndIO->open( m_pSfx->GetFileName() );
intp file = g_pSndIO->open( m_pSfx->GetFileName() );
if ( !file )
{
Warning( "Failed to find file for building soundcache [ %s ]\n", m_pSfx->GetFileName() );
+1 -1
View File
@@ -723,7 +723,7 @@ bool CAudioSourceWave::GetStartupData( void *dest, int destsize, int& bytesCopie
// requesting precache snippet as leader for streaming startup latency
if ( destsize )
{
int file = g_pSndIO->open( m_pSfx->GetFileName() );
intp file = g_pSndIO->open( m_pSfx->GetFileName() );
if ( !file )
{
return false;
+15 -3
View File
@@ -37,7 +37,7 @@ void VoiceTweak_EndVoiceTweakMode();
void EngineTool_OverrideSampleRate( int& rate );
// A fallback codec that should be the most likely to work for local/offline use
#define VOICE_FALLBACK_CODEC "vaudio_celt"
#define VOICE_FALLBACK_CODEC "vaudio_opus"
// Special entity index used for tweak mode.
#define TWEAKMODE_ENTITYINDEX -500
@@ -197,6 +197,9 @@ extern IVoiceRecord* CreateVoiceRecord_AudioQueue(int sampleRate);
extern IVoiceRecord* CreateVoiceRecord_OpenAL(int sampleRate);
#endif
#ifdef USE_SDL
extern IVoiceRecord *CreateVoiceRecord_SDL(int sampleRate);
#endif
static bool VoiceRecord_Start()
{
@@ -583,12 +586,13 @@ bool Voice_Init( const char *pCodecName, int nSampleRate )
bool bSpeex = Q_stricmp( pCodecName, "vaudio_speex" ) == 0;
bool bCelt = Q_stricmp( pCodecName, "vaudio_celt" ) == 0;
bool bOpus = Q_stricmp( pCodecName, "vaudio_opus" ) == 0;
bool bSteam = Q_stricmp( pCodecName, "steam" ) == 0;
// Miles has not been in use for voice in a long long time. Not worth the surface to support ancient demos that may
// use it (and probably do not work for other reasons)
// "vaudio_miles"
if ( !( bSpeex || bCelt || bSteam ) )
if ( !( bSpeex || bCelt || bOpus || bSteam ) )
{
Msg( "Voice_Init Failed: invalid voice codec %s.\n", pCodecName );
return false;
@@ -648,6 +652,8 @@ bool Voice_Init( const char *pCodecName, int nSampleRate )
}
#elif defined( WIN32 )
g_pVoiceRecord = CreateVoiceRecord_DSound( Voice_SamplesPerSec() );
#elif defined( USE_SDL )
g_pVoiceRecord = CreateVoiceRecord_SDL( Voice_SamplesPerSec() );
#else
g_pVoiceRecord = CreateVoiceRecord_OpenAL( Voice_SamplesPerSec() );
#endif
@@ -671,6 +677,12 @@ bool Voice_Init( const char *pCodecName, int nSampleRate )
CreateInterfaceFn createCodecFn = NULL;
g_hVoiceCodecDLL = FileSystem_LoadModule(pCodecName);
if( !g_hVoiceCodecDLL || (createCodecFn = Sys_GetFactory(g_hVoiceCodecDLL)) == NULL )
{
g_hVoiceCodecDLL = FileSystem_LoadModule( VOICE_FALLBACK_CODEC );
pCodecName = VOICE_FALLBACK_CODEC;
}
if ( !g_hVoiceCodecDLL || (createCodecFn = Sys_GetFactory(g_hVoiceCodecDLL)) == NULL ||
(g_pEncodeCodec = (IVoiceCodec*)createCodecFn(pCodecName, NULL)) == NULL || !g_pEncodeCodec->Init( quality ) )
{
@@ -1075,7 +1087,7 @@ int Voice_GetCompressedData(char *pchDest, int nCount, bool bFinal)
{
// Check g_bVoiceRecordStopping in case g_bUsingSteamVoice changes on us
// while waiting for the end of voice data.
if ( g_bUsingSteamVoice || g_bVoiceRecordStopping )
if ( g_bUsingSteamVoice && g_bVoiceRecordStopping )
{
uint32 cbCompressedWritten = 0;
uint32 cbUncompressedWritten = 0;
@@ -141,7 +141,7 @@ bool CMixerControls::GetValue_Float(Control iControl, float &value)
case MicVolume:
{
OSStatus theError = noErr;
for ( int iChannel = 0; iChannel < 3; iChannel++ )
for ( uint iChannel = 0; iChannel < 3; iChannel++ )
{
// scan the channel list until you find a channel set to non-zero, then use that
Float32 theVolume = 0;
+257
View File
@@ -0,0 +1,257 @@
//========= Copyright 1996-2009, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
// This module implements the voice record and compression functions
//#include "audio_pch.h"
//#include "voice.h"
#include "tier0/platform.h"
#include "ivoicerecord.h"
#include "tier0/dbg.h"
#include "tier0/threadtools.h"
#include <assert.h>
#include <SDL_audio.h>
#define RECORDING_BUFFER_SECONDS 3
#define SAMPLE_COUNT 2048
// ------------------------------------------------------------------------------
// VoiceRecord_SDL
// ------------------------------------------------------------------------------
struct AudioBuf
{
int Read(char *out, int len)
{
int nAvalible = (size + (writePtr - readPtr)) % size;
if( nAvalible == 0 )
return 0;
if( len > nAvalible ) len = nAvalible;
int diff = (data + size) - readPtr;
if( len > diff )
{
memcpy(out, readPtr, diff );
memcpy(out+diff, data, len-diff );
} else memcpy(out, readPtr, len);
readPtr += len;
if( readPtr >= data + size )
readPtr -= size;
return len;
}
void Write(char *in, int len)
{
int diff = (data + size) - writePtr;
if( len > diff )
{
memcpy(writePtr, in, diff );
memcpy(data, in+diff, len-diff );
} else memcpy(writePtr, in, len);
writePtr += len;
if (writePtr >= (data + size))
writePtr -= size;
}
int size;
char *data;
char *readPtr;
char *writePtr;
};
class VoiceRecord_SDL : public IVoiceRecord
{
protected:
virtual ~VoiceRecord_SDL();
public:
VoiceRecord_SDL();
virtual void Release();
virtual bool RecordStart();
virtual void RecordStop();
// Initialize. The format of the data we expect from the provider is
// 8-bit signed mono at the specified sample rate.
virtual bool Init(int sampleRate);
virtual void Idle() {}; // Stub
void RenderBuffer( char *pszBuf, int size );
// Get the most recent N samples.
virtual int GetRecordedData(short *pOut, int nSamplesWanted );
SDL_AudioSpec m_ReceivedRecordingSpec;
int m_BytesPerSample; // Да кому нужна эта ваша инкапсуляция?
int m_nSampleRate;
private:
bool InitalizeInterfaces(); // Initialize the openal capture buffers and other interfaces
void ReleaseInterfaces(); // Release openal buffers and other interfaces
void ClearInterfaces(); // Clear members.
private:
SDL_AudioDeviceID m_Device;
AudioBuf m_AudioBuffer;
};
void audioRecordingCallback( void *userdata, uint8 *stream, int len )
{
VoiceRecord_SDL *voice = (VoiceRecord_SDL*)userdata;
voice->RenderBuffer( (char*)stream, len );
}
VoiceRecord_SDL::VoiceRecord_SDL() :
m_nSampleRate( 0 ) ,m_Device( 0 )
{
m_AudioBuffer.data = NULL;
m_AudioBuffer.readPtr = NULL;
m_AudioBuffer.writePtr = NULL;
ClearInterfaces();
}
VoiceRecord_SDL::~VoiceRecord_SDL()
{
ReleaseInterfaces();
ClearInterfaces();
}
void VoiceRecord_SDL::Release()
{
ReleaseInterfaces();
ClearInterfaces();
delete this;
}
bool VoiceRecord_SDL::RecordStart()
{
if ( !m_Device )
InitalizeInterfaces();
if ( !m_Device )
return false;
SDL_PauseAudioDevice( m_Device, SDL_FALSE );
return true;
}
void VoiceRecord_SDL::RecordStop()
{
// Stop capturing.
if ( m_Device )
SDL_PauseAudioDevice( m_Device, SDL_TRUE );
// Release the capture buffer interface and any other resources that are no
// longer needed
ReleaseInterfaces();
}
bool VoiceRecord_SDL::InitalizeInterfaces()
{
//Default audio spec
SDL_AudioSpec desiredRecordingSpec;
SDL_zero(desiredRecordingSpec);
desiredRecordingSpec.freq = m_nSampleRate;
desiredRecordingSpec.format = AUDIO_S16;
desiredRecordingSpec.channels = 1;
desiredRecordingSpec.samples = SAMPLE_COUNT;
desiredRecordingSpec.callback = audioRecordingCallback;
desiredRecordingSpec.userdata = (void*)this;
//Open recording device
m_Device = SDL_OpenAudioDevice( NULL, SDL_TRUE, &desiredRecordingSpec, &m_ReceivedRecordingSpec, 0 );
if( m_Device != 0 )
{
//Calculate per sample bytes
m_BytesPerSample = m_ReceivedRecordingSpec.channels * ( SDL_AUDIO_BITSIZE( m_ReceivedRecordingSpec.format ) / 8 );
//Calculate bytes per second
int bytesPerSecond = m_ReceivedRecordingSpec.freq * m_BytesPerSample;
//Allocate and initialize byte buffer
m_AudioBuffer.size = RECORDING_BUFFER_SECONDS * bytesPerSecond;
if( !m_AudioBuffer.data )
m_AudioBuffer.data = (char *)malloc( m_AudioBuffer.size );
m_AudioBuffer.readPtr = m_AudioBuffer.data;
m_AudioBuffer.writePtr = m_AudioBuffer.data + SAMPLE_COUNT*m_BytesPerSample*2;
memset( m_AudioBuffer.data, 0, m_AudioBuffer.size );
return true;
}
else
return false;
}
bool VoiceRecord_SDL::Init(int sampleRate)
{
m_nSampleRate = sampleRate;
ReleaseInterfaces();
return true;
}
void VoiceRecord_SDL::ReleaseInterfaces()
{
if( m_Device != 0 )
SDL_CloseAudioDevice( m_Device );
m_Device = 0;
}
void VoiceRecord_SDL::ClearInterfaces()
{
if( m_AudioBuffer.data )
{
free( m_AudioBuffer.data );
m_AudioBuffer.data = NULL;
m_AudioBuffer.readPtr = NULL;
m_AudioBuffer.writePtr = NULL;
}
m_Device = 0;
}
void VoiceRecord_SDL::RenderBuffer( char *pszBuf, int size )
{
m_AudioBuffer.Write( pszBuf, size );
}
int VoiceRecord_SDL::GetRecordedData(short *pOut, int nSamples )
{
if ( !m_AudioBuffer.data || nSamples == 0 )
return 0;
int cbSamples = nSamples * m_BytesPerSample;
return m_AudioBuffer.Read( (char*)pOut, cbSamples )/m_BytesPerSample;
}
IVoiceRecord* CreateVoiceRecord_SDL(int sampleRate)
{
VoiceRecord_SDL *pRecord = new VoiceRecord_SDL;
if ( pRecord && pRecord->Init(sampleRate) )
return pRecord;
else if( pRecord )
pRecord->Release();
return NULL;
}