Sound processing: Should I use DirectSound or directly Win32 APIs?

10,016

Solution 1

The Directsound API's give you better realtime control. They are also the supported way to use sound in Windows. I was under the impression that the win32 api's were depracated, but I could be wrong on this.

This question is close to yours

https://stackoverflow.com/questions/314522/what-is-the-best-c-sound-api-for-windows

also

Is DirectSound the best audio abstraction layer for Windows?

last but not least, this is what microsoft has to say http://msdn.microsoft.com/en-us/library/dd370784(VS.85).aspx

Solution 2

Neither? :)

The story is that DirectSound is the replacement for waveOut, but DirectSound joined DirectInput as deprecated APIs in Vista and is replaced with WASAPI. DirectSound and waveOut are implemented on top of the User-Space WASAPI in Vista. On XP, waveOut and DirectSound feed to the same kernel level Mixer API.

To consolidate all of these interfaces take a look at something like OpenAL, it's a well supported audio standard along the same lines as OpenGL.

Solution 3

It sounds like you're going to be quite sensitive to latency. It might pay to look at ASIO

Solution 4

I found Harmony Central - Audio Programming. Also read w:DirectSound.

Windows Vista features a completely re-written audio stack based on the Universal Audio Architecture. Because of the architectural changes in the redesigned audio stack, a direct path from DirectSound to the audio drivers does not exist.

Because of Xbox 360 and Microsoft Windows integration, Microsoft is actively pushing developers to migrate new applications to equivalent Xbox audio APIs such as XAudio and XACT.

OpenAL looks promising.

Share:
10,016
recursive9
Author by

recursive9

Founder of Crystal Gears Portfolio: - www.movertrends.com - www.friendshopper.com - www.digitalshow.com - www.translatorscorner.com - www.gigpay.com

Updated on June 15, 2022

Comments

  • recursive9
    recursive9 almost 2 years

    I'm making an application where I will:

    • Record from the microphone and do some realtime processing on the input
    • Play an MP3 file (a regular song), but manipulating the output in realtime
    • Every now and then I'll need to play additional sounds over this song too, but I guess I can do that by simply adding the buffers.

    In short, I need to have circular buffers for both recording and playing, and I need to be "feeding" the output buffer every 20 ms or so with the new data that is just about to be played.

    I've been looking at DirectSound, and it doesn't seem to help a lot. The reading and writing to the output buffers seem very similar to Win32, the only place where it seems it'd help is in playing the "additional sounds" over the main song.

    Should I use DirectSound, or should I go straight to raw Windows APIs?
    Is DirectSound going to do anything for me?

    Thanks in Advance!

  • recursive9
    recursive9 over 15 years
    Ok, but if I use this WASAPI... Will my software also work on XP? Or should I have a different "legacy" codebase for XP? (in which case i'll go for the deprecated API, unless WASAPI gives me a very very good improvement over them)
  • joshperry
    joshperry over 15 years
    Yes WASAPI is Vista only. You definitely do not want to use the WinMM functions. Most pro audio apps use Kernel Streaming (WavePCI or WaveCyclic) because it works in Windows 2000/XP/Vista (with driver support), though it is more difficult to implement than something like DirectSound.
  • joshperry
    joshperry over 15 years
    I'd say use DirectSound if you want something that still works in Vista and XP but without too much headache. And I'd say Kernel Streaming if you have the capability to implement it.
  • joshperry
    joshperry over 15 years
    As you will see in the market though, most application provide an abstracted output via multiple user-selectable methods; if your application is meant to be a professional one it would probably benefit greatly from similar functionality.