DirectSound Capture problem

I also had problems using managed directsound, when I added reference to Microsoft.DirectX.DirectSound I can play sound without problems, but there is problem capturing sound. The example in C# works fine but when I do the same in C++ there is a System.Exception:

Message "Object reference not set to an instance of an object."

Source "Microsoft.DirectX.DirectSound"

StackTrace " at Microsoft.DirectX.DirectSound.Notify..ctor(CaptureBuffer lp)
at CaptureVoice.InitNotifications() in c:\my documents\visual studio projects\capturevoice.cpp:line 84"

I'm using MS Visual studio .Net 2003 and DirectX SDK December 2005 and the code is like this:

applicationDevice = new Capture(); // Caps is set

InputFormat = WaveFormat();

InputFormat.FormatTag = WaveFormatTag::Pcm;

InputFormat.BitsPerSample = 8;

InputFormat.SamplesPerSecond = 8000;

InputFormat.Channels = 1;

InputFormat.BlockAlign = (short)(InputFormat.Channels * (InputFormat.BitsPerSample / 8));

InputFormat.AverageBytesPerSecond = InputFormat.BlockAlign * InputFormat.SamplesPerSecond;

NotifySize = (1024 > InputFormat.AverageBytesPerSecond / 8) 1024 : (InputFormat.AverageBytesPerSecond / 8);

NotifySize -= NotifySize % InputFormat.BlockAlign;

CaptureBufferSize = NotifySize * NumberRecordNotifications;

CaptureBufferDescription dscheckboxd = CaptureBufferDescription();

dscheckboxd.BufferBytes = CaptureBufferSize;

dscheckboxd.Format = InputFormat;

applicationBuffer = new CaptureBuffer(&dscheckboxd, applicationDevice); // Caps is NOT set

NotifyThread = new Thread(new ThreadStart(this,&CaptureVoice::WaitThread));

NotifyThread->Start();

NotificationEvent = new AutoResetEvent(false);

applicationNotify = new Notify(applicationBuffer); // this throws exception

Can someone help me please, maybe it's some stupid slip but I can't see it. I also have another question, is it possible to use some codecs with managed directsound thanx



Answer this question

DirectSound Capture problem

  • Gnomie

    XxxFG wrote:
    They probably all works in C# but not when you do the same in C++.

    That doesn't make sense. Are you saying the DirectSound samples written in C++ in the Sample Browser don't work but the C# samples do What is the specific error your get then



  • TimHiggison

    I hoped someone can help me or at least write some comment, still no progress :(
  • Dennishx

    They probably all works in C# but not when you do the same in C++.
  • Mohamed Salah

    There are several C++ DirectSound samples found in the Sample Browser in the SDK. Do none of those work



  • DirectSound Capture problem