Debian Codegraph @

src/samplebuffer.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2015, Mike Walters <[email protected]>
3 *
4 * This file is part of inspectrum.
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include <QMutexLocker>
21 #include <string.h>
22 #include "samplebuffer.h"
23
24 template <typename Tin, typename Tout>
25 SampleBuffer<Tin, Tout>::SampleBuffer(std::shared_ptr<SampleSource<Tin>> src) : src(src)
26 {
27 src->subscribe(this);
28 }
29
30 template <typename Tin, typename Tout>
31 SampleBuffer<Tin, Tout>::~SampleBuffer()
32 {
33 src->unsubscribe(this);
34 }
35
36 template <typename Tin, typename Tout>
37 std::unique_ptr<Tout[]> SampleBuffer<Tin, Tout>::getSamples(size_t start, size_t length)
38 {
39 // TODO: base this on the actual history required
40 auto history = std::min(start, (size_t)256);
41 auto samples = src->getSamples(start - history, length + history);
42 if (samples == nullptr)
43 return nullptr;
44
45 auto temp = std::make_unique<Tout[]>(history + length);
46 auto dest = std::make_unique<Tout[]>(length);
47 QMutexLocker ml(&mutex);
48 work(samples.get(), temp.get(), history + length, start);
49 memcpy(dest.get(), temp.get() + history, length * sizeof(Tout));
50 return dest;
51 }
52
53 template <typename Tin, typename Tout>
54 void SampleBuffer<Tin, Tout>::invalidateEvent()
55 {
56 SampleSource<Tout>::invalidate();
57 }
58
59 template class SampleBuffer<std::complex<float>, std::complex<float>>;
60 template class SampleBuffer<std::complex<float>, float>;
61 template class SampleBuffer<float, float>;