#include #include "../include.h" #include static void openmpt_callback(void *mod, unsigned char *stream, int const length) { openmpt_module_read_interleaved_float_stereo(mod, SAMPLE_RATE, length / sizeof (float) / 2, (float *) stream); } static void libopenmpt_example_logfunc( const char * message, void * userdata ); static int libopenmpt_example_errfunc( int error, void * userdata ); static void libopenmpt_example_print_error( const char * func_name, int mod_err, const char * mod_err_str ); int module_openmpt(struct blob *file, struct userdata *userdata) { int mod_err = OPENMPT_ERROR_OK; const char *mod_err_str = NULL; openmpt_module *mod = openmpt_module_create_from_memory2(file->data, file->size, &libopenmpt_example_logfunc, NULL, &libopenmpt_example_errfunc, NULL, &mod_err, &mod_err_str, NULL); if (mod == NULL) { libopenmpt_example_print_error("openmpt_module_create_from_memory2()", mod_err, mod_err_str); openmpt_free_string(mod_err_str); return 1; } openmpt_module_set_repeat_count(mod, -1); userdata->callback = openmpt_callback; userdata->user = mod; userdata->freefunc = (void (*)(void *)) openmpt_module_destroy; return 0; } // copy pasted static void libopenmpt_example_logfunc( const char * message, void * userdata ) { (void)userdata; if ( message ) { fprintf( stderr, "openmpt: %s\n", message ); } } static int libopenmpt_example_errfunc( int error, void * userdata ) { (void)userdata; (void)error; return OPENMPT_ERROR_FUNC_RESULT_DEFAULT & ~OPENMPT_ERROR_FUNC_RESULT_LOG; } static void libopenmpt_example_print_error( const char * func_name, int mod_err, const char * mod_err_str ) { if ( !func_name ) { func_name = "unknown function"; } if ( mod_err == OPENMPT_ERROR_OUT_OF_MEMORY ) { mod_err_str = openmpt_error_string( mod_err ); if ( !mod_err_str ) { fprintf( stderr, "Error: %s\n", "OPENMPT_ERROR_OUT_OF_MEMORY" ); } else { fprintf( stderr, "Error: %s\n", mod_err_str ); openmpt_free_string( mod_err_str ); mod_err_str = NULL; } } else { if ( !mod_err_str ) { mod_err_str = openmpt_error_string( mod_err ); if ( !mod_err_str ) { fprintf( stderr, "Error: %s failed.\n", func_name ); } else { fprintf( stderr, "Error: %s failed: %s\n", func_name, mod_err_str ); } openmpt_free_string( mod_err_str ); mod_err_str = NULL; } fprintf( stderr, "Error: %s failed: %s\n", func_name, mod_err_str ); } }