private void ThreadFunctionActionDecrypt(WavFormatManager wfm, String originalName)
        {
            WindowPasswordInput wpi = new WindowPasswordInput(WindowPasswordInput.ProcessType.DECRYPTION, originalName);

            if (wpi.ShowDialog() == true)
            {
                WavFormatManager encryptedSound = new WavFormatManager();
                encryptedSound.SetBitsPerSample(24);
                encryptedSound.SetSampleRate(wfm.GetSampleRate());

                if (wfm.GetNumberOfChannels() == 1)
                {
                    encryptedSound.SetChannelCount(1);

                    Complex[] frq = FourierTransform.FFT_segmented(wfm.ReadAudioMono());
                    CryptoFFT.Decrypt(frq, wpi.GetPassword());
                    encryptedSound.WriteAudioMono(FourierTransform.IFFT_segmented(frq));
                }
                else
                {
                    encryptedSound.SetChannelCount(2);

                    Complex[] frqLeft  = FourierTransform.FFT_segmented(wfm.ReadAudioLeft());
                    Complex[] frqRight = FourierTransform.FFT_segmented(wfm.ReadAudioRight());
                    CryptoFFT.Decrypt(frqLeft, wpi.GetPassword());
                    CryptoFFT.Decrypt(frqRight, wpi.GetPassword());
                    encryptedSound.WriteAudioLeft(FourierTransform.IFFT_segmented(frqLeft));
                    encryptedSound.WriteAudioRight(FourierTransform.IFFT_segmented(frqRight));
                }

                Dispatcher.Invoke(new AddSoundPanelDelegate(CommitProcessedSoundToInterface), encryptedSound, wpi.GetName());
            }
        }
Ejemplo n.º 2
0
        public static void Play(WavFormatManager wfm, WindowMain.PlotGraphsDelegate plotDelegate, WindowMain handle)
        {
            wavePlayer?.Stop();
            wsp?.StopPlotting();
            wavePlayer = new WaveOut();
            wsp        = new WaveStreamProvider(wfm, plotDelegate, handle);

            wavePlayer.DesiredLatency = 80;
            wavePlayer.Init(wsp);
            wavePlayer.Play();
        }
        private void ThreadFunctionActionSave(WavFormatManager wfm, String originalName)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.FileName = originalName + ".wav";
            if (sfd.ShowDialog() == true)
            {
                String filename = sfd.FileName;
                wfm.SetBitsPerSample(24);
                wfm.EncodeFile(filename);
            }
        }
        private void CommitProcessedSoundToInterface(WavFormatManager wfm, String displayName)
        {
            SoundPanel sp = new SoundPanel(wfm, displayName);

            sp.SetEncryptButtonHandler(new Action(() => { ActionEncrypt(sp); }));
            sp.SetDecryptButtonHandler(new Action(() => { ActionDecrypt(sp); }));
            sp.SetPlayButtonHandler(new Action(() => { ActionPlay(sp); }));
            sp.SetSaveButtonHandler(new Action(() => { ActionSave(sp); }));

            int z = soundPanelList.Count;

            stackPanelSoundItems.Children.Insert(z, sp);
            soundPanelList.Add(sp);
        }
        private void CommitLoadToInterface(WavFormatManager wfm, String displayName)
        {
            buttonAddSoundFromFile.IsEnabled = true;

            if (wfm != null)
            {
                SoundPanel sp = new SoundPanel(wfm, displayName);
                sp.SetEncryptButtonHandler(new Action(() => { ActionEncrypt(sp); }));
                sp.SetDecryptButtonHandler(new Action(() => { ActionDecrypt(sp); }));
                sp.SetPlayButtonHandler(new Action(() => { ActionPlay(sp); }));
                sp.SetSaveButtonHandler(new Action(() => { ActionSave(sp); }));

                int z = soundPanelList.Count;

                stackPanelSoundItems.Children.Insert(z, sp);
                soundPanelList.Add(sp);
            }
        }
        private void ThreadFunctionLoadSoundFromFile(Object fileName)
        {
            String stringFileName = (String)fileName;

            WavFormatManager wfm = new WavFormatManager();

            try
            {
                wfm.DecodeFile(stringFileName);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "", MessageBoxButton.OK, MessageBoxImage.Error);
                Dispatcher.Invoke(new AddSoundPanelDelegate(CommitLoadToInterface), null, "");
                return;
            }

            Dispatcher.Invoke(new AddSoundPanelDelegate(CommitLoadToInterface), wfm, Path.GetFileNameWithoutExtension(stringFileName));
        }
        public WaveStreamProvider(WavFormatManager wfm, WindowMain.PlotGraphsDelegate plotDelegate, Window windowHandle)
        {
            this.plotMethod = plotDelegate;
            this.handle     = windowHandle;

            this.streamFormat = new WaveFormat((int)wfm.GetSampleRate(), 16, wfm.GetNumberOfChannels());

            if (this.streamFormat.Channels == 1)
            {
                this.bufferMono = wfm.ReadAudioMono();
            }
            else
            {
                this.bufferLeft  = wfm.ReadAudioLeft();
                this.bufferRight = wfm.ReadAudioRight();
            }

            currentBufferIndex = 0;

            this.stopThread    = false;
            this.plotterThread = new Thread(new ThreadStart(this.PlotterThreadFunction));
            this.plotterThread.Start();
        }
