Esempio n. 1
0
        public void RenderPNGvisual(PictureBox pictureBox, FileSystem fileSystem) //visualization af lyd, Kopieret fra nettet
        {
            var maxPeakProvider      = new MaxPeakProvider();
            var rmsPeakProvider      = new RmsPeakProvider(200);      // e.g. 200
            var samplingPeakProvider = new SamplingPeakProvider(200); // e.g. 200
            var averagePeakProvider  = new AveragePeakProvider(4);    // e.g. 4

            var topSpacerColor = Color.FromArgb(64, 224, 224, 224);

            var myRendererSettings = new SoundCloudBlockWaveFormSettings(Color.FromArgb(196, 197, 53, 0), topSpacerColor, Color.FromArgb(196, 79, 26, 0),
                                                                         Color.FromArgb(64, 79, 79, 79))
            {
                Name          = "SoundCloud Orange Transparent Blocks",
                PixelsPerPeak = 2,
                SpacerPixels  = 1,
                TopSpacerGradientStartColor = topSpacerColor,
                BackgroundColor             = Color.Transparent
            };;

            myRendererSettings.Width        = pictureBox.Width;
            myRendererSettings.TopHeight    = 20;
            myRendererSettings.BottomHeight = 15;


            var renderer      = new WaveFormRenderer();
            var audioFilePath = fileSystem.wavFiles[tal];
            var image         = renderer.Render(audioFilePath, rmsPeakProvider, myRendererSettings);

            pictureBox.Image = image;
        }
Esempio n. 2
0
        private void RenderChart(PictureBox picbox, string audioFilePath)
        {
            MaxPeakProvider      maxPeakProvider      = new MaxPeakProvider();
            RmsPeakProvider      rmsPeakProvider      = new RmsPeakProvider(200);      // e.g. 200
            SamplingPeakProvider samplingPeakProvider = new SamplingPeakProvider(200); // e.g. 200
            AveragePeakProvider  averagePeakProvider  = new AveragePeakProvider(4);    // e.g. 4

            StandardWaveFormRendererSettings myRendererSettings = new StandardWaveFormRendererSettings();

            myRendererSettings.Width        = 4320;
            myRendererSettings.TopHeight    = 256;
            myRendererSettings.BottomHeight = 256;
            //myRendererSettings.BottomSpacerPen = new Pen(Color.Transparent);
            //myRendererSettings.TopSpacerPen = new Pen(Color.Transparent);
            //myRendererSettings.PixelsPerPeak = 10;
            //myRendererSettings.SpacerPixels = 2;
            myRendererSettings.TopPeakPen      = new Pen(Color.FromArgb(0, 192, 192));
            myRendererSettings.BottomPeakPen   = new Pen(Color.FromArgb(100, 0, 192, 192));
            myRendererSettings.BackgroundColor = Color.Transparent;
            //myRendererSettings.DecibelScale = true;
            WaveFormRenderer renderer = new WaveFormRenderer();

            Image image = renderer.Render(audioFilePath, averagePeakProvider, myRendererSettings);

            picbox.Image = image;
        }
Esempio n. 3
0
        private void SelectSong_button_Click(object sender, EventArgs e)
        {
            //openFileDialog1.ShowDialog();
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                //listBox3.Items.Add(openFileDialog1.SafeFileName); //Addes the song to the list TODO: a function to call
            }

            var maxPeakProvider      = new MaxPeakProvider();
            var rmsPeakProvider      = new RmsPeakProvider(200);      // e.g. 200
            var samplingPeakProvider = new SamplingPeakProvider(200); // e.g. 200
            var averagePeakProvider  = new AveragePeakProvider(4);    // e.g. 4

            var myRendererSettings = new StandardWaveFormRendererSettings();

            myRendererSettings.Width           = 640;
            myRendererSettings.TopHeight       = 32;
            myRendererSettings.BottomHeight    = 32;
            myRendererSettings.BackgroundColor = Color.White;

            var renderer      = new WaveFormRenderer();
            var audioFilePath = "./user_data/sound/" + openFileDialog1.SafeFileName;
            var image         = renderer.Render(audioFilePath, myRendererSettings);

            pictureBox1.Image = image;
        }
