Exemplo n.º 1
0
        private bool ConstructMushraComponents()
        {
            if (_sessionIndex == _mushraSessionEnumerator.Count)
            {
                _sessionIndex = 0;
                return(false);
            }
            var currentMushraSessionObject = _mushraSessionEnumerator.ElementAtOrDefault(_sessionIndex);

            _currentTrialNumber = currentMushraSessionObject.TrialNumber;
            var count = 0;

            currentMushraSessionObject.Sample.All(sampleName =>
            {
                if (sampleName != "")
                {
                    count++;
                    return(true);
                }
                else
                {
                    return(false);
                }
            });

            MushraNextTrial?.Invoke(this, count);

            if (currentMushraSessionObject.Reference == "" || currentMushraSessionObject.Sample.Count() == 0)
            {
                System.Windows.Forms.MessageBox.Show("Reference and Sample files should not be empty!!!");
                return(false);
            }

            _audioObject = AudioFactory.GetAudioObject(_settingsObject.OutputDriver, _settingsObject.AsioDriver, _settingsObject.ExclusiveMode);

            if (!_audioObject.IntializeNAudioLibrary(_settingsObject.Latency))
            {
                return(false);
            }

            _doAudioOperations    = new List <WavePlayer>();
            _newlistOfWavePlayers = new List <WavePlayer>();

            if (_doAudioOperations == null)
            {
                throw new NullReferenceException("The WavePlayer instance is not initialized!!!!");
            }

            _doAudioOperations.Add(new WavePlayer(currentMushraSessionObject.Reference));
            _newlistOfWavePlayers.Add(new WavePlayer(currentMushraSessionObject.Reference));
            currentMushraSessionObject.Sample.All(sample =>
            {
                if (sample != "")
                {
                    _doAudioOperations.Add(new WavePlayer(sample));
                    _newlistOfWavePlayers.Add(new WavePlayer(sample));
                }
                return(true);
            });

            trialName.Content = string.Format("Trial {0} of {1}, Trial Name - {2}", currentMushraSessionObject.TrialNumber,
                                              _mushraTestDetailsModel.trials.Count, currentMushraSessionObject.TrialName);

            _doAudioOperations.All(audioChannels => { audioChannels.SetVolumeStream(0);       return(true); });
            _newlistOfWavePlayers.All(audioChannels => { audioChannels.SetVolumeStream(0); return(true); });

            _audioObject.MixWaveProviders(_doAudioOperations);

            WaveFormPlayer.Instance.OpenFile(currentMushraSessionObject.Reference);
            WaveFormDisplay.RegisterSoundPlayer(_waveDisplay);

            _sessionIndex++;
            var timeStamp = _audioObject.GetTotalDuration();

            StopText.Text  = string.Format("{0}:{1}:{2}", timeStamp.Minutes, timeStamp.Seconds, timeStamp.Milliseconds);
            StartText.Text = "0:0:0";
            return(true);
        }
Exemplo n.º 2
0
        private bool ConstructABCTestComponents()
        {
            if (_sessionIndex == abcSessionEnumerator.Count)
            {
                _sessionIndex = 0;
                return(false);
            }

            var currentAbcSessionObject = abcSessionEnumerator.ElementAtOrDefault(_sessionIndex);

            if (currentAbcSessionObject.Reference == "" || currentAbcSessionObject.Sample == "")
            {
                System.Windows.Forms.MessageBox.Show("Reference and Sample files should not be empty!!!");
                return(false);
            }

            _refFile    = currentAbcSessionObject.Reference;
            _sampleFile = currentAbcSessionObject.Sample;

            _audioObject = AudioFactory.GetAudioObject(_settingsObject.OutputDriver, _settingsObject.AsioDriver, _settingsObject.ExclusiveMode);

            var latency = 0;

            if (_settingsObject.OutputDriver == 0)
            {
                if (_settingsObject.Latency < 100)
                {
                    latency = _settingsObject.Latency * 10;                    // * _settingsObject.NumberOfBuffers;
                }
                else
                {
                    latency = _settingsObject.Latency;
                }
            }

            if (!_audioObject.IntializeNAudioLibrary(latency))
            {
                return(false);
            }

            _doAudioOperations    = new List <WavePlayer>();
            _newlistOfWavePlayers = new List <WavePlayer>();

            if (_doAudioOperations == null)
            {
                throw new NullReferenceException("The WavePlayer instance is not initialized!!!!");
            }
            _doAudioOperations.Add(new WavePlayer(_refFile));
            _newlistOfWavePlayers.Add(new WavePlayer(_refFile));

            if (currentAbcSessionObject.HiddenReference.Trim() == "B")
            {
                _doAudioOperations.Add(new WavePlayer(_refFile));
                _doAudioOperations.Add(new WavePlayer(_sampleFile));
                _newlistOfWavePlayers.Add(new WavePlayer(_refFile));
                _newlistOfWavePlayers.Add(new WavePlayer(_sampleFile));
            }
            else
            {
                _doAudioOperations.Add(new WavePlayer(_sampleFile));
                _doAudioOperations.Add(new WavePlayer(_refFile));
                _newlistOfWavePlayers.Add(new WavePlayer(_sampleFile));
                _newlistOfWavePlayers.Add(new WavePlayer(_refFile));
            }

            trialName.Content = string.Format("Trial {0} of {1}, Trial Name - {2}", currentAbcSessionObject.TrialNumber, _trialCount, currentAbcSessionObject.TrialName);

            _doAudioOperations.All(audioChannels => { audioChannels.SetVolumeStream(0); return(true); });
            _newlistOfWavePlayers.All(audioChannels => { audioChannels.SetVolumeStream(0); return(true); });

            _audioObject.MixWaveProviders(_doAudioOperations);

            WaveFormPlayer.Instance.OpenFile(_refFile);

            WaveFormDisplay.RegisterSoundPlayer(_waveDisplay);
            _sessionIndex++;

            var timeStamp = _audioObject.GetTotalDuration();

            StopText.Text  = string.Format("{0}:{1}:{2}", timeStamp.Minutes, timeStamp.Seconds, timeStamp.Milliseconds);
            StartText.Text = "0:0:0";

            return(true);
        }