Ejemplo n.º 1
0
        //Used to play out what is recording
        private void button2_Click(object sender, EventArgs e)
        {
            sourcestream.DeviceNumber = 0;
            int deviceNumber = SourceList.SelectedItems[0].Index;

            sourcestream            = new NAudio.Wave.WaveIn();
            sourcestream.WaveFormat = new NAudio.Wave.WaveFormat(44100, NAudio.Wave.WaveIn.GetCapabilities(0).Channels);
            NAudio.Wave.WaveInProvider waveIn = new NAudio.Wave.WaveInProvider(sourcestream);
            wavout = new NAudio.Wave.DirectSoundOut();
            wavout.Init(waveIn);
            sourcestream.StartRecording();
            wavout.Play();
        }
Ejemplo n.º 2
0
        public void RecordAndPlay()
        {
            m_oSourceStream = new NAudio.Wave.WaveIn();
            m_oSourceStream.DeviceNumber = m_iDeviceNumber;
            m_oSourceStream.WaveFormat   = new NAudio.Wave.WaveFormat(44100, NAudio.Wave.WaveIn.GetCapabilities(m_iDeviceNumber).Channels);

            NAudio.Wave.WaveInProvider oWaveIn = new NAudio.Wave.WaveInProvider(m_oSourceStream);

            m_oWaveOut = new NAudio.Wave.DirectSoundOut();
            m_oWaveOut.Init(oWaveIn);

            m_oSourceStream.StartRecording();
            m_oWaveOut.Play();
        }
        private void okBtn_Click(object sender, EventArgs e)
        {
            if (inputDeviceList.SelectedItems.Count == 0)
            {
                return;                                           //if 0, exit method
            }
            // if (sourceStream != null) return;

            int deviceNumber = inputDeviceList.SelectedItems[0].Index; //gets index of selected item

            sStream = new NAudio.Wave.WaveIn();                        //source stream constructer
            sStream.DeviceNumber = deviceNumber;                       //sets device number
            sStream.WaveFormat   = new NAudio.Wave.WaveFormat(44100, NAudio.Wave.WaveIn.GetCapabilities(deviceNumber).Channels);
            // assigns a standard wave format and retreives capabilities and number of channels of chosen device

            NAudio.Wave.WaveInProvider waveIn = new NAudio.Wave.WaveInProvider(sStream); //bridges gap between wavein object and directsoundout

            wOut = new NAudio.Wave.DirectSoundOut();                                     //creates wave output device
            wOut.Init(waveIn);                                                           //initialises waveout using wavein
        }
Ejemplo n.º 4
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (sourceList.SelectedItems.Count == 0)
            {
                return;
            }

            int deviceNumber = sourceList.SelectedItems[0].Index;

            sourceStream = new NAudio.Wave.WaveIn();
            sourceStream.DeviceNumber = deviceNumber;
            sourceStream.WaveFormat   = new NAudio.Wave.WaveFormat(8000, NAudio.Wave.WaveIn.GetCapabilities(deviceNumber).Channels);

            NAudio.Wave.WaveInProvider waveIn = new NAudio.Wave.WaveInProvider(sourceStream);

            waveOut = new NAudio.Wave.DirectSoundOut(a);
            waveOut.Init(waveIn);

            sourceStream.StartRecording();
            waveOut.Play();
        }
Ejemplo n.º 5
0
        public bool StartREcording()
        {
            if (microphoneIndex < 0)
            {
                return(false);
            }


            sourceStream = new NAudio.Wave.WaveIn();
            sourceStream.DeviceNumber = microphoneIndex;
            sourceStream.WaveFormat   = new NAudio.Wave.WaveFormat(44000, NAudio.Wave.WaveIn.GetCapabilities(microphoneIndex).Channels);
            NAudio.Wave.WaveInProvider waveIn = new NAudio.Wave.WaveInProvider(sourceStream);

            waveOut = new NAudio.Wave.DirectSoundOut();
            waveOut.Init(waveIn);

            sourceStream.StartRecording();
            waveOut.Play();

            return(true);
        }
