コード例 #1
3
		public AudioStreamHandler()
		{
		    log = Logger.GetLogger(GetType());
            WaveIn = new WasapiLoopbackCapture();
			WaveIn.DataAvailable += DataAvailable;
		    WaveIn.RecordingStopped += RecordingStopped;
            WaveOut = new WaveOut();
		    WaveOut.Init(new SilentWaveProvider());
		}
コード例 #2
2
ファイル: Audio_Capture.cs プロジェクト: Dryabadi/WebMCam
		public void Start(string path)
		{
			Source = new WasapiLoopbackCapture();

			Source.DataAvailable += new EventHandler<WaveInEventArgs>(waveSource_DataAvailable);
			Source.RecordingStopped += new EventHandler<StoppedEventArgs>(waveSource_RecordingStopped);

			File = new WaveFileWriter(path, Source.WaveFormat);

			Source.StartRecording();
			Recording = true;
		}
コード例 #3
0
        public MemoryStream GetMp3Sample(int seconds, string filepath = "")
        {
            try
            {
                var stream = new MemoryStream();
                // Start recording from loopback
                IWaveIn waveIn = new WasapiLoopbackCapture();
                waveIn.DataAvailable += waveIn_DataAvailable;
                waveIn.RecordingStopped += waveIn_RecordingStopped;
                // Setup MP3 writer to output at 96kbit/sec
                writer = new LameMP3FileWriter(stream, waveIn.WaveFormat, LAMEPreset.ABR_96);
                _isRecording = true;
                waveIn.StartRecording();

                // Wait for X seconds
                System.Threading.Thread.Sleep(seconds * 1000);
                waveIn.StopRecording();

                // flush output to finish MP3 file correctly
                writer.Flush();
                // Dispose of objects
                waveIn.Dispose();
                writer.Dispose();

                if (filepath != "")
                    using (var file = new FileStream(filepath, FileMode.Create, FileAccess.Write))
                        stream.WriteTo(file);

                return stream;
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #4
0
 public static void Start(TrackDto track)
 {
     lock (Lock)
     {
         currentTrack = track;
         waveIn = new WasapiLoopbackCapture();
         lameMp3FileWriter = new LameMP3FileWriter(GetFileName(), waveIn.WaveFormat, 256);
         recordingStopped = new ManualResetEvent(false);
         waveIn.DataAvailable += LoopbackDataAvailable;
         waveIn.RecordingStopped += LoopbackRecordingStopped;
         waveIn.StartRecording();
     }
 }
コード例 #5
0
ファイル: Audio_Capture.cs プロジェクト: Dryabadi/WebMCam
		void waveSource_RecordingStopped(object sender, StoppedEventArgs e)
		{
			if (Source != null)
			{
				Source.Dispose();
				Source = null;
			}

			if (File != null)
			{
				File.Dispose();
				File = null;
			}
		}
コード例 #6
0
ファイル: WasapiProvider.cs プロジェクト: Scannow/SWYH
        public WasapiProvider()
        {
            // Init Pipes
            this.recordingStream = new PipeStream();
            this.LoopbackMp3Stream = new PipeStream();
            this.LoopbackL16Stream = new PipeStream();

            // Init Wave Processor thread
            Thread waveProcessorThread = new Thread(new ThreadStart(this.waveProcessor)) { Priority = ThreadPriority.Highest };

            // Init Wasapi Capture
            this.loopbackWaveIn = new WasapiLoopbackCapture();
            this.loopbackWaveIn.DataAvailable += new EventHandler<WaveInEventArgs>(this.loopbackWaveIn_DataAvailable);
            
            // Init Raw Wav (16bit)
            WaveStream rawWave16b = new Wave32To16Stream(new RawSourceWaveStream(this.recordingStream, NAudio.Wave.WaveFormat.CreateIeeeFloatWaveFormat(this.loopbackWaveIn.WaveFormat.SampleRate, this.loopbackWaveIn.WaveFormat.Channels)));

            // Convert Raw Wav to PCM with audio format in settings
            var audioFormat = AudioSettings.GetAudioFormat();
            if (rawWave16b.WaveFormat.SampleRate == audioFormat.SampleRate
                && rawWave16b.WaveFormat.BitsPerSample == audioFormat.BitsPerSample
                && rawWave16b.WaveFormat.Channels == audioFormat.Channels)
            {
                // No conversion !
                this.rawConvertedStream = null;
                this.pcmStream = WaveFormatConversionStream.CreatePcmStream(rawWave16b);
            }
            else
            {
                // Resampler
                this.rawConvertedStream = new WaveProviderToWaveStream(new MediaFoundationResampler(rawWave16b, audioFormat));
                this.pcmStream = WaveFormatConversionStream.CreatePcmStream(rawConvertedStream);
            }

            // Init MP3 Encoder
            this.mp3Writer = new LameMP3FileWriter(this.LoopbackMp3Stream, pcmStream.WaveFormat, AudioSettings.GetMP3Bitrate());

            // Start Recording
            this.loopbackWaveIn.StartRecording();

            // Start Wave Processor thread
            waveProcessorThread.Start();
        }
コード例 #7
0
ファイル: Main_Form.cs プロジェクト: alexmelk/audioPlayer
        ///////////////////////////////////////////////////////////////////////////События формы
        /// <summary>
        /// Cобытие после загрузки формы
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Main_Form_Load(object sender, EventArgs e)
        {
            Eq = new EQ();
            Eq.Show();
            Eq.Visible = false;

            btStart     = btPlay;
            PlayListBox = listBox1;
            NameTrack   = tbName;
            Author      = tbAuthor;
            Date        = tbDate;
            Time        = tbTime;

            timer1.Start();
            timer2.Start();
            timer3.Start();

            loadChanges();

            Capt = new WasapiLoopbackCapture();
            Capt.DataAvailable += OnDataAvailable;
            Capt.StartRecording();
        }
コード例 #8
0
        public void button1_Click(object sender, EventArgs e)
        {
            Console.WriteLine("starting:");
            Console.WriteLine("");

            serialPort1.PortName  = textBox1.Text;
            serialPort1.BaudRate  = 115200;
            serialPort1.RtsEnable = true;
            serialPort1.DtrEnable = true;
            if (serialPort1.IsOpen)
            {
                try
                {
                    serialPort1.Close();
                }
                catch
                {
                }
            }
            try
            {
                serialPort1.Open();
            }
            catch
            {
                MessageBox.Show("Не удалось подключиться!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            capt = new WasapiLoopbackCapture();
            capt.DataAvailable += OnDataAvailable;
            capt.StartRecording();
            serialPort1.DataReceived += OnDataReceived;

            if (serialPort1.IsOpen)
            {
                MessageBox.Show("Успешно подключено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
コード例 #9
0
ファイル: WasapiLoopbackCapture.cs プロジェクト: h4ltYu/EOS
 /// <summary>
 /// Initialises a new instance of the WASAPI capture class
 /// </summary>
 // Token: 0x060007EA RID: 2026 RVA: 0x00017272 File Offset: 0x00015472
 public WasapiLoopbackCapture() : this(WasapiLoopbackCapture.GetDefaultLoopbackCaptureDevice())
 {
 }
コード例 #10
0
 private void Init()
 {
     _capture = new WasapiLoopbackCapture();
     _capture.DataAvailable += _capture_DataAvailable;
     _capture.RecordingStopped += _capture_RecordingStopped;
 }
コード例 #11
0
ファイル: Recorder.cs プロジェクト: Nhowka/WebMCam
    /// <summary>
    /// Stop Recording
    /// </summary>
    /// <returns>Successful</returns>
    public bool Stop()
    {
        if (!isRecording)
            return false;

        // Stop Capturing Audio
        if (recordAudio)
        {
            audioSource.StopRecording();

            if (audioSource != null)
            {
                audioSource.Dispose();
                audioSource = null;
            }

            if (audioFile != null)
            {
                audioFile.Dispose();
                audioFile = null;
            }
        }

        // Kill Timers
        StopTimers();

        status = "Idle";
        isRecording = false;
        return isRecording;
    }
コード例 #12
0
ファイル: Recorder.cs プロジェクト: Nhowka/WebMCam
    /// <summary>
    /// Start Recording
    /// </summary>
    /// <param name="recordAudio">Record Audio</param>
    /// <returns>Successful</returns>
    public bool Start(bool recordAudio = false)
    {
        if (isRecording)
            return false;

        // Reset
        status = "Pending";
        frames = 0;

        // Create Temporary Directory
        CreateTemporaryPath();

        // Setup Audio Recording
        if (recordAudio)
        {
            this.recordAudio = recordAudio;
            audioSource = new WasapiLoopbackCapture();
            audioSource.DataAvailable += new EventHandler<WaveInEventArgs>(WriteAudio);
            audioFile = new WaveFileWriter(Path.Combine(tempPath, "audio.wav"), audioSource.WaveFormat);

            audioSource.StartRecording();
        }

        // Start Timers
        StartTimers();

        status = "Recording";
        isRecording = true;
        return isRecording;
    }
コード例 #13
0
 /// <summary>
 ///     Set Parameters to WasapiLoopCapture
 /// </summary>
 private void InitializeWasapiLoopCapture()
 {
     _wasapiLoopback = new WasapiLoopbackCapture();
     _wasapiLoopback.DataAvailable += WasapiLoopbackOnDataAvailable;
 }
コード例 #14
0
ファイル: Recorder.cs プロジェクト: stefan-j/MPC-Streamer
 public Recorder()
 {
     waveIn = new WasapiLoopbackCapture();
     waveIn.DataAvailable += InputBufferToFileCallback;
 }