locked
How to refresh buffer in AudioCaptureRaw? RRS feed

  • Question

  • When I execute the Main method twice for refreshing the buffer in AudioCaptureRaw during a session, the program have fallen in dead-lock;

    What should I do?



    • Edited by _yi Tuesday, April 10, 2012 11:10 AM
    Tuesday, April 10, 2012 11:09 AM

Answers

  • Can you share a little bit about what you're trying to do?  AudioCaptureRaw in it's current implementation shows how to access the audio stream, but there are a number of things about it you would want to change if you're building a larger application based on it. 

    First off, right now it uses a fixed length 10 second buffer.  If you want to capture more data, it would be best to switch out to a wave writer that streams to disk.

    If you want to capture multiple sessions of data, you should still:

    • do all the initialization stuff once
    • run the audio capture loop constantly
    • have the logic inside the capture loop decide whether you're currently saving the data (in which case you should copy across to a streaming writer or memory buffer), or not (in which case you can just return)
    Tuesday, April 10, 2012 5:17 PM

All replies

  • Can you share a little bit about what you're trying to do?  AudioCaptureRaw in it's current implementation shows how to access the audio stream, but there are a number of things about it you would want to change if you're building a larger application based on it. 

    First off, right now it uses a fixed length 10 second buffer.  If you want to capture more data, it would be best to switch out to a wave writer that streams to disk.

    If you want to capture multiple sessions of data, you should still:

    • do all the initialization stuff once
    • run the audio capture loop constantly
    • have the logic inside the capture loop decide whether you're currently saving the data (in which case you should copy across to a streaming writer or memory buffer), or not (in which case you can just return)
    Tuesday, April 10, 2012 5:17 PM
  • i want it to capture data in real time.

    I add code is 'for loop', see "the for loop", it is placed about middle position,

    and move shutdown Function to Exit:

    int wmain() { int result = 0; IMMDevice *device = NULL; bool isDefaultDevice; ERole role; HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED); PickDevice(&device, &isDefaultDevice, &role); CWASAPICapture *capturer = new (std::nothrow) CWASAPICapture(device, role); for(int i=0; i<3; i++) { if (capturer->Initialize(TargetLatency)) { size_t captureBufferSize = capturer->SamplesPerSecond() * TargetDurationInSec * capturer->FrameSize(); BYTE *captureBuffer = new (std::nothrow) BYTE[captureBufferSize]; if (capturer->Start(captureBuffer, captureBufferSize)) { do { printf_s(" \r%d\r", TargetDurationInSec); Sleep(1000); } while (--TargetDurationInSec); printf_s("\n"); capturer->Stop(); SaveWaveData(captureBuffer, capturer->BytesCaptured(), capturer->MixFormat()); } printf("\n"); int m = 0; // select channel for (int i = 0; i < 90/*captureBufferSize / 16*/; i +=1) { float * pFloatSample = ((float *) captureBuffer) + i * 4 + m; printf("%d ", (*pFloatSample)); } delete []captureBuffer; Sleep(3000); } } Exit:

    capturer->Shutdown();
    delete capturer;

    SafeRelease(&device); CoUninitialize(); return 0; }

    when "the for loop" is executed second by Visual Studio, It return this,

    {

         AudioCaptureRaw.exe's Running is stopped,

         → check solution in online and close the program

         → close program

         → debug program

    }

    ...i think my algorithm is wrong

    Can you give me a solution?


    is there any problem i make you difficult to understand?







    • Edited by _yi Wednesday, April 18, 2012 5:53 AM
    Thursday, April 12, 2012 5:15 AM
  • Hi,

    Waiting for your reply.

    Regards,

                _yi.

    Wednesday, April 18, 2012 9:24 AM