[请高手看进来]关于wave_form device interface

goldolphin 2003-05-30 06:02:28
四个问题一并列出,如果解决,会再开帖给分:

1.waveInClose或waveInReset函数(具体是哪一个,不太清楚)在调用时可能产生死锁,即使使用线程通知机制响应设备消息,在某些时候仍可能产生死锁。可能是因此导致某些时候(不多)关闭程序时整个操作系统会停止响应几分钟(呈死机状)。我测试的平台为Windows2000 Professional SP3。

2.在waveInAddBuffers之后,能不能释放wavehdr?

3.同样,在waveOutWrite之后,能不能释放wavehdr?

4.对于waveOutWrite,故名思义应是将音频数据写入设备缓冲区,那么照我的理解,在该函数调用之后,应可以释放源音频数据的内存了吧?

...全文
95 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
NowCan 2003-06-02
  • 打赏
  • 举报
回复
队列的大小并不重要,反正有回调消息的。我一般就用几个2048字节的缓存循环。
goldolphin 2003-06-02
  • 打赏
  • 举报
回复
UP
goldolphin 2003-06-02
  • 打赏
  • 举报
回复
3X,
还有一个问题:
waveOut设备的回放缓冲区队列有多大?
如果用waveOutWrite不停地往设备中写入buffer的话,会不会出现溢出之类的情况?
AthlonxpX86 2003-06-01
  • 打赏
  • 举报
回复
up
NowCan 2003-05-31
  • 打赏
  • 举报
回复
WINDOWS低级音频函数介绍
文:苏信东
时间:2000年

  在WINDOWS下,音频函数有多种类型,如MCI、多媒体OLE控制、高级音频等,使用方法都比较简单。但如果想编写一个功能较强大的音频处理程序,那就必须使用低级音频函数和多媒体文件I/O来控制音频设备的输入和输出。因为低级音频函数可直接与音频驱动程序交互,通过窗口消息或回调(CALL BACK)函数来管理音频数据块的记录和播放,控制非常灵活。重要的一点是,低级音频函数为我们提供了一个设备无关的接口。

  播放数字音频

  在使用音频设备之前,必须打开设备驱动程序。为可靠起见,在播放和记录音频之前,要确定系统音频设备的能力。在用完之后必须关闭音频设备。具体流程如下:

  1.查询设备数目和能力

    使用waveOutGetNumDevs和waveOutGetDevCaps来获取波形输出设备的个数和能力。只有在确定设备存在之后,才可以打开设备、使用设备。

  2.打开波形输出设备

    使用waveOutOpen为进行重放操作打开特定的波形设备。该函数打开与指定的设备ID相关联的设备,并以给出指定内存句柄的方法返回打开波形设备的句柄。

    当有多种波形输出设备时,建议使用WAVE_MAPPER常数作为设备ID,这使waveOutOpen函数会自动挑选最适合播放给定的数据格式的设备。

  3.准备音频数据块

    在波形重放之前,要准备好音频数据块。将数据块传递给设备驱动程序就实现了重放。使用的函数是waveOutPerpareHeader。在用完数据块之后,必须用waveOutUnPrepareHeader函数来清除对波形数据块的准备。

  4.发送音频数据块

    在成功打开波形输出设备之后,就可以进行波形重放,使用waveOutWrite函数。在调用该函数后,必须等到设备驱动程序使用完音频数据块之后才可以把该数据块释放掉。

  5.管理波形重放

    在使用低级音频函数播放音频时,应用程序必须不断地向设备驱动程序提供数据块,直到播放结束。WINDOWS 95提供两种方法管理波形重放:一是使用窗口消息管理,二是使用低级回调函数管理。另外,通过使用waveOutPause、waveOutRestart和waveOutReset来进行暂停、重新启动和停止播放。

  6.关闭波形设备

    用完设备之后,必须调用waveOutClose函数关闭波形输出设备,以便其他程序可以使用设备。

  记录数字音频

    记录数字音频的方法基本同播放过程,不同在于记录期间是不提供诸如暂停和重新开始这样的控制的。使用到的函数包括:waveInGetDevCaps、waveInOpen、waveInPrepareHeader、waveInUnPrepareHeader、waveInAddBuffer、waveInReset、waveInStart、waveInStop、waveInClose等。

- END -

refer to: www.wavecn.com
NowCan 2003-05-31
  • 打赏
  • 举报
回复
1、waveInReset会死锁,http://asp.6to23.com/nowcan/tech/waveInReset.htm
其余几个问题不是很清楚。

http://asp.6to23.com/nowcan/code/wave.zip这是一个例子程序,可以参考。
goldolphin 2003-05-30
  • 打赏
  • 举报
回复
随便给点提示都好~~~~~~~~
goldolphin 2003-05-30
  • 打赏
  • 举报
