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

Read raw char data array from header #678

Closed rossmarinaro closed 1 year ago

rossmarinaro commented 1 year ago

Very simple question - Is it possible to read audio as a raw char array defined in a header? With opengl, I can create a 2d texture with the data as mentioned. There's online converters which can take any file and make it into a C array. Can I do the same with this library?

mackron commented 1 year ago

Yes, this is possible. If it's the raw contents of the entire file (as in the entire WAV, MP3, etc.) and not just the raw PCM audio data, use ma_decoder_init_memory(). If it's just raw PCM audio data, use ma_audio_buffer (https://miniaud.io/docs/manual/#AudioBuffers). If you're using ma_sound for playback, initialize your sound with ma_sound_init_from_data_source(), passing in your ma_decoder or ma_audio_buffer you initialized earlier (they are both data sources which means they can be plugged into any function that takes a ma_data_source*).