Linux下声卡的驱动
在具有单线输出的基本嵌入式系统扬声器上,在给定周期内将输出摆动为 0 或 1 会产生声音。
我想在现代 Linux 桌面上做类似的事情。对 Portaudio、OpenAL 和 ALSA 的简要观察表明,大多数人都在相当高的水平上做事。没关系,但不是我要找的。
(我以前从未在 Linux 上使用过声音,所以如果有教程存在,我很乐意看到它)。
On a basic embedded systems speaker with a single line of output, wiggling the output as 0 or 1 in a for given periods produces sound.
I'd like to do something similar on a modern Linux desktop. A brief look-see of Portaudio, OpenAL, and ALSA suggests to me that most people do things at a considerable higher level. That's ok, but not what I'm looking for.
(I've never worked with sounds on Linux before, so if a tutorial exists, I'd love to see it).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
事实上,它……有点像。虽然您可以自己生成波形,但您仍然需要使用 API 将其排队并将其发送到音频硬件;甚至不再存在直接调整音频线的合理方法。另外,您还可以免费获得跨平台兼容性。
Actually, it... kinda is. While you can generate the waveform yourself, you still need to use an API to queue it and send it to the audio hardware; there no longer even exists a sane way to twiddle the audio line directly. Plus you get cross-platform compatibility for free.
听起来很像旧的电脑扬声器。您可能仍然可以在 Linux 内核中找到它的代码。
然后你需要 AFAIK 的驱动程序 ALSA。您可以在那里找到有关如何编写 ALSA 驱动程序的信息。使用 PWM 来产生声音。
Sounds a lot like the old PC speaker. You might still find code for it in the Linux kernel.
Then you need AFAIK a driver for ALSA. There you can find infos on how to write an ALSA driver. Use PWM to produce the sound.
由于不同公司生产了许多不同的声卡和音频接口,因此没有统一的方法来对它们进行低级访问。对于大多数声音 I/O API,您需要做的是生成 PCM 数据并将其发送给司机。这几乎是您可以达到的最低级别。
但 PCM 数据与您描述的 0-1 方法非常相似。只是你也有中间的选择。 0-1 是 1 位音频。现代声卡上可以找到 8 位、16 位、24 位音频。还有 32 位和 64 位浮点格式。但它们仍然相似。
Since there are many different sound cards and audio interfaces produced by different companies, there is no uniform way to have a low level access to them. With most sound I/O APIs what you need to do is to generate the PCM data and send that to the driver. That's pretty much the lowest level you can go.
But PCM data is very similar to the 0-1 approach you describe. It's just that you have the in-between options too. 0-1 is 1-bit audio. 8-, 16-, 24-bit audio is what you'll find on a modern sound card. There are also 32- and 64-bit float formats. But they're still similar.