关键字: VB .NET DirectX DirectSound 3D 作者:董含君
经过一下午的奋战,走了若干弯路,终于可以播放3D声音效果了
感动 ~ ~
大体按照下列的步骤来:
1 关联设备 SetCooperativeLevel 2 设置3D硬件效果 DSoundHelper.Guid3DAlgorithmHrtfFull 3 格式要求 SoundFormat 必须是单声道,不能是立体声 4 主要缓冲区描述 5 创建Listenner 6 辅助缓冲区读取wav 7 创建3D缓冲区 8 播放 9 控制空间位置,以及设置多普勒效应因子,衰减因子 10 停止播放
以下代码注释比较全,顺序比微软的例子简单不少
由于CSDN的Blog不能上传贴图以及RAR,只能帖代码了,有两个Button 一个Picturebox,还有若干Label
==================================================================================
Imports Microsoft.DirectX Imports Microsoft.DirectX.DirectSound Imports System.Drawing Imports System.Drawing.Graphics
Public Class Form1 Inherits System.Windows.Forms.Form
Dim Dev As Device ''''设备 Dim Buff As Buffer ''''主要缓冲 Dim SBuff As SecondaryBuffer ''''二级缓冲 Dim Buff3D As Buffer3D ''''3D缓冲 Dim descBuff As BufferDescription ''''缓冲区描述 Dim Buff3DSet As Buffer3DSettings ''''3D缓冲设置 Dim Listenner As Listener3D ''''听众 Dim ListennerSet As Listener3DSettings ''''听众设置 Dim Pic As Graphics Dim BMP As Bitmap Const FN = "g:\media\wav\rod2m.wav" ''''要播放的文件,必须是单声道 #Region " Windows 窗体设计器生成的代码 "
Public Sub New() MyBase.New()
''''该调用是 Windows 窗体设计器所必需的。 InitializeComponent()
''''在 InitializeComponent() 调用之后添加任何初始化
End Sub
''''窗体重写 dispose 以清理组件列表。 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 窗体设计器所必需的 Private components As System.ComponentModel.IContainer
''''注意: 以下过程是 Windows 窗体设计器所必需的 ''''可以使用 Windows 窗体设计器修改此过程。 ''''不要使用代码编辑器修改它。 Friend WithEvents Button1 As System.Windows.Forms.Button Friend WithEvents Button2 As System.Windows.Forms.Button Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox Friend WithEvents Label1 As System.Windows.Forms.Label Friend WithEvents Label2 As System.Windows.Forms.Label Friend WithEvents Label3 As System.Windows.Forms.Label Friend WithEvents Label4 As System.Windows.Forms.Label Friend WithEvents TextBox1 As System.Windows.Forms.TextBox Friend WithEvents TextBox2 As System.Windows.Forms.TextBox Friend WithEvents TextBox3 As System.Windows.Forms.TextBox Friend WithEvents TextBox4 As System.Windows.Forms.TextBox Friend WithEvents Label5 As System.Windows.Forms.Label Friend WithEvents TextBox5 As System.Windows.Forms.TextBox Friend WithEvents Label6 As System.Windows.Forms.Label <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.Button1 = New System.Windows.Forms.Button Me.Button2 = New System.Windows.Forms.Button Me.PictureBox1 = New System.Windows.Forms.PictureBox Me.Label1 = New System.Windows.Forms.Label Me.Label2 = New System.Windows.Forms.Label Me.Label3 = New System.Windows.Forms.Label Me.Label4 = New System.Windows.Forms.Label Me.TextBox1 = New System.Windows.Forms.TextBox Me.TextBox2 = New System.Windows.Forms.TextBox Me.TextBox3 = New System.Windows.Forms.TextBox Me.TextBox4 = New System.Windows.Forms.TextBox Me.Label5 = New System.Windows.Forms.Label Me.TextBox5 = New System.Windows.Forms.TextBox Me.Label6 = New System.Windows.Forms.Label Me.SuspendLayout() '''' ''''Button1 '''' Me.Button1.Location = New System.Drawing.Point(24, 8) Me.Button1.Name = "Button1" Me.Button1.Size = New System.Drawing.Size(88, 32) Me.Button1.TabIndex = 0 Me.Button1.Text = "初始化" '''' ''''Button2 '''' Me.Button2.Location = New System.Drawing.Point(24, 48) Me.Button2.Name = "Button2" Me.Button2.Size = New System.Drawing.Size(88, 32) Me.Button2.TabIndex = 1 Me.Button2.Text = "播放" '''' ''''PictureBox1 '''' Me.PictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle Me.PictureBox1.Location = New System.Drawing.Point(152, 48) Me.PictureBox1.Name = "PictureBox1" Me.PictureBox1.Size = New System.Drawing.Size(552, 432) Me.PictureBox1.TabIndex = 2 Me.PictureBox1.TabStop = False '''' ''''Label1 '''' Me.Label1.Location = New System.Drawing.Point(8, 104) Me.Label1.Name = "Label1" Me.Label1.TabIndex = 3 Me.Label1.Text = "多普勒效应0~10" '''' ''''Label2 '''' Me.Label2.Location = New System.Drawing.Point(8, 160) Me.Label2.Name = "Label2" Me.Label2.TabIndex = 4 Me.Label2.Text = "衰减因子 0~10" '''' ''''Label3 '''' Me.Label3.Location = New System.Drawing.Point(8, 216) Me.Label3.Name = "Label3" Me.Label3.TabIndex = 5 Me.Label3.Text = "最大距离 0~100" '''' ''''Label4 '''' Me.Label4.Location = New System.Drawing.Point(8, 272) Me.Label4.Name = "Label4" Me.Label4.TabIndex = 6 Me.Label4.Text = "最小距离 [1] [2] [3] 下一页 [Web开发]VS2005+SQL2005之.NET2.0数据库连接 [常用软件]公共场所慎用Foxmail5 以防泄露隐私 [VB.NET程序]定制VB.NET控件编程之拦截击键动作 [VB.NET程序]VB.NET VS C#. [VB.NET程序]VB.NET 中调用浏览目录对话框 [VB.NET程序]VB.NET and C# 语法比较手册 [VB.NET程序]VB.NET 拖动无边框的窗体 [VB.NET程序]C# to VB.NET 翻译器 [VB.NET程序]101 VB.NET Applications 读书笔记(1) [VB.NET程序]vb.net 程序设计规范(1)
|