Platform SDK: DirectX |
This section pertains only to DirectX for Visual Basic. See DirectSound C/C++ Tutorials.
After you create the main DirectSound object, the next step is to create a secondary sound buffer and load a wave file into it.
You describe the characteristics of the buffer in a DSBUFFERDESC type. The first member sets the size of the buffer. However, because you are going to create the buffer from a file, you don't have to initialize this member. DirectSound makes the buffer just the right size for the data in the file. The second member describes various capabilities you want the buffer to have. The following example code describes a buffer that will allow the application to change the frequency, pan, and volume. In addition, the DDSBCAPS_STATIC flag indicates that the buffer should be located in memory on the sound card if this is available. Usually it isn't.
Dim bufferDesc As DSBUFFERDESC Dim waveFormat As WAVEFORMATEX bufferDesc.lFlags = DSBCAPS_CTRLFREQUENCY Or DSBCAPS_CTRLPAN _ Or DSBCAPS_CTRLVOLUME Or DSBCAPS_STATIC
The other variable you need to pass to the creation method is a WAVEFORMATEX type. Again, DirectSound will get the necessary wave format information from the file, so you don't need to initialize this type. If you like, you can check the type after the method call to see what format was set.
To create the buffer, call the DirectSound.CreateSoundBufferFromFile method, as follows:
Set m_dsBuffer(i) = m_ds.CreateSoundBufferFromFile( _ sfile, bufferDesc, waveFormat)
Next: Step 3: Play the Sound