private static OffsetSampleProvider CreateSignalGenerator(int @from, int channels)
 {
     var signalGenerator = new SignalGenerator(@from, channels);
     signalGenerator.Type = SignalGeneratorType.SawTooth;
     signalGenerator.Frequency = 512;
     signalGenerator.Gain = 0.3f;
     var offset = new OffsetSampleProvider(signalGenerator);
     offset.TakeSamples = @from * channels * 5; // 5 seconds
     return offset;
 }
Пример #2
0
        public MainWindow()
        {
            frqLog = Math.Log10(fMax / fMin);

            // Init Audio
            driverOut = new WaveOut();
            driverOut.DesiredLatency = 100;
            wave = new ADSRSignalGenerator();
            osc1 = new SignalGenerator();
            osc2 = new SignalGenerator();
            osc3 = new SignalGenerator();
            driverOut.Init(wave);
            envEnabled = false;

            // Init UI
            InitializeComponent();
        }
Пример #3
0
        public GeneratorPanel()
        {
            // Const
            Log10FmaxFMin = Math.Log10(FMax/FMin);

            // Panel Init
            InitializeComponent();
            this.Disposed += new EventHandler(GeneratorPanel_Disposed);

            // Init Audio
            driverOut = new WaveOut();
            driverOut.DesiredLatency = 100;
            //driverOut = new AsioOut(0);
            wg = new SignalGenerator();

            // Par Default Frq 1200Hz
            cmbFrq.SelectedIndex = 0;
            cmbPrecisionFrq.SelectedIndex = 2;
            tbFrq.Value = 12; // 1200Hz
            tbToFrq();

            // Par Default Frq End 2000Hz
            cmbFrqEnd.SelectedIndex = 0;
            cmbPrecisionFrqEnd.SelectedIndex = 2;
            tbFrqEnd.Value = tbFrqEnd.Maximum;
            tbToFrqEnd();

            // comboBox Type
            cmbType.DataSource = Enum.GetValues(typeof (SignalGeneratorType));
            cmbType.SelectedIndex = 0;

            // Par Default Gain -20dB
            tbGain.Value = -20;
            tbToGain();

            // Par Default SweepSeconds
            tbSweepLength.Value = 10;
            tbToSweepLength();

            // Init Driver Audio
            driverOut.Init(wg);
            StartStopEnabled();
        }
Пример #4
0
        public GeneratorPanel()
        {
            // Const
            log10FmaxFMin = Math.Log10(FMax/FMin);

            // Panel Init
            InitializeComponent();
            Disposed += OnGeneratorPanelDisposed;

            // Init Audio
            driverOut = new WaveOutEvent();
            //driverOut = new AsioOut(0);
            wg = new SignalGenerator();

            // Par Default Frq 1200Hz
            cmbFrq.SelectedIndex = 0;
            cmbPrecisionFrq.SelectedIndex = 2;
            tbFrq.Value = 12; // 1200Hz
            CalculateTrackBarFrequency();

            // Par Default Frq End 2000Hz
            cmbFrqEnd.SelectedIndex = 0;
            cmbPrecisionFrqEnd.SelectedIndex = 2;
            tbFrqEnd.Value = tbFrqEnd.Maximum;
            CalculateTrackBarEndFrequency();

            // comboBox Type
            cmbType.DataSource = Enum.GetValues(typeof (SignalGeneratorType));
            cmbType.SelectedIndex = 0;

            // Par Default Gain -20dB
            tbGain.Value = -20;
            CalculateTrackBarToGain();

            // Par Default SweepSeconds
            tbSweepLength.Value = 10;
            CalculateTrackBarToSweepLength();

            // Init Driver Audio
            driverOut.Init(wg);
            StartStopEnabled();

        }
Пример #5
0
 private static WaveStream CreatePcmTestStream()
 {
     var testFile = @"C:\Users\Mark\Code\CodePlex\pcm mono 16 bit 8kHz.wav";
     if (File.Exists(testFile))
     {
         return new WaveFileReader(testFile);
     }
     var outFormat = new WaveFormat(8000, 16, 1);
     const int durationInSeconds = 5;
     var sg = new SignalGenerator(outFormat.SampleRate, outFormat.Channels)
     {
         Frequency = 1000,
         Gain = 0.25,
         Type = SignalGeneratorType.Sin
     };
     var sp = sg.ToWaveProvider16();
     byte[] data = new byte[outFormat.AverageBytesPerSecond * durationInSeconds];
     var bytesRead = sp.Read(data, 0, data.Length);
     Assert.AreEqual(bytesRead, data.Length);
     return new RawSourceWaveStream(new MemoryStream(data), outFormat);
 }
Пример #6
0
        public static void PlaySingleNote(Object n)
        {
            Note note = (Note)n;

            int msduration = getDuration(note);

            SignalGeneratorType t = SignalGeneratorType.Triangle;

            if (note.waveform == Waveforms.Triangle)
            {
                t = SignalGeneratorType.Triangle;
            }
            else if (note.waveform == Waveforms.Sawtooth)
            {
                t = SignalGeneratorType.SawTooth;
            }
            else if (note.waveform == Waveforms.Pulse)
            {
                t = SignalGeneratorType.Square;
            }


            var signal = new NAudio.Wave.SampleProviders.SignalGenerator()
            {
                Gain      = 0.8,
                Frequency = note.frequency,
                Type      = t
            }.Take(TimeSpan.FromMilliseconds(msduration));

            using (var wo = new WaveOutEvent())
            {
                wo.Init(signal);
                wo.Play();
                while (wo.PlaybackState == PlaybackState.Playing)
                {
                    //Thread.Sleep(1);
                }
            }
        }
Пример #7
0
        // Clean DriverOut
        private void Cleanup()
        {
            if (driverOut != null)
                driverOut.Stop();

            if (wg != null)
                wg = null;

            if (driverOut != null)
            {
                driverOut.Dispose();
            }
        }
Пример #8
0
        private void CreateMixerWave()
        {
            osc1 = new SignalGenerator();
            switch (osc1Menu.SelectedIndex)
            {
                case 0:
                    osc1.Type = SignalGeneratorType.Sin;
                    break;
                case 1:
                    osc1.Type = SignalGeneratorType.Square;
                    break;
                case 2:
                    osc1.Type = SignalGeneratorType.Triangle;
                    break;
                case 3:
                    osc1.Type = SignalGeneratorType.SawTooth;
                    break;
                default:
                    break;
            }

            osc2 = new SignalGenerator();
            switch (osc2Menu.SelectedIndex)
            {
                case 0:
                    osc2.Type = SignalGeneratorType.Sin;
                    break;
                case 1:
                    osc2.Type = SignalGeneratorType.Square;
                    break;
                case 2:
                    osc2.Type = SignalGeneratorType.Triangle;
                    break;
                case 3:
                    osc2.Type = SignalGeneratorType.SawTooth;
                    break;
                default:
                    break;
            }
            osc3 = new SignalGenerator();
            switch (osc3Menu.SelectedIndex)
            {
                case 0:
                    osc3.Type = SignalGeneratorType.Sin;
                    break;
                case 1:
                    osc3.Type = SignalGeneratorType.Square;
                    break;
                case 2:
                    osc3.Type = SignalGeneratorType.Triangle;
                    break;
                case 3:
                    osc3.Type = SignalGeneratorType.SawTooth;
                    break;
                default:
                    break;
            }
        }
		public NaudioSignalGeneratorNode()
		{
			FSigGen = new SignalGenerator();
			FSigGen.Type = SignalGeneratorType.Square;
		}