コード例 #1
0
ファイル: sentence.cpp プロジェクト: Bubbasacs/FinalProj
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : buf - 
//-----------------------------------------------------------------------------
void CSentence::CacheRestoreFromBuffer( CUtlBuffer& buf )
{
	Assert( !buf.IsText() );

	Reset();

	m_bIsCached = true;

	int version = buf.GetChar();
	if ( version != CACHED_SENTENCE_VERSION )
	{
		// Uh oh, version changed...
		m_bIsValid = false;
		return;
	}

	unsigned short pcount = (unsigned short)buf.GetShort();
	
	CPhonemeTag pt;
	int i;

	for ( i = 0; i < pcount; ++i )
	{
		unsigned short code = buf.GetShort();
		float st = buf.GetFloat();
		float et = buf.GetFloat();

		pt.SetPhonemeCode( code );
		pt.SetStartTime( st );
		pt.SetEndTime( et );

		AddRuntimePhoneme( &pt );
	}

	// Now read emphasis samples
	int c = buf.GetShort();

	for ( i = 0; i < c; i++ )
	{
		CEmphasisSample sample;
		sample.SetSelected( false );

		sample.time = buf.GetFloat();
		sample.value = (float)buf.GetShort() / 32767.0f;

		m_EmphasisSamples.AddToTail( sample );
	}

	// And voice duck
	SetVoiceDuck( buf.GetChar() == 0 ? false : true );
	m_bIsValid = true;
}
コード例 #2
0
void CSentence::ParseWords( CUtlBuffer& buf )
{
	char token[ 4096 ];
	char word[ 256 ];
	float start, end;

	while ( 1 )
	{
		buf.GetString( token );
		if ( !stricmp( token, "}" ) )
			break;

		if ( stricmp( token, "WORD" ) )
			break;

		buf.GetString( token );
		Q_strncpy( word, token, sizeof( word ) );

		buf.GetString( token );
		start = atof( token );
		buf.GetString( token );
		end = atof( token );

		CWordTag *wt = new CWordTag( word );
		assert( wt );
		wt->m_flStartTime = start;
		wt->m_flEndTime = end;

		AddWordTag( wt );

		buf.GetString( token );
		if ( stricmp( token, "{" ) )
			break;

		while ( 1 )
		{
			buf.GetString( token );
			if ( !stricmp( token, "}" ) )
				break;

			// Parse phoneme
			int code;
			char phonemename[ 256 ];
			float start, end;
			float volume;

			code = atoi( token );

			buf.GetString( token );
			Q_strncpy( phonemename, token, sizeof( phonemename ) );
			buf.GetString( token );
			start = atof( token );
			buf.GetString( token );
			end = atof( token );
			buf.GetString( token );
			volume = atof( token );

			CPhonemeTag *pt = new CPhonemeTag();
			assert( pt );
			pt->SetPhonemeCode( code );
			pt->SetTag( phonemename );
			pt->SetStartTime( start );
			pt->SetEndTime( end );

			AddPhonemeTag( wt, pt );
		}
	}
}