Capture UA-1G with C#
Hi,
I'm currently working on an C#-application, which should be able to capture audio from the Cakewalk UA-1G audio interface.
I decided to use SlimDX for that, which is a wrapper using DirectX. The current program can already capture audio from my sound card, also the device to capture from can be changed. The problem is, that, if I choose the UA-1G, all data that comes from there is 0.0.
Here's the source code:
[font="'courier new'"]
[font="'courier new'"]using System;
[font="'courier new'"]using System.Collections.Generic;
[font="'courier new'"]using System.Linq;
[font="'courier new'"]using System.Text;
[font="'courier new'"]using System.IO;
[font="'courier new'"]using SlimDX;
[font="'courier new'"]
[font="'courier new'"]
[font="'courier new'"]namespace audiocapture
[font="'courier new'"]{
[font="'courier new'"] class Program
[font="'courier new'"] {
[font="'courier new'"]
[font="'courier new'"]
[font="'courier new'"] static void Main(string[] args)
[font="'courier new'"] {
[font="'courier new'"]
[font="'courier new'"] #region slimdx
[font="'courier new'"] SlimDX.DirectSound.DeviceCollection test = new SlimDX.DirectSound.DeviceCollection();
[font="'courier new'"] test = SlimDX.DirectSound.DirectSoundCapture.GetDevices();
[font="'courier new'"] SlimDX.DirectSound.DeviceInformation device = test[1];
[font="'courier new'"]
[font="'courier new'"] SlimDX.DirectSound.DirectSoundCapture captureDevice = new SlimDX.DirectSound.DirectSoundCapture(device.DriverGuid);
[font="'courier new'"]
[font="'courier new'"]
[font="'courier new'"]
[font="'courier new'"] SlimDX.Multimedia.WaveFormat waveFormat = new SlimDX.Multimedia.WaveFormat();
[font="'courier new'"] waveFormat.FormatTag = SlimDX.Multimedia.WaveFormatTag.IeeeFloat;
[font="'courier new'"] waveFormat.BitsPerSample = 32;
[font="'courier new'"] waveFormat.BlockAlignment = (short)(waveFormat.BitsPerSample / 8);
[font="'courier new'"] waveFormat.Channels = 1;
[font="'courier new'"] waveFormat.SamplesPerSecond = 44100;
[font="'courier new'"] waveFormat.AverageBytesPerSecond =
[font="'courier new'"] waveFormat.SamplesPerSecond * waveFormat.BlockAlignment * waveFormat.Channels;
[font="'courier new'"]
[font="'courier new'"] SlimDX.DirectSound.CaptureBufferDescription bufferDescription =
[font="'courier new'"] new SlimDX.DirectSound.CaptureBufferDescription();
[font="'courier new'"] bufferDescription.BufferBytes = 8192;
[font="'courier new'"] bufferDescription.Format = waveFormat;
[font="'courier new'"] bufferDescription.WaveMapped = false;
[font="'courier new'"]
[font="'courier new'"] SlimDX.DirectSound.CaptureBuffer buffer =
[font="'courier new'"] new SlimDX.DirectSound.CaptureBuffer(captureDevice, bufferDescription);
[font="'courier new'"] buffer.Start(true);
[font="'courier new'"]
[font="'courier new'"]
[font="'courier new'"] float[] sample = new float[8192 / sizeof(float)];
[font="'courier new'"]
[font="'courier new'"] int i = 0;
[font="'courier new'"]
[font="'courier new'"] while (i<8100)
[font="'courier new'"] {
[font="'courier new'"] i++;
[font="'courier new'"] buffer.Read(sample, 0, true);
[font="'courier new'"]
[font="'courier new'"] }
[font="'courier new'"]
[font="'courier new'"] buffer.Stop();
[font="'courier new'"] buffer.Dispose();
[font="'courier new'"] captureDevice.Dispose();
[font="'courier new'"] #endregion
[font="'courier new'"]
[font="'courier new'"] }
[font="'courier new'"] }
[font="'courier new'"]}
Where's the problem? Is there a better way to do this?
Thanks
Nick