开发者

Driving the sound card in Linux

开发者 https://www.devze.com 2023-04-13 09:07 出处:网络
On a basic embedded systems 开发者_如何学Cspeaker with a single line of output, wiggling the output as 0 or 1 in a for given periods produces sound.

On a basic embedded systems 开发者_如何学Cspeaker 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).


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.


[...] embedded systems speaker with a single line of output, wiggling the output as 0 or 1 in a for given periods produces sound.

Sounds a lot like the old PC speaker. You might still find code for it in the Linux kernel.

I'd like to do something similar on a modern Linux desktop.

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号