SlimDX audio, newb

Started by
12 comments, last by FenixRoA 14 years, 1 month ago
Hello, I am using the SlimDX framework for the first time in a Windows 7 x64 environment. I think I've got the project set to compile correctly (target is Debug/x64). I am using the following code as a test. The object of the test is to write a number of samples from a capture device to a file on the hard drive. Below is my code.

/*I've tried enumerating all the capture devices returned by the DirectSoundCapture class. The final entry (#3, zero-based) was the stereo mix. 
The others were primary, microphone, and CD Audio, in that order. I've also tried Primary, and Microphone and those fail in the same way. My goal is to 
sample the stereo mix.*/
            var dsc = new SlimDX.DirectSound.DirectSoundCapture(SlimDX.DirectSound.DirectSoundCapture.GetDevices()[3].DriverGuid); 
            var wf = new SlimDX.Multimedia.WaveFormat();
            wf.BitsPerSample = 16;
            wf.BlockAlignment = (short)(wf.BitsPerSample/8);
            wf.Channels = 2;
            wf.FormatTag = SlimDX.Multimedia.WaveFormatTag.Pcm;
            wf.SamplesPerSecond = 44100;
            wf.AverageBytesPerSecond = wf.SamplesPerSecond * wf.BlockAlignment * wf.Channels;

            var cbd = new SlimDX.DirectSound.CaptureBufferDescription();
            cbd.Format = wf;
            cbd.BufferBytes = 8192;
            cbd.WaveMapped = false;
            System.Windows.Forms.MessageBox.Show("Creating Buffer...");
            cb = new SlimDX.DirectSound.CaptureBuffer(dsc, cbd);
            System.Windows.Forms.MessageBox.Show("Buffer Created!");
            cb.Start(false);
            short[] samples = new short[5000];
            cb.Read<short>(samples, 0, true);
            cb.Stop();
            System.IO.BinaryWriter bw = new System.IO.BinaryWriter(System.IO.File.Open("test.hex", System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.None));
            for (int x = 0; x < samples.Length; x++)
            {
                bw.Write(samples[x]);
            }
            bw.Close();
            System.Windows.Forms.MessageBox.Show("Done!");




This code is placed in a form_load method. Whenever I run this code I get the "Creating Buffer..." messagebox. But as soon as I OK that, the form loads as regular without showing the "Buffer Created!" or "Done!" messages. Also, the text.hex file is never created. What am I doing wrong?
Advertisement
What you're doing wrong is to let the event handler swallow your exception, which is probably being thrown by SlimDX at some point. Move your code to the constructor; it should more or less the same effect and you'll actually get to see the exception being generated.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
:S

I'll try that now. However I'm confused as to why this happens. Normally when I run code in an event method, the program is halted and VS shows the code that threw an exception along with details about that exception.

It occurs to me now that I have never programmed x64 before in VS, and that that may stop regular error handling. Is that possible?


I'll post back once I try your suggestion Promit.
Ok, so I just tried it, and you were of course correct Promit.

I now get a DirectSoundException:
E_INVALIDARG: An invalid parameter was passed to the returning function (-2147024809)

Any ideas?

I have not changed my code except to put it in the forms constructor.
No responses for a while. I tried changing it up.

I switched the project type to "Any CPU", and also switched the slimDX reference to it's x86 equivalent. No changes on behaviour.


I googled E_INVALIDARG, and the error code. Maybe it's just me, but I'm not finding anything that could be wrong, and I can't seem to find anything at all in the slimDX documentation.

Any suggestions will be appreciated
What call is causing this exception? Do you get anything from the debug runtimes?
Mike Popoloski | Journal | SlimDX
The offender is the call to the CaptureBuffer constructor.

I'm trying to set up the debug runtimes as specified in your link Mike. I succeed up to the point where I set "Enable unmanaged code debugging."

I now get an error when I try to build that says:

The debugger does not support debugging managed and native code at the same time on this platform.

I do have 2 projects in this solution but I have unloaded the other one. As for the project in question I only have the generated Program.cs and Form1.cs. There is nothing notably special about my program that I can think would create a problem like this.
Use DebugView then to see the native debugging output.
Mike Popoloski | Journal | SlimDX
Bad timing,

