Exemplo n.º 1
0
void device_sound_interface::interface_post_start()
{
	// count the outputs
	for (int outputnum = 0; outputnum < MAX_OUTPUTS; outputnum++)
	{
		// stop when we run out of streams
		sound_stream *stream = stream_find_by_device(&m_device, outputnum);
		if (stream == NULL)
			break;

		// accumulate the number of outputs from this stream
		int numoutputs = stream_get_outputs(stream);
		assert(m_outputs + numoutputs < MAX_OUTPUTS);

		// fill in the array
		for (int curoutput = 0; curoutput < numoutputs; curoutput++)
		{
			sound_output *output = &m_output[m_outputs++];
			output->stream = stream;
			output->output = curoutput;
		}
	}

	// iterate over all the sound devices
	device_sound_interface *sound = NULL;
	for (bool gotone = m_device.machine->m_devicelist.first(sound); gotone; gotone = sound->next(sound))
	{
		// scan each route on the device
		for (const device_config_sound_interface::sound_route *route = sound->sound_config().m_route_list; route != NULL; route = route->m_next)
		{
			// if we are the target of this route, hook it up
			device_t *target_device = m_device.machine->device(route->m_target);
			if (target_device == &m_device)
			{
				// iterate over all outputs, matching any that apply
				int inputnum = route->m_input;
				int numoutputs = stream_get_device_outputs(*sound);
				for (int outputnum = 0; outputnum < numoutputs; outputnum++)
					if (route->m_output == outputnum || route->m_output == ALL_OUTPUTS)
					{
						sound_stream *inputstream, *stream;
						int streaminput, streamoutput;

						// get the input and output streams and wire them together
						if (stream_device_input_to_stream_input(target_device, inputnum++, &inputstream, &streaminput))
							if (stream_device_output_to_stream_output(*sound, outputnum, &stream, &streamoutput))
								stream_set_input(inputstream, streaminput, stream, streamoutput, route->m_gain);
					}
			}
		}
	}
}
Exemplo n.º 2
0
static void start_sound_chips(void)
{
	int sndnum;

	/* reset the sound array */
	memset(sound, 0, sizeof(sound));

	/* start up all the sound chips */
	for (sndnum = 0; sndnum < MAX_SOUND; sndnum++)
	{
		const sound_config *msound = &Machine->drv->sound[sndnum];
		sound_info *info;
		int num_regs;
		int index;

		/* stop when we hit an empty entry */
		if (msound->type == SOUND_DUMMY)
			break;
		totalsnd++;

		/* zap all the info */
		info = &sound[sndnum];
		memset(info, 0, sizeof(*info));

		/* copy in all the relevant info */
		info->sound = msound;

		/* start the chip, tagging all its streams */
		VPRINTF(("sndnum = %d -- sound_type = %d\n", sndnum, msound->type));
		num_regs = state_save_get_reg_count();
		streams_set_tag(Machine, info);
		if (sndintrf_init_sound(sndnum, msound->type, msound->clock, msound->config) != 0)
			fatalerror("Sound chip #%d (%s) failed to initialize!", sndnum, sndnum_name(sndnum));

		/* if no state registered for saving, we can't save */
		num_regs = state_save_get_reg_count() - num_regs;
		if (num_regs == 0)
		{
			logerror("Sound chip #%d (%s) did not register any state to save!\n", sndnum, sndnum_name(sndnum));
			if (Machine->gamedrv->flags & GAME_SUPPORTS_SAVE)
				fatalerror("Sound chip #%d (%s) did not register any state to save!", sndnum, sndnum_name(sndnum));
		}

		/* now count the outputs */
		VPRINTF(("Counting outputs\n"));
		for (index = 0; ; index++)
		{
			sound_stream *stream = stream_find_by_tag(info, index);
			if (!stream)
				break;
			info->outputs += stream_get_outputs(stream);
			VPRINTF(("  stream %p, %d outputs\n", stream, stream_get_outputs(stream)));
		}

		/* if we have outputs, examine them */
		if (info->outputs)
		{
			/* allocate an array to hold them */
			info->output = auto_malloc(info->outputs * sizeof(*info->output));
			VPRINTF(("  %d outputs total\n", info->outputs));

			/* now fill the array */
			info->outputs = 0;
			for (index = 0; ; index++)
			{
				sound_stream *stream = stream_find_by_tag(info, index);
				int outputs, outputnum;

				if (!stream)
					break;
				outputs = stream_get_outputs(stream);

				/* fill in an entry for each output */
				for (outputnum = 0; outputnum < outputs; outputnum++)
				{
					info->output[info->outputs].stream = stream;
					info->output[info->outputs].output = outputnum;
					info->outputs++;
				}
			}
		}
	}
}