On Nov 9, 2006, at 11:52 AM, Robert Carroll wrote:
HI,
I'm hoping to be able to port the following VB code to Realbasic
for a simple windows sound app.
Attribute VB_Name = "directSnd"
Public samPles As Long, myByte(360) As Byte
Public DX7 As New DirectX7, DS As DirectSound, DSB(1) As
DirectSoundBuffer
Public DESC As DSBUFFERDESC, PCM As WAVEFORMATEX
Sub Init_DX7(Hwnd As Long)
Set DS = DX7.DirectSoundCreate("") 'Create the DirectSound Object
DS.SetCooperativeLevel Hwnd, DSSCL_NORMAL 'Set the Cooperative Level
'Fill WaveFormat Structure
PCM.nFormatTag = WAVE_FORMAT_PCM
PCM.nChannels = 1
PCM.lSamplesPerSec = 11025
PCM.nBitsPerSample = 8
PCM.nBlockAlign = 1
PCM.lAvgBytesPerSec = PCM.lSamplesPerSec * PCM.nBlockAlign
PCM.nSize = 0
DESC.lFlags = DSBCAPS_STATIC Or DSBCAPS_CTRLVOLUME Or
DSBCAPS_CTRLFREQUENCY Or DSBCAPS_CTRLPAN
'set Bytes
DESC.lBufferBytes = samPles
'********************************************************
'Create Buffers (buffer "0" and buffer "1")
Set DSB(0) = DS.CreateSoundBuffer(DESC, PCM)
Set DSB(1) = DS.CreateSoundBuffer(DESC, PCM)
DSB(0).Play DSBPLAY_LOOPING 'Initialize to play loop DSBPLAY_LOOPING
DSB(1).Play DSBPLAY_LOOPING '( DSBPLAY_DEFAULT would play the sound
only one time )
End Sub
Sub Term_DX7() 'Clear the created DX7 Objects.
Set DSB(0) = Nothing: Set DSB(1) = Nothing: Set DS = Nothing:
Set DX7 = Nothing
End Sub
Sub DSBWRITE(Num As Integer, ByRef Buffer() As Byte)
'Writing an array of bytes to a given DirectSoundBuffer.
DSB(Num).WriteBuffer 0, 0, Buffer(0), DSBLOCK_ENTIREBUFFER
End Sub
So far, only at the creating directsound object level, I've tried:
declare function DirectSoundCreate lib "dsound.dll" (lpGuid as
integer, ppOS as ptr, pUnkOuter as ptr) as integer
and
declare function DirectSoundCreate lib "dsound.dll" () as integer
since that should work with the default sound device.
then :
dim osErr as integer
osErr = DirectSoundCreate()
this actually returns an integer (probably the equivalent of some
error code).
The MSDN library lists the following return values for this function:
Return Values
If the function succeeds, the return value is DS_OK.
If the function fails, the return value may be one of the following
error values:
DSERR_ALLOCATED
DSERR_INVALIDPARAM
DSERR_NOAGGREGATION
DSERR_NODRIVER
DSERR_OUTOFMEMORY
These are probably just CONSTs (that have integer values), or are C-
style enums; again, with a mapping directly to integers.
all of which look like string values, but RB will not accept my
declaration line with a string variable return. How can I correctly
access the return values?
And, of course, how is it possible to dim RB objects to refer to
the directsound and directX objects as in lines 3 & 4 of the VB code?
any suggestions would be appreciated.
thanks
Rob
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>