VE Lua Documentation

Press F to search!

hzToFMODHz

Definition


-- @/lua/vehicle/sounds.lua:1285
-- IMPORTANT: code also present in engine/audio/backends/fmod/trueforceDSP.cpp. Make sure you sync LUA changes to the C++ port
local function hzToFMODHz(hzValue)
  local range = #fmodtable - 1
  hzValue = max(fmodtable[1], min(hzValue, fmodtable[#fmodtable])) --clamp hzValue to min/max possible values
  for i = range, 1, -1 do --iterate all fmod hz entries starting at the top
    if fmodtable[i] <= hzValue then --if we found an fmod hz value smaller than our target, set that as our range
      range = i
      break
    end
  end
  return 100 * ((range - 1) + ((hzValue - fmodtable[range]) / (fmodtable[range + 1] - fmodtable[range])))
end

Callers

@/lua/vehicle/powertrain/combustionEngine.lua
    local scaledEngineLoad = engineLoad * (device.soundMaxLoadMix - device.soundMinLoadMix) + device.soundMinLoadMix
    local fundamentalFreq = sounds.hzToFMODHz(rpm * device.soundConfiguration.engine.params.fundamentalFrequencyRPMCoef)
    obj:setEngineSound(device.engineSoundID, rpm, scaledEngineLoad, fundamentalFreq, volumeCoef)
    local scaledEngineLoadExhaust = engineLoad * ((device.soundMaxLoadMixExhaust or device.soundMaxLoadMix) - minLoad) + minLoad
    local fundamentalFreqExhaust = sounds.hzToFMODHz(rpm * device.soundConfiguration.exhaust.params.fundamentalFrequencyRPMCoef)
    obj:setEngineSound(device.engineSoundIDExhaust, rpm, scaledEngineLoadExhaust, fundamentalFreqExhaust, volumeCoef)

        local eq_a_freq = sounds.hzToFMODHz(soundConfig.lowShelfFreq or soundConfig.lowCutFreq or 20)
        local eq_a_gain = soundConfig.lowShelfGain or 0
        local eq_a_gain = soundConfig.lowShelfGain or 0
        local eq_b_freq = sounds.hzToFMODHz(soundConfig.highShelfFreq or soundConfig.highCutFreq or 10000)
        local eq_b_gain = soundConfig.highShelfGain or 0
        local eq_b_gain = soundConfig.highShelfGain or 0
        local eq_c_freq = sounds.hzToFMODHz(soundConfig.eqLowFreq or 500)
        local eq_c_gain = soundConfig.eqLowGain or 0
        local eq_c_reso = soundConfig.eqLowWidth or 0
        local eq_d_freq = sounds.hzToFMODHz(soundConfig.eqHighFreq or 2000)
        local eq_d_gain = soundConfig.eqHighGain or 0

        local eq_a_freq = sounds.hzToFMODHz(soundConfig.lowShelfFreq or soundConfig.lowCutFreq or 20)
        local eq_a_gain = soundConfig.lowShelfGain or 0
        local eq_a_gain = soundConfig.lowShelfGain or 0
        local eq_b_freq = sounds.hzToFMODHz(soundConfig.highShelfFreq or soundConfig.highCutFreq or 10000)
        local eq_b_gain = soundConfig.highShelfGain or 0
        local eq_b_gain = soundConfig.highShelfGain or 0
        local eq_c_freq = sounds.hzToFMODHz(soundConfig.eqLowFreq or 500)
        local eq_c_gain = soundConfig.eqLowGain or 0
        local eq_c_reso = soundConfig.eqLowWidth or 0
        local eq_d_freq = sounds.hzToFMODHz(soundConfig.eqHighFreq or 2000)
        local eq_d_gain = soundConfig.eqHighGain or 0
@/lua/ge/extensions/editor/engineAudioDebug.lua
local fmodtable = {20.0, 40.0, 80.0, 160.0, 330.0, 660.0, 1300.0, 2700.0, 5400.0, 11000.0, 22000.0} --Hz values
local function hzToFMODHz(hzValue)
  local range = #fmodtable - 1
        mufflingOffsetRevLimiter = 0,
        eq_a_freq = hzToFMODHz(lowShelfFreq[0]),
        eq_a_gain = lowShelfGain[0],
        eq_a_gain = lowShelfGain[0],
        eq_b_freq = hzToFMODHz(highShelfFreq[0]),
        eq_b_gain = highShelfGain[0],
        eq_b_gain = highShelfGain[0],
        eq_c_freq = hzToFMODHz(eqLowFreq[0]),
        eq_c_gain = eqLowGain[0],
        eq_c_reso = eqLowWidth[0],
        eq_d_freq = hzToFMODHz(eqHighFreq[0]),
        eq_d_gain = eqHighGain[0],
          mufflingOffsetRevLimiter = 0,
          eq_a_freq = hzToFMODHz(20),
          eq_a_gain = 0,
          eq_a_gain = 0,
          eq_b_freq = hzToFMODHz(10000),
          eq_b_gain = 0,
          eq_b_gain = 0,
          eq_c_freq = hzToFMODHz(500),
          eq_c_gain = 0,
          eq_c_reso = 0,
          eq_d_freq = hzToFMODHz(2000),
          eq_d_gain = 0,
@/lua/vehicle/powertrain/electricMotor.lua
  local engineLoad = clamp(device.soundLoadSmoother:get(abs(device.instantEngineLoad), dt), device.soundMinLoadMix, device.soundMaxLoadMix)
  local fundamentalFreq = sounds.hzToFMODHz(rpm * device.fundamentalFrequencyRPMCoef)
  obj:setEngineSound(device.engineSoundID, rpm, engineLoad, fundamentalFreq, device.engineVolumeCoef)

          local eq_a_freq = sounds.hzToFMODHz(soundConfig.lowCutFreq or 20)
          local eq_b_freq = sounds.hzToFMODHz(soundConfig.highCutFreq or 10000)
          local eq_a_freq = sounds.hzToFMODHz(soundConfig.lowCutFreq or 20)
          local eq_b_freq = sounds.hzToFMODHz(soundConfig.highCutFreq or 10000)
          local eq_c_freq = sounds.hzToFMODHz(soundConfig.eqLowFreq or 500)
          local eq_b_freq = sounds.hzToFMODHz(soundConfig.highCutFreq or 10000)
          local eq_c_freq = sounds.hzToFMODHz(soundConfig.eqLowFreq or 500)
          local eq_c_gain = soundConfig.eqLowGain or 0
          local eq_c_reso = soundConfig.eqLowWidth or 0
          local eq_d_freq = sounds.hzToFMODHz(soundConfig.eqHighFreq or 2000)
          local eq_d_gain = soundConfig.eqHighGain or 0