关于VB6的爱好者.大家还是尽快放弃VB6吧,我从97年开始用,现在终于也到了.Net了,中间的痛苦可想而知。尤其是服务器编程,.NET会方便很多。客户端随着XP的推广跟windows update的升级,也快了,别到时候别没有准备。
我的学习方法:
看SDK的文档,了解诸多概念,然后看SDK C#的教程(已经习惯了)
准备工作:
VS2003(有2002的,但是不用那个版本)
DXSDK 9.0C 2004 Dec(记住,是for VS2k3的,曾经有过VS2k2的,而且很多地方不通用)
Win2k(这个久不用说了吧)
主要步骤:
1、首先要添加引用.否则直接imports没办法找到 Microsoft.Directx....
2、引用完了,为了方便再imports Microsoft.DirectX.directsound
为了播放一个简单的声音文件进行如下操作:
.创建一个设备,关联到这个窗体
.创建一个缓冲,指定来源(这里用文件)
.播放...
Dim ad As Device '创建设备
Dim Buf As SecondaryBuffer '创建缓冲
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ad = New Device '实力化设备对象
ad.SetCooperativeLevel(Me.Handle, CooperativeLevel.Normal) '关联
Buf = New SecondaryBuffer("G:\MEDIA\WAV\ff9start.wav", ad) '实力化缓冲区
Buf.Play(0, BufferPlayFlags.Looping) '播放,同时指定开始位置跟方式
End Sub
这是一个最基本最简单的例子,目的是了解步骤。
有趣的现象,由于DS关联的是窗体,当窗体失去焦点的时候,他会停止播放 一旦重新获得焦点会继续播放。
很方便吧
但是DS用的是缓冲区的,在切换的时候,会丢失声音,少了那么一点,SDK也提到过,但是我没有认真看(1 感觉问题不大(除非录音) 2 英文的,懒~)
实际上没有必要解决丢失问题,因为对buf描述的时候就有这个选项。
普通的(就是默认的,我用的这种)
Sticky 看原文吧:Buffers with "sticky" focus will continue to play if the user switches to another application not using DirectSound. However, if the user switches to another DirectSound application, all normal-focus and sticky-focus buffers in the previous application are muted.";
全局的:Buffers with global focus will continue to play if the user switches focus to another application, even if the new application uses DirectSound. The one exception is if you switch focus to a DirectSound application that uses the DSSCL_WRITEPRIMARY cooperative level. In this case, the global-focus buffers from other applications will not be audible.";
再就是 默认硬件加速软件加速 (用默认就好,有硬件就用硬件,否则模拟)
以下是原文:
if (MixHardware)
{
sText = sText + "\n\nWith the hardware mixing flag, the new buffer will be forced to use hardware mixing. If the device does not support hardware mixing or if the required hardware resources are not available, the call to the DirectSound.CreateSoundBuffer method will fail.";
}
else if (MixSoftware)
{
sText = sText + "\n\nWith the software mixing flag, the new buffer will use software mixing, even if hardware resources are available.";
}
else
{
// Default mixing
sText = sText + "\n\nWith default mixing, the new buffer will use hardware mixing if available, otherwise software mixing will be used.";
}
由于内容很简单,没有翻译的必要(主要是因为懒,自己能看懂稍微记录一下就算了)
实际上DirectSound能作的工作很多,包括特效,3D音效跟混音以及声音抓取等。