如何实现实时录音并通过XAudio2播放音频?

spacefly7 2018-03-20 11:23:32
最近在做一个音频处理的程序,想在WINDOWS下实现实时采集麦克的声音,并通过XAudio2播放出来。整体思路是:声音先后录入2个缓存——用XAudio2中的SubmitSourceBuffer(&buffer)轮流读取缓存信息之后播放。

其中声音采集的部分有几个思路,不知道哪一个更好一些,请大家支招。
方法一:用waveIn实现采集,
方法二:用directsound采集,听说高版本的windows不能用了,不知道还行不行。
方法三:用DirectX中的CWaveFile实现录音采集。个人理解,这个类主要作用是将声音写入wave文件,如果不保存声音直接播放的话应该用不着它。
不知道我想的对不对,或者有没有其他更好的方法,恳请各位大牛不吝赐教!谢谢
...全文
2166 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
donjin9 2018-03-21
  • 打赏
  • 举报
回复
用了wavein,为啥不用waveout呢? win10不能用directsound吗?没试过。
spacefly7 2018-03-21
  • 打赏
  • 举报
回复
在这里https://www.codeproject.com/Articles/460145/Recording-and-playing-PCM-audio-on-Windows-VB我找到了这么一段话: MediaElement - All the UI frameworks have a MediaElement control - XAML for Windows 8, WPF, Silverlight, WinForms. They let you play audio and video. But they don't have an interface for recording, and they don't let you send your own raw audio data. (The best you can do is build a WAV file and tell them to play it). waveOut and waveIn - These legacy APIs used to be the simplest and easiest libraries to use from .NET, for recording and playing raw audio. Unfortunately they're not allowed in Windows app-store apps. WASAPI (Windows Audio Session API) - Introduced in Vista, this C++/COM API is the new recommended way to record and play audio. xAudio2 - This is a low-level C++/COM API for audio, aimed at game developers, and allowed in Windows app-store apps. It is the successor to DirectSound.
赵4老师 2018-03-20
  • 打赏
  • 举报
回复
http://www.codeproject.com搜“audio record”?

5,530

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 模式及实现
社区管理员
  • 模式及实现社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