internal AudioCapture(AudioDevice audioDevice, string deviceName, int sampleRate, AudioFormat bitDepth, int channels, int bufferSize) : base(audioDevice) { if (deviceName != null && !AvailableDevices.Contains(deviceName)) { throw new InvalidOperationException(string.Format("CaptureDevice \"{0}\" does not exist.", deviceName)); } if (sampleRate <= 0 || sampleRate >= 44100) { throw new ArgumentOutOfRangeException("sampleRate", "SampleRate must be larger than 0 and smaller or equals to 44100."); } if (bitDepth != AudioFormat.Byte8 || bitDepth != AudioFormat.Short16) { throw new ArgumentException("BitDepth must be either Byte8 oder Short16.", "bitDepth"); } if (channels <= 0 || channels > 2) { throw new ArgumentOutOfRangeException("channels", "AudioCapture only supports 1 or 2 channels."); } if (bufferSize <= 0) { throw new ArgumentOutOfRangeException("bufferSize", "BufferSize must be larger than 0."); } var format = EnumConverter.GetFormat(bitDepth, channels); this.handle = new AudioCaptureInternal(deviceName, sampleRate, format, bufferSize); }
public AudioDevice(string deviceName) { if (deviceName != null && !AvailableDevices.Contains(deviceName)) { throw new InvalidOperationException(string.Format("AudioDevice \"{0}\" does not exist.", deviceName)); } Context = new OpenTK.Audio.AudioContext(deviceName, 0, 15, true, true, AudioContext.MaxAuxiliarySends.UseDriverDefault); CheckAlcError(); deviceHandle = Alc.GetContextsDevice(Alc.GetCurrentContext()); CheckAlcError(); Efx = new EffectsExtension(); CheckAlcError(); int[] val = new int[4]; DeviceName = Context.CurrentDevice; VendorName = AL.Get(ALGetString.Vendor); Renderer = AL.Get(ALGetString.Renderer); DriverVersion = AL.Get(ALGetString.Version); int major, minor; Alc.GetInteger(deviceHandle, AlcGetInteger.MajorVersion, 1, val); major = val[0]; Alc.GetInteger(deviceHandle, AlcGetInteger.MinorVersion, 1, val); minor = val[0]; Version = new Version(major, minor); Alc.GetInteger(deviceHandle, AlcGetInteger.EfxMajorVersion, 1, val); major = val[0]; Alc.GetInteger(deviceHandle, AlcGetInteger.EfxMinorVersion, 1, val); minor = val[0]; EfxVersion = new Version(major, minor); Alc.GetInteger(deviceHandle, AlcGetInteger.EfxMaxAuxiliarySends, 1, val); MaxRoutes = val[0]; Extensions = new List <string>(AL.Get(ALGetString.Extensions).Split(' ')).AsReadOnly(); AL.DistanceModel(ALDistanceModel.ExponentDistance); CheckAudioCapabilities(LogLevel.Verbose); LogDiagnostics(LogLevel.Verbose); Factory = new AudioFactory(this); Listener = new AudioListener(this); Listener.Orientation(Vector3.UnitY, Vector3.UnitZ); updateTaskCancelation = new CancellationTokenSource(); updateTask = Task.Factory.StartNew(Update); }