简单的用 Microsoft.DirectX.DirectSound播放wave音频文件

用DevicesCollection 枚举电脑的多个声卡设备(播放设备/音频输出设备),

通过他们的GUID创建播放声音的设备,遍历够就能在两个声卡上听到声音,下面是简要的C#代码:

 

  Microsoft.DirectX.DirectSound.DevicesCollection sound_devices = new Microsoft.DirectX.DirectSound.DevicesCollection();
            foreach (object sound in sound_devices)
            {
                Microsoft.DirectX.DirectSound.DeviceInformation deviceinfo =( Microsoft.DirectX.DirectSound.DeviceInformation)sound ;
                if (string.IsNullOrEmpty (deviceinfo.ModuleName )) continue;
                MessageBox.Show(deviceinfo.ToString());
                Microsoft.DirectX.DirectSound.Device sound_device_output = new Microsoft.DirectX.DirectSound.Device(deviceinfo.DriverGuid);
                sound_device_output.SetCooperativeLevel(this, Microsoft.DirectX.DirectSound.CooperativeLevel.Normal);//设置设备协作级别
                Microsoft.DirectX.DirectSound.BufferDescription buffDes = new Microsoft.DirectX.DirectSound.BufferDescription();
                buffDes.GlobalFocus = true;//设置缓冲区全局获取焦点
                buffDes.ControlVolume = true;//指明缓冲区可以控制声音
                buffDes.ControlPan = true;//指明缓冲区可以控制声道平衡
                Microsoft.DirectX.DirectSound.SecondaryBuffer secondary_buffer = new Microsoft.DirectX.DirectSound.SecondaryBuffer(textBox1.Text, buffDes, sound_device_output);//创建辅助缓冲区
                secondary_buffer.Play(0, Microsoft.DirectX.DirectSound.BufferPlayFlags.Looping);//设置缓冲区为循环播放
            }

 

 

 

问题是如果实现声音同步在两个设备上播放,比如一个realtek的集成声卡和一个USB Audio Device,努力ing

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值