Closed h1cks closed 3 years ago
I've added SoundStream and RiffParser from SharpDX, I've managed to handle sound playing without issues, code bellow:
IXAudio2 xaudio2 = XAudio2Create();
using (IXAudio2MasteringVoice masteringVoice = xaudio2.CreateMasteringVoice())
{
using (var stream = new SoundStream(File.OpenRead("ergon.wav")))
{
var waveFormat = stream.Format!;
var buffer = new AudioBuffer(stream.ToDataStream());
using (var sourceVoice = xaudio2.CreateSourceVoice(waveFormat, true))
{
sourceVoice.BufferStart += (context) => Console.WriteLine(" => event received: buffer start");
sourceVoice.BufferEnd += (context) => Console.WriteLine(" => event received: end of buffer");
sourceVoice.SubmitSourceBuffer(buffer, stream.DecodedPacketsInfo);
sourceVoice.Start();
int count = 0;
while (sourceVoice.State.BuffersQueued > 0/* && !IsKeyPressed(ConsoleKey.Escape)*/)
{
if (count == 50)
{
Console.Write(".");
Console.Out.Flush();
count = 0;
}
Thread.Sleep(10);
count++;
}
sourceVoice.DestroyVoice();
}
}
}
Cheers, I have found the issue, I had some logic around callbacks causing an issue and not releasing the sound channel (my version of wrapper for voice sharing). I realised I didnt have to create a separate IXAudio2VoiceCallback class, I just had to implement the interface into my Sound Channel. I had some weird memory sharing problems, no errors now and all is happy go lucky!
Will close @amerkoleci
Update, the issue still exists, just less so. The issue is occurring around the time I free and create a voice in quick succession. There maybe a threading issue. The problem is hidden by putting a try/catch around the createvoice code so the problem is hidden.
Well if the problem is not from Vortice.Windows side then I would close the issue?
I've found the issue, this is related to the sample encoding, playing an MS Extensible Wav Format causes an exception in CreateSourceVoice call. I changed the sound format to PCM Wav and sample worked.
Will close @amerkoleci
I will test with soundstream and see if the sound will work. If it does then it means my current load method is flawed
Running my game, i'm calling CreateSourceVoice which randomly throws an exception each time. I removed my custom parameters but same issue. I've attached the error content from the exception including the HRESULT. If the info isn't enough, may need to give you access to my project as the issue is 100% reproducible.
I may also look at maybe the way i'm handling buffers also, so I may close if I find an issue in my own handling logic, but currently error thrown seems to be unidentified. The issue is occurs sporadically after that, it seems to recover than fail again. The exception swallows the error and the game continues.
Code Sample it crashes in.