KDM engine Notes (5/3/95):
Updated: 11/27/1999 (added tempo to KDM.EXE and PLAYKDM.EXE)

KDM programmed by Ken Silverman

Ŀ
                              About KDM:                                   

	 KDM supports 16 simultaneous sounds in both the left and right speakers.
	 It supports SB, SBPRO, SB16, PAS16, and PC speaker.  PC speaker will
	 crash if you set the rate too high for your computer.

	 Playkdm and Kdm both take these command line parameters:
		 PlayKDM/KDM [KDM file][options]

		 KDM stands for Ken's Digital Music!

		 Options summary: (Defaults listed on left)
			 ?.WAV     - Dump digital music into a standard .WAV file.
							 (Playkdm only)  Use any option you desire.
			 r#####    - Sample rate (r6000 - r44100)
			 s/m       - Stereo / Mono
			 16/8      - Bits per Sample
			 sb/pas/pc - Type of sound card
			 hi/lo     - Quality (hi quality filters out the high pitched crap)
			 l###      - Loop # times before quitting
			 t###      - Set music tempo (default is 120, range is 30-480)

	 Ex: playkdm prepsong r44100 16 s hi sb
		  (these are the defaults)
Ŀ
                         How to use the KDM editor:                        

Main menu (list of tracks):
	Important keys:
				 ESC = Quit
Arrows,PGUP/PGDN = Move cursor
					I = Go to Instrument menu

					N = new KDM song
					L = load KDM song
					S = save KDM song
			  Space = play KDM song (Space again to stop play)

		  K. Enter = record track (K. Enter again when done, ESC to cancel)
			 Delete = delete highlighted track
					M = Swap tracks.  Press M twice, once on each track to swap
					E = Go to Edit track menu (not yet documented)
					W = Show wave mode
					F = Fiddle mode.  Keys: A-K are C-C
											Octave control: Shifts,Ctrls,<, and >

Instrument menu (list of instruments):
	Important keys:
				 ESC = Back to main screen
					U = Update instrument.  This "U" works like the "U" in Editart
			  Space = Test play highlighted instrument
					N = Name instrument
			 Delete = Delete instrument
					M = Swap insts.  Press M twice, once on each inst. to swap

					V = View inst.  Use mouse to remove junk at beginning and end
					R = Set repeat start and length.  (Use with music only)
				 -,= = Fine tune.  Use with shift for 10 at a time.  1 octave=748
					W = Show wave mode
					F = Fiddle mode.  Keys: A-K are C-C
											Octave control: Shifts,Ctrls,<, and >

To quickly load sounds in the KWV file, do this:
	Make sure all .WAV or .RAW files are in same directory.
	Go into KDM.EXE
	Press "I" for instrument menu
	Press "U" and select the instrument with arrows&enter.
	When you quit KDM by pressing ESC, press Y if you want to save changes.

Ŀ
                         How to edit KDM music:                            

	Not yet documented.  All KDM files were made with this KDM.EXE.  For now
	you can use my extremely evil and scary music.

Ŀ
                       How to program for KDM:                             

--- Whenever you want KDM sounds in your game, you must link with:

	 kdmeng.obj (C source) and
	 k.obj (ASM source)

--- Add this to the initialization part of your game: ---

		static long digihz[7] = {6000,8000,11025,16000,22050,32000,44100};

		initsb(option[1],option[2],digihz[option[7]>>4],((option[7]&4)>0)+1,
				((option[7]&2)>0)+1,60,option[7]&1);
		loadsong("klabsong.kdm");   //Optional - if you want digital music
		musicon();                  //Optional - if you want digital music


--- Add these calls where necessary throughout your game code: ---

		How to make sounds the easy way:


			wsay(char *soundname, long freq, long leftvol, long rightvol)
				Soundname is not an actual filename, but a .KWV instrument name.
				Freq is normally 4096.  Higher is higher and lower is lower.
				Leftvol is left speaker volume.  255 is max.
				Rightvol is right speaker volume.  255 is max.
				KDM will average left & right for mono speakers.

				Ex: wsay("blowup.wav",4096L,256L,256L);


		How to make sounds the fancy way:
			For my fancy stereo sounds, you should call setears once per frame.
				Putting it in drawrooms will work fine.


			setears(long posx, long posy, long xvect, long yvect)
				This sets the positions of the left and right speakers in space.
				For Build, trust me, just call it with these parameters:

				Ex: setears(posx[screenpeek],posy[screenpeek],
								(long)sintable[(ang[screenpeek]+512)&2047]<<14,
								(long)sintable[ang[screenpeek]&2047]<<14);


			wsayfollow(char *soundname, long freq, long vol,
						  long *xplc, long *yplc, char followstat)

				Soundname is not an actual filename, but a .KWV instrument name.
				Freq is normally 4096.  Higher is higher and lower is lower.
				Vol ranges from 0-255.  255 is loudest.
				Xplc and yplc are passed as pointers.  They must be long
					variables and on the same scale as posx and posy.
				If (followstat == 0) then the sound will be locked at xplc, yplc.
					You should do this if the values of xplc and yplc may somehow
					become invalid, such as calling deletesprite too soon.
				If (followstat == 1) then the KDM will actually recalculate many
					times a second where the stereo position of the sound will
					be.  This will work great with bullets flying by your head.

				Ex: wsayfollow("blowup.wav",4096L,256L,
									&sprite[i].x,&sprite[i].y,0);


--- Add this to the uninitialization part of your game: ---

		musicoff();                 //Optional - if you want digital music
		uninitsb();



A note of warning:
	Kdmeng/k worked on every Sound Blaster / ProAudio spectrum I tried.
	KDM however may not.  (I hope it works for you!)  It may be due to the
		fact that KDM tries to use the MIDI port.  Besides that, I don't know
		why it would crash.  May the non-crashiness be with you.
