<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using NAudio.Wave;
using AudioAlign.Audio.Streams;

namespace AudioAlign.LibSampleRate.Test {
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window {

        //private SampleRateConverter src;
        private MixerStream mixer;
        WasapiOut audioOutput;

        public MainWindow() {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e) {
            //src = new SampleRateConverter(ConverterType.SRC_SINC_FASTEST, 1);

            audioOutput = new WasapiOut(global::NAudio.CoreAudioApi.AudioClientShareMode.Shared, true, 10);
            mixer = new MixerStream(2, 44100);
            MonoStream mono = new MonoStream(mixer);
            ResamplingStream resampler = new ResamplingStream(mono, ResamplingQuality.SincFastest, 5512);
            ResamplingStream resampler2 = new ResamplingStream(resampler, ResamplingQuality.SincFastest, 44100);
            NAudioSinkStream naudioSink = new NAudioSinkStream(resampler2);
            audioOutput.Init(naudioSink);

            sliderSampleRate.ValueChanged += new RoutedPropertyChangedEventHandler<double>(delegate(object s2, RoutedPropertyChangedEventArgs<double> e2) {
                if (resampler.CheckTargetSampleRate(sliderSampleRate.Value)) {
                    resampler.TargetSampleRate = sliderSampleRate.Value;
                }
            });
        }

        private void button1_Click(object sender, RoutedEventArgs e) {
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.DefaultExt = ".wav";
            dlg.Filter = "Wave files|*.wav";

            if (dlg.ShowDialog() == true) {
                mixer.Clear();
                mixer.Add(new IeeeStream(new NAudioSourceStream(new WaveFileReader(dlg.FileName))));
                //mixer.Add(new NAudioSourceStream(new WaveChannel32(new WaveFileReader(dlg.FileName))));
                lblFile.Content = dlg.FileName;
            }
        }

        private void button2_Click(object sender, RoutedEventArgs e) {
            if (audioOutput.PlaybackState == PlaybackState.Playing)
                audioOutput.Pause();
            else if (audioOutput.PlaybackState == PlaybackState.Paused || audioOutput.PlaybackState == PlaybackState.Stopped)
                audioOutput.Play();
        }<commit_msg>Clean up resampling test program code<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using NAudio.Wave;
using AudioAlign.Audio.Streams;

namespace AudioAlign.LibSampleRate.Test {
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window {

        private MixerStream mixer;
        WasapiOut audioOutput;

        public MainWindow() {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e) {
            audioOutput = new WasapiOut(global::NAudio.CoreAudioApi.AudioClientShareMode.Shared, true, 10);
            mixer = new MixerStream(2, 44100);
            MonoStream mono = new MonoStream(mixer);
            ResamplingStream resampler = new ResamplingStream(mono, ResamplingQuality.SincMedium, 44100);
            NAudioSinkStream naudioSink = new NAudioSinkStream(resampler);
            audioOutput.Init(naudioSink);

            sliderSampleRate.ValueChanged += new RoutedPropertyChangedEventHandler<double>(delegate(object s2, RoutedPropertyChangedEventArgs<double> e2) {
                if (resampler.CheckTargetSampleRate(sliderSampleRate.Value)) {
                    resampler.TargetSampleRate = sliderSampleRate.Value;
                }
            });
        }

        private void button1_Click(object sender, RoutedEventArgs e) {
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.DefaultExt = ".wav";
            dlg.Filter = "Wave files|*.wav";

            if (dlg.ShowDialog() == true) {
                mixer.Clear();
                mixer.Add(new IeeeStream(new NAudioSourceStream(new WaveFileReader(dlg.FileName))));
                lblFile.Content = dlg.FileName;
            }
        }

        private void button2_Click(object sender, RoutedEventArgs e) {
            if (audioOutput.PlaybackState == PlaybackState.Playing)
                audioOutput.Pause();
            else if (audioOutput.PlaybackState == PlaybackState.Paused || audioOutput.PlaybackState == PlaybackState.Stopped)
                audioOutput.Play();
        }
{'fraction_non_alphanumeric': 0.092, 'fraction_numerical': 0.009714285714285713, 'mean_word_length': 2.7083333333333335, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5710217', 'n_tokens_mistral': 1486, 'n_tokens_neox': 1416, 'n_words': 288}