samplebuffer: Make the history stuff actually work

This commit is contained in:
Mike Walters
2016-04-28 01:18:11 +01:00
parent 20c90635d3
commit 62b75728cc

View File

@@ -18,6 +18,7 @@
*/
#include <QMutexLocker>
#include <string.h>
#include "samplebuffer.h"
template <typename Tin, typename Tout>
@@ -35,14 +36,17 @@ SampleBuffer<Tin, Tout>::~SampleBuffer()
template <typename Tin, typename Tout>
std::unique_ptr<Tout[]> SampleBuffer<Tin, Tout>::getSamples(off_t start, off_t length)
{
auto margin = std::min(start, 128L);
auto samples = src->getSamples(start - margin, length + margin);
// TODO: base this on the actual history required
auto history = std::min(start, 256L);
auto samples = src->getSamples(start - history, length + history);
if (samples == nullptr)
return nullptr;
std::unique_ptr<Tout[]> temp(new Tout[history + length]);
std::unique_ptr<Tout[]> dest(new Tout[length]);
QMutexLocker ml(&mutex);
work(samples.get() + margin, dest.get(), length, start);
work(samples.get(), temp.get(), history + length, start);
memcpy(dest.get(), temp.get() + history, length * sizeof(Tout));
return dest;
}