Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Game Programming > DirectX > Streaming DS directly from memory


Reply
 
Thread Tools Display Modes
  #1  
Old 02-26-2006, 11:34 PM
VirgilFox VirgilFox is offline
Newcomer
 
Join Date: Feb 2006
Location: Auckland
Posts: 1
Default Streaming DS directly from memory


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.
Reply With Quote
  #2  
Old 03-02-2006, 04:32 AM
Leade's Avatar
Leade Leade is offline
Junior Contributor
 
Join Date: Jul 2005
Location: Wherever i fall over
Posts: 222
Cool 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!!!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->