Exemplo n.º 1
0
        ////////////////////////////////////////////////////////

        public SignalGeneratorResult GenerateSignal(SignalGenerateParams s, out WavData wavData)
        {
            List <PcmSamples1Channel> samples = new List <PcmSamples1Channel>();

            int nSample           = s.seconds * s.sampleRate;
            PcmSamples1Channel ch = new PcmSamples1Channel(nSample, s.bitsPerSample);

            samples.Add(ch);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            SignalGeneratorResult result = SignalGeneratorResult.Success;
            double truncFreq             = (s.sampleRate / 2) * s.truncationRatio;

            switch (s.ss)
            {
            case SignalShape.SineWave:
                result = GenerateSineWave(ch, s.sampleRate, s.freq, s.amplitude);
                break;

            case SignalShape.SquareWave:
                result = GenerateSquareWave(ch, s.sampleRate, s.freq, s.amplitude, truncFreq);
                break;

            case SignalShape.SawToothWaveDesc:
                result = GenerateSawToothWave(ch, s.sampleRate, s.freq, s.amplitude, truncFreq, false);
                break;

            case SignalShape.SawToothWaveAsc:
                result = GenerateSawToothWave(ch, s.sampleRate, s.freq, s.amplitude, truncFreq, true);
                break;

            case SignalShape.TriangleWave:
                result = GenerateTriangleWave(ch, s.sampleRate, s.freq, s.amplitude, truncFreq);
                break;

            default:
                System.Diagnostics.Debug.Assert(false);
                break;
            }

            sw.Stop();
            Console.WriteLine("{0} ms", sw.ElapsedMilliseconds);


            wavData = new WavData();
            wavData.Create(s.sampleRate, s.bitsPerSample, samples);
            return(result);
        }
        ////////////////////////////////////////////////////////
        public SignalGeneratorResult GenerateSignal(SignalGenerateParams s, out WavData wavData)
        {
            List<PcmSamples1Channel> samples = new List<PcmSamples1Channel>();

            int nSample = s.seconds * s.sampleRate;
            PcmSamples1Channel ch = new PcmSamples1Channel(nSample, s.bitsPerSample);
            samples.Add(ch);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            SignalGeneratorResult result = SignalGeneratorResult.Success;
            double truncFreq = (s.sampleRate / 2) * s.truncationRatio;

            switch (s.ss) {
            case SignalShape.SineWave:
                result = GenerateSineWave(ch, s.sampleRate, s.freq, s.amplitude);
                break;
            case SignalShape.SquareWave:
                result = GenerateSquareWave(ch, s.sampleRate, s.freq, s.amplitude, truncFreq);
                break;
            case SignalShape.SawToothWaveDesc:
                result = GenerateSawToothWave(ch, s.sampleRate, s.freq, s.amplitude, truncFreq, false);
                break;
            case SignalShape.SawToothWaveAsc:
                result = GenerateSawToothWave(ch, s.sampleRate, s.freq, s.amplitude, truncFreq, true);
                break;
            case SignalShape.TriangleWave:
                result = GenerateTriangleWave(ch, s.sampleRate, s.freq, s.amplitude, truncFreq);
                break;
            default:
                System.Diagnostics.Debug.Assert(false);
                break;
            }

            sw.Stop();
            Console.WriteLine("{0} ms", sw.ElapsedMilliseconds);

            wavData = new WavData();
            wavData.Create(s.sampleRate, s.bitsPerSample, samples);
            return result;
        }