buen37
Messages postés6Date d'inscriptionlundi 20 février 2006StatutMembreDernière intervention12 juillet 2009
-
12 juil. 2009 à 20:32
grigoulette
Messages postés11Date d'inscriptionjeudi 18 février 2010StatutMembreDernière intervention 2 avril 2010
-
2 avril 2010 à 11:36
Bonjour,
mon problème est le suivant :
j'ai un bout de code (dont certaines parties proviennent d'internet) que j'ai bidouillé pour capturer du son via le micro de mon pc...l'acquisition a l'air de pas trop mal se passer...mais quand je veux lire ce que j'ai capturé, j'ai seulement un "clac" dans les haut parleurs...
Pour l'acquisition j'utilise DirectX, voici le code :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.DirectSound;
using System.IO;
namespace GuitarAccorder
{
public partial class Form1 : Form
{
/// <summary>
/// variables
/// </summary>
private Device device;
private Capture capture;
private Microsoft.DirectX.DirectSound.Buffer buffer;
private BufferDescription bufferDesc;
private CaptureBuffer captureBuffer;
private WaveFormat waveFormat;
private CaptureBufferDescription captureBuffDesc;
private MemoryStream stream;
private byte[] streamBuffer;
private int len = 20000;
private Boolean boolock = false;
public Form1()
{
InitializeComponent();
// Device init
device = new Device();
device.SetCooperativeLevel(this,CooperativeLevel.Priority);
createWaveFormat();
createBufferDescription();
buffer = new Microsoft.DirectX.DirectSound.Buffer(bufferDesc, this.device);
capture = new Capture();
createCapureDescription();
createStreamBuffer();
}
private void button1_Click(object sender, EventArgs e)
{
if (!boolock)
{
captureBuffer = new CaptureBuffer(captureBuffDesc, capture);
stream = new MemoryStream(streamBuffer);
this.captureBuffer.Start(true);
boolock = true;
}
else
{
boolock = false;
this.captureBuffer.Stop();
captureBuffer.Read(0, this.stream, len, LockFlag.None);
buffer.Write(0, this.stream, len, LockFlag.None);
richTextBox1.Text = "";
for (int i = 0; i < streamBuffer.Length; i++)
{
richTextBox1.AppendText(streamBuffer[i].ToString()+" // ");
}
buffer.Play(0, BufferPlayFlags.Looping);
captureBuffer.Dispose();
stream.Dispose();
}
}
public void createWaveFormat()
{
waveFormat = new WaveFormat();
waveFormat.BitsPerSample = 8;
waveFormat.Channels = 1;
waveFormat.SamplesPerSecond = 96000;
waveFormat.FormatTag = WaveFormatTag.Pcm;
waveFormat.BlockAlign = (short)(waveFormat.Channels * (waveFormat.BitsPerSample / 8));
waveFormat.AverageBytesPerSecond = 96000;
}
public void createBufferDescription()
{
bufferDesc = new BufferDescription();
bufferDesc.Format = waveFormat;
bufferDesc.BufferBytes = len;
bufferDesc.ControlPositionNotify = true;
bufferDesc.ControlFrequency = true;
bufferDesc.ControlPan = true;
bufferDesc.ControlVolume = true;
}
public void createCapureDescription()
{
captureBuffDesc = new CaptureBufferDescription();
captureBuffDesc.BufferBytes = len;
captureBuffDesc.Format = this.waveFormat;
}
public void createStreamBuffer()
{
streamBuffer = new byte[len];
for (int i = 0; i < streamBuffer.Length; i++)
streamBuffer[i] = 0;
}
}
}