mirror of
https://github.com/miek/inspectrum.git
synced 2026-03-07 00:37:05 +01:00
samplebuffer: Make the history stuff actually work
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user