using NAudio.Wave; using QuikDawEditor.Properties; using QuikDawEditor.SampleProviders; using System; using System.Diagnostics; using System.Windows; using static QuikDawEditor.EDITING.StaticProperties; namespace QuikDawEditor; public partial class ProjectPlayer { internal bool _AudioDeviceOK = true; public bool AudioDeviceOK { get { return _AudioDeviceOK; } set { _AudioDeviceOK = value; NotifyPropertyChanged(nameof(AudioDeviceOK)); NotifyPropertyChanged(nameof(RecordButEnabled)); NotifyPropertyChanged(nameof(CanMixdown)); if (editingProject != null) UpdateTrackArmButs(editingProject.Tracks); } } internal bool InitializeAudio() { switch (Settings.Default.AsioInRadioButtonChecked) { case true: try { playAsioOut = new AsioOut(SelectedAudioOutIndex); playAsioOut.Init(bufferedSampleProvider.ToWaveProvider16()); //MessageBox.Show("inputcount=" + playAsioOut.DriverInputChannelCount.ToString() + "\noutputocount=" + playAsioOut.DriverOutputChannelCount.ToString()); } catch (Exception ex) { Debug.WriteLine ("Error creating asioOut\n" + ex.Message + "\n\nNo sound will be played.\n\nCheck audio setup."); return false; } break; case false: //playWaveOut.Dispose(); //playWaveOut = new WaveOutEvent() { DeviceNumber = SelectedAudioOutIndex }; //playWaveOut.Dispose(); //playWaveOut.Init(bufferedWaxeProvider); //recordWaveIn = new WaveInEvent() { DeviceNumber = SelectedAudioInIndex }; MessageBox.Show("Wave button was selected but not supported"); return false; } return true; } internal void CreateNewAsioOut() { try { playAsioOut = new AsioOut(SelectedAudioOutIndex); playAsioOut.Init(bufferedSampleProvider.ToWaveProvider16()); bufferedSampleProvider.ClearBuffer(); playAsioOut.Play(); StartPlayTimer(); } catch { } } internal void StartAudio() { IsProjectPlaying = false; if (AudioDeviceOK) { CurrentPlayingPosMS = editingProject.StartingBookmarkMs; try { ChangePlayPos(editingProject.StartingBookmarkMs); } catch (Exception ex1) { MessageBox.Show("error changing playpos1\n" + ex1.Message); } try { AudioPlayerPlay(); } catch (Exception ex1) { MessageBox.Show("error starting audio playerplay\n" + ex1.Message); } //MessageBox.Show("audio player played"); try { StartPlayTimer(); } catch (Exception ex1) { MessageBox.Show("error starting play timer\n" + ex1.Message); } } else MessageBox.Show("Device was not ok!"); } internal void AudioPlayerPlay() { if (Settings.Default.AsioInRadioButtonChecked) playAsioOut.Play(); //else // playWaveOut.Play(); } internal void AudioPlayerStop() { if (Settings.Default.AsioInRadioButtonChecked) { if (playAsioOut != null) { if (playAsioOut.PlaybackState == PlaybackState.Playing) playAsioOut.Stop(); } } else { //if (playWaveOut != null) // if (playWaveOut.PlaybackState == PlaybackState.Playing) // playWaveOut.Stop(); } } internal bool ResetAudio() { //Reset player with new audio out StopPlayTimer(); IsProjectPlaying = false; projPlayTimer.Stop(); mmsp = new MasterMixingSampleProvider(DefaultPlayWaveFormat, editingProject) { ReadFully = true }; //bufferedSampleProvider = new BufferedSampleProvider(new WaveFormat(44100, 16, 2)) { DiscardOnBufferOverflow = true }; projPlayTimer.Start(); return InitializeAudio(); } }