欢迎光临
我们一直在努力

学习笔记,VB.NET使用DirectSound9 (2)-.NET教程,VB.Net语言

建站超值云服务器,限时71元/月

第二步分,如何控制音量的大小

如果想控制音量大小跟左右声道或者播放速度,那么创建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

======================================

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 学习笔记,VB.NET使用DirectSound9 (2)-.NET教程,VB.Net语言
分享到: 更多 (0)

相关推荐

  • 暂无文章