-1

私は自分のプログラムでかなり長い間ウェーブフォーマットを設定しようとしてきましたが、成功していません...

directsound->setFormat メソッドで常に false を返します...誰か助けてくれませんか?

以下に掲載されているのは、私が取り組んでいるコードです

bool SoundClass::InitializeDirectSound(HWND HANDLE)
{
HRESULT hr;
DSBUFFERDESC BufferDesc;
WAVEFORMATEX WaveFormat;

hr = DirectSoundCreate8(NULL,&m_pDirectSound,NULL);
if(FAILED(hr))
{
    return false;
}
hr = m_pDirectSound->SetCooperativeLevel(HANDLE,DSSCL_PRIORITY);
if(FAILED(hr))
{
    return false;
}

      //setup primary buffer desc

BufferDesc.dwSize = sizeof(DSBUFFERDESC);
BufferDesc.dwBufferBytes = 0;
BufferDesc.dwFlags =  DSBCAPS_PRIMARYBUFFER | DSBCAPS_CTRLVOLUME;
BufferDesc.guid3DAlgorithm = GUID_NULL;
BufferDesc.dwReserved = 0;
BufferDesc.lpwfxFormat = NULL;

      // Get control of the primary sound buffer on the default sound device.

hr = m_pDirectSound->CreateSoundBuffer(&BufferDesc,&m_pPrimarySoundBuffer,NULL);
if(FAILED(hr))
{
    return false;
}

      //setup the format of primary buffer
      // In this case it is a .WAV file recorded at 44,100 samples per second in 16-bit stereo (cd audio format).

WaveFormat.wFormatTag = WAVE_FORMAT_PCM;
WaveFormat.nSamplesPerSec = 44,100;
WaveFormat.wBitsPerSample = 16;
WaveFormat.nChannels = 2;
WaveFormat.nBlockAlign =(WaveFormat.wBitsPerSample / 8) * WaveFormat.nChannels;
WaveFormat.nAvgBytesPerSec = WaveFormat.nSamplesPerSec * WaveFormat.nBlockAlign;
WaveFormat.cbSize = 0;

      //set the primary buffer format to the described waveformat(it always returns false here)

hr = m_pPrimarySoundBuffer->SetFormat(&WaveFormat);
if(FAILED(hr))
{
    return false;
}
return true;
}
4

1 に答える 1

1

タイプミスでない限り、次の行に問題がある可能性があります。

WaveFormat.nSamplesPerSec = 44,100;

そのはず

WaveFormat.nSamplesPerSec = 44100L;
于 2013-06-25T07:17:18.263 に答える