ÀÌ°ÍÀº 1999³â ÇÏÀÌÅÚ °ÔÀÓ Á¦ÀÛ µ¿È£È¸¿¡ ¿Ã·È´ø °­Á 4ȸºÐ ÀÔ´Ï´Ù.

#####################################################

------------------------------------------------------------------------
### µ¨ÆÄÀÌ·Î ÇÏ´Â Direct X - Direct Sound (1/4)

    1. Direct Sound ÀÇ °³¿ä
    ~~~~~~~~~~~~~~~~~~~~~~~
    2. Direct Sound ÃʱâÈ­¿Í Wave Àбâ
    3. ¹öÆÛ¸¦ ÅëÇÑ Ãâ·Â°ú ¹Í½Ì
    4. 3D ¹öÆÛ¸¦ ÅëÇÑ Ãâ·Â°ú ¹Í½Ì

------------------------------------------------------------------------
                                    ÀÛ¼ºÀÚ : ¾È¿µ±â ( HiTEL ID : SMgal )

------------------------------------------------------------------------

(1) Direct Sound ¶õ ¹«¾ùÀΰ¡ ?

Direct Sound ´Â Direct X ¿¡¼­  Wav ¸¦ Ãâ·ÂÇϰųª ¹Í½Ì Çϴµ¥ ÁÖ·Î »ç¿ëµÇ
¸ç »ç¿îµå¸¦ ĸÃç ÇÏ´Â µ¥µµ »ç¿ëµÈ´Ù.

ÀÌÀü DOS ½ÃÀý¿¡´Â, »ç¿îµå Ä«µå¸¦ »ç¿îµå Æ÷Æ®¸¦ ÅëÇØ Á÷Á¢ ÀÔÃâ·ÂÇÏ´Â ¹æ½Ä
À¸·Î ¸ðµç À½À» Ãâ·ÂÇÏ´Â ¶§°¡ ÀÖ¾ú´Ù. AdLib Æ÷Æ®³ª MPU-401 MIDI Æ÷Æ®¸¦ Åë
ÇØ ¹è°æÀ½¾ÇÀ» ¿¬ÁÖÇßÀ¸¸ç »ç¿îµå ºí·¡½ºÅÍ DMA ·Î WAV ¸¦ Ãâ·ÂÇØ¾ß Çß¾ú´Âµ¥,
±× Á¤µµÀÇ ½Ç·ÂÀ» °®Ãß¸é ²Ï³ª ÀÎÁ¤¹Þ´ø ¶§¿´´Ù.

ÇÏÁö¸¸ ÀÌÁ¦´Â ½Ã´ë°¡ º¯Çß´Ù. À©µµ¿ìÁî¶ó´Â OS°¡ µîÀåÇÏ´õ´Ï ÀÌ·± ½ÄÀ¸·Î ÇÏ
µå¿þ¾î¿¡ Á¢±ÙÇÏ´Â ¹æ¹ýÀ» ¸ðµÎ ¸·¾Æ ¹ö¸° °ÍÀÌ´Ù.  ±×¸®°í´Â WAV ¸¦ Á¦¾î ÇÒ
¼ö ÀÖ´Â API ±âº» ÇÔ¼öµé°ú waveOut.... À¸·Î ½ÃÀÛÇÏ´Â Àú¼öÁØ WAV ÀÔÃâ·Â ÇÔ
¼ö¸¦ Á¦°øÇß´Ù. ÇÏÁö¸¸ ±× ÇÔ¼ö¸¸À¸·Î´Â Á÷Á¢ »ç¿îµå Ä«µåÀÇ Çϵå¿þ¾î °¡¼ÓÀ»
ÀÌ¿ëÇÑ ¹Í½ÌÀ̳ª latency °ÅÀÇ ¾ø´Â °í¼ÓÀÇ Ãâ·ÂÀº Á¦°øÇÏÁö ¸øÇß´Ù.

ÀÌ·± ¿¬À¯¿¡¼­ Microsoft ¿¡¼­´Â Game SDK ¶ó´Â °ÍÀ» ÅëÇØ,  Çϵå¿þ¾î °¡¼ÓÀ»
ÀÌ¿ëÇÒ ¼ö ÀÖ´Â ¹æ¹ýÀ» Á¦½ÃÇÏ¿´°í ±×°ÍÀÌ Direct Sound °¡ µÇ¾ú´ø °ÍÀÌ´Ù.

Direct Sound µµ ¿ª½Ã COM À» ±â¹ÝÀ¸·Î ÇÑ´Ù.  ¸ðµç ÀÎÅÍÆäÀ̽º´Â IUnknownÀ»
±â¹ÝÀ¸·Î ÇÏ°í ÀÖÀ¸¸ç QueryInterface ¸¦ ÅëÇØ  ´ÙÀ½ ÀÎÅÍÆäÀ̽ºÀÇ  Æ÷ÀÎÅ͸¦
¾ò¾î ¿À´Â ¹æ½ÄÀ» ±×´ë·Î ÅÃÇÏ°í ÀÖ´Ù.  Direct Sound ÀÇ ÀÎÅÍÆäÀ̽º  °èÅëÀº
´ÙÀ½°ú °°´Ù.

IDirectSound
     |
     +------ IDirectSoundBuffer
                     |
                     +----------- IDirectSound3DBuffer
                     |
                     +----------- IDirectSound3DListener
                     |
                     +----------- IDirectSoundNotify
                     |
                     +----------- IKsPropertySet

IDirectSoundCapture
     |
     +----------- IDirectSoundCaptureBuffer


±×·³ Çϳª¾¿ ÀÎÅÍÆäÀ̽º¸¦ ¼³¸íÇØ º¸¸é,

1) IDirectSound

   - Direct Sound ÀÇ ÁÖ°¡ µÇ´Â °´Ã¼ÀÌ´Ù.  ¿©±â¼­ IDirectSoundBuffer °´Ã¼
     ¸¦ »ý¼º ÇÒ ¼ö ÀÖ°í, 1Â÷ ¹öÆÛ¿Í 2Â÷ ¹öÆÛ¸¦ ¸¸µé¾î ³½´Ù.

2) IDirectSoundBuffer

   - 1Â÷ ¹öÆÛ ¶Ç´Â 2Â÷ ¹öÆÛ°¡ µÇ´Â °´Ã¼ÀÌ´Ù. 1Â÷ ¹öÆÛ´Â Çϳª¸¸ ÀÖ¾î¾ß ÇÏ
     Áö¸¸  2Â÷ ¹öÆÛ´Â ¿©·¯ °³°¡ µ¿½Ã¿¡ Á¸ÀçÇÒ ¼ö ÀÖÀ¸¸ç  2Â÷ ¹öÆÛ¿¡ ÀÖ´Â
     WAVµéÀÌ ¹Í½Ì µÇ¾î¼­ 1Â÷ ¹öÆÛ·Î °¡°Å³ª Á÷Á¢ ¹öÆÛ¿¡ Á¢±ÙÇÏ¿© µ¥ÀÌÅ͸¦
     Á¶ÀÛÇÒ ¼öµµ ÀÖ´Ù.

3) IDirectSound3DBuffer

   - 3D »óÀÇ À½Çâ È¿°ú¸¦ ³ªÅ¸³¾ ¶§  ¾ÆÁÖ ÆíÇÏ°Ô ±× È¿°ú¸¦ ³ªÅ¸³¾ ¼ö ÀÖ°Ô
     ÇØÁØ´Ù. ´ÜÁö ¼Ò¸®°¡ ³ª¿Ã (x,y,z) ÁÂÇ¥¿¡ ´ëÇÑ Å©±â °ª¸¸ Á¤ÇØÁÖ¸é  ¾Ë
     ¾Æ¼­ È¿°úÀ½À» ±×¿¡ ¸Â°Ô Ãâ·ÂÇØÁØ´Ù.  ÀÏ´Ü  IDirectSound3DBuffer  ´Â
     IDirectSoundBuffer ÀÇ ¿¬ÀåÀ̱⠶§¹®¿¡  IDirectSoundBuffer ¿¡¼­ ±¸Çö
     ÇÏ´Â °Íº¸´Ù´Â ´À·ÁÁø´Ù. ( »ç¿îµå Ä«µåÀÇ ¿µÇâÀ» ¸¹ÀÌ ¹Þ¾Æ¼­, ½ÇÁ¦ ±×
     Ä«µåÀÇ ¼º´É¿¡ µû¶ó 3D À½ÇâÀÌ ÀüÇØÁø´Ù. )

4) IDirectSound3DListener

   - IDirectSound3DBuffer °¡ À½¿øÀ» ±âÁØÀ¸·Î ¼Ò¸®°¡ ³ª´Â À§Ä¡¸¦ Á¤Çß´Ù¸é
     IDirectSound3DListener ´Â  µè´Â »ç¶÷À»  ±âÁØÀ¸·Î ÇÑ´Ù.  À½ÇâÀ» µè´Â
     »ç¶÷ÀÌ À§Ä¡¸¦ À̵¿ÇÑ´Ù¸é À½¿øÀÌ °íÁ¤µÇ¾î ÀÖ´õ¶óµµ  ±Í¿¡¼­ µé¸®´Â À§
     Ä¡´Â ´Ù¸£±â ¶§¹®ÀÌ´Ù.

5) IDirectSoundCapture

   - DirectSound ÀÇ ¿ä¼ÒÀÌÁö¸¸ IDirectSound ¿Í´Â º°µµ·Î Create ÇØÁà¾ß ÇÏ
     ´Â  °´Ã¼ÀÌ´Ù.  ÀÌ°ÍÀº  »ç¿îµå¸¦  Ä¸ÃçÇÏ±â  À§Çؼ­  »ç¿ëÇÏ´Â °ÍÀε¥,
     waveIn... ÀÇ Á¢µÎ¾î·Î ½ÃÀÛÇÏ´Â »ç¿îµå ÀÔ·Â API ¸¦  ·¡ÇÎ(wrapping)ÇÑ
     ¼öÁØÀ¸·Î, Çϵå¿þ¾î °¡¼ÓµîÀÇ ÀÌÁ¡Àº ¾øÀ¸³ª ¼Õ½±°Ô »ç¿îµå ÀÔ·Â ¹öÆÛ¸¦
     °ü¸®ÇÒ ¼ö ÀÖ°í ÀÚµ¿À¸·Î ¼øȯ ¹öÆÛ¸¦ ±¸¼ºÇØÁØ´Ù.

6) IDirectSoundCaptureBuffer

   - IDirectSoundCapture ¸¦  »ç¿ëÇϱâ À§ÇÑ ¹öÆÛÀÌ´Ù.  IDirectSoundBuffer
     ¿Í °°Àº ¸Æ¶ôÀ¸·Î ÀÌÇØÇÏ¸é µÈ´Ù.

7) IDirectSoundNotify

   - WAV Ãâ·ÂÀÇ Ç÷¹À̹éÀ̳ª ÀԷ¿¡ ´ëÇÑ ¾Ë¸² À̺¥Æ®¸¦ ¼³Á¤ÇÒ ¼ö ÀÖ´Ù.
     SetNotificationPositions() À̶ó´Â  ´Ü ÇϳªÀÇ ¿À¸®Áö³¯ ¸Þ½îµå¸¦ °¡Áö
     °í ÀÖ´Ù.

8) IKsPropertySet

   - »ç¿îµå Ä«µå ÀÚüÀÇ È®ÀåµÈ Á¤º¸¸¦ ¾ò°Å³ª ´Ù½Ã ¼³Á¤ ÇÒ ¶§ »ç¿ëÇÑ´Ù.
     À̸§ÀÌ ¿©Å¸ÀÇ Direct Sound ÀÇ ÀÎÅÍÆäÀ̽º¿Í´Â ´Ù¸¥µ¥,  ÀÌ ÀÎÅÍÆäÀ̽º
     ´Â WDM KS (Win32 driver model kernel streaming) ÀÇ ºÎºÐÀÌ±â  ¶§¹®ÀÌ
     ´Ù.


À̹øÀÇ Direct Sound °­Á¿¡¼­´Â IDirectSoundCapture ÀÌÈÄÀÇ °ÍÀº ´Ù·çÁö ¾Ê
°Ú´Ù. ½ÇÁ¦·Î waveIn... °è¿­ÀÇ API ¸¸À¸·Îµµ ÃæºÐÈ÷ °¡´ÉÇÑ ±â´ÉµéÀÌ°í,  ÇÊ
ÀÚ°¡ Direct Sound ÀÇ Ä¸Ãç ±â´ÉÀ» ¾Ë±â Àü¿¡  ÀÌ¹Ì waveIn À¸·Î ³ìÀ½ ·çƾÀ»
¸¸µé¾ú¾ú±â ¶§¹®¿¡ Áö±Ýµµ ±×°ÍÀ» »ç¿ëÇÏ°í ÀÖ´Ù.  Áï,  IDirectSoundCapture
ÂÊÀº  ¸ð¸¥´Ù´Â À̾߱â´Ù.  ±×¸®°í IDirectSoundNotify ³ª IKsPropertySet ÀÇ
¿ëµµ¿¡ ¸Â´Â ÇÁ·Î±×·¥À» Â¥º» ÀûÀÌ ¾ø¾î¼­ ±×ÂÊÀÇ Áö½Äµµ Àü¹«ÇÏ´Ù.

Ȥ½Ã³ª ÇÊÀÚ°¡ ´Ù·çÁö ¾Ê´Â ºÎºÐ¿¡ ´ëÇؼ­ ±Ã±ÝÇϽŠºÐµéÀº Á÷Á¢ DirectX SDK
¿¡ µþ·Á¿À´Â µµÅ¥¸àÆ®¸¦ Àо½Ã±â ¹Ù¶õ´Ù. Á¤¸» ÀÚ¼¼ÇÏ°Ô ¼³¸íµÇ¾î Àֱ⠶§
¹®¿¡ ´Ù¸¥ Ã¥ÀÌ ÀüÇô ÇÊ¿ä°¡ ¾øÀ» Á¤µµÀÌ´Ù.  Áö±Ý ÀÌ ±ÛÀ» ÀûÀ¸¸é¼­µµ ¶Ç ´Ù
¸¥ â¿¡´Â Direct Sound µµÅ¥¸àÆ®¸¦ ¶ç¿ö ³õ°í °°ÀÌ ÂüÁ¶ÇÏ°í ÀÖ´Ù.

