Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best API for low-level audio in Windows?

I'm working on an audio application, written in C. I need to provide live audio playback under Windows. I need to decide which audio API to use. I'm planning to use the basic waveOut API, but I wanted to check to see what the community here recommends.

I want code that will Just Work on any recent version of Windows, with no need to install libraries; and I want minimal latency.

I don't need or want any "effects", I just need to faithfully play whatever wave samples the application generates.

My understanding is that most of the professional audio applications on Windows use ASIO, which gives excellent low latency, but I don't want ASIO because I want my code to Just Work and most people don't have ASIO pre-installed on their computers. (At a later date I may go back and also add ASIO as an option, but I'm going for the most general solution first.)

Is there anything out there that would be better than waveOut for my purposes, or is that the best choice?

like image 992
steveha Avatar asked Jan 06 '10 01:01

steveha


People also ask

What is my sound API?

The Sound API provides functions to control the volume level for several sound types and to check whether a specified sound device type is connected. You can get the maximum volume level for system, notifications, alarm, media and so on. Also, you can change or get the current volume level.

How do I reduce the audio buffer size in Windows 10?

Choose Edit > Device Setup to open the Device Setup dialog. In the Device Setup dialog, select the audio device whose buffer size you want to change from the ASIO Driver menu. Click Device Control Panel to open the device settings dialog for the selected audio device.


2 Answers

It depends on what you are trying to do. The basic waveOut audio API is better for streaming audio. It lets you queue up several buffers and have them automatically played in succession. But if audio is playing and you want to change it, or add something to it, that's relatively hard.

DirectX audio is better for event based audio. You can have several things playing at the same time without having to do the mixing yourself. You can add or remove little pieces of audio easily - like playing a sound when the user pulls the trigger on their gun. But streaming (i.e. playing 1 buffer after another) is harder.

waveOut is designed to facilitate playing audio that is constant, like a .mp3 file. DirectX is designed for audio that is intermittent, like feedback in a game.

ASIO is like the worst of waveOut and DirectX in terms of difficulty of programming, and it's not that stable. Applications typically can't share the audio device. However, it gives you the lowest latency access to that audio hardware. ASIO also gives you a way to synchronize playback on multiple devices.

If you don't need to be able to change what is going to be played right before it is played, and you don't need to synchronize multiple devices, then you don't need ASIO.

like image 101
John Knoeller Avatar answered Oct 12 '22 01:10

John Knoeller


At the time I asked this question, I wrote streaming code using the waveOut and waveIn APIs. Since then, I have discovered a useful library:

PortAudio http://www.portaudio.com/

PortAudio is free software with a commercial-friendly license. If you write your code to call PortAudio it should be able to work with waveOut devices but also with ASIO devices under Windows; it can be then recompiled for Linux and should work with ALSA devices; and it can then be recompiled for the Mac and should work with CoreAudio devices. I haven't tested the Mac part but my project is working great with Windows and Linux.

like image 42
steveha Avatar answered Oct 12 '22 02:10

steveha