• Advertisement
Sign in to follow this  

Capture Buffer cannot call start() for 2 times?

This topic is 4763 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone, I am using Directsound to perform the audio capture function. I can create the capture device and capture buffer object successfully. But when I run the below codes, some problem occur. Here is some of my code: void CCap::Capture() { if (SUCCEEDED(DirectSoundCaptureCreate(NULL,&g_pDSCapture,NULL))) cout << "Capture device created!\n"; WAVEFORMATEX wfx = {WAVE_FORMAT_PCM, 1, 44100, 88200, 2, 16, 0}; dscbd.dwSize = sizeof(DSCBUFFERDESC); dscbd.dwFlags = 0; dscbd.dwBufferBytes = wfx.nAvgBytesPerSec; dscbd.dwReserved = 0; dscbd.lpwfxFormat = &wfx; dscbd.dwFXCount = 0; dscbd.lpDSCFXDesc = NULL; if (g_pDSCapture != NULL) { g_pDSCapture->CreateCaptureBuffer(&dscbd, &g_pDSBCapture,NULL); cout <<"g_pDSBCapture = "<<g_pDSBCapture<<endl; } g_pDSBCapture->Start(DSCBSTART_LOOPING ); Sleep(500); g_pDSBCapture->Stop(); cout <<"Capture Stopped!" <<endl; RecordCapturedData(g_pDSCapture,g_pDSBCapture); g_pDSBCapture->Start(DSCBSTART_LOOPING ); Sleep(500); g_pDSBCapture->Stop(); cout <<"Capture Stopped!" <<endl; RecordCapturedData(g_pDSCapture,g_pDSBCapture); if (SUCCEEDED(snd_manager->Create(&snd,TEXT("c:\\a.wav"),0,GUID_NULL,1))) cout << "Sound loaded!\n"; if (SUCCEEDED(snd->Play(0,0))) cout << "Sound played!\n"; } The RecordCapturedData() copies the capture audio to the a.wav file. When I call the g_pDSBCapture->Start(DSCBSTART_LOOPING) for the first time, there is no problem for the buffer to record data and write to a file. When I call it the second time, the buffer however cannot record anything. I call the GetCurrentPosition() and I found that the offset position of the buffer does not advance. Is it a mistake to call the Start() method for more than one time? Thank you for answering my question and looking the long text!!

Share this post


Link to post
Share on other sites
Advertisement
Looks like an earlier version of a post I have just responded to.

It looks like the provided code is supposed to be some function that you call each time you want to record some data. In that case:

Some questions and remarks:

Do you create the capture buffer every time you call this function, because you don't destroy it when you are done.

You don't set the position when you start. Not a problem on the first call but after the first stop the record position is going to be where ever that stop is.

How do you determine where to read? Is it safe?

Its not clear what 'doesn't' happen on your second call. Do you get just garbage or nothing (have you simply reread what'a already in the buffer)?

Brian

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement