tailieunhanh - Advanced 3D Game Programming with DirectX - phần 3
Trong khi bạn có thể liệt kê tất cả các thiết bị âm thanh với DirectSoundEnumerate, thường chỉ có một card âm thanh trên máy tính. Để có được các thiết bị mặc định (đó là những gì bạn muốn, thường), thiết lập này để NULL. Được sử dụng cho COM tập hợp, để điều này như là NULL. | HRESULT WINAPI DirectSoundCreate8 LPCGUID lpcGuid LPDIRECTSOUND8 ppDS LPUNKNOWN pUnkOuter lpcGuid A pointer to a GUID that describes the device you wish to create. While you can enumerate all of the sound devices with DirectSoundEnumerate generally there is only one sound card on a machine. To get the default device which is what you want usually set this to NULL. PpDS A pointer to an LPDIRECTSOUND8 interface pointer that will be filled with a valid interface pointer if the function succeeds. pUnkOuter Used for COM aggregation leave this as NULL. Sample code to create the sound interface appears in the following LPDIRECTSOUND8 m_pDSound 0 Create IDirectSound using the primary sound device hr DirectSoundCreate8 NULL m pDSound NULL if FAILED hr Handle critical error Setting the Cooperative Level After you acquire the interface pointer the next step is to declare how cooperative you intend on being. Just like DirectInput this is done using the SetCooperativeLevel command. HRESULT IDirectSound8 SetCooperativeLevel HWND hwnd DWORD dwLevel 143 hwnd Handle to the window to be associated with the DirectSound object. This should be the primary window. dwLevel One of the following flags describing the desired cooperative level. DSSCL_EXCLUSIVE Grab exclusive control of the sound device. When the application has focus it is the only audible application. DSSCL_NORMAL Smoothest yet most restrictive cooperative level. The primary format cannot be changed. This is the cooperative level the sound layer uses. DSSCL_PRIORITY Like DDSCL_NORMAL except the primary format may be changed. DSSCL_WRITEPRIMARY This is the highest possible priority for an application to have. It can t play any secondary buffers and it has the ability to manually mangle the bits of the primary buffer. Only for the extremely hardcore This code will be changing the primary format of the sound buffer so I ll go ahead and set this to DSSCL_PRIORITY. Sample code to do this appears in the following pDSound is a .
đang nạp các trang xem trước