Esempio n. 4
0
        private void Visualization()
        {
            var rmsPeakProvider    = new RmsPeakProvider(200);
            var myRendererSettings = new StandardWaveFormRendererSettings();

            myRendererSettings.Width           = 1376;
            myRendererSettings.TopHeight       = 91;
            myRendererSettings.BottomHeight    = 91;
            myRendererSettings.BackgroundColor = Color.Black;
            myRendererSettings.TopPeakPen      = penWhite;
            myRendererSettings.BottomPeakPen   = penGray;
            var   renderer = new WaveFormRenderer();
            Image image    = renderer.Render(filepath.Text, rmsPeakProvider, myRendererSettings);

            pictureBoxWave.Image = image;
        }
Esempio n. 5
0
        //SINGLE-IMPORT AUDIO
        private void button1_Click(object sender, EventArgs e)
        {
            //GET AUDIO FILE
            OpenFileDialog openFileDialog1 = new OpenFileDialog
            {
                InitialDirectory = @"C:\",
                Title            = "Browse Audio Files",

                CheckFileExists = true,
                CheckPathExists = true,

                DefaultExt       = "wav",
                Filter           = "wav files (*.wav)|*.wav",
                FilterIndex      = 2,
                RestoreDirectory = true,

                ReadOnlyChecked = true,
                ShowReadOnly    = true
            };

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                single_audio   = openFileDialog1.FileName;
                textBox1.Text += "Opened Audio File Successfully" + "\r\n";
                textBox2.Text  = "Imported Audio: " + single_audio;
            }

            if (single_audio != null)
            {
                //DISPLAY WAVEFORM
                var maxPeakProvider      = new MaxPeakProvider();
                var rmsPeakProvider      = new RmsPeakProvider(200);      // e.g. 200
                var samplingPeakProvider = new SamplingPeakProvider(200); // e.g. 200
                var averagePeakProvider  = new AveragePeakProvider(4);    // e.g. 4

                var myRendererSettings = new StandardWaveFormRendererSettings();
                myRendererSettings.Width        = 651;
                myRendererSettings.TopHeight    = 24;
                myRendererSettings.BottomHeight = 24;

                var renderer      = new WaveFormRenderer();
                var audioFilePath = single_audio;
                var image         = renderer.Render(audioFilePath, averagePeakProvider, myRendererSettings);

                pictureBox1.Image = image;
            }
        }
Esempio n. 6
0
        private void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    fileName = openFileDialog1.FileName;
                }
            }
            catch (ArgumentNullException)
            {
                return;
            }

            // 1. Configure Providers
            MaxPeakProvider      maxPeakProvider      = new MaxPeakProvider();
            RmsPeakProvider      rmsPeakProvider      = new RmsPeakProvider(200);      // e.g. 200
            SamplingPeakProvider samplingPeakProvider = new SamplingPeakProvider(200); // e.g. 200
            AveragePeakProvider  averagePeakProvider  = new AveragePeakProvider(4);    // e.g. 4

            // 2. Configure the style of the audio wave image
            StandardWaveFormRendererSettings myRendererSettings = new StandardWaveFormRendererSettings();

            myRendererSettings.Width        = 1080;
            myRendererSettings.TopHeight    = 64;
            myRendererSettings.BottomHeight = 64;

            myRendererSettings.BackgroundImage = new Bitmap(@"C:\Users\Kao\Pictures\Background\73109534_p6_master1200.jpg");

            // 3. Define the audio file from which the audio wave will be created and define the providers and settings
            WaveFormRenderer renderer = new WaveFormRenderer();
            Image            image    = renderer.Render(fileName, averagePeakProvider, myRendererSettings);

            // 4. Store the image
            image.Save(@"../render.png", ImageFormat.Png);
            pictureBox1.Image = image;
            // Or jpeg, however PNG is recommended if your audio wave needs transparency
            // image.Save(@"C:\Users\sdkca\Desktop\myfile.jpg", ImageFormat.Jpeg);

            waveOut = new WaveOut();
            waveOut.PlaybackStopped += WaveOut_OnPlaybackStopped;
            var reader = new Mp3FileReader(fileName);

            waveOut.Init(reader);
        }
