Article 135396 of rec.games.programmer: Path: news.doit.wisc.edu!brodskye From: brodskye at cae.wisc.edu Newsgroups: rec.games.programmer Subject: Re: sound fx Date: 30 Jun 1997 18:51:00 GMT Organization: University of Wisconsin, Madison Lines: 49 Message-ID: <5p8v6k$lfo@news.doit.wisc.edu> References: <867644173.14837@dejanews.com> Reply-To: ebrodsky@pobox.com NNTP-Posting-Host: hp-4.cae.wisc.edu Originator: brodskye at hp-4.cae.wisc.edu In article <867644173.14837@dejanews.com>, wrote: >if a game has a lot of sound fx, so much as to really infringe of memory, >whats the best way to load/play them? do games with megs of sound fx >really load them all into memory? reading them all off the hard drive >obviously seems inefficient as well. how do programmers balance this? i'm >making a dos game with a lot of sound fx and want to conserve some memory >but not at the expense of killing the speed. should i just sample lower >and load everything or is there a trick? thanks Since you're worried about memory, I'm assuming you're working in real-mode. If you want to work only with conventional memory, then you're going to need to do some extra work. For short sounds that occur often in response to user actions (gunshots and stuff that should be available instantly), you really have no choice but to keep them in memory at all times. Try to make a list of which sounds will be required for each level, then load them at the begining, and unload them at the end. For larger sounds that occur less frequently and in a more predictable manner, you can get away with loading them on demand and discarding them when you're finished playing. However, if you have cut screens or something with long sound effects, you're still going to run out of memory. One thing you can do is load the sound in small chunks. Allocate a small buffer (enough for a second or so of audio is best, since that will prevent interruptions if the disk is busy). Treat it as a circular buffer, with 4 or so segments, loading a segment with new data as soon as it is finished playing. Copy the data out of that buffer into your DMA buffer. Another solution is to use extended (XMS) or expanded (EMS) memory. Expanded memory is slightly more efficient when you're trying to make things go fast, but I've vowed never to use it, so I'll discuss XMS. With XMS, you can usually load all the sounds into memory at once. However, you can't access them without copying to conventional memory. Think of extended memory as a really fast hard disk. You can't just access it randomly like an array in memory, you have to "load" or "save" the data to/from conventional memory. The moves can require a switch to protected mode, so it's best to try to minimize them. My SMIX library, available from my WWW page, at the URL listed in my .sig, uses the extended memory technique described above. Versions are available for Turbo Pascal, Borland C, and Watcom C DOS/4GW. Ethan Brodsky -- ---- Ethan Brodsky