void OnData(object sender, DataAvailableEventArgs e)
        {
            _tracker.OnData(e.Format.BytesToMilliseconds(e.ByteCount));
            var startStep = _tracker.CurrentTimeAtBeginningOfLastRecordedSample;
            var stepTime = 1 * 1000 * 10000 / e.Format.SampleRate / e.Format.Channels;
            long tick = (long)startStep;

            var target = new float[e.ByteCount / 4];
            System.Buffer.BlockCopy(e.Data, 0, target, 0, e.ByteCount);
            int i = 0;
            foreach (var ee in target)
            {
                i++;
                tick += stepTime;
                if (ee == 1.0f && i % 2 == 0) {
                    _audioTicks.Add(tick);
                    if (firstStart) {
                        Console.WriteLine($"Start in... {5 - _audioTicks.Count}");
                    }
                    if (firstStart && _audioTicks.Count == 5) {
                        _audioTicks.Clear();
                        firstStart = false;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        void OnData(object sender, DataAvailableEventArgs e)
        {
            _tracker.OnData(e.Format.BytesToMilliseconds(e.ByteCount));

            if (_writer != null) {
                if (_recordStartTime == 0) {
                    _recordStartTime = _tracker.CurrentTimeAtBeginningOfLastRecordedSample;
                }
                lock (_writer) _writer.Write(e.Data, 0, e.ByteCount);
            }
        }
Ejemplo n.º 3
0
 private void RaiseDataAvilable(byte[] buffer, int offset, int count)
 {
     if (count <= 0)
     {
         return;
     }
     if (DataAvailable != null)
     {
         var e = new DataAvailableEventArgs(buffer, offset, count, WaveFormat);
         if (_synchronizationContext != null)
         {
             _synchronizationContext.Post(o => DataAvailable(this, e), null); //use post instead of send to avoid deadlocks
         }
         else
         {
             DataAvailable(this, e);
         }
     }
 }
Ejemplo n.º 4
0
 private void OnNewData(object sender, DataAvailableEventArgs e)
 {
     int read = 0;
     while ((read = _source.Read(_writerBuffer, 0, _writerBuffer.Length)) > 0)
     {
         _writer.Write(_writerBuffer, 0, read);
     }
 }
Ejemplo n.º 5
0
 private void OnDataAvailable(object sender, DataAvailableEventArgs e)
 {
     int written = _buffer.Write(e.Data, 0, e.ByteCount);
     if (e.ByteCount > 0 && DataAvailable != null)
         DataAvailable(this, e);
 }
Ejemplo n.º 6
0
 private void OnDataAvailable(object sender, DataAvailableEventArgs e)
 {
     _buffer.Write(e.Data, 0, e.ByteCount);
     EventHandler<DataAvailableEventArgs> dataAvailable = this.DataAvailable;
     if (e.ByteCount > 0 && dataAvailable != null)
         dataAvailable(this, e);
 }
Ejemplo n.º 7
0
 private void RaiseDataAvailable(byte[] buffer, int offset, int count)
 {
     if (count <= 0)
         return;
     if (DataAvailable != null)
     {
         var e = new DataAvailableEventArgs(buffer, offset, count, WaveFormat);
         if (_synchronizationContext != null)
             _synchronizationContext.Post(o => DataAvailable(this, e), null); //use post instead of send to avoid deadlocks
         else
             DataAvailable(this, e);
     }
 }