//----------------------------------------------------------------------------- // Purpose: // Input : *soundname - // params - // Output : Returns true on success, false on failure. //----------------------------------------------------------------------------- bool CSoundEmitterSystemBase::GetParametersForSound( const char *soundname, CSoundParameters& params ) { int index = GetSoundIndex( soundname ); if ( index == -1 ) { DevMsg( "CSoundEmitterSystemBase::GetParametersForSound: No such sound %s\n", soundname ); return false; } CSoundParametersInternal *internal = InternalGetParametersForSound( index ); if ( !internal ) { Assert( 0 ); DevMsg( "CSoundEmitterSystemBase::GetParametersForSound: No such sound %s\n", soundname ); return false; } params.channel = internal->channel; params.volume = RandomInterval( internal->volume ); params.pitch = RandomInterval( internal->pitch ); params.pitchlow = internal->pitch.start; params.pitchhigh = params.pitchlow + internal->pitch.range; params.count = internal->soundnames.Count(); params.soundname[ 0 ] = 0; if ( params.count >= 1 ) { CUtlSymbol sym = internal->soundnames[ random->RandomInt( 0, params.count - 1 ) ]; Q_strncpy( params.soundname, m_Waves.String( sym ), sizeof( params.soundname ) ); } params.soundlevel = (soundlevel_t)(int)RandomInterval( internal->soundlevel ); params.play_to_owner_only = internal->play_to_owner_only; if ( !params.soundname[ 0 ] ) { DevMsg( "CSoundEmitterSystemBase::GetParametersForSound: sound %s has no wave or rndwave key!\n", soundname ); return false; } if ( internal->had_missing_wave_files && params.soundname[ 0 ] != CHAR_SENTENCE ) { char testfile[ 256 ]; Q_snprintf( testfile, sizeof( testfile ), "sound/%s", PSkipSoundChars( params.soundname ) ); if ( !filesystem->FileExists( testfile ) ) { DevMsg( "CSoundEmitterSystemBase::GetParametersForSound: sound '%s' references wave '%s' which doesn't exist on disk!\n", soundname, params.soundname ); return false; } } return true; }
//----------------------------------------------------------------------------- // Generates a sound clip for the game sound //----------------------------------------------------------------------------- CDmeSoundClip *CSFMGenApp::CreateSoundClip( CDmeFilmClip *pShot, const char *pAnimationSetName, const char *pGameSound, studiohdr_t *pStudioHdr, CDmeGameSound **ppGameSound ) { *ppGameSound = NULL; CDmeTrackGroup *pTrackGroup = pShot->FindOrAddTrackGroup( "audio" ); CDmeTrack *pTrack = pTrackGroup->FindOrAddTrack( pAnimationSetName, DMECLIP_SOUND ); // Get the gender for the model gender_t actorGender = g_pSoundEmitterSystem->GetActorGender( pStudioHdr->name ); // Get the wav file for the gamesound. CSoundParameters params; if ( !g_pSoundEmitterSystem->GetParametersForSound( pGameSound, params, actorGender ) ) { Warning( "Unable to determine .wav file for gamesound %s!\n", pGameSound ); return NULL; } // Get the sound duration char pFullPath[MAX_PATH]; char pRelativePath[MAX_PATH]; const char *pWavFile = PSkipSoundChars( params.soundname ); Q_ComposeFileName( "sound", pWavFile, pRelativePath, sizeof(pRelativePath) ); g_pFullFileSystem->RelativePathToFullPath( pRelativePath, "GAME", pFullPath, sizeof(pFullPath) ); DmeTime_t duration( GetWavSoundDuration( pFullPath ) ); CDmeGameSound *pDmeSound = CreateElement< CDmeGameSound >( pGameSound, pTrack->GetFileId() ); Assert( pDmeSound ); pDmeSound->m_GameSoundName = pGameSound; pDmeSound->m_SoundName = params.soundname; pDmeSound->m_Volume = params.volume; pDmeSound->m_Level = params.soundlevel; pDmeSound->m_Pitch = params.pitch; pDmeSound->m_IsStatic = true; pDmeSound->m_Channel = CHAN_STATIC; pDmeSound->m_Flags = 0; pDmeSound->m_Origin = vec3_origin; pDmeSound->m_Direction = vec3_origin; CDmeSoundClip *pSubClip = CreateElement< CDmeSoundClip >( pGameSound, pTrack->GetFileId() ); pSubClip->m_Sound = pDmeSound; pSubClip->SetStartTime( DMETIME_ZERO ); pSubClip->SetTimeOffset( DmeTime_t( -params.delay_msec / 1000.0f ) ); pSubClip->SetDuration( duration ); pTrack->AddClip( pSubClip ); *ppGameSound = pDmeSound; return pSubClip; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- int CSoundEmitterSystemBase::CheckForMissingWavFiles( bool verbose ) { int missing = 0; int c = GetSoundCount(); int i; char testfile[ 512 ]; for ( i = 0; i < c; i++ ) { CSoundParametersInternal *internal = InternalGetParametersForSound( i ); if ( !internal ) { Assert( 0 ); continue; } int waveCount = internal->soundnames.Count(); for ( int wave = 0; wave < waveCount; wave++ ) { CUtlSymbol sym = internal->soundnames[ wave ]; const char *name = m_Waves.String( sym ); if ( !name || !name[ 0 ] ) { Assert( 0 ); continue; } // Skip ! sentence stuff if ( name[0] == CHAR_SENTENCE ) continue; Q_snprintf( testfile, sizeof( testfile ), "sound/%s", PSkipSoundChars( name ) ); if ( filesystem->FileExists( testfile ) ) continue; internal->had_missing_wave_files = true; ++missing; if ( verbose ) { DevMsg( "Sound %s references missing file %s\n", GetSoundName( i ), name ); } } } return missing; }
//----------------------------------------------------------------------------- // Purpose: Simple wrapper to crack naming convention and create the proper wave source // Input : *pName - WAVE filename // Output : CAudioSource //----------------------------------------------------------------------------- CAudioSource *AudioSource_Create( const char *pName ) { if ( !pName ) return NULL; // if ( TestSoundChars(pName, CHAR_SENTENCE) ) // sentence ; // Names that begin with CHAR_STREAM are streaming. // Skip over the CHAR_STREAM and create a streamed source if ( TestSoundChar( pName, CHAR_STREAM ) ) // stream return Audio_CreateStreamedWave( PSkipSoundChars(pName) ); // These are loaded into memory directly return Audio_CreateMemoryWave( PSkipSoundCars(pName) ); }
//----------------------------------------------------------------------------- // Purpose: // Input : *name - // flags - // Output : int //----------------------------------------------------------------------------- int CGameServer::PrecacheSound( char const *name, int flags ) { if ( !m_pSoundPrecacheTable ) return -1; int idx = m_pSoundPrecacheTable->AddString( true, name ); if ( idx == INVALID_STRING_INDEX ) { return -1; } // mark the sound as being precached, but check first that reslist generation is enabled to save on the va() call if (MapReslistGenerator().IsEnabled() && name[0]) { MapReslistGenerator().OnResourcePrecached( va( "sound/%s", PSkipSoundChars( name ) ) ); } // first time, set file size & flags CPrecacheUserData p; CPrecacheUserData const *pExisting = (CPrecacheUserData const *)m_pSoundPrecacheTable->GetStringUserData( idx, NULL ); if ( !pExisting ) { p.flags = flags; } else { // Just or in any new flags p = *pExisting; p.flags |= flags; } m_pSoundPrecacheTable->SetStringUserData( idx, sizeof( p ), &p ); CPrecacheItem *slot = &sound_precache[ idx ]; slot->SetName( name ); return idx; }