Beispiel #1
0
        private void AudioUpdaterWork(object sender, DoWorkEventArgs e)
        {
            while (!Stop)
            {
                AudioStream audioStream = ThreadControlCenter.Main.ActiveAudioStream;
                if (ThreadControlCenter.Main.ActiveSnapshot == null || audioStream == null || !audioStream.ReadyForWrite || audioStream.Saturated)
                {
                    System.Threading.Thread.Sleep(1);
                    continue;
                }
                audioStream.StartTime = ThreadControlCenter.Main.SecondsSinceStart + 1;
                Parallel.For(0, 8, threadIndex => {
                    //doing this in multiple threads to speed it up.

                    int index = audioStream.GetNextBlockIndex();
                    while (index >= 0 && !Stop)
                    {
                        double time = audioStream.GetBlockTime(index);
                        while (ThreadControlCenter.Main.SecondsSinceStart < time && !Stop)
                        {
                            System.Threading.Thread.Sleep(1);
                        }

                        Snapshot snapshot    = ThreadControlCenter.Main.ActiveSnapshot;
                        Audio10msBlock block = Audio10msBlock.FromSnapshot(snapshot, time, index, ThreadControlCenter.Main.AmplifyLeft, ThreadControlCenter.Main.AmplifyRight);

                        audioStream.SetBlock(index, block);
                        index = audioStream.GetNextBlockIndex();

                        if (audioStream != ThreadControlCenter.Main.ActiveAudioStream)
                        {
                            break;
                        }
                    }
                });
            }
        }
Beispiel #2
0
        private void AudioPlayerWorkSoundPlayer()
        {
            SoundPlayer soundPlayer = new SoundPlayer();

            while (!Stop)
            {
                try
                {
                    AudioStream audioStream = new AudioStream(1);
                    ActiveAudioStream  = audioStream;
                    soundPlayer.Stream = audioStream;
                    soundPlayer.PlaySync();
                }
                catch
                {
                    soundPlayer.Stop();
                    soundPlayer.Dispose();
                }
            }
            if (soundPlayer != null)
            {
                soundPlayer.Dispose();
            }
        }
Beispiel #3
0
 private void ResetAudio(object sender, StoppedEventArgs e)
 {
     ActiveAudioStream = new AudioStream(audioResetTime, false);
 }