日期:2014-05-17  浏览次数:21042 次

C# DirectX对声卡的操作
我想实现的是通过采集的数字信号(这个数字信号可能是txt中保存的一些数据),输入到声卡,然后实时输出,不知如何处理,

还请各位高手帮忙!谢谢~~

下面是我写的代码:(但是输出的wave文件有,但是听不到声音)

    public partial class Form3 : Form
    {
        #region 用户变量
        private string strRecSaveFile = string.Empty;//文件保存路径
        private Notify myNotify = null;//缓冲区提示事件
        private FileStream fsWav = null;//保存的文件流
        private int iNotifyNum = 16;//通知的个数
        private int iBufferOffset = 0;//本次数据起始点, 上一次数据的终点。
        private int iSampleSize = 0;//所采集到的数据大小
        private int iNotifySize = 0;//通知所在区域大小
        private int iBufferSize = 0;//缓冲区大小
        private BinaryWriter mWriter;
        private Capture capture = null;//捕捉设备对象
        private CaptureBuffer capturebuffer = null;//捕捉缓冲区
        private AutoResetEvent notifyevent = null;
        private Thread notifythread = null;
        private WaveFormat mWavFormat;//PCM格式
        #endregion

        /// <summary>
        /// 设置PCM格式;
        /// </summary>
        /// <returns></returns>
        private WaveFormat SetWaveFormat()
        {
            WaveFormat format = new WaveFormat();
            format.FormatTag = WaveFormatTag.Pcm;//设置音频类型
            format.SamplesPerSecond = 22050;//采样率(单位:赫兹)典型值:11025、22050、44100Hz
            format.BitsPerSample = 16;//采样位数
            format.Channels = 1;//声道