예제 #1
0
        public void TestMethod()
        {
            const double silence = 0.0001;

            var    wavDataSmall = new float[] { 0.0001f, -0.8f, 0.05f, -0.05f, 0.2f, 0.4f, 1.0f, 0.0001f };
            Bitmap png          = AudioAnalyzer.DrawWaveformMono(wavDataSmall, new Size(1000, 600), 1, 1, 0, 44100);
            string fileName     = String.Format("wave-small-dataset-{0}.png", 1);

            png.Save(fileName);

            // crop
            float[] wavDataSmallCropped = AudioUtils.CropAudioAtSilence(wavDataSmall, silence, false, 0);
            png      = AudioAnalyzer.DrawWaveformMono(wavDataSmallCropped, new Size(1000, 600), 1, 1, 0, 44100);
            fileName = String.Format("wave-small-dataset-cropped{0}.png", 1);
            png.Save(fileName);

            // init audio system
            var audioSystem = BassProxy.Instance;

            float[] wavDataBig = BassProxy.ReadMonoFromFile(WAVE_INPUT_FILEPATH, 44100, 10, 0);
            png      = AudioAnalyzer.DrawWaveformMono(wavDataBig, new Size(1000, 600), 2000, 1, 0, 44100);
            fileName = String.Format("wave-big-dataset-{0}.png", 1);
            png.Save(fileName);

            // crop
            float[] wavDataBigCropped = AudioUtils.CropAudioAtSilence(wavDataBig, silence, false, 0);
            png      = AudioAnalyzer.DrawWaveformMono(wavDataBigCropped, new Size(1000, 600), 1, 1, 0, 44100);
            fileName = String.Format("wave-big-dataset-cropped{0}.png", 1);
            png.Save(fileName);
        }
예제 #2
0
        /// <summary>
        /// sets graph data
        /// </summary>
        public void SetAudioData(float[] audioData)
        {
            this.audioData = audioData;
            bmp            = AudioAnalyzer.DrawWaveformMono(audioData,
                                                            new Size(this.Width, this.Height),
                                                            waveDisplayAmplitude,
                                                            waveDisplayStartZoomPosition,
                                                            waveDisplayEndZoomPosition,
                                                            sampleRate, true);

            // force redraw
            this.Invalidate();
        }
        private void UpdateWaveform()
        {
            if (soundPlayer == null || soundPlayer.WaveformData == null)
            {
                return;
            }

            if (soundPlayer.WaveformData != null && soundPlayer.WaveformData.Length > 1)
            {
                this.offlineBitmap = AudioAnalyzer.DrawWaveformMono(soundPlayer.WaveformData, new Size(this.Width, this.Height), amplitude, startZoomSamplePosition, endZoomSamplePosition, soundPlayer.SampleRate, true);

                // force redraw
                this.Invalidate();
            }
        }
예제 #4
0
        void MeasureLFOBtnClick(object sender, EventArgs e)
        {
            MeasureLFOInit();
            VstHost host = VstHost.Instance;

            var lfoAlreadyProcessed = new List <string>();

            // step through the LFO steps
            int count = 0;

            for (float paramValue = 1.0f; paramValue >= 0.0f; paramValue -= 0.020f)
            {
                // time how long this takes
                Stopwatch stopwatch = Stopwatch.StartNew();

                // init the buffers
                host.ClearRecording();
                host.ClearLastProcessedBuffers();

                // start record
                host.Record = true;

                // set the parameter
                PluginContext.PluginCommandStub.SetParameter(SYLENTH_PARAM_LFO1_RATE, paramValue);

                // get param display value
                string paramDisplay = PluginContext.PluginCommandStub.GetParameterDisplay(SYLENTH_PARAM_LFO1_RATE);

                // check if already processed
                if (lfoAlreadyProcessed.Contains(paramDisplay))
                {
                    continue;
                }
                else
                {
                    lfoAlreadyProcessed.Add(paramDisplay);
                }

                // wait until it has started playing
                while (!host.LastProcessedBufferLeftPlaying)
                {
                    // start playing audio
                    Playback.Play();

                    // play midi
                    host.SendMidiNote(host.SendContinousMidiNote, host.SendContinousMidiNoteVelocity);

                    if (stopwatch.ElapsedMilliseconds > 5000)
                    {
                        stopwatch.Stop();
                        Console.Out.WriteLine("MeasureLFOBtnClick: Playing Midi Failed!");
                        return;
                    }
                    System.Threading.Thread.Sleep(100);
                }

                // play for approx 1000 ms
                // paramValue: 1 = 1/256 Triple     (count = 0)
                // paramValue: 0 = 8/1 D			(count = 10)
                System.Threading.Thread.Sleep((int)(20 * Math.Pow(count, 2)));

                // stop midi
                host.SendMidiNote(host.SendContinousMidiNote, 0);

                // wait until it has stopped playing
                while (host.LastProcessedBufferLeftPlaying)
                {
                    if (stopwatch.ElapsedMilliseconds > 40000)
                    {
                        Console.Out.WriteLine("MeasureLFOBtnClick: Playing never stopped?!");
                        break;
                    }
                }
                // stop playing audio
                Playback.Stop();

                stopwatch.Stop();
                Console.Out.WriteLine("MeasureLFOBtnClick: Playing stopped: {0} ms. {1}", stopwatch.ElapsedMilliseconds, paramDisplay);

                // stop recording
                host.Record = false;

                // crop
                CropAudio();

                // store this in a wav ouput file.
                string wavFilePath = String.Format("audio-LFO-{0}-{1}.wav", StringUtils.MakeValidFileName(paramDisplay), StringUtils.GetCurrentTimestamp());
                AudioUtilsNAudio.CreateWaveFile(host.RecordedLeft.ToArray(), wavFilePath, new WaveFormat(host.SampleRate, 1));

                // store as a png
                System.Drawing.Bitmap png = AudioAnalyzer.DrawWaveformMono(host.RecordedLeft.ToArray(), new System.Drawing.Size(1000, 600), 1, host.SampleRate);
                string fileName           = String.Format("audio-LFO-{0}-{1}.png", StringUtils.MakeValidFileName(paramDisplay), StringUtils.GetCurrentTimestamp());
                png.Save(fileName);

                // clear
                ClearAudio();

                // wait a specfied time
                System.Threading.Thread.Sleep(100);

                stopwatch.Stop();

                count++;
            }
        }
