[RESOLVED] Using PDK Sound Service

For topics related to the creation of simulation objects (SimObjects). This includes development of aircraft, ground, and maritime vehicles.
flyboy7798
Posts: 31
Joined: Thu Jul 20, 2017 7:15 pm

[RESOLVED] Using PDK Sound Service

Postby flyboy7798 » Sun Dec 09, 2018 9:29 pm

In a class that is responsible for playing a specific .wav file, the header has the following:

Code: Select all

#include <atlcomcli.h> #include <Pdk.h> #include <InitGuid.h> #include <ISoundService.h> ... P3D::IPdk* pIPdk = nullptr; CComPtr<P3D::ISoundServiceV440> pPdkSoundService; CComPtr<P3D::ISoundInstanceV440> pPdkGearWarningSoundInstance; LPCWSTR pszFileName = L"sound.wav";
In the accompanying implementation, the class constructor (exception handling removed for simplicity) has this:

Code: Select all

query_pdk(P3D::IID_IPdk, (void **)&pIPdk); pIPdk->QueryService(P3D::SID_SoundService, P3D::IID_ISoundInstanceV440, (void**)&pPdkSoundService); pPdkSoundService->CreateSoundInstance(pszFileName, P3D::SOUND_GROUP::SOUND_GROUP_COCKPIT, P3D::VIEW_POINT::VIEW_POINT_INTERIOR, TRUE, FALSE, FALSE, (void **)&pPdkGearWarningSoundInstance);
And finally in a function call to play the sound I have this:

Code: Select all

pPdkGearWarningSoundInstance->Play();
I would like to know if this arrangement would work or if I have missed something...thanks in advance!

User avatar
Rob McCarthy
Lockheed Martin
Posts: 2275
Joined: Wed Aug 24, 2011 1:37 pm

Re: Using PDK Sound Service

Postby Rob McCarthy » Mon Dec 10, 2018 2:56 pm

Hello,

Are you seeing any issues with the sound playing?

Regards,
Rob McCarthy
Rob McCarthy
Prepar3D® Core Lead

flyboy7798
Posts: 31
Joined: Thu Jul 20, 2017 7:15 pm

Re: Using PDK Sound Service

Postby flyboy7798 » Mon Dec 10, 2018 4:21 pm

I tested it last night and this morning never made it into the simulator. This is the error:

Debug Assertion Failed

File:D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\atlmfc\include\atlcomcli.h

Line:182

Expression: p!= 0

...and even with a breakpoint, I couldn't get it to break where I could see what was causing the failure. Any help would be greatly appreciated.

flyboy7798
Posts: 31
Joined: Thu Jul 20, 2017 7:15 pm

Re: Using PDK Sound Service

Postby flyboy7798 » Mon Dec 10, 2018 5:46 pm

Update to the above:

I know that this is because I'm calling a function through an uninitialized pointer. And most likely its this line didn't do the initialization on pIPdk,

query_pdk(P3D::IID_IPdk, (void **)&pIPdk);

and this is the call that probably threw the exception because of it,

pIPdk->QueryService(P3D::SID_SoundService, P3D::IID_ISoundInstanceV440, (void**)&pPdkSoundService);

...pIPdk was not initialized. It tells me I've missed something...is there some other step required to initialize the pIPdk pointer?

Also, I went back over the code and saw this in the API documentation:

IID_IPdkv01

So now this line of code reads

query_pdk(P3D::IID_IPdkV01, (void **)&pIPdk);

Testing now. Thanks in advance for the assistance

flyboy7798
Posts: 31
Joined: Thu Jul 20, 2017 7:15 pm

Re: Using PDK Sound Service

Postby flyboy7798 » Mon Dec 10, 2018 5:54 pm

Same failure...

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

Re: Using PDK Sound Service

Postby Mike Schroeter » Mon Dec 10, 2018 7:49 pm

What does query_pdk return? I assume this is from the gauges.h and you've verified that other gauge api functions are working properly?

As for the

Code: Select all

pIPdk->QueryService(P3D::SID_SoundService, P3D::IID_ISoundInstanceV440, (void**)&pPdkSoundService);
this should be

Code: Select all

pIPdk->QueryService(P3D::SID_SoundService, P3D::IID_IID_ISoundServiceV440, (void**)&pPdkSoundService);
You will need to get the service before you can create an instance.

