From dc05437e4fa5a62b83f259f1856615901b5cf0c4 Mon Sep 17 00:00:00 2001 From: Jonathan Thomas Date: Thu, 13 Feb 2014 03:16:18 -0600 Subject: [PATCH] Added estimated_frame to AudioSourceReader... which estimates what frame is being currently played. --- include/AudioReaderSource.h | 2 ++ src/AudioReaderSource.cpp | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/AudioReaderSource.h b/include/AudioReaderSource.h index bfacb3d0..9b69f7ed 100644 --- a/include/AudioReaderSource.h +++ b/include/AudioReaderSource.h @@ -64,6 +64,8 @@ namespace openshot int64 frame_number; /// The current frame number tr1::shared_ptr frame; /// The current frame object that is being read int frame_position; /// The position of the current frame's buffer + double estimated_frame; /// The estimated frame position of the currently playing buffer + int estimated_samples_per_frame; /// The estimated samples per frame of video /// Get more samples from the reader void GetMoreSamplesFromReader(); diff --git a/src/AudioReaderSource.cpp b/src/AudioReaderSource.cpp index d141ec70..0569bf33 100644 --- a/src/AudioReaderSource.cpp +++ b/src/AudioReaderSource.cpp @@ -33,7 +33,7 @@ using namespace openshot; // Constructor that reads samples from a reader AudioReaderSource::AudioReaderSource(ReaderBase *audio_reader, int64 starting_frame_number, int buffer_size) : reader(audio_reader), frame_number(starting_frame_number), original_frame_number(starting_frame_number), - size(buffer_size), position(0), frame_position(0) { + size(buffer_size), position(0), frame_position(0), estimated_frame(0) { // Initialize an audio buffer (based on reader) buffer = new juce::AudioSampleBuffer(reader->info.channels, size); @@ -62,6 +62,9 @@ void AudioReaderSource::GetMoreSamplesFromReader() { amount_remaining = 0; } + // Init estimated buffer equal to the current frame position (before getting more samples) + estimated_frame = frame_number; + // Init new buffer juce::AudioSampleBuffer *new_buffer = new juce::AudioSampleBuffer(reader->info.channels, size); new_buffer->clear(); @@ -177,6 +180,9 @@ void AudioReaderSource::getNextAudioBlock (const AudioSourceChannelInfo& info) position += number_to_copy; } + // Adjust estimate frame number (the estimated frame number that is being played) + estimated_samples_per_frame = Frame::GetSamplesPerFrame(estimated_frame, reader->info.fps, reader->info.sample_rate); + estimated_frame += double(info.numSamples) / double(estimated_samples_per_frame); } }