1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-18 20:34:39 +01:00

Synchronize buffer chunks with audio stream

The chunks are now determined by the density of data in the buffer
to the length of audio in the buffer. The chunk length can change
size so that the audio that is analysed is exactly what is being played
at the instant the frame is requested.
This commit is contained in:
Mark Furneaux 2014-04-30 14:18:39 -04:00
parent ee7fed36bc
commit 6c653e5ba2

View File

@ -244,7 +244,6 @@ void GstEngine::AddBufferToScope(GstBuffer* buf, int pipeline_id) {
}
const Engine::Scope& GstEngine::scope(int chunk_length) {
// the new buffer could have a different size
if (have_new_buffer) {
if (latest_buffer_ != nullptr) {
@ -267,7 +266,11 @@ const Engine::Scope& GstEngine::scope(int chunk_length) {
void GstEngine::UpdateScope(int chunk_length_) {
typedef Engine::Scope::value_type sample_type;
int chunk_size = GST_BUFFER_SIZE(latest_buffer_) / (scope_chunks);
// determine where to split the buffer
int chunk_density = GST_BUFFER_SIZE(latest_buffer_) /
(GST_BUFFER_DURATION(latest_buffer_) / 1000000);
int chunk_size = chunk_length_ * chunk_density;
// determine the number of channels
GstStructure* structure =
@ -284,15 +287,24 @@ void GstEngine::UpdateScope(int chunk_length_) {
return;
}
// pass the next chunk of the buffer to the analyser
// set the starting point in the buffer to take data from
const sample_type* source =
reinterpret_cast<sample_type*>(GST_BUFFER_DATA(latest_buffer_));
source += (chunk_size / sizeof(sample_type)) * scope_chunk;
sample_type* dest = scope_.data();
const int bytes = qMin(
int bytes;
// make sure we don't go beyond the end of the buffer
if (scope_chunk == scope_chunks - 1) {
bytes = qMin(
static_cast<Engine::Scope::size_type>(GST_BUFFER_SIZE(latest_buffer_) - (chunk_size * scope_chunk)),
scope_.size() * sizeof(sample_type));
} else {
bytes = qMin(
static_cast<Engine::Scope::size_type>(chunk_size),
scope_.size() * sizeof(sample_type));
}
scope_chunk++;