float PORT_GetFloatValue(void* controlIDV) {
    PortControl* portControl = (PortControl*) controlIDV;
    float value = 0.0F;

    if (portControl != NULL) {
        if (portControl->controlType == CONTROL_TYPE_VOLUME) {
            switch (portControl->channel) {
            case CHANNELS_MONO:
                value = getRealVolume(portControl, SND_MIXER_SCHN_MONO);
                break;

            case CHANNELS_STEREO:
                value = getFakeVolume(portControl);
                break;

            default:
                value = getRealVolume(portControl, portControl->channel);
            }
        } else if (portControl->controlType == CONTROL_TYPE_BALANCE) {
            if (portControl->channel == CHANNELS_STEREO) {
                value = getFakeBalance(portControl);
            } else {
                ERROR0("PORT_GetFloatValue(): Balance only allowed for stereo channels!\n");
            }
        } else {
            ERROR1("PORT_GetFloatValue(): inappropriate control type: %s!\n",
                   portControl->controlType);
        }
    }
    return value;
}
static float getFakeVolume(PortControl* portControl) {
    float valueL;
    float valueR;
    float value;

    valueL = getRealVolume(portControl, SND_MIXER_SCHN_FRONT_LEFT);
    valueR = getRealVolume(portControl, SND_MIXER_SCHN_FRONT_RIGHT);
    // volume is the greater value of both
    value = valueL > valueR ? valueL : valueR ;
    return value;
}
static float getFakeBalance(PortControl* portControl) {
    float volL, volR;

    // pan is the ratio of left and right
    volL = getRealVolume(portControl, SND_MIXER_SCHN_FRONT_LEFT);
    volR = getRealVolume(portControl, SND_MIXER_SCHN_FRONT_RIGHT);
    if (volL > volR) {
        return -1.0f + (volR / volL);
    }
    else if (volR > volL) {
        return 1.0f - (volL / volR);
    }
    return 0.0f;
}
예제 #4
0
long SIDInfo::getVolume()
{
	if (!hasVolume || !_sid || globalMax < 1) return 0;

	long r = getRealVolume() - min;

	return (r*globalMax/(max-min));
}
예제 #5
0
bool SIDInfo::setEmulMute(bool mute)
{
	if (!hasVolume || !_sid) return false;

	snd_mixer_elem_t* elem = snd_mixer_find_selem(_handle, _sid);

	if (!elem) return false;

	if (mute == _isEmulMuted) return true;

	if (mute)
	{
		_isEmulMuted = true;
		_lastVol = getRealVolume();
		return setRealVolume(min);
	}
	else
	{
		_isEmulMuted = false;
		bool ret = setRealVolume(_lastVol);
		_lastVol = min;
		return ret;
	}
}