Запись звука с микрофона - C# (234128)
Формулировка задачи:
Попытался записать звук с микрофона компиляция ошибок не дает но при запуске виснет.
Помогите разобраться.
прикремпил весь проект на вский случай
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.DirectSound;
using Buffer = Microsoft.DirectX.DirectSound.Buffer;
using System.IO;
namespace DirectSound_
{
public partial class Form1 : Form
{
Device device;
Capture capture;
Buffer buffer;
BufferDescription bufferDesc;
CaptureBuffer captureBuffer;
WaveFormat waveFormat;
CaptureBufferDescription captureBuffDesc;
MemoryStream stream;
byte[] streamBuffer;
public Form1()
{
InitializeComponent();
device = new Device(); // Setup DirectSound
waveFormat = new WaveFormat();// Load the sound
waveFormat.BitsPerSample = 8;
waveFormat.BlockAlign = 1;
waveFormat.Channels = 1;
waveFormat.AverageBytesPerSecond = 20500;
waveFormat.SamplesPerSecond = 20500;
waveFormat.FormatTag = WaveFormatTag.Pcm;
bufferDesc = new BufferDescription();
bufferDesc.Format = waveFormat;
bufferDesc.BufferBytes = 100000;
bufferDesc.ControlPositionNotify = true;
bufferDesc.ControlFrequency = true;
bufferDesc.ControlPan = true;
bufferDesc.ControlVolume = true;
buffer = new Buffer(bufferDesc, this.device);
device.SetCooperativeLevel(this, CooperativeLevel.Priority); // Set the cooperative level
capture = new Capture();
captureBuffDesc = new CaptureBufferDescription();
captureBuffDesc.BufferBytes = 100000;
captureBuffDesc.Format = this.waveFormat;
captureBuffer = new CaptureBuffer(captureBuffDesc, capture);
streamBuffer = new byte[100000];
for (int i = 0; i < 100000; i++)
{
streamBuffer[i] = 0;
}
stream = new MemoryStream(streamBuffer);
}
private void button1_Click(object sender, EventArgs e)
{
this.captureBuffer.Read(0, this.stream, 100000, LockFlag.None);
buffer.Write(0, this.stream, (int)this.stream.Length, LockFlag.EntireBuffer);
buffer.Play(0, BufferPlayFlags.Looping);
}
private void button2_Click(object sender, EventArgs e)
{
buffer.Stop();
}
private void button3_Click(object sender, EventArgs e)
{
this.captureBuffer.Start(true);
}
private void button4_Click(object sender, EventArgs e)
{
this.captureBuffer.Stop();
}
}
}Решение задачи: «Запись звука с микрофона»
textual
Листинг программы
captureBuffDesc.BufferBytes = 20500 / 20;