------------------------------------------------------------------------

                                                          1999 / 11 / 07

#####################################################


------------------------------------------------------------------------
### µ¨ÆÄÀÌ·Î ÇÏ´Â Direct X - Direct Sound (2/4)

    1. Direct Sound ÀÇ °³¿ä
    2. Direct Sound ÃʱâÈ­¿Í Wave Àбâ
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    3. ¹öÆÛ¸¦ ÅëÇÑ Ãâ·Â°ú ¹Í½Ì
    4. 3D ¹öÆÛ¸¦ ÅëÇÑ Ãâ·Â°ú ¹Í½Ì

------------------------------------------------------------------------
                                    ÀÛ¼ºÀÚ : ¾È¿µ±â ( HiTEL ID : SMgal )

------------------------------------------------------------------------

(1) Direct Sound ÀÇ ÃʱâÈ­

Direct Sound µµ COM À» ±â¹ÝÀ¸·Î ÇÏ´Â ¿©Å¸ÀÇ Direct X ÀÇ ¿ä¼Òµé°ú ¿Í °°ÀÌ,
COM ¹æ½ÄÀÇ ÃʱâÈ­¿Í Create ¹æ½ÄÀÇ ÃʱâÈ­ µÑ ´Ù¸¦ Áö¿øÇÏ´Ù. ( ´Ü, °¡Àå ÃÖ
±Ù¿¡ »ý±ä Direct Music ÀÇ °æ¿ì¿¡´Â COM ¹æ½Ä¸¸ Áö¿øÇÑ´Ù. )

COM ¹æ½ÄÀÇ ÃʱâÈ­´Â

|   CoInitialize(nil);
|   CoCreateInstance(CLSID_ .... );

¿Í °°Àº ÀüÇüÀûÀÎ ¸ð½ÀÀ» ÇÏ°í Àִµ¥.. ÀÌ ¹æ¹ýÀº ´ÙÀ½ÀÇ Direct Music °­ÁÂ
¿¡¼­ ÀÚ¼¼ÇÏ°Ô ´Ù·ç°Ú´Ù.

Create ÇÔ¼ö¿¡ ÀÇÇÑ ¹æ¹ýÀº DirectSoundCreate ¶ó´Â ÇÔ¼ö¸¦ »ç¿ëÇÏ´Â °ÍÀÌ´Ù.
½ÇÁ¦ »ç¿ë¹ýÀº ¾Æ·¡¿Í °°´Ù.

|   DirectSoundCreate(nil,DirectSound,nil);
|   if not Assigned(DirectSound) then ..... // »ý¼º ½ÇÆÐ

ù¹ø° ÆĶó¸ÞÅÍ´Â »ç¿îµå µð¹ÙÀ̽ºÀÇ GUID ¸¦ ³Ö´Â ºÎºÐÀε¥, »ç¿îµå Ä«µå°¡
2°³ ÀÌ»óÀÏ ¶§ ¾î¶² °ÍÀ» »ç¿ëÇÒ °ÍÀÎÁö¸¦ ¾Ë·ÁÁÖ´Â °ÍÀÌ´Ù. ¸¸¾à GUID°¡ nil
À̶ó¸é µðÆúÆ®ÀÇ »ç¿îµå µð¹ÙÀ̽º°¡ ¼±ÅõȴÙ.

µÎ¹ø° ÆĶó¸ÞÅÍ´Â Direct Sound °´Ã¼¸¦ ¹Þ±â À§ÇÑ  Direct Sound ÀÎÅÍÆäÀ̽º
ÀÇ ÀνºÅϽº¸¦ ·¹ÆÛ·±½º·Î ³Ö´Â´Ù. ¿©±â¼­´Â DirectSound °¡ IDirectSound ·Î
¼±¾ðµÈ °´Ã¼ÀÇ º¯¼öÀ̸ç,  ÇÔ¼ö°¡ ½ÇÆÐÇÏ°Ô µÇ¸é DirectSound °¡ nil ÀÌ µÇ°Ô
µÈ´Ù.

¼¼¹ø° ÆĶó¸ÞÅÍ´Â Ç×»ó nil ÀÌ´Ù.


ÀÌ·¸°Ô Direct Sound °´Ã¼¸¦ ¹Þ¾ÒÀ¸¸é ÀÌ ÇÁ·Î±×·¥ÀÌ ´Ù¸¥ ÇÁ·Î±×·¥°ú ¾î¶°ÇÑ
¹æ½ÄÀ¸·Î  »ç¿îµå µð¹ÙÀ̽º¸¦ °øÀ¯ÇÒ °ÍÀΰ¡¸¦ ¾Ë·ÁÁÖ´Â  'Çù·Â ·¹º§ ¼³Á¤'À»
ÇØ¾ß ÇÑ´Ù. ±× »ç¿ë¹ýÀ» º¸¸é ´ÙÀ½°ú °°´Ù.

|   DirectSound.SetCooperativeLevel(Handle,DSSCL_NORMAL);

ù¹ø° ÆĶó¸ÞÅÍ´Â À©µµ¿ìÀÇ ÇÚµéÀÌ µé¾î°£´Ù.

µÎ¹ø° ÆĶó¸ÞÅÍ¿¡´Â Çù·Â ·¹º§À» ¼³Á¤ÇÏ´Â °ªÀÌ µé¾î°¡´Âµ¥...

   DSSCL_NORMAL       : ´Ù¸¥ ÇÁ·Î±×·¥°ú »ç¿îµå µð¹ÙÀ̽º¸¦ °øÀ¯ÇÑ´Ù. À©µµ
                        ¿ìÀÇ ¹Ìµð¾î Ç÷¹À̾¼­ MP3 ¸¦ ¿¬ÁÖÇϸ鼭, ´Ù½Ã
                        ¹Ìµð¾î Ç÷¹À̾î·Î  µ¿¿µ»óÀ» µ¹·Áµµ  µÑ ´Ù ¼Ò¸®°¡
                        Á¦´ë·Î ³ª¿À´Â ÀÌÀ¯°¡ ÀÌ·¸°Ô ¼­·ÎÀÇ ·¹º§À» ¼³Á¤ÇÏ
                        ±â ¶§¹®ÀÌ´Ù.

   DSSCL_PRIORITY     : ÀÌ ÇÁ·Î±×·¥¿¡ »ç¿îµå µð¹ÙÀ̽º¿¡ ´ëÇÑ ¿ì¼± ¼øÀ§¸¦
                        ÁØ´Ù. ÀÌ ·¹º§ÀÏ ¶§, SetFormat() ÇÔ¼ö¿Í Compack()
                        ÇÔ¼ö¸¦ »ç¿ëÇÒ ¼ö ÀÖ´Ù. Áï 1Â÷ ¹öÆÛÀÇ Ãâ·Â Æ÷¸ËÀ»
                        º¯°æÇÒ ¼ö°¡ ÀÖ´Ù´Â °ÍÀÌ´Ù.

   DSSCL_EXCLUSIVE    : ÀÌ ÇÁ·Î±×·¥ »ç¿îµå µð¹ÙÀ̽º¸¦ µ¶Á¡Àû(¹èŸÀû)À¸·Î
                        »ç¿ëÇÑ´Ù. WinAMP ¿¡¼­ MP3 ¸¦ µè°í ÀÖÀ» ¶§ ¹Ìµð¾î
                        Ç÷¹À̾¼­ À½¾ÇÀ» µéÀ¸·Á¸é  ¿¡·¯°¡ ³ª´Â ÀÌÀ¯°¡
                        ÀÌ ¶§¹®ÀÌ´Ù.

   DSSCL_WRITEPRIMARY : 1 Â÷ ¹öÆÛ¿¡  ¹Ù·Î Á¢±Ù ÇÒ ¼ö ÀÖ´Â  ÃÖ°íÀÇ ±ÇÇÑÀ»
                        °¡Áø´Ù. 1 Â÷ ¹öÆÛ¿¡¼­ Á÷Á¢ ¹Í½ÌÀ» °¡´ÉÇÏ°Ô ÇØ ÁÖ
                        ±â ¶§¹®¿¡ »ç¿ëÀÚ°¡ »ç¿îµå ¹Í½ÌÀ» ÇؾßÇÏ´Â Àǹ«¸¦
                        °¡Áø´Ù.

------------------------------------------------------------------------

(2) Wave ÆÄÀÏ Àбâ

½ÇÁ¦·Î Wave ÆÄÀÏ Àбâ´Â Direct Sound ÀÇ °´Ã¼³ª ¸Þ½îµå¿Í´Â ¹«°üÇÏ´Ù. µµ¸®
¾î waveOut... Á¢µÎ¾î¸¦ °¡Áø ¸ÖƼ¹Ìµð¾î API ¸¦ À§ÇÑ  ¹æ½ÄÀ̶ó°í º¸´Â °ÍÀÌ
¸Â´Ù. ÇÏÁö¸¸ Direct Sound ¿¡¼­´Â Á÷Á¢ WAV ÆÄÀÏÀ» ÀÛ¾÷ÇÏ´Â ¹öÆÛ¿¡ ¿Ã·Á ÁÖ
´Â ÇÔ¼ö°¡ ¾ø±â ¶§¹®¿¡ Á÷Á¢ WAV ÆÄÀÏÀ» Àо ¹öÆÛ¿¡ ¿Ã¸®´Â ¼ö ¹Û¿¡ ¾ø´Ù.
ÇÏÁö¸¸ ´ÙÇàÀ̵µ ¸ÖƼ¹Ìµð¾î I/O API ¿¡  WAV °°Àº RIFF Æ÷¸ËÀ» Àбâ À§ÇÑ ÀÔ
Ãâ·Â ÇÔ¼ö°¡ ¹Ì¸® Á¤ÀǵǾî Àִµ¥´Ù°¡  WAV Æ÷¸Ë ÀÚü°¡ ±²ÀåÈ÷ °£´ÜÇϱ⠶§
¹®¿¡ ±×³ª¸¶ ¿ì¸®°¡ ¸Ó¸®¸¦ ½Î¸Å¾ß ÇÒ Á¤µµ´Â ¾Æ´Ï°Ô µÇ¾ú´Ù.

¾Æ·¡ÀÇ ¼Ò½º´Â Wave ÆÄÀÏÀ» ¹öÆÛ¿¡ Àд ÇÔ¼öÀÌ´Ù. ¼³¸íÀº ´ç¿¬È÷ ÁÖ¼®¿¡´Ù°¡
ÇØ ³õ°Ú´Ù.
( Á÷Á¢ »ç¿ëÇÏ´ø °ÍÀε¥, ºÒÇÊ¿ä ÇÑ°ÍÀ» »©´Ùº¸´Ï Ȥ½Ã ¿À·ù°¡ ÀÖÀ»Áöµµ ¸ð¸¥
  ´Ù. )

| var
|    Buffer        : PByte;  // Àü¿ª º¯¼ö, ¶Ç´Â Ŭ·¡½º³»ÀÇ ¸â¹ö º¯¼ö
|
|
| function    LoadWave(FileName : PChar) : integer;
| var
|    mmIO          : HmmIO;
|    Parent, Child : TmmCkInfo;
|    WaveFormatEx  : TWaveFormatEx;
| begin
|    LoadWave := -1;                       // ½ÇÆÐ ÄÚµå
|
|    FillChar(Parent,sizeof(TmmCkInfo),0); // ºÎ¸ð ûũ ÃʱâÈ­
|    FillChar(Child ,sizeof(TmmCkInfo),0); // ÀÚ½Ä Ã»Å© ÃʱâÈ­
|
|    mmIO  := mmioOpen(FileName,nil,MMIO_READ or MMIO_ALLOCBUF);
|       // FIleName ÀÇ ÆÄÀÏÀ» Àбâ Àü¿ëÀ¸·Î ¿¬´Ù.
|
|    if mmIO = 0 then exit;
|       // ¸¸¾à ÆÄÀÏ ÇÚµéÀÎ mmIO °¡ 0 À̸é ( ÇÔ¼ö ½ÇÆÐ ) Á¾·á
|
|    Parent.fccType := mmioFOURCC('W','A','V','E');
|       // Parent ûũÀÇ Å¸ÀÔÀ» 'WAVE' ¶ó´Â 4bytes ¹®ÀÚ·Î ³Ö´Â´Ù.
|    if mmioDescend(mmIO,@Parent,nil,MMIO_FINDRIFF) <> 0 then begin
|       // 'RIFF' ¸¦ ãÀº ÈÄ ±× ¾Æ·¡ÀÇ 'WAVE' ¹®ÀÚ¿­À» ã´Â´Ù.
|       // ¸¸¾à 0 ÀÌ ¾Æ´Ñ °ªÀÌ µ¹¾Æ¿À¸é ÀÌ ÆÄÀÏÀº Wav ÆÄÀÏÀÌ ¾Æ´Ï´Ù.
|       // ¿©±â¿¡ º¸¸é Parent º¯¼ö¸¦ Child ûũ ÂÊÀ¸·Î ³Ö´Â´Ù.
|       // ³ªÁß¿¡ ÀçÈ°¿ëÀ» À§Çؼ­ ÀÌ·¸°Ô ÇÑ °ÍÀÌÁö µý ¶æÀº ¾ø´Ù.
|       mmioClose(mmIO,0);
|       exit;
|    end;
|
|    Child.ckid := mmioFOURCC('f','m','t',' ');
|       // Child ûũÀÇ ID ¸¦ 'fmt ' ¶ó´Â ¹®ÀÚ¿­·Î ¸¸µç´Ù.
|    if mmioDescend(mmIO,@Child,@Parent,0) <> 0 then begin
|       // ¸¸¾à 0 ÀÌ ¾Æ´Ñ °ªÀÌ µ¹¾Æ¿À¸é fmt ûũ°¡ ¾ø´Ù´Â °ÍÀÌ´Ù.
|       mmioClose(mmIO,0);
|       exit;               
|    end;
|
|    if mmIORead(mmIO,PChar(@WaveFormatEx),sizeof(TWaveFormatEx)) <>
|                                       sizeof(TWaveFormatEx) then begin
|       // ÇöÀç mmioDescend ¿¡ ÀÇÇØ ÆÄÀÏ Æ÷ÀÎÅÍ°¡ 'fmt '¶ó´Â ¹®ÀÚ¿­ ¹Ù·Î