Ejemplo n.º 6
0
        public void upgrate(int d)
        {
            if (sourceList.SelectedItems.Count == 0)
            {
                return;
            }

            int deviceNumber = sourceList.SelectedItems[0].Index;

            sourceStream = new NAudio.Wave.WaveIn();
            sourceStream.DeviceNumber = deviceNumber;
            sourceStream.WaveFormat   = new NAudio.Wave.WaveFormat(8000, NAudio.Wave.WaveIn.GetCapabilities(deviceNumber).Channels);

            NAudio.Wave.WaveInProvider waveIn = new NAudio.Wave.WaveInProvider(sourceStream);



            waveOut = new NAudio.Wave.DirectSoundOut(a);
            waveOut.Init(waveIn);

            sourceStream.StartRecording();
            waveOut.Play(); waveOut.Volume = 100.0F;
        }
        //The record button can be used to stop/start recording
        private void recordButton_Click(object sender, EventArgs e)
        {
            //if its already recording, it will stop recording
            if (isRecording == true) 
            {
                DisposeWave();
                stopRecording();
            }
            else if (isRecording == false) //it will start recording if not recording already
            {
                //sets up the sourcestream, ready for recording
                sourceStream = new NAudio.Wave.WaveIn();    
                sourceStream.DeviceNumber = setting.deviceNumber;
                sourceStream.WaveFormat = setting.format;

                //requests where to save files BEFORE recording has started.
                //i contemplated requesting filepath/name after recording but it was of low priority.
                SaveFileDialog save = new SaveFileDialog();
                save.Filter = "Wave File (*.wav)|*.wav;";
                if (save.ShowDialog() != System.Windows.Forms.DialogResult.OK) return;
                filePathLbl.Text = save.FileName;

                //creates a wavefilewriter to write the sourcestream data in to the savefile
                waveWriter = new NAudio.Wave.WaveFileWriter(save.FileName, sourceStream.WaveFormat);
                NAudio.Wave.WaveInProvider waveIn = new NAudio.Wave.WaveInProvider(sourceStream); //bridges gap between wavein object and directsoundout

                waveOut = new NAudio.Wave.DirectSoundOut(); //creates wave output device
                waveOut.Init(waveIn); //sets the waveout device up to receive sourcestream data

                sourceStream.DataAvailable += new EventHandler<NAudio.Wave.WaveInEventArgs>(SourceStream_DataAvailuable); //creates an event handler to deal with data as it is received in to the sourcestream

                sourceStream.StartRecording(); //instructs source to start retreiving samples from audio device
                isRecording = true; //impacts the effects next time the record button is pressed
                waveOut.Play(); //begins playback from buffer
            }
        }
Ejemplo n.º 8
0
        private void StartRecording()
        {
            // Check if there are sources for input sound
            int numResource = NAudio.Wave.WaveIn.DeviceCount;
            if (numResource == 0) return;

            // Use the first source as default
            sourceStream = new NAudio.Wave.WaveIn();
            // Set wave format
            sourceStream.WaveFormat = new NAudio.Wave.WaveFormat(16000, 16, 1);

            NAudio.Wave.WaveInProvider waveIn = new NAudio.Wave.WaveInProvider(sourceStream);

            //waveOut = new NAudio.Wave.DirectSoundOut();
            //waveOut.Init(waveIn);

            sourceStream.StartRecording();
            //waveOut.Play(); // plays the audio, serve as demo, can be deleted

            sourceStream.DataAvailable += new EventHandler<NAudio.Wave.WaveInEventArgs>(sourceStream_DataAvailable);
            // Save the file temporarily in the audio folder, note that previous recording will be overwritten
            waveWriter = new NAudio.Wave.WaveFileWriter("audio/temp.wav", sourceStream.WaveFormat);
        }
Ejemplo n.º 9
0
        private void buttonRecStart_Click(object sender, EventArgs e)
        {
            if (listViewSources.SelectedItems.Count == 0)
            {
                Console.WriteLine("No device selected.");
                return;
            }

            int deviceNumber = listViewSources.SelectedItems[0].Index;
            labelRecDevice.Text = deviceNumber.ToString();

            sourceStream = new NAudio.Wave.WaveIn();
            sourceStream.DeviceNumber = deviceNumber;
            sourceStream.WaveFormat = new NAudio.Wave.WaveFormat(44100, NAudio.Wave.WaveIn.GetCapabilities(deviceNumber).Channels);
            sourceStream.DataAvailable += new EventHandler<NAudio.Wave.WaveInEventArgs>(waveIn_DataAvailable);
            sourceStream.StartRecording();

            if (checkBoxPlayback.Checked)
            {
                NAudio.Wave.WaveInProvider waveIn = new NAudio.Wave.WaveInProvider(sourceStream);
                waveOut = new NAudio.Wave.DirectSoundOut(NAudio.Wave.WaveOut.GetCapabilities(outputDevice).ProductGuid);
                waveOut.Init(waveIn);
                waveOut.Play();
            }
            else
            {
                NAudio.Wave.WaveIn waveIn = new NAudio.Wave.WaveIn();
            }

            pictureBoxRecording.BackColor = Color.Red;
        }