Managed DirectSound volume doesn't work.

Posted on 2006-05-22
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
    LVL 2

    Expert Comment

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

    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.

    LVL 2

    Accepted Solution

    thanks and best of luck. ;)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    Title # Comments Views Activity
    Update a DataTable to the database. 3 26
    Disable & as shortcut in label 3 26
    Linq Unique list ? 3 31
    Richtextbox formatting 8 18
    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…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    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…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now