From: Elliott Oti Newsgroups: comp.os.msdos.djgpp Subject: Re: Using MikAllegro2.1 (doesn't play!) Date: Mon, 23 Sep 1996 10:41:28 -0700 Organization: Academic Computer Centre Utrecht, (ACCU) Lines: 208 Message-ID: <3246CBC8.925@stud.warande.ruu.nl> References: <526d5d$edv AT dfw-ixnews9 DOT ix DOT netcom DOT com> NNTP-Posting-Host: warande1078.warande.ruu.nl Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: Takahiro Horie To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Takahiro Horie wrote: > Dear Programmers, > > I created a program named PLAYSONG.C and it compiled without > any errors. BUT, when I ran the program, I got a list of all > the samples, then was kicked out of the program without even > hearing one note of the music. Can anyone help? ----------< SNIP SOURCE CODE >------------------------- > > void main(void) > { > MP_Init(mf); > md_numchn=mf->numchn+4; // what does this command do? > MD_PlayStart(); > > readkey(); // wait until user presses a key > > MD_PlayStop(); > ML_Free(mf); > ----------< SNIP SOURCE CODE >------------------------- > > Sorry about the long source code! When the program is run, it > lists all of the instruments in the s3m file, pauses, then dumps > me out into dos with all the values of the registers. :( > That's not the way MikMod works: it's not hooked up to the timer interrupt so you can't just say MD_PlayStart() and forget about things; you have to call MD_Update() within your main loop as this is the routine responsible for mixing. And your main loop has to run in 1/12 of a sec or faster or you get mixing problems. As for the dumping of s3m instruments, in the load_s3m.c file there are a couple of printf's that dump the instrument names; comment them out or mail me for a copy that's cleaned up. The other song formats don't have this problem. Below is the source code for a crappy little mod player using MikAlleg; it demonstrates most of the features of MikMod and a couple of Allegro. compile with gcc elmo.c -O2 -lalleg -lpc -o elmo.exe. It works OK. Look at it, use it, sell it, rename it, delete it, whatever. Have fun, Elliott ----------------------- FILE ELMO.C --------------------------------------- #include #include #include #include #include #include #include int _crt0_startup_flags = _CRT0_FLAG_NEARPTR; #include #include //////////////////////////////////////////////////////////////////////// void WaitRetrace(void) { while( inportb(0x3da) & 0x08 ){} while(!(inportb(0x3da) &0x08 )){} } void DoShit(UNIMOD *mf) { char str[6]; textout(screen,font,mf->songname,1,10,55); textout(screen,font,"Song Position : ",1,20,25); textout(screen,font,itoa(mp_sngpos,str,10),130,20,15); textout(screen,font,"Pat. Position : ",1,30,25); textout(screen,font,itoa(mp_patpos,str,10),130,30,15); textout(screen,font,"Song Speed :",1,40,25); textout(screen,font,itoa(mp_sngspd,str,10),130,40,15); textout(screen,font,"BPM :",1,50,25); textout(screen,font,itoa(mp_bpm,str,10),130,50,15); textout(screen,font,"Volume : ",1,60,25); textout(screen,font,itoa(mp_volume,str,10),130,60,15); if(mp_loop) textout(screen,font,"Loop On ",1,70,25); else textout(screen,font,"Loop Off",1,70,25); WaitRetrace(); rectfill(screen,1,80,319,199,55); circlefill(screen,30 + rand()%240, 110 + rand()%140, rand()%10 + 10, rand()%255); } void StopMod(UNIMOD *mf); void tickhandler(void) { MP_HandleTick(); /* play 1 tick of the module */ MD_SetBPM(mp_bpm); } int InitShit(void) { md_mixfreq =44100; /* standard mixing freq */ md_dmabufsize =10000; /* standard dma buf size */ md_mode =DMODE_16BITS|DMODE_STEREO; /* standard mixing mode */ md_device =0; /* standard device: autodetect */ ML_RegisterLoader(&load_m15); /* if you use m15load, register it as first! */ ML_RegisterLoader(&load_mod); ML_RegisterLoader(&load_mtm); ML_RegisterLoader(&load_s3m); ML_RegisterLoader(&load_stm); ML_RegisterLoader(&load_ult); ML_RegisterLoader(&load_uni); ML_RegisterLoader(&load_xm); MD_RegisterDriver(&drv_nos); MD_RegisterDriver(&drv_sb); MD_RegisterDriver(&drv_gus); MD_RegisterPlayer(tickhandler); if(!MD_Init()) { return 0; } return 1; } int PlayMod(UNIMOD *mf,char *name) { mf=ML_LoadFN(name); if(mf==NULL){ return 0; } MP_Init(mf); md_numchn=mf->numchn; MD_PlayStart(); while(!MP_Ready()) { if(keypressed()) { if(key[KEY_ESC]){ StopMod(mf);return 1; } if(key[KEY_UP]) { mp_volume += 1; if(mp_volume > 100)mp_volume = 100; } if(key[KEY_DOWN]) { mp_volume -= 1; if(mp_volume > 100)mp_volume = 0; } if(key[KEY_PGUP])MP_PrevPosition(); if(key[KEY_PGDN])MP_NextPosition(); if(key[KEY_ENTER]) { if(mp_loop == 0)mp_loop = 1; else mp_loop = 0; } } MD_Update(); DoShit(mf); } return 1; } void StopMod(UNIMOD *mf) { MD_PlayStop(); /* stop playing */ ML_Free(mf); /* and free the module */ } int QuitMod(UNIMOD *mf) { MD_Exit(); return 0; } int main(int argc,char *argv[]) { UNIMOD *mf; int c = 1; unsigned char mv = 200; char path[80]; allegro_init(); install_keyboard(); install_mouse(); install_timer(); set_gfx_mode(GFX_VGA,320,200,0,0); set_pallete(desktop_pallete); if(!InitShit()) { alert("Error Initializing","Sound Card",NULL,"OK",NULL,0,0); return 0;} while(c) { while(file_select("CHOOSE, IDIOT !!!",path,"MOD;XM;S3M;STM;MTM;UNI;M15;ULT")) { clear(screen); PlayMod(mf,path); clear(screen); } if(alert("Quit ?",NULL,NULL,"OK","Cancel",0,0) == 1)c = 0; } QuitMod(mf); return 1; }