Home > Archive > Visual Basic > March 2006 > Multiple DirectSound Buffers?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Multiple DirectSound Buffers?
|
|
| FrankAm 2006-03-30, 9:55 pm |
| Anybody know how to set up multiple secondary buffers in DirectSound,
whereby I have 24 small wav files, and I want to marry each of them to
their own buffer so that I do not need to first load each file before I
play it?
Do I just add them to the module where my first buffer is declared,
like so:
Public Type DSOUND
DSBuffer1 As DirectSoundSecondaryBuffer8
DSBuffer2 As DirectSoundSecondaryBuffer8
DSBuffer3 As DirectSoundSecondaryBuffer8
DSBuffer4 As DirectSoundSecondaryBuffer8
ETC......???
Do I need 24 of the following blocks of code also? IE... BufferDesc1
and BufferDesc2 etc...?
Dim BufferDesc As DSBUFFERDESC
With BufferDesc
.lFlags = DSBCAPS_CTRLFREQUENCY Or DSBCAPS_CTRLPAN Or
DSBCAPS_CTRLVOLUME Or DSBCAPS_STATIC 'Or DSBCAPS_CTRLFX
With .fxFormat
.nFormatTag = WAVE_FORMAT_PCM
.nChannels = 2
.lSamplesPerSec = 44100
.nBitsPerSample = 16
.nBlockAlign = (.nChannels * .nBitsPerSample) / 8
.lAvgBytesPerSec = .lSamplesPerSec * .nBlockAlign
.nSize = 0 ' Ignored for WAVE_FORMAT_PCM
End With
End With
What does the Set thing do, do I need 24 of these?
Set SONG(nCurrentSong).DRUM(Index).SoundBuffer.DSBuffer =
ds. CreateSoundBufferFromFile(SONG(nCurrentS
ong).DRUM(Index).sWavFile,
BufferDesc) 'As DirectSoundSecondaryBuffer8
End Sub
Any help is much appreciated.
| |
| Alfie [UK] 2006-03-31, 7:55 am |
| On 30 Mar 2006 18:36:13 -0800, "FrankAm" <frankamendola@sbcglobal.net>
wrote:
>Anybody know how to set up multiple secondary buffers in DirectSound,
>whereby I have 24 small wav files, and I want to marry each of them to
>their own buffer so that I do not need to first load each file before I
>play it?
>
>Do I just add them to the module where my first buffer is declared,
>like so:
>
>Public Type DSOUND
> DSBuffer1 As DirectSoundSecondaryBuffer8
> DSBuffer2 As DirectSoundSecondaryBuffer8
> DSBuffer3 As DirectSoundSecondaryBuffer8
> DSBuffer4 As DirectSoundSecondaryBuffer8
>ETC......???
You can do, personally I would just use an ARRAY rather than a TYPE.
>
>Do I need 24 of the following blocks of code also? IE... BufferDesc1
>and BufferDesc2 etc...?
>
>Dim BufferDesc As DSBUFFERDESC
> With BufferDesc
> .lFlags = DSBCAPS_CTRLFREQUENCY Or DSBCAPS_CTRLPAN Or
>DSBCAPS_CTRLVOLUME Or DSBCAPS_STATIC 'Or DSBCAPS_CTRLFX
> With .fxFormat
> .nFormatTag = WAVE_FORMAT_PCM
> .nChannels = 2
> .lSamplesPerSec = 44100
> .nBitsPerSample = 16
> .nBlockAlign = (.nChannels * .nBitsPerSample) / 8
> .lAvgBytesPerSec = .lSamplesPerSec * .nBlockAlign
> .nSize = 0 ' Ignored for WAVE_FORMAT_PCM
> End With
> End With
If all your sounds have the same 'capabilities' then you only need 1
buffer descriptor, as you can re-use it for each sound.
You can ignore the .fxFormat flag if you are loading the sound from a
file or resource (the format will be read from the loaded file).
Also pay attention to the capabilities, PAN and VOLUME cannot be mixed
and FX is incompatible with many other capabilities.
>
>What does the Set thing do, do I need 24 of these?
>
>Set SONG(nCurrentSong).DRUM(Index).SoundBuffer.DSBuffer =
>ds. CreateSoundBufferFromFile(SONG(nCurrentS
ong).DRUM(Index).sWavFile,
>BufferDesc) 'As DirectSoundSecondaryBuffer8
>End Sub
>
>Any help is much appreciated.
The SET command is actually loading the buffer with a sound, but there's
a lot of object nesting there to confuse the issue. You will need to SET
each buffer to be loaded with the relevant sound file.
So, minimal version of above;
Dim DSArray(23) as DirectSoundSecondaryBuffer8
Dim BufferDesc As DSBUFFERDESC
BufferDesc.lFlags = DSBCAPS_CTRLFREQUENCY Or DSBCAPS_CTRLVOLUME Or
DSBCAPS_STATIC
Set DSArray(0) = ds.CreateSoundBufferFromFile('FileName0', BufferDesc)
Set DSArray(1) = ds.CreateSoundBufferFromFile('FileName1', BufferDesc)
Set DSArray(2) = ds.CreateSoundBufferFromFile('FileName2', BufferDesc)
Set DSArray(3) = ds.CreateSoundBufferFromFile('FileName3', BufferDesc)
....etc...
--
Alfie
<http://www.delphia.co.uk/>
I'm multi-talented. I can talk and piss you off at the same time.
| |
| FrankAm 2006-03-31, 9:55 pm |
| Thanks!
|
|
|
|
|