1

WASAPI を使用して Windows phone8 用のシンプルな VoIP アプリを作成しようとしています。

hr = m_pCaptureClient->GetBuffer(&pbData, &nFrames, &dwFlags, nullptr, nullptr)

数分後、dwFlags は繰り返し 1 (AUDCLNT_BUFFERFLAGS_DATA_DISCONTINUITY) に設定され、返されたパケットはますます小さくなり、その間、吃音はますます大きくなりますが、プロジェクトの一部の実行では、すべてが正常で、音声は完全にクリアです。

誰でもそれについて助けることができますか?

  //MAX_RAW_BUFFER_SIZE 320

     void BackEndAudio::CaptureThread(Windows::Foundation::IAsyncAction^ operation)
{
    uint8_t amrEncodedData[13];
    uint8_t SendingData[14];
    HRESULT hr = m_pDefaultCaptureDevice->Start();
    BYTE *pLocalBuffer = new BYTE[MAX_RAW_BUFFER_SIZE];
    HANDLE eventHandles[] = {
                             hCaptureEvent,        // WAIT_OBJECT0 
                             hShutdownEvent        // WAIT_OBJECT0 + 1
                            };

    if (SUCCEEDED(hr) && pLocalBuffer)  
    { 
        unsigned int uAccumulatedBytes = 0;
        while (SUCCEEDED(hr))
        {
            DWORD waitResult = WaitForMultipleObjectsEx(SIZEOF_ARRAY(eventHandles), eventHandles, FALSE, INFINITE, FALSE);
             if (WAIT_OBJECT_0 == waitResult)
            {
                BYTE* pbData = nullptr;
                UINT32 nFrames = 0;
                DWORD dwFlags = 0;
                if (SUCCEEDED(hr))
                {

                    hr = m_pCaptureClient->GetBuffer(&pbData, &nFrames, &dwFlags, nullptr, nullptr);//Retrieves a pointer to the next available packet of data in the capture endpoint buffer. 

                    unsigned int incomingBufferSize = nFrames * m_sourceFrameSizeInBytes;
                    if (*SendFrameNo==(uint8_t)256) 
                        *SendFrameNo=0;
                    if(dwFlags==1)
                        glitch++;
                        while(MAX_RAW_BUFFER_SIZE - uAccumulatedBytes < incomingBufferSize)
                        {

                            memcpy(pLocalBuffer + uAccumulatedBytes, pbData,MAX_RAW_BUFFER_SIZE-uAccumulatedBytes);

                            if (transportController)
                            {
                                short *tempbuffer=new short[160];
                                for(int i=0;i<160;i++)
                                {
                                    BToS.buf[0]=pLocalBuffer[i*2];
                                    BToS.buf[1]=pLocalBuffer[i*2+1];
                                    tempbuffer[i]=BToS.shbuf;
                                }
                                bool bRet = EasyVAD_IsSilence(hVAD,tempbuffer,160);
                                if(!bRet)
                                {
                                    Encoder_Interface_Encode(amren, MR475, (const short *)pLocalBuffer, amrEncodedData, 0);
                                    memcpy(SendingData,SendFrameNo,1);
                                    memcpy(SendingData+1,amrEncodedData,13);
                                    transportController->Write(SendingData, 14);
                                    (*SendFrameNo)++;
                                }

                            }
                            pbData+=(MAX_RAW_BUFFER_SIZE-uAccumulatedBytes);
                            incomingBufferSize-=(MAX_RAW_BUFFER_SIZE-uAccumulatedBytes);
                            uAccumulatedBytes=0;
                        }

                    if(MAX_RAW_BUFFER_SIZE - uAccumulatedBytes == incomingBufferSize)
                    {
                        memcpy(pLocalBuffer + uAccumulatedBytes, pbData, incomingBufferSize);
                        if (transportController)
                        {
                            short *tempbuffer=new short[160];
                            for(int i=0;i<160;i++)
                                {
                                    BToS.buf[0]=pLocalBuffer[i*2];
                                    BToS.buf[1]=pLocalBuffer[i*2+1];
                                    tempbuffer[i]=BToS.shbuf;
                                }
                                bool bRet = EasyVAD_IsSilence(hVAD,tempbuffer,160);
                                if(!bRet)
                                {
                                    Encoder_Interface_Encode(amren, MR475, (const short *)pLocalBuffer, amrEncodedData, 0);
                                    memcpy(SendingData,SendFrameNo,1);
                                    memcpy(SendingData+1,amrEncodedData,13);
                                    transportController->Write(SendingData, 14);
                                    (*SendFrameNo)++;
                                }

                        }
                        // Reset our counter
                        uAccumulatedBytes = 0;
                    }
                    else if(MAX_RAW_BUFFER_SIZE - uAccumulatedBytes > incomingBufferSize)
                    {
                        memcpy(pLocalBuffer + uAccumulatedBytes, pbData, incomingBufferSize);
                        uAccumulatedBytes += incomingBufferSize;
                    }

                }

                 if (SUCCEEDED(hr))
                {
                    hr = m_pCaptureClient->ReleaseBuffer(nFrames);
                }
            }
            else if (WAIT_OBJECT_0 + 1 == waitResult)
            {
                // We're being asked to shutdown
                break;
            }
            else
            {
                // Unknown return value
                DbgRaiseAssertionFailure();
            }
        }
    }
    delete[] pLocalBuffer;
}

コードは各呼び出しの間に多くの作業を行うことを知っています。GetBufferこれはおそらく時間の不具合の主な問題ですが、私の質問は、なぜそれが発生する場合と発生しない場合があるのですか?

4

0 に答える 0