Fixed logic in SoundOutput.lua to play internal sound files with SRS

This commit is contained in:
kaltokri 2023-12-26 13:24:56 +01:00
parent aeac2eb3d7
commit 46f70dd8a6

View File

@ -160,52 +160,61 @@ do -- Sound File
-- @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 #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. -- @param #number Duration Duration in seconds, how long it takes to play the sound file. Default is 3 seconds.
-- @param #bolean UseSrs Set if SRS should be used to play this file. Default is false.
-- @return #SOUNDFILE self -- @return #SOUNDFILE self
function SOUNDFILE:New(FileName, Path, Duration) function SOUNDFILE:New(FileName, Path, Duration, UseSrs)
-- Inherit BASE. -- Inherit BASE.
local self=BASE:Inherit(self, BASE:New()) -- #SOUNDFILE local self=BASE:Inherit(self, BASE:New()) -- #SOUNDFILE
-- Debug info:
self:F( {FileName, Path, Duration, UseSrs} )
-- Set file name. -- Set file name.
self:SetFileName(FileName) self:SetFileName(FileName)
-- Set if SRS should be used to play this file
self:SetPlayWithSRS(UseSrs or false)
-- Set path. -- Set path.
self:SetPath(Path) self:SetPath(Path)
-- Set duration. -- Set duration.
self:SetDuration(Duration) self:SetDuration(Duration)
-- Debug info:
self:T(string.format("New SOUNDFILE: file name=%s, path=%s", self.filename, self.path))
return self return self
end end
--- Set path, where the sound file is located. --- Set path, where the sound file is located.
-- @param #SOUNDFILE self -- @param #SOUNDFILE self
-- @param #string Path Path to the directory, where the sound file is located. In case this is nil, it defaults to the DCS mission temp directory. -- @param #string Path Path to the directory, where the sound file is located. In case this is nil, it defaults to the DCS mission temp directory.
-- @return #SOUNDFILE self -- @return #SOUNDFILE self
function SOUNDFILE:SetPath(Path) function SOUNDFILE:SetPath(Path)
self:F( {Path} )
-- Init path. -- Init path.
self.path=Path or "l10n/DEFAULT/" if not Path then
if self.useSRS then -- use path to mission temp dir
if not Path and self.useSRS then -- use path to mission temp dir self.path = lfs.tempdir() .. "Mission\\l10n\\DEFAULT"
self.path = os.getenv('TMP') .. "\\DCS\\Mission\\l10n\\DEFAULT" else -- use internal path in miz file
end self.path="l10n/DEFAULT/"
end
end
-- Remove (back)slashes. -- Remove (back)slashes.
local nmax=1000 ; local n=1 local nmax=1000 ; local n=1
while (self.path:sub(-1)=="/" or self.path:sub(-1)==[[\]]) and n<=nmax do while (self.path:sub(-1)=="/" or self.path:sub(-1)==[[\]]) and n<=nmax do
self.path=self.path:sub(1,#self.path-1) self.path=self.path:sub(1,#self.path-1)
n=n+1 n=n+1
end end
-- Append slash. -- Append slash.
self.path=self.path.."/" self.path=self.path.."/"
self:T("self.path=".. self.path)
return self return self
end end
--- Get path of the directory, where the sound file is located. --- Get path of the directory, where the sound file is located.
-- @param #SOUNDFILE self -- @param #SOUNDFILE self
@ -228,7 +237,7 @@ do -- Sound File
--- Get the sound file name. --- Get the sound file name.
-- @param #SOUNDFILE self -- @param #SOUNDFILE self
-- @return #string Name of the soud file. This does *not* include its path. -- @return #string Name of the soud file. This does *not* include its path.
function SOUNDFILE:GetFileName() function SOUNDFILE:GetFileName()
return self.filename return self.filename
end end
@ -264,14 +273,16 @@ do -- Sound File
-- @param #boolean Switch If true or nil, use SRS. If false, use DCS transmission. -- @param #boolean Switch If true or nil, use SRS. If false, use DCS transmission.
-- @return #SOUNDFILE self -- @return #SOUNDFILE self
function SOUNDFILE:SetPlayWithSRS(Switch) function SOUNDFILE:SetPlayWithSRS(Switch)
self:F( {Switch} )
if Switch==true or Switch==nil then if Switch==true or Switch==nil then
self.useSRS=true self.useSRS=true
else else
self.useSRS=false self.useSRS=false
end end
self:T("self.useSRS=".. tostring(self.useSRS))
return self return self
end end
end end
do -- Text-To-Speech do -- Text-To-Speech