How to output multiple sounds with SDL? - c++

I have a library to decode some audio data into PCM and it works fine with Alsa.
I chose SDL to abstract the audio output because SDL is platform-independent. I rewrote it to use SDL to output the audio and it works. However, I want to output multiple sounds simultaneously and SDL only supports one sound per time.
What should I do?
I can use other audio library if it is free, lightweight and supports Linux, Windows XP and Android 2.3.
EDIT: Instead of decoding the entire audio data and filling the audio buffer, I have to fill the buffer partially on each iteration. Loops or callback functions are the solution to fill the next audio frame to play.

SDL_Mixer is the way to go if you're using SDL. It can play multiple sounds at a time, although only one music.
You can download SDL_Mixer, and get documentation, at http://www.libsdl.org/projects/SDL_mixer/ (or google SDL_Mixer).

Related

use IXAudio2 to play sound mix?

I write a MFC project . I use IXAudio2 to play wav file.
my code is like this :
pSourceVoice->SubmitSourceBuffer( &buffer );
hr = pSourceVoice->Start( 0 );
but in this way I only can play one sound by a time. It must wait this .wav file play over. I can play the second file. How can I play the file I need and not wait for the first one is over, likes mixing sounds?
How can I achieve this function?
You create one IXAudio2SourceVoice for each 'playing, active' sound you want at a time. Typically games will create a few hundred source voices to manage--beyond that the sound mix is typically too muddy to hear anyhow.
Game audio engines have a mix of 'one-shot' voices that just play-on-demand until they complete--at which point that frees up that source voice for use by another one-shot sound--, 'ambients' or 'music' voices that are manipulated as they play, and 3D audio positioned sounds which have to be updated every rendering frame to track the 3D rendering object they are emitted from.
If you submit the same audio data to two distinct IXAudio2SourceVoice instances, then you'll hear it being played twice, mixed together in real-time. Typically you won't start them at precisely the same instant because the result is just a louder version of the one sound. Normally they are started at different times so you get overlapped playback.
See XAudio2 Programming Guide, GitHub, and DirectX Tool Kit for Audio.

Rendering to video file by SFML

I have written a program using SFML Library (in C++) rendering simple 2D animation.
I would like to save the animation to a video file instead of drawing it on the screen.
Does SFML provide such functionality? Is there any other, portable way to do this? (portable between different OSes)
SFML does not have such a feature, especially since video processing is a whole world of its own. You can take a look at FFmpeg and GStreamer. Both libraries are cross-platform and should be able to record, playback and stream videos. If you want a specific codec, you could directly look at the codec's website and/or search for good encoder.
Overall it's not an easy task and depending on what you're trying to do, you could also think about grabbing the rendering directly with an third-party application, e.g. Open Broadcaster Software or (again) FFmpeg.

Best way to load in a video and to grab images using c++

I am looking for a fast way to load in a video file and to create images from them at certain intervals ( every second, every minute, every hour, etc.).
I tried using DirectShow, but it just ran too slow for me to start the video file and move to a certain location to get data and to save it out to an image. Even if I disabled the reference clock. Tried OpenCV, but it has trouble opening the AVI file unless I know the exact codec information. So if I know a way to get the codec information out from OpenCV I may give it another shot. I tried to use FFMPEG, but I don't have as much control over it as well as I would wish.
Any advice would be greatly appreciated. This is being developed on a Windows box since it has to be hosted on a Windows box.
MPEG-4 format is not an intra-coded format, so you can't just jump to a random frame and decode it on its own, as most frames only encode the differences from one or more other frames. I suspect your decoding is slow because when you land on a frame for which several other dependent frames to be decoded first.
One way to improve performance would be to determine which frames are keyframes (or sometimes also called 'sync' points) and limit your decoding to those frames, since these can be decoded on their own.
I'm not very familiar with DirectShow capabilities, but I would expect it has some API to expose sync points.
Also, I should mention that the QuickTime SDK on Windows is possibly another good option that you have for decoding frames from movies. You should first test that your AVI movies are played correctly in the QuickTime Player. And the QT SDK does expose sync points, see the section Finding Interesting Times in the QT SDK documentation.
ffmpeg's libavformat might work for ya...

edit frames from a video source before render c++

I need you to recommend me a library for c++ to use with visual c++ 2008 to perform an edition ef the frames from a video source before been rendered on the screen. I dont want to perform effects like blur or things like that, I want to change the size en some cases and other stuff.
I have tried with phonon (where I cant access the frames) and opencv (where I can get the frames but I cant display the audio because the library is for other purpose), I have been reading about directshow on windows but I still dont know if I can recover the frame.
Regards, Marco.
Try ffmpeg. It's what OpenCV uses to read frames.
FFMPEG includes a simple player -- ffplay. Have a look at its source for an idea of how to use the library.
As misha said FFMPEG is THE library for videoacquisition. As you use C++, you can try the simpler to use FOBS, which is a C++ encapsulation of FFMPEG. You can look at the sources if you want to do your own C++ wrap around FFMPEG.
my2c

Displaying a video in DirectX

What is the best/easiest way to display a video (with sound!) in an application using XAudio2 and Direct3D9/10?
At the very least it needs to be able to stream potentially larger videos, and take care of the fact that the windows aspect ratio may differ from the videos (eg by adding letter boxes), although ideally Id like the ability to embed the video into a 3D scene.
I could of course work out a way to load each frame into a texture, discarding/reusing the textures once rendered, and playing the audio separately through XAudio2, however as well as writing a loader for at least one format, ive also got to deal with stuff like synchronising the video and audio components, so hopefully there is an eaier solution available or even a ready made free one with a suitable lisence (commercial distribution in binary form, dynamic linking is fine in the case of say LGPL).
In Windows SDK, there is a DirectShow example for rendering video to texture. It handles audio output too.
But there are limitations and I can't honestly call it easy.
Have you looked at Bink video? Its what lots of games use for video playback. Works great and you don't have to code all that video stuff yourself from scratch.