// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef SERVICES_AUDIO_DELAY_BUFFER_H_ #define SERVICES_AUDIO_DELAY_BUFFER_H_ #include <memory> #include "base/containers/circular_deque.h" namespace media { class AudioBus; } // namespace media namespace audio { // Records and maintains a recent history of an audio signal, then allows // read-back starting from part of the recording. While this looks a lot like a // FIFO, it is not because Read() will typically not be reading from one end of // a queue. // // The audio format is the same throughout all operations, as this DelayBuffer // does not resample or remix the audio. Also, for absolute precision, it uses // frame counts to track the timing of the audio recorded and read. // // The typical use case is the loopback audio system: In this scenario, the // service has an audio output stream running for local playback, and the // stream's audio is timed to play back in the near future (usually, 1 ms to 20 // ms, depending on the platform). When loopback is active, that audio will be // copied into this DelayBuffer via calls to Write(). Then, the loopback audio // stream implementation will Read() the audio at a time in the recent past // (approximately 20 ms before "now," but this will vary slightly). Because of // clock drift concerns, the loopback implementation will slightly compress/ // stretch the audio signal it pulls out of this buffer, to maintain // synchronization, and this will cause it to vary the number of frames read for // each successive Read() call. class DelayBuffer { … }; } // namespace audio #endif // SERVICES_AUDIO_DELAY_BUFFER_H_