private void InitializeAudioRenderer() { AudioRendererManager = new AudioRendererManager(); AudioDeviceSessionRegistry = new VirtualDeviceSessionRegistry(); IWritableEvent[] writableEvents = new IWritableEvent[RendererConstants.AudioRendererSessionCountMax]; for (int i = 0; i < writableEvents.Length; i++) { KEvent systemEvent = new KEvent(KernelContext); writableEvents[i] = new AudioKernelEvent(systemEvent); } HardwareDevice[] devices = new HardwareDevice[RendererConstants.AudioRendererSessionCountMax]; // TODO: don't hardcode those values. // TODO: keep the device somewhere and dispose it when exiting. // TODO: This is kind of wrong, we should have an high level API for that and mix all buffers between them. for (int i = 0; i < devices.Length; i++) { devices[i] = new AalHardwareDevice(i, Device.AudioOut, 2, RendererConstants.TargetSampleRate); } AudioRendererManager.Initialize(writableEvents, devices); }
public void Process(HardwareDevice outputDevice) { OutputDevice = outputDevice; StartTime = (ulong)PerformanceCounter.ElapsedNanoseconds; foreach (ICommand command in Commands) { if (command.Enabled) { bool shouldMeter = command.ShouldMeter(); long startTime = 0; if (shouldMeter) { startTime = PerformanceCounter.ElapsedNanoseconds; } command.Process(this); if (shouldMeter) { ulong effectiveElapsedTime = (ulong)(PerformanceCounter.ElapsedNanoseconds - startTime); if (effectiveElapsedTime > command.EstimatedProcessingTime) { Logger.Warning?.Print(LogClass.AudioRenderer, $"Command {command.GetType().Name} took {effectiveElapsedTime}ns (expected {command.EstimatedProcessingTime}ns)"); } } } } EndTime = (ulong)PerformanceCounter.ElapsedNanoseconds; }
public void Process(CommandList context) { HardwareDevice device = context.OutputDevice; if (device.GetSampleRate() == RendererConstants.TargetSampleRate) { int channelCount = (int)device.GetChannelCount(); uint bufferCount = Math.Min(device.GetChannelCount(), InputCount); const int sampleCount = RendererConstants.TargetSampleCount; short[] outputBuffer = new short[bufferCount * sampleCount]; for (int i = 0; i < bufferCount; i++) { ReadOnlySpan <float> inputBuffer = GetBuffer(InputBufferIndices[i], sampleCount); for (int j = 0; j < sampleCount; j++) { outputBuffer[i + j * channelCount] = PcmHelper.Saturate(inputBuffer[j]); } } device.AppendBuffer(outputBuffer, InputCount); } else { // TODO: support resampling for device only supporting something different throw new NotImplementedException(); } }
public static HardwareDeviceViewModel ToViewModel(HardwareDevice entity) { var viewModel = TrackedEntityViewModel <HardwareDeviceViewModel, HardwareDevice> .ToViewModel(entity); viewModel.Name = entity.Name; viewModel.Description = entity.Description; viewModel.Host = entity.Host; viewModel.Port = entity.Port; viewModel.DeviceType = entity.DeviceType; viewModel.LastUpdateReceived = entity.LastUpdateReceived; return(viewModel); }
public void AddHardware(System.Type hostedHardwareType, Point location, params byte[] ports) { var newHardware = new HardwareDevice(); newHardware.driver = Activator.CreateInstance(hostedHardwareType) as Hardware; if (newHardware.driver == null) throw new InvalidProgramException("Cannot host devices that are not visual hardware."); var size = newHardware.driver.PreferredSize; newHardware.position = new Rectangle(location.X, location.Y, size.X, size.Y); newHardware.ports = ports; hardware.Add(newHardware); newHardware.driver.Connect(CPU, ports); }
public SplitterHardwareDevice(HardwareDevice baseDevice, HardwareDevice secondaryDevice) { _baseDevice = baseDevice; _secondaryDevice = secondaryDevice; }