Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Unified Diff: media/base/audio_fifo.cc

Issue 10918098: Introduce AudioOutputResampler for browser side resampling. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: First draft! Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: media/base/audio_fifo.cc
diff --git a/media/base/audio_fifo.cc b/media/base/audio_fifo.cc
index 87a5d823c41b2c11aef41ae376bf5709fc3febbd..ded104426bb62199064e698fcbfbcdce7190c11c 100644
--- a/media/base/audio_fifo.cc
+++ b/media/base/audio_fifo.cc
@@ -35,12 +35,12 @@ AudioFifo::AudioFifo(int channels, int frames)
AudioFifo::~AudioFifo() {}
-bool AudioFifo::Push(const AudioBus* source) {
+bool AudioFifo::Push(const AudioBus* source, int frames) {
DCHECK(source);
DCHECK_EQ(source->channels(), audio_bus_->channels());
// Ensure that there is space for the new data in the FIFO.
- const int source_size = source->frames();
+ const int source_size = frames;
if (frames_in_fifo_ + source_size > max_frames()) {
DLOG(ERROR) << "FIFO overflow.";
return false;
@@ -71,7 +71,8 @@ bool AudioFifo::Push(const AudioBus* source) {
return true;
}
-bool AudioFifo::Consume(AudioBus* destination, int frames_to_consume) {
+bool AudioFifo::Consume(AudioBus* destination, int start_frame,
+ int frames_to_consume) {
DCHECK(destination);
DCHECK_EQ(destination->channels(), audio_bus_->channels());
@@ -83,8 +84,8 @@ bool AudioFifo::Consume(AudioBus* destination, int frames_to_consume) {
// A copy from the FIFO to |destination| will only be performed if the
// allocated memory in |destination| is sufficient.
- if (frames_to_consume > destination->frames()) {
- DLOG(ERROR) << "Insufficient space in destination.";
+ if (frames_to_consume + start_frame > destination->frames()) {
+ LOG(ERROR) << "Insufficient space in destination.";
return false;
}
@@ -102,10 +103,11 @@ bool AudioFifo::Consume(AudioBus* destination, int frames_to_consume) {
const float* src = audio_bus_->channel(ch);
// Copy a selected part of the FIFO to the destination.
- memcpy(&dest[0], &src[read_pos_], consume_size * sizeof(src[0]));
+ memcpy(&dest[start_frame], &src[read_pos_], consume_size * sizeof(src[0]));
if (wrap_size > 0) {
// Wrapping is needed: copy remaining part to the destination.
- memcpy(&dest[consume_size], &src[0], wrap_size * sizeof(src[0]));
+ memcpy(&dest[consume_size + start_frame], &src[0],
+ wrap_size * sizeof(src[0]));
}
}

Powered by Google App Engine
This is Rietveld 408576698