I was JUST about to post that I tried the DebugView solution as well but nothing is showing up. To reiterate I went to the DX control panel and set the audio tab to use debug engine for XACT, and set the directsound debug level to max. I also set the D3D 9 tab to use the Debug version and set the output level to max as well, even though I'm not really using that in my project.



Please help!


EDIT:
Additionally, I've run debugview as administrator, set it to capture kernel, win32, and global. The include filter is set to '*' and the exclude filter is set to nothing. I run my app in Visual Studio 2008 (not express editions), I have also set up the D3D 10/11 debug runtimes for my application folder.

...
Ok, so I played around a bit. For some reason I thought "Any CPU" is equivalent to setting it for "x86". Apparently it's not. When I set it to x86, I can now set "Enable unmanaged code debugging."

However, I have just checked the DX control panel and everything is in full debug mode, in it's most verbose setting. When I run the program all I get is:

'xyz.exe': Loaded 'C:\Windows\SysWOW64\rpcrt4.dll''xyz.exe': Loaded 'C:\Windows\SysWOW64\sspicli.dll''xyz.exe': Loaded 'C:\Windows\SysWOW64\cryptbase.dll''xyz.exe': Loaded 'C:\Windows\SysWOW64\shlwapi.dll''xyz.exe': Loaded 'C:\Windows\SysWOW64\gdi32.dll''xyz.exe': Loaded 'C:\Windows\SysWOW64\user32.dll''xyz.exe': Loaded 'C:\Windows\SysWOW64\lpk.dll''xyz.exe': Loaded 'C:\Windows\SysWOW64\usp10.dll''xyz.exe': Loaded 'C:\Windows\SysWOW64\imm32.dll''xyz.exe': Loaded 'C:\Windows\SysWOW64\msctf.dll''xyz.exe': Loaded 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll''xyz.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.vc80.crt_1fc8b3b9a1e18e3b_8.0.50727.4927_none_d08a205e442db5b5\msvcr80.dll''xyz.exe': Loaded 'C:\Windows\SysWOW64\shell32.dll''xyz.exe': Loaded 'C:\Windows\SysWOW64\ole32.dll''xyz.exe': Loaded 'C:\Windows\SysWOW64\profapi.dll''xyz.exe': Loaded 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\Culture.dll''xyz.exe': Unloaded 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\Culture.dll''xyz.exe': Loaded 'C:\Windows\assembly\NativeImages_v2.0.50727_32\mscorlib\8c1770d45c63cf5c462eeb945ef9aa5d\mscorlib.ni.dll''xyz.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.'xyz.exe': Loaded 'C:\Windows\SysWOW64\uxtheme.dll''xyz.exe': Loaded 'C:\Program Files (x86)\DisplayFusion\DisplayFusionHookx86.dll''xyz.exe' (Managed): Loaded 'E:\VSprojects\xyz\xyz\bin\x86\Debug\xyz.exe', Symbols loaded.'xyz.exe': Loaded 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorjit.dll''xyz.exe': Loaded 'C:\Windows\assembly\NativeImages_v2.0.50727_32\System\5ba3bf5367fc012300c6566f20cb7f54\System.ni.dll''xyz.exe': Loaded 'C:\Windows\assembly\NativeImages_v2.0.50727_32\System.Drawing\ead6be8b410d56b5576b10e56af2c180\System.Drawing.ni.dll''xyz.exe': Loaded 'C:\Windows\assembly\NativeImages_v2.0.50727_32\System.Windows.Forms\fedf1ba58dced4f0b3f8c457648ceed9\System.Windows.Forms.ni.dll''xyz.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Windows.Forms\2.0.0.0__b77a5c561934e089\System.Windows.Forms.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.'xyz.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.'xyz.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.'xyz.exe': Loaded 'C:\Windows\assembly\NativeImages_v2.0.50727_32\System.Configuration\4b1350e31ff09cc583b34854816d8036\System.Configuration.ni.dll''xyz.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.'xyz.exe': Loaded 'C:\Windows\assembly\NativeImages_v2.0.50727_32\System.Xml\5dd9f783008543df3e642ff1e99de4e8\System.Xml.ni.dll''xyz.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.'xyz.exe': Loaded 'ImageAtBase0x6b7a0000', No symbols loaded.'xyz.exe': Loaded 'ImageAtBase0x400000', No symbols loaded.'xyz.exe': Unloaded 'ImageAtBase0x6b7a0000''xyz.exe': Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\9.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll''xyz.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\9.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll''xyz.exe': Loaded 'C:\Program Files\Microsoft Visual Studio 9.0\Common7\Packages\Debugger\x86\Microsoft.VisualStudio.Debugger.Runtime.Impl.dll''xyz.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4926_none_508ed732bcbc0e5a\msvcr90.dll''xyz.exe': Loaded 'ImageAtBase0x61560000''xyz.exe': Unloaded 'ImageAtBase0x61560000''xyz.exe': Loaded 'C:\Windows\assembly\NativeImages_v2.0.50727_32\SlimDX\59b2532eb80f36f34b7c5447b2bd356b\SlimDX.ni.dll''xyz.exe': Loaded 'C:\Windows\assembly\GAC_32\SlimDX\2.0.8.42__b1b0c32fd1ffe4f9\SlimDX.dll''xyz.exe': Unloaded 'C:\Windows\assembly\GAC_32\SlimDX\2.0.8.42__b1b0c32fd1ffe4f9\SlimDX.dll''xyz.exe': Loaded 'C:\Windows\assembly\GAC_32\SlimDX\2.0.8.42__b1b0c32fd1ffe4f9\SlimDX.dll''xyz.exe': Unloaded 'C:\Windows\assembly\GAC_32\SlimDX\2.0.8.42__b1b0c32fd1ffe4f9\SlimDX.dll''xyz.exe': Loaded 'C:\Windows\assembly\GAC_32\SlimDX\2.0.8.42__b1b0c32fd1ffe4f9\SlimDX.dll''xyz.exe': Loaded 'C:\Windows\SysWOW64\winmm.dll''xyz.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4926_none_508ed732bcbc0e5a\msvcp90.dll''xyz.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4926_none_508ed732bcbc0e5a\msvcm90.dll''xyz.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_32\SlimDX\2.0.8.42__b1b0c32fd1ffe4f9\SlimDX.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.'xyz.exe': Loaded 'C:\Windows\SysWOW64\cryptsp.dll''xyz.exe': Loaded 'C:\Windows\SysWOW64\rsaenh.dll''xyz.exe' (Managed): Loaded 'C:\Windows\WinSxS\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4926_none_508ed732bcbc0e5a\msvcm90.dll''xyz.exe': Loaded 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\diasymreader.dll''xyz.exe': Loaded 'C:\Windows\SysWOW64\dwmapi.dll''xyz.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.7600.16385_none_72fc7cbf861225ca\GdiPlus.dll''xyz.exe': Loaded 'C:\Windows\SysWOW64\dsound.dll''xyz.exe': Loaded 'C:\Windows\SysWOW64\powrprof.dll''xyz.exe': Loaded 'C:\Windows\SysWOW64\setupapi.dll''xyz.exe': Loaded 'C:\Windows\SysWOW64\cfgmgr32.dll''xyz.exe': Loaded 'C:\Windows\SysWOW64\oleaut32.dll''xyz.exe': Loaded 'C:\Windows\SysWOW64\devobj.dll''xyz.exe': Loaded 'C:\Windows\SysWOW64\MMDevAPI.dll''xyz.exe': Loaded 'C:\Windows\SysWOW64\propsys.dll''xyz.exe': Loaded 'C:\Windows\SysWOW64\wdmaud.drv''xyz.exe': Loaded 'C:\Windows\SysWOW64\ksuser.dll''xyz.exe': Loaded 'C:\Windows\SysWOW64\avrt.dll''xyz.exe': Loaded 'C:\Windows\SysWOW64\AudioSes.dll''xyz.exe': Loaded 'C:\Windows\SysWOW64\msacm32.drv''xyz.exe': Loaded 'C:\Windows\SysWOW64\msacm32.dll''xyz.exe': Loaded 'C:\Windows\SysWOW64\midimap.dll''xyz.exe': Loaded 'C:\Windows\SysWOW64\clbcatq.dll'A first chance exception of type 'SlimDX.DirectSound.DirectSoundException' occurred in SlimDX.dllAn unhandled exception of type 'SlimDX.DirectSound.DirectSoundException' occurred in SlimDX.dllAdditional information: E_INVALIDARG: An invalid parameter was passed to the returning function (-2147024809)The program '[2496] xyz.exe: Managed' has exited with code 0 (0x0).The program '[2496] xyz.exe: Native' has exited with code 0 (0x0).

This topic is closed to new replies.

Advertisement