예제 #1
0
	/// sets velocity of the soundsource
	virtual void SetVelocity(const float x, const float y, const float z){
		if(!Is3D())return;
		mlVel.x = x * mSoundSystem->mfDistanceFactor;
		mlVel.y = y * mSoundSystem->mfDistanceFactor;
		mlVel.z = z * mSoundSystem->mfDistanceFactor;
		if(mpChannel == 0)return;

		result = FMOD_Channel_Set3DAttributes(mpChannel, &mlPos, &mlVel);
		ERRCHECK(result);
	}
예제 #2
0
Sound::Sound(const Sound &_sound)
{
	//FMOD_SOUND *temp = *&_sound.sound;
	this->sound = *&_sound.sound;
	f_pos = _sound.f_pos;
	f_vel = _sound.f_vel;
	*result = FMOD_Channel_Set3DAttributes(channel,&f_pos,&f_vel);
	ERRCHECK();
	*result = FMOD_Channel_SetPaused(channel, true);
	ERRCHECK();

	pos = new Vector(_sound.pos->X_Y_Z[0],_sound.pos->X_Y_Z[1],_sound.pos->X_Y_Z[2]);
	vel = new Vector(_sound.vel->X_Y_Z[0],_sound.vel->X_Y_Z[1],_sound.vel->X_Y_Z[2]);
}
예제 #3
0
void Sound::update()
{
	f_pos.x = pos->X_Y_Z[0];
	f_pos.y = pos->X_Y_Z[1];
	f_pos.z = pos->X_Y_Z[2];

	f_vel.x = vel->X_Y_Z[0];
	f_vel.y = vel->X_Y_Z[1];
	f_vel.z = vel->X_Y_Z[2];

	//*result = channel->set3DAttributes(&f_pos,&f_vel);
	*result = FMOD_Channel_Set3DAttributes(channel,&f_pos,&f_vel);
	ERRCHECK();
}
예제 #4
0
void Sound::play(Vector &position)
{
	pos = &position;
	f_pos.x = pos->X_Y_Z[0];
	f_pos.y = pos->X_Y_Z[1];
	f_pos.z = pos->X_Y_Z[2];

	f_vel.x = vel->X_Y_Z[0];
	f_vel.y = vel->X_Y_Z[1];
	f_vel.z = vel->X_Y_Z[2];
	
	*result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound, false, &channel);
	ERRCHECK();
	*result = FMOD_Channel_Set3DAttributes(channel,&f_pos,&f_vel);
	ERRCHECK();
}
예제 #5
0
Sound::Sound(const char *file, int _mode,Vector &_pos, Vector&_vel, FMOD_SYSTEM *_system, FMOD_RESULT &_result)
{
	system = _system;
	result = &_result;
	if(_mode > 1)
	{
		mode =_mode = 0;
	}else
	{
		mode = _mode;
	}
	
	switch(_mode)
	{
	case SOUND:
		*result = FMOD_System_CreateSound(system, file, FMOD_DEFAULT, 0, &sound);
		this->setSoundMode(FMOD_LOOP_OFF);
		break;
	case STREAM:
		*result =  FMOD_System_CreateStream(system, file, FMOD_DEFAULT, 0,&sound);
		this->setSoundMode(FMOD_LOOP_NORMAL);
		break;
	}
	ERRCHECK();

	pos = &_pos;
	vel = &_vel;

	f_pos.x = pos->X_Y_Z[0];
	f_pos.y = pos->X_Y_Z[1];
	f_pos.z = pos->X_Y_Z[2];

	f_vel.x = vel->X_Y_Z[0];
	f_vel.y = vel->X_Y_Z[1];
	f_vel.z = vel->X_Y_Z[2];

	//*result = channel->set3DAttributes(&f_pos,&f_vel);
	*result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound, true, &channel);
	ERRCHECK();
	*result = FMOD_Channel_Set3DAttributes(channel,&f_pos,&f_vel);
	ERRCHECK();
	*result = FMOD_Channel_SetPaused(channel, true);
	ERRCHECK();
}
예제 #6
0
int main(int argc, char **argv)
{
	setup_ui(&argc, &argv);

	FMOD_SOUND *soundtrack;
	FMOD_CHANNEL *channel1;

	FMOD_VECTOR position = { 0, 0, 0 };
	FMOD_VECTOR velocity = { 0, 0, 0 };
	FMOD_VECTOR forward = { 0, 0, 1 };
	FMOD_VECTOR up = { 0, 1, 0 };

	FMOD_System_Create(&fsystem);
	FMOD_System_Init(fsystem, 100, FMOD_INIT_NORMAL, NULL);
	FMOD_System_Set3DSettings(fsystem, 1.0f, 1.0f, 1.0f);

	FMOD_System_CreateSound(fsystem, argc < 2 ? "../sounds/blast.wav" : argv[1], FMOD_3D | FMOD_LOOP_NORMAL, 0, &soundtrack);
	FMOD_System_PlaySound(fsystem, soundtrack, NULL, 1, &channel1);
	FMOD_Channel_Set3DAttributes(channel1, &position, &velocity, NULL);
	FMOD_Channel_SetPaused(channel1, 0);

	FMOD_System_Set3DListenerAttributes(fsystem, 0, &position, &velocity, &forward, &up);
	FMOD_System_Update(fsystem);

	gtk_main();

	/*int i = 0;
	while (i < 500) {
		i++;
		FMOD_System_Update(fsystem);

		struct timespec sleepTime = { 0, 50 * 1000 * 1000 };
		nanosleep(&sleepTime, NULL);
	}*/

	FMOD_Sound_Release(soundtrack);
	FMOD_System_Close(fsystem);
	FMOD_System_Release(fsystem);
}
예제 #7
0
void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{
	auto listener = m_World->GetComponent<Components::Listener>(entity);
	if(listener)
	{
		int lID = std::find(m_Listeners.begin(), m_Listeners.end(), entity) - m_Listeners.begin();
		auto lTransform = m_World->GetComponent<Components::Transform>(entity);
		
		glm::vec3 tPos = m_TransformSystem->AbsolutePosition(entity);
		FMOD_VECTOR lPos = {tPos.x, tPos.y, tPos.z}; 

		glm::vec3 tVel = (lTransform->Velocity * 1000.f) / (float)dt;
		FMOD_VECTOR lVel = {tVel.x, tVel.y, tVel.z};

		glm::vec3 tUp = glm::normalize(lTransform->Orientation * glm::vec3(0,1,0));
		FMOD_VECTOR lUp = {tUp.x, tUp.y, tUp.z}; 
		glm::vec3 tForward = glm::normalize(lTransform->Orientation * glm::vec3(0,0,-1));
		FMOD_VECTOR lForward = {tForward.x, tForward.y, tForward.z};

		FMOD_System_Set3DListenerAttributes(m_System, lID, (const FMOD_VECTOR*)&lPos, (const FMOD_VECTOR*)&lVel, (const FMOD_VECTOR*)&lForward, (const FMOD_VECTOR*)&lUp);
	}

	auto emitter = m_World->GetComponent<Components::SoundEmitter>(entity);
	if(emitter)
	{
		FMOD_CHANNEL* channel = m_Channels[entity];
		FMOD_SOUND* sound = m_Sounds[entity];
		auto eTransform = m_World->GetComponent<Components::Transform>(entity);
		
		glm::vec3 tPos = m_TransformSystem->AbsolutePosition(entity);
		FMOD_VECTOR ePos = {tPos.x, tPos.y, tPos.z};

		glm::vec3 tVel = (eTransform->Velocity * 1000.f) / float(dt);
		FMOD_VECTOR eVel = {tVel.x, tVel.y, tVel.z};
		
		FMOD_Channel_Set3DAttributes(channel, &ePos, &eVel);
	}
}
예제 #8
0
	/// starts or continue playing, true if successfull
	virtual const bool Play(){
		if(IsPlaying())return true;
		if(IsPaused()){
			// unpause sound
			if(mpChannel){
				result = FMOD_Channel_SetPaused(mpChannel,false);
				ERRCHECK(result);
			}
		} else {
			// start playing
			mpChannel = 0;
			// alloc channel
			if(mpSound && mSoundSystem && mSoundSystem->mpSystem){
				result = FMOD_System_PlaySound(mSoundSystem->mpSystem, FMOD_CHANNEL_FREE, mpSound, true, &mpChannel);
				ERRCHECK(result);
			}
			
			// channel free and working?
			if(mpChannel){
				
				if(mb3D){
					// set 3d position and velocity data
					result = FMOD_Channel_Set3DAttributes(mpChannel, &mlPos, &mlVel);
					ERRCHECK(result);
					// set currently set minmax distances
					SetMinMaxDistance(mfMinDistance,mfMaxDistance);
				} 
				
				result = FMOD_Channel_SetPaused(mpChannel,false);
				ERRCHECK(result);
				
				return true;
			} else return false;
		}
		return false;
	}
예제 #9
0
파일: sound.cpp 프로젝트: Joooo/pseudoform
 void sound::pos(const vec3 &v)
 {
     FMOD_VECTOR fv = { v.x, v.y, v.z };
     FMOD_Channel_Set3DAttributes(_chan, &fv, NULL);
 }