|       // ´ÙÀ½ÀÇ 4 bytes ( WaveFormatEx ÀÇ Å©±â°¡ µé¾î ÀÖÀ½ ) ±îÁö ÀÐÀº
|       // »óÅ°¡ µÇ±â ¶§¹®¿¡ ¹Ù·Î ÀÐÀ¸¸é WaveFormatEx ±¸Á¶Ã¼°¡ ÀоîÁø´Ù.
|       mmioClose(mmIO,0);
|       exit;               
|    end;
|
|    if WaveFormatEx.wFormatTag <> WAVE_FORMAT_PCM then begin
|       // ÀоîµéÀÎ WaveFormatExÀÇ Å±װ¡ WAVE_FORMAT_PCM °¡ ¾Æ´Ï¶ó¸é ÀÌ
|       // ÆÄÀÏÀº PCM Çü½ÄÀÌ ¾Æ´Ñ WAV ÀÌ´Ù.
|       mmioClose(mmIO,0);
|       exit;               
|    end;
|
|    if mmioAscend(mmIO,@Child,0) <> 0 then begin
|       // ´Ù½Ã 'fmt ' ¶ó´Â ¹®ÀÚ¿­ÀÌ ÀÖ´Â Æ÷ÀÎÅÍ·Î ÆÄÀÏ Æ÷ÀÎÅ͸¦ ¿Å±ä´Ù.
|       mmioClose(mmIO,0);
|       exit;               
|    end;
|
|    Child.ckid := mmioFOURCC('d','a','t','a');
|    if mmioDescend(mmIO,@Child,@Parent,MMIO_FINDCHUNK) <> 0 then begin
|       // 'fmt ' ¶ó´Â ¹®ÀÚ¿­ÀÇ À§Ä¡¿¡¼­  'data' ¶ó´Â ¹®ÀÚ¿­·Î ÆÄÀÏÀÇ Æ÷
|       // ÀÎÅ͸¦ ¿Å±ä´Ù. ¿©±â¼­ 0 ÀÌ ¾Æ´Ñ °ªÀÌ µ¹¾Æ ¿À¸é data ûũ°¡ ¾ø
|       // ´Ù´Â °ÍÀÌ´Ù.
|       mmioClose(mmIO,0);
|       exit;               
|    end;
|
|    GetMem(Buffer,Child.cksize);
|       // Child ÀÇ Ã»Å© ID °¡ 'data' À̹ǷΠChild.cksize ¿¡´Â 'data' û
|       // Å©ÀÇ »çÀÌÁî°¡ µé¾î°£´Ù.  ½ÇÁ¦·Î WAV ±¸Á¶¿¡¼­ 'data' ¶ó´Â ¹®ÀÚ
|       // ¿­ ´ÙÀ½ÀÇ 4 bytes °¡ data »çÀÌÁî°¡ µÈ´Ù.
|
|    if not Assigned(Buffer) then begin
|       mmIOClose(mmIO,0);
|       exit;
|    end;
|
|    if mmIORead(mmIO,PChar(Buffer),Child.cksize) <> Child.cksize then
|    begin
|       // data »çÀÌÁŭ ¹öÆÛ¿¡ ÀÐ¾î µéÀδÙ.
|       mmioClose(mmIO,0);
|       exit;              
|    end;
|
|    mmIOClose(mmIO,0);
|
| end;

À§¿¡¼­´Â WAV ÆÄÀÏ ±¸Á¶°¡ ½±´Ù°í Çß¾ú´Âµ¥.... ¼³¸íÀ» ÇÏ´Ùº¸´Ï ±¦È÷ ¾î·Æ°Ô
´À²¸Áö±â´Â ÇÑ´Ù. ÇÏÁö¸¸ Á¤¸» ½±´Ù. mmIO °¡ ¾î·Æ°Ô ´À²¸Áú »ÓÀÎ °ÍÀÌ´Ù...

À§ÀÇ ¼Ò½º´ë·Î ÇÏ¸é  WaveFormatEx ¿¡´Â WAV ÆÄÀÏ¿¡ ´ëÇÑ Çì´õ°¡ µé¾î¿À°Ô µÇ
°í Buffer ¿¡´Â wave data °¡ µé¾î¿Â´Ù.

ÀÌ°ÍÀº ³ªÁß¿¡  Direct Sound ¹öÆÛ¸¦ ¸¸µé°í  µ¥ÀÌÅ͸¦ Áý¾î³ÖÀ» ¶§ ÇÙ½ÉÀûÀÎ
ÀÚ·á°¡ µÈ´Ù.

À§¿¡ º¸¸é Delphi ¿¡´Â ÇÔ¼ö°¡ Çϳª ³ª¿Â´Ù.  mmioFOURCC ¶ó´Â °ÍÀε¥ VC¿¡¼­
´Â ÀÌ°ÍÀÌ mmsystem.h ÀÇ #define À¸·Î óÀ½ºÎÅÍ Áö¿øÇÏ´Â MAKEFOURCC() ¶ó´Â
°ÍÀε¥ ¾îÂîµÈ °ÍÀÎÁö Delphi ¿¡´Â ¾ø¾î¼­  VC ¿¡ ÀÖ´Â #define À» ±×´ë·Î ÄÁ
¹öÆà Çß´Ù. ¼Ò½º´Â ¾Æ·¡¿Í °°´Ù.

| function    mmioFOURCC(Data1,Data2,Data3,Data4 : char) : FOURCC;
| var
|    Buffer : FOURCC;
| begin
|    Buffer := ord(Data4);
|    Buffer := Buffer shl 8;
|    Buffer := Buffer or ord(Data3);
|    Buffer := Buffer shl 8;
|    Buffer := Buffer or ord(Data2);
|    Buffer := Buffer shl 8;
|    Buffer := Buffer or ord(Data1);
|
|    mmioFOURCC := Buffer;
| end;

( Áö±Ýº¸´Ï °¡º¯ record ·Î ÇÏ´Â°Ô ´õ ³ªÀ» °Í °°´Ù... )

------------------------------------------------------------------------
                                                          1999 / 11 / 07

#####################################################


------------------------------------------------------------------------
### µ¨ÆÄÀÌ·Î ÇÏ´Â Direct X - Direct Sound (3/4)

    1. Direct Sound ÀÇ °³¿ä
    2. Direct Sound ÃʱâÈ­¿Í Wave Àбâ
    3. ¹öÆÛ¸¦ ÅëÇÑ Ãâ·Â°ú ¹Í½Ì
    ~~~~~~~~~~~~~~~~~~~~~~~~~~
    4. 3D ¹öÆÛ¸¦ ÅëÇÑ Ãâ·Â°ú ¹Í½Ì

------------------------------------------------------------------------
                                    ÀÛ¼ºÀÚ : ¾È¿µ±â ( HiTEL ID : SMgal )

------------------------------------------------------------------------

(1) Direct Sound ÀÇ ¹öÆÛ

Direct Sound ´Â 1 °³ÀÇ 1 Â÷ ¹öÆÛ ( Primary Buffer ) ¿Í  1 °³ ÀÌ»óÀÇ 2 Â÷
¹öÆÛ ( Secondary Buffer ) ¸¦ °¡Áú ¼ö°¡ ÀÖ´Ù.

1 Â÷ ¹öÆÛ´Â »ý¼ºµÉ ¶§,  22 KHz 8 bit ½ºÅ×·¹¿À°¡ µðÆúÆ®·Î ¼³Á¤µÈ´Ù.  2 Àå
¿¡ ¸»ÇßµíÀÌ Çù·Â ·¹º§ÀÌ DSSCL_PRIORITY ÀÌ»óÀÌ µÇ¾î¾ß ÀÌ Æ÷¸ËÀ» º¯°æÇÒ ¼ö
°¡ Àִµ¥,  ½ÇÁ¦ Direct Sound °¡ ÃÖ°íÀÇ ÆÛÆ÷¸Õ½º¸¦ ³»·Á¸é  1 Â÷ ¹öÆÛ¿Í 2
Â÷ ¹öÆÛ°¡ °°Àº Æ÷¸ËÀÏ ¶§ °¡´ÉÇϹǷΠ2 Â÷ ¹öÆÛ¿¡ ¸Â´Â 1 Â÷ ¹öÆÛ Æ÷¸ËÀ» À¯
Àú°¡ Á÷Á¢ ¹Ù²ã ÁÖ¾î¾ß ÇÏ´Â °æ¿ì°¡ »ý±ä´Ù.
( À̹ø¿¡ ¿¹·Î µé, DSSCL_NORMAL ÀÇ ¿¹Á¦¿¡¼­´Â ÀÌ ºÎºÐ°ú »ó°ü¾ø´Ù. )

2 Â÷ ¹öÆÛ´Â ½ÇÁ¦·Î ¹Í½ÌµÉ wave data °¡ µé¾î ÀÖ´Â ºÎºÐÀÌ´Ù.  ¸» ±×´ë·Î ¹ö
ÆÛÀ̱⠶§¹®¿¡ ´Ù¸¥ ¹öÆÛÀÇ °³³ä°ú °°À¸³ª, Lock()¿¡ ÀÇÇؼ­¸¸ Á¢±Ù ÇÒ ¼ö ÀÖ
´Ù´Â °Í°ú ¿øÇü ¹öÆÛÀ̱⠶§¹®¿¡  ³¡ ºÎºÐÀ» ³Ñ¾î°¡¸é  Ã³À½ºÎÅÍ ´Ù½Ã Æ÷ÀÎÅÍ
°¡ Áõ°¡ÇÑ´Ù´Â °ÍÀÌ´Ù.

2 Â÷ ¹öÆÛ¿¡´Â Å©°Ô ½ºÅÂƽ ¹öÆÛ¿Í ½ºÆ®¸®¹Ö ¹öÆÛ°¡ ÀÖ´Ù.

½ºÅÂƽ ¹öÆÛ´Â, ½´Æà °ÔÀÓ¿¡¼­ ¹ß»ç ¹öÆ°À» ´©¸£¸é °è¼Ó ³ª¿Í¾ß Çϴ ªÀº ¼Ò
¸® °°Àº °Í¿¡ ¾²ÀδÙ. µðÆúÆ®´Â Çϵå¿þ¾î ¹öÆÛ ( »ç¿îµå Ä«µå ³»¿¡ ÀÖ´Â ) ¿¡
¸¸µé¾îÁ®¼­ ÃÖ´ëÇÑ »¡¸® Ãâ·ÂÀ» ÇÒ ¼ö ÀÖ°Ô Çϸç, Ç×»ó ¹öÆÛ¿¡ ¸ðµç µ¥ÀÌÅÍ°¡
»óÁÖÇØ Àִ´Ù.

½ºÆ®¸®¹Ö ¹öÆÛ´Â, WAV ÆÄÀÏ·Î ¹è°æ À½¾ÇÀ» ¿¬ÁÖÇϰųª ÇÒ ¶§ »ç¿ëµÈ´Ù.  ½ÇÁ¦
¹è°æ À½¾Ç¿ë WAV ÆÄÀÏÀº ±²ÀåÈ÷ Å©±â ¶§¹®¿¡  Çϵå¿þ¾î ¹öÆÛ¿¡³ª  ¼ÒÇÁÆ®¿þ¾î
¹öÆÛ ( ½Ã½ºÅÛ ·¥ ) ¿¡ ¸ðµÎ ¿Ã·Á³õÀº ÈÄ ¿¬ÁÖÇϱ⿡´Â ¸ÂÁö ¾Ê´Ù.

½ºÆ®¸®¹Ö ¹öÆÛ¸¦ ¿î¿ëÇÏ´Â ¹æ¹ý¿¡ À־´Â, 2 ÃÊ Á¤µµÀÇ ¹öÆÛ °ø°£¸¸À» ¸¸µç
ÈÄ¿¡ ¸ÖƼ¹Ìµð¾î ŸÀÌ¸Ó ( ÀÌÀü¿¡ °­Á¸¦ Çß´Ù. °Å±æ Âü°íÇϽñæ ) ·Î ÀÏÁ¤ÇÑ
Á⵿ֱ¾È¿¡  Å¸ÀÌ¸Ó ÄݹéÀ» ¸¸µç ÈÄ  °»½ÅµÉ ºÎºÐ¸¸ °è¼Ó ÆÄÀÏ¿¡¼­ ÀÐ¾î µé¿©
¹öÆÛ¿¡ ¾²´Â ½ÄÀÌ´Ù. WinAMP °°Àº À½¾Ç ¿¬ÁÖ ÇÁ·Î±×·¥ÀÌ, »ç¿ëÀÚÀÇ ¹«½¼ ÀÛ¾÷
¿¡ ÀÇÇØ ±×ÂÊ¿¡ ¸ðµç ºÎÇÏ°¡ °¡¹ö¸®¸é  Å¸ÀÌ¸Ó À̺¥Æ®¸¦ ¹ÞÁö ¸øÇØ  1-2 ÃÊÀÇ
±¸°£À» °è¼Ó ¹Ýº¹ÇÏ´Â °ÍÀ» °æÇèÇϼÌÀ» ºÐµµ °è½Ç °ÍÀÌ´Ù.  ÀÌ°ÍÀº  ½ºÆ®¸®¹Ö
¹öÆÛ ±¸Á¶¸¦ »ç¿ëÇϱ⠶§¹®¿¡ »ý±â´Â ÀÏÀÌ´Ù.

