Esempio n. 1
0
NMUInt32 GetTimestampMilliseconds()
{
	NMUInt32		timestamp = 0;
	NMUInt32 		clocksPerSec;
	
#ifdef OP_PLATFORM_MAC_CFM
	double		clocks;
#else
	clock_t		clocks;
#endif


#ifdef OP_PLATFORM_MAC_CFM
	UnsignedWide mSeconds;
	clocksPerSec = 1000000;  // Magic Number = Microseconds
	Microseconds( &mSeconds );
    
	// Convert to appropriate type in the floating point domain
	clocks = ( mSeconds.hi * 4294967296.0 + mSeconds.lo );
	 
#else
	clocksPerSec = MACHINE_TICKS_PER_SECOND;
	clocks = machine_tick_count();

#endif

	timestamp = (NMUInt32)((clocks / (double)clocksPerSec) * (double)MILLISECS_PER_SEC);

	return timestamp;
}
void SoundMemoryManager::Add(boost::shared_ptr<SoundData> data, short index, short slot)
{
	m_entries[index].data[slot] = data;
	m_entries[index].last_played = machine_tick_count();

	m_size += data->size();

	while (m_size > m_max_size)
	{
		std::cerr << "Size is too big (" << m_size << ">" << m_max_size << ")" << std::endl;
		ReleaseOldestSound();
	}
}
void SoundManager::PlaySound(short sound_index, 
			     world_location3d *source,
			     short identifier, // NONE is no identifer and the sound is immediately orphaned
			     _fixed pitch) // on top of all existing pitch modifiers
{
	/* donÕt do anything if weÕre not initialized or active, or our sound_code is NONE,
		or our volume is zero, our we have no sound channels */
	if (sound_index!=NONE && active && sound_index < number_of_sound_definitions && parameters.volume > 0 && total_channel_count > 0)
	{
		Channel::Variables variables;

		CalculateInitialSoundVariables(sound_index, source, variables, pitch);
		
		/* make sure the sound data is in memory */
		if (LoadSound(sound_index))
		{
			Channel *channel = BestChannel(sound_index, variables);;
			/* get the channel, and free it for our new sound */
			if (channel)
			{
				/* set the volume and pitch in this channel */
				InstantiateSoundVariables(variables, *channel, true);
				
				/* initialize the channel */
				channel->flags= 0;
				channel->callback_count= 0; // #MD
				channel->start_tick= machine_tick_count();
				channel->sound_index= sound_index;
				channel->identifier= identifier;
				channel->dynamic_source= (identifier==NONE) ? (world_location3d *) NULL : source;
				MARK_SLOT_AS_USED(channel);
				
				/* start the sound playing */
				BufferSound(*channel, sound_index, pitch);

				/* if we have a valid source, copy it, otherwise remember that we donÕt */
				if (source)
				{
					channel->source= *source;
				}
				else
				{
					channel->flags|= _sound_is_local;
				}
			}
		}
	}
}
void SoundManager::DirectPlaySound(short sound_index, angle direction, short volume, _fixed pitch)
{
	/* donÕt do anything if weÕre not initialized or active, or our sound_code is NONE,
	   or our volume is zero, our we have no sound channels */

	if (sound_index != NONE && active && sound_index < number_of_sound_definitions && parameters.volume > 0 && total_channel_count > 0)
	{
		if (LoadSound(sound_index))
		{
			Channel::Variables variables;
			Channel *channel = BestChannel(sound_index, variables);
			if (channel)
			{
				world_location3d *listener = _sound_listener_proc();

				variables.priority = 0;
				variables.volume = volume;

				if (direction = NONE || !listener)
				{
					variables.left_volume = variables.right_volume = volume;
				}
				else
				{
					AngleAndVolumeToStereoVolume(direction - listener->yaw, volume, &variables.right_volume, &variables.left_volume);
				}

				InstantiateSoundVariables(variables, *channel, true);
				/* initialize the channel */
				channel->flags = _sound_is_local; // but possibly being played in stereo
				channel->callback_count = 0;
				channel->start_tick = machine_tick_count();
				channel->sound_index = sound_index;
				channel->dynamic_source = 0;
				MARK_SLOT_AS_USED(channel);

				/* start the sound playing */
				BufferSound(*channel, sound_index, pitch);
			}
		}
	}
}
bool SoundManager::LoadSound(short sound_index)
{
	if (active)
	{
		SoundDefinition *definition = GetSoundDefinition(sound_index);
		if (!definition) return false;

		// Load all the external-file sounds for each index; fill the slots appropriately.
		int NumSlots= (parameters.flags & _more_sounds_flag) ? definition->permutations : 1;
		for (int k = 0; k < NumSlots; k++)
		{
			SoundOptions *SndOpts = SoundReplacements::instance()->GetSoundOptions(sound_index, k);
			if (!SndOpts) continue;
			FileSpecifier File;
			if (!File.SetNameWithPath(SndOpts->File.c_str())) continue;
			if (!SndOpts->Sound.LoadExternal(File)) continue;
		}

		if (definition->sound_code != NONE &&
		    (parameters.flags & _ambient_sound_flag) || !(definition->flags & _sound_is_ambient))
		{
			if (!definition->LoadedSize())
			{
				definition->Load(*(sound_file.opened_sound_file), parameters.flags & _more_sounds_flag);
				loaded_sounds_size += definition->LoadedSize();
				definition->last_played = machine_tick_count();
				while (loaded_sounds_size > total_buffer_size)
					ReleaseLeastUsefulSound();
			}
			if (definition->LoadedSize())
			{
				definition->permutations_played = 0;
			}
		}
		
		return definition->LoadedSize() ? true : false;
	}	

	return false;
}
void SoundMemoryManager::Update(short index)
{
	m_entries[index].last_played = machine_tick_count();
}
Esempio n. 7
0
static void release_openplay(
	void)
{
	struct loaded_modules_data *loaded_module = gOp_globals.loaded_modules;

	shutdown_report();
	
	/* Release all the endpoints.. */
	while(loaded_module)
	{
		struct loaded_modules_data *next_module = loaded_module->next;
		struct Endpoint *loaded_endpoint;
		NMBoolean done = false;
		long initial_ticks = machine_tick_count();
		
		while(!done && machine_tick_count()-initial_ticks < 10*MACHINE_TICKS_PER_SECOND)
		{
			loaded_endpoint = loaded_module->first_loaded_endpoint;
			if(loaded_endpoint)
			{
				done = true; //start optimistic
				while(loaded_endpoint)
				{
					struct Endpoint *next_endpoint = loaded_endpoint->next;
				
					if(loaded_endpoint->state != _state_closing && loaded_endpoint->state != _state_closed)
					{
						NMErr err;
                                          /* dprintf("Trying to free endpoint at %x (this was abortive)", loaded_endpoint); */
						DEBUG_PRINT("calling ProtocolCloseEndpoint, %s:%d", __FILE__, __LINE__);
						err = ProtocolCloseEndpoint(loaded_endpoint, false);
						//if we closed ok, we wanna keep waiting
						if (!err)
							done = false;
					}
					else
						done = false; //its probably closing
					loaded_endpoint = next_endpoint;
				}
			} else {
				/* this module is clean. */
				done = true;
			}
		}

		op_vwarn(done, "WARNING: release_openplay was unable to close all netmodules!!");
		
		/* Free the library */
		loaded_module = next_module; /* cached so we don't free too early.. */
	}

	/* Remove all the modules with zero counts (which should be all of them) */
	module_management_idle_time();
	
	/* Free the available modules list */
	if(gOp_globals.module_count)
	{
		gOp_globals.module_count = 0;
		dispose_pointer(gOp_globals.modules);
		gOp_globals.modules = NULL;
	}
	
	return;
}