首页 > 编程 > .NET > 正文

学习笔记,VB.NET使用DirectSound9 (2)

2024-07-10 13:04:29
字体:
来源:转载
供稿:网友
,欢迎访问网页设计爱好者web开发。第二步分,如何控制音量的大小

如果想控制音量大小跟左右声道或者播放速度,那么创建buf之前还需要做一些工作

创建一个bufferdescription对象
dim desc as new bufferdescription

设置desc的属性

desc.controlpan = true
desc.controlvolume = true
desc.controlfrequency = true
(当然这里还有其他功能,以后再说,3d那里我还没有研究,一步一步的来)

完成之后,可以创建了,跟一开始的不一样了,多了一个desc
buf = new secondarybuffer("g:/media/wav/rod2.wav", desc, ad)

(微软:你要控制音量大小可以说嘛,虽然你很深情的望着我,但是你不说我会怎么知道呢.....)

记住,上面仅仅是说明你可以改面音量大小了,但是还没有提到怎么改变.

buf.volume=0 '这个声音就是最大了
buf.volume=-5000 '微软给的例子是-5000 实际上 -50的时候就听不见什么动静了..

buf.pan=0 '两边声道均衡 -10000 跟 10000 是左右声道

buf.frequency= desc.format.samplespersecond '默认的声音 44khz 就是 44100 这个是速度

ok,速度一般不需要多大的变化.偶尔玩玩是可以,实际意义就不大了.

改动之后的代码

======================================
dim ad as device
dim buf as secondarybuffer

private sub form1_load(byval sender as system.object, byval e as system.eventargs) handles mybase.load
ad = new device
dim desc as new bufferdescription
desc.controlpan = true
desc.controlvolume = true
desc.controlfrequency = true
desc.flags = bufferdescriptionflags.globalfocus '全局的,上一篇有介绍


ad.setcooperativelevel(me.handle, cooperativelevel.normal)
buf = new secondarybuffer("g:/media/wav/rod2.wav", desc, ad)
buf.play(0, bufferplayflags.looping)

label5.text = buf.frequency.tostring
end sub

private sub form1_keydown(byval sender as object, byval e as system.windows.forms.keyeventargs) handles mybase.keydown
buf.volume = 0 '最大就是0
label2.text = buf.volume.tostring
end sub

private sub form1_keyup(byval sender as object, byval e as system.windows.forms.keyeventargs) handles mybase.keyup
' buf.volume = -50 * 100
buf.volume = -5 * 100
label2.text = buf.volume.tostring

end sub

private sub form1_mousedown(byval sender as object, byval e as system.windows.forms.mouseeventargs) handles mybase.mousedown
if e.button = mousebuttons.left then
buf.pan = -20 * 500
else
buf.pan = 20 * 500
end if
label4.text = buf.pan.tostring
end sub

private sub form1_mouseup(byval sender as object, byval e as system.windows.forms.mouseeventargs) handles mybase.mouseup
buf.pan = 0
label4.text = buf.pan.tostring

end sub
======================================


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表