ÀÏ´Ü ´ÙÀ½ °­Á¿¡ ÇÒ Direct Music À̶ó´Â ºÎºÐÀÌ Direct X ·Î ¹è°æÀ½¾ÇÀ» ¿¬
ÁÖÇÏ´Â ºÎºÐÀÌ ÀÖÀ¸¹Ç·Î À̹ø °­Á¿¡¼­´Â ½ºÆ®¸®¹Ö ¹öÆÛ¿¡ ´ëÇÑ °ÍÀº ÇÏÁö ¾Ê
±â·Î ÇÑ´Ù.

------------------------------------------------------------------------

(2) Direct Sound Buffer »ý¼º

¸ÕÀú 1Â÷ ¹öÆÛ »ý¼ººÎÅÍ ¾Ë¾Æº¸°Ú´Ù.

| const
|    DS_BITPERSAMPLE   = 8;
|    DS_CHANSPERSAMPLE = 1;
|    DS_SAMPLERATE     = 22050;

| var
|    BufferLength      : DWORD;
|    DirectSoundBuffer : IDirectSoundBuffer;
|       // Àü¿ª º¯¼ö ¶Ç´Â Ŭ·¡½ºÀÇ ¸â¹ö º¯¼ö°¡ µÇ´Â Sound Buffer °´Ã¼

| function    CreatePrimaryBuffer : boolean;
| var
|    DSBufferDesc  : TDSBUFFERDESC;
|    WaveFormatEx  : TWaveFormatEx;
|    DSBCaps       : TDSBCaps;
|    DSResult      : HResult;
| begin
|    CreatePrimaryBuffer := FALSE;
|    if not Assigned(DirectSound) then exit;
|       // Direct Sound °¡ ÃʱâÈ­ µÇ¾î ÀÖÁö ¾Ê´Ù¸é ÀÌ ÇÔ¼ö´Â ½ÇÆÐ
|
|    FillChar(WaveFormatEx,sizeof(TWaveFormatEx),0);
|       // WaveFormatEx ±¸Á¶Ã¼ ÃʱâÈ­
|
|    WaveFormatEx.wFormatTag      := WAVE_FORMAT_PCM;
|       // wave Æ÷¸ËÀº PCM Çü½Ä
|    WaveFormatEx.nChannels       := DS_BITPERSAMPLE;
|       // 1 ÀÌ¸é ¸ð³ëÀÌ°í 2 ÀÌ¸é ½ºÅ×·¹¿À.
|    WaveFormatEx.nSamplesPerSec  := DS_SAMPLERATE;
|       // ÃÊ´ç »ùÇøµ ¼ö, ÀÌ °æ¿ì¿¡´Â 22KHz
|    WaveFormatEx.wBitsPerSample  := DS_BITPERSAMPLE;
|       // »ùÇà ºñÆ®, ÀÌ °æ¿ì¿¡´Â 8 bit »ç¿îµå
|    WaveFormatEx.nBlockAlign     := WaveFormatEx.nChannels
|                                    * DS_BITPERSAMPLE div 8;
|       // ÇϳªÀÇ »ùÇÿ¡ ´ëÇÑ ÇÒ´ç ¹ÙÀÌÆ® ¼ö
|    WaveFormatEx.nAvgBytesPerSec := WaveFormatEx.nSamplesPerSec
|                                    * WaveFormatEx.nBlockAlign;
|       // ÃÊ´ç »ùÇÃ ¹ÙÀÌÆ® ¼ö
|    WaveFormatEx.cbSize          := 0;
|
|    FillChar(DSBufferDesc,sizeof(TDSBufferDesc),0);
|       // DSBufferDesc ±¸Á¶Ã¼ ÃʱâÈ­
|
|    DSBufferDesc.dwSize          := sizeof(TDSBufferDesc);
|       // Ç×»ó ÀÚ½ÅÀÇ »çÀÌÁ Ç¥½Ã ( ¾È ±×·¯¸é ¿¡·¯ ¹ß»ý )
|    DSBufferDesc.dwFlags         := DSBCAPS_PRIMARYBUFFER;
|
|    DSResult := DirectSound.SetCooperativeLevel(Handle,
|                                                   DSSCL_WRITEPRIMARY);
|       // Çù·Â ·¹º§À» ¼³Á¤, 2 Àå¿¡¼­µµ ¸»ÇßµíÀÌ DSSCL_NORMAL Àº ¾ÈµÈ´Ù.
|    if DSResult = DS_OK then begin
|       DSResult := DirectSound.CreateSoundBuffer(DSBufferDesc,
|                                                DirectSoundBuffer,nil);
|          // 1 Â÷¹öÆÛ¸¦ ¾òÀ½
|       if DSResult = DS_OK then begin
|          DSResult := DirectSoundBuffer.SetFormat(WaveFormatEx);
|             // WaveFormatEx ¿¡ ¼³Á¤ÇÑ´ë·Î 1 Â÷ ¹öÆÛ Æ÷¸ËÀ» ¹Ù²Þ
|          if DSResult = DS_OK then begin
|             DSBCaps.dwSize      := sizeof(TDSBCaps);
|             DirectSoundBuffer.GetCaps(DSBCaps);
|                // »ý¼ºÇÑ »ç¿î ¹öÆÛ¿¡ ´ëÇÑ Á¤º¸¸¦ ÀÐÀ½
|             BufferLength        := DSBCaps.dwBufferBytes;
|                // ¹öÆÛ¿¡ ÇÒ´çµÈ ¹ÙÀÌÆ® ¼ö¸¦ ÀúÀå
|             CreatePrimaryBuffer := TRUE;
|                // ÇÔ¼ö ¼º°ø
|             exit;
|          end;
|       end;
|    end;
|
|    DirectSoundBuffer := nil;
|    BufferLength      := 0;
|       // ÇÔ¼ö ½ÇÆÐ
| end;

1 Â÷ ¹öÆÛ¸¦ »ý¼ºÇÒ ¶§¿¡´Â  Çù·Â ·¹º§ÀÌ ´Þ¶óÁö¸ç  »ç¿ëÀÚ Æ÷¸ËÀ» Á¤ÀÇÇÒ ¼ö
ÀÖ´Ù´Â °Í Á¤µµ¸¸ ÁÖÀÇÇÏ¸é µÈ´Ù.


À̹ø¿¡´Â 2 Â÷ ¹öÆÛÀÌ´Ù.

| var
|    DirectSoundBuffer : IDirectSoundBuffer;
|       // Àü¿ª º¯¼ö ¶Ç´Â Ŭ·¡½ºÀÇ ¸â¹ö º¯¼ö°¡ µÇ´Â Sound Buffer °´Ã¼

| function   CreateSoundBuffer(WaveFormatEx  : TWaveFormatEx) : boolean;
| var
|    DSBufferDesc  : TDSBUFFERDESC;
|    DSResult      : HResult;
| begin
|    CreateSoundBuffer := FALSE;
|    if not Assigned(DirectSound) then exit;
|       // Direct Sound °¡ ÃʱâÈ­ µÇ¾î ÀÖÁö ¾Ê´Ù¸é ÀÌ ÇÔ¼ö´Â ½ÇÆÐ
|
|    WaveFormatEx.cbSize          := sizeof(TWaveFormatEx);
|       // º¸Åë WAV ÆÄÀÏ¿¡¼­ WaveFormatEx ¸¦ °¡Á® ¿Ã ¶§  cbSize ºÎºÐ±îÁö
|       // Á¤º¸¸¦ ÀúÀåÇÏÁö ¾Ê´Â WAV Æ÷¸ËÀÌ ÀÖ´Ù. ±×·² ¶§¸¦ ´ëºñÇؼ­ ¼öµ¿
|       // À¸·Î ³Ö¾î ÁØ´Ù. ¾È ³Ö¾îµµ µÉÁöµµ ¸ð¸¥´Ù.
|
|    FillChar(DSBufferDesc,sizeof(TDSBufferDesc),0);
|       // DSBufferDesc ±¸Á¶Ã¼ ÃʱâÈ­
|
|    DSBufferDesc.dwSize          := sizeof(TDSBufferDesc);
|       // Ç×»ó ÀÚ½ÅÀÇ »çÀÌÁ Ç¥½Ã ( ¾È ±×·¯¸é ¿¡·¯ ¹ß»ý )
|    DSBufferDesc.dwFlags         := DSBCAPS_CTRLDEFAULT or
|                          DSBCAPS_STATIC or DSBCAPS_GETCURRENTPOSITION2
|       // DSBCAPS_CTRLDEFAULT - º¼·ý, ÆÒ, ÁÖÆļö Á¦¾î °¡´É
|       // DSBCAPS_STATIC      - ÀÌ ¹öÆÛ´Â ½ºÅÂƽ ¹öÆÛ
|       // DSBCAPS_GETCURRENTPOSITION2 - ÇöÀç Ç÷¹ÀÌ À§Ä¡ ¾ò±â °¡´É
|    DSBufferDesc.dwBufferBytes   := BufferLength;
|       // »ý¼ºÇÒ ¹öÆÛÀÇ Å©±â, º¸Åë ½ºÅÂƽ ¹öÆÛ¿¡¼­´Â WAV ÀüüÀÇ Å©±â
|    DSBufferDesc.lpwfxFormat     := @WaveFormatEx;
|       // Àû¿ëÇÒ WaveFormatEx ±¸Á¶Ã¼°¡ ÀÖ´Â °÷ÀÇ Æ÷ÀÎÅÍ
|    DSResult := DirectSound.CreateSoundBuffer(DSBufferDesc,
|                                                DirectSoundBuffer,nil);
|       // »ç¿îµå ¹öÆÛ »ý¼º
|
|    if DSResult <> DS_OK then begin
|       DirectSoundBuffer := nil;
|          // »ý¼º ½ÇÆÐ
|       exit;
|    end;
|
|    CreateSoundBuffer := TRUE;
|       // »ý¼º ¼º°ø
| end;

1Â÷ ¹öÆÛÀÏ ¶§¿Í °¡Àå Å©°Ô ´Ù¸¥ Á¡Àº DSBufferDesc ¿¡¼­ Ç÷¡±× ¼³Á¤ÀÌ´Ù.
DSBCAPS_PRIMARYBUFFER ¶ó´Â Ç÷¡±× ´ë½Å ÇöÀç ¹öÆÛ¿¡ ¾µ ´Ù¸¥ ¿©·¯ Ç÷¡±×µé
À» ¼³Á¤ÇØ ÁÖ¾ú´Ù. ±×¸®°í WaveFormatEx ±¸Á¶Ã¼ °°Àº °æ¿ì¿¡´Â 2 Àå¿¡¼­ ¾ð±Þ
ÇÑ LoadWave() ÇÔ¼ö¿¡¼­ ¾òÀ» ¼ö ÀÖ¾ú´Ù.


ÇÏÁö¸¸ À§ÀÇ ¼Ò½º¿¡´Â ´ÜÁö ÀÏÁ¤ Å©±âÀÇ ¹öÆÛ¸¸ »ý¼ºÇßÀ» »Ó  ±× ¹öÆÛ¿¡ ÀÚ·á
¸¦ ³ÖÁö´Â ¾Ê¾Ò´Ù.  ±×·³ À̹ø¿¡´Â »ý¼ºÇÑ ¹öÆÛ¿¡´Ù°¡ ÀڷḦ ¾²´Â ¹ýÀ» ¾Ë¾Æ
º¸ÀÚ.

| function    FillBuffer : boolean;
| var
|    AudioPtr1,   AudioPtr2   : Pointer;
|    AudioBytes1, AudioBytes2 : DWORD;
|    DSResult                 : HResult;
| begin
|    FillBuffer := FALSE;
|    if not Assigned(DirectSound) then exit;
|       // Direct Sound °¡ ÃʱâÈ­µÇ¾î ÀÖÁö ¾Ê´Ù¸é ÀÌ ÇÔ¼ö´Â ½ÇÆÐ
|
|    DSResult   := DS_OK;
|    repeat
|       if DSResult = DSERR_BUFFERLOST then DirectSoundBuffer.Restore;
|          // ¸¸¾à »ç¿îµå ¹öÆÛ¸¦ ÀÒ¾î¹ö¸° »óŶó¸é º¹±¸
|       DSResult := DirectSoundBuffer.Lock(0,BufferLength,AudioPtr1,
|                                  AudioBytes1,AudioPtr2,AudioBytes2,0);
|          // ¹öÆÛ¸¦ Lock Çؼ­ ¾µ Æ÷ÀÎÅ͸¦ ¾òÀ½
|          // 0            - ½ÃÀÛ ¿ÀÇÁ¼Â ( 0 Àº Á¦ÀÏ Ã³À½ )
|          // BufferLength - ÀÌÀü¿¡ ±¸ÇØ ³õ¾Ò´ø ÀÌ ¹öÆÛÀÇ Å©±â
|          // AudioPtr1    - ù ¹ø° ºí·Ï Æ÷ÀÎÅÍ
|          // AudioBytes1  - ù ¹ø° ºí·Ï Å©±â
|          // AudioPtr2    - µÎ ¹ø° ºí·Ï Æ÷ÀÎÅÍ
|          // AudioBytes2  - µÎ ¹ø° ºí·Ï Å©±â
|    until DSResult <> DSERR_BUFFERLOST;
|       // ¹öÆÛ¸¦ ÀÒ¾ú´Ù´Â ¸Þ¼¼Áö°¡ ¾Æ´Ï¸é Å»Ãâ
|
|    if DSResult <> DS_OK then exit;
|
|    CopyMemory(AudioPtr1,Buffer,AudioBytes1);
|       // Buffer ÀÇ ³»¿ëÀ» AudioPtr1 ¿¡ AudioBytes1 ¸¸Å­ º¹»ç
|       // ÀÌ°ÍÀº API ÇÔ¼ö
|    if Assigned(AudioPtr2) then begin
|       CopyMemory(AudioPtr2,PByte(DWORD(Buffer)+AudioBytes1),
|                                                          AudioBytes2);
|          // ¸¸¾à µÎ ¹ø° Æ÷ÀÎÅÍ°¡ ÀÖ´Ù¸é ±×°Íµµ º¹»ç
|    end;
|
|    DSResult := DirectSoundBuffer.UnLock(AudioPtr1,AudioBytes1,
|                                                AudioPtr2,AudioBytes2);
|       // ¾²±â¸¦ À§ÇØ Àá±É´ø ¹öÆÛ¸¦ ´Ù½Ã ÇØÁ¦ÇÑ´Ù.
|
|    if DSResult <> DS_OK then exit;
|
|    FillBuffer := TRUE;
|       // ÇÔ¼ö ¼º°ø
| end;

