1
我基本上試圖將音頻流的內容讀入char *緩衝區以應用FFT。 我正在使用SAPI來簡化應用我的FFT後需要做的轉換。從一個IStream讀取到一個緩衝區(音頻)
我有我的HGLOBAL分配
// 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內容的IStream的緩衝區:
// Speak the modified stream.
cpVoice->SetOutput(NULL, FALSE);
cpVoice->SpeakStream(cpSpStream, SPF_DEFAULT, NULL);
但是,當我嘗試獲取流的緩衝區時,我只讀ga垃圾數據(全部'='在緩衝區中)。
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