/// <summary> /// Constructs an AudioManager given a track resource store, and a sample resource store. /// </summary> /// <param name="audioThread">The host's audio thread.</param> /// <param name="trackStore">The resource store containing all audio tracks to be used in the future.</param> /// <param name="sampleStore">The sample store containing all audio samples to be used in the future.</param> public AudioManager(AudioThread audioThread, ResourceStore <byte[]> trackStore, ResourceStore <byte[]> sampleStore) { Thread = audioThread; Thread.RegisterManager(this); AudioDevice.ValueChanged += onDeviceChanged; trackStore.AddExtension(@"mp3"); sampleStore.AddExtension(@"wav"); sampleStore.AddExtension(@"mp3"); globalTrackManager = new Lazy <TrackManager>(() => GetTrackManager(trackStore)); globalSampleManager = new Lazy <SampleManager>(() => GetSampleManager(sampleStore)); scheduler.Add(() => { try { setAudioDevice(); } catch { } }); scheduler.AddDelayed(delegate { updateAvailableAudioDevices(); checkAudioDeviceChanged(); }, 1000, true); }
/// <summary> /// Constructs an AudioStore given a track resource store, and a sample resource store. /// </summary> /// <param name="audioThread">The host's audio thread.</param> /// <param name="trackStore">The resource store containing all audio tracks to be used in the future.</param> /// <param name="sampleStore">The sample store containing all audio samples to be used in the future.</param> public AudioManager(AudioThread audioThread, ResourceStore <byte[]> trackStore, ResourceStore <byte[]> sampleStore) { thread = audioThread; thread.RegisterManager(this); AudioDevice.ValueChanged += onDeviceChanged; globalTrackStore = new Lazy <TrackStore>(() => { var store = new TrackStore(trackStore, TrackMixer); AddItem(store); store.AddAdjustment(AdjustableProperty.Volume, VolumeTrack); return(store); }); globalSampleStore = new Lazy <SampleStore>(() => { var store = new SampleStore(sampleStore, SampleMixer); AddItem(store); store.AddAdjustment(AdjustableProperty.Volume, VolumeSample); return(store); }); AddItem(TrackMixer = createAudioMixer(null, nameof(TrackMixer))); AddItem(SampleMixer = createAudioMixer(null, nameof(SampleMixer))); CancellationToken token = cancelSource.Token; scheduler.Add(() => { // sync audioDevices every 1000ms new Thread(() => { while (!token.IsCancellationRequested) { try { syncAudioDevices(); Thread.Sleep(1000); } catch { } } }) { IsBackground = true }.Start(); }); }
/// <summary> /// Constructs an AudioStore given a track resource store, and a sample resource store. /// </summary> /// <param name="audioThread">The host's audio thread.</param> /// <param name="trackStore">The resource store containing all audio tracks to be used in the future.</param> /// <param name="sampleStore">The sample store containing all audio samples to be used in the future.</param> public AudioManager(AudioThread audioThread, ResourceStore <byte[]> trackStore, ResourceStore <byte[]> sampleStore) { Thread = audioThread; Thread.RegisterManager(this); AudioDevice.ValueChanged += onDeviceChanged; globalTrackStore = new Lazy <TrackStore>(() => { var store = new TrackStore(trackStore); AddItem(store); store.AddAdjustment(AdjustableProperty.Volume, VolumeTrack); return(store); }); globalSampleStore = new Lazy <SampleStore>(() => { var store = new SampleStore(sampleStore); AddItem(store); store.AddAdjustment(AdjustableProperty.Volume, VolumeSample); return(store); }); // check for device validity every 100ms scheduler.AddDelayed(() => { try { if (!IsCurrentDeviceValid()) { setAudioDevice(); } } catch { } }, 100, true); // enumerate new list of devices every second scheduler.AddDelayed(() => { try { setAudioDevice(AudioDevice.Value); } catch { } }, 1000, true); }
/// <summary> /// Constructs an AudioStore given a track resource store, and a sample resource store. /// </summary> /// <param name="audioThread">The host's audio thread.</param> /// <param name="trackStore">The resource store containing all audio tracks to be used in the future.</param> /// <param name="sampleStore">The sample store containing all audio samples to be used in the future.</param> public AudioManager(AudioThread audioThread, ResourceStore <byte[]> trackStore, ResourceStore <byte[]> sampleStore) { Thread = audioThread; Thread.RegisterManager(this); AudioDevice.ValueChanged += onDeviceChanged; trackStore.AddExtension(@"mp3"); sampleStore.AddExtension(@"wav"); sampleStore.AddExtension(@"mp3"); globalTrackStore = new Lazy <TrackStore>(() => { var store = new TrackStore(trackStore); AddItem(store); store.AddAdjustment(AdjustableProperty.Volume, VolumeTrack); return(store); }); globalSampleStore = new Lazy <SampleStore>(() => { var store = new SampleStore(sampleStore); AddItem(store); store.AddAdjustment(AdjustableProperty.Volume, VolumeSample); return(store); }); scheduler.Add(() => { try { setAudioDevice(); } catch { } }); scheduler.AddDelayed(delegate { updateAvailableAudioDevices(); checkAudioDeviceChanged(); }, 1000, true); }
/// <summary> /// Constructs an AudioStore given a track resource store, and a sample resource store. /// </summary> /// <param name="audioThread">The host's audio thread.</param> /// <param name="trackStore">The resource store containing all audio tracks to be used in the future.</param> /// <param name="sampleStore">The sample store containing all audio samples to be used in the future.</param> public AudioManager(AudioThread audioThread, ResourceStore <byte[]> trackStore, ResourceStore <byte[]> sampleStore) { Thread = audioThread; Thread.RegisterManager(this); AudioDevice.ValueChanged += onDeviceChanged; globalTrackStore = new Lazy <TrackStore>(() => { var store = new TrackStore(trackStore); AddItem(store); store.AddAdjustment(AdjustableProperty.Volume, VolumeTrack); return(store); }); globalSampleStore = new Lazy <SampleStore>(() => { var store = new SampleStore(sampleStore); AddItem(store); store.AddAdjustment(AdjustableProperty.Volume, VolumeSample); return(store); }); // sync audioDevices every 200ms CancellationToken token = cancellationTokenSource.Token; Task.Factory.StartNew(() => { while (!token.IsCancellationRequested) { try { var task = Task.Delay(200, token); syncAudioDevices(); task.Wait(token); } catch { } } }, token, TaskCreationOptions.None, TaskScheduler.Default); }