Jump to content
Tuts 4 You

minifmod help, win32 api programming, thx


alaphate

Recommended Posts

Posted
case WM_CREATE:

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 {

//FMUSIC_PlaySong(mod);

//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.

o10.zip

Posted

Yo!

Gimme a lil time bro and I'll debug this.

I'm glad there's more C/C++ coders around... :D

Posted (edited)

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;
} MEMFILE;
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));
}
*//*
[
[DESCRIPTION] [PARAMETERS] [RETURN_VALUE] [REMARKS] [SEE_ALSO]
]
*/
void main(int argc, char *argv[])
{
FMUSIC_MODULE *mod;
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");
printf("-------------------------\n\n\n");
// ================================================================================
==========
// LOAD SONG
// ================================================================================
==========
mod = FMUSIC_LoadSong(NULL, NULL); //sampleloadcallback);
if (!mod)
{
// printf("Error loading song\n");
return;
} FSOUND_rev_info.wet_mul = 0.15f;
FSOUND_rev_info.dry_mul = 0.9f; // ================================================================================
==========
// PLAY SONG
// ================================================================================
==========
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;
do
{
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;
fflush(stdout);
}
else if (key=='2')
{
printf("Reverb is OFF\r");
FSOUND_rev_info.wet_mul = 0.0f;
FSOUND_rev_info.dry_mul = 1.0f;
fflush(stdout);
}
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"));
Sleep(100);
} while (key != 27);
} FMUSIC_FreeSong(mod);}

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

Odd.

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
Posted

thx a lot, I'll try it. :)

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...