¿©±â¼­ Buffer º¯¼ö¿Í DirectSoundBuffer °´Ã¼¿Í BufferLength ´Â  ÀÌ¹Ì ±¸ÇØ
Á® ÀÖ´ø °ÍÀÌ´Ù.

À̹ø¿¡´Â Lock() °ú Unlock() À̶ó´Â ÇÔ¼ö°¡ µîÀåÇß´Ù.  ÀÌ ÇÔ¼öµéÀº  ¹öÆÛ¿¡
Á÷Á¢ ÀÐ°í ¾²´Â °ÍÀ» °¡´ÉÇÏ°Ô ÇØÁÖ´Â IDirectSoundBuffer ÀÇ ¸Þ½îµå´Ù.

Lock() À» ÇÏ°Ô µÇ¸é Æ÷ÀÎÅÍ¿Í »çÀÌÁî°¡ °¢°¢ 2°³°¡ µ¹¾Æ¿À°Ô µÈ´Ù.  ±× ÀÌÀ¯
´Â ¹öÆÛ°¡ ¿øÇüÀ̶ó´Âµ¥ ÀÖ´Ù. À̹øÀÇ °æ¿ì¿¡´Â 0 ¹ø ¿ÀÇÁ¼ÂºÎÅÍ ¾²±â ¶§¹®¿¡
ÇØ´ç »çÇ×Àº ¾øÁö¸¸ ¸¸¾à 1000 ¹ÙÀÌÆ®ÀÇ Å©±âÀÎ ¹öÆÛ¿¡¼­ 900 ¹ÙÀÌÆ® ° ¿ÀÇÁ
¼ÂÀ¸·ÎºÎÅÍ 200 ¹ÙÀÌÆ®¸¸Å­À» ¾²±â °¡´ÉÀ¸·Î ÇÏ·Á¸é ¾î¶»°Ô µÇ°Ú´Â°¡. ±×·¸´Ù,
900 - 1000 ±îÁö°¡ ù ¹ø° ºí·ÏÀ¸·Î ÁöÁ¤µÇ°í 0 - 100 ±îÁö°¡  µÎ ¹ø° ºí·Ï
À¸·Î ÁöÁ¤µÇ´Â °ÍÀÌ´Ù. 1000 ¹øÀº ¹Ù·Î 0 ¹øÀ¸·Î À̾îÁö±â ¶§¹®ÀÌ´Ù.  ±×¸®°í
ÀÌ·± ½ÄÀ¸·Î  ¹öÆÛÀÇ ³¡¿¡¼­ ´Ù½Ã µ¹¾Æ¿À´Â ÀÏÀÌ ¾ø´Ù¸é  µÎ ¹ø° Æ÷ÀÎÅÍ¿¡´Â
Ç×»ó nil ÀÌ µ¹¾Æ¿Â´Ù.

Lock ÀÇ ¸¶Áö¸· ÀÎÀÚ¿¡ ÇöÀç´Â 0 ÀÌ µé¾î°¬´Âµ¥, ±× ÀÌ¿Ü¿¡µµ 2°¡Áö Ç÷¡±×°¡
´õ µé¾î °¥ ¼ö°¡ ÀÖ´Ù.

   DSBLOCK_FROMWRITECURSOR - ÇöÀç ¾²±â Ä¿¼­°¡ ÀÖ´Â ºÎºÐºÎÅÍ  ¿ÀÇÁ¼ÂÀ» Àâ
                             ´Â´Ù. ÀÌ°ÍÀ» »ç¿ëÇÏ°Ô µÇ¸é ¿ÀÇÁ¼Â ÀÎÀÚ¸¦ ¹«
                             ½ÃÇÏ°Ô µÈ´Ù.
   DSBLOCK_ENTIREBUFFER    - Àüü ¹öÆÛ¿¡ ´ëÇؼ­ Lock À» ¼öÇàÇÑ´Ù. ÀÌ°ÍÀ»
                             »ç¿ëÇÏ°Ô µÇ¸é Lock ÇÒ ¹öÆÛ »çÀÌÁî´Â  ¹«½ÃµÈ
                             ´Ù.

±×¸®°í ¹°·Ð Lock() ¿¡ ´ëÀÀÇÏ´Â Unlock() µµ ÀØÀ¸¸é ¾È µÈ´Ù. ( Direct Draw
¿Í ¸¶Âù°¡Áö·Î À̰͵µ ½ÖÀÌ´Ù. )  ´Ü Direct Draw ÀÇ Unlock() °ú  ´Ù¸¥ Á¡Àº
Lock() À¸·Î ¹ÞÀº 4 °³ÀÇ ÀÎÀÚ¸¦ ¸ðµÎ Unlock() ¿¡¼­µµ ±âÀÔÀ» ÇØÁÖ¾î¾ß ÇÑ´Ù
´Â °ÍÀÌ´Ù.

±×¸®°í repeat until ºÎºÐ¿¡ º¸¸é  ¹öÆÛ¸¦ ÀÒ´Â °Í¿¡ ´ëÇÑ  ´ëºñÃ¥ÀÌ ÀÖ¾ú´Ù.
Lock() À» ½ÃµµÇÏ·Á´Âµ¥ ¾î¶°ÇÑ ¿ÜºÎÀûÀÎ »óȲ ( ¸Þ¸ð¸® ¹Ýȯ ¿ä±¸ )  ¶§¹®¿¡
¹öÆÛ ¸Þ¸ð¸®¸¦ ÀÒ¾úÀ» ¶§´Â Lock ÀÌ µÇÁö ¾Ê°í  DSERR_BUFFERLOST ¶ó´Â  ¿¡·¯
Äڵ尡 µ¹¾Æ¿Â´Ù.  À̶§´Â IDirectSoundBuffer °´Ã¼ÀÇ Restore() ¸Þ½îµå¸¦ ¾²
¸é ´Ù½Ã ¹öÆÛ°¡ º¹±¸µÈ´Ù.  ( °ÅÀÇ ¸ðµç ¸Þ½îµå°¡  DSERR_BUFFERLOST ¿¡·¯ ÄÚ
µå¸¦ ¸®ÅÏ ÇÒ ¼ö°¡ ÀÖÀ¸¸ç ½ÇÁ¦·Î ¸Þ¼Òµå¸¦ ¾µ ¶§¸¶´Ù Ç×»ó °Ë»ç ÇØÁÖ¾î¾ß Á¤
¼®ÀÌ´Ù. )

------------------------------------------------------------------------

(3) Wave Àç»ý

Àç»ýÇϱâ À§ÇÑ ÃÖ¼ÒÀÇ ÀýÂ÷´Â ´ÙÀ½°ú °°´Ù.

1. Direct Sound °´Ã¼¸¦ »ý¼ºÇÑ´Ù.
2. WAV ÆÄÀÏÀ» ÀÐ¾î µéÀδÙ.
3. ¹öÆÛ¸¦ Çϳª »ý¼ºÇÑ´Ù. ( 1, 2 Â÷ »ó°ü¾øÀ½ )
4. ±× ¹öÆÛ¿¡ wave data ¸¦ ¾´´Ù.
5. Ç÷¹ÀÌ ÇÒ À§Ä¡ ¼³Á¤
6. Ç÷¹ÀÌ
7. Á¤Áö

ÇöÀç±îÁö ÇÑ °ÍÀº 4¹ø±îÁöÀÇ ÀýÂ÷¿´´Ù.  ´ÙÇàÇÏ°Ôµµ 5 ¹ø ÀÌÈÄÀÇ ÀýÂ÷´Â ¸ðµÎ
¸Þ½îµå Çϳª¸¸À¸·Î ½ÇÇàÀÌ °¡´ÉÇÏ´Ù.


¸ÕÀú Ç÷¹ÀÌÇÒ À§Ä¡¸¦ ¼³Á¤Çϱâ À§Çؼ­´Â ´ÙÀ½°ú °°ÀÌ ÇÑ´Ù.

|   DirectSoundBuffer.SetCurrentPosition(0);

À§¿Í °°ÀÌ Çϸé Á¦ÀÏ Ã³À½ºÎÅÍ ¿¬ÁÖ¸¦ ½ÃÀÛÇ϶ó´Â ¶æÀÌ µÇ°í,  ÆĶó¸ÞÅÍ¿¡ µé
¾î°¥ °ªÀº ¿¬ÁÖ¸¦ ½ÃÀÛÇÒ À§Ä¡¸¦ ¹ÙÀÌÆ® ´ÜÀ§·Î ³Ö¾î¾ß ÇÑ´Ù. ÀÌ¹Ì ¹öÆÛÀÇ Á¤
º¸´Â ¾Ë°í ÀÖÀ¸¹Ç·Î 1 ÃÊ°¡ ¸î ¹ÙÀÌÆ®ÀÎÁö ¾Ë ¼ö°¡ Àֱ⠶§¹®¿¡  ½±°Ô À§Ä¡¸¦
ÁöÁ¤ÇÒ ¼ö°¡ ÀÖ´Ù.( Âü°í -> WaveFormatEx.nAvgBytesPerSec ÃÊ´ç ¹ÙÀÌÆ® ¼ö )


±×¸®°í ¿¬ÁÖ¸¦ ½ÃÀÛÇÏ°Ô Çϱâ À§Çؼ­´Â ´ÙÀ½°ú °°Àº ¸Þ½îµå¸¦ »ç¿ëÇÏ¸é µÈ´Ù.

|   DirectSoundBuffer.Play(0,0,0);

ù ¹ø° ÆĶó¸ÞÅÍ´Â Ç×»ó 0 ÀÌ´Ù.

µÎ ¹ø° ÆĶó¸ÞÅÍ´Â Çϵå¿þ¾î ¹Í½Ì ¸®¼Ò½º¸¦ ÁöÁ¤ÇÒ ¶§  ±× ¿ì¼± ¼øÀ§ ±ÇÇÑÀ»
°áÁ¤Çϱâ À§Çؼ­ ¾²À̴µ¥, ¹öÆÛ°¡ DSBCAPS_LOCDEFER Ç÷¡±×·Î ÁöÁ¤µÇÁö ¾Ê¾Ò
À¸¸é  Ç×»ó 0 À¸·Î  µÖ¾ßÇÑ´Ù.  DSBCAPS_LOCDEFER Ç÷¡±×´Â  Direct X 7.0 ÀÇ
Direct Sound¿¡¼­ óÀ½ »ý±ä °ÍÀ̱⠶§¹®¿¡ ÇÏÀ§È£È¯À» À§Çؼ­ 0 À¸·Î µÎÀÚ.

¼¼ ¹ø° ÆĶó¸ÞÅÍ¿¡ 0 À» ³ÖÀ¸¸é  ±×³É ÇÑ ¹ø¸¸ ¿¬ÁÖÇÑ´Ù.  µû·Î ¸ØÃçÁà¾ß ÇÒ
ÇÊ¿ä´Â ¾ø´Ù. ±×¸®°í DSBPLAY_LOOPING À» ³ÖÀ¸¸é °è¼Ó ¹Ýº¹µÇ°Ô µÈ´Ù. ±×¸®°í
±× ÀÌ¿Ü¿¡ ´ÙÀ½°ú °°Àº °ÍµéÀÌ ÀÖ´Ù.  ( ¿¹Àü¿£ ÀÌ µÎ °¡Áö°¡ ÀüºÎ¿´´Âµ¥  DX
7.0 ¿¡¼­ »õ·Î »ý±ä °ÍµéÀÌ´Ù. )

  Voice Allocation flags
     DSBPLAY_LOCHARDWARE
     DSBPLAY_LOCSOFTWARE

  Voice Management flags
     DSBPLAY_TERMINATEBY_TIME
     DSBPLAY_TERMINATEBY_DISTANCE
     DSBPLAY_TERMINATEBY_PRIORITY

À̰͵éÀº ¸ðµÎ DSBCAPS_LOCDEFER ·Î »ý¼ºµÈ ¹öÆÛ¿¡¼­¸¸ ¾²Àδٰí ÇÑ´Ù.  ÀÚ¼¼
ÇÑ °ÍÀº ÇÊÀÚµµ ¸ð¸¦»Ó´õ·¯ ¾ÕÀ¸·Îµµ ¸ð¸¥ ä·Î Áö³¾ °Í °°´Ù. ( Direct X ´Â
1 ³âµµ ¾ÈµÇ¾î¼­ »õ ¹öÀüÀÌ ³ª¿À°í, ¶Ç ÀÌ·± ½ÄÀ¸·Î ±â´ÉÀÌ Ãß°¡°¡ µÈ´Ù.  ±×
¸®°í ÀÌ·± ½ÄÀ¸·Î ´Ù ¾Ë·Á¸é »õ ¹öÀü °øºÎ¸¸ ÇÏ´Ù°¡ ¶Ç »õ ¹öÀüÀ» ¸ÂÀ» °Í °°
´Ù.. -_-; )


¿¬Áֵǰí ÀÖ´Â WAV ¸¦ ¸ØÃß·Á¸é ´ÙÀ½ÀÇ ¸Þ½îµå¸¦ ÀÌ¿ëÇÑ´Ù.

