Directsound capture

di il
8 risposte

Directsound capture

Buongiorno a tutti,
sto cercando di imparare la directsound library. Ho scritto il seguente codice ma mi da errore nel creare il buffer. Qualcuno mi puo dire dove sbaglio.

// c++ DirectSound Capture.cpp : definisce il punto di ingresso dell'applicazione console.
//

#include "stdafx.h"
#include <dsound.h>

#pragma comment(lib, "dsound.lib")

HRESULT hresult;

void dsError(HRESULT hresult);

int _tmain(int argc, _TCHAR* argv[])
{
// typedef struct IDirectSoundCapture *LPDIRECTSOUNDCAPTURE;

// HRESULT DirectSoundCaptureCreate8(LPCGUID lpcGUID, LPDIRECTSOUNDCAPTURE8 * lplpDSC, LPUNKNOWN pUnkOuter);
IDirectSoundCapture * lpDSC;
LPDIRECTSOUNDCAPTURE * lplpDSC = &lpDSC;

hresult = DirectSoundCaptureCreate(NULL, &lpDSC, 0);
printf("DirectSoundCaptureCreate %d \n", hresult);

// HRESULT CreateCaptureBuffer(LPCDSCBUFFERDESC pcDSCBufferDesc, LPDIRECTSOUNDCAPTUREBUFFER * ppDSCBuffer, LPUNKNOWN pUnkOuter)
WAVEFORMATEX waveformatex;
LPWAVEFORMATEX lpwaveformatex = &waveformatex;;

waveformatex.cbSize = 0;
waveformatex.wBitsPerSample = 16;
waveformatex.nSamplesPerSec = 48000;
waveformatex.nChannels = 2;
waveformatex.wFormatTag = WAVE_FORMAT_PCM;
waveformatex.nBlockAlign = ((waveformatex.wBitsPerSample / * waveformatex.nChannels);
waveformatex.nAvgBytesPerSec = waveformatex.nSamplesPerSec * waveformatex.nBlockAlign;

{
printf("cbSize %d \n", lpwaveformatex->cbSize);
printf("nAvgBytesPerSec %d \n", lpwaveformatex->nAvgBytesPerSec);
printf("nBlockAlign %d \n", lpwaveformatex->nBlockAlign);
printf("nChannels %d \n", lpwaveformatex->nChannels);
printf("nSamplesPerSec %d \n", lpwaveformatex->nSamplesPerSec);
printf("wBitsPerSamples %d \n", lpwaveformatex->wBitsPerSample);
printf("wFormatTag %d \n", lpwaveformatex->wFormatTag);
system("PAUSE");
}

DSCBUFFERDESC DSCBufferDesc;
LPCDSCBUFFERDESC pcDSCBufferDesc = &DSCBufferDesc;

DSCBufferDesc.dwSize = sizeof(DSCBUFFERDESC);
DSCBufferDesc.dwBufferBytes = waveformatex.nAvgBytesPerSec * 10000;
DSCBufferDesc.dwFlags = 0;
DSCBufferDesc.lpwfxFormat = lpwaveformatex;

{
printf("BufferDesc->dwSize %d \n", pcDSCBufferDesc->dwSize);
printf("BufferDesc->dwBufferBytes %d \n", pcDSCBufferDesc->dwBufferBytes);
printf("BufferDesc->dwFlags %d \n", pcDSCBufferDesc->dwFlags);
}

IDirectSoundCaptureBuffer * pDSCBuffer;
LPDIRECTSOUNDCAPTUREBUFFER * ppDSCBuffer = &pDSCBuffer;

hresult = lpDSC->CreateCaptureBuffer(pcDSCBufferDesc, ppDSCBuffer, NULL);
printf("CreateCaptureBuffer %d \n", hresult);
dsError(hresult);

system("PAUSE");

return 0;
}

8 Risposte

  • Re: Directsound capture

    Cioè quale errore? Esattamente in quale riga?

    Perché non usi i tag CODE per rendere il codice leggibile?
  • Re: Directsound capture

    Sto abbozzando per provare in modo veloce quindi non ho inserito tag code.

    Mi da errore nella creazione del buffer

    hresult = lpDSC->CreateCaptureBuffer(pcDSCBufferDesc, ppDSCBuffer, NULL);

    cod.Errore -2147024809
    An invalid parameterwas passed to the returning function.

    Grazie per la collaborazione
  • Re: Directsound capture

    ppDSCBuffer
    Address of a variable that receives an IDirectSoundCaptureBuffer interface pointer. Use QueryInterface to obtain IDirectSoundCaptureBuffer8. See Remarks.
    On Microsoft Windows98 and Windows2000, each capture device supports a single buffer.

    The IDirectSoundCaptureBuffer8 interface is supported only on buffers created by an object of class CLSID_DirectSoundCapture8. If the IDirectSoundCapture8 interface was obtained from DirectSoundCaptureCreate8, IDirectSoundCaptureBuffer8 is supported. If IDirectSoundCapture8 was obtained from the earlier DirectSoundCaptureCreate function, only IDirectSoundCaptureBuffer is supported.
  • Re: Directsound capture

    HRESULT CreateCaptureBuffer(LPDIRECTSOUNDCAPTURE8 pDSC, 
                                LPDIRECTSOUNDCAPTUREBUFFER8* ppDSCB8)
    {
      HRESULT hr;
      DSCBUFFERDESC               dscbd;
      LPDIRECTSOUNDCAPTUREBUFFER  pDSCB;
      WAVEFORMATEX                wfx =
        {WAVE_FORMAT_PCM, 2, 44100, 176400, 4, 16, 0};
        // wFormatTag, nChannels, nSamplesPerSec, mAvgBytesPerSec,
        // nBlockAlign, wBitsPerSample, cbSize
     
      if ((NULL == pDSC) || (NULL == ppDSCB8)) return E_INVALIDARG;
      dscbd.dwSize = sizeof(DSCBUFFERDESC);
      dscbd.dwFlags = 0;
      dscbd.dwBufferBytes = wfx.nAvgBytesPerSec;
      dscbd.dwReserved = 0;
      dscbd.lpwfxFormat = &wfx;
      dscbd.dwFXCount = 0;
      dscbd.lpDSCFXDesc = NULL;
     
      if (SUCCEEDED(hr = pDSC->CreateCaptureBuffer(&dscbd, &pDSCB, NULL)))
      {
        hr = pDSCB->QueryInterface(IID_IDirectSoundCaptureBuffer8, (LPVOID*)ppDSCB8);
        pDSCB->Release();  
      }
      return hr;
    }
  • Re: Directsound capture

    Ciao,
    ho inserito il seguente codice nel mio listato

    if (lpDSC->CreateCaptureBuffer(pcDSCBufferDesc, &pDSCBuffer, NULL) != 0)
    {
    hresult = lpDSC->QueryInterface(IID_IDirectSoundCaptureBuffer8, (LPVOID*)ppDSCBuffer);
    printf("CreateCaptureBuffer %d \n", hresult);
    dsError(hresult);
    lpDSC->Release();
    }

    in esecuzione mi da l'errore seguente:

    -2147467262
    The requested COM interface is not available.
  • Re: Directsound capture

    Guarda qui
  • Re: Directsound capture

    Ho dato un occhio alla creazione di istanze ma il risultato è il medesimo.

    Sempre con lo stesso errore nello stesso punto.
  • Re: Directsound capture

    Ho scritto il seguente codice passo dopo passo da msdn di microsoft

    // c++ dx dsound.cpp : definisce il punto di ingresso dell'applicazione console.
    //

    #include "stdafx.h"
    #include <dsound.h>

    #pragma comment(lib, "dsound.lib")
    #pragma comment(lib, "dxguid.lib")

    LPDIRECTSOUNDCAPTUREBUFFER8* ppDSCB8;
    LPDIRECTSOUNDCAPTURE8 pDSC;

    HRESULT CreateCaptureBuffer(LPDIRECTSOUNDCAPTURE8 pDSC, LPDIRECTSOUNDCAPTUREBUFFER8* ppDSCB8);
    void dsError(HRESULT hr);

    int _tmain(int argc, _TCHAR* argv[])
    {

    LPDIRECTSOUNDCAPTURE8 lpds;
    HRESULT hr = DirectSoundCaptureCreate8(NULL, &lpds, NULL);
    printf("%d \n", hr);
    dsError(hr);
    system("PAUSE");


    hr = CoInitializeEx(NULL, 0);
    printf("%d \n", hr);
    dsError(hr);
    system("PAUSE");

    hr = CoCreateInstance(CLSID_DirectSoundCapture8, NULL, CLSCTX_INPROC_SERVER, IID_IDirectSoundCapture8, (LPVOID*) &lpds);
    printf("%d \n", hr);
    dsError(hr);
    system("PAUSE");

    hr = lpds->Initialize(NULL);
    printf("%d \n", hr);
    dsError(hr);
    system("PAUSE");

    hr = CreateCaptureBuffer(pDSC, ppDSCB8);
    printf("%d \n", hr);
    dsError(hr);
    system("PAUSE");

    return 0;

    }

    HRESULT CreateCaptureBuffer(LPDIRECTSOUNDCAPTURE8 pDSC, LPDIRECTSOUNDCAPTUREBUFFER8* ppDSCB8)
    {
    HRESULT hr;
    DSCBUFFERDESC dscbd;
    LPDIRECTSOUNDCAPTUREBUFFER pDSCB;
    WAVEFORMATEX wfx =
    {WAVE_FORMAT_PCM, 2, 44100, 176400, 4, 16, 0};
    // wFormatTag, nChannels, nSamplesPerSec, mAvgBytesPerSec,
    // nBlockAlign, wBitsPerSample, cbSize

    if ((NULL == pDSC) || (NULL == ppDSCB8)) return E_INVALIDARG;
    dscbd.dwSize = sizeof(DSCBUFFERDESC);
    dscbd.dwFlags = 0;
    dscbd.dwBufferBytes = wfx.nAvgBytesPerSec;
    dscbd.dwReserved = 0;
    dscbd.lpwfxFormat = &wfx;
    dscbd.dwFXCount = 0;
    dscbd.lpDSCFXDesc = NULL;

    if (SUCCEEDED(hr = pDSC->CreateCaptureBuffer(&dscbd, &pDSCB, NULL)))
    {
    printf("QueryInterface\n");
    hr = pDSCB->QueryInterface(IID_IDirectSoundCaptureBuffer8, (LPVOID*)ppDSCB8);
    pDSCB->Release();
    }
    return hr;
    }

    void dsError(HRESULT hr) {
    }

    Mi restituisce l'errore numero -2147024809 che equivale a
    An invalid paramer was passed to the returning the function.
    all'istruzione hr = pDSC->CreateCaptureBuffer(&dscbd, &pDSCB, NULL).

    Praticamente sono punto e a capo con lo stesso errore!!!!!
    Qualcuno mi sa aiutare!!!!
    Grazie per la collaborazione.
    Marcello
Devi accedere o registrarti per scrivere nel forum
8 risposte