int RageSoundReader_Resample_Good::Read( float *pBuf, int iFrames )
{
	int iChannels = m_apResamplers.size();

	int iFramesRead = 0;

	/* If the ratio is 1:1, then we're effectively disabled, and we can read
	 * directly into the buffer. */
	int iDownFactor, iUpFactor;
	GetFactors( iDownFactor, iUpFactor );

	if( m_apResamplers[0]->GetFilled() == 0 && iDownFactor == iUpFactor && GetRate() == 1.0f )
		return m_pSource->Read( pBuf, iFrames );

	{
		int iFramesNeeded = m_apResamplers[0]->NumInputsForOutputSamples(iFrames);
		float *pTmpBuf = (float *) alloca( iFramesNeeded * sizeof(float) * iChannels );
		ASSERT( pTmpBuf != NULL );
		int iFramesIn = m_pSource->Read( pTmpBuf, iFramesNeeded );
		if( iFramesIn < 0 )
			return iFramesIn;

		for( int iChannel = 0; iChannel < iChannels; ++iChannel )
		{
			int iGotFrames = m_apResamplers[iChannel]->Run( pTmpBuf + iChannel, iFramesIn, pBuf + iChannel, iFrames, iChannels );
			ASSERT( iGotFrames <= iFrames );

			if( iChannel == 0 )
				iFramesRead += iGotFrames;
		}
	}

	return iFramesRead;
}
/* Call this if the sample factor changes. */
void RageSoundReader_Resample_Good::ReopenResampler()
{
	for( size_t iChannel = 0; iChannel < m_apResamplers.size(); ++iChannel )
		delete m_apResamplers[iChannel];
	m_apResamplers.clear();

	int iDownFactor, iUpFactor;
	GetFactors( iDownFactor, iUpFactor );

	for( size_t iChannel = 0; iChannel < m_pSource->GetNumChannels(); ++iChannel )
	{
		int iMinDownFactor = iDownFactor;
		int iMaxDownFactor = iDownFactor;
		if( m_fRate != -1 )
			iMaxDownFactor *= 5;

		RageSoundResampler_Polyphase *p = new RageSoundResampler_Polyphase( iUpFactor, iMinDownFactor, iMaxDownFactor );
		m_apResamplers.push_back( p );
	}

	if( m_fRate != -1 )
		iDownFactor = lrintf( m_fRate * iDownFactor );

	for( size_t iChannel = 0; iChannel < m_apResamplers.size(); ++iChannel )
		m_apResamplers[iChannel]->SetDownFactor( iDownFactor );
}
示例#3
0
bool    Automatic31(void)
{
  double2 db2 = ReadTrans31_Full();
  if (db2.fValid == false) return false;

  ShowPercent(100);

  SetupFactors(GetFactors(db2.dbValue, 10000));

  return true;
}
示例#4
0
void CMNet::CreateTabularPotential( const intVector& domain,
        const floatVector& data )
{
    AllocFactor( domain.size(), &domain.front() );

    pFactorVector factors;
    int numFactors = GetFactors( domain.size(), &domain.front(), &factors );
    if( numFactors != 1 )
    {
        PNL_THROW( CInconsistentSize,
            "domain must be the same as corresponding domain size got from graph" );
    }
    factors[0]->AllocMatrix( &data.front(), matTable );
}
/*
 * A resampler is commonly used for two things: to change the sample rate of audio,
 * in order to give an audio driver what it wants (SetSampleRate), and to change the
 * sound of audio, changing its speed and pitch (SetRate).  These are the same
 * operation, and we do both in the same pass; the only difference is that SetSampleRate
 * causes GetSampleRate() to change, while SetRate() causes GetStreamToSourceRatio() to change.
 *
 * Changing these values will take effect immediately, with a buffering latency of L/4
 * frames.
 */
void RageSoundReader_Resample_Good::SetRate( float fRatio )
{
	ASSERT( fRatio > 0 );
	bool bRateChangingWasEnabled = m_fRate != -1;
	m_fRate = fRatio;

	if( !bRateChangingWasEnabled )
		ReopenResampler();

	int iDownFactor, iUpFactor;
	GetFactors( iDownFactor, iUpFactor );
	if( m_fRate != -1 )
		iDownFactor = lrintf( m_fRate * iDownFactor );

	/* Set m_fRate to the actual rate, after quantization by iUpFactor. */
	m_fRate = float(iDownFactor) / iUpFactor;

	for( size_t iChannel = 0; iChannel < m_apResamplers.size(); ++iChannel )
		m_apResamplers[iChannel]->SetDownFactor( iDownFactor );
}
示例#6
0
void CMNet::GetFactors( int numberOfNodes, const int *nodes,
					    int *numberOfFactors, CFactor ***params ) const
{
	// bad-args check
    PNL_CHECK_LEFT_BORDER( numberOfNodes, 1 );
    PNL_CHECK_IS_NULL_POINTER(nodes);
    PNL_CHECK_IS_NULL_POINTER(numberOfFactors);
    PNL_CHECK_IS_NULL_POINTER(params);
	// bad-args check end

	if( GetFactors( numberOfNodes, nodes, &m_paramsForNodes ) )
	{
		*numberOfFactors = m_paramsForNodes.size();
        *params             = &m_paramsForNodes.front();
	}
    else
    {
        *numberOfFactors = 0;
        *params             = NULL;
    }
}
示例#7
0
int CGraphicalModel::GetFactors( const intVector& subdomainIn,
		                    pFactorVector *paramsOut ) const
{
	return GetFactors( subdomainIn.size(), &subdomainIn.front(),
		paramsOut );
};