Beispiel #1
0
//---------------------------------------------------------------------------
long SoundSystem::playDigitalSample (unsigned long sampleId, Stuff::Vector3D pos, bool allowDupes)
{
	if (useSound && allowDupes || (!isPlayingSample(sampleId) && !allowDupes))
	{
		if (sampleId >= numSoundBites)
			return(-1);
			
		long ourChannel = findOpenChannel(1,SUPPORT_CHANNEL);
	
		if (ourChannel != -1)
		{
			float distanceVolume = 1.0f;
			float panVolume = 0.0f;
			if (eye && (pos.z != -9999.0f))
			{
				Stuff::Vector3D distance;
				distance.Subtract(eye->getPosition(),pos);
				float dist = distance.GetApproximateLength();
				if (dist < FALLOFF_DISTANCE)
					distanceVolume = (FALLOFF_DISTANCE - dist) / FALLOFF_DISTANCE;
				else
					return -1;		//Do not play sound.  TOO far away!!

				//Figure out where in stereo field to play.
				OppRotate(distance,eye->getRotation().y);

				panVolume = distance.x / (FALLOFF_DISTANCE * 0.5f);
				if (panVolume > 1.0f)
					panVolume = 1.0f;
				else if (panVolume < -1.0f)
					panVolume = -1.0f;
			}

			float vol = sounds[sampleId].volume * distanceVolume;
			if (vol > 1.0f)
				vol = 1.0f;
			else if (vol <= 0.0f)		//No VOlume.  DON't PLAY!
				return -1;

			gosAudio_SetChannelSlider(ourChannel,gosAudio_Panning, panVolume);
			gosAudio_SetChannelSlider(ourChannel,gosAudio_Volume, (digitalMasterVolume * vol * SFXVolume)) ;
			channelSampleId[ourChannel] = sampleId;
			channelInUse[ourChannel] = TRUE;
				
			if (sounds[sampleId].biteData && sounds[sampleId].resourceHandle)
			{
				gosAudio_AssignResourceToChannel( ourChannel, sounds[sampleId].resourceHandle );
				gosAudio_SetChannelPlayMode(ourChannel, gosAudio_PlayOnce);
			}
			
			return(ourChannel);
		}
	}

	return(-1);
}
	static void update(){ //update method pattern
		if(head_ == tail_) return;
		
		RessourceId resource = loadSound(pending_[head_].id);
		int channel = findOpenChannel();
		if(channel == -1) return;
		startSound(resource, channel, pending_[head_].volume);

		head_ = (head_ +1) % MAX_PENDING;
	}