毕业论文开发语言企业开发JAVA技术.NET技术WEB开发Linux/Unix数据库技术Windows平台移动平台嵌入式论文范文英语论文
您现在的位置: 毕业论文 >> net技术 >> 正文

C#中如何使用DirectSound来获取麦克音量 第3页

更新时间:2012-9-4:  来源:毕业论文
            _waveLeft = new double[CaptureData.Length / 4];
            _waveRight = new double[CaptureData.Length / 4];

            // Split out channels from sample
            int h = 0;
            for (int i = 0; i < CaptureData.Length; i += 4)
            {
                _waveLeft[h] = (double)BitConverter.ToInt16(CaptureData, i);
                _waveRight[h] = (double)BitConverter.ToInt16(CaptureData, i + 2);
                h++;
            }


            double sum = 0;
            foreach (double item in _waveLeft)
            {
                if (item > 0)
                    sum += item;
                else
                    sum += -item;
            }

            int result = (int)(((sum / _waveLeft.Length)) / 32768 * 100);

            if (state == State.Starting||state == State.Started)
            {
                secondBuffer.Add(CaptureData);
            }
            OnVolumeChanged(new OnVolumeChangedEventArgs(result));

            if (state == State.Started)
            {
                if (result < accuracy)
                {
                    silence++;
                    if (silence > 10)
                    {
                        silence = 0;
                        SwitchState(State.Paused);
                    }
                }
            }
            else if (state == State.Paused)
            {
                if (result > accuracy)
                {
                    silence = 0;
                    secondBuffer = new List<byte[]>();
                    int n = _thirdBuffer.Count;
                    for (int i = 0; i < n; i++)
                    {
                        secondBuffer.Add(_thirdBuffer.Dequeue());
                    }
                    secondBuffer.Add(CaptureData);
                    SwitchState(State.Started);

                }
            }

            if (_thirdBuffer.Count <= _THIRD_BUFFER_SIZE)
            {
                _thirdBuffer.Enqueue(CaptureData);
            }
            else
            {
                _thirdBuffer.Enqueue(CaptureData);
                _thirdBuffer.Dequeue();
            }
        }

第二个读buffer,然后用公式换算成电平值

上一页  [1] [2] [3] 

设为首页 | 联系站长 | 友情链接 | 网站地图 |

copyright©youerw.com 优尔论文网 严禁转载
如果本毕业论文网损害了您的利益或者侵犯了您的权利,请及时联系,我们一定会及时改正。