Esempio n. 1
0
        public static void PreprocessWithEnvelope(string filePath)
        {
            Console.WriteLine($"Pre-processing for word count of file {filePath}");

            using (var afr = new FileStream(filePath, FileMode.Open))
            {
                // create a signal file
                var            waveFile = new WaveFile(afr);
                DiscreteSignal signal   = waveFile[Channels.Left];

                // smooth signal with envelope
                DiscreteSignal envelope = Operation.Envelope(signal);

                // instance of SimpleGate
                SimpleGate sg = new SimpleGate(30, 30, envelope.SamplingRate);

                for (int i = 0; i < envelope.Length; i++)
                {
                    double inValue = envelope.Samples[i];

                    sg.Process(ref inValue);

                    envelope.Samples[i] = (float)inValue;
                }

                using (var stream = new FileStream($"{DATA_PATH}/envelope.wav", FileMode.Create))
                {
                    var signalFile = new WaveFile(envelope);
                    signalFile.SaveTo(stream);
                }
            }
        }
Esempio n. 2
0
        public static void PreprocessForWordCount(string filePath)
        {
            Console.WriteLine($"Pre-processing for word count of file {filePath}");

            using (var afr = new FileStream(filePath, FileMode.Open))
            {
                // create a signal file
                var            waveFile = new WaveFile(afr);
                DiscreteSignal signal   = waveFile[Channels.Left];

                // smooth signal via moving average filter
                var            maFilter       = new MovingAverageFilter(19);
                DiscreteSignal smoothedSignal = maFilter.ApplyTo(signal);

                // instance of SimpleGate
                SimpleGate sg = new SimpleGate(30, 30, smoothedSignal.SamplingRate);

                for (int i = 0; i < smoothedSignal.Length; i++)
                {
                    double inValue = smoothedSignal.Samples[i];

                    sg.Process(ref inValue);

                    smoothedSignal.Samples[i] = (float)inValue;
                }

                using (var stream = new FileStream($"{DATA_PATH}/preprocessed.wav", FileMode.Create))
                {
                    var signalFile = new WaveFile(smoothedSignal);
                    signalFile.SaveTo(stream);
                }
            }
        }
Esempio n. 3
0
            public void DefaultsForProperties()
            {
                var target = new SimpleGate();

                Assert.IsTrue(target.CheckRequestGate);
                Assert.IsTrue(target.CheckStatisticGate);
                Assert.IsTrue(target.RequestGate(null, null));
                Assert.IsTrue(target.StatisticsGate(null, null));
            }
Esempio n. 4
0
        public static void TestSimpleGate(string filePath)
        {
            Console.WriteLine($"Testing 'SingleGate' class with file {filePath}");

            using (var afr = new FileStream(filePath, FileMode.Open))
            {
                // create a signal file
                var            waveFile = new WaveFile(afr);
                DiscreteSignal signal   = waveFile[Channels.Left];

                List <Tuple <int, int> > attackReleaseValues = new List <Tuple <int, int> > {
                    new Tuple <int, int>(5, 5),
                    new Tuple <int, int>(5, 10),
                    new Tuple <int, int>(10, 5),
                    new Tuple <int, int>(10, 10),
                    new Tuple <int, int>(10, 15),
                    new Tuple <int, int>(15, 10),
                    new Tuple <int, int>(15, 15),
                    new Tuple <int, int>(15, 20),
                    new Tuple <int, int>(20, 15),
                    new Tuple <int, int>(20, 20),
                    new Tuple <int, int>(20, 25),
                    new Tuple <int, int>(25, 20),
                    new Tuple <int, int>(25, 25),
                };

                // for each attack/release pair combination
                for (int i = 0; i < attackReleaseValues.Count; i++)
                {
                    int attack, release;
                    attack  = attackReleaseValues[i].Item1;
                    release = attackReleaseValues[i].Item2;

                    // instance of SimpleGate
                    SimpleGate sg = new SimpleGate(attack, release, signal.SamplingRate);

                    for (int j = 0; j < signal.Length; j++)
                    {
                        double inValue = signal.Samples[j];
                        sg.Process(ref inValue);
                        signal.Samples[j] = (float)inValue;
                    }

                    using (var stream = new FileStream($"{DATA_PATH}/gate-{attack}-{release}.wav", FileMode.Create))
                    {
                        var signalFile = new WaveFile(signal);
                        signalFile.SaveTo(stream);
                    }
                }
            }
        }
Esempio n. 5
0
        public static DiscreteSignal PreprocessAudio(DiscreteSignal signal)
        {
            // smooth signal via moving average filter
            var maFilter = new MovingAverageFilter(19);
            DiscreteSignal smoothedSignal = maFilter.ApplyTo(signal);



            using (var stream = new FileStream("smoothedSignal.wav", FileMode.Create))
            {
                var signalFile = new WaveFile(smoothedSignal);
                signalFile.SaveTo(stream);
            }



            // pre-process signal with SimpleGate
            SimpleGate sg = new SimpleGate(30, 30, smoothedSignal.SamplingRate);

            // apply for each measured sample
            for (int i = 0; i < smoothedSignal.Length; i++)
            {
                double inValue = smoothedSignal.Samples[i];

                sg.Process(ref inValue);

                smoothedSignal.Samples[i] = (float)inValue;
            }

            // apply envelope operation
            DiscreteSignal envelopeSignal = Operation.Envelope(smoothedSignal);

            using (var stream = new FileStream("envelopeSignal.wav", FileMode.Create))
            {
                var signalFile = new WaveFile(envelopeSignal);
                signalFile.SaveTo(stream);
            }

            return envelopeSignal;
        }