Exemplo n.º 1
0
        public void Render(IAudioRecording audioRecording, Canvas audioCanvas)
        {
            using (var audioFileReader = new AudioFileReader(audioRecording.Filename))
            {
                var canvasWidth = audioCanvas.ActualWidth;

                var waveFormat   = audioFileReader.WaveFormat;
                var totalSamples = audioFileReader.Length / (waveFormat.Channels * waveFormat.BitsPerSample / 8);

                var bytesPerBatch = (int)Math.Max(40, totalSamples / canvasWidth);
                var mid           = 100;
                var yScale        = 100;

                float[] byteBuffer = new float[bytesPerBatch];
                var     xPos       = 0;

                bool hasBytesRemaining = true;
                while (hasBytesRemaining)
                {
                    var actualBytesRead = audioFileReader.Read(byteBuffer, 0, bytesPerBatch);
                    hasBytesRemaining = actualBytesRead == bytesPerBatch;

                    float maxValue = FindMaxValue(byteBuffer);
                    DrawVerticalLine(audioCanvas, xPos, maxValue);
                    xPos++;
                }
            }
        }
Exemplo n.º 2
0
        public void Play(IAudioRecording audio)
        {
            if (currentlyPlayingConceptId == audio.ConceptId)
            {
                return;
            }
            currentlyPlayingConceptId = audio.ConceptId;

            /* Handle the case where a new audio file gets queued over the current one. */
            if (audioDisposable != null)
            {
                audioDisposable.Dispose();
                audioDisposable = null;
            }

            var outputDevice = new WaveOutEvent();
            var audioFile    = new AudioFileReader($@"{audio.ConceptId.ToString()}.wav");

            outputDevice.PlaybackStopped += OnPlaybackStopped;
            outputDevice.Init(audioFile);
            outputDevice.Play();

            audioDisposable = new CompositeDisposable()
            {
                // TODO: Is it valid to assume here that we can dispose of the
                // output device immediately after telling the device to stop?
                Disposable.Create(outputDevice.Stop),
                outputDevice,
                audioFile
            };
        }
Exemplo n.º 3
0
 public NAudioRecorder(WaveIn waveInput, IAudioRecording audioRecording)
 {
     _waveInput     = waveInput;
     AudioRecording = audioRecording;
 }
Exemplo n.º 4
0
 public void Add(IAudioRecording recording)
 {
 }