Ejemplo n.º 8
0
        public SoundPanel(WavFormatManager wfm, String displayName)
        {
            this.encryptHandler = null;
            this.decryptHandler = null;
            this.playHandler    = null;

            this.soundObject = wfm;
            this.displayText = displayName;

            Image encryptImage = new Image();
            Image decryptImage = new Image();
            Image playImage    = new Image();
            Image saveImage    = new Image();

            encryptImage.Source  = new BitmapImage(new Uri(@"pack://*****:*****@"pack://application:,,,/Resources/decrypt.png"));
            playImage.Source     = new BitmapImage(new Uri(@"pack://*****:*****@"pack://application:,,,/Resources/save.png"));
            encryptImage.Stretch = Stretch.Uniform;
            decryptImage.Stretch = Stretch.Uniform;
            playImage.Stretch    = Stretch.Uniform;
            saveImage.Stretch    = Stretch.Uniform;
            encryptImage.Height  = 45;
            decryptImage.Height  = 45;
            playImage.Height     = 45;
            saveImage.Height     = 45;

            this.encryptButton         = new Button();
            this.decryptButton         = new Button();
            this.playButton            = new Button();
            this.saveButton            = new Button();
            this.encryptButton.Content = encryptImage;
            this.decryptButton.Content = decryptImage;
            this.playButton.Content    = playImage;
            this.saveButton.Content    = saveImage;
            this.encryptButton.ToolTip = "Encrypt this sound";
            this.decryptButton.ToolTip = "Decrypt this sound";
            this.playButton.ToolTip    = "Play this sound";
            this.saveButton.ToolTip    = "Save as .wav";
            this.encryptButton.Style   = (Style)FindResource("ButtonStyleDarkMode");
            this.decryptButton.Style   = (Style)FindResource("ButtonStyleDarkMode");
            this.playButton.Style      = (Style)FindResource("ButtonStyleDarkMode");
            this.saveButton.Style      = (Style)FindResource("ButtonStyleDarkMode");
            this.encryptButton.Margin  = new Thickness(4);
            this.decryptButton.Margin  = new Thickness(4);
            this.playButton.Margin     = new Thickness(4);
            this.saveButton.Margin     = new Thickness(4);
            this.encryptButton.Click  += this.EncryptButton_Click;
            this.decryptButton.Click  += this.DecryptButton_Click;
            this.playButton.Click     += this.PlayButton_Click;
            this.saveButton.Click     += this.SaveButton_Click;

            RowDefinition buttonGridRow0 = new RowDefinition();

            buttonGridRow0.Height = new GridLength(1, GridUnitType.Auto);
            ColumnDefinition buttonGridColumn0 = new ColumnDefinition();
            ColumnDefinition buttonGridColumn1 = new ColumnDefinition();
            ColumnDefinition buttonGridColumn2 = new ColumnDefinition();
            ColumnDefinition buttonGridColumn3 = new ColumnDefinition();

            buttonGridColumn0.Width = new GridLength(1, GridUnitType.Auto);
            buttonGridColumn1.Width = new GridLength(1, GridUnitType.Auto);
            buttonGridColumn2.Width = new GridLength(1, GridUnitType.Auto);
            buttonGridColumn3.Width = new GridLength(1, GridUnitType.Auto);

            Grid buttonGrid = new Grid();

            buttonGrid.HorizontalAlignment = HorizontalAlignment.Center;
            buttonGrid.RowDefinitions.Add(buttonGridRow0);
            buttonGrid.ColumnDefinitions.Add(buttonGridColumn0);
            buttonGrid.ColumnDefinitions.Add(buttonGridColumn1);
            buttonGrid.ColumnDefinitions.Add(buttonGridColumn2);
            buttonGrid.ColumnDefinitions.Add(buttonGridColumn3);
            Grid.SetRow(this.encryptButton, 0);
            Grid.SetRow(this.decryptButton, 0);
            Grid.SetRow(this.playButton, 0);
            Grid.SetRow(this.saveButton, 0);
            Grid.SetColumn(this.encryptButton, 0);
            Grid.SetColumn(this.decryptButton, 1);
            Grid.SetColumn(this.playButton, 2);
            Grid.SetColumn(this.saveButton, 3);
            buttonGrid.Children.Add(this.encryptButton);
            buttonGrid.Children.Add(this.decryptButton);
            buttonGrid.Children.Add(this.playButton);
            buttonGrid.Children.Add(this.saveButton);

            DockPanel dockPanelButtons = new DockPanel();

            dockPanelButtons.HorizontalAlignment = HorizontalAlignment.Stretch;
            dockPanelButtons.Children.Add(buttonGrid);

            TextBlock soundName = new TextBlock();

            soundName.FontSize            = 20;
            soundName.HorizontalAlignment = HorizontalAlignment.Left;
            soundName.Margin = new Thickness(4);
            soundName.Text   = displayName;

            RowDefinition gridRow0 = new RowDefinition();
            RowDefinition gridRow1 = new RowDefinition();

            gridRow0.Height = new GridLength(1, GridUnitType.Auto);
            gridRow1.Height = new GridLength(1, GridUnitType.Auto);
            ColumnDefinition gridColumn0 = new ColumnDefinition();

            gridColumn0.Width = new GridLength(1, GridUnitType.Star);

            Grid contentHolderGrid = new Grid();

            contentHolderGrid.Background          = new SolidColorBrush(Color.FromArgb(0xFF, 0xA0, 0xA0, 0xA0));
            contentHolderGrid.HorizontalAlignment = HorizontalAlignment.Stretch;
            contentHolderGrid.RowDefinitions.Add(gridRow0);
            contentHolderGrid.RowDefinitions.Add(gridRow1);
            contentHolderGrid.ColumnDefinitions.Add(gridColumn0);
            Grid.SetRow(soundName, 0);
            Grid.SetRow(dockPanelButtons, 1);
            Grid.SetColumn(soundName, 0);
            Grid.SetColumn(dockPanelButtons, 0);
            contentHolderGrid.Children.Add(soundName);
            contentHolderGrid.Children.Add(dockPanelButtons);

            this.BorderThickness     = new Thickness(1.5);
            this.BorderBrush         = new SolidColorBrush(Color.FromArgb(0xFF, 0x91, 0x91, 0x91));
            this.Margin              = new Thickness(5, 5, 5, 0);
            this.HorizontalAlignment = HorizontalAlignment.Stretch;
            this.Child = contentHolderGrid;
        }