Podstrony
- Strona startowa
- Stalo sie jutro Zbior 24
- [eBook] DirectX 3D Graphics Programming Bible
- (ebook pdf) Teach Yourself SQL in 21 Days
- Teach Yourself Visual C 6 in 21 days
- Sams' Teach Yourself Linux In 24 Hours
- SAMS Teach Yourself PHP4 in 24 Hours
- Asimov Isaac Narodziny Fundacji (SCAN dal 10
- Koonz Dean R Tunel strachu
- Rowling J K Harry Potter i wiezien Azkabanu
- Silverberg Robert Valentine Pontifex (SCAN dal 10
- zanotowane.pl
- doc.pisz.pl
- pdf.pisz.pl
- ugrzesia.htw.pl
[ Pobierz całość w formacie PDF ]
.Figures 6.2 and 6.3 reveal the circular nature of sound buffers by visuallyshowing two approaches to a 2KB lock within a 3KB buffer.FIGURE 6.2 Locked Data Unlocked DataA 2KB lock performedfrom the beginning of0 KB 1 KB 2 KB 3 KBa 3KB sound buffer.Pointer 1 Pointer 2 = NULLLocked Data Unlocked Data Locked DataFIGURE 6.3A 2KB lock performedat 2KB into a0 KB 1 KB 2 KB 3 KB3KB sound buffer,resulting in a circularwraparound.Pointer 2 Pointer 1In Figure 6.3, the buffer data is circular because there isn t room to write 2KB ofdata when there is only 1KB left until the end of the buffer.So, the remaining 1KBis wrapped around to the beginning of the buffer.Two data pointers are necessary toaccount for the wraparound.Although this is a nice feature, in most cases you will lockthe entire buffer, which means that you ll only use the first data pointer passed to theLock() method.It s very important not to leave buffers locked for long periods of time.This is because ofthe fact that you might be playing a buffer as you are writing to it, and keeping the buffer6locked for too long might result in the play cursor catching up with the locked data.Thiscan result in random noise, which is a bad thing.You call the Unlock() method to unlocka sound buffer:HRESULT Unlock(LPVOID lpvAudioPtr1, DWORD dwAudioBytes1, LPVOID lpvAudioPtr2,¥'DWORD dwAudioBytes2);As you can see, the Unlock() function takes four of the same parameters that you passedinto Lock().This allows it to properly free the memory that was locked down.10 1634xCH06 11/13/99 11:23 AM Page 108108 Hour 6Playing and Stopping a Sound BufferThe Play() method is used to play sound buffers.Playing a buffer actually means thatthe buffer is mixed into the primary buffer, which is then output to the sound device.IfPlay() is called on a buffer that is already playing, the call succeeds without interruptingplay.Following is the prototype for the Play() function:HRESULT Play(DWORD dwReserved1, DWORD dwReserved2, DWORD dwFlags);The first two parameters to Play() are reserved and must be passed as 0.The last para-meter is a flag that specifies how the buffer is to be played.The only flag defined inDirectSound is DSBPLAY_LOOPING, which indicates that the buffer is to continue playingover and over until it is explicitly stopped.You pass 0 to indicate that the buffer is to onlybe played once.To stop playing a sound buffer, you call the Stop() method.Stop() is most commonlyused to stop the play of looping sound buffers, which don t stop playing on their own.Following is the prototype for the Stop() function:HRESULT Stop();There isn t too much more to say about Stop(); just call it on a buffer to stop it.Getting Sound Buffer StatusYou can obtain information about the status of a sound buffer by calling the GetStatus()method:HRESULT GetStatus(LPDWORD lpdwStatus);The only parameter to GetStatus() is a pointer to a DWORD, lpdwStatus, which is wherethe resulting buffer status is stored.The status of the buffer consists of whether the bufferis currently playing, whether it is looping, and whether the buffer has been lost.Ofcourse, a buffer must be playing for it to be looping.The three corresponding status flagsare DSBSTATUS_PLAYING, DSBSTATUS_LOOPING, and DSBSTATUS_BUFFERLOST.In the event of a buffer being lost, as indicated by the DSBSTATUS_BUFFERLOST flag, youmust call the Restore() method and then reinitialize the sound buffer data.You learnhow to do this in the next hour when you put DirectSound to work.Setting Sound Buffer VolumeYou get and set the volume of a DirectSoundBuffer object by calling the GetVolume()and SetVolume() methods:HRESULT GetVolume(LPLONG lplVolume);HRESULT SetVolume(LONG lVolume);10 1634xCH06 11/13/99 11:23 AM Page 109DirectSound Adding Ambience and Sound Effects to Your Game 109Volume is measured in hundredths of decibels (dB), which results in possible valuesranging from 10,000 to 10,000.Negative volumes attenuate a sound whereas positivevolumes amplify a sound; a volume of zero results in a sound being played at itsrecorded level.Controlling Sound Buffer PanningTo get and set the panning of a DirectSoundBuffer object, you must call the GetPan()and SetPan() methods:HRESULT GetPan(LPLONG lplPan);HRESULT SetPan(LONG lPan);The panning of a sound buffer determines how the sound is played with respect to theleft and right speakers.Panning is expressed in hundredths of decibels (dB), which deter-mines how much a channel is attenuated.Panning values range from 10,000 to 10,000,with negative values attenuating the right channel and positive values attenuating the leftchannel; a panning value of zero results in both channels at full volume.It s important tonote that panning is applied in addition to volume settings.Altering Sound Buffer FrequencyYou get and set the frequency of a DirectSoundBuffer object by calling theGetFrequency() and SetFrequency() methods:HRESULT GetFrequency(LPDWORD lpdwFrequency);HRESULT SetFrequency(DWORD dwFrequency);Frequency is measured in Hertz (Hz), with possible values ranging from 100 to 100,000.Keep in mind that sounds are typically recorded at 11,250Hz (11kHz), 22,500Hz(22kHz), or 44,100Hz (44kHz).So, you can effectively slow down a 22kHz sound bysetting its frequency to 15,000Hz, for example.Static and Streaming Sound BuffersIt s worth pointing out that the DirectSoundBuffer object supports both static andNEW TERM6streaming sound buffers.A static sound buffer is a buffer that contains an entiresound in memory, whereas a streaming sound buffer usually contains only part of a soundand requires the application to write new data to the sound buffer as the buffer is beingplayed.Static buffers are more efficient because DirectSound will store them directly inthe memory of a hardware audio device if possible.If a static buffer can be stored in thehardware audio device s memory, the sound hardware takes on the task of mixing theaudio, which is much faster than leaving it up to the system CPU.It is also possible touse hardware mixing with streaming sound buffers providing that the system data bus isfast enough to transfer the stream of data to the audio hardware as it is delivered.10 1634xCH06 11/13/99 11:23 AM Page 110110 Hour 6Unless you are building an application that pulls audio from the Internet, you will morethan likely want to use static sound buffers because they are more efficient.It is impor-tant to point out that audio hardware memory is limited, which means that there mightnot be enough room for it to hold all the static sound buffers you are using.Therefore,you should prioritize sound buffers so that the most commonly played buffers have thebest chance of being stored directly in audio hardware memory
[ Pobierz całość w formacie PDF ]