Пример #1
0
size_t CSoundLibrary::AddSound(const tstring& pszFilename)
{
	size_t iSound = FindSound(pszFilename);
	if (iSound != ~0)
	{
		Get()->m_apSounds[iSound]->m_iReferences++;
		return iSound;
	}

	size_t iLocation = ~0;
	for (size_t i = 0; i < Get()->m_apSounds.size(); i++)
	{
		if (!Get()->m_apSounds[i])
		{
			iLocation = i;
			break;
		}
	}

	if (iLocation == ~0)
	{
		iLocation = Get()->m_apSounds.size();
		Get()->m_apSounds.push_back();
	}

	Get()->m_iSoundsLoaded++;

	Get()->m_apSounds[iLocation] = new CSound(pszFilename);
	Get()->m_apSounds[iLocation]->m_iReferences++;
	return iLocation;
}
Пример #2
0
/**
**  Maps a sound name to its id
**
**  @param name  Sound name.
**
**  @return      Sound identifier for this name.
*/
CSound *SoundForName(const std::string &name)
{
	Assert(!name.empty());
	CSound *sound = FindSound(name);
	if (sound) {
		return sound;
	}
	DebugPrint("Can't find sound `%s' in sound table\n" _C_ name.c_str());
	return NULL;
}
Пример #3
0
/**
**  Ask the sound server to build a special sound group.
**
**  Register two sound groups together to make a special sound (for
**  selection). Return the corresponding id after registering it under a
**  given name.
**
**  @param name    the name of the group (handled by caller).
**  @param first   id of the first group
**  @param second  id of the second group
**
**  @return        Registered sound identifier.
*/
CSound *MakeSoundGroup(const std::string &name, CSound *first, CSound *second)
{
	CSound *sound;

	if ((sound = FindSound(name))) {
		DebugPrint("re-register sound `%s'\n" _C_ name.c_str());
		return sound;
	}

	sound = RegisterTwoGroups(first, second);
	if(sound != NO_SOUND)
		MapSound(name, sound);

	return sound;
}
Пример #4
0
/**
**  Ask the sound server to register a sound and store the mapping
**  between its name and its id.
**  Register a sound group (or an unique sound if nb==1) and get the
**  corresponding sound id.
**
**  @param name  name of this sound group (Freed by caller).
**  @param file  list of sound file names
**  @param nb    number of sounds
**
**  @return      the sound id of the created group
*/
CSound *MakeSound(const std::string &name, const char *file[], int nb)
{
	CSound *sound;

	Assert(nb <= 255);

	if ((sound = FindSound(name))) {
		DebugPrint("re-register sound `%s'\n" _C_ name.c_str());
		return sound;
	}

	sound = RegisterSound(file, nb);
	if(sound != NO_SOUND)
		MapSound(name, sound);

	return sound;
}
Пример #5
0
int SoundManager::CreateSound(String &fileName, SOUND_TYPE soundType)
{
	Archive *      fileArchive;
	FMOD_RESULT    result;
	FMOD::Sound *  sound;
	String         fullPathName;
	SoundInstance *newSoundInstance;

	int soundIndex;
	soundIndex = FindSound(fileName, soundType);
	if (soundIndex != INVALID_SOUND_INDEX)
		return soundIndex;

	fullPathName = fileName;
	FileLocator * fileLocator = (FileLocator * )ResourceGroupManager::getSingletonPtr();
	fileArchive = fileLocator->Find(fullPathName);
	if (!fileArchive)
	{
		Ogre::LogManager::getSingleton().logMessage("SoundManager::CreateSound could not find sound '" + fileName + "'");
		return INVALID_SOUND_INDEX;
	}

	IncrementNextSoundInstanceIndex();
	newSoundInstance = soundInstanceVector->at(nextSoundInstanceIndex);
	newSoundInstance->fileName = fileName;
	newSoundInstance->fileArchive = fileArchive;
	newSoundInstance->soundType = soundType;

	switch (soundType)
	{
	case SOUND_TYPE_3D_SOUND:
		{
			result = system->createSound((const char *)newSoundInstance, FMOD_3D | FMOD_HARDWARE, 0, &sound);
			break;
		}

	case SOUND_TYPE_3D_SOUND_LOOPED:
		{
			result = system->createSound((const char *)newSoundInstance, FMOD_LOOP_NORMAL | FMOD_3D | FMOD_HARDWARE, 0, &sound);
			break;
		}

	case SOUND_TYPE_2D_SOUND:
		{
			result = system->createStream((const char *)newSoundInstance, FMOD_DEFAULT, 0, &sound);
			break;
		}

	case SOUND_TYPE_2D_SOUND_LOOPED:
		{
			result = system->createStream((const char *)newSoundInstance, FMOD_LOOP_NORMAL | FMOD_2D | FMOD_HARDWARE, 0, &sound);
			break;
		}

	default:
		{
			Ogre::LogManager::getSingleton().logMessage("SoundManager::CreateSound could not load sound '" + fileName + "' (invalid soundType)");
			return INVALID_SOUND_INDEX;
		}
	}

	if (result != FMOD_OK)
	{
		Ogre::LogManager::getSingleton().logMessage("SoundManager::CreateSound could not load sound '" + fileName + "'  FMOD Error:" + FMOD_ErrorString(result));
		return INVALID_SOUND_INDEX;
	}

	newSoundInstance->fmodSound = sound;
	return nextSoundInstanceIndex;
}
Пример #6
0
int main( int argc, char* argv[] )
{
	bool writewav = false;
	bool list = false;
	std::vector< std::string > soundlist;

	SetRetromatFreq( 44100 );

	int i;
	for( i=1; i<argc; ++i )
	{
		if( 0 == strcmp( argv[i], "-writewav" ) )
			writewav = true;
		else if( 0 == strcmp( argv[i], "-list" ) )
			list = true;
		else
			soundlist.push_back( argv[i] );
	}

	if( list )
	{
		SoundEntry* p=Sounds;
		while( p->name )
		{
			printf( "%s\n", p->name );
			++p;
		}
		return 0;
	}


	if( soundlist.empty() )
	{
		SoundEntry* p=Sounds;
		while( p->name )
		{
			soundlist.push_back( p->name );
			++p;
		}
	}


	for( i=0; i<soundlist.size(); ++i )
	{

		SoundEntry* snd = FindSound( soundlist[i] );
		if( !snd )
		{
			printf("ERROR: couldn't find sound %s!\n", soundlist[i].c_str() );
			return -1;
		}


		std::vector< float > buf;
		buf.reserve( 10 * (int)stk::Stk::sampleRate() );
		(*snd->fn)( buf );
		if( writewav )
		{
            std::string filename = soundlist[i] + ".wav";
			printf("writing %s...", filename.c_str() );
            stk::FileWvOut out( filename );
			std::vector<float>::const_iterator it;
			for( it=buf.begin(); it!=buf.end(); ++it )
				out.tick( *it );
			printf("ok\n");
		}
		else
		{
			printf("playing %s...", soundlist[i].c_str() );
			fflush( stdout );
            stk::RtWvOut out(1);
			std::vector<float>::const_iterator it;
			for( it=buf.begin(); it!=buf.end(); ++it )
				out.tick( *it );
			printf("ok\n");
		}
	}
	
	return 0;	
}