mackron / miniaudio

Audio playback and capture library written in C, in a single source file.
https://miniaud.io
Other
4.07k stars 361 forks source link

Adding Vorbis in split version #751

Closed blazer2k1 closed 1 year ago

blazer2k1 commented 1 year ago

For some reason, the program just exits when using the split version with stb_vorbis.c and playing ogg files.

I have no problems running it with the default single header and the latest version.

Using MinGW GCC Win10.

mackron commented 1 year ago

The way stb_vorbis is used by miniaudio makes it awkward to use with the split version. The header section of stb_vorbis needs to be visible to the implementation section of miniaudio, which in the split version is the .c file. It's not as simple as just including stb_vorbis.c in the .c file in your project.

I have been discouraging the use of stb_vorbis and instead encouraging people to use the libvorbis decoder instead: https://github.com/mackron/miniaudio/blob/master/extras/miniaudio_libvorbis.h

blazer2k1 commented 1 year ago

Ok will try this, thanks.

I'm assuming this header is now w/o the #define #undefine like in stb vorbis c.

mackron commented 1 year ago

I had forgotten that the libvorbis thing I linked to earlier has also been designed around the single file version of miniaudio.h. If you were wanting to use it, you would need to include the header section just after miniaudio.h, like this:

#include "miniaudio.h"
#include "miniaudio_libvorbis.h"

And then in one source file, you would have to do something like this:

#include "miniaudio.h"

#include MINIAUDIO_IMPLEMENTATION
#include "miniaudio_libvorbis.h"

But honestly, it might even be easier to just take miniaudio_libvorbis.h and just split it out manually into separate .h and .c files and use it like a normal source code pair. Just make sure both files include "miniaudio.h" at the top.

blazer2k1 commented 1 year ago

Aside from the setup, are there any differences?

I find the stb vorbis version easier to include when not using split, except with the longer gcc compile time.