Managed DirectSound volume doesn't work.

Posted on 2006-05-22
Medium Priority
Last Modified: 2013-12-03

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?


Question by:bti_admin
  • 2

Expert Comment

by:anwar ul haque
ID: 16749734
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

Author Comment

ID: 16780461
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.


Accepted Solution

anwar ul haque earned 1500 total points
ID: 16782154
thanks and best of luck. ;)

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question