Keywords: VB.NET DirectSound 9 sound effects Echo Echo Author: Dong Jun containing reproduced please specify from: http: //blog.9cbs.net/a11s fact, this is the legendary mix, add various effects up to Microsoft to become The mixer strictly speaking, this is a special effect of the sound. There is still a feature of the example of Microsoft DirectX. It is to complicate simple questions. I use a lot of time to make out the middle of the various objects. How to collaborate After understanding, I will take into account your own use. Although Microsoft can do this, it may be reasonable, but it is not suitable for beginners. After trying to finish the following results. First, generally introduce step ========== ============================================================================================================================================================================================================= Load 1 requires a device and a buffer for playing sound (for details, please refer to this buffer, remember to add the attribute of controleffects = true (with controlvolume is a truth) Read 3 New SecondaryBuffer read files If this file is too small, there will be an error. If you do not reflect the effect, you need to catch the setting effect 4 Setup effect needs to introduce some objects, then say 5 playback, at the same time, can perform the related attributes 6 special effects Removal 7 stop 7 Play ===================================== It can be seen that the general step is similar to the 3D sound effect, only However, there is more effective settings. The following is the introduction of objects. 1 First need to know, a voice (buffer) can apply a variety of effects at the same time, how to set up our secondaryBuffer, how these effects DirectSound are used in one array To add an effect, this array has an element. Two effects, this array has two elements. It is pushed. Our SecondaryBuffer is passed directly to SecondaryBuffer together. SB. STEFFECTS (EFFD) 2 Don't do it yourself in why special effects! Don't think so, otherwise you need to study computer acoustics) Microsoft DirectSound has several effects. You can see the last example of Microsoft SDK, or you can use DSOoundHelper.standardechoguid Similar to this form list 3 The properties of each effect are a structure (also understandable object). We have many special effects, such as Dim Echo As EC HoEffect4 Attributes of each special effect object are a structure (which needs to be distinguished with the above area), such as the RCHOEFFECT object cannot directly modify the echo.wetdrymix attribute to use a structure to complete the storage of Echo properties, this structure is called EffectSecho (Microsoft is really doing, the name is so like this, it is difficult to distinguish) DIM EFF AS New Effectsecho '' structure EFF = ECHO.ALLPARAMETERS EFF.wetDrymix = 0 EFF.FEEDBACK = 0 EFF.LEFTDELAY = 1 EFF.rightdeLay =
1 after the EFF.Pandelay = 0 Settings, one-time pass to effect object echo echo.allparameters = ECHO ECHO.ALLPARETERS = Eff5 buffer can adjust the special effect attributes, as long as echo.allparameters, you can know how to do it in the middle, then look The code code is divided into several parts. Mainly in order to easily understand the first step, initialize the equipment (really too classic, don't read) the second step, load WAV (there is more controleffect, other things) Step, set the sound (separate view) fourth step, play (simple one Play) fifth step, stop playing imports Microsoft.directx.directsound
Public Class Form1
Inherits System.Windows.Forms.form
#Region "Windows Form Designer Generated Code"
Public Sub New ()
Mybase.new ()
'This call is required for the Windows Form Designer.
InitializeComponent ()
'Add any initialization after INITIALIZECOMPONENT ()
End Sub
'Form rewriting Dispose to clean up the list of components.
Protected Overloads Overrides Sub Dispose (Byval Disposing as Boolean)
IF Disposing then
IF not (Components Is Nothing) THEN
Components.dispose ()
END IF
END IF
Mybase.dispose (Disposing)
End Sub
'Windows Form Designer
Private Components as System.comPonentModel.icontainer
'Note: The following process is necessary for the Windows Form Designer.
'You can modify this process using the Windows Form Designer.
'Don't modify it using the code editor.
Friend Withevents TextBox1 As System.Windows.Forms.TextBox
Friend Withevents Button1 As System.Windows.Forms.Button
Friend Withevents Button2 As System.Windows.Forms.Button
Friend Withevents Button3 As System.Windows.Forms.Button
Friend Withevents Button4 As System.Windows.Forms.Button
Friend Withevents Button5 As System.Windows.Forms.Button
Me.TextBox1 = new system.windows.Forms.TextBox
Me.Button1 = new system.windows.Forms.Button
Me.Button2 = new system.windows.Forms.Button
Me.Button3 = new system.windows.Forms.Button
Me.Button4 = new system.windows.Forms.Button
Me.Button5 = new system.windows.Forms.Button
Me.suspendlayout ()
'
'TextBox1
'
Me.TextBox1.Location = new system.drawing.point (104, 40) Me.TextBox1.name = "textbox1"
Me.TextBox1.size = new system.drawing.size (160, 21)
Me.TextBox1.tabindex = 2
Me.TextBox1.text = "g: /media/wav/rod2.wav"
'
'Button1
'
Me.button1.location = new system.drawing.point (16, 8)
Me.Button1.name = "button1"
Me.Button1.size = new system.drawing.size (80, 24)
Me.button1.tabindex = 3
Me.Button1.text = "init"
'
'Button2
'
Me.button2.location = new system.drawing.point (16, 40)
Me.Button2.name = "button2"
Me.Button2.size = new system.drawing.size (80, 24)
Me.button2.tabindex = 4
Me.Button2.text = "load"
'
'Button3
'
Me.Button3.Location = new system.drawing.point (16, 72)
Me.Button3.name = "button3"
Me.Button3.Size = new system.drawing.size (80, 24)
Me.button3.tabindex = 5
Me.Button3.text = "play"
'
'Button4
'
Me.Button4.Location = new system.drawing.point (16, 104)
Me.Button4.name = "Button4"
Me.button4.size = new system.drawing.size (80, 24)
Me.button4.tabindex = 6
Me.Button4.text = "stop"
'
'Button5
'
Me.Button5.location = new system.drawing.point (280, 40)
Me.Button5.name = "button5"
Me.button5.size = new system.drawing.size (88, 24)
Me.button5.tabindex = 7
Me.Button5.text = "echo"
'
'Form1
'
Me.autoscalebasesize = new system.drawing.size (6, 14)
Me.ClientSize = new system.drawing.size (400, 269)
Me.Controls.add (me.button5)
Me.Controls.add (me.button4)
Me.Controls.add (me.button3)
Me.Controls.add (me.button2) me.controls.add (me.button1)
Me.Controls.add (Me.TextBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout (false)
End Sub
#End region
Dim dev As Device
DIM PB As Buffer
DIM SB As SecondaryBuffer
DIM DESC1 AS BUFFERDESCRIPTION
DIM DESC2 AS BUFFERDESCRIPTION
DIM EFF AS EffectdScription
Private Structure EffectInfo
Public Description as EffectDescription
Public EffectSettings As Object
Public Effect As Object
End structure
Private sub button1_click (byvale as system.object, byval e as system.eventargs) Handles Button1.click
'' Loading DirectSound
Dev = new device
Dev.SetcoOPERATIVELEVELEVELEVELEVELEVELEVEL (ME, COOPERATIVELEVEL.PRIORITY)
Me.Text = "Init OK"
End Sub
Private sub Button2_click (byvalgend, byval e as system.eventargs) Handles Button2.click
'' 'Read WAV
Desc1 = new bufferDescription
DESC1.CONTROLEFFECTS = TRUE
SB = New SecondaryBuffer (TextBox1.Text, Desc1, DEV)
Me.Text = "Load OK"
End Sub
Private sub button3_click (byval sender as system.object, byval e as system.eventargs) Handles Button3.click
'' Play a play
IF sb is nothing the eXIT SUB
Sb.play (0, bufferplayflags.default)
Me.text = "playing"
End Sub
Private sub button4_click (byval sender as system.object, byval e as system.eventargs) Handles Button4.click
'' Stop playback, release the current WAV
Sb.stop ()
Sb.dispose ()
Me.Text = "disposed"
End Sub
Private sub button5_click (byvale as system.object, byval e as system.eventargs) Handles Button5.click
'' 'Mainly of this
'' 'My array declares an element, it seems that there is no need, but when setting, it must be an array, even if the elements have only one
'' If you need more effect, set the number of corresponding elements
DIM EFFD (0) AS EffectDescription '' Description Collection DIM EFF AS New Effectsecho '' structure, because the object cannot set an attribute separately, you can only use it indirectly
'' 'Key Steps, Specify the type of special effects
Effd (0) .GuideffectClass = dsoundhelper.standardechoguid '' 'Description The first effect is echo
'' 'Software, if you use hardware, I don't oppose it.
EFFD (0) .locateinsoftware = TRUE
'' 'Is directly submitted to buffer, submitting a array
Sb.seteffects (EFFD)
'' Declaration of a special effect object, don't forget that we need to modify the parameters
Dim echo as echoeffect
'' Get the current buffer effect
'' 'This is the index that you pass the effect of the past, forgot? Just that array
echo = sb.geteffects (0)
'' 'Object cannot be changed directly, so use it to indirectly change
EFF = ECHO.AllParameters
EFF.wetDrymix = 50
EFF.FEEDBACK = 50
EFF.LEFTDELAY = 500
EFF.rightdeLay = 500
eff.pandelay = 0
"'' OK, in this way, you can try to replace the value inside with other data, where Leftdelay is in the definition domain of Rightdelay at 1 ~ 2000,
'' 'You can get the maximum minimum value with the properties of echo (convenient)
echo.allparameters = EFF
Me.Text = "echo ok"
End Sub
END CLASS
Ok, copying the past is directly running. I used Echo as an example to explain the problem (it is estimated that this is also the most, the effect is mostly the effect), you refer to Microsoft example, change the above code Easy to achieve, I will not talk nonsense. Next step. Recording