回复
我自己顶
1 , TaskBar_v0.5.zip"Form_Taskbar is a control for Visual Basic which, once placed onto a form, makes the form act like the Taskbar (minus the Start Menu)." -- David Newcum2 , RemBuilderplus.zip"Rem Builder will auto load on startup to use Rem Builder; start your Visual Basic program with your project code showing, right click and you should see "Rem Builder".3 , syntax.zipThis is an excellent example of how to highlight HTML code in a rich textbox. I encourage everyone to check it out.4 , status.zipThis example demonstrates how to display text about each control the mouse is currently above.5 , dm10e.zipThis COM object allows you to send SMTP mail from many of the most used applications, including:Active Server Pages (Microsoft IIS or Chili!ASP extensions) Microsoft Visual Basic 4.x/5.x/6.x Microsoft Word, Access, Excel 95/97 (VBA) Windows Scripting Host (cscript / wscript) Perl 5.x for Win32 Inprise Delphi 4 Microsoft Visual C++ 4.x/5.x/6.x Microsoft Visual J++ 1.x/6.0 (Java) 6 , ocxex.zip"This is a quick example I made to show you how to use Events and properties in a OCX."7 , news.exeThis control aids as a complete Newsgroup control. It can post messages and recieve messages through the internet.8 , optiondemo.zipThis example demonstrates how to create realistic Option Buttons in Visual Basic.9 , mencrypt.zipThis ocx allows you to encrypt strings while utilizing a password shift method.10 , listtxt.zipThis shows how to retrieve the text from the current selection in a listbox.11 , list_index.zipThis example tells you if the inputted List Index is selected or not.12 , fade.zipThis is a bas to fade a pictuerbox. Can be used to make a progressbar13 , subcls32.zipThis demonstrates hoe to write a subclassing control. And it has many examples as to how to use the control (included.)14 , djmeter.zipThis is the source for a Progress Bar control. Also includes a helpful example.15 , progress.zipThis is an example on how to use the Progress Bar included with Microsoft's Visual Basic.16 , slider.zip"This is a sample of the Slider control that is part of the Microsoft Windows Common Controls(COMCTL32.OCX). "17 , statusbar.zip"This is a sample of the StatusBar control that is part of the Microsoft Windows Common Controls(COMCTL32.OCX). "18 , tabstrip.zip"This is a sample of the TabStrip control that is part of the Microsoft Windows Common Controls(COMCTL32.OCX). "19 , uncommondialog.zipThis is an alternative to Microsoft's (tm) Common Dialog control by Nick Mancini.20 , ucmdex.zipThis is the example to go with Uncommon Dialog OCX.21 , scroll.zipThis demonstrates how to create an auto-scrolling textbox.22 , splitter.zipThis demonstrates how to "split" controls. This is an excellent example, and I reccomend this file for everyone. 23 , mtymse.zip"This project is a fully working ActiveX control, with code, that allows you to control almost every aspect of the mouse. You can move the mouse, click the buttons and adjust the click time from your application."24 , ucmdsrc.zipThis is the source to my OCX. This demontrates how to create a basic OCX. This will aid anyone who wants to create an OCX.25 , avb-systray.zipThis is a good example to add your programs' icon to the Systray. This Zip also includes a helpful example.26 , cmdex.zipThis is an example of how to use the Common Dialog. This demonstrates most of the event procedures of the CM Dialog control.27 , campbell-reg.zipThis demonstrates how to write and retrieve information from the registry.28 , basChangeCursor.zipThis module demonstrates how to animate your cursor through Visual Basic, and Win32.29 , hdcat.zipThis will grab every file on your hard drive and add its path to a listbox.30 , vbo_bump.zipThis DLL allows programmers to easily draw 3D grippers and lines on Device Contexts (DC). 31 , vbo_user32_bas.zipThis BAS file contains many functions to ease the process of using the USER32 DLL. 32 , vbo_gdi32_bas.zipThis BAS File conatains many functions to ease the process of using the GDI32 DLL. 33 , vbo_button_bas.zipThis bas contains functions to manipulate Button class objects34 , LPT_Port.zipRead/write to LPT parallel port35 , DancingBaby.zipA Dancing Baby Screen Saver Which Dance on A Famous Song Macarena ( With Sound ) A Very Cute Screen Saver ,with source code, If you want more avi files then please mail me.36 , superwriter.zipA complete Wordprocessor, with source code. You can save, open files, print them out, copy, cut, paste, well you know the concept!37 , LogOff.zipThis conveniently placed program allows you to log off from your system tray.38 , ChPass.zipChanges NT Domain Passord. This program has two compenants... a server and a a client. The Server must run on a Domain Controller.39 , Reboot.zipThis conveniently placed program allows you to restart your computer more easily, from your system tray. 40 , analogclock.zipThis is a very good demo OCX for an analog clock. Although quite big in size, this is due to the very good background to the clock face. The analog click itself is very accurate and looks very impressive.41 , edge.zipThis program uses a few API calls/functions to set 3D, sunken and etched effects to an image inside an image control. It also has an example of how to change a label control to a 3D command button.42 , splitpanel2.zipA re-written version of the SplitPanel that David originally put onto this site about a year ago. It basically is a control that you place on a form and you can put other controls on the form and by dragging the splitpanel bar around, it does the resizing for you. 43 , avcontrol.zipThis control takes care of many audio and visual functions needed for game and graphical programmers. You can easily retrieve or change the screen resolution and color depth, play audio CDs and standard wave files 44 , fsocontrol.zipThis demonstration version of this control is a wrapper around the FileSystemObject - and makes using the FSO much easier.45 , slidingtoolbar.zipThis project shows how to implement a sliding toolbar in an application using one quick Kernel32 API function "Sleep". The application is fairly simple and easy to implement. 46 , dcsize.zipWhen this control is put onto a form, it ensures that all other controls retain the correct aspect-ratio from the design time view. Basically, it resize all controls on a form when the form resizes. This code is 100% free.47 , colorchooseocx.zipThis great OCX allows you to have a drop down list of colors to allow your user to choose from. The control itself has all the events and properties that you need.48 , xgraphmeter.zipThis is XGraphMeter, a bargraph/meter control good for displaying constantly changing values such as CPU usage or DUN throughput.49 , dynlistmnu.zipWhile trying to come up with a Dynamic menu in VB, I decided that VBs menu object was just too much of a pain to work with This project contains a form to mimic the functionality that I was looking for.. Part of my design criteria was that the menu form 50 , runtime.zipSupposedly, what this code does cannot be done... But it works. Basically, its a demonstration of how you can change control properties at run-time. If you try it in VB, you will get a runtime error, but this code shows you how to do it. Gilbert says51 , ledbulb.zipThis is a first for this author. Its an OCX which represents a characters in the form of led bulbs.52 , textapiroutines.basContained here is a small set of routines can be used with a Rich Text box (RTF) control. It can be used for other controls as well with minor modifications. You are welcome to change, use and distribute the code as you see fit.53 , xflatbutton.zipFlatButton is an owner-drawn flat button that pops up when the mouse passes over it. This version is text-only, but has flexible color support.54 , urllabel.zipWith the development of the internet and intranet applications, this control could could in more and more useful. Its a hyperlink label which will change color or underline when the mouse goes over it 55 , progbar.zipThis is a great replacement for the standard VB progress bar. Its smooth, totally free (all the source code is here), and more versitile than the one that comes with VB.56 , splitpanel.zipThis little control with full source code is remarkably compact but does a lot of fancy things. It allows you to be able to split panels and handles all the resizing behind it. We couldn't think of how to describe it properly, but 下载 it and try it57,basicreg.zipBasic Save and Retrieve Functions58,proguse.zipKeep Track of a Programs Usage59,millisec.zipCount Time in Milliseconds 60,getday.zipGet the Day of Week that a Day Falls On61,shellend.zipNotify the User when a Shelled Process Ends 62,varlist.zipGet a List of Windows Variables 63,detdisp.zipDetermine Display Colors 64,ctrlntwk.zipControl Panel - Network65,ctrluser.zipControl Panel - User Properties66,ctrltwui.zipControl Panel - TweakUI67,ctrlthm.zipControl Panel - Themes68,ctrltele.zipControl Panel - Telephony69,ctrlsys.zipControl Panel - System Properties70,ctrlscrn.zipControl Panel - Screen Savers71,ctrlreg.zipControl Panel - Regional Settings72,ctrlprnt.zipControl Panel - Printers73,ctrlpwr.zipControl Panel - Power Management74,ctrlpw.zipControl Panel - Passwords75,ctrlodbc.zipControl Panel - ODBC3276,ctrlmm.zipControl Panel - Multimedia77,ctrlmdm.zipControl Panel - Modem78,ctrlkbd.zipControl Panel - Keyboard79,ctrlmous.zipControl Panel - Mouse80,ctrlpoa.zipControl Panel - Post Office Admin81,ctrlotlk.zipControl Panel - Outlook82,ctrljoy.zipControl Panel - Joystick83,ctrlie4.zipControl Panel - Internet Explorer 84,ctrlgame.zipControl Panel - Game Controllers85,ctrlfont.zipControl Panel - Fonts86,ctrlarmp.zip Control Panel - Add/Remove Programs87,ctrlanh.zipControl Panel - Add New Hardware88,ctrlanp.zipControl Panel - Add New Printer89,ctrlaccs.zipControl Panel - Accessibility90,ctrlbrf.zipControl Panel - Create Briefcase91,ctrlcdsk.zipControl Panel - Copy Disk92,ctrlcns.zipControl Panel - Create New Shortcut93,ctrldun.zipControl Panel - Dial-Up Networking94,ctrldisp.zipControl Panel - Display Properties95,RegControl.zipFree Registry ActiveX Control. Read/Write String/Binary/DWord values, Check if key/value exists, CreateKey, Delete key/value and enumerate keys/values!96,MouseEvent.zipThis is a Mouse Event procedure that is pretty cool. It can be used for Web designing. Check it out!97,ShellTrayIcon.zipThe CShellTrayIcon class allows your VB application to set, change and delete icons in the system's tray 98,Reboot2.zipReboot remotely. I wrote this to reboot selected PC's during off hours. It is a standalone application that will display a 10 second countdown. Any open data will try to be saved prior to the shutdown process.99,S-Secure.zipThis is S-Secure.....a security program I've coded for Windows. It has 4 modules each in a separate VB project. 100,DriveSpace.zipThis Program finds and displays the Drive's Space.101,Disable_X.zipThis user control allows you to disable the windows close "X" button. Example program included.102,SetParnt.zipShows how to assign controls to different forms at run time. 103,phone.zipA Cellular Phone Application Uses MSCOMM, Modem and normal telephone lines to make calls. You can use this application to make local as well as International calls. 104,Timer01.zipSimple program demonstrating how to create a stop watch using the Timer control. 105,Bubblesort.zipA simple Bubble Sort code that shows how the program works within a VB program. 106,systray.zipJust another Systray Utility, but worse than the others !!! static, flashing and animated Tray-Icons 107,FolderFiles.zipDemonstrates usage of progress bar and list box controls. Its purpose is to get all the files from a specified folder while showing the progress completed. 108,MultipleDataSets.zipThis is a simple, (1) form VB 6.0 program which demonstrates how to plot multiple sets of data on the same graph using the MSChart Control 6.0 (OLEDB). 109,MthVwPrj.zipMonthView control. Lets users view and set date information via a calendar-like interface. 110,calculator4.zipI know this is wierd but I made a calculator control. Just add it to your control bar, double click, and you can use the calculator when your project is at run-time. Source included.111,GradientButton.zipThis button was created to be an enhanced replacement for Visual Basic's standard command button by adding 2 more Border appearance schemes, 2 more button styles, and hover effects. 112,MSChart.zipMSChart. You can view MSChart in Line graph,Pie , Area, etc.. also you can update data provided in the Grid.. Very interesting must see it... 113,printing_tut.zipI made this for a freind to help him out with some basic Printing, i got the idea from a printing tut i found on the net, so the code is not mine. 114,treeview.zipThis code can as many child nodes to a tree view control and can save the data and structure of the treeview control in a text file. Later the data and structure can be retrieved from the text file and filled in the tree view control by clicking the load button. 115,alarm_clock.zipIt simulates an alarm clock. 116,DesktopByAlexDrankus.zipThis program hides/shows desktop, hides/shows taskbar, hides it self from the ctrl+alt+delete, uses pictures to create the forms (pretty cool forms) and many other functions just place this program and all components in a sub-folder 117,Label3D.zipLabel3D lets you change the Label Face Color Shadow Color ON/OFF Shadow. 118,HotLinks.zip Custom Control which acts like a text box, except the developer can specify hot links in the control which act like web page links allowing users to click them, while allowing the developer full control over the result of the click. 119,custbutt.zipThis application shows how to create non rectangular buttons. 120,grid.zipComplete grid coded in vb. supports : locked rows/columns , fg/bg colors , text alignment , cell-edge styles , different selectionstyles . texbox/dropdown cells , cell icons and lots more... 121,analogmeter.zipCreate your own analog meters using MSPaint. These .bmp or .gif files become your meter face. Use the (analogmeter) subroutine to automatically draw the meter needle over the meter face 122,wheel.zipSpinWheel control to be used in place of either the UpDown control or the ScrollBar control.123,ArielBrowseFolder.zipA browse folder control resembling a combobox. When the dropdown button is clicked, browse through a folder treeview to select a directory. Uses the SHBrowseForFolder function, amongst other APIs. A call back procedure is implemented showing the currently selected folder in the browse for folder dialog. 124,pp_prj.zipThis program shows you how to create a sample project that adds print preview capabilities to your Visual Basic program by using a generic object and the Printer object. 125,popup.zipPopUp buttons with only 4 lines of code. 126,adbevel.zipThe bevel control in Delphi is now available in VB. 127,rainbow.zipCool! Have a ProgressBar like in InstallShield!With free selectable fore- and backcolor and the percent value displayed in the middle!Check it out.128,gb12.zipWell folks. Another version of Gold Button is here. I've added a few things. Here they are: Property descriptions, MaskColor, UseMask, Base Address in OCX, picture will now automatically align with text and when you are in desing mode and OnUp property is bsNone, a Dash-Dot-Dot box is drawn over the button, so you can see th button's area. 129,gb11.zipA new version of Gold Button is here dudes.New version has Picture Property and Skin Support. 130,BIGDOGMEDIA.zipMEDIA PLAYER THAT SUPPORTS FORMATS LIKE MP3,AVI,MPEG,WAV ECT.EXAMPLE OF USING ANIMATION WHEN PLAYER IS LAUNCHED. 131,HTML.zipAn HTML editor with complete VB source code. 132,PrintPreview1.zipPrint Setup, and Print Priview application. 133,RTFEditor.zipRTF text editor, HTML text editor, web browser, and more...Try it. Note, make sure your printer is turned on before running the application. 134,VBExplorer-II.zipVBExplorer file utility application. This application uses the Visual Basic TreeView and ListView controls to create a file management application similar to Windows Explorer.135,resizepic.zipShows how to resize a picture box control on a form at run time.
52799di.pdf Access odd memory locations without hardware . . . . . . . . . . . . . . . . . . .101 Charge indicator gauges lead-acid batteries . . . . . . . . . . . . . . . . . .102 Use derivatives to catch RF calibration errors . . . . . . . . . . . . . . . . . . .104 mC-based circuit performs frequency multiplication . . . . . . . . . . . . . . . . . . . . . .108 Kick start a crystal oscillator in Spice 110598di.pdf Low-voltage interface circuits translate 1.8 to 5V..........................................................119 Laser-diode driver stabilizes sensitivity parameters ....................................................120 Voice-storage chips talk to each other....122 3.3V converter delivers 3W from Li-ion battery ............................................................124 Pulsing charge pump drives capacitive loads ..............................................................126 Short-circuit finder uses few parts ..........130(只用1.5V,一只LM10+蜂鸣器,就是一个短路测试器 “Tube” circuit provides linear tuning ......130 111199di.pdf Controller IC halves switcher’s standby power..............................................169 Load detector controls power sources ..............................................170 Two-wire interface has galvanic isolation ........................................174 (3只光偶做I2C隔离总线) Measure power-on current transients on ac line ....................................176 Generator has independent pulse width, frequency................................178 Customized potentiometers aid amplifier design ..........................................180 Ring your bell; light your light ..................182 111198di.pdf Voltage reference sets current limit ........129 Accelerometer output gives temperature info ..........................................130 Voltage comparator forms pulse demodulator ......................................132 Watchdog-reset catcher aids embedded-system debugging ................132 Easily display bit-map images on small-graphic LCDs ..............................134 CMOS inverter VCO tunes octave to UHF ............................................................138 Pushbutton or logic controls nonvolatile DAC ..........................................140 12199di.pdf RISC mP implements fast FIR filter ..........119 Simple algorithm transforms filter coefficients ....................................................120 Door/window sensor resists tampering ......................................................120 Use a trick to count scope events ............122 A primer on binary-arithmetic rounding ........................................................124 Light powers isolation amplifier ..............128 Low-cost feedback circuit boosts efficiency ........................................................130 102298.di.pdf Ethernet 10BaseT simulator jig yields zero emissions Digital potentiometer autonulls op amp Single wire connects microcontrollers Photo-flash charger minimizes parts count Generate an analog signal with a mC 080405di.pdf AGC amplifier features 60-dB dynamic range Precision active load operates as low as 2V Squeeze extra outputs from a pin-limited microcontroller 072105di.pdf Power-supply interrupter fights ESD-induced device latch-up High-impedance FET probe extends RF-spectrum analyzer’s usable range Watchdog circuit protects against loss of battery charger’s control signals Circuit adds foldback-current protection (稳压IC加入折回式短路保护) 70705di.pdf Contact-debouncing algorithm emulates Schmitt trigger Inexpensive peak detector requires few components Free program designs and analyzes passive and active filters 62305di.pdf Digital countdown timer may never need battery replacement Wide-range regulator delivers 12V, 3A output from 16 to 100V source Stable, 18-MHz oscillator features automatic level control, clean-sine-wave output Ultra-low-noise low-dropout regulator achieves 6-nV/Hz noise floor 60905di.pdf Inrush limiter also provides short-circuit protection (简单的电源短路保护) Microprocessorbased dual timer features four outputs Wide-range voltage regulator automatically selects operating mode. CMOS hex inverter generates low-distortion sine waves. 52605di.pdf Interrupt-driven keyboard for MCS-51 uses few components Simplified white-LED flasher operates from one cell Low power voltage-to-frequency converter makes a wireless probe for testing an inductive power supply Simple circuit converts 5V to -10V 51205di.pdf Versatile digital speedometer uses few components ..................................95 Microprocessor, linear potentiometer deliver echo pulses ........................................96 Passive-detector receiver keeps you informed, entertained during flights ........98 Quickly estimate an electronic system’s cooling requirements ................100 Spreadsheet converts sound levels 42805di.pdf Camera serializer/deserializer chip set reduces wire count for keypad....................75 Rearranged reference helps ADC measure its own supply voltage ................76 Difference amplifier measures high voltages ..................................................78 Linear potentiometer provides nonlinear light-intensity control.. 41405di.pdf High-side current-sensing switched-mode regulator provides constant-current LED drive ..........................95 Microcontroller’s DAC provides code analysis ..................................................96 Two gates and a microprocessor form digital PLL ..............................................98
Tricks of the Windows video Game Programming

PART I Windows Programming Foundations 7
1 Journey into the Abyss 9
A Little History........................................................................................9
Designing Games ..................................................................................13
Types of Games ....................................................................................13
Brainstorming........................................................................................14
The Design Document and Storyboards................................................15
Making the Game Fun ..........................................................................16
The Components of a Game..................................................................16
Section 1: Initialization....................................................................17
Section 2: Enter Game Loop............................................................17
Section 3: Retrieve Player Input ......................................................17
Section 4: Perform AI and Game Logic ..........................................17
Section 5: Render Next Frame ........................................................18
Section 6: Synchronize Display ......................................................18
Section 7: Loop................................................................................18
Section 8: Shutdown ........................................................................18
General Game Programming Guidelines ..............................................21
Using Tools............................................................................................26
C/C++ Compilers ............................................................................26
2D Art Software................................................................................26
Sound Processing Software..............................................................26
3D Modelers ....................................................................................26
Music and MIDI Sequencing Programs ..........................................27
Setting Up to Get Down—Using the Compiler ....................................27
An Example: FreakOut..........................................................................29
Summary................................................................................................46
2 The Windows Programming Model 47
The Genesis of Windows ......................................................................48
Early Windows Versions ..................................................................48
Windows 3.x ....................................................................................48
Windows 95......................................................................................49
Windows 98......................................................................................50
Windows NT ....................................................................................50
Basic Windows Architecture:Win9X/NT........................................50
Multitasking and Multithreading ..........................................................51
Getting Info on the Threads ............................................................52
The Event Model..............................................................................53

0072313618 FM 10/26/99 9:32 AM Page vi
vi
TRICKS OF THE WINDOWS GAME PROGRAMMING GURUS
Programming the Microsoft Way: Hungarian Notation........................55
Variable Naming ..............................................................................56
Function Naming..............................................................................56
Type and Constant Naming..............................................................57
Class Naming....................................................................................57
Parameter Naming............................................................................58
The World’s Simplest Windows Program..............................................58
It All Begins with
WinMain() ..........................................................59
Dissecting the Program....................................................................60
Choosing a Message Box ................................................................63
Real-World Windows Applications (Without Puck)..............................66
The Windows Class ..............................................................................66
Registering the Windows Class ............................................................74
Creating the Window ............................................................................75
The Event Handler ................................................................................77
The Main Event Loop............................................................................84
Making a Real-Time Event Loop..........................................................89
Opening More Windows........................................................................90
Summary................................................................................................93
3 Advanced Windows Programming 95
Using Resources....................................................................................96
Putting Your Resources Together ....................................................98
Using Icon Resources ......................................................................99
Using Cursor Resources ................................................................102
Creating String Table Resources....................................................106
Using Sound
.WAV Resources ........................................................108
Last, But Not Least—Using the Compiler to Create
.RC Files ....114
Working with Menus ..........................................................................116
Creating a Menu ............................................................................116
Loading a Menu..............................................................................119
Responding to Menu Event Messages ..........................................122
Introduction to GDI ............................................................................128
The
WM_PAINT Message Once Again ..............................................128
Video Display Basics and Color....................................................133
RGB and Palletized Modes............................................................135
Basic Text Printing ........................................................................137
Handling Important Events..................................................................143
Window Manipulation....................................................................143
Banging on the Keyboard ..............................................................150
Squeezing the Mouse......................................................................158
Sending Messages Yourself ................................................................161
Summary..............................................................................................163

0072313618 FM 10/26/99 9:32 AM Page vii
vii
CONTENTS
4 Windows GDI, Controls, and Last-Minute Gift Ideas 165
Advanced GDI Graphics......................................................................166
Under the Hood with the Graphics Device Context......................166
Color, Pens, and Brushes................................................................167
Working with Pens ........................................................................168
Painting with Brushes ....................................................................172
Points, Lines, Polygons, and Circles ..................................................173
Straight to the Point........................................................................173
Getting a Line on Things................................................................175
Getting Rectangular........................................................................177
Round and Round She Goes—Circles ..........................................180
Polygon, Polygon,Wherefore Art Thou, Polygon? ......................181
More on Text and Fonts ......................................................................182
Timing Is Everything ..........................................................................184
The
WM_TIMER Message ..................................................................184
Low-Level Timing..........................................................................187
Playing with Controls..........................................................................190
Buttons............................................................................................191
Sending Messages to Child Controls ............................................195
Getting Information ............................................................................197
The T3D Game Console......................................................................205
Summary..............................................................................................210
PART II DirectX and 2D Fundamentals 211
5 DirectX Fundamentals and the Dreaded COM 213
DirectX Primer ....................................................................................214
The HEL and HAL ........................................................................216
The DirectX Foundation Classes in Depth ....................................216
COM: Is It the Work of Microsoft… or Demons?..............................218
What Exactly Is a COM Object?....................................................219
More on Interface IDs and GUIDs ................................................223
Building a Quasi-COM Object ......................................................224
A Quick Recap of COM ................................................................226
A Working COM Program ............................................................226
Working with DirectX COM Objects..................................................231
COM and Function Pointers ..........................................................232
Creating and Using DirectX Interfaces..........................................236
Querying for Interfaces..................................................................237
The Future of COM ............................................................................238
Summary..............................................................................................239

0072313618 FM 10/26/99 9:32 AM Page viii
viii
TRICKS OF THE WINDOWS GAME PROGRAMMING GURUS
6 First Contact: DirectDraw 241
The Interfaces of DirectDraw..............................................................242
Interface Characteristics ................................................................242
Using the Interfaces Together ........................................................244
Creating a DirectDraw Object ............................................................245
Error Handling with DirectDraw....................................................246
Getting an Interface Lift ................................................................247
Cooperating with Windows ................................................................250
Getting into the Mode of Things ........................................................255
The Subtleties of Color........................................................................259
Building a Display Surface..................................................................263
Creating a Primary Surface............................................................264
Attaching the Palette......................................................................272
Plotting Pixels ................................................................................272
Cleaning Up....................................................................................284
Summary..............................................................................................285
7 Advanced DirectDraw and Bitmapped Graphics 287
Working with High-Color Modes........................................................288
16-Bit High-Color Mode................................................................289
Getting the Pixel Format................................................................290
24/32-Bit High-Color Mode ..........................................................299
Double Buffering ................................................................................301
Surface Dynamics................................................................................307
Page Flipping ......................................................................................311
Using the Blitter ..................................................................................317
Using the Blitter for Memory Filling ............................................320
Copying Bitmaps from Surface to Surface....................................328
Clipper Fundamentals..........................................................................332
Clipping Pixels to a Viewport ........................................................332
Clipping Bitmaps the Hard Way....................................................334
Making a DirectDraw Clip with
IDirectDrawClipper..................339
Working with Bitmaps ........................................................................345
Loading
.BMP files..........................................................................345
Working with Bitmaps....................................................................352
Loading an 8-Bit Bitmap................................................................353
Loading a 16-Bit Bitmap................................................................354
Loading a 24-Bit Bitmap................................................................355
Last Word on Bitmaps....................................................................356
Offscreen Surfaces ..............................................................................356
Creating Offscreen Surfaces ..........................................................356
Blitting Offscreen Surfaces............................................................358
Setting Up the Blitter......................................................................359
Color Keys......................................................................................360
Source Color Keying......................................................................361

0072313618 FM 10/26/99 9:32 AM Page ix
ix
CONTENTS
Destination Color Keying ..............................................................364
Using the Blitter (Finally!) ............................................................365
Bitmap Rotation and Scaling ..............................................................366
Discrete Sampling Theory ..................................................................368
Color Effects........................................................................................373
Color Animation in 256-Color Modes ..........................................373
Color Rotation in 256-Color Modes..............................................379
Tricks with RGB Modes ................................................................381
Manual Color Transforms and Lookup Tables....................................381
The New DirectX Color and Gamma Controls Interface....................382
Mixing GDI and DirectX ....................................................................383
Getting the Lowdown on DirectDraw ................................................386
The Main DirectDraw Object ........................................................386
Surfing on Surfaces........................................................................388
Playing with Palettes......................................................................389
Using DirectDraw in Windowed Modes..............................................390
Drawing Pixels in a Window..........................................................392
Finding the Real Client Area (51)..................................................395
Clipping a DirectX Window ..........................................................397
Working with 8-Bit Windowed Modes..........................................398
Summary..............................................................................................400
8 Vector Rasterization and 2D Transformations 401
Drawing Lines......................................................................................402
Bresenham’s Algorithm..................................................................403
Speeding Up the Algorithm............................................................409
Basic 2D Clipping................................................................................411
Computing the Intersection of Two Lines Using the Point
Slope Form ..................................................................................413
Computing the Intersection of Two Lines Using
the General Form ........................................................................416
Computing the Intersection of Two Lines Using
the Matrix Form ..........................................................................416
Clipping the Line............................................................................419
The Cohen-Sutherland Algorithm..................................................420
Wireframe Polygons............................................................................427
Polygon Data Structures ................................................................428
Drawing and Clipping Polygons....................................................430
Transformations in the 2D Plane ........................................................432
Translation......................................................................................433
Rotation..........................................................................................435
Scaling............................................................................................445
Introduction to Matrices......................................................................446
The Identity Matrix........................................................................448
Matrix Addition..............................................................................449

0072313618 FM 10/26/99 9:32 AM Page x
x
TRICKS OF THE WINDOWS GAME PROGRAMMING GURUS
Matrix Multiplication ....................................................................449
Transformations Using Matrices....................................................452
Translation ..........................................................................................454
Scaling..................................................................................................455
Rotation................................................................................................455
Solid Filled Polygons ..........................................................................458
Types of Triangles and Quadrilaterals............................................459
Drawing Triangles and Quadrilaterals............................................461
Triangular Deconstruction Details ................................................464
The General Case of Rasterizing a Quadrilateral..........................472
Triangulating Quads ......................................................................473
Collision Detection with Polygons......................................................478
Proximity AKA Bounding Sphere/Circle ......................................478
Bounding Box ................................................................................481
Point Containment..........................................................................484
More on Timing and Synchronization ................................................486
Scrolling and Panning..........................................................................488
Page Scrolling Engines ..................................................................488
Homogeneous Tile Engines............................................................489
Sparse Bitmap Tile Engines ..........................................................494
Fake 3D Isometric Engines..................................................................496
Method 1: Cell-Based, Totally 2D ................................................496
Method 2: Full-Screen-Based, with 2D or 3D
Collision Networks......................................................................498
Method 3: Using Full 3D Math, with a Fixed Camera View ........500
The T3DLIB1 Library ........................................................................500
The Engine Architecture ................................................................500
Basic Definitions............................................................................501
Working Macros ............................................................................502
Data Types and Structures..............................................................503
Global Domination ........................................................................506
The DirectDraw Interface ..............................................................507
2D Polygon Functions....................................................................511
2D Graphic Primitives....................................................................513
Math and Error Functions..............................................................517
Bitmap Functions............................................................................519
Palette Functions............................................................................522
Utility Functions ............................................................................525
The BOB (Blitter Object) Engine........................................................527
Summary..............................................................................................535
9 Uplinking with DirectInput and Force Feedback 537
The Input Loop Revisited....................................................................538
DirectInput Overture............................................................................539
The Components of DirectInput ....................................................541
The General Steps for Setting Up DirectInput ..............................542

0072313618 FM 10/26/99 9:32 AM Page xi
xi
CONTENTS
Data Acquisition Modes ................................................................544
Creating the Main DirectInput Object............................................544
The 101-Key Control Pad ..............................................................546
Problem During Reading: Reacquisition........................................554
Trapping the Mouse........................................................................556
Working the Joystick......................................................................561
Massaging Your Input ....................................................................576
Going Deeper with Force Feedback....................................................579
The Physics of Force Feedback......................................................580
Setting Up Force Feedback............................................................580
A Force Feedback Demo................................................................581
Writing a Generalized Input System:
T3DLIB2.CPP ............................582
The T3D Library at a Glance ........................................................588
Summary..............................................................................................588
10 Sounding Off with DirectSound and DirectMusic 589
Sound Programming on the PC ..........................................................589
And Then There Was Sound…............................................................590
Digital versus MIDI—Sounds Great, Less Filling..............................594
Digital Sound—Let the Bits Begin................................................594
Synthesized Sound and MIDI........................................................596
It’s MIDI Time!..............................................................................597
Sound Hardware..................................................................................598
Wave Table Synthesis ....................................................................598
Wave Guide Synthesis....................................................................598
Digital Recording: Tools and Techniques............................................599
Recording Sounds ..........................................................................600
Processing Your Sounds ................................................................600
DirectSound on the Mic ......................................................................601
Starting Up DirectSound......................................................................602
Understanding the Cooperation Level............................................604
Setting the Cooperation Level........................................................605
Primary and Secondary Sound Buffers ..............................................606
Working with Secondary Buffers ..................................................606
Creating Secondary Sound Buffers................................................607
Writing Data to Secondary Buffers................................................610
Rendering Sounds................................................................................612
Playing a Sound..............................................................................612
Stopping a Sound............................................................................612
Controlling the Volume..................................................................612
Freaking with the Frequency..........................................................613
Panning in 3D ................................................................................614
Making DirectSound Talk Back..........................................................614
Reading Sounds from Disk..................................................................616
The
.WAV Format ............................................................................616
Reading
.WAV Files ........................................................................617

0072313618 FM 10/26/99 9:32 AM Page xii
xii
TRICKS OF THE WINDOWS GAME PROGRAMMING GURUS
DirectMusic: The Great Experiment ..................................................622
DirectMusic Architecture ....................................................................622
Starting Up DirectMusic......................................................................624
Initializing COM............................................................................624
Creating the Performance ..............................................................625
Adding a Port to the Performance..................................................626
Loading a MIDI Segment....................................................................626
Creating the Loader........................................................................627
Loading the MIDI File ..................................................................627
Manipulating MIDI Segments ............................................................630
Playing a MIDI Segment................................................................630
Stopping a MIDI Segment..............................................................631
Checking the Status of a MIDI Segment ......................................631
Releasing a MIDI Segment............................................................631
Shutting Down DirectMusic ..........................................................631
A Little DirectMusic Example ......................................................632
The
T3DLIB3 Sound and Music Library ..............................................632
The Header ....................................................................................633
The Types ......................................................................................633
Global Domination ........................................................................634
The DirectSound API Wrapper......................................................635
The DirectMusic API Rapper—Get It?..........................................640
Summary..............................................................................................643
PART III Hard Core Game Programming 645
11 Algorithms, Data Structures, Memory Management,
and Multithreading 647
Data Structures ....................................................................................648
Static Structures and Arrays ..........................................................648
Linked Lists....................................................................................649
Algorithmic Analysis ..........................................................................657
Recursion ............................................................................................659
Trees ....................................................................................................662
Building BSTs................................................................................666
Searching BSTs..............................................................................668
Optimization Theory............................................................................671
Using Your Head ............................................................................671
Mathematical Tricks ......................................................................672
Fixed-Point Math............................................................................673
Unrolling the Loop ........................................................................677
Look-Up Tables..............................................................................678
Assembly Language ......................................................................679
Making Demos ....................................................................................680
Prerecorded Demos........................................................................680
AI-Controlled Demos ....................................................................682

0072313618 FM 10/26/99 9:32 AM Page xiii
xiii
CONTENTS
Strategies for Saving the Game ..........................................................682
Implementing Multiple Players ..........................................................683
Taking Turns ..................................................................................683
Split-Screen Setups ........................................................................684
Multithreaded Programming Techniques ............................................685
Multithreaded Programming Terminology ....................................686
Why Use Threads in a Game?........................................................687
Conjuring a Thread from the Plasma Pool ....................................689
Sending Messages from Thread to Thread ....................................697
Waiting for the Right Moment ......................................................702
Multithreading and DirectX ..........................................................709
Advanced Multithreading ..............................................................711
Summary..............................................................................................711
12 Making Silicon Think with Artificial Intelligence 713
Artificial Intelligence Primer ..............................................................714
Deterministic AI Algorithms................................................................715
Random Motion..............................................................................716
Tracking Algorithms ......................................................................717
Anti-Tracking: Evasion Algorithms ..............................................722
Patterns and Basic Control Scripting ..................................................722
Basic Patterns ................................................................................723
Patterns with Conditional Logic Processing..................................727
Modeling Behavioral State Systems....................................................729
Elementary State Machines............................................................730
Adding More Robust Behaviors with Personality..........................734
Modeling Memory and Learning with Software ................................736
Planning and Decision Trees ..............................................................740
Coding Plans ..................................................................................742
Implementing a Real Planner ........................................................745
Pathfinding ..........................................................................................747
Trial and Error................................................................................748
Contour Tracing..............................................................................749
Collision Avoidance Tracks............................................................749
Waypoint Pathfinding ....................................................................750
A Racing Example..........................................................................753
Robust Pathfinding ........................................................................754
Advanced AI Scripting ........................................................................759
Designing the Scripting Language ................................................759
Using the C/C++ Compiler............................................................762
Artificial Neural Networks..................................................................767
Genetic Algorithms..............................................................................770
Fuzzy Logic ........................................................................................772
Normal Set Theory ........................................................................773
Fuzzy Set Theory............................................................................774

0072313618 FM 10/26/99 9:32 AM Page xiv
xiv
TRICKS OF THE WINDOWS GAME PROGRAMMING GURUS
Fuzzy Linguistic Variables and Rules............................................776
Fuzzy Manifolds and Membership ................................................779
Fuzzy Associative Matrices............................................................783
Processing the FAM with the Fuzzified Inputs..............................787
Warm and Fuzzy ............................................................................794
Building Real AI for Games................................................................794
Summary..............................................................................................795
13 Playing God: Basic Physics Modeling 797
Fundamental Laws of Physics ............................................................798
Mass (m) ........................................................................................799
Time (t) ..........................................................................................799
Position (s)......................................................................................800
Velocity (v) ....................................................................................802
Acceleration (a)..............................................................................804
Force (F) ........................................................................................807
Forces in Higher Dimensions ........................................................808
Momentum (P)................................................................................809
The Physics of Linear Momentum: Conservation and Transfer ........810
Modeling Gravity Effects....................................................................813
Modeling a Gravity Well................................................................815
Modeling Projectile Trajectories....................................................818
The Evil Head of Friction....................................................................821
Basic Friction Concepts..................................................................821
Friction on an Inclined Plane (Advanced) ....................................823
Basic Ad Hoc Collision Response ......................................................828
Simple x,y Bounce Physics............................................................828
Computing the Collision Response with Planes of
Any Orientation ..........................................................................830
An Example of Vector Reflection..................................................834
Intersection of Line Segments........................................................835
Real 2D Object-to-Object Collision Response (Advanced)................841
Resolving the n-t Coordinate System..................................................846
Simple Kinematics ..............................................................................853
Solving the Forward Kinematic Problem ......................................854
Solving the Inverse Kinematic Problem ........................................858
Particle Systems ..................................................................................859
What Every Particle Needs ............................................................859
Designing a Particle Engine ..........................................................860
The Particle Engine Software ........................................................861
Generating the Initial Conditions ..................................................866
Putting the Particle System Together ............................................869
Playing God: Constructing Physics Models for Games......................870
Data Structures for Physics Modeling............................................870
Frame-Based Versus Time-Based Modeling..................................871
Summary..............................................................................................873

0072313618 FM 10/26/99 9:32 AM Page xv
xv
CONTENTS
14 Putting It All Together: You Got Game! 875
The Initial Design of Outpost..............................................................876
The Story........................................................................................876
Designing the Gameplay................................................................877
The Tools Used to Write the Game ....................................................877
The Game Universe: Scrolling in Space..............................................878
The Player’s Ship: “The Wraith” ........................................................880
The Asteroid Field ..............................................................................882
The Enemies........................................................................................884
The Outposts ..................................................................................885
The Predator Mines........................................................................886
The Gunships..................................................................................888
The Power-Ups....................................................................................891
The HUDS ..........................................................................................892
The Particle System ............................................................................896
Playing the Game ................................................................................896
Compiling Outpost ..............................................................................897
Compilation Files ..........................................................................897
Runtime Files..................................................................................898
Epilogue ..............................................................................................898
P
ART IV Appendixes 901
A What’s on the CD 903
B Installing DirectX and Using the C/C++ Compiler 907
Using the C/C++ Compiler..................................................................908
C Math and Trigonometry Review 911
Trigonometry ......................................................................................911
Vectors..................................................................................................915
Vector Length ................................................................................916
Normalization ................................................................................917
Scalar Multiplication......................................................................917
Vector Addition ..............................................................................918
Vector Subtraction..........................................................................919
The Inner Product, or the “Dot” Product ......................................919
The Cross Product..........................................................................921
The Zero Vector..............................................................................923
Position Vectors..............................................................................923
Vectors as Linear Combinations ....................................................924

0072313618 FM 10/26/99 9:32 AM Page xvi
xvi
TRICKS OF THE WINDOWS GAME PROGRAMMING GURUS
D C++ Primer 925
What Is C++? ......................................................................................925
The Minimum You Need to Know About C++ ..................................928
New Types, Keywords, and Conventions............................................929
Comments ......................................................................................929
Constants........................................................................................929
Referential Variables ......................................................................929
Creating Variables On-the-Fly........................................................930
Memory Management..........................................................................931
Stream I/O............................................................................................932
Classes..................................................................................................934
The New Struct in Town ................................................................934
Just a Simple Class ........................................................................935
Public Versus Private......................................................................936
Class Member Functions (A.K.A. Methods) ................................937
Constructors and Destructors ........................................................938
Writing a Constructor ....................................................................939
Writing a Destructor ......................................................................941
The Scope Resolution Operator ..........................................................943
Function and Operator Overloading....................................................945
Summary..............................................................................................947
E Game Programming Resources 949
Game Programming Sites....................................................................949
Download Points..................................................................................950
2D/3D Engines ....................................................................................950
Game Programming Books..................................................................951
Microsoft DirectX Multimedia Exposition..........................................951
Usenet Newsgroups ............................................................................951
Keeping Up with the Industry: Blues News........................................952
Game Development Magazines ..........................................................952
Game Web Site Developers ................................................................953
Xtreme Games LLC ............................................................................953
F ASCII Tables 955
Index 961

2,644

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 硬件/系统
社区管理员
  • 硬件/系统社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