Esempio n. 1
0
        public static Microsoft.DirectX.DirectSound.WaveFormat CreateWaveFormat(int hz, short bits, short channels)
        {
            Microsoft.DirectX.DirectSound.WaveFormat format = new Microsoft.DirectX.DirectSound.WaveFormat();
            format.FormatTag             = Microsoft.DirectX.DirectSound.WaveFormatTag.Pcm;
            format.SamplesPerSecond      = hz;
            format.BitsPerSample         = bits;
            format.Channels              = channels;
            format.BlockAlign            = (short)(format.Channels * (format.BitsPerSample / 8));
            format.AverageBytesPerSecond = format.BlockAlign * format.SamplesPerSecond;

            return(format);
        }
        private void initMasterPeakRetrieval(Microsoft.DirectX.DirectSound.DeviceInformation deviceInformation)
        {
            Microsoft.DirectX.DirectSound.CaptureDevicesCollection audioDevices = new Microsoft.DirectX.DirectSound.CaptureDevicesCollection();

            for (int deviceIndex = 0; deviceIndex < audioDevices.Count; deviceIndex++)
            {
                if (captureMixer.DeviceDetail.MixerName == audioDevices[deviceIndex].Description)
                {
                    // captureMixer.DeviceDetail.MixerName
                    // initialize the capture buffer on the defaut device
                    Microsoft.DirectX.DirectSound.Capture cap = new Microsoft.DirectX.DirectSound.Capture(audioDevices[deviceIndex].DriverGuid);
                    Microsoft.DirectX.DirectSound.CaptureBufferDescription desc = new Microsoft.DirectX.DirectSound.CaptureBufferDescription();
                    Microsoft.DirectX.DirectSound.WaveFormat wf = new Microsoft.DirectX.DirectSound.WaveFormat();
                    wf.BitsPerSample = 16;
                    wf.SamplesPerSecond = SAMPLE_FREQUENCY;
                    wf.Channels = 2;
                    wf.BlockAlign = (short)(wf.Channels * wf.BitsPerSample / 8);
                    wf.AverageBytesPerSecond = wf.BlockAlign * wf.SamplesPerSecond;
                    wf.FormatTag = Microsoft.DirectX.DirectSound.WaveFormatTag.Pcm;

                    desc.Format = wf;
                    desc.BufferBytes = SAMPLES * wf.BlockAlign;

                    buffer = new Microsoft.DirectX.DirectSound.CaptureBuffer(desc, cap);
                    buffer.Start(true);
                }
            }
        }