/// <summary> /// cTor: creates a Player Task (BG Worker) /// </summary> public LoopWorker( ) { _playerWaitHandle = new AutoResetEvent(false); _player = new WaveProc(_playerWaitHandle, true); this.WorkerSupportsCancellation = true; this.WorkerReportsProgress = true; this.DoWork += SoundWorker_DoWork; }
/// <summary> /// cTor: create from a number of values /// </summary> /// <param name="melody">Melody to play from</param> /// <param name="note">The Note to play</param> /// <param name="loops">Loops to add (max 5)</param> /// <param name="volume">Volume to play with (default = 1.0)</param> /// <param name="speed">Speed Factor (default = 1.0)</param> public SoundBite(Melody melody, uint note, uint loops, float volume = 1.0f, float speed = 1.0f) { Melody = melody; var tune = WaveProc.GetInstalledSounds().Where(x => x.Melody == melody).FirstOrDefault(); if (tune == null) { // sould not happen ..... LOG.LogError($"SoundBite: Cannot find the Melody: {melody}"); Melody = Melody.Silence; return; } Tone = (note < tune.NumTones) ? note : note % tune.NumTones; // safeguard Note Volume = (volume >= 0) ? volume : 0; // must be >= 0.0 Loops = (loops <= 5) ? loops : 5; // must be <= 5 SpeedFact = (speed > 0) ? speed : 1; // must be > 0.0 }
/// <summary> /// Start the Sound processing /// </summary> /// <param name="parameter">A parameter obj to use (NOT USED)</param> public void InitPlayer(object parameter) { if (!this.IsBusy) { // restart _player?.Dispose( ); _playerWaitHandle.Dispose( ); _playerWaitHandle = new AutoResetEvent(false); _player = new WaveProc(_playerWaitHandle, true); ClearSoundBites( ); _progressCount = 0; this.RunWorkerAsync(parameter); } else { throw new InvalidOperationException("PingLib-Loop: ERROR - Cannot InitPlayer while Busy. Must Cancel first!"); } }