int mixer_allocate_channels(int channels, const int *default_mixing_levels) { int i, j; /* make sure we didn't overrun the number of available channels */ if (first_free_channel + channels > MIXER_MAX_CHANNELS) { logerror("Too many mixer channels (requested %d, available %d)\n", first_free_channel + channels, MIXER_MAX_CHANNELS); exit(1); } /* loop over channels requested */ for (i = 0; i < channels; i++) { struct mixer_channel_data *channel = &mixer_channel[first_free_channel + i]; /* extract the basic data */ channel->default_mixing_level = MIXER_GET_LEVEL(default_mixing_levels[i]); channel->pan = MIXER_GET_PAN(default_mixing_levels[i]); channel->gain = MIXER_GET_GAIN(default_mixing_levels[i]); channel->volume = 100; /* backwards compatibility with old 0-255 volume range */ if (channel->default_mixing_level > 100) channel->default_mixing_level = channel->default_mixing_level * 25 / 255; /* attempt to load in the configuration data for this channel */ channel->mixing_level = channel->default_mixing_level; if (!config_invalid) { /* if the defaults match, set the mixing level from the config */ if (channel->default_mixing_level == channel->config_default_mixing_level) channel->mixing_level = channel->config_mixing_level; /* otherwise, invalidate all channels that have been created so far */ else { config_invalid = 1; for (j = 0; j < first_free_channel + i; j++) mixer_set_mixing_level(j, mixer_channel[j].default_mixing_level); } } /* set the default name */ mixer_set_name(first_free_channel + i, 0); } /* increment the counter and return the first one */ first_free_channel += channels; return first_free_channel - channels; }
void xmame_set_mixer_volume( int ch, int level ) { if( use_fmgen ){ switch( ch ){ case XMAME_MIXER_FMPSG: if( level < FMPSGVOL_MIN ) level = FMPSGVOL_MIN; if( level > FMPSGVOL_MAX ) level = FMPSGVOL_MAX; mixer_set_mixing_level( 0, level ); mixer_set_mixing_level( 1, level ); break; case XMAME_MIXER_BEEP: if( level < BEEPVOL_MIN ) level = BEEPVOL_MIN; if( level > BEEPVOL_MAX ) level = BEEPVOL_MAX; mixer_set_mixing_level( 2, level ); break; default: for( ch=0; ch<MIXER_MAX_CHANNELS ; ch++ ){ const char *name = mixer_get_name(ch); if(name) printf( "%d[ch] %s\t:%d\n", ch,name,mixer_get_mixing_level(ch)); } break; } return; } switch( ch ){ case XMAME_MIXER_PSG: if( level < PSGVOL_MIN ) level = PSGVOL_MIN; if( level > PSGVOL_MAX ) level = PSGVOL_MAX; mixer_set_mixing_level( 0, level ); mixer_set_mixing_level( 1, level ); mixer_set_mixing_level( 2, level ); break; case XMAME_MIXER_FM: if( level < FMVOL_MIN ) level = FMVOL_MIN; if( level > FMVOL_MAX ) level = FMVOL_MAX; if( sound_board==SOUND_I ){ mixer_set_mixing_level( 3, level ); }else{ mixer_set_mixing_level( 3, level ); mixer_set_mixing_level( 4, level ); } break; case XMAME_MIXER_BEEP: if( level < BEEPVOL_MIN ) level = BEEPVOL_MIN; if( level > BEEPVOL_MAX ) level = BEEPVOL_MAX; if( sound_board==SOUND_I ){ mixer_set_mixing_level( 4, level ); }else{ mixer_set_mixing_level( 5, level ); } break; case XMAME_MIXER_RHYTHM: if( level < RHYTHMVOL_MIN ) level = RHYTHMVOL_MIN; if( level > RHYTHMVOL_MAX ) level = RHYTHMVOL_MAX; if( sound_board==SOUND_II ){ rhythmvol = level; } break; case XMAME_MIXER_ADPCM: if( level < ADPCMVOL_MIN ) level = ADPCMVOL_MIN; if( level > ADPCMVOL_MAX ) level = ADPCMVOL_MAX; if( sound_board==SOUND_II ){ adpcmvol = level; } break; default: for( ch=0; ch<MIXER_MAX_CHANNELS ; ch++ ){ const char *name = mixer_get_name(ch); if(name) printf( "%d[ch] %s\t:%d\n", ch,name,mixer_get_mixing_level(ch)); } break; } }