在 Windows 上使用 C 将数据流式传输到声卡
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6144543/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Streaming Data to Sound Card Using C on Windows
提问by sheepez
As part of a university project I have to do some signal processing and would like to output the results using the PC sound card. The software has to be written in C and needs to work with Windows (preferably 7 and XP).
作为大学项目的一部分,我必须进行一些信号处理,并希望使用 PC 声卡输出结果。该软件必须用 C 编写,并且需要与 Windows(最好是 7 和 XP)一起使用。
I have found code examples for outputting .wav and similar files, but I am interested in continuously outputting data rather than outputting from files. It is likely that the data for output will be presented as an array although some sound APIs seem to have their own ways of dealing with buffers.
我找到了输出 .wav 和类似文件的代码示例,但我对连续输出数据而不是从文件输出感兴趣。尽管一些声音 API 似乎有自己的处理缓冲区的方式,但输出数据可能会以数组的形式呈现。
Any suggestions would be great, as would code examples or even the best API. I have looked at DirectSound and OpenAL but am still unsure how to get started.
任何建议都会很棒,代码示例甚至最好的 API 也是如此。我看过 DirectSound 和 OpenAL,但仍然不确定如何开始。
回答by Judge Maygarden
PortAudiois a C library that should suit your needs. There is a tutorialto get you started.
PortAudio是一个 C 库,应该可以满足您的需求。有一个教程可以帮助您入门。
PortAudio is a free, cross-platform, open-source, audio I/O library. It lets you write simple audio programs in 'C' or C++ that will compile and run on many platforms including Windows, Macintosh OS X, and Unix (OSS/ALSA). It is intended to promote the exchange of audio software between developers on different platforms. Many applications use PortAudio for Audio I/O.
PortAudio provides a very simple API for recording and/or playing sound using a simple callback function or a blocking read/write interface. Example programs are included that play sine waves, process audio input (guitar fuzz), record and playback audio, list available audio devices, etc.
PortAudio 是一个免费、跨平台、开源的音频 I/O 库。它让您可以用“C”或 C++ 编写简单的音频程序,这些程序将在许多平台上编译和运行,包括 Windows、Macintosh OS X 和 Unix (OSS/ALSA)。旨在促进不同平台开发者之间的音频软件交流。许多应用程序使用 PortAudio 进行音频 I/O。
PortAudio 提供了一个非常简单的 API,用于使用简单的回调函数或阻塞读/写接口来录制和/或播放声音。包括播放正弦波、处理音频输入(吉他模糊)、录制和播放音频、列出可用音频设备等的示例程序。
回答by rogerdpack
https://github.com/rdp/directshow-demo-audio-input-open-sourcemight help, if you want to use directshow.
如果您想使用 directshow,https://github.com/rdp/directshow-demo-audio-input-open-source可能会有所帮助。