diff --git a/LaunchScript/VirtualAcousticStarterConfig.ITC16100.json b/LaunchScript/VirtualAcousticStarterConfig.ITC16100.json index 2076a591f8bb5868f64d23eaba3e729c2b9bb23a..9a78f77c90a97c5eee895978ca71fcd75675b4ec 100644 --- a/LaunchScript/VirtualAcousticStarterConfig.ITC16100.json +++ b/LaunchScript/VirtualAcousticStarterConfig.ITC16100.json @@ -3,7 +3,8 @@ "nLauncherPort": 41578, "nVAServerPort": 12340, "nDefaultSleep": 5, - "lsReproductionModules": ["TalkthroughHP", "CTC"], + "lsDefaultReproductionModules": ["TalkthroughHP", "CTC"], + "lsBinauralReproductionModules": ["TalkthroughHP", "CTC"], "dVAServerDirectories" = { "20160906.aixcave" : "D:/Demos/VA_20160906/Binaries", diff --git a/LaunchScript/VirtualAcousticStarterConfig.json b/LaunchScript/VirtualAcousticStarterConfig.json index 4fba0d7854570d319b76845adbf93358ba58b5db..85e9a07c118b2a3e6c8f7dc4fb8e87c39ca6a86d 100644 --- a/LaunchScript/VirtualAcousticStarterConfig.json +++ b/LaunchScript/VirtualAcousticStarterConfig.json @@ -3,7 +3,9 @@ "nLauncherPort": 41578, "nVAServerPort": 12340, "nDefaultSleep": 3, - "lsReproductionModules": ["TalkthroughHP", "CTC"], + "lsDefaultReproductionModules": ["TalkthroughHP", "CTC"], + "lsBinauralReproductionModules": ["TalkthroughHP"], + "lsAmbisonicsReproductionModules": ["AmbisonicsBinauralMixdown"], "dVAServerDirectories": { "2018.a": "../v2018.a", diff --git a/LaunchScript/VirtualAcousticsStarterServer.py b/LaunchScript/VirtualAcousticsStarterServer.py index 9de977503d862cdfec2181fa3911e2dbbb465303..ee7e25f2d6b1e51c09a0718e0d1cb56d267f36bd 100644 --- a/LaunchScript/VirtualAcousticsStarterServer.py +++ b/LaunchScript/VirtualAcousticsStarterServer.py @@ -14,6 +14,12 @@ class ErrorCodes(Enum): ERROR_INCOMPLETE_VA_INI = 7 ERROR_UNDEFINED_LAUNCHER_STATE = 8 +class ReproductionInput(Enum): + NOT_SPECIFIED = 0 + BINAURAL = 1 + AMBISONICS = 2 + CUSTOM = 3 + # Class representing the VA-Launcher config (.json) file class LauncherConfig: def __init__(conf, sConfigFile): @@ -30,14 +36,32 @@ class LauncherConfig: conf.nLauncherPort = json_config["nLauncherPort"] conf.nVAServerPort = json_config["nVAServerPort"] conf.nDefaultSleep = json_config["nDefaultSleep"] - conf.lsReproductionModules = json_config["lsReproductionModules"] + conf.lsDefaultReproductionModules = json_config["lsDefaultReproductionModules"] except KeyError as e: print( "ERROR reading the json config. Missing " + str(e.args[0]) ) sys.exit( ErrorCodes.ERROR_INCOMPLETE_CONFIG ) + + try: + conf.lsBinauralReproductionModules = json_config["lsBinauralReproductionModules"] + except KeyError: + conf.lsBinauralReproductionModules = None + try: + conf.lsAmbisonicsReproductionModules = json_config["lsAmbisonicsReproductionModules"] + except KeyError: + conf.lsAmbisonicsReproductionModules = None + try: + conf.lsCustomReproductionModules = json_config["lsCustomReproductionModules"] + except KeyError: + conf.lsCustomReproductionModules = None + class VAComposedIniParser: - def __init__(self, lsReproductionModuleIDs): - self.lsReproductionModuleIDs = lsReproductionModuleIDs + def __init__(self, oLauncherConf : LauncherConfig): + self.lsDefaultReproductionModules = oLauncherConf.lsDefaultReproductionModules + self.lsBinauralReproductionModules = oLauncherConf.lsBinauralReproductionModules + self.lsAmbisonicsReproductionModules = oLauncherConf.lsAmbisonicsReproductionModules + self.lsCustomReproductionModules = oLauncherConf.lsCustomReproductionModules + self.eReproductionInput = ReproductionInput.NOT_SPECIFIED self.sRendererIniPath = None self.sConfFolder = "../conf/" @@ -89,7 +113,24 @@ class VAComposedIniParser: print( "ERROR: " + str(e) ) sys.exit( ErrorCodes.ERROR_INCOMPLETE_VA_INI ) - for sReproductionID in self.lsReproductionModuleIDs: + lsReproductionModuleIDs = self.lsDefaultReproductionModules + if self.eReproductionInput == ReproductionInput.BINAURAL: + if self.lsBinauralReproductionModules: + lsReproductionModuleIDs = self.lsBinauralReproductionModules + else: + print("WARNING: Requested BINAURAL reproduction modules are not specified, using default") + elif self.eReproductionInput == ReproductionInput.AMBISONICS: + if self.lsAmbisonicsReproductionModules: + lsReproductionModuleIDs = self.lsAmbisonicsReproductionModules + else: + print("WARNING: Requested AMBISONICS reproduction modules are not specified, using default") + elif self.eReproductionInput == ReproductionInput.CUSTOM: + if self.lsCustomReproductionModules: + lsReproductionModuleIDs = self.lsCustomReproductionModules + else: + print("WARNING: Requested CUSTOM reproduction modules are not specified, using default") + + for sReproductionID in lsReproductionModuleIDs: sSection = "Reproduction:" + sReproductionID if not reproductionIni.has_section(sSection): print( "ERROR: Reproduction module with ID: '" + sReproductionID + "' not available in respective ini file '" + sFileToRead + "'") @@ -100,6 +141,7 @@ class VAComposedIniParser: reproductionIni.write(inifile) +#Main class representing the VA Launcher app class VirtualAcousticsLauncher: def __init__(self): print("init") @@ -144,7 +186,7 @@ class VirtualAcousticsLauncher: print("Using config: " + sUsedConfigFile) self.oConfig = LauncherConfig( sUsedConfigFile ) - self.vaIniParser = VAComposedIniParser(self.oConfig.lsReproductionModules) + self.vaIniParser = VAComposedIniParser(self.oConfig) #Open network socket used for the communication def open_server_socket(self): @@ -232,13 +274,20 @@ class VirtualAcousticsLauncher: if ":" not in sMessage: #VAServer ID, should be received last self.sVAServerID = sMessage - else: #VARenderer.ini file, optional + elif sMessage.startswith("reproduction_input_type:"): #ReproductionInput type (Binaural / Ambisonics), optional + self.receive_reproduction_input(sMessage) + return self.receive_va_start_info() + elif sMessage.startswith("file:"): #VARenderer.ini file, optional self.vaIniParser.sRendererIniPath = self.receive_file(sMessage) return self.receive_va_start_info() + else: + lMessageParts = sMessage.split(":") + print("ERROR: Invalid message keyword '" + lMessageParts[0] + "' while receiving VA start info") + return False - print( "Received launch request for variant: " + self.sVAServerID ) + print( "Received launch request for VAServer ID: " + self.sVAServerID ) except socket.error: - print( "Error while reading variant" ) + print( "ERROR: Socket error while reading VAServer ID" ) self._reset_connection() return False else: @@ -255,6 +304,21 @@ class VirtualAcousticsLauncher: return True + def receive_reproduction_input(self, sMessage): + try: + lsMessageParts = sMessage.split(":") + sReproductionInput = lsMessageParts[1].upper() + self.vaIniParser.eReproductionInput = ReproductionInput[sReproductionInput] + except IndexError: + print("ERROR: Message for receiving reproduction input type was empty") + self.oLauncherConnection.send( b'fail' ) + except ValueError: + print("ERROR: Invalid ID (case-insensitive) for reproduction input: '" + sReproductionInput + "'") + self.oLauncherConnection.send( b'fail' ) + else: #send acceptance + self.oLauncherConnection.send( b'ack' ) + + #Starts the VAServer from given directory def start_va_server(self): @@ -350,7 +414,7 @@ class VirtualAcousticsLauncher: os.makedirs(Fullpath) #send acceptance - self.oLauncherConnection.send( b'ack' ) + self.oLauncherConnection.send( b'ack' ) #receive file iBytesReceived = 0