amerkoleci / Vortice.Windows

.NET bindings for Direct3D12, Direct3D11, WIC, Direct2D1, XInput, XAudio, X3DAudio, DXC, Direct3D9 and DirectInput.
MIT License
1.01k stars 73 forks source link

Help needed, to play a mp3 file with Vortice.XAudio2 #444

Closed shellohunter closed 4 months ago

shellohunter commented 4 months ago

I spent another day trying to play a mp3 file with Vortice.XAudio2, no luck yet.

Here's my source code: https://gist.github.com/shellohunter/8158a170b479f17b0d93cf57eacb533e

It uses Vortice.MediaFoundation as the decoder, then submits decoded data to XAudio2. I picked up some code from: https://github.com/walbourn/directx-sdk-samples/tree/main/XAudio2/XAudio2MFStream which is written in cpp. There's a lot of macros I cannot find in vortice, so I have to made it myself.

AFAK, I should call SetCurrentMediaType on IMFSourceReader to specify the audio format I needed. the reader will load corresponding decoder internally, and give me the expected pcm stream. then I can submit pcm data to Xaudio2.

I haven't go far yet, since the program always went wrong at this line:

IMFMediaType expectedType = MFCreateMediaType(); // SOMETHING WENT WRONG HERE !!!!!!!!

Vortice.MediaFoundation.MediaFactory.MFCreateMediaType throws SharpGen.Runtime.SharpGenException

These API are mystery for me. I've no idea how to debug. I googled around, and found barely nothing helpful. :-(