簡體   English   中英

從IStream讀取到緩沖區(音頻)

[英]Reading from an IStream to a Buffer (Audio)

我基本上是試圖將音頻流的內容讀入char *緩沖區以應用FFT。 我正在使用SAPI簡化應用FFT后需要進行的轉換。

我在HGLOBAL上分配了一個IStream緩沖區

// Address of IStream* pointer variable that receives the interface pointer to the new stream object.
CComPtr<IStream> pMemStream;
// A memory handle allocated by the GlobalAlloc function, or if NULL a new handle is to be allocated instead.
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, sizeof(pMemStream));
// Create stream object that uses an HGLOBAL memory handle to store the stream contents.
hr = ::CreateStreamOnHGlobal(hGlobal, TRUE, &pMemStream);

然后我將WAV內容寫入此流

// Variable to receive ISpStream pointer
CComPtr<ISpStream> cpSpStream;
hr = cpSpStream.CoCreateInstance(CLSID_SpStream);
hr = cpSpStream->SetBaseStream(pMemStream, SPDFID_WaveFormatEx, defaultStreamFormat.WaveFormatExPtr());
hr = cpVoice->SetOutput(cpSpStream, TRUE);
hr = cpVoice->Speak(L"This is a phrase.", SPF_DEFAULT, NULL);

我可以通過說出流來驗證流中是否包含wav內容:

// Speak the modified stream.
cpVoice->SetOutput(NULL, FALSE);
cpVoice->SpeakStream(cpSpStream, SPF_DEFAULT, NULL);

但是,當我嘗試獲取流的緩沖區時,我僅讀取垃圾數據(緩沖區中的所有“ =”)。

IStream *pIstream;
cpSpStream->GetBaseStream(&pIstream);
STATSTG stats;
pIstream->Stat(&stats, STATFLAG_NONAME);
ULONG sSize = stats.cbSize.QuadPart;
ULONG bytesRead;
char *pBuffer = new char[sSize];
pIstream->Read(pBuffer, sSize, &bytesRead);

我究竟做錯了什么? 這讓我發瘋。 謝謝,-Francisco

在SAPI寫入流之后,流位置在末尾,因此IStream :: Read將其“讀取”輸出設置為零字節。

從流中讀取之前,請調用IStream :: Seek(zero,STREAM_SEEK_SET,NULL),您將能夠讀取數據。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM