Helpful ReplyCapture UA-1G with C#

Author
Dr.Nick
Max Output Level: -90 dBFS
  • Total Posts : 3
  • Joined: 2011/01/11 19:41:22
  • Status: offline
2011/01/11 19:53:01 (permalink)

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
#1
Chappel
Max Output Level: -52.5 dBFS
  • Total Posts : 2300
  • Joined: 2009/07/11 14:55:32
  • Location: California
  • Status: offline
Re:Capture UA-1G with C# 2011/01/11 22:08:35 (permalink) ☄ Helpful
Have you tried doing it with the UA-1G advanced driver off? Is the UA-1G set to 44.1 kHz?
#2
Dr.Nick
Max Output Level: -90 dBFS
  • Total Posts : 3
  • Joined: 2011/01/11 19:41:22
  • Status: offline
Re:Capture UA-1G with C# 2011/01/12 05:56:45 (permalink)
Yes, I tried nearly every setting on the device. Still the same problem.
#3
Chappel
Max Output Level: -52.5 dBFS
  • Total Posts : 2300
  • Joined: 2009/07/11 14:55:32
  • Location: California
  • Status: offline
Re:Capture UA-1G with C# 2011/01/12 07:27:33 (permalink) ☄ Helpful
Don't forget you have to unplug the UA-1G and then plug it back to enable any changes made to it.
#4
Dr.Nick
Max Output Level: -90 dBFS
  • Total Posts : 3
  • Joined: 2011/01/11 19:41:22
  • Status: offline
Re:Capture UA-1G with C# 2011/01/12 07:34:21 (permalink)
That's it! I finally found the right configuration for capturing, with advanced driver off!

Both of your posts were very helpful, thanks a lot!
post edited by Dr.Nick - 2011/01/12 10:37:16
#5
Jump to:
© 2024 APG vNext Commercial Version 5.1