Example #1
0
int USBAudioDevice::GetCurrentSampleRate()
{
	if(!IsValidDevice())
		return 0;

	if(m_acInterfaceList.Count() == 1 && m_acInterfaceList.First()->m_clockSourceList.Count() == 1)
	{
		int acInterfaceNum = m_acInterfaceList.First()->Descriptor().bInterfaceNumber;
		int clockID = m_acInterfaceList.First()->m_clockSourceList.First()->m_clockSource.bClockID;
		return GetSampleRateInternal(acInterfaceNum, clockID);
	}
	else
	{
		//more AC interfaces???
	}

	return 0;
}
void RageSoundReader_Merge::Finish( int iPreferredSampleRate )
{
	/* Figure out how many channels we have.  All sounds must either have 1 or 2 channels,
	 * which will be converted as needed, or have the same number of channels. */
	m_iChannels = 1;
	FOREACH( RageSoundReader *, m_aSounds, it )
		m_iChannels = max( m_iChannels, (*it)->GetNumChannels() );

	/*
	 * We might get different sample rates from our 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_iSampleRate = GetSampleRateInternal();
	if( m_iSampleRate == -1 )
	{
		FOREACH( RageSoundReader *, m_aSounds, it )
		{
			RageSoundReader *&pSound = (*it);

			RageSoundReader_Resample_Good *pResample = new RageSoundReader_Resample_Good( pSound, iPreferredSampleRate );
			pSound = pResample;
		}
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() );
}