How to play XM Music From your own code

Over View
=========

Heya all,
the perefect way to play XM music is by using the MiniFmod.
since it is free to use, we can producereally cool keygens.
i'v choosed keygens as the perfect taregt to play music on,
as we all know its cool in the end.

allright, lets begine.
first we will deal with the music.
The best way to find our XM music is the mod archive located at:
http://www.modarchive.com/
it is a huge archive, and allot of cool music can be found there,
so just before coding, select ur file (recomended size : 2k-30k)
i especially like the "Hybrid Song.XM", (i first heard it in a installer
of Worms :-) ) or "trainer.XM", but i am sure there are millions of them out there.

once we choose our music, we need to dump its content!!
now, sicne this article is for Visual C++ coders, our dump
is apparently C++ style hex.
for the dumping rutine we will use Thigo's exccelent Table Extractor,
located at protools/anticrack..or just google for it.

Duming Table
============

/* Dumping Hybrid Song.XM (51k) */

Load your XM file in Thigo's Table extractor,
now we need to supply few info to the program:
Address (HEX): 0
Items: Bytes
Size (Bytes) of Table(Hex): CCD4 /* File Size */
Number Of Items on a Line: 20    /* put how many you like personally i put 20 */
C/C++                            /* Dump Style Language  */
Dump to file: checked            /* [v] */

ok, we dont need anymore options filled,
Press the "Go !" button and we see our thread make an effort to dump 
the Image as fast as possible ;-),
0....100%, great Table dumped in result.txt (same dir as the XM file).

Coder Point of View
===================

look at the dumped results.txt..geesh, it is very big..(300k)
yes, thats the coast of files that have 20++k and above!, 
so keep in mind that since your making a keygen, the file should be 
as minimal as possible, but consider the best sound u can get :-)
save this file somewhere, we need to use some source code from now on.

The MiniFmod
============

information about MiniFmod 1.6:
This small XM replay system only adds 5k to your exe! Now including FULL SOURCE CODE!!! 
FEXP tool to export a header based on your song, which will be compiled into MiniFMOD and exclude whole portions of code! 
Pre-buffered output for 0 latency, and high output stability 
100% click free.
XM sample callbacks for user generated or compressed XM samples! 
File system callbacks so you can specify whatever loading system you like! (disk/wad/memory) 
Copyright 2001-2002 Firelight Technologies Pty.

The MiniFmod can be found at http://www.Fmod.org
or for quick download: http://www.fmod.org/files/minifmod160.zip
note: I dont use the GCC, so if you do, u'll have to sort things out :-)

The Tools:
==========

inside the MiniFmod package, there is a small tool called Fexp.exe,
this will be our XMeffects optimizer for the dumped result.txt!!
other that, we have the *.c/*.h files that we will incldue in our program.

i have included a keygen template which will suite us for including the sound code.
that way, we will code together step by step.
ok, get the template and load the DSW into VC++ IDE.
it is a very basic keygen with 3 buttons, 
Generate, Play, About.
our main goal is to make the sound be playble via the Play button,
it is later to be loaded automatiaclly when keygen starts.
ok, so we have our keygen.cpp with everything ready.

Starting to Code
================

the Sound must have an Handle, of course, that way 
we can determine whenever we try to stop, reload, and even sharing
with other sound players (i.e: Winamp)

as a global variable, we start with: 
FMUSIC_MODULE *mod; /* fmod music handler */
now, before we add more code, lets add to our project the minifmod
functions and main code.
make a new folder in the keygen's main folder, call it "Lib"
you can see it is also in the minifmod16.zip
copy the files from the minifmod16.zip/lib -> our lib folder
note: in the zip/lib there is 2 folders named "debug/final" don'not
copy its content!

alright, now back to our project, 
in the project dir viewer, make a folder named "MiniFmod.c" (under the Source Files folder)
add all *.c files into it from our lib folder.
these files are:

1. Fmusic.c
2. Fsound.c
3. mixer_clipcopy.c
4. mixer_fpu_ramp.c
5. music_formatxm.c
6. system_file.c

now we need to add the header files (*.h),
make a new folder named "MiniFmod.h" (under the Header Files folder)
add all *.h files into the it from our lib folder + the lib file.
these files are:

1.  minifmod.h 
2.  Mixer.h
3.  mixer_clipcopy.h
4.  mixer_fpu_ramp.h
5.  Music.h
6.  music_formatxm.h
7.  Sound.h
8.  system_file.h
9.  system_memory
10. xmeffects.h
11. winmm.lib    ; not an *.h file, but dont forget to add it too!!!

now, since its a keygen and using the standard minifmod source is not enough,
we will make some modifications into its code, that means some files from the original
has been slighly modifyed to suite our needs!
note: the modified files has been added to the source code, so i took of it already.

another thing we need to do is to create a new folder named "loadmusic.h" 
(under the Header Files folder).
now listen carefully, remember the result.txt we have dumped ?
we will use it's hex dump as the file it self!,
rename the result.txt -> music.h (as specified in the modified files :-))
open it (be carefull, editing big files can cause a crash :-)),
now we need to edit the file a bit.

original Dump:
==============
static unsigned char table[52436] = {};

Modified Dump:
==============
#define MUSIC_LEN 4092

static unsigned char music[]=
{
};

note: the diffrences, always do this when trying to load new music into ur keygen!!!
once we finished editing and saving, we need to make a new *.h file:
open notepad and write/paste this code:

//===============================================================
#ifndef __LOADMUSIC_H__
#define __LOADMUSIC_H__

