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++; } } } } }
static void route_sound(void) { int sndnum, spknum, routenum, outputnum; /* iterate over all the sound chips */ for (sndnum = 0; sndnum < totalsnd; sndnum++) { sound_info *info = &sound[sndnum]; /* iterate over all routes */ for (routenum = 0; routenum < info->sound->routes; routenum++) { const sound_route *mroute = &info->sound->route[routenum]; speaker_info *speaker; sound_info *sound; /* find the target */ speaker = find_speaker_by_tag(mroute->target); sound = find_sound_by_tag(mroute->target); /* if neither found, it's fatal */ if (speaker == NULL && sound == NULL) fatalerror("Sound route \"%s\" not found!\n", mroute->target); /* if we got a speaker, bump its input count */ if (speaker != NULL) { if (mroute->output >= 0 && mroute->output < info->outputs) speaker->inputs++; else if (mroute->output == ALL_OUTPUTS) speaker->inputs += info->outputs; } } } /* now allocate the mixers and input data */ streams_set_tag(Machine, NULL); for (spknum = 0; spknum < totalspeakers; spknum++) { speaker_info *info = &speaker[spknum]; if (info->inputs != 0) { info->mixer_stream = stream_create(info->inputs, 1, Machine->sample_rate, info, mixer_update); info->input = auto_malloc(info->inputs * sizeof(*info->input)); info->inputs = 0; } else logerror("Warning: speaker \"%s\" has no inputs\n", info->speaker->tag); } /* iterate again over all the sound chips */ for (sndnum = 0; sndnum < totalsnd; sndnum++) { sound_info *info = &sound[sndnum]; /* iterate over all routes */ for (routenum = 0; routenum < info->sound->routes; routenum++) { const sound_route *mroute = &info->sound->route[routenum]; speaker_info *speaker; sound_info *sound; /* find the target */ speaker = find_speaker_by_tag(mroute->target); sound = find_sound_by_tag(mroute->target); /* if it's a speaker, set the input */ if (speaker != NULL) { for (outputnum = 0; outputnum < info->outputs; outputnum++) if (mroute->output == outputnum || mroute->output == ALL_OUTPUTS) { char namebuf[256]; int index; sndnum_to_sndti(sndnum, &index); /* fill in the input data on this speaker */ speaker->input[speaker->inputs].gain = mroute->gain; speaker->input[speaker->inputs].default_gain = mroute->gain; sprintf(namebuf, "%s:%s #%d.%d", speaker->speaker->tag, sndnum_name(sndnum), index, outputnum); speaker->input[speaker->inputs].name = auto_strdup(namebuf); /* connect the output to the input */ stream_set_input(speaker->mixer_stream, speaker->inputs++, info->output[outputnum].stream, info->output[outputnum].output, mroute->gain); } } /* if it's a sound chip, set the input */ else { for (outputnum = 0; outputnum < info->outputs; outputnum++) if (mroute->output == outputnum || mroute->output == ALL_OUTPUTS) stream_set_input(sound->output[0].stream, 0, info->output[outputnum].stream, info->output[outputnum].output, mroute->gain); } } } }
static void route_sound(void) { int sndnum, routenum, outputnum; const device_config *curspeak; /* iterate over all the sound chips */ for (sndnum = 0; sndnum < totalsnd; sndnum++) { sound_info *info = &sound[sndnum]; /* iterate over all routes */ for (routenum = 0; routenum < info->sound->routes; routenum++) { const sound_route *mroute = &info->sound->route[routenum]; speaker_info *speaker; sound_info *sound; /* find the target */ speaker = find_speaker_by_tag(mroute->target); sound = find_sound_by_tag(mroute->target); /* if neither found, it's fatal */ if (speaker == NULL && sound == NULL) fatalerror("Sound route \"%s\" not found!\n", mroute->target); /* if we got a speaker, bump its input count */ if (speaker != NULL) { if (mroute->output >= 0 && mroute->output < info->outputs) speaker->inputs++; else if (mroute->output == ALL_OUTPUTS) speaker->inputs += info->outputs; } } } /* now allocate the mixers and input data */ streams_set_tag(Machine, NULL); for (curspeak = speaker_output_first(Machine->config); curspeak != NULL; curspeak = speaker_output_next(curspeak)) { speaker_info *info = curspeak->token; if (info->inputs != 0) { info->mixer_stream = stream_create(info->inputs, 1, Machine->sample_rate, info, mixer_update); info->input = auto_malloc(info->inputs * sizeof(*info->input)); info->inputs = 0; } else logerror("Warning: speaker \"%s\" has no inputs\n", info->tag); } /* iterate again over all the sound chips */ for (sndnum = 0; sndnum < totalsnd; sndnum++) { sound_info *info = &sound[sndnum]; /* iterate over all routes */ for (routenum = 0; routenum < info->sound->routes; routenum++) { const sound_route *mroute = &info->sound->route[routenum]; speaker_info *speaker; sound_info *sound; /* find the target */ speaker = find_speaker_by_tag(mroute->target); sound = find_sound_by_tag(mroute->target); /* if it's a speaker, set the input */ if (speaker != NULL) { for (outputnum = 0; outputnum < info->outputs; outputnum++) if (mroute->output == outputnum || mroute->output == ALL_OUTPUTS) { char namebuf[256]; int index; sound_type sndtype = sndnum_to_sndti(sndnum, &index); /* built the display name */ namebuf[0] = '\0'; /* speaker name, if more than one speaker */ if (speaker_output_count(Machine->config) > 1) sprintf(namebuf, "%sSpeaker '%s': ", namebuf, speaker->tag); /* device name */ sprintf(namebuf, "%s%s ", namebuf, sndnum_name(sndnum)); /* device index, if more than one of this type */ if (sndtype_count(sndtype) > 1) sprintf(namebuf, "%s#%d ", namebuf, index); /* channel number, if more than channel for this device */ if (info->outputs > 1) sprintf(namebuf, "%sCh.%d", namebuf, outputnum); /* remove final space */ if (namebuf[strlen(namebuf) - 1] == ' ') namebuf[strlen(namebuf) - 1] = '\0'; /* fill in the input data on this speaker */ speaker->input[speaker->inputs].gain = mroute->gain; speaker->input[speaker->inputs].default_gain = mroute->gain; speaker->input[speaker->inputs].name = auto_strdup(namebuf); /* connect the output to the input */ stream_set_input(speaker->mixer_stream, speaker->inputs++, info->output[outputnum].stream, info->output[outputnum].output, mroute->gain); } } /* if it's a sound chip, set the input */ else { if (mroute->input < 0) { for (outputnum = 0; outputnum < info->outputs; outputnum++) if (mroute->output == outputnum || mroute->output == ALL_OUTPUTS) stream_set_input(sound->output[0].stream, 0, info->output[outputnum].stream, info->output[outputnum].output, mroute->gain); } else { assert(mroute->output != ALL_OUTPUTS); for (outputnum = 0; outputnum < info->outputs; outputnum++) if (mroute->output == outputnum) stream_set_input(sound->output[0].stream, mroute->input, info->output[outputnum].stream, info->output[outputnum].output, mroute->gain); } } } } }