Managed DirectSound volume doesn't work.


I'm doing some work in Managed DirectSound in VB.NET.  Changes in the SecondaryBuffer's Volume property seem to have no effect on the volume of the sound produced.  My code looks like this:

Public Class Sound
    Private buf As SecondaryBuffer
    Private bufDesc As BufferDescription

    Public Name As String
    Public KeyList() As Keys
    Sub New(ByVal soundName As String, ByVal path As String, ByRef dev As Device, ByVal triggerKeys() As Keys)
        Name = soundName
        bufDesc = New BufferDescription()
        bufDesc.ControlVolume = True

            buf = New SecondaryBuffer(path, bufDesc, dev)
            IsLoaded = True
        Catch ex As Exception
            MsgBox("The Sound " & Name & " Could not be initialized")
        End Try

        KeyList = triggerKeys
    End Sub

    Public Sub Play()
        buf.Play(0, BufferPlayFlags.Default)
    End Sub

    Public Sub Stp()
        If Not buf Is Nothing Then
            If buf.PlayPosition > 0 Then
            End If
        End If
    End Sub

    Public Sub SetVolume(ByVal newVolume As Integer)
        If newVolume >= -10000 And newVolume <= 0 Then
            buf.Volume = newVolume
            MsgBox("Invalid volume setting """ & newVolume.ToString & """ on DirectSound SecondaryBuffer of sound """ & Name & """")
        End If
    End Sub

End Class

Calls to SetVolume() don't do anything, and even if I set the volume directly in the New() sub, it has no effect.  What am I doing wrong?


Who is Participating?
anwar ul haqueCommented:
thanks and best of luck. ;)
anwar ul haqueCommented:
It depends on media driver that you are using please confirm it, this happened mostly when we want to play IVR. I'd used QuartzTypeLib and its rate property will do the same and it will return an error if specified rate is not supported by your driver.
 Public g_objMediaControl As QuartzTypeLib.FilgraphManage
'initialize this object and render any file for playing.then set the rate propery accordingly
 g_objMediaControl.Rate = 2.
There is little material provided on MSDN to guide the developers to sort out these things but may be you will get an idea.

Anwar ul Haque
bti_adminAuthor Commented:
Thanks for your response.

I did some reading on the quartz.dll, and I'll use it if I have to, but I'd rather stick with plain ol' DirectSound.  

I'll give you the points if no one else responds, but I'm leaving this question open for now in hopes of getting a more direct answer to my question.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.