示例#1
0
文件: Program.cs 项目: yazici/yaalp
        // Test between 20Hz and 500Hz. This works very well, although it is hard to eliminate octave errors
        // This test will play original, then a sine at the frequency it detected. The two should line up.
        private static void pitchdetectwav(AudioPlayer pl, string strFilename, PitchDetection.PitchDetectAlgorithm algorithm)
        {
            string    strInstdir = mediadir + @"pitchdetect\";
            WaveAudio w          = new WaveAudio(strInstdir + strFilename);

            if (w.getNumChannels() != 1)
            {
                w.setNumChannels(1, true);
            }
            double    dfreq     = PitchDetection.DetectPitch(w, 50, 500, algorithm);
            WaveAudio testPitch = new Triangle(dfreq, 0.7).CreateWaveAudio(1.0);

            pl.Play(w);
            pl.Play(testPitch);
        }
示例#2
0
文件: Program.cs 项目: yazici/yaalp
        static void iotests_perfile(string strFilename, int nBits, int nChannels, int nRate)
        {
            WaveAudio w01 = new WaveAudio(strFilename);

            asserteq(w01.getNumChannels(), nChannels);
            asserteq(w01.getSampleRate(), nRate, "011");
            asserteqf(w01.LengthInSamples, 90725 * (nRate / 22050), 1.0, "012"); //note give 1.0 tolerance
            asserteqf(w01.LengthInSeconds, 4.1145124, "013");

            asserteq(w01.data.Length, nChannels);
            asserteq(w01.data[0].Length, w01.LengthInSamples);
            for (int i = 0; i < nChannels; i++)
            {
                asserteq(w01.data[i].Length, w01.LengthInSamples);
            }

            // test converting to other rates / quality
            w01.SaveWaveFile(mediadir + "ttout\\o_" + nRate + "_" + nBits + "_" + nRate + "_" + nChannels + ".wav", nBits);
            nBits = (nBits == 8) ? 16 : 8;
            w01.SaveWaveFile(mediadir + "ttout\\ot_" + nRate + "_" + nBits + "_" + nRate + "_" + nChannels + ".wav", nBits);
        }
        public WaveAudio Generate(double timeScale, int timeShift)
        {
            if (wLast != null && timeScale == this.timeScaleLast && timeShift == this.timeShiftLast && !bNeedUpdate)
            {
                return(wLast);
            }

            WaveAudio w = wInput.Clone();

            for (int ch = 0; ch < w.getNumChannels(); ch++)
            {
                for (int i = 0; i < w.data[ch].Length; i++)
                {
                    w.data[ch][i] = w.data[ch][i] + w.data[ch][((int)(i * timeScale) + timeShift) % w.data[ch].Length];
                }
            }
            this.timeScaleLast = timeScale;
            this.timeShiftLast = timeShift;
            this.wLast         = w;
            this.bNeedUpdate   = false;
            return(w);
        }
示例#4
0
文件: Program.cs 项目: yazici/yaalp
        public static void propertytests()
        {
            // these aren't the best tests.
            WaveAudio w1 = new WaveAudio(44100, 2);

            asserteq(w1.data.Length, 2, "channels");
            asserteq(w1.getNumChannels(), 2, "channels");
            assert(w1.data[0] != null && w1.data[1] != null, "channels");
            assert(w1.data[0].Length == 1 && w1.data[1].Length == 1, "004");
            asserteq(w1.getSampleRate(), 44100, "005");

            WaveAudio w1m = new WaveAudio(22050, 1);

            asserteq(w1m.data.Length, 1, "channels");
            assert(w1m.data[0] != null, "channels");
            asserteq(w1m.data[0].Length, 1, "004");
            asserteq(w1m.getSampleRate(), 22050, "005");

            // now set some properties
            w1m.LengthInSamples = 100;
            asserteq(w1m.data[0].Length, 100);
            asserteqf(w1m.LengthInSeconds, 100 / (double)w1m.getSampleRate(), 0.001);
        }