mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Sound update 4
This commit is contained in:
parent
6b747e924b
commit
3129c8c8ea
@ -34,6 +34,14 @@
|
||||
-- @type MSRS
|
||||
-- @field #string ClassName Name of the class.
|
||||
-- @field #string lid Class id string for output to DCS log file.
|
||||
-- @field #table frequencies Frequencies used in the transmissions.
|
||||
-- @field #table modulations Modulations used in the transmissions.
|
||||
-- @field #number coalition Coalition of the transmission.
|
||||
-- @field #number port Port. Default 5002.
|
||||
-- @field #string name Name. Default "DCS-STTS".
|
||||
-- @field #number volume Volume between 0 (min) and 1 (max). Default 1.
|
||||
-- @field #string culture Culture. Default "en-GB".
|
||||
-- @field #string path Path to the SRS exe.
|
||||
-- @extends Core.Base#BASE
|
||||
|
||||
--- *It is a very sad thing that nowadays there is so little useless information.* - Oscar Wilde
|
||||
@ -52,11 +60,24 @@
|
||||
--
|
||||
-- @field #MSRS
|
||||
MSRS = {
|
||||
ClassName = "MSRS",
|
||||
lid = nil,
|
||||
ClassName = "MSRS",
|
||||
lid = nil,
|
||||
frequencies = {},
|
||||
modulations = {},
|
||||
coalition = 0,
|
||||
speed = 1,
|
||||
port = 5002,
|
||||
name = "DCS-STTS",
|
||||
volume = 1,
|
||||
culture = "en-GB",
|
||||
gender = "female",
|
||||
voice = nil,
|
||||
latitude = nil,
|
||||
longitude = nil,
|
||||
altitude = nil,
|
||||
}
|
||||
|
||||
--- ATIS class version.
|
||||
--- MSRS class version.
|
||||
-- @field #string version
|
||||
MSRS.version="0.0.1"
|
||||
|
||||
@ -78,15 +99,16 @@ MSRS.version="0.0.1"
|
||||
-- @return #MSRS self
|
||||
function MSRS:New(PathToSRS, Frequency, Modulation)
|
||||
|
||||
-- Inherit everything from FSM class.
|
||||
local self=BASE:Inherit(self, FSM:New()) -- #MSRS
|
||||
|
||||
self.path=self:SetPath(PathToSRS)
|
||||
|
||||
self.frequency=Frequency or 143
|
||||
|
||||
self.modulation=Modulation or radio.modulation.AM
|
||||
-- Defaults.
|
||||
Frequency =Frequency or 143
|
||||
Modulation= Modulation or radio.modulation.AM
|
||||
|
||||
-- Inherit everything from FSM class.
|
||||
local self=BASE:Inherit(self, BASE:New()) -- #MSRS
|
||||
|
||||
self:SetPath(PathToSRS)
|
||||
self:SetFrequencies(Frequency)
|
||||
self:SetModulations(Modulation)
|
||||
|
||||
return self
|
||||
end
|
||||
@ -96,7 +118,7 @@ end
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
--- Set path, where the sound file is located.
|
||||
--- Set path to SRS install directory. More precisely, path to where the DCS-
|
||||
-- @param #MSRS self
|
||||
-- @param #string Path Path to the directory, where the sound file is located.
|
||||
-- @return #MSRS self
|
||||
@ -106,31 +128,62 @@ function MSRS:SetPath(Path)
|
||||
return nil
|
||||
end
|
||||
|
||||
-- Set path.
|
||||
self.path=Path
|
||||
|
||||
-- Remove (back)slashes.
|
||||
local nmax=1000
|
||||
local n=1
|
||||
local n=1 ; local nmax=1000
|
||||
while (self.path:sub(-1)=="/" or self.path:sub(-1)==[[\]]) and n<=nmax do
|
||||
env.info(string.format("FF SRS path=%s (before)", self.path))
|
||||
self.path=self.path:sub(1,#self.path-1)
|
||||
env.info(string.format("FF SRS path=%s (after)", self.path))
|
||||
n=n+1
|
||||
end
|
||||
|
||||
env.info(string.format("FF SRS path=%s (final)", self.path))
|
||||
self:I(string.format("SRS path=%s", self:GetPath()))
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Get path to SRS directory.
|
||||
-- @param #MSRS self
|
||||
-- @return #string
|
||||
-- @return #string Path to the directory.
|
||||
function MSRS:GetPath()
|
||||
return self.path
|
||||
end
|
||||
|
||||
--- Set path, where the sound file is located.
|
||||
--- Set frequencies.
|
||||
-- @param #MSRS self
|
||||
-- @param #table Frequencies Frequencies in MHz. Can also be given as a #number if only one frequency should be used.
|
||||
-- @return #MSRS self
|
||||
function MSRS:SetFrequencies(Frequencies)
|
||||
|
||||
-- Ensure table.
|
||||
if type(Frequencies)~="table" then
|
||||
Frequencies={Frequencies}
|
||||
end
|
||||
|
||||
self.frequencies=Frequencies
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Set modulations.
|
||||
-- @param #MSRS self
|
||||
-- @param #table Modulations Modulations. Can also be given as a #number if only one modulation should be used.
|
||||
-- @return #MSRS self
|
||||
function MSRS:SetModulations(Modulations)
|
||||
|
||||
-- Ensure table.
|
||||
if type(Modulations)~="table" then
|
||||
Modulations={Modulations}
|
||||
end
|
||||
|
||||
self.modulations=Modulations
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Play sound file (ogg or mp3) via SRS.
|
||||
-- @param #MSRS self
|
||||
-- @param Sound.SoundFile#SOUNDFILE Soundfile Sound file to play.
|
||||
-- @param #number Delay Delay in seconds, before the sound file is played.
|
||||
@ -138,31 +191,57 @@ end
|
||||
function MSRS:PlaySoundfile(Soundfile, Delay)
|
||||
|
||||
if Delay and Delay>0 then
|
||||
self:ScheduleOnce(Delay, MSRS.PlaySoundfile, Soundfile, 0)
|
||||
self:ScheduleOnce(Delay, MSRS.PlaySoundfile, self, Soundfile, 0)
|
||||
else
|
||||
|
||||
local exe=self:GetPath().."/".."DCS-SR-ExternalAudio.exe"
|
||||
local soundfile=Soundfile:GetName()
|
||||
local freq=table.concat(self.frequencies, " ")
|
||||
local modu=table.concat(self.modulations, " ")
|
||||
local coal=self.coalition
|
||||
local port=self.port
|
||||
|
||||
env.info(string.format("FF PlaySoundfile soundfile=%s", soundfile))
|
||||
|
||||
local command=string.format("%s --file %s --freqs %d --modulations %d --coalition %d", exe, soundfile, self.frequency, 0)
|
||||
local command=string.format("%s --file %s --freqs %s --modulations %s --coalition %d --port %d -h", exe, soundfile, freq, modu, coal, port)
|
||||
|
||||
env.info(string.format("FF PlaySoundfile command=%s", command))
|
||||
|
||||
end
|
||||
|
||||
-- TODO: execute!
|
||||
|
||||
-- Execute SRS command.
|
||||
os.execute(command)
|
||||
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set path, where the sound file is located.
|
||||
--- Play text message via STTS.
|
||||
-- @param #MSRS self
|
||||
-- @param #string Message Text message.
|
||||
-- @param #number Delay Delay in seconds, before the message is played.
|
||||
-- @return #MSRS self
|
||||
function MSRS:PlayText(Message)
|
||||
function MSRS:PlayText(Message, Delay)
|
||||
|
||||
if Delay and Delay>0 then
|
||||
self:ScheduleOnce(Delay, MSRS.PlayText, self, Message, 0)
|
||||
else
|
||||
|
||||
local text=string.format("\"%s\"", Message)
|
||||
local exe=self:GetPath().."/".."DCS-SR-ExternalAudio.exe"
|
||||
local freq=table.concat(self.frequencies, " ")
|
||||
local modu=table.concat(self.modulations, " ")
|
||||
local coal=self.coalition
|
||||
local port=self.port
|
||||
local gender="male"
|
||||
|
||||
local command=string.format("%s -h --text=%s --freqs=%s --modulations=%s --coalition=%d --port=%d --gender=%s", exe, text, freq, modu, coal, port, gender)
|
||||
|
||||
env.info(string.format("FF Text command=%s", command))
|
||||
|
||||
-- Execute SRS command.
|
||||
os.execute(command)
|
||||
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
|
||||
@ -48,17 +48,17 @@ do -- Sound File
|
||||
|
||||
--- Constructor to create a new SOUNDFILE object.
|
||||
-- @param #SOUNDFILE self
|
||||
-- @param #string filename The name of the sound file, e.g. "Hello World.ogg".
|
||||
-- @param #string FileName The name of the sound file, e.g. "Hello World.ogg".
|
||||
-- @param #string Path The path of the directory, where the sound file is located. Default is "l10n/DEFAULT/" within the miz file.
|
||||
-- @param #number Duration Duration in seconds, how long it takes to play the sound file. Default is 3 seconds.
|
||||
-- @return #SOUNDFILE self
|
||||
function SOUNDFILE:New(filename, Path, Duration)
|
||||
function SOUNDFILE:New(FileName, Path, Duration)
|
||||
|
||||
-- Inherit BASE.
|
||||
local self=BASE:Inherit(self, BASE:New()) -- #SOUNDFILE
|
||||
|
||||
-- Set file name.
|
||||
self.filename=filename or "Hallo World.ogg"
|
||||
self.filename=FileName or "Hallo World.ogg"
|
||||
|
||||
--TODO: check that sound file is .ogg or .mp3
|
||||
|
||||
@ -76,15 +76,19 @@ do -- Sound File
|
||||
--- Set path, where the sound file is located.
|
||||
-- @param #SOUNDFILE self
|
||||
-- @param #string Path Path to the directory, where the sound file is located.
|
||||
-- @return self
|
||||
-- @return #SOUNDFILE self
|
||||
function SOUNDFILE:SetPath(Path)
|
||||
|
||||
self.path=Path or "l10n/DEFAULT/"
|
||||
|
||||
while self.path:sub(-1)=="/" or self.path:sub(-1)=="\\" do
|
||||
self.path=self.path:sub(1,-1)
|
||||
|
||||
-- Remove (back)slashes.
|
||||
local nmax=1000
|
||||
local n=1
|
||||
while (self.path:sub(-1)=="/" or self.path:sub(-1)==[[\]]) and n<=nmax do
|
||||
self.path=self.path:sub(1,#self.path-1)
|
||||
n=n+1
|
||||
end
|
||||
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
@ -115,26 +119,4 @@ do -- Sound File
|
||||
return name
|
||||
end
|
||||
|
||||
|
||||
--- Set the userflag to a given Number.
|
||||
-- @param #SOUNDFILE self
|
||||
-- @param #number Number The number value to be checked if it is the same as the userflag.
|
||||
-- @param #number Delay Delay in seconds, before the flag is set.
|
||||
-- @return #SOUNDFILE self
|
||||
-- @usage
|
||||
-- local BlueVictory = USERFLAG:New( "VictoryBlue" )
|
||||
-- BlueVictory:Set( 100 ) -- Set the UserFlag VictoryBlue to 100.
|
||||
--
|
||||
function SOUNDFILE:Set( Number, Delay ) --R2.3
|
||||
|
||||
if Delay and Delay>0 then
|
||||
self:ScheduleOnce(Delay, USERFLAG.Set, self, Number)
|
||||
else
|
||||
--env.info(string.format("Setting flag \"%s\" to %d at T=%.1f", self.UserFlagName, Number, timer.getTime()))
|
||||
trigger.action.setUserFlag( self.UserFlagName, Number )
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
end
|
||||
Loading…
x
Reference in New Issue
Block a user