[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.vb.general.discussion

Problem with Direct Sound / VB6

cphx

8/15/2010 10:53:00 PM

I am trying to write an application that play a mp2 encoded audio in
chunks via direct sound. I searched the web and found an tutorial that
shows how to accomplish it. My problem is that VB reports an invalid
procedure call or invalid argument error. I do not think that i've
made any big mistakes :( Please could someone help me out of the
misery ? Kind regards, cphx

http://www.rookscape.com/vbgaming...

my source:

frm_main.frm :

Dim WaveFormat As WAVEFORMATEX
Dim DS_BufferDesc As DSBUFFERDESC

Const ChunkSize = 1024

Private Sub cmd_play_stream_Click()

Dim PtrWavData As Long


Call DSound_OpenWav(App.Path & "\Sound.wav", 1, WaveFormat)
PtrWavData = DSound_GetPtrWavData()

DS_BufferDesc.lBufferBytes = ChunkSize

MsgBox WaveFormat.lSamplesPerSec

i = 0

Call DSound_GetWavData(PtrWavData + (ChunkSize * i), ChunkSize)

Call DSound_SetPriBuffer(Wav_Buffer(), ChunkSize, DS_BufferDesc,
WaveFormat)
Call DSound_PriBuffer_Play

Call DSound_CloseWav

End Sub

Private Sub Form_Load()

Call DSound_Init

End Sub


mod_dsound.bas


Dim DX As DirectX7
Dim DS As DirectSound

Global DS_Buffer_Pri As DirectSoundBuffer
Global DS_Buffer_Sec As DirectSoundBuffer

Global Wav_Buffer() As Byte

Private Type Wave_Format_Ex
Magic As String * 12
FormatID As String * 4
ChunkSize As Long
FormatTag As Integer
Channels As Integer
SamplesPerSec As Long
AvgBytesPerSec As Long
BlockAlign As Integer
BitsPerSample As Integer
End Type

Public Sub DSound_Init()

' Init Direct X / Direct Sound

Set DX = New DirectX7
Set DS = DX.DirectSoundCreate("")

' Set the DirectSound object's cooperative level (Priority gives us
sole control)

DS.SetCooperativeLevel frm_main.hWnd, DSSCL_PRIORITY

End Sub

Public Function DSound_OpenWav(File$, Start%, WaveFormat As
WAVEFORMATEX)

Dim Buffer As Wave_Format_Ex

Open File$ For Binary As #1

Get #1, Start%, Buffer

With WaveFormat
.lAvgBytesPerSec = Buffer.AvgBytesPerSec
.lSamplesPerSec = Buffer.SamplesPerSec
.nBitsPerSample = Buffer.BitsPerSample
.nBlockAlign = Buffer.BlockAlign
.nChannels = Buffer.Channels
.nFormatTag = Buffer.FormatTag
End With

End Function

Public Function DSound_GetPtrWavData(Optional Start%) As Long

Dim Buffer As String * 4
Dim StartFlag As Byte

If Start% <> 0 Then StartFlag = 1

For i = 1 + Start% - StartFlag To LOF(1)

Get #1, i, Buffer

If UCase(Buffer) = "DATA" Then
DSound_GetPtrWavData = i + 4
Exit Function
End If

Next i

DSound_GetPtrWavData = -1

End Function

Public Function DSound_GetWavData(Start As Long, ChunkSize As Long)

ReDim Wav_Buffer(ChunkSize)
Get #1, Start, Wav_Buffer()

End Function

Public Function DSound_CloseWav()

Close #1

End Function

Function DSound_SetPriBuffer(Data() As Byte, ChunkSize As Long,
BufferDesc As DSBUFFERDESC, WaveFormat As WAVEFORMATEX)


Set DS_Buffer_Pri = DS.CreateSoundBuffer(BufferDesc, WaveFormat)

' Load the buffer with data

DS_Buffer_Pri.WriteBuffer 0, ChunkSize, Data(1),
DSBLOCK_ENTIREBUFFER

End Function

Function DSound_PriBuffer_Play()
DS_Buffer_Pri.Play DSBPLAY_DEFAULT
End Function
14 Answers

cphx

8/15/2010 10:57:00 PM

0

The Error is raised when i try to set the Direct Sound Buffer.

cphx

8/15/2010 11:08:00 PM

0

i worked out some errors. please refer to this code instead. The
problem is still persisting, anyway :(

frm_main.frm

Dim WaveFormat As WAVEFORMATEX
Dim DS_BufferDesc As DSBUFFERDESC

Private Sub cmd_play_stream_Click()

Dim PtrWavData As Long


Call DSound_OpenWav(App.Path & "\Sound.wav", 1, WaveFormat)
PtrWavData = DSound_GetPtrWavData()

DS_BufferDesc.lBufferBytes = Wav_ChunkSize

MsgBox WaveFormat.lSamplesPerSec

i = 0

Call DSound_GetWavData(PtrWavData + (Wav_ChunkSize * i),
Wav_ChunkSize)

Call DSound_SetPriBuffer(Wav_Buffer(), Wav_ChunkSize,
DS_BufferDesc, WaveFormat)
Call DSound_PriBuffer_Play

Call DSound_CloseWav

End Sub

Private Sub Form_Load()

Call DSound_Init

End Sub


mod_dsound.bas



Dim DX As DirectX7
Dim DS As DirectSound

Global DS_Buffer_Pri As DirectSoundBuffer
Global DS_Buffer_Sec As DirectSoundBuffer

Global Wav_Buffer() As Byte
Global Wav_ChunkSize As Long

Private Type Wave_Format_Ex
Magic As String * 12
FormatID As String * 4
BlockSize As Long
FormatTag As Integer
Channels As Integer
SamplesPerSec As Long
AvgBytesPerSec As Long
BlockAlign As Integer
BitsPerSample As Integer
End Type

Public Sub DSound_Init()

' Init Direct X / Direct Sound

Set DX = New DirectX7
Set DS = DX.DirectSoundCreate("")

' Set the DirectSound object's cooperative level (Priority gives us
sole control)

DS.SetCooperativeLevel frm_main.hWnd, DSSCL_PRIORITY

End Sub

Public Function DSound_OpenWav(File$, Start%, WaveFormat As
WAVEFORMATEX)

Dim Buffer As Wave_Format_Ex

Open File$ For Binary As #1

Get #1, Start%, Buffer

With WaveFormat
.lAvgBytesPerSec = Buffer.AvgBytesPerSec
.lSamplesPerSec = Buffer.SamplesPerSec
.nBitsPerSample = Buffer.BitsPerSample
.nBlockAlign = Buffer.BlockAlign
.nChannels = Buffer.Channels
.nFormatTag = Buffer.FormatTag
End With

End Function

Public Function DSound_GetPtrWavData(Optional Start%) As Long

Dim Buffer As String * 4
Dim StartFlag As Byte

If Start% <> 0 Then StartFlag = 1

For i = 1 + Start% - StartFlag To LOF(1)

Get #1, i, Buffer

If UCase(Buffer) = "DATA" Then

DSound_GetPtrWavData = i + 4
Get #1, , Wav_ChunkSize

Exit Function

End If

Next i

DSound_GetPtrWavData = -1

End Function

Public Function DSound_GetWavData(Start As Long, ChunkSize As Long)

ReDim Wav_Buffer(ChunkSize)
Get #1, Start, Wav_Buffer()

End Function

Public Function DSound_CloseWav()

Close #1

End Function

Function DSound_SetPriBuffer(Data() As Byte, BlockSize As Long,
BufferDesc As DSBUFFERDESC, WaveFormat As WAVEFORMATEX)


Set DS_Buffer_Pri = DS.CreateSoundBuffer(BufferDesc, WaveFormat)

' Load the buffer with data

DS_Buffer_Pri.WriteBuffer 0, BlockSize, Data(1),
DSBLOCK_ENTIREBUFFER

End Function

Function DSound_PriBuffer_Play()
DS_Buffer_Pri.Play DSBPLAY_DEFAULT
End Function

(nobody)

8/15/2010 11:17:00 PM

0

Your original post didn't appear in MS News Server because it contains an
outlawed sequence of characters:

_P_e_r_S_

Also, anyone who replies to your post and include these characters will have
their post auto deleted from MS News Server, but would appear in other
server. Try editing your code, and post it again. See these links to see
which server shows your post:

news://msnews.microsoft.com/microsoft.public.vb.general.discussion
news://news.aioe.org/microsoft.public.vb.general.discussion



Dee Earley

8/17/2010 8:33:00 AM

0

On 16/08/2010 00:16, Nobody wrote:
> Your original post didn't appear in MS News Server because it contains an
> outlawed sequence of characters:
>
> _P_e_r_S_

Err, out of interest, any idea why??
Google doesn't seem to return anything relevant...

--
Dee Earley (dee.earley@icode.co.uk)
i-Catcher Development Team

iCode Systems

(Replies direct to my email address will be ignored.
Please reply to the group.)

Mike Williams

8/17/2010 11:53:00 AM

0

"Dee Earley" <dee.earley@icode.co.uk> wrote in message
news:eSiJbdePLHA.2068@TK2MSFTNGP05.phx.gbl...
> On 16/08/2010 00:16, Nobody wrote:
>> Your original post didn't appear in MS News Server
>> because it contains an outlawed sequence of characters:
>>
>> _P_e_r_S_
>
> Err, out of interest, any idea why??
> Google doesn't seem to return anything relevant...

No idea. In fact (as far as I know) the fact that the specific sequence of
characters mentioned fails MS news filters was first noticed by me when I
posted some code (I can't remember exactly what that code was) which
contained a variable having the following name (without the underscores of
course):

S_a_m_p_l_e_s_P_e_r_S_e_c_o_n_d

It was a very long message as I recall and I had to spend some time
repeatedly doing a "binary chop" of its contents and sending the message
parts individually until I finally discovered what the problem piece of text
was. Then a bit later I tested to find which specific part of the word the
MS servers objected to (the _p_e_r_s_ as I recall). I've no idea what the MS
filters objected to about that sequence of characters, and as far as I know
it has no rude or offensive translation in any language. The more suspicious
amongst us (myself included!) guessed that any variable with a name that
indicated it might be used to hold the result of a speed test, possibly
comparing VB6 to VB.Net, might be frowned upon my MS ;-)

Mike





(nobody)

8/17/2010 1:10:00 PM

0

"Dee Earley" <dee.earley@icode.co.uk> wrote in message
news:eSiJbdePLHA.2068@TK2MSFTNGP05.phx.gbl...
> On 16/08/2010 00:16, Nobody wrote:
>> Your original post didn't appear in MS News Server because it contains an
>> outlawed sequence of characters:
>>
>> _P_e_r_S_
>
> Err, out of interest, any idea why??
> Google doesn't seem to return anything relevant...

Google without the extra characters:

Microsoft .Net b_e_n_c_h_m_a_r_k_s

It was not allowed to do the "B" word above in early EULA.


(nobody)

8/17/2010 2:36:00 PM

0

"Nobody" <nobody@nobody.com> wrote in message
news:i4e1nv$3o3$1@speranza.aioe.org...
> "Dee Earley" <dee.earley@icode.co.uk> wrote in message
> news:eSiJbdePLHA.2068@TK2MSFTNGP05.phx.gbl...
>> On 16/08/2010 00:16, Nobody wrote:
>>> Your original post didn't appear in MS News Server because it contains
>>> an
>>> outlawed sequence of characters:
>>>
>>> _P_e_r_S_
>>
>> Err, out of interest, any idea why??
>> Google doesn't seem to return anything relevant...
>
> Google without the extra characters:
>
> Microsoft .Net b_e_n_c_h_m_a_r_k_s
>
> It was not allowed to do the "B" word above in early EULA.
>

P.S. The B word was allowed in dotnet groups, not in this VB Classic group.
I guess they know which is best!


Dee Earley

8/17/2010 2:41:00 PM

0

On 17/08/2010 15:36, Nobody wrote:
> "Nobody"<nobody@nobody.com> wrote in message
> news:i4e1nv$3o3$1@speranza.aioe.org...
>> "Dee Earley"<dee.earley@icode.co.uk> wrote in message
>> news:eSiJbdePLHA.2068@TK2MSFTNGP05.phx.gbl...
>>> On 16/08/2010 00:16, Nobody wrote:
>>>> Your original post didn't appear in MS News Server because it contains
>>>> an
>>>> outlawed sequence of characters:
>>>>
>>>> _P_e_r_S_
>>>
>>> Err, out of interest, any idea why??
>>> Google doesn't seem to return anything relevant...
>>
>> Google without the extra characters:
>>
>> Microsoft .Net b_e_n_c_h_m_a_r_k_s
>>
>> It was not allowed to do the "B" word above in early EULA.
>>
>
> P.S. The B word was allowed in dotnet groups, not in this VB Classic group.
> I guess they know which is best!

Seems incredibly stupid to blanket ban that word, especially in a
programming channel when people may want help speed testing something
completely unrelated to .net...

--
Dee Earley (dee.earley@icode.co.uk)
i-Catcher Development Team

iCode Systems

(Replies direct to my email address will be ignored.
Please reply to the group.)

Larry Serflaten

8/17/2010 2:59:00 PM

0


"Mike Williams" <Mike@WhiskyAndCoke.com> wrote
> No idea. In fact (as far as I know) the fact that the specific sequence of
> characters mentioned fails MS news filters was first noticed by me when I
> posted some code (I can't remember exactly what that code was) which
> contained a variable having the following name (without the underscores of
> course):
>
> S_a_m_p_l_e_s_P_e_r_S_e_c_o_n_d
>

SamplesPerSecond

Really?

???
LFS


Jeff Johnson [MVP: VB]

8/17/2010 4:02:00 PM

0

"Larry Serflaten" <serflaten@gmail.com> wrote in message
news:i4e81o$n5r$1@news.eternal-september.org...

>> No idea. In fact (as far as I know) the fact that the specific sequence
>> of
>> characters mentioned fails MS news filters was first noticed by me when I
>> posted some code (I can't remember exactly what that code was) which
>> contained a variable having the following name (without the underscores
>> of
>> course):
>>
>> S_a_m_p_l_e_s_P_e_r_S_e_c_o_n_d
>>
>
> SamplesPerSecond
>
> Really?

While I am generally not a tinfoil-hat kind of guy, in this case I can
believe it.