miniorg is a tiny ANSI C library for reading and decoding Organya music (.org files).
Organya is a sequenced music format created in 1999 by Studio Pixel and used in games such as Cave Story, Azarashi (2001 version), STARGAZER, and more.
The library does not use floating point arithmetic, or allocate any memory. In fact, it does not use libc at all,
and can be cleanly compiled with -std=c89 -Wall -Wextra -Wpedantic -Werror -nostdlib.
To use this library, just #include "miniorg.h" in your project. Define MINIORG_IMPLEMENTATION before including the
header in one .c file to create the implementation.
#define MINIORG_IMPLEMENTATION
#include "miniorg.h"
int main(void)
{
// Create the context. soundbank_data must not be freed as it will be used as long as the context is
miniorg_context ctx;
if (miniorg_init(&ctx, soundbank_data, sizeof(soundbank_data), 44100) != MINIORG_RESULT_SUCCESS)
{
// Handle the error here
return 1;
}
// song_data must not be freed as it will be used as long as the context is, or until another song is loaded
if (miniorg_read(&ctx, song_data, sizeof(song_data)) != MINIORG_RESULT_SUCCESS)
{
// Handle the error here
return 1;
}
// Generate samples (which would then be output to an audio player, or a .wav file, or etc.)
// The size of output_buffer should be a multiple of 4 (sizeof(int16) * 2).
miniorg_render(&ctx, (miniorg_int16 *)output_buffer, sizeof(output_buffer));
// You do not have to deinitialize the context, however...
// If you allocated soundbank_data or song_data dynamically, you should free those once you are done using the context.
return 0;
}There are some extra preprocessor definitions you can define to change the functionality of the library:
- Define
MINIORG_NO_INTERPOLATIONto disable interpolation in the sound mixer (faster, but results in worse sound quality). - Define
MINIORG_NO_VOLUME_RAMPto disable ramping for volume changes (faster, but results in a popping noise when volume changes). - Define
MINIORG_USE_STDINTto usestdint.hfor the integer types. This is recommended if your compiler/environment supports it.
You must make sure the definitions are consistent each time the library is #included.
It is recommended to define them in your compiler flags (as in -DMINIORG_...).