0

我的主要目标是捕获 2 个音频流并将它们存储为vector<BYTE>然后提出一个全等算法来检查是否相等。现在我只捕获一个流,但是流的值为 0'/0'。为什么我的 BYTE 向量中的所有元素都得到空终止值?

    void AudioDeviceOperator::TakeInput(AudioStreamModel* m)
{
  HRESULT hr;
  IAudioClient *iac = NULL;
  IAudioCaptureClient *pCaptureClient = NULL;
  WAVEFORMATEX *mixFormat;
  UINT32 bufferFrameCount;

  HRESULT de;
  de = AudioDeviceEnumerator -> GetDefaultAudioEndpoint(eCapture, eConsole, &SelectedAudioDeviceModel->AudioDevice);
  hr = SelectedAudioDeviceModel->AudioDevice -> Activate(IID_IAudioClient, CLSCTX_ALL, NULL, (void**)&iac);


  REFERENCE_TIME bufferDuration = 0;  //default to min
  REFERENCE_TIME periodicity = 0;

  GUID trashGuid;
  HRESULT tg = CoCreateGuid(&trashGuid);
  LPCGUID AudioSessionGuid = &trashGuid;
  GUID guid2 = *AudioSessionGuid;
  HRESULT guidError = UuidCreate(&guid2); //project -> properties -> Linker -> Command Line -> Rpctr4.lib

  iac->GetMixFormat(&mixFormat);
  m->StreamFormat = *mixFormat;
  if (SUCCEEDED(guidError)) {
    cout << "/n" << "Initializing audio stream..";
    hr = iac->Initialize(AUDCLNT_SHAREMODE_SHARED, AUDCLNT_STREAMFLAGS_CROSSPROCESS, bufferDuration, periodicity, mixFormat, AudioSessionGuid);
    cout << hr;
    hr = iac->GetBufferSize(&bufferFrameCount);
    cout << hr;
    iac->GetService(IID_IAudioCaptureClient, (void**)&pCaptureClient);
    // Calculate the actual duration of the allocated buffer.
    double hnsActualDuration = (double)REFTIMES_PER_SEC * bufferFrameCount / mixFormat-> nSamplesPerSec;

    bool recordAudio = TRUE;
    BYTE *sData;
    UINT32 numFramesAvailable = 0;
    DWORD flags;
    UINT32 packetLength = 0;
    int numOfPackets = 0;
    iac->Start();
    while (recordAudio == TRUE)
    {
      hr = pCaptureClient->GetNextPacketSize(&packetLength);
      while (packetLength != 0) {
        hr = pCaptureClient->GetBuffer(&sData, &numFramesAvailable, &flags, NULL, NULL);
        if (sData != NULL) {
          m->Stream.push_back((*sData)); //here is where I write to the vector
          numOfPackets++;
        }
        if (numOfPackets == 100) {  // just getting 100 packets for testing
          recordAudio = FALSE;
          break;
        }
      }
      hr = pCaptureClient->ReleaseBuffer(numFramesAvailable);
    }
  }
  else
    cout << "AudioSessionGuidError";

  CoTaskMemFree(iac);
  AudioDeviceEnumerator->Release();
  //pCaptureClient->Release();  // releaseBuffer seeming to release capture client interface as weell.
};

当音频会话开始时,我确保发出一些噪音。使用矢量值的方式,我没有什么可比较的。我还假设使用该字节向量并使用 IAudioRenderClient 渲染它不会产生任何结果,但这是我的下一个行动计划。有任何想法吗??

4

0 回答 0