// Memory functions
unsigned int memopen(char *name);
void memclose(unsigned int handle);
int memread(void *buffer, int size, unsigned int handle);
void memseek(unsigned int handle, int pos, signed char mode);
int memtell(unsigned int handle);

void loadmusic(void); // Load music fucntion

#endif
//==============================================================

its a few addons, basically we are making it easier for us to load the dumped xm
file into memory and make it playble.
save this file as loadmusic.h
finally, we add those 2 files (music.h / loadmusic.h) into the loadmusic folder.

last and not least, we need to add the loadmusic.cpp, which is ofcourse not a part
of minifmod, as i said it is our modified code.
make a folder named "loadmusic.c" (under the Source Files fodler).
add this file (loadmusic.cpp)

allright, this fun the setup part of minifmod,
we now need to add those as #include in our main keygen.cpp

#include "loadmusic/loadmusic.h"
#include "lib/minifmod.h"
#include "lib/buffer.h"

note: if you take a look at loadmusic.cpp you can see our music.h declared there,
along with our new modified functions.

The Last Touch
==============

we have declared the handle of our fmod music rememebr?
FMUSIC_MODULE *mod;

right, all we need to do is to set the Fmod up and load the dumped xm file (music.h)
into memory and alst call the play function!

at our play button id code (case IDC_PLAY:)
we add this code:

if (mod == NULL) // mod handle is free? (though it will work fine with other loaded audio devices)
{
   // We defined our music file to be loaded in loadmusic.cpp //
   //=============================================================//
   loadmusic(); // Call & set ready memory to load the music
   if(!FSOUND_Init(44100, 0)) // intialize memory for sound and format
   {  
      break;
   }
   mod = FMUSIC_LoadSong(NULL, NULL); // handle = LoadSong() 
   FMUSIC_PlaySong(mod); // Play it (from memory), way cool!!
}
note: if you put this code in the WM_INITDIALOG, you will get autoplay effect when
loading the keygen!

if we want to Stop the music only thing we need to do is add new button called Stop,
choose an ID to it and use this code:

if (mod != NULL) // handle is loaded (playing)?
{
   FMUSIC_FreeSong(mod); // Free memory (handle)
   FSOUND_Close();       // Close it (stop it from playing)
   mod=NULL;             // make handle to be Free again
}

note: add same code at  WM_CLOSE msg!! 

Important Tips
==============

this is the part where if u dont read it, u will get a funny results
when playing your XM file!!

/* from Firelight's readme */
 
Making your exe even smaller with XMEFFECTS.H and FEXP.EXE:
- Note all the effects in the xm replay code are wrapped with #ifdef's.  They are defined in 
  xmeffects.h.
- Have a look in the zip/lib directory .. There is an executable called FEXP.EXE
- Use FEXP.EXE on an xm file and it will generate xmeffects.h for you!
- Recompile the minifmod library with the new xmeffects.h
- See your exe size go down AGAIN!
- (only play the song you fexp'ed or it will screw up on other songs probably :) ..)

yup, this mean, we make a new xmeffects.h for each music file we dump!!
else as said, we have a screwed up music :-)
-> fexp Hybrid_Song.XM -> xmeffects.h

overwrite the old xmeffects.h in our keygen/lib/ folder, and recompile our source code,
see your music plays fine.

some little note is that the minifmod abit looses the quality of the music,
well this is understandble since minifmod is not a part of the fmod library, so
it does miss some important stuff, but hey, nothing is perfect!!
for me, it rox to have cool sound in keygens, and now you guys too.

Ending
======

well,this complete the essay,
the best way to learn from it is by using the files included in the compiled keygen,
that way u can always have this as a base keygen.

MiniFmod is coded by FireLight (r)
Keygen source code + music coded by Ben & [Goofy] of FreeStylerS 2002

greets to all RCE members, and the REA community!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
城市应急指挥系统是智慧城市建设的重要组成部分,旨在提高城市对突发事件的预防和处置能力。系统背景源于自然灾害和事故灾难频发,如汶川地震和日本大地震等,这些事件造成了巨大的人员伤亡和财产损失。随着城市化进程的加快,应急信息化建设面临信息资源分散、管理标准不统一等问题,需要通过统筹管理和技术创新来解决。 系统的设计思路是通过先进的技术手段,如物联网、射频识别、卫星定位等,构建一个具有强大信息感知和通信能力的网络和平台。这将促进不同部门和层次之间的信息共享、交流和整合,提高城市资源的利用效率,满足城市对各种信息的获取和使用需求。在“十二五”期间,应急信息化工作将依托这些技术,实现动态监控、风险管理、预警以及统一指挥调度。 应急指挥系统的建设目标是实现快速有效的应对各种突发事件,保障人民生命财产安全,减少社会危害和经济损失。系统将包括预测预警、模拟演练、辅助决策、态势分析等功能,以及应急值守、预案管理、GIS应用等基本应用。此外,还包括支撑平台的建设,如接警中心、视频会议、统一通信等基础设施。 系统的实施将涉及到应急网络建设、应急指挥、视频监控、卫星通信等多个方面。通过高度集成的系统,建立统一的信息接收和处理平台,实现多渠道接入和融合指挥调度。此外,还包括应急指挥中心基础平台建设、固定和移动应急指挥通信系统建设,以及应急队伍建设,确保能够迅速响应并有效处置各类突发事件。 项目的意义在于,它不仅是提升灾害监测预报水平和预警能力的重要科技支撑,也是实现预防和减轻重大灾害和事故损失的关键。通过实施城市应急指挥系统,可以加强社会管理和公共服务,构建和谐社会,为打造平安城市提供坚实的基础。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值