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 IWritableEvent MutateOutgoing(IWritableEvent Event) { foreach (var header in _workHeaders) { Event.Descriptor.Headers[header.Key] = header.Value.ToString(); } return(Event); }
/// <summary> /// Clones the stream for caching, add an event to the new clone stream optionally /// </summary> /// <param name="event"></param> /// <returns></returns> public IEventStream Clone(IWritableEvent @event = null) { var committed = Committed.ToList(); if (@event != null) { committed.Add(@event); } return(new EventStream <T>(null, null, Bucket, StreamId, committed, _snapshot)); }
public KEvent RegisterBufferEvent() { IWritableEvent outEvent = _system.RegisterBufferEvent(); if (outEvent is AudioKernelEvent) { return(((AudioKernelEvent)outEvent).Event); } else { throw new NotImplementedException(); } }
private void InitializeAudioRenderer(ITickSource tickSource) { AudioManager = new AudioManager(); AudioOutputManager = new AudioOutputManager(); AudioInputManager = new AudioInputManager(); AudioRendererManager = new AudioRendererManager(tickSource); AudioRendererManager.SetVolume(Device.Configuration.AudioVolume); AudioDeviceSessionRegistry = new VirtualDeviceSessionRegistry(); IWritableEvent[] audioOutputRegisterBufferEvents = new IWritableEvent[Constants.AudioOutSessionCountMax]; for (int i = 0; i < audioOutputRegisterBufferEvents.Length; i++) { KEvent registerBufferEvent = new KEvent(KernelContext); audioOutputRegisterBufferEvents[i] = new AudioKernelEvent(registerBufferEvent); } AudioOutputManager.Initialize(Device.AudioDeviceDriver, audioOutputRegisterBufferEvents); AudioOutputManager.SetVolume(Device.Configuration.AudioVolume); IWritableEvent[] audioInputRegisterBufferEvents = new IWritableEvent[Constants.AudioInSessionCountMax]; for (int i = 0; i < audioInputRegisterBufferEvents.Length; i++) { KEvent registerBufferEvent = new KEvent(KernelContext); audioInputRegisterBufferEvents[i] = new AudioKernelEvent(registerBufferEvent); } AudioInputManager.Initialize(Device.AudioDeviceDriver, audioInputRegisterBufferEvents); IWritableEvent[] systemEvents = new IWritableEvent[Constants.AudioRendererSessionCountMax]; for (int i = 0; i < systemEvents.Length; i++) { KEvent systemEvent = new KEvent(KernelContext); systemEvents[i] = new AudioKernelEvent(systemEvent); } AudioManager.Initialize(Device.AudioDeviceDriver.GetUpdateRequiredEvent(), AudioOutputManager.Update, AudioInputManager.Update); AudioRendererManager.Initialize(systemEvents, Device.AudioDeviceDriver); AudioManager.Start(); }
/// <summary> /// Create a new <see cref="AudioDeviceSession"/>. /// </summary> /// <param name="deviceSession">The device driver session associated</param> /// <param name="bufferEvent">The release buffer event</param> /// <param name="bufferRegisteredLimit">The max number of buffers that can be registered to the device driver at a time</param> public AudioDeviceSession(IHardwareDeviceSession deviceSession, IWritableEvent bufferEvent, uint bufferRegisteredLimit = 4) { _bufferEvent = bufferEvent; _hardwareDeviceSession = deviceSession; _bufferRegisteredLimit = bufferRegisteredLimit; _buffers = new AudioBuffer[Constants.AudioDeviceBufferCountMax]; _serverBufferIndex = 0; _hardwareBufferIndex = 0; _releasedBufferIndex = 0; _bufferAppendedCount = 0; _bufferRegisteredCount = 0; _bufferReleasedCount = 0; _volume = 1.0f; _state = AudioDeviceState.Stopped; }
public AudioRenderSystem(AudioRendererManager manager, IWritableEvent systemEvent) { _manager = manager; _terminationEvent = new ManualResetEvent(false); _dspMemoryPoolState = MemoryPoolState.Create(MemoryPoolState.LocationType.Dsp); _voiceContext = new VoiceContext(); _mixContext = new MixContext(); _sinkContext = new SinkContext(); _splitterContext = new SplitterContext(); _effectContext = new EffectContext(); _commandProcessingTimeEstimator = null; _systemEvent = systemEvent; _behaviourContext = new BehaviourContext(); _totalElapsedTicksUpdating = 0; _sessionId = 0; }
public Task <int> WriteSnapshot(string stream, IWritableEvent snapshot, IDictionary <string, string> commitHeaders) { Logger.Write(LogLevel.Debug, () => $"Writing snapshot to stream id [{stream}]"); var settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto, Binder = new EventSerializationBinder(_mapper), //ContractResolver = new EventContractResolver(_mapper) }; var descriptor = snapshot.Descriptor; descriptor.EventId = snapshot.EventId ?? Guid.NewGuid(); descriptor.CommitHeaders = commitHeaders ?? new Dictionary <string, string>(); var mappedType = snapshot.Event.GetType(); if (!mappedType.IsInterface) { mappedType = _mapper.GetMappedTypeFor(mappedType) ?? mappedType; } var @event = snapshot.Event.Serialize(settings).AsByteArray(); if (_compress.HasFlag(Compression.Snapshots)) { descriptor.Compressed = true; @event = @event.Compress(); } var metadata = descriptor.Serialize(settings).AsByteArray(); var data = new EventData( descriptor.EventId, mappedType.AssemblyQualifiedName, !descriptor.Compressed, @event, metadata ); return(DoWrite(stream, new[] { data })); }
/// <summary> /// Create a new <see cref="AudioOutputSystem"/>. /// </summary> /// <param name="manager">The manager instance</param> /// <param name="parentLock">The lock of the manager</param> /// <param name="deviceSession">The hardware device session</param> /// <param name="bufferEvent">The buffer release event of the audio output</param> public AudioOutputSystem(AudioOutputManager manager, object parentLock, IHardwareDeviceSession deviceSession, IWritableEvent bufferEvent) { _manager = manager; _parentLock = parentLock; _session = new AudioDeviceSession(deviceSession, bufferEvent); }
public IWritableEvent MutateOutgoing(IWritableEvent Event) { return(Event); }