예제 #5
0
        void MeasureADSRParameter(int paramName, float paramValue, string envName, bool measureRelease = false)
        {
            Console.Out.WriteLine("MeasureADSREntry: Measuring {0} at value {1:0.00}...", envName, paramValue);

            VstHost host = VstHost.Instance;

            // time how long this takes
            Stopwatch stopwatch = Stopwatch.StartNew();

            // init the buffers
            host.ClearRecording();
            host.ClearLastProcessedBuffers();

            // start record
            host.Record = true;

            // set the parameter
            PluginContext.PluginCommandStub.SetParameter(paramName, paramValue);
            ((HostCommandStub)PluginContext.HostCommandStub).SetParameterAutomated(paramName, paramValue);

            // wait until it has started playing
            while (!host.LastProcessedBufferLeftPlaying)
            {
                // start playing audio
                Playback.Play();

                // play midi
                host.SendMidiNote(host.SendContinousMidiNote, host.SendContinousMidiNoteVelocity);

                if (stopwatch.ElapsedMilliseconds > 5000)
                {
                    stopwatch.Stop();
                    Console.Out.WriteLine("MeasureADSREntry: Playing Midi Failed!");
                    return;
                }
                System.Threading.Thread.Sleep(100);
            }

            if (measureRelease)
            {
                // release is a special case where you only measure the tail after
                // a short midi signal
                // therefore we need to stop the midi message here
                host.SendMidiNote(host.SendContinousMidiNote, 0);
            }

            // wait until it has stopped playing
            stopwatch.Stop();
            stopwatch.Start();
            while (host.LastProcessedBufferLeftPlaying)
            {
                if (stopwatch.ElapsedMilliseconds > 40000)
                {
                    stopwatch.Stop();
                    Console.Out.WriteLine("MeasureADSREntry: Playing never stopped?!");
                    break;
                }
            }

            // stop playing audio
            Playback.Stop();

            stopwatch.Stop();
            Console.Out.WriteLine("MeasureADSREntry: Playing stopped: {0} ms.", stopwatch.ElapsedMilliseconds);

            // stop recording
            host.Record = false;

            // wait a specfied time
            System.Threading.Thread.Sleep(100);

            // crop
            CropAudio();

            // store the duration
            RetrieveDuration();

            // store this in a wav ouput file.
            float  param       = PluginContext.PluginCommandStub.GetParameter(paramName);
            string wavFilePath = String.Format("{0}{1:0.00}s-{2}.wav", envName, param, StringUtils.GetCurrentTimestamp());

            AudioUtilsNAudio.CreateWaveFile(host.RecordedLeft.ToArray(), wavFilePath, new WaveFormat(host.SampleRate, 1));

            // store as a png
            System.Drawing.Bitmap png = AudioAnalyzer.DrawWaveformMono(host.RecordedLeft.ToArray(), new System.Drawing.Size(1000, 600), 1, host.SampleRate);
            string fileName           = String.Format("{0}{1:0.00}s-{2}.png", envName, param, StringUtils.GetCurrentTimestamp());

            png.Save(fileName);

            if (!measureRelease)
            {
                // turn of midi unless we are measuring a release envelope
                // then it should have been turned of immideately after a small signal is generated
                host.SendMidiNote(host.SendContinousMidiNote, 0);
            }

            // clear
            ClearAudio();

            // wait a specfied time
            System.Threading.Thread.Sleep(100);

            stopwatch.Stop();
        }