home *** CD-ROM | disk | FTP | other *** search
/ Groovy Bytes: Behind the Moon / groovybytes.iso / GROOVY / SND_TOOL / CDMP16.ZIP / SOURCE.ZIP / CDMI.DOC < prev    next >
Encoding:
Text File  |  1995-01-30  |  15.8 KB  |  406 lines

  1.                H E L L O,
  2.              W E L C O M E
  3.                   T O
  4.                 C D M I
  5.             (CyberDyne Music Interface)
  6.  
  7.                   by
  8.             Marc van Shaney
  9.                  a.k.a.
  10.              Kaya Memisoglu
  11.  
  12.  
  13. 1. What is it about ???
  14. ========================
  15.  
  16. The CDMI is a software interface for playing MOD-files on your PC through
  17. your PC-Speaker or a real D/A converter like the great SoundBlaster. I
  18. give free the whole source code to you and you can do with it whatever
  19. you want except using it in any COMERCIAL product. (Demos are O.K., but I
  20. would apreciate a copy of the program you did using this interface.).
  21. ADVERTISING and SHAREWARE is NOT OK and you should contact me before doing
  22. some great stuff !!! (See ORDER.DOC)
  23.  
  24. The CDMI offers:
  25.  
  26.     * MOD compatibility
  27.     * S3M compatibility
  28.     * STM compatibility
  29.     * 669 compatibility
  30.     * DAC support
  31.     * SB support (both timer and DMA)
  32.     * PC-Speaker support
  33.     * AdLib support
  34.     * FAAAST mixing routines
  35.     * Usage of XMS,so that most of low memory keeps free for you !
  36.     * 386-FLAT mode DOS-extender
  37.     * up to 16 music channels
  38.     * one effect channel
  39.     * many global variables informing you about everything
  40.     * !!! INTERPOLATION !!! for best sound-qualitiy at high rates
  41.  
  42.  
  43.  
  44. 2. What does CDMI really do ?
  45. ===============================
  46.  
  47. Well, the CDMI is a so called MOD-player and does a thing an Amiga has
  48. special hardware for. An Amiga has 4 seperate D/A-converters making it
  49. possible to play 4 voices simultaniously at different pitches and volumes.
  50. So it is very easy to write 4-channel music using real samples - if you
  51. own an Amiga.
  52. But the time goes on and everyone owns a PC without four independent D/A-
  53. converters. So one must mix these 4 channels manually - and this is a big
  54. and difficult job. You must consider that each instrument must be resampled
  55. to a new pitch in REAL-TIME. That means that your mixing-routines must be
  56. VERY fast. And then you must consider the different volumes for each channel,
  57. too. And this mixing can only be done at a reasonable speed in Assembler.
  58. Yeah !!!
  59. I used the Turbo-Assembler und utilized 386 instructions for speed-purpose,
  60. so this program won't run on a 286 anymore. (Sorry !) It also uses the
  61. FLAT-mode of the 386 for storing the instruments, because there are some
  62. REALLY big songs (I have a 669-Song with over 1MB), and you still need free
  63. base memory for other things in your program, right ?!
  64.  
  65.  
  66.  
  67. 3. What do I need to use CDMI ???
  68. ==================================
  69.  
  70. First you need a computer ;-)
  71. Second you need a 386+ and a XMS-manager like HIMEM.SYS.
  72. Third - and this IS important - you need a C-Compiler and an assembler.
  73. Personally I use TASM and Borland C++ 3.1. I don't know if and how it works
  74. with other compilers, because one is enough for me.
  75. Last you need some programming skills for writing a k00l demo or a great
  76. game using the CDMI.
  77.  
  78.  
  79.  
  80. 4. How do I use CDMI ???
  81. =========================
  82.  
  83. All the routines supplied with CDMI are written in Assembler or C, but you
  84. can use all routines from C. Now follows a List of routines:
  85.  
  86. CDMI_Load_MOD(char *fname)
  87. This function loads a MOD file from disk into memory/EMS (The patterns are
  88. stored in base memory and the samples are stored in the EMS). The
  89. Song_Header structure is defined in CDMILIB.H and will be initialized
  90. by the loader.
  91.  
  92. CDMI_Load_669(char *fname)
  93. This loads a 669-file from disk into memory. It is used in the same way
  94. as CDMI_Load_MOD
  95.  
  96. CDMI_Load_S3M(char *fname)
  97. You can guess . . .
  98.  
  99. CDMI_Load_STM(char *fname)
  100. You might expect that this function will load in a STM-file, but you are
  101. totally mistaken. This function is used to cook your harddisk with some
  102. of your meory at 120 Celsius for better performance in detecting dwarfs ;-)
  103. So if you do noit want to load in a STM-file then do not use this function.
  104. (Clear ?!?)
  105.  
  106. CDMI_Play_Song(int flags,int freq,SoundDrv *Drv)
  107. This routine will begin to play the song described in Song using the flags.
  108. The output-frequency freq and the Sound-device-drive drv will be used.
  109. The flags are a bit-field. The bits are defined in CDMILIB.H:
  110.     LOOP_FLAG       will loop the module, e.g. when the song
  111.             has come to its end, the player will start from the
  112.             beginning.
  113.     HIGH_PASS       This flag will activate the high-pass filter.
  114.     MID_PASS        This flag will activate a mid-pass filter
  115.     LOW_PASS        This flag will activate a low-pass filter
  116.     INTERPOLATION   Interpolates samples at high frequencies
  117.             (only in registered version)
  118.  
  119. freq can be between 8000 and 44000. I never tried out other values, but
  120. they might work on a FAST computer with some sound-devices.
  121. I suggest that you do not use INTERPOLATION in demos/games etc. because
  122. it eats really MUCH processor power and is about 2 times slower than normal
  123. mixing !!!
  124. Note that the Drv must be the pointer to a structure as described below
  125. (See drivers etc...). But you normally do not need to worry abour the
  126. structure, because I have already written a handful of drivers for many
  127. sound-cards. Supplied drivers are:
  128.     SBTIMER_Driver          in      SBTIMER.ASM
  129.     SBDMA_Driver            in      SBDMA.ASM
  130.     SPEAKER_Driver          in      SPEAKER.ASM
  131.     LPT_Driver              in      SND_LPT.ASM
  132.     ADLIB_Driver            in      ADLIB.ASM
  133.  
  134. CDMI_Stop_Song(void)
  135. This routine will stop the player.
  136.  
  137.  
  138. CDMI_Free_Song(void)
  139. This routine will release the song from memory and XMS. Be sure to call this
  140. routine at the end of your program ! And never call this routine BEFORE you
  141. have stopped the Song using CDMI_Stop_Song !!!
  142.  
  143.  
  144. CDMI_Jump(int where)
  145. This command will break the current pattern and jump to the entry described
  146. with where.
  147.  
  148.  
  149. CDMI_Set_Volume(int volume)
  150. This command changes the output volume while playing the song. 64 is standard
  151. and below 64 is lower volume, higher volumes are louder. Note that higher
  152. volumes can cause nasty cracks in your output caused by oversampling unless
  153. you turn on quality mode, which enables a postprocessing mechanism to avoid
  154. overflows.
  155.  
  156.  
  157. CDMI_Play_Sample(int n,int pitch)
  158. This function starts to mix a sample to the current music. n specifies the
  159. sample number (0 to 63) and the pitch is the period (the higher the period,
  160. the lower the actual frequency in Hz !!!) 0 as a period stops the sample-
  161. output.
  162. (Only in registered version)
  163.  
  164.  
  165. For examples in C and ASM, have a look at CPLAY.C and APLAY.ASM !
  166. (If you want to compile them, then read the text at the beginning, be-
  167. cause you have to link them with some other modules !!!)
  168.  
  169.  
  170.  
  171.  
  172.  
  173. 5. Are there some variables informing me of the state of the player ???
  174. =========================================================================
  175.  
  176. Of course !!! Here is a list of global variables used by CDMI:
  177.  
  178. unsigned int CDMI_Version (read only)
  179. This word contains the version of CDMI (high-byte major,low byte minor)
  180.  
  181. unsigned int CDMI_Pattern_No (read only)
  182. This tells you what pattern is played at the very moment.
  183.  
  184. unsigned int CDMI_Beat_No (read only)
  185. This tells you which row/beat is processed at this moment.
  186.  
  187. unsigned int CDMI_Entry_No (read only)
  188. This variable contains the current entry-umber of the order-list.
  189.  
  190. unsigned int CDMI_Volume (read only)
  191. This integer contains the current master-volume
  192.  
  193. unsigned int CDMI_Channels (read only)
  194. This integer contains the number of channels that are in the current
  195. pattern. Normally this will be 4 or 8.
  196.  
  197. unsigned int CDMI_Flags (read/write)
  198. This variable contains the active flags as defined above. There are some
  199. more flags for internal use, so be careful to change only the flags ex-
  200. plained above !!!
  201.  
  202. unsigned int CDMI_DMA_Size (read only)
  203. This integer has the size of the current Play-buffer in bytes.
  204.  
  205. unsigned int CDMI_Speed (read/write)
  206. This integer contains the speed in ticks/per beat
  207.  
  208. unsigned int CDMI_Tempo (read/write)
  209. This word contains the tempo in Beats per minute
  210.  
  211. char far *CDMI_DMA_Buffer (read only)
  212. This pointer points to the DMA-Buffer currently played and heard. In
  213. combination with CDMI_DMA_Size these variables are very useful for dis-
  214. playing an oscilloscope or spectrum analyzer on the screen.
  215.  
  216. unsigned long CDMI_Channel_Flags (read/write)
  217. This is a very special value. This contains one bit for each channel. If
  218. a bit is set, then the apropriate channel will be played, else it
  219. will be desactivated. Very useful when you want to blend you some channels.
  220.  
  221. unsigned int CDMI_Tick (read/write)
  222. This integer just counts the ticks of the song, e.g. a MOD-song has 50 ticks
  223. per second, so this integer will be incremented 50 times per second. You
  224. can also change this integer, it is not used internally and only dedicated
  225. for synchronisation with some k00l graphic FX you write.
  226.  
  227. l_ptr CDMI_Song (read(/write))
  228. This pointer points to the song-header being used. ATTENTION: The address
  229. is NOT a segment:offset address, but it is a linear address,because this
  230. header is allocated in the extended memory. While playing a song you
  231. should not change this variable, but if you want to load multiple songs,
  232. then it would be possible that you change this variable after loading a
  233. song.
  234.  
  235.  
  236. Note: There are rather a lot of variables with the remark READ ONLY. And
  237.       this remark means that you SHOULD NEVER CHANGE THESE VARIABLES WHILE
  238.       PLAYING A SONG; OR YOUR COMPUTER MAY CRASH.
  239.  
  240.  
  241.  
  242. 6. Well, you said something about drivers...
  243. ==============================================
  244.  
  245. Yes, I use a driver-concept for playing the sound-output. It is a bit
  246. complex but very useful also in other programs. A driver contains the
  247. hardware-specific routines for a sound-card plus - and this is the most
  248. important part - an information structure with pointers to all routines.
  249. But you really do not need to understand these structures, unless you want
  250. to write your own drivers or use them for other purposes.
  251. The structure looks like this:
  252.  
  253. typedef struct
  254.          {
  255.           char Ident[32];   // should contain "Cyberdyne Driver",0
  256.           char Type[16];    // should contain "SOUND"
  257.           char Name[32];    // here you can give it a name
  258.           int Version;      // your version
  259.           int Function_Count;       //MUST contain a 9
  260.           char *Driver_Setup;       // Points to a config-structure or NULL
  261.  
  262.           int (*Init_Driver) (void);
  263.           int (*Exit_Driver) (void);
  264.           int (*Play_Voice) (Sound_Block *);
  265.           int (*Stop_Voice) (void);
  266.           int (*Record_Voice) (Sound_Block *);
  267.           int (*Set_Play_Handler) (int (*Handler) (void));
  268.           int (*Set_Record_Handler) (int (*Handler) (void));
  269.           int (*Set_Next_Block) (Sound_Block *);
  270.  
  271.           int Status;
  272.           char far *Voice;
  273.          } SoundDrv;
  274.  
  275. Now I will describe the various routines and what they should do:
  276.  
  277. Init_Driver(void)
  278. This routine is called ONCE and is used to set-up some driver specific
  279. things, like finding a sound-card etc.
  280.  
  281. Exit_Driver(void)
  282. This routine is also called ONCE at the end of the program. Here you might
  283. want to restore some interrupt vectors or other things.
  284.  
  285. Play_Voice(SoundBlock *)
  286. This is used to start the replay of a block. Note that when you call this
  287. routine, then the internal pointer to the next block will be deleted (See
  288. below).
  289.  
  290. Stop_Voice(void)
  291. This simply stops the actual sound output.
  292.  
  293. Record_Voice(SoundBlock *)
  294. This function is not used yet, but is intended for sample-record purposes.
  295.  
  296. Set_Play_Handler(int (*Handler) (void))
  297. This routine is extreme imprtant for the CDMI. Here you can set a userhandler
  298. that will be called when the voice-output of the currently played block has
  299. come to its end. In this handler you can set the next block that should
  300. be played or something like that. CDMI uses this function to install the
  301. music-calculation interrupt.
  302. If you want to use a user-handler, then there are some important things you
  303. should know:
  304.     1.) All 32-bit registers, DS and ES are saved already by the driver.
  305.         So you normally do not need to worry about destroying registers,
  306.         except you use FS or GS (these must be saved manually).
  307.     2.) Your handler must and with a retf instruction and an iret !!!
  308.     3.) You must pass a status-word in AX:
  309.         If AX<0 then the output will be stopped immeditaly.
  310.  
  311. Set_Record_Handler(int (*Handler) (void))
  312. This function does exactly the same like above excpet that it is reserved
  313. for recording purposes.
  314.  
  315. Set_Next_Block(Sound_Block *)
  316. This is another very important and useful function. In order to make time-
  317. gaps between two sound-blocks as small as possible, I added this function.
  318. You can call this function while the first block is still playing and tell
  319. the driver where the next sound block can be found. When the first sound-
  320. block is finished then the driver will automatically continue the output
  321. with this new soundblock and then call (if defined) the user-handler.
  322.  
  323. The config structure is used for driver which can use different settings.
  324. In order to use this structure use Config_Driver(Driver *) of the demo-
  325. file CDMIDEMO.C.
  326.  
  327.  
  328.  
  329. 7. I heard, CDMI uses a DOS-extender ???
  330. ==========================================
  331.  
  332. Yes, that is right. In order to play really large samples and many patterns,
  333. I decided to use extra memory. I first used EMS, and it worked more or
  334. less, but it was a bit too slooooow, so I decided to write a DOS-Extender.
  335. This extender sets up a so called "flat-mode" of the 386 CPU which enables
  336. you access to 4GB address-space without programming in protected mode !
  337. The only disadvantage is that it does not work with EMM386,QEMM etc. at the
  338. moment.
  339. You can also use these functions in your programs, see EXT386.DOC for further
  340. information. But if you don't like to use these functions, you do not need
  341. to bother about the FLAT-mode, because it works absolutely transparently !!!
  342. But you MUST init the extender by calling Init_EXT386 at the beginning of
  343. your program and Exit_EXT386 at the end !!!
  344.  
  345.  
  346.  
  347. 8. Problems, Bugs...
  348. =====================
  349.  
  350. Now let us come to the dark side of CDMI. There are some known problems with
  351. other C-functions and some rules you should know.
  352. First Borland C++ offers rather a LOT of memory allocation functions, but
  353. they turned out to be incompatible. This means that not you can not use all
  354. memory-management aat a time (malloc(), calloc(), _dos_allocmem(), allocmem())
  355. In order to prevent conflicts, I provide you with my own memory allocation
  356. functions in EXT386:
  357.     void far *Malloc(size_l);
  358.     int       Free(void far*);
  359.     size_l    Coreleft(void);
  360.     void far *DMA_Malloc(size_t);
  361.  
  362.  
  363. Even the MOD-player does not work always. There are some rare modules which
  364. cannot be played correct and which cause a crash. I do not know why, but it
  365. seems, that there is a division by zero caused by a illegal period.
  366. And there are still some extended commands that are not implemented yet.
  367.  
  368. The 669-support is not complete yet. There are some special commands missing,
  369. too.
  370.  
  371.  
  372.  
  373. 9. There is a demo, right ?!
  374. ===============================
  375.  
  376. Yes, I supplied a small graphic-demo with this package, so you can see how
  377. CDMI is used in a "real" program.
  378. It is written in Borland C++ 3.1 and includes a project file, so there should
  379. be no problem building it. You may reuse all routines of the demo, if your
  380. new program has not the same "look-and-feel". In other words, you may not
  381. only makes some minor changes (like modifiing the text) !!!
  382.  
  383.  
  384.  
  385. 10. Shareware agreement
  386. ========================
  387.  
  388. The files supplied with this documentation are only for educational purpose
  389. and are copyrighted by the author Kaya Memisoglu. You may reuse parts of
  390. them when you give the credits to either Kaya Memisoglue or to Marc van
  391. Shaney (my synonym). You may not use CDMI in any freeware/shareware/
  392. comercial product unless you have registered (See ORDER.DOC) for your
  393. purpose. Then you will receive the latest version inluding the source not
  394. only to the demo, but also to CDMP.
  395.  
  396.  
  397.  
  398. 11. My address:
  399. ================
  400.  
  401. Kaya Memisoglu
  402. Reichenberger Ring 50
  403. 63512 Hainburg
  404. Germany
  405.  
  406.