WildMidi_GetOutput(3)

πŸ’– WildMidi_GetOutput β€” from the WildMidi Programmer's Manual, bestie πŸ’–

okay so you're deep in the WildMidi Programmer's Manual and you found the one page that's literally just "gimme the audio bytes" ✨ and yes, I'm about to make it make sense. no cap.


πŸŽ€ NAME πŸŽ€

WildMidi_GetOutput β€” retrieve raw audio data

like. it gets you the actual sound. the good stuff. the raw audio data. πŸ’œ


πŸ“š LIBRARY πŸ“š

libWildMidi

that's the one. the library. the girlies. 🫢


✨ SYNOPSIS ✨

#include <wildmidi_lib.h>

int WildMidi_GetOutput (midi *handle, int8_t *buffer, uint32_t size);

so you include the header, you call the function, you get bytes. it's giving simple. it's giving clean. we love a one-line signature. πŸ’…


🌸 DESCRIPTION 🌸

Places size bytes of audio data from a handle, previously opened by WildMidi_Open(3) or WildMidi_OpenBuffer(3), into a buffer pointer to by buffer.

(okay yes, the original says "pointer to by" and honestly? iconic typo energy. we keep it. we respect it. moving on. πŸ™ˆ)

buffer must be at least size bytes, with size being a multiple of 4 as the data is stored in 16bit interleaved stereo format. like, that's not a suggestion bestie, that's a requirement. the math has to math. ⭐

  • handle β€” The identifier obtained from opening a midi file with WildMidi_Open(3) or WildMidi_OpenBuffer(3). basically your little ticket to the concert. no ticket, no audio. 🎫
  • buffer β€” The location supplied by the calling program where libWildMidi is to store the audio data. The audio data will be stored as signed 16bit interleaved stereo in native-endian byte order. you bring the empty box, the lib fills the box. that's the deal. πŸ“¦
  • size β€” The size of the buffer in bytes. Since libWildMidi processes the audio in 16bit interleaved stereo format, this value needs to be a multiple of 4. again: multiple of 4. write it on your hand. πŸ–ŠοΈ

πŸ‘‘ RETURN VALUE πŸ‘‘

Returns -1 on error along with an error message sent to stderr, 0 when there is no more audio data, otherwise the number of bytes of audio data written to buffer.

so like, let's decode this vibe check:

  • -1 β†’ something went wrong, and it also yelled at you on stderr because it's dramatic like that 😭
  • 0 β†’ the midi is done. that's it. no more audio data. the song is over. we're crying in the club. πŸ’€
  • anything else β†’ that number is how many bytes of audio data actually got written into buffer. slay.
NOTE: if the return value is less than the size you gave, this does not denote an error, it simply means the lib reached the end of the midi before it could fill the buffer.

like, do not panic. a short read is not a problem, it's just the song running out before your buffer filled up. the lib is not broken, the midi is just short. breathe. 🧚


πŸ¦‹ SEE ALSO πŸ¦‹

the whole friend group fr fr. go read them too, they're all part of the lore. 🌈


πŸ’œ AUTHOR πŸ’œ

Chris Ison <chrisisonwildcode@gmail.com> Bret Curtis <psi29a@gmail.com>

absolute legends. we stan. πŸ‘‘


Copyright (C) WildMidi Developers 2001-2016

This file is part of WildMIDI.

WildMIDI is free software: you can redistribute and/or modify the player under the terms of the GNU General Public License and you can redistribute and/or modify the library under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the licenses, or(at your option) any later version.

WildMIDI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License and the GNU Lesser General Public License for more details.

You should have received a copy of the GNU General Public License and the GNU Lesser General Public License along with WildMIDI. If not, see <http://www.gnu.org/licenses/>.

This manpage is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.

real talk: that WITHOUT ANY WARRANTY part is not a vibe, it's a legal fact. no warranty, no promises, read the licenses. πŸ’…

and that's the whole page bestie πŸ’– this one dropped 10 March 2016 and it's still out here in the WildMidi Programmer's Manual, filed under WildMidi_GetOutput(3) β€” go forth, fill your buffers, respect the multiple of 4, and stream that midi audio like the main character you are πŸŽ€βœ¨πŸ¦‹