Mike

flyboy7798
Posts: 31
Joined: Thu Jul 20, 2017 7:15 pm

Re: Using PDK Sound Service

Postby flyboy7798 » Mon Dec 10, 2018 8:32 pm

Answers to your questions,

What does the query_pdk return?

I can't tell because even with breakpoints at the proper points the exception is thrown before I even get to a breakpoint. When I select retry on the dialog Prepar3D CTDs and the debugger quits.

I assume this is from the gauges.h and you've verified that other gauge api functions are working properly?

Yes to both. The class that this code belongs to is a non-pdk based class, I wanted to try to play a sound via the service for an individual class that is part of a larger "system." This class is not the driver class that contains the module_init and module_deinit, it is a class that belongs to a subsystem, an aircraft component, of which there are many classes/objects like it which are combined as components and grouped into subsystems. I use a SimConnect Adapter class to provide access via that channel. So there is no problem getting and setting Avars and using Lvars. I got to a requirement where a sound needed to be implemented and thought if query_pdk can provide an interface to request services, then I wanted to try to play that sound via the PDK, instead of a separate sound solution. The entire aircraft has been in unit/alpha test for quite some time and didn't start failing until I tried to use the PDK.

I'll try your suggestion and respond...And thank you again for a fast answer!

flyboy7798
Posts: 31
Joined: Thu Jul 20, 2017 7:15 pm

Re: Using PDK Sound Service

Postby flyboy7798 » Mon Dec 10, 2018 9:02 pm

Mike,

Thanks so much. That seemed to have done the trick. At least it got me into the simulator but the sound instance didn't play the sound...so at least I got this far without crashing the sim. Off to go figure that one out.

Before I do, another question if I may. When using this way to integrate the PDK into what is essentially a non-PDK solution (at this point in time), is there some canonical or idiomatic steps to getting a service (beyond the sound service)?

V/R
Jim

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

Re: Using PDK Sound Service

Postby Mike Schroeter » Tue Dec 11, 2018 4:47 pm

Maybe I'm misunderstanding something, but wasn't the crash with the query_pdk call? The suggestion I gave you was for the subsequent call for the sound service, which would not be possible without successfully calling query_pdk, right? Is that working for you?

Mike

flyboy7798
Posts: 31
Joined: Thu Jul 20, 2017 7:15 pm

Re: Using PDK Sound Service

Postby flyboy7798 » Tue Dec 11, 2018 5:12 pm

I changed the code as you suggested, and now the aircraft code/DLL runs in the simulator, but for some reason, it won't create the sound instance...here's the stuff in the constructor (exception handling/debug stuff removed for simplicity):

I've declared these in the class header file:

Code: Select all

P3D::IPdk* pIPdk = nullptr; CComPtr<P3D::ISoundServiceV440> pPdkSoundService; CComPtr<P3D::ISoundInstanceV440> pPdkGearWarningSoundInstance; LPCWSTR pszFileName = L"sound.wav";
...and this is the class constructor in the implementation file:

Code: Select all

query_pdk(P3D::IID_IPdkV01, (void **)&pIPdk); pIPdk->QueryService(P3D::SID_SoundService, P3D::IID_ISoundServiceV440, (void**)&pPdkSoundService); pPdkSoundService->CreateSoundInstance(pszFileName, P3D::SOUND_GROUP::SOUND_GROUP_COCKPIT, P3D::VIEW_POINT::VIEW_POINT_INTERIOR, TRUE, FALSE, FALSE, (void **)&pPdkGearWarningSoundInstance);
That last line is the one that fails. Also for some reason, I can't seem to hit a breakpoint in the constructor to read the HRESULT value.

V/R
Jim

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

Re: Using PDK Sound Service

Postby Mike Schroeter » Tue Dec 11, 2018 6:13 pm

You may want to try providing the full path in your sound file name.

Mike

flyboy7798
Posts: 31
Joined: Thu Jul 20, 2017 7:15 pm

Re: Using PDK Sound Service

Postby flyboy7798 » Tue Dec 11, 2018 7:53 pm

That got it...thanks again.


Return to “Simulation Object Development Questions”

Who is online

Users browsing this forum: No registered users and 1 guest