Esempio n. 7
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var openFileDialog1 = new OpenFileDialog();

            try
            {
                fileName = openFileDialog1.FileName;
            }
            catch (ArgumentNullException)
            {
                return;
            }

            // 1. Configure Providers
            MaxPeakProvider      maxPeakProvider      = new MaxPeakProvider();
            RmsPeakProvider      rmsPeakProvider      = new RmsPeakProvider(200);      // e.g. 200
            SamplingPeakProvider samplingPeakProvider = new SamplingPeakProvider(200); // e.g. 200
            AveragePeakProvider  averagePeakProvider  = new AveragePeakProvider(4);    // e.g. 4

            // 2. Configure the style of the audio wave image
            StandardWaveFormRendererSettings myRendererSettings = new StandardWaveFormRendererSettings();

            myRendererSettings.Width        = 1080;
            myRendererSettings.TopHeight    = 64;
            myRendererSettings.BottomHeight = 64;

            myRendererSettings.BackgroundImage = new Bitmap(@"C:\Users\ciit\Pictures\Konachan.com - 218504 arima_kousei a-shacho blonde_hair dark glasses instrument male miyazono_kaori piano shigatsu_wa_kimi_no_uso tree violin.jpg");

            // 3. Define the audio file from which the audio wave will be created and define the providers and settings
            WaveFormRenderer renderer = new WaveFormRenderer();
            Image            image    = renderer.Render(fileName, averagePeakProvider, myRendererSettings);

            // 4. Store the image
            image.Save(@"../render.png", ImageFormat.Png);
            MusicImage.Image = image;
            // Or jpeg, however PNG is recommended if your audio wave needs transparency
            // image.Save(@"C:\Users\sdkca\Desktop\myfile.jpg", ImageFormat.Jpeg);

            waveOut = new WaveOut();
            waveOut.PlaybackStopped += WaveOut_OnPlaybackStopped;
            var reader = new Mp3FileReader(fileName);

            waveOut.Init(reader);
        }
Esempio n. 8
0
        private void ButBrowse_Click_1(object sender, EventArgs e)      //browse button
        {
            string oSelectedFile = "";

            System.Windows.Forms.OpenFileDialog oDlg = new System.Windows.Forms.OpenFileDialog();
            if (System.Windows.Forms.DialogResult.OK == oDlg.ShowDialog())
            {
                oSelectedFile = oDlg.FileName;      //selected file = oSelectedFile
                textBox1.Text = oSelectedFile;

                //configure Providers
                MaxPeakProvider      maxPeakProvider      = new MaxPeakProvider();
                RmsPeakProvider      rmsPeakProvider      = new RmsPeakProvider(200);
                SamplingPeakProvider samplingPeakProvider = new SamplingPeakProvider(200);      //could control these values with sliders?
                AveragePeakProvider  averagePeakProvider  = new AveragePeakProvider(4);

                //configure the style of the audio wave image
                StandardWaveFormRendererSettings myRendererSettings = new StandardWaveFormRendererSettings();
                myRendererSettings.Width        = 1080;
                myRendererSettings.TopHeight    = 64;
                myRendererSettings.BottomHeight = 64;

                WaveFormRenderer renderer      = new WaveFormRenderer();
                String           audioFilePath = textBox1.Text;
                Image            image         = renderer.Render(audioFilePath, averagePeakProvider, myRendererSettings);
                string           folder        = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
                System.IO.Directory.CreateDirectory(folder + "\\AudioManipulation");
                image.Save(folder + "\\AudioManipulation\\output.png", ImageFormat.Png);

                AddToLog("- Sound Played");

                //loads waveform after generation on file browse
                Image loadImage = Image.FromFile("\\output.png");
                pictureBox2.Image  = image;
                pictureBox2.Height = image.Height;
                pictureBox2.Width  = image.Width;
            }
        }
Esempio n. 9
0
        public AudioFileViewModel(string filepath)
        {
            FilePath = filepath;

            var blockSize      = 200;
            var sampleInterval = 200;
            var scaleFactor    = 4;

            var maxPeakProvider      = new MaxPeakProvider();
            var rmsPeakProvider      = new RmsPeakProvider(blockSize);           // e.g. 200
            var samplingPeakProvider = new SamplingPeakProvider(sampleInterval); // e.g. 200
            var averagePeakProvider  = new AveragePeakProvider(scaleFactor);     // e.g. 4

            var myRendererSettings = new StandardWaveFormRendererSettings();

            myRendererSettings.Width        = 640;
            myRendererSettings.TopHeight    = 32;
            myRendererSettings.BottomHeight = 32;

            var renderer = new WaveFormRenderer();

            Image = ConvertImage(renderer.Render(FilePath, averagePeakProvider, myRendererSettings));
        }
