twkmz
twkmz

Reputation: 449

How to load ogg file in c?

I'm learning about audio with openal and trying to load ogg files into memory so I can play them with openal. I have been searching for a library to load ogg files and the best one I found was this one, it has no dependences. But the documentation is messy and I can't find a decent tutorial-example online. All I want to know is how to load an ogg and get something that I can actually send to a openal buffer.

Q: If I have this call:

stb_vorbis_decode_filename(const char *filename, int *channels, int *sample_rate, short **output);

it should decode "filename" and store the data into "output". So I can send it to openal right? It's not lack of research, after hours of reading I can't really get how it works. If there's another library to load ogg files easily then please let me know.

Thanks!

Upvotes: 2

Views: 2804

Answers (1)

John Hascall
John Hascall

Reputation: 9416

Have you tried it? What results/error did you get? Perhaps something like this:

int channels;
int sample_rate;
short * output;
int rc = stb_vorbis_decode_filename("somefile.ogg", &channels, &sample_rate, &output);
if (rc == -1) fprintf(stderr, "oops\n");

Upvotes: 1

Related Questions