SoundReader *ApplyFilters( SoundReader *s, int filters )
{
	if( filters & FILTER_PRELOAD )
	{
		SoundReader_Preload *r = new SoundReader_Preload();
		if( r->Open( s ) )
			s = r;
		else
		{
			printf( "Didn't preload\n" );
			delete r;
		}
	}
	
	if( filters & FILTER_RESAMPLE_FAST )
	{
		RageSoundReader_Resample *r = RageSoundReader_Resample::MakeResampler( RageSoundReader_Resample::RESAMP_FAST );
		r->Open( s );
		r->SetSampleRate( 10000 );

		s = r;
	}

	return s;
}
Example #2
0
void RageSound::LoadSoundReader( SoundReader *pSound )
{
	Unload();

	m_iDecodePosition = m_iStoppedPosition = 0;

	const int iNeededRate = SOUNDMAN->GetDriverSampleRate( pSound->GetSampleRate() );
	if( iNeededRate != pSound->GetSampleRate() )
	{
		RageSoundReader_Resample *Resample = RageSoundReader_Resample::MakeResampler( PREFSMAN->m_SoundResampleQuality );
		Resample->Open( pSound );
		Resample->SetSampleRate( iNeededRate );
		pSound = Resample;
	}

	m_pSource = pSound;
}
Example #3
0
void RageSoundReader_Chain::Finish()
{
	/* Remove any sounds that don't have corresponding SoundReaders. */
	for( unsigned i = 0; i < m_Sounds.size(); )
	{
		sound &sound = m_Sounds[i];

		map<CString, SoundReader *>::iterator it = m_apLoadedSounds.find( sound.sPath );
		if( it == m_apLoadedSounds.end() )
		{
			m_Sounds.erase( m_Sounds.begin()+i );
			continue;
		}

		++i;
	}

	/* Figure out how many channels we have. */
	m_iChannels = 1;
	map<CString, SoundReader *>::iterator it;
	for( it = m_apLoadedSounds.begin(); it != m_apLoadedSounds.end(); ++it )
		m_iChannels = max( m_iChannels, it->second->GetNumChannels() );

	/* If any sounds have a non-0 pan, we're stereo. */
	for( unsigned i = 0; i < m_Sounds.size(); ++i )
		if( fabs(m_Sounds[i].fPan) > 0.0001f )
			m_iChannels = 2;
	
	/*
	 * We might get different sample rates fro mour sources.  If they're all the same
	 * sample rate, just leave it alone, so the whole sound can be resampled as a group.
	 * If not, resample eveything to the preferred rate.  (Using the preferred rate
	 * should avoid redundant resampling later.)
	 */
	m_iActualSampleRate = GetSampleRateInternal();
	if( m_iActualSampleRate == -1 )
	{
		for( it = m_apLoadedSounds.begin(); it != m_apLoadedSounds.end(); ++it )
		{
			SoundReader *&pSound = it->second;

			/* We're preprocessing this; let's just use high quality resampling. */
			RageSoundReader_Resample *pResample = RageSoundReader_Resample::MakeResampler( RageSoundReader_Resample::RESAMP_HIGHQUALITY );
			pResample->Open( pSound );
			pResample->SetSampleRate( m_iPreferredSampleRate );
			pSound = pResample;
		}

		m_iActualSampleRate = m_iPreferredSampleRate;
	}

	/* Attempt to preload all sounds. */
	for( it = m_apLoadedSounds.begin(); it != m_apLoadedSounds.end(); ++it )
	{
		SoundReader *&pSound = it->second;
		RageSoundReader_Preload::PreloadSound( pSound );
	}

	/* Sort the sounds by start time. */
	sort( m_Sounds.begin(), m_Sounds.end() );
}