从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);
我做错了什么?我快疯了。谢谢,旧金山
SAPI写入流后,流的位置在末尾,因此IStream::Read将其" Read "输出设置为零字节。
在从流中读取数据之前,调用IStream::Seek(zero, STREAM_SEEK_SET, NULL),您将能够读取数据
相关文章:
- 让 iaxClient 将音频发送到缓冲区而不是音频设备/从缓冲区获取音频
- 音频缓冲区列表,用于输出流格式已压缩的 AUHAL 单元
- 为什么 SDL2 为音频样本提供的缓冲区不够大
- 使用超强 SDK 从缓冲区播放音频
- 核心音频(Wasapi)缓冲区事件时机
- 使用ExtAudioFileWrite for iOS将音频样本的缓冲区写入aac文件
- 录制音频,存储在缓冲区中,然后通过PulseAudio将字节写入声卡
- 预加载音频缓冲区-什么是合理和可靠的
- Qt缓冲区不足播放RAW音频
- 如何有效地确定用于循环的预渲染正弦波音频缓冲区的最小必要大小
- 如何创建指向与 VST 音频缓冲区相同的指针数组的指针
- Qt - 如何设置音频播放从缓冲区的开头开始
- 如何刷出直接显示音频渲染器缓冲区
- 写入wav[PMC]的音频缓冲区整数会产生高噪声
- 插入耳机时音频缓冲区错误
- 我的OpenAL c++音频流缓冲区故障
- 如何处理在使用libpd时不能被64整除的音频缓冲区大小
- 是否有可能在Windows 7中抓取指向默认音频端点设备缓冲区的指针?
- Android:如何在C/ c++中获得首选(本地)音频缓冲区大小和音频采样率
- FFMPEG音频解码:从短到浮点样本缓冲区的有效转换