Audio with SimConnect

smguest
Posts: 38
Joined: Fri Jan 28, 2011 9:21 pm

Postby smguest » Wed Apr 11, 2012 3:39 pm

We are using a modification of the ExternalSim sample code in with our own simulation controlling the vehicle. We’ve gotten things to work pretty well but one thing that we’ve noticed is that there is no sound. If we manually load our model from within Prepar3D, the sounds work as expected. When we connect to Prepar3D using a SimConnect client, we get no audio. Is there something we need to do to enable the aircraft sounds to work? I’m mainly wanting the engine sounds to work so is there something like a sim variable that needs to be set and sent?



Thanks,

Stephen

smguest
Posts: 38
Joined: Fri Jan 28, 2011 9:21 pm

Postby smguest » Thu Apr 12, 2012 2:40 pm

I'm guessing the real question is how do you trigger/use the default sounds set up by that vehicle's sound config file if you are using an external simulation. Is it possible or is the sound engine disconnected for that object when you take over with an external sim? In this particular case, I am using SimConnect_ChangeVehicleWithExternalSim to make the connection.

Mike Schroeter
Lockheed Martin
Posts: 294
Joined: Thu Jan 12, 2012 7:05 pm

Postby Mike Schroeter » Fri Apr 13, 2012 2:55 pm

I haven’t tried this myself, but in theory I think it should be possible. To give it a try, your implementation will need to provide the relevant data for the type of engine you want using the variables in the Simulation Variables document. For starters, you’ll need to add engine type and number of engines just to get the sound classes loaded and initialized. E.g. add to your output definition:



SimConnect_AddToDataDefinition(g_hSimConnect, PER_VEHICLE_OUTPUT_DEFINITION, ("NUMBER OF ENGINES"), ("number"), SIMCONNECT_DATATYPE_FLOAT64);

SimConnect_AddToDataDefinition(g_hSimConnect, PER_VEHICLE_OUTPUT_DEFINITION, ("ENGINE TYPE"), ("enum"), SIMCONNECT_DATATYPE_FLOAT64);



After that, I would provide the major impacts on sound depending on your engine type… e.g. RPM, Combustion. Report back and let us know how this works.



Mike


smguest
Posts: 38
Joined: Fri Jan 28, 2011 9:21 pm

Postby smguest » Mon Apr 16, 2012 9:30 am

Hmmm - still no go. So I've included the following simulation variables to the per vehicle output data structure -

double numEngs;

double engType;

double engComb;

double genEngComb1;

double genEngThrotLeverPos1;

double propRPM1;



I've added them to the per vehicle output data definition:

SimConnect_AddToDataDefinition(g_hSimConnect, PER_VEHICLE_OUTPUT_DEFINITION, ("NUMBER OF ENGINES"), ("number"), SIMCONNECT_DATATYPE_FLOAT64 );

SimConnect_AddToDataDefinition(g_hSimConnect, PER_VEHICLE_OUTPUT_DEFINITION, ("ENGINE TYPE"), ("enum"), SIMCONNECT_DATATYPE_FLOAT64 );

SimConnect_AddToDataDefinition(g_hSimConnect, PER_VEHICLE_OUTPUT_DEFINITION, ("ENG COMBUSTION"), ("bool"), SIMCONNECT_DATATYPE_FLOAT64 );

SimConnect_AddToDataDefinition(g_hSimConnect, PER_VEHICLE_OUTPUT_DEFINITION, ("GENERAL ENG COMBUSTION:1"), ("bool"), SIMCONNECT_DATATYPE_FLOAT64 );

SimConnect_AddToDataDefinition(g_hSimConnect, PER_VEHICLE_OUTPUT_DEFINITION, ("GENERAL ENG THROTTLE LEVER POSITION:1"), ("percent"), SIMCONNECT_DATATYPE_FLOAT64 );

SimConnect_AddToDataDefinition(g_hSimConnect, PER_VEHICLE_OUTPUT_DEFINITION, ("PROP RPM:1"), ("rpm"), SIMCONNECT_DATATYPE_FLOAT64 );



And I hardwired these variables at runtime:

pvo.numEngs = 1.0;

pvo.engType = 0.0;

pvo.engComb = 1.0;

pvo.genEngComb1 = 1.0;

pvo.genEngThrotLeverPos1 = 100.0;

pvo.propRPM1 = 2000.0;



And still no sound. Anything else that you can see I'm missing? Looking at the documentation, I don't see an engine rpm that can be set; however, I can set the prop rpm and do so.



Thanks,

Stephen


Mike Schroeter
Lockheed Martin
Posts: 294
Joined: Thu Jan 12, 2012 7:05 pm

Postby Mike Schroeter » Mon Apr 16, 2012 6:33 pm

It looks like you're simulating a piston engine, right? Digging a little more, try adding this additional one: "GENERAL ENG COMBUSTION SOUND PERCENT" (double). This value (0 - 100%) essentially should reflect the magnitude of the sound.



Mike


smguest
Posts: 38
Joined: Fri Jan 28, 2011 9:21 pm

Postby smguest » Tue Apr 17, 2012 9:14 am

Yep, it is supposed to be a piston engine. I've added the sound percent to the data definition and I've still no sound but according to the documentation, it appears that that variable is not settable and is read only.



I do have a question, if you note that above when I define the engComb variable, I have it set up as a double and not a boolean. This is because if I initialize it as a boolean, my aircraft never recieves the positional information that is registered afterwards. So to reiterate, I initialize like this -



double engComb;



but add to the data definition like this -



SimConnect_AddToDataDefinition(g_hSimConnect, PER_VEHICLE_OUTPUT_DEFINITION, ("ENG COMBUSTION"), ("bool"), SIMCONNECT_DATATYPE_FLOAT64 );



So while the data itself represents a boolean, locally it is a double variable but flagged in the DataDefinition statement as a "bool" BUT with a FLOAT64 type (as I cannot find a BOOL simconnect datatype). So maybe I've really messed this up but I did so because this is what it seemed to take to keep the rest of the data working correctly. Should this work?



Thanks,

Stephen

smguest
Posts: 38
Joined: Fri Jan 28, 2011 9:21 pm

Postby smguest » Tue Apr 17, 2012 11:06 am

The bool concern I previously stated is not an issue. I've been able to confirm that it works correctly, although I did define the local struct "bool" vars as ints and pass them via the SimConnect_AddToDataDefinition call with a simconnect type of SIMCONNECT_DATATYPE_INT32.



Still no joy on getting any of the sound to work this way and I've gone a step further to make sure that master battery switch is turned on and the left and right magnetos are enabled. I can see the results of everything working with the cockpit gauges/switches and with the propeller (and of course with the aircraft moving about in 3D space), but just without any sound. So I'm still missing something essential.



Stephen

Mike Schroeter
Lockheed Martin
Posts: 294
Joined: Thu Jan 12, 2012 7:05 pm

Postby Mike Schroeter » Wed Apr 18, 2012 2:35 pm

Thanks for your patience, Stephen. Unfortunately I can't determine from code inspection why this doesn't work. I'll try to set up some prototype code myself to see if we can figure out how to make this scenario work. Sorry.



About your "bool" issue above... yes, that should work. It's a little misleading, but that "bool" represents a unit-type rather than a data-type. It's normally used for converting data between native and requested units, such as feet-to-meters.



Mike



Return to “SimConnect Interface Questions”

Who is online

Users browsing this forum: No registered users and 4 guests