
03-02-2006, 04:32 AM
|
 |
Junior Contributor
|
|
Join Date: Jul 2005
Location: Wherever i fall over
Posts: 222
|
|
Stream from a buffer.
Quote:
|
Originally Posted by VirgilFox
I've downloaded sample code for directsound which demonstrates loading a DS buffer from a wave or loading from a resource - even streaming from a file, but is it possible to stream directly from an array in memory?
I'm generating sound samples in real time. I want to send them directly to a streaming DS buffer.
Thanks.
|
I am on fire today.
If you want to stream from memory then you have to create the buffer from scratch. use the create function to make the buffer you must know the parameters for the buffer or it will fail. Then you just play it in the normal way.
you can erase the buffer once it has be created.
Leade
Code:
Option Explicit
Private Const WaveFormat = DxVBLibA.WAVE_FORMAT_PCM
Private Format As DxVBLibA.WAVEFORMATEX
Private Type SecondaryBufferDetails
SoundBuffer As DxVBLibA.DirectSoundSecondaryBuffer8
SoundDescription As DxVBLibA.DSBUFFERDESC
SoundCursor As DxVBLibA.DSCURSORS
BufferStatus As DxVBLibA.CONST_DSBSTATUSFLAGS
End Type
Private SoundData As SecondaryBufferDetails
'Creation
Public Function Create(ByRef Dx8Sound As DxVBLibA.DirectSound8, BytesPerSec As Long, Extra As Long, _
SamplesPerSec As Long, BitsPerSample As Integer, _
BlockAlign As Integer, Channels As Integer, _
FormatTag As Integer, Size As Integer, BufferBytes As Long, _
ByRef Data() As Byte, Optional Offset As Long = 0)
'First we must set the format
With SoundData.SoundDescription
.fxFormat.lAvgBytesPerSec = BytesPerSec
.fxFormat.lExtra = Extra
.fxFormat.lSamplesPerSec = SamplesPerSec
.fxFormat.nBitsPerSample = BitsPerSample
.fxFormat.nBlockAlign = BlockAlign
.fxFormat.nChannels = Channels
.fxFormat.nFormatTag = FormatTag
.fxFormat.nSize = Size
Format = .fxFormat
.guid3DAlgorithm = ""
.lFlags = DSBCAPS_LOCDEFER Or DSBCAPS_CTRLFREQUENCY Or DSBCAPS_CTRLPAN Or DSBCAPS_CTRLVOLUME Or DSBCAPS_CTRLPOSITIONNOTIFY Or DSBCAPS_STATIC 'Or DSBCAPS_CTRLFX
.lBufferBytes = BufferBytes
End With
'Now we must create a sound buffer
With SoundData
Set .SoundBuffer = Nothing
Set .SoundBuffer = Dx8Sound.CreateSoundBuffer(.SoundDescription)
End With
'Now read the wave data from the byte array
'SoundData.SoundBuffer.WriteBuffer 0, 0, Data(Offset), DSBLOCK_ENTIREBUFFER
SoundData.SoundBuffer.WriteBuffer 0, BufferBytes, Data(Offset), DSBLOCK_ENTIREBUFFER
SoundData.SoundBuffer.SetCurrentPosition 1
End Function
|
__________________
Fact: The best ideas come when your smashed of your face. So drink beer and be merry!!!
|