|   DirectSoundBuffer.Stop;

¾ÆÁÖ °£´ÜÇÏ´Ù. ¿ì¸® ¸ðµÎ ÀÌ·± ¿ë¹ýÀÇ ÇÔ¼ö¸¦ ÁÁ¾ÆÇÏÁö ¾Ê´Â°¡ ?


------------------------------------------------------------------------

(4) wave data ¹Í½Ì

¹Í½Ì¹ýÀº Çù·Â ·¹º§¿¡ µû¶ó ´Ù¸£´Ù.  

DSSCL_WRITEPRIMARY ·Î ¼³Á¤À» Çß´Ù¸é  1 Â÷ ¹öÆÛ¿¡¼­  Á÷Á¢ ¹Í½ÌÀ» ÇؾßÇÏ°í
DSSCL_NORMAL ·Î ¼³Á¤Çß´Ù¸é  1 Â÷ ¹öÆÛ¸¦ »ý¼ºÇÒ ÇÊ¿ä ¾øÀÌ 2 Â÷ ¹öÆ۵鸸À¸
·Î ¹Í½ÌÀÌ °¡´ÉÇÏ´Ù.

1. DSSCL_NORMAL ÀÇ °æ¿ì

   À§¿¡¼­ ÇÑ ¹æ¹ý´ë·Î 2 Â÷ ¹öÆÛ¸¦ 2 °³ ÀÌ»ó ¸¸µé¾î º»´Ù. ¹öÆÛ¿¡ µ¥ÀÌÅ͸¦
   ¿Ã¸° ÈÄ,  µÑ ´Ù °°ÀÌ ¿¬ÁÖÇϰųª ½Ã°£Â÷¸¦ µÎ°í Play() ÇÔ¼ö¸¦ ½ÇÇàÇØ º¸
   ÀÚ.  ¿ì¸®´Â ¾Æ¹« °Íµµ ¾È ÇßÁö¸¸, Direct Sound °¡ ½º½º·Î ¾Ë¾Æ¼­ ¿¬ÁÖµÇ
   °í ÀÖ´Â 2 Â÷ ¹öÆÛ³¢¸® ¹Í½ÌÀ» ÇÏ°Ô µÇ°í,  µ¿½Ã¿¡ µÎ °¡Áö ÀÌ»óÀÇ ¼Ò¸®°¡
   ³ª¿À°Ô µÈ´Ù.

2. DSSCL_WRITEPRIMARY ÀÇ °æ¿ì

   ¼ÖÁ÷ÇÏ°Ô ÀÌ ¸ðµå·Î ÀÛ¾÷À» Çغ» ÀûÀº ¾ø´Ù. ¾µ ÀÏÀÌ ¾ø¾úÀ¸´Ï±î.  ÇÏÁö¸¸
   ¿¹Àü µµ½º ¶§´Â Á÷Á¢ Çϵå¿þ¾î¿¡ ¹Í½ÌÀ» ÇßÀ¸´Ï ±×¶§ »ç¿îµå ºí·¡½ºÅÍ DMA
   ¿¡ ¹Í½ÌÇϱâ À§ÇØ ¸¸µé¾ú´ø ÇÊÀÚÀÇ ¼Ò½º¸¦ ¿¹·Î µé°Ú´Ù.  ( ÀÌ°Ç µ¨ÆÄÀÌ¿¡
   ¹Ù·Î Àû¿ëÇÒ ¼ö´Â ¾øÀ¸´Ï ¾Ë°í¸®Áò Â÷¿ø¿¡¼­ ¾Ë¾ÆµÎ´Â Á¤µµ¸é µÇ°Ú´Ù. )

|    if (is_playing_voice) and (is_multivoice) then begin
|       c := SBreadDMAChannel(SB_DMA_PORT);
|       if c = $FFFF then exit;
|       move(m_multivoice_data^[m_multivoice_size-c],
|                                              m_multivoice_data^[1],c);
|          // À½¼º µ¥ÀÌÅÍ ¿µ¿ªÀ¸·Î º¹»ç
|     {$IFDEF DPMI}
|       physical := longint(m_multivoice_ptr shr 16) shl 4;
|          // º¸È£¸ðµåÀÏ ¶§ À½¼º µ¥ÀÌÅÍÀÇ ¹°¸®Àû ÁÖ¼Ò ¾ò±â
|     {$ELSE}
|       physical := longint(Seg(m_multivoice_data^)) shl 4 +
|                                               Ofs(m_multivoice_data^);
|          // ¸®¾ó¸ðµåÀÏ ¶§ À½¼º µ¥ÀÌÅÍÀÇ ¹°¸®Àû ÁÖ¼Ò ¾ò±â
|     {$ENDIF}
|       for i := 1 to m_voice_data[handle].size do begin
|          // ¹öÆÛ »çÀÌÁŭ ¹Í½ÌÀ»..
|          if (m_multivoice_size >= i) and (m_multivoice_data^[i] <>
|                              m_voice_data[handle].data^[i]) then begin
|             j := m_multivoice_data^[i];
|                // »õ·Î µé¾î¿Ã µ¥ÀÌÅÍ
|             k := m_voice_data[handle].data^[i];
|                // ÀÌ¹Ì ¹öÆÛ¿¡ µé¾î ¿Í ÀÖ´Â µ¥ÀÌÅÍ
|             j := j+k-128;
|                // ¹Í½Ì ( ÀÌ ºÎºÐÀÇ °ø½ÄÀº Á÷Á¢ ±Í·Î µè°í ¸ÂÃç¾ß ÇÔ )
|             if j < 0 then j := 0;
|                // ¾ð´õ Ç÷οìÀÏ ¶§
|             if j > $FF then j := $FF;
|                // ¿À¹ö Ç÷οìÀÏ ¶§
|          end else j := m_voice_data[handle].data^[i];
|             // ¹Í½Ì ÇÒ µ¥ÀÌÅÍ ¿µ¿ªÀÌ ¾Æ´Ï¸é ±×´ë·Î
|          m_multivoice_data^[i] := j;
|             // ¹Í½Ì µÈ µ¥ÀÌÅ͸¦ ¹öÆÛ¿¡ ³Ö±â
|       end;
|
|       if c < m_voice_data[handle].size then
|          m_multivoice_size := m_voice_data[handle].size
|       else
|          m_multivoice_size := c;
|       playDMAVoice(physical,m_multivoice_size);
|          // »ç¿îµå ºí·¡½ºÅÍ DMA ·Î Ç÷¹ÀÌÇÑ´Ù.
|    end
|    else begin


------------------------------------------------------------------------

(5) Direct Sound ¼Ò¸ê

ÇÊÀÚ°¡ »ç¿ëÇÏ°í ÀÖ´Â ¼Ò¸êÀÚÀÇ ÇÑ ºÎºÐÀÌ´Ù.

|    for i := 0 to MAX_CHANNEL do begin
|       if Assigned(DirectSoundBuffer[i]) then begin
|          DirectSoundBuffer[i]._Release;
|          Pointer(DirectSoundBuffer[i]) := nil;
|       end;
|       if Assigned(DirectSound3DBuffer[i]) then begin
|          DirectSound3DBuffer[i]._Release;
|          Pointer(DirectSound3DBuffer[i]) := nil;
|       end;
|    end;
|
|    if Assigned(DirectSound) then begin
|       DirectSound._Release;
|       Pointer(DirectSound) := nil;
|    end;

ÀڱⰡ ¸¸µç ¹öÆÛÀÇ °³¼ö¸¸Å­ Release ½ÃÄÑ Áִµ¥ ( ¹°·Ð ÇÒ´çµÈ ¹öÆÛ¿¡¸¸ )
2D ¹öÆÛÀ̵ç, 3D ¹öÆÛÀÌµç °£¿¡ ¸ðµÎ ÇØÁ¦ÇØ¾ß ÇÏ°í, ¹öÆÛ¸¦ ÇØÁ¦ÇßÀ¸¸é ¸¶Áö
¸·À¸·Î IDirectSound ÀÎÅÍÆäÀ̽º °´Ã¼¸¦ Release ½ÃŲ´Ù.

Áï, ÀڱⰡ ¸¸µç °Í¸¸ Ã¥ÀÓÀ» Áö¸é µÇ´Â °ÍÀÌ´Ù.


------------------------------------------------------------------------
                                                          1999 / 11 / 07

#####################################################


------------------------------------------------------------------------
### µ¨ÆÄÀÌ·Î ÇÏ´Â Direct X - Direct Sound (4/4)

    1. Direct Sound ÀÇ °³¿ä
    2. Direct Sound ÃʱâÈ­¿Í Wave Àбâ
    3. ¹öÆÛ¸¦ ÅëÇÑ Ãâ·Â°ú ¹Í½Ì
    4. 3D ¹öÆÛ¸¦ ÅëÇÑ Ãâ·Â°ú ¹Í½Ì
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

------------------------------------------------------------------------
                                    ÀÛ¼ºÀÚ : ¾È¿µ±â ( HiTEL ID : SMgal )

------------------------------------------------------------------------

(1) Direct Sound Buffer ÀÇ ½ºÅ×·¹¿À Á¦¾î

ÀÏ´Ü 3D ¹öÆÛ¿¡ µé¾î°¡±â Àü¿¡ ¸ÕÀú ÇØ¾ß ÇÒ °ÍÀÌ Àִµ¥,  ±×°ÍÀº ´Ù¸§ ¾Æ´Ï
¶ó Volume Á¦¾î¿Í Pan Á¦¾îÀÌ´Ù.  Volume Àº ´Ù ¾Æ½Ç °ÍÀÌ°í  Pan Àº Balance
¿Í °°Àº ¸»ÀÌ´Ù. ÁÂ¿ì ½ºÇÇÄ¿ÀÇ ¾î´À ÂÊÀ¸·Î À½ÀÌ ÆíÇâµÇ´Â °¡¸¦ ¸»ÇÑ´Ù.
( ½ÇÁ¦ Pan Àº ¾çÂÊ Volume À» ¼­·Î ´Ù¸£°Ô Á¶ÀýÇÏ´Â °Í»ÓÀÌ´Ù. )

IDirectSoundBuffer ¿¡´Â ´ÙÀ½ÀÇ 4 °³ÀÇ ¸Þ½îµå°¡ ÀÖ´Ù.
¹°·Ð ÀÌ°ÍÀº ¹öÆÛ°¡ »ý¼ºµÉ ¶§  DSBCAPS_CTRLDEFAULT Ç÷¡±×¸¦ »ç¿ëÇؼ­ »ý¼º
ÇßÀ» ¶§¸¸ »ç¿ë °¡´ÉÇÑ °ÍÀÌ´Ù.

   SetVolume() - Volume À» Á¶ÀýÇÑ´Ù.
                 DSBVOLUME_MIN ÀÌ  °¡Àå ÀÛÀº °ª  ( ¼Ò¸®°¡ ¾È µé¸² ) ÀÌ°í
                 DSBVOLUME_MAX °¡Àå Å« °ª ( ¿ø·¡ÀÇ ¼Ò¸® Å©±â ) ÀÌ´Ù.

   GetVolume() - ÇöÀçÀÇ Volume À» °¡Á®¿Â´Ù.
                 DSBVOLUME_MIN = -10000;
                 DSBVOLUME_MAX = 0; À¸·Î ¼³Á¤µÇ¾î ÀÖ´Ù.

   SetPan()    - Pan À» Á¶ÀýÇÑ´Ù.
                 DSBPAN_LEFT ´Â ¿ÞÂÊ ÆíÇâÀÇ ÃÖ´ë °ªÀÌ°í  DSBPAN_RIGHT ´Â
                 ¿À¸¥ÂÊ ÆíÇâÀÇ ÃÖ´ë °ªÀÌ´Ù.  ¾çÂÊÀ» °°Àº Å©±â·Î ¸¸µé·Á¸é
                 DSBPAN_CENTER À» »ç¿ëÇÏ¸é µÈ´Ù.

   GetPan()    - ÇöÀçÀÇ Pan À» °¡Á®¿Â´Ù.
                 DSBPAN_LEFT = -10000;
                 DSBPAN_CENTER = 0;
                 DSBPAN_RIGHT = 10000; À¸·Î ¼³Á¤µÇ¾î ÀÖ´Ù.


½ÇÁ¦·Î class ¸¦ ±¸¼ºÇØ º»´Ù´Â ¾Æ·¡Ã³·³ ¸¸µé ¼ö ÀÖ°Ú´Ù.
¾Æ·¡¿¡¼­´Â Volume °ú Pan À» property ·Î  ¼³Á¤Çϸ鼭  ±× °ªÀÇ ¹üÀ§¸¦ ¿ì¸®
¿¡°Ô Àͼ÷ÇÑ 0 °ú 255 ÀÇ °ªÀ¸·Î ¸®½ºÄÉÀϸµ Çß´Ù.

