How to mute the sound without stopping the it

Started by Ravindra, March 19, 2016, 07:47:23 AM

Previous topic - Next topic

Ravindra

Hello,

Is there a function to mute the sound at any position without actually
stopping the sound and without changing current volume level.

Ravindra.

Administrator

Hello,

this feature is not directly available but you may apply a custom DSP and, inside the callback function, to set to 0 any byte of the buffer passed to the DSP.
See the "How to manage custom DSP effects" tutorial for information about DSP effects management.

Kind regards

Severino Delaurenti
MultiMedia Soft



Ravindra

Hi Severino,

Thanks for solution.
I am still not able to get what strFunctionName to be used to set the DSP.
For ex. in your tutorials of Reverb the string ""fnReverbCallback" is used.

What are those string functions i am supposed to mute the sound ?
If you provide couple of lines of code will be appreciated.

Regards,

Ravindra.

Administrator

Hello Ravindra,

a "custom DSP" is usually an external DLL which exports some function invoked from the multimedia engine of our component: if you are the developer of the "custom DSP" DLL, you are free to assign to these exported functions the name you prefer and, when you set the DSP in your code, you use this function name with the strFunctionName parameter of the CustomDSP.ExternalSetFunction method so the multimedia engine will be able to invoke it directly.

Inside the setup package of our DJ Studio component there are a couple of these custom DSPs (usually installed under "C:\Program Files\Audio Sound Suite for .NET\Samples\CustomDSP\MyCustomDSP" or under "C:\Program Files\Audio DJ Studio for .NET\Samples\CustomDSP\MyCustomDSP") and the "MyCustomDSP" one contains the "fnReverbCallback" callback function which is exported and accessible from outside: you can use and modify the "MyCustomDSP" project (also changing the name of the produced DLL), by simply modifying the code of the "fnReverbCallback" callback function, which could be renamed "fnMuteCallback", in this way:


void WINAPI fnMuteCallback (void *bufferSamples, DWORD bufferSamplesLength, DWORD dwUserData)
{
    DWORD   index;
    for (index = 0; index < bufferSamplesLength / 4; index +=2 )
        bufferSamples[index] = 0.0f;
}


In this way any incoming sample will be totally silent without any modification of the volume level.
If you change the callback function's name from "fnReverbCallback" to "fnMuteCallback" you will obviously have to modify the same name also inside the "MyCustomDSP.def" definition file and inside the "MyCustomDSP.h" header.

Hope this helps.

Kind regards

Severino Delaurenti
MultiMedia Soft

Ravindra

Dear Severino,

Thanks, i will try this.

Ravindra.

Ravindra

Dear Severino,

I am more comfortable in using VB.NET than C# so i modified the code as follows,

Added one more button,

Private Sub btnMute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMute.Click

            Try

                audioDjStudio1.CustomDSP.Enable(0, m_idDspReverbExternal, True, 0, 0)

           Catch ex As Exception

            End Try
end sub

'//
Private Sub ReverbCallback(ByVal bufferSamples As IntPtr, ByVal bufferSamplesLength As Int32, ByVal nUserData As Int32)
           
Dim buffTemp As Single() = New Single(bufferSamplesLength / 4 - 1) {}
            Dim index As Int32

            Marshal.Copy(bufferSamples, buffTemp, 0, bufferSamplesLength / 4)

            index = 0
            Do While index < (bufferSamplesLength / 4)
                buffTemp(index) = 0
                index += 2
            Loop

            Marshal.Copy(buffTemp, 0, bufferSamples, bufferSamplesLength / 4)

        End Sub

But this code does't work.

Can you guide me where i am wrong ?

Thanks and Regards,

Ravindra.

Administrator

Hello,

the original C++ snippet I posted missed the muting of the right channel for stereo files so the correct VB.NET code should have been like this:


            Do While index < (bufferSamplesLength / 4)
                buffTemp(index) = 0
                buffTemp(index+1) = 0
                index += 2
            Loop


Anyway, attached you will find a modified version of the CustomDSP VB.NET sample which adds the internal DSP for muting audio.
Hope this will help you better.

Kind Regards

Severino Delaurenti
MultiMedia Soft