2

I would like to output an audio stream (asynchronously) in C++.

I have already looked here,here, and here but it is obsolete and the link is broken.

I am sure this is a simple task, yet I can't find anywhere on the web to do it. I prefer something neat and tidy, STL oriented (e.g. device I can write to like I am writing to the screeen?). As I am using VC2013, I can use windows precompiled headers but prefer to avoid it.

Thanks,

UPDATE:

I was trying to stay close to STL, but by the look of it, I can't, so I'll stick with windows API. PlaySound is inappropriate because my data is not on file, it is in a buffer in he memory. I have tried using waveOutWrite but I would like to play two sound sequentially, i.e at t=0 start a sound for 2 sec, and at t=1 start a sound for 3 sec (overlap)

Community
  • 1
  • 1
Mercury
  • 1,886
  • 5
  • 25
  • 44
  • 2
    Audio output is simple task? Did I miss something in this year? Here is no any standartized way so it can't be `simple task`. Also what is wrong with links you've posted? I see you are using windows environment so why not to use directx api, `PlaySound`, etc? – VP. Dec 16 '14 at 13:35
  • 3
    First of all, no you can't do it like you "writing to the screen" because audio is not part of C++, it's something platform dependent and you have to use platform specific functions to make it work. Secondly, what have you tried yourself? How did that work (or not work)? And precompiled headers have nothing to do with it, it's just a way to speed up compilation. – Some programmer dude Dec 16 '14 at 13:41
  • use sndPlaySound (or PlaySound) – Fl0 Dec 16 '14 at 14:19
  • https://miniaud.io is great for this stuff. – sammonius Aug 01 '22 at 17:40

2 Answers2

1

There are many different ways to output audio, and I can't list them all here.

Since you are using Windows, you can use the MS APIs like Core Audio or DirectSound.

You can also use a cross platform API like FMOD Ex.

Either way, outputting audio is not hard, but it isn't really trivial ; you should expect ~10 API calls for a decent working audio stream example.

ElderBug
  • 5,926
  • 16
  • 25
1

Under Windows you can use WSAPI.

Here are working WSAPI examples:

http://msdn.microsoft.com/en-us/library/windows/desktop/dd316756%28v=vs.85%29.aspx

Under Linux you can use alsa, pulseaudio etc.

gj13
  • 1,314
  • 9
  • 23