| type
|
|    TDXSound = class
|       property    Volume[Channel : integer] : Longint
|                                       read  GetVolume write SetVolume;
|          // º¼·ýÀº 0 - 255 ÀÇ ¹üÀ§¸¦ °¡Áø´Ù.
|       property    Pan   [Channel : integer] : Longint
|                                       read  GetPan    write SetPan;
|          // LEFT ÃÖ´ë : -256, RIGHT ÃÖ´ë : 256
|    end;
|
| const
|    MAX_PAN_VALUE   = 256;
|    MIN_PAN_VALUE   = -256;
|    MIN_VOL_VALUE   = 0;
|    MAX_VOL_VALUE   = 256;
|    SHIFT_VOL_VALUE = -256;
|    SHIFT_PAN_VALUE = -0;
|    MUL_PAN_VALUE   = 20;
|    MUL_VOL_VALUE   = 20;
|
| procedure   TDXSound.SetVolume(Channel : integer; Value : Longint);
| var
|    HR : Longint;
| begin
|    if not Assigned(DirectSound) then exit;
|
|    if Channel in [1..MAX_CHANNEL] then
|    if Assigned(DirectSoundBuffer[Channel]) then begin
|       if Value < MIN_VOL_VALUE then Value := MIN_VOL_VALUE;
|       if Value > MAX_VOL_VALUE then Value := MAX_VOL_VALUE;
|       HR := DirectSoundBuffer[Channel].SetVolume(
|                            (Value + SHIFT_VOL_VALUE) * MUL_VOL_VALUE);
|    end;
| end;
|
| function    TDXSound.GetVolume(Channel : integer) : Longint;
| var
|    HR    : Longint;
|    Value : Longint;
| begin
|    GetVolume := 0;
|    if not Assigned(DirectSound) then exit;
|
|    if Channel in [1..MAX_CHANNEL] then
|    if Assigned(DirectSoundBuffer[Channel]) then begin
|       Value := 0;
|       HR := DirectSoundBuffer[Channel].GetVolume(Value);
|       GetVolume := Value div MUL_VOL_VALUE - SHIFT_VOL_VALUE;
|    end;
| end;
|
| procedure   TDXSound.SetPan(Channel : integer; Value : Longint);
| var
|    HR : Longint;
| begin
|    if not Assigned(DirectSound) then exit;
|
|    if Channel in [1..MAX_CHANNEL] then
|    if Assigned(DirectSoundBuffer[Channel]) then begin
|       if Value < MIN_PAN_VALUE then Value := MIN_PAN_VALUE;
|       if Value > MAX_PAN_VALUE then Value := MAX_PAN_VALUE;
|       HR := DirectSoundBuffer[Channel].SetPan(
|                            (Value + SHIFT_PAN_VALUE) * MUL_PAN_VALUE);
|    end;
| end;
|
| function    TDXSound.GetPan(Channel : integer) : Longint;
| var
|    HR    : Longint;
|    Value : Longint;
| begin
|    GetPan := 0;
|    if not Assigned(DirectSound) then exit;
|
|    if Channel in [1..MAX_CHANNEL] then
|    if Assigned(DirectSoundBuffer[Channel]) then begin
|       Value := 0;
|       HR := DirectSoundBuffer[Channel].GetPan(Value);
|       GetPan := Value div MUL_PAN_VALUE - SHIFT_PAN_VALUE;
|    end;
| end;

------------------------------------------------------------------------

(2) Direct Sound 3D Buffer ÀÇ °³¿ä

3D ¹öÆÛ´Â Áö±Ý±îÁö ¾ð±ÞÇÑ 2D ¹öÆÛ¿Í´Â ´Þ¸® ½ÇÁ¦ °ø°£»ó¿¡¼­ÀÇ À½¿øÀ» ½Ã¹Ä
·¹ÀÌÆ® ÇØÁØ´Ù. »ç¶÷ÀÇ ±Í´Â µÎ °³À̱⠶§¹®¿¡ ¾î´À ÂÊ¿¡¼­ ¼Ò¸®°¡ ³µ´ÂÁö ¾Ë
¼ö°¡ ÀÖ´Ù. À̷лóÀ¸·Î 2 °³À̱⠶§¹®¿¡  ¿À¸¥ÂÊÀÎÁö ¿ÞÂÊÀÎÁöÀÇ 1 Â÷¿ø ÀûÀ¸
·Î ¼Ò¸®ÀÇ ¹æÇâÀ» ¾Ë ¼ö ÀÖ¾î¾ß ÇÑ´Ù. ÇÏÁö¸¸ ½ÇÁ¦´Â ±×·¸Áö ¾Ê´Ù.  À§ÂÊ¿¡¼­
¼Ò¸®°¡ ³µ´Ù´Â °Íµµ ¾Ë ¼ö ÀÖ°í ¼Ò¸®°¡ ¸Ö¾îÁö°í ÀÖ´ÂÁö ´Ù°¡¿À´Â ¼Ò¸®ÀÎÁöµµ
¾Ë ¼ö ÀÖ°í ¿À¸¥ÂÊÀ̳ª ¿ÞÂÊÀ¸·Î ¾ó¸¶³ª Ä¡¿ìÃÄÁø °÷¿¡¼­ ¼Ò¸®°¡ ³ª´ÂÁöµµ ¾Ë
¼ö ÀÖ´Ù.

µµ´ëü »ç¶÷ÀÇ ±Í´Â ¾î¶² ¸ÞÄ«´ÏÁòÀ¸·Î ±×·± ¼Ò¸®µéÀ» ºÐÇØ ÇÒ ¼ö Àִ°¡..
±×¸®°í  ±× ¿ø¸®¸¸ ¾È´Ù¸é  ÄÄÇ»ÅÍ·Î ÃæºÐÈ÷ ½Ã¹Ä·¹ÀÌÆ® ÇÒ ¼ö ÀÖÀ» °ÍÀ̶ó´Â
»ý°¢¿¡¼­ ³ª¿Â °ÍÀÌ Head - Relative transfer ¶ó´Â °ÍÀÌ´Ù.

¼Ò¸®°¡ ¿À¸¥ÂÊÀ¸·Î ¾ó¸¶³ª Ä¡¿ìÃÆ´ÂÁö ±Í°¡ ¾Ë ¼ö ÀÖ´Â ¹æ¹ýÀ» ¾Ë¾Æº¸ÀÚ.  ¸Õ
Àú ±ÍÀÇ ´ÞÆØÀÌ°ü ¾È¿¡´Â °¢ ÁÖÆļö ´ë¿ªº°·Î °øÁøÀ» ÇÒ ¼ö ÀÖ´Â µ¹±â°¡ ÀÖ¾î
¼­  ÇöÀç µé¾î¿Â ÁÖÆļö¿¡ ´ëÇØ °øÁø ÇÔÀ¸·Î½á  Ã»½Å°æ¿¡ ¾î¶² ÁÖÆļöÀÇ À½ÀÌ
µé¾î¿À°í ÀÖ´Ù´Â °ÍÀ» ¾Ë ¼ö ÀÖ´Ù. ±×¸®°í ±× µ¹±â´Â ÁÖÆļö¿Í À½ÀÇ ÇÇÄ¡( À½
»öÀ» °áÁ¤ )¿Í µé¾î¿Â ½Ã°£Àº ¼¼¹ÐÇÏ°Ô ºÐ¼® ÇÒ ¼ö ÀÖ´Ù. Áö±Ý ¸»ÇÏ·Á°í ÇÏ´Â
'¾î´À ÂÊÀ¸·Î Ä¡¿ìÃƴ°¡' ÇÏ´Â ¹®Á¦´Â ¹Ù·Î ½Ã°£Â÷¿¡ ÀÖ´Ù.  ÇÑ À½¿ø¿¡¼­ ³ª
¿Â ¼Ò¸®°¡ À̵¿ÇÏÁö ¾Ê´Â´Ù¸é ÁÖÆļö¿Í ÇÇÄ¡´Â °°´Ù.  ÇÏÁö¸¸ ¿ÞÂÊ ±Í¿Í ¿À¸¥
ÂÊ ±Í´Â ¾î´À Á¤µµ °Å¸®¸¦ µÎ°í ÀÖ°í ±²ÀåÈ÷ ªÀº ¼ø°£ÀÌÁö¸¸ ¿ÞÂÊ ±Í¿¡¼­ À½
À» ¹Þ¾ÒÀ» ¶§¿Í ¿À¸¥ ÂÊ ±Í¿¡¼­ À½À» ¹Þ¾ÒÀ» ¶§ÀÇ ½Ã°£ Â÷ÀÌ°¡ Àִµ¥,  ÀÌ°Í
À» ³ú°¡ ºÐ¼®Çؼ­ ¾î´À ÂÊ¿¡¼­ ¼Ò¸®°¡ µé¾î¿À´Â °¡¸¦ ¾Ë ¼ö°¡ ÀÖ´Â °ÍÀÌ´Ù.

±×¸®°í ¼Ò¸®°¡ ´Ù°¡¿À°Å³ª ¸Ö¾îÁö´Â °Íµµ ±Í°¡ °¨Áö ÇÒ ¼ö ÀÖ´Ù. ÀÌ°ÍÀº õ¹®
Çп¡¼­ »ç¿ëÇÏ´Â µµÇ÷¯È¿°ú·Î ¼³¸íµÉ ¼ö°¡ ÀÖ´Ù.  ¿ø·¡ µµÇ÷¯È¿°ú´Â ¸Ö¾îÁö
´Â Ç×¼ºÀº 'Àû»ö ÆíÀÌ'°¡ ÀϾ°í  ´Ù°¡¿À´Â º°Àº 'û»ö ÆíÀÌ'°¡ ÀϾ´Ù°í
°íµîÇб³ ¶§ ¹è¿ü¾ú´Ù.  Àû»ö ÆíÀ̶ó´Â °ÍÀº ¿ø·¡ »öº¸´Ù  Àû»öÀ¸·Î º¯ÇÑ´Ù´Â
°ÍÀε¥, ºû ¿ª½Ã ÁÖÆļöÀÓÀ» »ý°¢Çغ¸¸é ÁÖÆļö°¡ °¨¼ÒÇÑ´Ù´Â °³³äÀ¸·Î ¾Ë ¼ö
ÀÖ´Ù. ¹Ý´ë·Î û»ö ÆíÀÌ´Â ÁÖÆļö°¡ ¿ø·¡º¸´Ù Áõ°¡ÇÏ´Â °ÍÀÌ´Ù.  ¼Ò¸®µµ ¸¶Âù
°¡ÁöÀε¥, ´Ù°¡¿À´Â ¼Ò¸®´Â ÁÖÆļö°¡ Áõ°¡ÇÏ°í ¸Ö¾îÁö´Â ¼Ò¸®´Â ÁÖÆļö°¡  °¨
¼ÒÇÑ´Ù. ±×·¡¼­ ±Í°¡ ±× ÁÖÆļöÀÇ º¯È­¸¦ °¨ÁöÇؼ­ À½¿øÀÇ À̵¿ ¿©ºÎ¸¦ ¾Ë ¼ö
°¡ ÀÖ´Â °ÍÀÌ´Ù.

À§ÀÇ µÑÀ» ÇÕÇÑ´Ù¸é ¿ÞÂÊ¿¡¼­ ¿À¸¥ÂÊÀ¸·Î ¸Ö¾îÁö°Ô À̵¿ÇÏ´Â À½¿øÀ» ½ºÇÇÄ¿·Î
µµ Ç¥Çö ÇÒ ¼ö ÀÖÀ» °ÍÀÌ´Ù.
( 1ÀÎĪ 3D °ÔÀÓ¿¡¼­ ¹°Ã¼°¡ ȹ~~ÇÏ°í ³¯¾Æ¼­ Áö³ª°¡´Â ¼Ò¸®ÀÇ Ç¥ÇöÀÌ °¡´ÉÇØ
Áø´Ù )

±×¸®°í  ±× ÀÌ¿Ü¿¡ '·Ñ¿ÀÇÁ'¶ó´Â °³³äÀÌ ÀÖ´Ù.  ÀÌ°ÍÀº ¼Ò¸®°¡ ¸Ö¾îÁö°Å³ª ÇÒ
¶§ °¨¼è Á¤µµ¸¦ ¸»ÇÏ´Â °ÍÀÌ´Ù. ¼Ò¸®°¡ ÆÛÁ® ³ª°¥ ¶§ °Å¸®ÀÇ Á¦°öÀ¸·Î ¿¡³ÊÁö
°¡ ¹ÝÀ¸·Î ÁÙ ±â ¶§¹®¿¡  ÀÌ °³³äÀÌ ÇÊ¿äÇÑ °ÍÀÌ´Ù.  ( 3 Â÷¿ø °ø°£¿¡¼­ ÆÛÁ®
³ª°¡´Â ÂÊÀ» ½Ã°£ ÃàÀ¸·Î ÀâÀ» ¼ö Àֱ⠶§¹®¿¡ ³²Àº °ÍÀº 2 Â÷¿ø.. µû¶ó¼­ Á¦
°ö¸¸Å­ ¿¡³ÊÁö°¡ ÆÛÁø´Ù. ) ÇÏÁö¸¸ ½ÇÁ¦ÀÇ °ÔÀÓ  Á¦ÀÛ¿¡¼­´Â ½Ç¼¼°èÀÇ ·Ñ¿ÀÇÁ
¸¦ Àû¿ëÇÏ¸é ¾È µÈ´Ù.  ±×·¸±â ¶§¹®¿¡ Direct Sound ¿¡¼­µµ ·Ñ¿ÀÇÁ ¼öÄ¡¸¦ Á÷
Á¢ ÁöÁ¤ÇÒ ¼ö ÀÖ°Ô ÇØÁØ´Ù.


------------------------------------------------------------------------

(3) Direct Sound 3D Buffer ÀÇ »ý¼º

DirectSound3DBuffer ¸¦ »ý¼ºÇÏ´Â ¹æ¹ýÀÌ ¾Æ·¡¿¡ ÀÖ´Ù.

| var
|    DirectSoundBuffer : IDirectSoundBuffer;
|       // Àü¿ª º¯¼ö ¶Ç´Â Ŭ·¡½ºÀÇ ¸â¹ö º¯¼ö°¡ µÇ´Â Sound Buffer °´Ã¼

