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