I've trying to get this code to run in DBP since ages..
It worked using sytx but to get it to run the user has to do some
complicated steps which needs a full version of Visual studio..
I tried alot of things but had no luck so I thought in the end...
My only hope is the pros in the GC Forums!
here it is...
using System;
using Microsoft.DirectX.DirectSound;
public class Class1
{
private const int SAMPLES = 8;
private int[] SAMPLE_FORMAT_ARRAY = { SAMPLES, 2, 1 };
private CaptureDevicesCollection audioDevices;
//private static int deviceIndex = 0;
private Microsoft.DirectX.DirectSound.CaptureBuffer buffer;
//private static double last = 0;
private DevicesCollection dc = new DevicesCollection();
private Capture cap = new Capture();
private CaptureBufferDescription desc = new CaptureBufferDescription();
private WaveFormat wf = new WaveFormat();
private Array samples;
public void initsound()
{
dc = new DevicesCollection();
audioDevices = new CaptureDevicesCollection();
cap = new Capture(audioDevices[0].DriverGuid);
desc = new CaptureBufferDescription();
wf = new WaveFormat();
wf.BitsPerSample = 16;
wf.SamplesPerSecond = 44100;
wf.Channels = 2;
wf.BlockAlign = (short)(wf.Channels * wf.BitsPerSample / 8);
wf.AverageBytesPerSecond = wf.BlockAlign * wf.SamplesPerSecond;
wf.FormatTag = WaveFormatTag.Pcm;
desc.Format = wf;
desc.BufferBytes = SAMPLES * wf.BlockAlign;
buffer = new Microsoft.DirectX.DirectSound.CaptureBuffer(desc, cap);
buffer.Start(true);
}
public int tickme()
{
try
{
int average = 0;
samples = buffer.Read(0, typeof(Int16), LockFlag.FromWriteCursor, SAMPLE_FORMAT_ARRAY);
for (int i = 0; i < SAMPLES; i++)
{
average += (Int16)samples.GetValue(i, 0, 0);
}
double am = Math.Max((average / SAMPLES) / 10, 0);
return (int)am;
}
catch
{
return 0;
}
}
}
as simple as it sounds...
initialize it, then use tickme() in a loop it will return the level of the mic
I'll be so greatful if some one can help.
and will be a good addition to the dbp dll list
Snake_x86