| function   CreateSoundBuffer(WaveFormatEx  : TWaveFormatEx) : boolean;
| var
|    DSBufferDesc  : TDSBUFFERDESC;
|    DSResult      : HResult;
| begin
|    CreateSoundBuffer := FALSE;
|    if not Assigned(DirectSound) then exit;
|       // Direct Sound °¡ ÃʱâÈ­ µÇ¾î ÀÖÁö ¾Ê´Ù¸é ÀÌ ÇÔ¼ö´Â ½ÇÆÐ
|
|    WaveFormatEx.cbSize          := sizeof(TWaveFormatEx);
|       // º¸Åë WAV ÆÄÀÏ¿¡¼­ WaveFormatEx ¸¦ °¡Á® ¿Ã ¶§  cbSize ºÎºÐ±îÁö
|       // Á¤º¸¸¦ ÀúÀåÇÏÁö ¾Ê´Â WAV Æ÷¸ËÀÌ ÀÖ´Ù. ±×·² ¶§¸¦ ´ëºñÇؼ­ ¼öµ¿
|       // À¸·Î ³Ö¾î ÁØ´Ù. ¾È ³Ö¾îµµ µÉÁöµµ ¸ð¸¥´Ù.
|
|    FillChar(DSBufferDesc,sizeof(TDSBufferDesc),0);
|       // DSBufferDesc ±¸Á¶Ã¼ ÃʱâÈ­
|
|    DSBufferDesc.dwSize          := sizeof(TDSBufferDesc);
|       // Ç×»ó ÀÚ½ÅÀÇ »çÀÌÁ Ç¥½Ã ( ¾È ±×·¯¸é ¿¡·¯ ¹ß»ý )
|    DSBufferDesc.dwFlags         := DSBCAPS_CTRL3D;
|       // 3D ¹öÆÛ¸¦ »ç¿ëÇÔ
|    DSBufferDesc.dwBufferBytes   := BufferLength;
|       // »ý¼ºÇÒ ¹öÆÛÀÇ Å©±â, º¸Åë ½ºÅÂƽ ¹öÆÛ¿¡¼­´Â WAV ÀüüÀÇ Å©±â
|    DSBufferDesc.lpwfxFormat     := @WaveFormatEx;
|       // Àû¿ëÇÒ WaveFormatEx ±¸Á¶Ã¼°¡ ÀÖ´Â °÷ÀÇ Æ÷ÀÎÅÍ
|    DSResult := DirectSound.CreateSoundBuffer(DSBufferDesc,
|                                                DirectSoundBuffer,nil);
|       // »ç¿îµå ¹öÆÛ »ý¼º
|
|    DirectSoundBuffer.QueryInterface(IID_IDirectSound3DBuffer,
|                                                  DirectSound3DBuffer);
|       // ¾Æ·¡¿¡ ¼³¸í ÂüÁ¶
|
|    if DSResult <> DS_OK then begin
|       DirectSoundBuffer := nil;
|          // »ý¼º ½ÇÆÐ
|       exit;
|    end;
|
|    CreateSoundBuffer := TRUE;
|       // »ý¼º ¼º°ø
| end;

º¸½Ã¸é ¾Ë°ÚÁö¸¸ 2D ¹öÆÛ¿Í º° ´Ù¸¦ °Ô ¾ø´Ù. ´ÜÁö ´Ù¸¥ Á¡À̶ó¸é DSBufferDe
sc ÀÇ dwFlags ¿¡ DSBCAPS_CTRL3D ¶ó´Â Ç÷¡±×¸¦ ³Ö´Â´Ù´Â °ÍÀÌ´Ù.  ±×¸®°í´Â
±×³É ÀÏ¹Ý »ç¿îµå ¹öÆÛ¿Í °°ÀÌ ¸¸µç´Ù.

IDirectSound3DBuffer ÀÇ °æ¿ì¿¡´Â IDirectSoundBuffer  °´Ã¼¿¡¼­ ÀÎÅÍÆäÀ̽º
Äõ¸®¿¡ ÀÇÇØ ±× °´Ã¼¸¦ ¹ÞÀ» ¼ö°¡ ÀÖ´Ù.

|    DirectSoundBuffer.QueryInterface(IID_IDirectSound3DBuffer,
|                                                  DirectSound3DBuffer);

¿©±â ÀÌ ±¸¹®Àε¥.. ÀüÇüÀûÀÎ COM ÀÇ ¹æ½Ä ±×´ë·ÎÀÌ´Ù. ÆĶó¸ÞÅÍ¿¡ 3D ¹öÆÛÀÇ
ÀÎÅÍÆäÀ̽º ID ¸¦ ³Ö°í ¹öÆÛÀÇ °´Ã¼¸¦ »©¿À¸é µÈ´Ù.

ÀÌ·¸°Ô ÇÏ¸é  ±× ´ÙÀ½ºÎÅÍ´Â DirectSound3DBuffer ¿¡¼­ ¸Þ½îµå¸¦ »ç¿ëÇÏ¸é µÈ
´Ù.
( Pan °ü·Ã ¸Þ½îµå¸¦ Á¦¿ÜÇÑ ¸ðµç 2D ¹öÆÛÀÇ ¸Þ½îµå¸¦ »ç¿ëÇÒ ¼ö°¡ ÀÖ´Ù. )

IDirectSound3DBuffer ¿¡ ÀÖ´Â ¸Þ½îµåÀÇ ±â´ÉÀ» ¿ä¾àÇÏ¸é ´ÙÀ½°ú °°´Ù.

1) SetAllParameters     -
   ÁÖ¾îÁø TDS3DBuffer ±¸Á¶Ã¼·ÎºÎÅÍ  Çѹø¿¡ 3D »ç¿îµå ¹öÆÛ¿¡ ´ëÇÑ ¸ðµç ÆÄ
   ¶ó¸ÞÅ͸¦ ¼³Á¤ÇÑ´Ù. TDS3DBuffer ±¸Á¶Ã¼´Â ¾Æ·¡¿Í °°ÀÌ Á¤ÀǵǾîÁ® ÀÖ´Ù.

   TDS3DBuffer = packed record
      dwSize             : DWORD;      // TDS3DBuffer ±¸Á¶Ã¼ Å©±â
      vPosition          : TD3DVector; // À½¿ø À§Ä¡
      vVelocity          : TD3DVector; // À½¿ø ¼Óµµ
      dwInsideConeAngle  : DWORD;      // ³»ºÎ »ç¿îµå ÄÜ °¢µµ
      dwOutsideConeAngle : DWORD;      // ¿ÜºÎ »ç¿îµå ÄÜ °¢µµ
      vConeOrientation   : TD3DVector; // »ç¿îµå ÄÜÀÌ ÇâÇÏ´Â ¹æÇâ
      lConeOutsideVolume : Longint;    // »ç¿îµå ÄÜ¿¡¼­ ¹ß»ýÇÏ´Â º¼·ý
      flMinDistance      : TD3DValue;  // ÃÖ¼Ò °Å¸® ¼³Á¤
      flMaxDistance      : TD3DValue;  // ÃÖ´ë °Å¸® ¼³Á¤
      dwMode             : DWORD;      // 3D ¹öÆÛ ¼³Á¤ ¸ðµå
   end;

   TD3DValue = single;

   TD3DVector = packed record
      case Integer of
      0: (
         x : TD3DValue;
         y : TD3DValue;
         z : TD3DValue;
      );
      1: (
         dvX : TD3DValue;
         dvY : TD3DValue;
         dvZ : TD3DValue;
      );
   end;

2) SetConeAngles        -
   ³»ºÎ »ç¿îµå ÄÜ °¢µµ¿Í ¿ÜºÎ »ç¿îµå ÄÜ °¢µµ¸¦ ÁÙ ¼ö ÀÖ´Ù. »ç¿îµå ÄÜÀ̶õ
   È®¼º±â ¸ð¾çÀ¸·Î ÆÛÁ® ³ª°¡´Â À½À» Ãß»óÈ­ÇÑ °ÍÀÌ´Ù.

3) SetConeOrientation   -
   µðÆúÆ®´Â z ¸¸ 1 ÀÌ µÈ´Ù. ÇöÀç »ç¿îµå ÄÜÀÌ ÇâÇÏ´Â ¹æÇâÀ» ÁöÁ¤ÇÑ´Ù.

4) SetConeOutsideVolume -
   »ç¿îµå ÄÜÀÇ º¼·ýÀÌ´Ù.

5) SetMaxDistance       -
   ¹ÌÅÍ ´ÜÀ§ÀÇ ÃÖ´ë °Å¸® ¼³Á¤. ½ÇÁ¦ µé¸®Áö ¾ÊÀ» °÷±îÁö ¼³Á¤Çؼ­ CPU ¿¡°Ô
   ºÎ´ãÀ»  Á༭´Â ¾È µÈ´Ù. °ÔÀÓ¿¡ ¸Â´Â ¼öÄ¡¸¦ ³ÖÀ¸¸é µÈ´Ù. µðÆúÆ®´Â 10¾ï
   ¹ÌÅÍ

6) SetMinDistance       -
   ¹ÌÅÍ ´ÜÀ§ÀÇ ÃÖ¼Ò °Å¸® ¼³Á¤.  ÃּҰŸ®¸¦ ¼³Á¤ÇÏÁö ¾ÊÀ¸¸é À½¿ø°ú ºÎµúÇû
   À» ¶§ ¹Ù·Î ±Í¿¡´Ù°¡ ¼Ò¸®Ä¡´Â È¿°ú¸¦ ³»ÁÖ¾î¾ß ÇÏÁö¸¸  ÃּҰŸ® ¼³Á¤ ´ö
   ºÐ¿¡ ¾î´À Á¤µµ Á¢±ÙÇÏ¸é ¼Ò¸®ÀÇ db Áõ°¡´Â ¾ø¾îÁø´Ù. µðÆúÆ®´Â 1 ¹ÌÅÍ

7) SetMode              -
   ¹öÆÛÀÇ ¸ðµå¸¦ ¼³Á¤Çϴµ¥ ÃÑ 3 °¡ÁöÀÇ °æ¿ì°¡ ÀÖ´Ù.

   DS3DMODE_NORMAL       - Àý´ë ÁÂÇ¥ÀûÀÎ À§Ä¡ÀÇ ¹öÆÛ°¡ µÈ´Ù. µðÆúÆ®
   DS3DMODE_HEADRELATIVE - 1 ÀÎĪ ½ÃÁ¡À¸·Î µè´Â »ç¶÷ Áß½ÉÀÌ µÈ´Ù.
   DS3DMODE_DISABLE      - »ç¿îµå ¹öÆÛ¿¡ ´ëÇÑ 3D ±â´ÉÀ» ²ö´Ù.

8) SetPosition          -
   À½¿øÀÇ À§Ä¡¸¦ °áÁ¤ÇÑ´Ù. x °¡ + ÀÌ¸é ¿À¸¥ÂÊ, y °¡ + À̸é À§ÂÊÀ»,  z °¡
   + ÀÌ¸é µÚÂÊÀ» °¡¸®Å²´Ù.

9) SetVelocity          -
   À½¿øÀÇ À̵¿ ¼Óµµ¸¦ ³ªÅ¸³½´Ù. ´ÜÀ§´Â ¹ÌÅÍÀÌ´Ù.

------------------------------------------------------------------------

(4) Direct Sound 3D Buffer ÀÇ Àç»ý

Àç»ýÀº 2D ¹öÆÛÀÏ ¶§¿Í º°¹Ý ´Ù¸£Áö ¾Ê´Ù.
¸¸¾à  À½¿øÀÇ À§Ä¡¸¦ ÁöÁ¤ÇÏÁö ¾Ê°í  µðÆúÆ®¸¦ ±×´ë·Î ¾´´Ù¸é ÀüÇô 2D ¹öÆÛ¿Í
´Ù¸¥ Á¡À» ´À³¥ ¼ö ¾øÀ» Á¤µµÀÌ´Ù.

°£´ÜÇÏ°Ô (x,y,z) ÁÂÇ¥¿¡ ÀÖ´Â À½¿ø¿¡¼­ ³ª´Â ¼Ò¸®¸¦  Ç÷¹ÀÌ Çغ¸¸é  ´ÙÀ½°ú
°°´Ù.

|   DirectSound3DBuffer.SetPosition(x,y,z,DS3D_IMMEDIATE);
|   DirectSoundBuffer.SetCurrentPosition(0);
|   DirectSoundBuffer.Play(0,0,0);

SetPosition() ´ë½Å À§ÀÇ ´Ù¸¥ ¸Þ½îµå¸¦ ½á¼­µµ ½ÃÇèÀ» Çغ¸¸é °á°ú¸¦  ¾Ë ¼ö
ÀÖÀ» °ÍÀÌ´Ù.


------------------------------------------------------------------------

<< ¿¡ÇÊ·Î±× >>

Áö±Ý±îÁö ¼³¸íÇÑ °ÍÀº Direct X ÀÇ »ç¿îµå µð¹ÙÀ̽º ºÎºÐÀÎ  Direct Sound ºÎ
ºÐÀ̾ú½À´Ï´Ù. µ¨ÆÄÀÌ·Î °ÔÀÓ ¸¸µå½Ã·Á´Â ºÐµé²² Á¶±ÝÀ̳ª¸¶ µµ¿òÀÌ µÇ¾úÀ¸¸é
ÁÁ°Ú½À´Ï´Ù.

Áö±Ý±îÁö µ¨ÆÄÀÌ·Î Direct Draw, ¸ÖƼ¹Ìµð¾î ŸÀ̸Ó, DIB, Direct Input, MMX,
Direct Sound ±îÁöÀÇ °­Á¸¦ Çߴµ¥... ÀÌ ¸ðµç °­ÁµéÀº Á¦ ȨÆäÀÌÁö¿¡ ¿À½Ã
¸é ¹ÙÀ̳ʸ® ÀÚ·áµµ °°ÀÌ ±¸ÇÏ½Ç ¼ö°¡ ÀÖ½À´Ï´Ù.  ( ¹°·Ð ¹ÙÀ̳ʸ® ÀÚ·á°¡ ÀÖ
´Â °Í¸¸.. )

   < http://smgal.com/ >

¾ÕÀ¸·Î °­Á ¿¹Á¤ÀÌ Direct Music °ú Direct Play ÀÔ´Ï´Ù. µÉ ¼ö ÀÖÀ¸¸é ³¡±î
Áö °­Á¸¦  ½á º¸°í ½Í½À´Ï´Ù...

±×·³ ¸¶Áö¸·À¸·Î ÇѸ¶µð ³²±â°Ú½À´Ï´Ù.

          " A mountain is a mountain, Water is water. "
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

                                              copyright SMgal 1999/11/07