Esempio n. 10
0
        private static void MakeWav(string source, string target)
        {
            // 1. Configure Providers
            MaxPeakProvider      maxPeakProvider      = new MaxPeakProvider();
            RmsPeakProvider      rmsPeakProvider      = new RmsPeakProvider(200);      // e.g. 200
            SamplingPeakProvider samplingPeakProvider = new SamplingPeakProvider(200); // e.g. 200
            AveragePeakProvider  averagePeakProvider  = new AveragePeakProvider(4);    // e.g. 4

            // 2. Configure the style of the audio wave image
            //StandardWaveFormRendererSettings myRendererSettings = new StandardWaveFormRendererSettings();
            //myRendererSettings.Width = 1080;
            //myRendererSettings.TopHeight = 64;
            //myRendererSettings.BottomHeight = 64;

            // 3. Define the audio file from which the audio wave will be created and define the providers and settings
            WaveFormRenderer renderer = new WaveFormRenderer();
            //String audioFilePath = @"C:\Users\sdkca\Desktop\when_the_sun_goes_down_arctic_monkeys.mp3";
            Image image = renderer.Render(source, averagePeakProvider, _settings);

            // 4. Store the image
            image.Save(target, ImageFormat.Png);
            // Or jpeg, however PNG is recommended if your audio wave needs transparency
            // image.Save(@"C:\Users\sdkca\Desktop\myfile.jpg", ImageFormat.Jpeg);
        }
    private void GetWaveform(WaveStream reader, int width, int height, int peakCount, Action <Texture2D> callback)
    {
        int           bytesPerSample  = reader.WaveFormat.BitsPerSample / 8;
        var           samples         = reader.Length / bytesPerSample;
        var           samplesPerPixel = (int)(samples / width);
        IPeakProvider peakProvider    = new RmsPeakProvider(1);

        peakProvider.Init(reader.ToSampleProvider(), samplesPerPixel);
        int       p           = 0;
        var       currentPeak = peakProvider.GetNextPeak();
        int       peakNum     = 0;
        Texture2D texture     = new Texture2D(waveFormWidth, waveFormHeight);

        for (int x = 0; x < waveFormWidth; x++)
        {
            for (int y = 0; y < waveFormHeight; y++)
            {
                texture.SetPixel(x, y, Color.clear);
            }
        }
        float[] peakSizes   = new float[peakCount];
        float   peakSize    = 0f;
        float   maxPeakSize = 0f;

        while (p < width)
        {
            peakSize += Mathf.Abs(currentPeak.Max) + Mathf.Abs(currentPeak.Min);
            if (p % (peakWidth + spaceWidth) == 0)
            {
                peakSizes[peakNum] = peakSize;
                maxPeakSize        = maxPeakSize < peakSize ? peakSize : maxPeakSize;
                peakSize           = 0;
                peakNum++;
            }
            var nextPeak = peakProvider.GetNextPeak();
            currentPeak = nextPeak;
            p++;
        }
        peakNum = 0;
        p       = 0;
        float k = waveFormHeight / (2 * maxPeakSize + peakWidth);

        while (p < width)
        {
            peakSize = peakSizes.Length <= peakNum ? 0f : peakSizes[peakNum];
            peakSize = peakSize * k;
            var pos = p % (peakWidth + spaceWidth);
            if (pos > spaceWidth)
            {
                int pX = pos - spaceWidth;
                pX = pX <= peakWidth / 2 ? pX : peakWidth - pX;
                var pS = peakSize + Mathf.Sqrt(3 / 4 * peakWidth - 2 * pX * pX + 2 * pX * peakWidth);
                for (int y = 0; y < waveFormHeight; y++)
                {
                    if (Mathf.Abs(y - waveFormHeight / 2) < pS)
                    {
                        texture.SetPixel(p, y, new Color(1, 1, 1, pS - Mathf.Abs(y - waveFormHeight / 2)));
                    }
                }
            }
            if ((p + spaceWidth) % (spaceWidth + peakWidth) == 0)
            {
                peakNum++;
            }
            p++;
        }
        texture.Apply();
        texture.filterMode = FilterMode.Bilinear;
        callback?.Invoke(texture);
    }