2

There is an old code that uses SDL audio to output music. I am porting it to Qt and I want to replace SDL audio with native Qt audio API.

The flow, in simplest terms, is this:

...
// Initialization
wanted_spec.callback = sdl_audio_callback;
SDL_OpenAudio(&wanted_spec, &spec);
...

// copies raw data to audio buffer
static void sdl_audio_callback(void *opaque, Uint8 *stream, int len)

Which audio Api of Qt should I be using? There is no video involved

S B
  • 8,134
  • 10
  • 54
  • 108

2 Answers2

2

Normally you would use the higher level Phonon module, here are the API docs for it. But because you are dealing with raw samples you will need the lower level QtMultimedia module, specifically the QAudioOutput class. Docs here.

cmannett85
  • 21,725
  • 8
  • 76
  • 119
  • I have decoded audio samples that need to be sent to output device / speakers. SDL does that. However, while Phonon provides an end-to-end solution to read media files from file on network, decode and playback them, it seems it does not work with already decoded samples. I need something more low level than Phonon. – S B Aug 07 '12 at 10:55
  • @Saptarshi I've made an edit, I think this is how it's intended that you play decoded data. – cmannett85 Aug 07 '12 at 11:08
  • `MediaObject` accepts `MediaSource` in `setCurrentSource()`, not `QBuffer`. Now `MediaSource` can be a filename, url, disc or QIODevice. So I tried initializing a `MediaSource` object from QIODevice but that does not play. I think the QIODevice option is just a mechanism of providing encoded data. So have you really used this code to play raw stream or it is an educated guess? – S B Aug 07 '12 at 17:21
  • It was an educated guess, but after some more searching, I realise now that your right: Phonon is too high level. Thankfully Qt has the much lower level `QtMultimedia` module where the `QAudioOutput` class can take a buffer of raw data and you can specify it's sample rate, etc. Before pushing it out the sound device. I'll edit my answer accordingly. – cmannett85 Aug 07 '12 at 17:36
  • `QAudioOutput` seems to be the way to go. Will check it out – S B Aug 07 '12 at 17:50
1

SFML - Simple and Fast Multimedia Library

Main features:

Portable SFML compiles on standard platforms like Windows (98, 2000, XP, Vista) and Unix systems (Linux, Mac OS X). As the library grows up, support for more operating systems will be added.

Object-oriented SFML is written in C++ and provides an efficient, object-oriented design. It relies on standard patterns and idioms to provide a simple and robust framework.

Easy to use SFML aims at being easy to manipulate. Effort is put on internal code to provide the simplest public interface.

Flexible Instead of being one big API, SFML rather contains a lot of small packages, that can be chosen and combined according to the intended usage. You can use only the base package to get input and windowing, as well as the full graphics package with sprites and post-effects.

Easily integrable SFML can be used in one or more windows, and/or can be integrated in existing interface components. Integration with existing graphical user interface (GUI) libraries is easy, so that you can add SFML views into complex interfaces built with Qt, wxWidgets, MFC or whatever.

Hope this helps.

Community
  • 1
  • 1
talha2k
  • 24,937
  • 4
  • 62
  • 81