Jump to content
Tuts 4 You

minifmod help, win32 api programming, thx


Recommended Posts


FSOUND_File_SetCallbacks(memopen, memclose, memread, memseek, memtell);

mod = FMUSIC_LoadSong("myMusic", NULL);

if(!mod) {

MessageBox(NULL, "Cannot init handle", "ERROR", 0);

return 0;

} else {


//if use this function, the exe will crash


return 0;

Any buddy can help me to tackle this problem? Thanks a lot.

Attachment is my source files.


Link to comment

I tested out the code..And its a strange bug....

For example....

#include <conio.h>
#include <windows.h>
#include "lib/minifmod.h"// --- import global reverb structure -- UGLY!! //
#include "lib/audio_fx.h" // VERY DIRTY HACK!!
extern "C" struct fx_reverb_info FSOUND_rev_info; // DO NOT DO THIS AT HOME KIDS!// this is if you want to replace the samples with your own (in case you have compressed them)
//void sampleloadcallback(void *buff, int lenbytes, int numbits, int instno, int sampno)
// printf("pointer = %p length = %d bits = %d instrument %d sample %d\n", buff, lenbytes, numbits, instno, sampno);
typedef struct
int length;
int pos;
void *data;
unsigned int memopen(char *name)
MEMFILE *memfile; memfile = (MEMFILE *)calloc(sizeof(MEMFILE),1); HRSRC rec;
HGLOBAL handle; rec = FindResource(GetModuleHandle(NULL), "MOD", RT_RCDATA);
handle = LoadResource(NULL, rec); memfile->data = LockResource(handle);
memfile->length = SizeofResource(NULL, rec);
memfile->pos = 0;
return (unsigned int)memfile;
}void memclose(unsigned int handle)
MEMFILE *memfile = (MEMFILE *)handle; free(memfile);
}int memread(void *buffer, int size, unsigned int handle)
MEMFILE *memfile = (MEMFILE *)handle; if (memfile->pos + size >= memfile->length)
size = memfile->length - memfile->pos; memcpy(buffer, (char *)memfile->data+memfile->pos, size);
memfile->pos += size; return size;
}void memseek(unsigned int handle, int pos, signed char mode)
MEMFILE *memfile = (MEMFILE *)handle; if (mode == SEEK_SET)
memfile->pos = pos;
else if (mode == SEEK_CUR)
memfile->pos += pos;
else if (mode == SEEK_END)
memfile->pos = memfile->length + pos; if (memfile->pos > memfile->length)
memfile->pos = memfile->length;
}int memtell(unsigned int handle)
MEMFILE *memfile = (MEMFILE *)handle; return memfile->pos;
void songcallback(FMUSIC_MODULE *mod, unsigned char param)
printf("order = %d, row = %d \r", FMUSIC_GetOrder(mod), FMUSIC_GetRow(mod));
void main(int argc, char *argv[])
FSOUND_File_SetCallbacks(memopen, memclose, memread, memseek, memtell);// if (argc < 2)
// {
// printf("-------------------------------------------------------------\n");
// printf("MINIFMOD example XM player.\n");
// printf("Copyright (c) Firelight Technologies, 2000-2004.\n");
// printf("-------------------------------------------------------------\n");
// printf("Syntax: simplest infile.xm\n\n");
// return;
// } printf("-------------------------\n");
printf(" XM Player with reverb\n");
printf(" Based on MINIFMOD\n\n");
printf(" Reverb code by\n");
printf(" TRC / Weird Magic\n");
// ================================================================================
// ================================================================================
mod = FMUSIC_LoadSong(NULL, NULL); //sampleloadcallback);
if (!mod)
// printf("Error loading song\n");
} FSOUND_rev_info.wet_mul = 0.15f;
FSOUND_rev_info.dry_mul = 0.9f; // ================================================================================
// ================================================================================
FMUSIC_PlaySong(mod);// printf("Press any key to quit\n");
// printf("=========================================================================\n");
// printf("Playing song...\n"); printf("Press ESCAPE key to quit\n");
printf("Press 1 to enable the reverb\n");
printf("Press 2 to disable the reverb\n");
printf("Reverb is ON \r");
char key = 0;
bool rev_on = true;
int ord = 0, row = 0;
float mytime = 0;
if (kbhit())
key = getch();
} if (key=='1')
printf("Reverb is ON \r");
FSOUND_rev_info.wet_mul = 0.15f;
FSOUND_rev_info.dry_mul = 0.9f;
else if (key=='2')
printf("Reverb is OFF\r");
FSOUND_rev_info.wet_mul = 0.0f;
FSOUND_rev_info.dry_mul = 1.0f;
else if (key=='3')
{ } ord = FMUSIC_GetOrder(mod);
row = FMUSIC_GetRow(mod);
mytime = (float)FMUSIC_GetTime(mod) / 1000.0f; //printf("ord %2d row %2d seconds %5.02f %s \r", ord, row, mytime, (row % 8 ? " " : "TICK"));
} while (key != 27);
} FMUSIC_FreeSong(mod);}

works great...Yet your code messes up...


That said, use BASS/BASSMOD or UFMOD. BASS has code samples of how to load files from resources, and it can be easily adapted for music (works great in my own code). OR uFMOD has native support for loading from resources. All you do is give it a resource handle and it does the rest.

BTW, thanks for the code HVC! ^_^ Looks really cool, and plus, I needed a decent XM to inc convertor....

Edited by mudlord
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...