Fixed some stuff

This commit is contained in:
Ryzerth
2021-02-20 15:27:43 +01:00
parent d0bea51cd4
commit 89d0f6b761
15 changed files with 731 additions and 64 deletions

View File

@@ -10,14 +10,14 @@ namespace dsp {
Add(stream<T>* a, stream<T>* b) { init(a, b); }
~Add() { generic_block<Add>::stop(); }
~Add() { generic_block<Add<T>>::stop(); }
void init(stream<T>* a, stream<T>* b) {
_a = a;
_b = b;
generic_block<Add>::registerInput(a);
generic_block<Add>::registerInput(b);
generic_block<Add>::registerOutput(&out);
generic_block<Add<T>>::registerInput(a);
generic_block<Add<T>>::registerInput(b);
generic_block<Add<T>>::registerOutput(&out);
}
int run() {
@@ -32,7 +32,57 @@ namespace dsp {
}
if constexpr (std::is_same_v<T, complex_t> || std::is_same_v<T, stereo_t>) {
volk_32fc_x2_add_32fc(out.writeBuf, _a->readBuf, _b->readBuf, a_count);
volk_32fc_x2_add_32fc((lv_32fc_t*)out.writeBuf, (lv_32fc_t*)_a->readBuf, (lv_32fc_t*)_b->readBuf, a_count);
}
else {
volk_32f_x2_add_32f(out.writeBuf, _a->readBuf, _b->readBuf, a_count);
}
_a->flush();
_b->flush();
if (!out.swap(a_count)) { return -1; }
return a_count;
}
stream<T> out;
private:
int a_count, b_count;
stream<T>* _a;
stream<T>* _b;
};
template <class T>
class Substract : public generic_block<Substract<T>> {
public:
Substract() {}
Substract(stream<T>* a, stream<T>* b) { init(a, b); }
~Substract() { generic_block<Substract<T>>::stop(); }
void init(stream<T>* a, stream<T>* b) {
_a = a;
_b = b;
generic_block<Substract<T>>::registerInput(a);
generic_block<Substract<T>>::registerInput(b);
generic_block<Substract<T>>::registerOutput(&out);
}
int run() {
a_count = _a->read();
if (a_count < 0) { return -1; }
b_count = _b->read();
if (b_count < 0) { return -1; }
if (a_count != b_count) {
_a->flush();
_b->flush();
return 0;
}
if constexpr (std::is_same_v<T, complex_t> || std::is_same_v<T, stereo_t>) {
volk_32f_x2_subtract_32f((float*)out.writeBuf, (float*)_a->readBuf, (float*)_b->readBuf, a_count * 2);
}
else {
volk_32f_x2_add_32f(out.writeBuf, _a->readBuf, _b->readBuf, a_count);