Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dofile(LockOn_Options.script_path.."command_defs.lua")
- local dev = GetSelf()
- local dt = 0.024
- make_default_activity(dt)
- local cockpitVolume = get_option_value("sound.cockpit","local")
- if cockpitVolume == nil then
- cockpitVolume = 0
- end
- local headphonesVolume = get_option_value("sound.headphones","local")
- if headphonesVolume == nil then
- headphonesVolume = 0
- end
- local worldVolume = get_option_value("sound.world","local")
- if worldVolume == nil then
- worldVolume = 0
- end
- local cockpitGain = (cockpitVolume + 100.0) /100.0
- local headphonesGain = (headphonesVolume + 100.0) /100.0
- local worldGain = (worldVolume + 100.0) /100.0
- -----------------------------
- -- Key Commands to Monitor --
- -----------------------------
- dev:listen_command(Keys.iCommandPlaneEject)
- ---------------------------------
- -- SOUND PARAMETERS (from dll) --
- ---------------------------------
- -- Gain/Pitch Parameters
- local MISSILE_TONE_VOLUME = get_param_handle("MISSILE_TONE_VOLUME")
- local THREAT_VOLUME = get_param_handle("THREAT_VOLUME")
- local INTERCOM_VOLUME = get_param_handle("INTERCOM_VOLUME")
- local TACAN_VOLUME = get_param_handle("TACAN_VOLUME")
- local ILS_VOLUME = get_param_handle("ILS_VOLUME")
- local PRESSURIZATION_VOLUME = get_param_handle("PRESSURIZATION_VOLUME")
- local HEARING_VOLUME = get_param_handle("HEARING_VOLUME")
- local AFTERBURNER_VOLUME = get_param_handle("AFTERBURNER_VOLUME")
- local ENGINE_1_VOLUME = get_param_handle("ENGINE_1_VOLUME")
- local ENGINE_2_VOLUME = get_param_handle("ENGINE_2_VOLUME")
- local ENGINE_3_VOLUME = get_param_handle("ENGINE_3_VOLUME")
- local ENGINE_1_PITCH = get_param_handle("ENGINE_1_PITCH")
- local ENGINE_2_PITCH = get_param_handle("ENGINE_2_PITCH")
- local ENGINE_3_PITCH = get_param_handle("ENGINE_3_PITCH")
- -- Sound Trigger Parameters
- -- valid data if > -999
- -- Value of 0 means stop
- -- Any other value (besides -999) means play
- local SOUND_THROTTLE_IDLE_CUTOFF = get_param_handle("SOUND_THROTTLE_IDLE_CUTOFF")
- local SOUND_THROTTLE_DETENT_1 = get_param_handle("SOUND_THROTTLE_DETENT_1")
- local SOUND_THROTTLE_DETENT_2 = get_param_handle("SOUND_THROTTLE_DETENT_2")
- local SOUND_THROTTLE_AB_STAGE = get_param_handle("SOUND_THROTTLE_AB_STAGE")
- local SOUND_AFTERBURNER_IN = get_param_handle("SOUND_AFTERBURNER_IN")
- local SOUND_AFTERBURNER_START_IN = get_param_handle("SOUND_AFTERBURNER_START_IN")
- local SOUND_CANOPY_OPEN_LOOP = get_param_handle("SOUND_CANOPY_OPEN_LOOP")
- local SOUND_CANOPY_CLOSE_LOOP = get_param_handle("SOUND_CANOPY_CLOSE_LOOP")
- local SOUND_CANOPY_OPEN = get_param_handle("SOUND_CANOPY_OPEN")
- local SOUND_CANOPY_CLOSE = get_param_handle("SOUND_CANOPY_CLOSE")
- local SOUND_SEAT_ADJUSTMENT_UP_LOOP = get_param_handle("SOUND_SEAT_ADJUSTMENT_UP_LOOP")
- local SOUND_SEAT_ADJUSTMENT_DOWN_LOOP = get_param_handle("SOUND_SEAT_ADJUSTMENT_DOWN_LOOP")
- local SOUND_VM_PULLUP = get_param_handle("SOUND_VM_PULLUP")
- local SOUND_VM_ALTITUDE = get_param_handle("SOUND_VM_ALTITUDE")
- local SOUND_VM_WARNING = get_param_handle("SOUND_VM_WARNING")
- local SOUND_VM_JAMMER = get_param_handle("SOUND_VM_JAMMER")
- local SOUND_VM_COUNTER = get_param_handle("SOUND_VM_COUNTER")
- local SOUND_VM_CHAFF_FLARE = get_param_handle("SOUND_VM_CHAFF_FLARE")
- local SOUND_VM_LOW = get_param_handle("SOUND_VM_LOW")
- local SOUND_VM_OUT = get_param_handle("SOUND_VM_OUT")
- local SOUND_VM_LOCK = get_param_handle("SOUND_VM_LOCK")
- local SOUND_VM_CAUTION = get_param_handle("SOUND_VM_CAUTION")
- local SOUND_VM_BINGO = get_param_handle("SOUND_VM_BINGO")
- local SOUND_VM_DATA = get_param_handle("SOUND_VM_DATA")
- local SOUND_VM_IFF = get_param_handle("SOUND_VM_IFF")
- local SOUND_VMS_TEST = get_param_handle("SOUND_VMS_TEST")
- local SOUND_LANDING_GEAR_WARNING_HORN = get_param_handle("SOUND_LANDING_GEAR_WARNING_HORN")
- local SOUND_LOW_SPEED_WARNING_TONE = get_param_handle("SOUND_LOW_SPEED_WARNING_TONE")
- local SOUND_BATTERY = get_param_handle("SOUND_BATTERY")
- local SOUND_DEPRESSURIZATION = get_param_handle("SOUND_DEPRESSURIZATION")
- local SOUND_DEPRESSURIZATION = get_param_handle("SOUND_DEPRESSURIZATION")
- local SOUND_JFS_LOOP = get_param_handle("SOUND_JFS_LOOP")
- --From other LUA systems
- local SOUND_MAGSWITCH_OUT = get_param_handle("SOUND_MAGSWITCH_OUT")
- --------------------------
- function createInternal(sound_host, sdef_name)
- return sound_host:create_sound("Aircrafts/F-16/Internal/" .. sdef_name)
- end
- function createExternal(sound_host, sdef_name)
- return sound_host:create_sound("Aircrafts/F-16/External/" .. sdef_name)
- end
- function createInternalLoop(sound_host, start_sound_length, sdef_name_start, sdef_name_loop, sdef_name_end)
- start_length_ = start_sound_length or 0
- if sdef_name_start then
- sound_start_ = createInternal(sound_host, sdef_name_start)
- else
- sound_start_ = nil
- end
- sound_loop_ = createInternal(sound_host, sdef_name_loop)
- if sdef_name_end then
- sound_end_ = createInternal(sound_host, sdef_name_end)
- else
- sound_end_ = nil
- end
- return {
- startLength = start_length_,
- timePlaying = 0,
- isPlaying = false,
- sound_start = sound_start_,
- sound_loop = sound_loop_,
- sound_end = sound_end_,
- }
- end
- function createExternalLoop(sound_host, start_sound_length, sdef_name_start, sdef_name_loop, sdef_name_end)
- start_length_ = start_sound_length or 0
- if sdef_name_start then
- sound_start_ = createExternal(sound_host, sdef_name_start)
- else
- sound_start_ = nil
- end
- sound_loop_ = createExternal(sound_host, sdef_name_loop)
- if sdef_name_end then
- sound_end_ = createExternal(sound_host, sdef_name_end)
- else
- sound_end_ = nil
- end
- return {
- startLength = start_length_,
- timePlaying = 0,
- isPlaying = false,
- sound_start = sound_start_,
- sound_loop = sound_loop_,
- sound_end = sound_end_,
- }
- end
- function post_initialize()
- if create_sound_host ~= nil then
- ext_sh = create_sound_host("EXTERNAL_AIRCRAFT","3D",0,0,0)
- cpt_mech_sh = create_sound_host("COCKPIT_MECHANICAL","2D",0,0,0)
- cpt_sys_sh = create_sound_host("COCKPIT_SYSTEMS","2D",0,0,0)
- intercom_sh = create_sound_host("COCKPIT_INTERCOM","2D",0,0,0)
- cpt_eng_sh = create_sound_host("COCKPIT_ENGINE","2D",0,0,0)
- sound_EjectLever = createInternal(cpt_mech_sh, "EjectLever")
- sound_ThrottleIdleCutoff = createInternal(cpt_mech_sh, "ThrottleDetent2")
- sound_ThrottleDetent1 = createInternal(cpt_mech_sh, "ThrottleDetent1")
- sound_ThrottleDetent2 = createInternal(cpt_mech_sh, "ThrottleDetent2")
- sound_ThrottleABStage = createInternal(cpt_mech_sh, "ThrottleABStage")
- sound_AfterburnerStartIn = createInternal(cpt_eng_sh, "AfterburnerStart_In")
- sound_AfterburnerIn = createInternalLoop(cpt_eng_sh, nil, nil, "Afterburner_In")
- sound_Engine1In = createInternalLoop(cpt_eng_sh, nil, nil, "Engine1In")
- sound_Engine2In = createInternalLoop(cpt_eng_sh, nil, nil, "Engine2In")
- sound_Engine3In = createInternalLoop(cpt_eng_sh, nil, nil, "Engine3In")
- sound_JFSIn = createInternalLoop(cpt_mech_sh, 27.000, "JFSStart_In", "JFSLoop_In", "JFSEnd_In")
- sound_CanopyOpenLoop = createInternalLoop(cpt_mech_sh, 0.7041, "CanopyOpenStart", "CanopyOpenLoop", "CanopyOpenEnd")
- sound_CanopyCloseLoop = createInternalLoop(cpt_mech_sh, 1.1459, "CanopyCloseStart", "CanopyCloseLoop", "CanopyCloseEnd")
- sound_CanopyClose = createInternal(cpt_mech_sh, "CanopyClose")
- sound_CanopyOpen = createInternal(cpt_mech_sh, "CanopyOpen")
- sound_SeatAdjustmentUpLoop = createInternalLoop(cpt_mech_sh, nil, nil, "SeatAdjustmentUp", "SeatAdjustmentUpEnd")
- sound_SeatAdjustmentDownLoop = createInternalLoop(cpt_mech_sh, nil, nil, "SeatAdjustmentDown", "SeatAdjustmentDownEnd")
- sound_MagswitchOut = createInternal(cpt_mech_sh, "MagswitchOut")
- sound_PULLUP = createInternal(intercom_sh, "PULLUP")
- sound_ALTITUDE = createInternal(intercom_sh, "ALTITUDE")
- sound_WARNING = createInternal(intercom_sh, "WARNING")
- sound_JAMMER = createInternal(intercom_sh, "JAMMER")
- sound_COUNTER = createInternal(intercom_sh, "COUNTER")
- sound_CHAFF_FLARE = createInternal(intercom_sh, "CHAFF_FLARE")
- sound_LOW = createInternal(intercom_sh, "LOW")
- sound_OUT = createInternal(intercom_sh, "OUT")
- sound_LOCK = createInternal(intercom_sh, "LOCK")
- sound_CAUTION = createInternal(intercom_sh, "CAUTION")
- sound_BINGO = createInternal(intercom_sh, "BINGO")
- sound_DATA = createInternal(intercom_sh, "DATA")
- sound_IFF = createInternal(intercom_sh, "IFF")
- sound_VMSTest = createInternalLoop(intercom_sh, nil, nil, "VMSTest")
- sound_LandingGearWarningHorn = createInternalLoop(intercom_sh, nil, nil, "LandingGearWarningHorn")
- sound_LowSpeedWarningTone = createInternalLoop(intercom_sh, nil, nil, "LowSpeedWarningTone")
- sound_Battery = createInternalLoop(cpt_sys_sh, nil, nil, "Battery")
- sound_Pressurization = createInternalLoop(cpt_sys_sh, nil, nil, "Pressurization")
- sound_Depressurization = createInternal(cpt_mech_sh, "Depressurization")
- end
- SOUND_THROTTLE_IDLE_CUTOFF:set(-999)
- SOUND_THROTTLE_DETENT_1:set(-999)
- SOUND_THROTTLE_DETENT_2:set(-999)
- SOUND_THROTTLE_AB_STAGE:set(-999)
- SOUND_AFTERBURNER_IN:set(-999)
- SOUND_AFTERBURNER_START_IN:set(-999)
- SOUND_CANOPY_OPEN_LOOP:set(-999)
- SOUND_CANOPY_CLOSE_LOOP:set(-999)
- SOUND_CANOPY_OPEN:set(-999)
- SOUND_CANOPY_CLOSE:set(-999)
- SOUND_SEAT_ADJUSTMENT_UP_LOOP:set(-999)
- SOUND_SEAT_ADJUSTMENT_DOWN_LOOP:set(-999)
- SOUND_VM_PULLUP:set(-999)
- SOUND_VM_ALTITUDE:set(-999)
- SOUND_VM_WARNING:set(-999)
- SOUND_VM_JAMMER:set(-999)
- SOUND_VM_COUNTER:set(-999)
- SOUND_VM_CHAFF_FLARE:set(-999)
- SOUND_VM_LOW:set(-999)
- SOUND_VM_OUT:set(-999)
- SOUND_VM_LOCK:set(-999)
- SOUND_VM_CAUTION:set(-999)
- SOUND_VM_BINGO:set(-999)
- SOUND_VM_DATA:set(-999)
- SOUND_VM_IFF:set(-999)
- SOUND_VMS_TEST:set(-999)
- SOUND_LANDING_GEAR_WARNING_HORN:set(-999)
- SOUND_LOW_SPEED_WARNING_TONE:set(-999)
- SOUND_BATTERY:set(-999)
- SOUND_JFS_LOOP:set(-999)
- SOUND_MAGSWITCH_OUT:set(-999)
- end
- function updateSoundParameters(sound, pitch, gain, lowpass)
- if sound then
- sound:update(pitch, gain, lowpass)
- end
- end
- function stopSound(sound)
- if sound and sound:is_playing() then
- sound:stop()
- end
- end
- function playSoundOnce(sound)
- if sound then
- if sound:is_playing() then
- sound:stop()
- end
- sound:play_once()
- end
- end
- function stopLoopSound(loopSound, playEndSound)
- stopSound(loopSound.sound_start)
- stopSound(loopSound.sound_loop)
- loopSound.isPlaying = false
- loopSound.timePlaying = 0
- if playEndSound then
- playSoundOnce(loopSound.sound_end)
- end
- end
- function updateLoopSoundParameters(loopSound, pitch, gain, lowpass)
- updateSoundParameters(loopSound.sound_start, pitch, gain, lowpass)
- updateSoundParameters(loopSound.sound_loop, pitch, gain, lowpass)
- updateSoundParameters(loopSound.sound_end, pitch, gain, lowpass)
- end
- function playSoundOnceFromParam(param, sound)
- if param:get() > -999 then
- if sound then
- if sound:is_playing() then
- sound:stop()
- end
- if param:get() ~= 0 then
- sound:play_once()
- end
- end
- param:set(-999)
- end
- end
- function playLoopingSound(loopSound)
- loopSound.sound_loop:play_continue()
- end
- function playLoopingSoundFromParam(param, loopSound)
- if param == nil then
- loopSound.sound_loop:play_continue()
- return
- end
- if param:get() > -999 then
- if loopSound then
- if param:get() == 0 and loopSound.isPlaying then
- --Stop command given
- stopLoopSound(loopSound, true)
- elseif param:get() ~= 0 then
- --Play command given
- if loopSound.isPlaying then
- -- first stop if playing
- stopLoopSound(loopSound)
- end
- if loopSound.sound_start then
- loopSound.sound_start:play_once()
- else
- loopSound.sound_loop:play_continue()
- end
- loopSound.isPlaying = true
- end
- end
- param:set(-999)
- else
- --no sound command given, manage start/looping sound
- if loopSound.isPlaying then
- loopSound.timePlaying = loopSound.timePlaying + dt
- if loopSound.sound_start and loopSound.sound_start:is_playing() then
- if loopSound.timePlaying > (loopSound.startLength - dt) then
- loopSound.sound_loop:play_continue()
- end
- if loopSound.timePlaying > loopSound.startLength then
- loopSound.sound_start:stop()
- loopSound.sound_loop:play_continue()
- end
- else
- loopSound.sound_loop:play_continue()
- end
- end
- end
- end
- function update()
- local intercomGain = (INTERCOM_VOLUME:get() * INTERCOM_VOLUME:get()) * headphonesGain
- local pressurizationGain = PRESSURIZATION_VOLUME:get() * cockpitGain
- local afterburnerGain = AFTERBURNER_VOLUME:get() * cockpitGain
- local engine1Gain = ENGINE_1_VOLUME:get() * cockpitGain
- local engine2Gain = ENGINE_2_VOLUME:get() * cockpitGain
- local engine3Gain = ENGINE_3_VOLUME:get() * cockpitGain
- -- Mechanical Sounds
- playSoundOnceFromParam(SOUND_THROTTLE_IDLE_CUTOFF, sound_ThrottleIdleCutoff)
- playSoundOnceFromParam(SOUND_THROTTLE_DETENT_1, sound_ThrottleDetent1)
- playSoundOnceFromParam(SOUND_THROTTLE_DETENT_2, sound_ThrottleDetent2)
- playSoundOnceFromParam(SOUND_THROTTLE_AB_STAGE, sound_ThrottleABStage)
- playLoopingSoundFromParam(SOUND_CANOPY_OPEN_LOOP, sound_CanopyOpenLoop)
- playLoopingSoundFromParam(SOUND_CANOPY_CLOSE_LOOP, sound_CanopyCloseLoop)
- playSoundOnceFromParam(SOUND_CANOPY_OPEN, sound_CanopyOpen)
- playSoundOnceFromParam(SOUND_CANOPY_CLOSE, sound_CanopyClose)
- playLoopingSoundFromParam(SOUND_SEAT_ADJUSTMENT_UP_LOOP, sound_SeatAdjustmentUpLoop)
- playLoopingSoundFromParam(SOUND_SEAT_ADJUSTMENT_DOWN_LOOP, sound_SeatAdjustmentDownLoop)
- playSoundOnceFromParam(SOUND_MAGSWITCH_OUT, sound_MagswitchOut)
- -- Warning Sounds
- -- Voice Messages
- playSoundOnceFromParam(SOUND_VM_PULLUP, sound_PULLUP)
- playSoundOnceFromParam(SOUND_VM_ALTITUDE, sound_ALTITUDE)
- playSoundOnceFromParam(SOUND_VM_WARNING, sound_WARNING)
- playSoundOnceFromParam(SOUND_VM_JAMMER, sound_JAMMER)
- playSoundOnceFromParam(SOUND_VM_COUNTER, sound_COUNTER)
- playSoundOnceFromParam(SOUND_VM_CHAFF_FLARE, sound_CHAFF_FLARE)
- playSoundOnceFromParam(SOUND_VM_LOW, sound_LOW)
- playSoundOnceFromParam(SOUND_VM_OUT, sound_OUT)
- playSoundOnceFromParam(SOUND_VM_LOCK, sound_LOCK)
- playSoundOnceFromParam(SOUND_VM_CAUTION, sound_CAUTION)
- playSoundOnceFromParam(SOUND_VM_BINGO, sound_BINGO)
- playSoundOnceFromParam(SOUND_VM_DATA, sound_DATA)
- playSoundOnceFromParam(SOUND_VM_IFF, sound_IFF)
- -- VMS Test
- playLoopingSoundFromParam(SOUND_VMS_TEST, sound_VMSTest)
- -- Audio Tones
- playLoopingSoundFromParam(SOUND_LANDING_GEAR_WARNING_HORN, sound_LandingGearWarningHorn)
- playLoopingSoundFromParam(SOUND_LOW_SPEED_WARNING_TONE, sound_LowSpeedWarningTone)
- -- Cockpit Systems
- playLoopingSoundFromParam(SOUND_BATTERY, sound_Battery)
- playLoopingSound(sound_Pressurization)
- playSoundOnceFromParam(SOUND_DEPRESSURIZATION, sound_Depressurization)
- -- Engine
- playSoundOnceFromParam(SOUND_AFTERBURNER_START_IN, sound_AfterburnerStartIn)
- playLoopingSoundFromParam(SOUND_AFTERBURNER_IN, sound_AfterburnerIn)
- playLoopingSound(sound_Engine1In)
- playLoopingSound(sound_Engine2In)
- playLoopingSound(sound_Engine3In)
- -- JFS
- playLoopingSoundFromParam(SOUND_JFS_LOOP, sound_JFSIn)
- -- update volumes
- updateSoundParameters(sound_EjectLever, nil, cockpitGain, nil)
- updateSoundParameters(sound_ThrottleIdleCutoff, nil, cockpitGain, nil)
- updateSoundParameters(sound_ThrottleDetent1, nil, cockpitGain, nil)
- updateSoundParameters(sound_ThrottleDetent2, nil, cockpitGain, nil)
- updateSoundParameters(sound_ThrottleABStage, nil, cockpitGain, nil)
- updateSoundParameters(sound_CanopyClose, nil, cockpitGain, nil)
- updateSoundParameters(sound_CanopyOpen, nil, cockpitGain, nil)
- updateSoundParameters(sound_MagswitchOut, nil, cockpitGain, nil)
- updateLoopSoundParameters(sound_Battery, nil, cockpitGain, nil)
- updateLoopSoundParameters(sound_CanopyOpenLoop, nil, cockpitGain, nil)
- updateLoopSoundParameters(sound_CanopyCloseLoop, nil, cockpitGain, nil)
- updateLoopSoundParameters(sound_SeatAdjustmentUpLoop, nil, cockpitGain, nil)
- updateLoopSoundParameters(sound_SeatAdjustmentDownLoop, nil, cockpitGain, nil)
- updateLoopSoundParameters(sound_Pressurization, nil, pressurizationGain, nil)
- updateSoundParameters(sound_Depressurization, nil, pressurizationGain, nil)
- updateSoundParameters(sound_AfterburnerStartIn, nil, cockpitGain, nil)
- updateLoopSoundParameters(sound_AfterburnerIn, nil, afterburnerGain, nil)
- updateLoopSoundParameters(sound_Engine1In, ENGINE_1_PITCH:get(), engine1Gain, nil)
- updateLoopSoundParameters(sound_Engine2In, ENGINE_2_PITCH:get(), engine2Gain, nil)
- updateLoopSoundParameters(sound_Engine3In, ENGINE_3_PITCH:get(), engine3Gain, nil)
- updateSoundParameters(sound_PULLUP, nil, intercomGain, nil)
- updateSoundParameters(sound_ALTITUDE, nil, intercomGain, nil)
- updateSoundParameters(sound_WARNING, nil, intercomGain, nil)
- updateSoundParameters(sound_JAMMER, nil, intercomGain, nil)
- updateSoundParameters(sound_COUNTER, nil, intercomGain, nil)
- updateSoundParameters(sound_CHAFF_FLARE, nil, intercomGain, nil)
- updateSoundParameters(sound_LOW, nil, intercomGain, nil)
- updateSoundParameters(sound_OUT, nil, intercomGain, nil)
- updateSoundParameters(sound_LOCK, nil, intercomGain, nil)
- updateSoundParameters(sound_CAUTION, nil, intercomGain, nil)
- updateSoundParameters(sound_BINGO, nil, intercomGain, nil)
- updateSoundParameters(sound_DATA, nil, intercomGain, nil)
- updateSoundParameters(sound_IFF, nil, intercomGain, nil)
- updateLoopSoundParameters(sound_VMSTest, nil, intercomGain, nil)
- updateLoopSoundParameters(sound_LandingGearWarningHorn, nil, intercomGain, nil)
- updateLoopSoundParameters(sound_LowSpeedWarningTone, nil, intercomGain, nil)
- end
- function SetCommand(command,value)
- if command == Keys.iCommandPlaneEject then
- playSoundOnce(sound_EjectLever)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement