예제 #1
0
void SoundScriptManager::modulate(int actor_id, int mod, float value, int linkType, int linkItemID)
{
    if (disabled)
        return;

    if (mod >= SS_MAX_MOD)
        return;

    for (int i = 0; i < free_gains[mod]; i++)
    {
        SoundScriptInstance* inst = gains[mod + i * SS_MAX_MOD];
        if (inst && inst->actor_id == actor_id && inst->sound_link_type == linkType && inst->sound_link_item_id == linkItemID)
        {
            // this one requires modulation
            float gain = value * value * inst->templ->gain_square + value * inst->templ->gain_multiplier + inst->templ->gain_offset;
            gain = std::max(0.0f, gain);
            gain = std::min(gain, 1.0f);
            inst->setGain(gain);
        }
    }

    for (int i = 0; i < free_pitches[mod]; i++)
    {
        SoundScriptInstance* inst = pitches[mod + i * SS_MAX_MOD];
        if (inst && inst->actor_id == actor_id && inst->sound_link_type == linkType && inst->sound_link_item_id == linkItemID)
        {
            // this one requires modulation
            float pitch = value * value * inst->templ->pitch_square + value * inst->templ->pitch_multiplier + inst->templ->pitch_offset;
            pitch = std::max(0.0f, pitch);
            inst->setPitch(pitch);
        }
    }
}