mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2025-07-10 19:15:31 +02:00
even more stuff
This commit is contained in:
30
core/src/dsp/convert/complex_to_real.h
Normal file
30
core/src/dsp/convert/complex_to_real.h
Normal file
@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
#include "../processor.h"
|
||||
|
||||
namespace dsp::convert {
|
||||
class ComplexToReal : public Processor<complex_t, float> {
|
||||
using base_type = Processor<complex_t, float>;
|
||||
public:
|
||||
ComplexToReal() {}
|
||||
|
||||
ComplexToReal(stream<complex_t>* in) { init(in); }
|
||||
|
||||
void init(stream<complex_t>* in) { base_type::init(in); }
|
||||
|
||||
inline static int process(int count, const complex_t* in, float* out) {
|
||||
volk_32fc_deinterleave_real_32f(out, (lv_32fc_t*)in, count);
|
||||
return count;
|
||||
}
|
||||
|
||||
int run() {
|
||||
int count = base_type::_in->read();
|
||||
if (count < 0) { return -1; }
|
||||
|
||||
process(count, base_type::_in->readBuf, base_type::out.writeBuf);
|
||||
|
||||
base_type::_in->flush();
|
||||
if (!base_type::out.swap(count)) { return -1; }
|
||||
return count;
|
||||
}
|
||||
};
|
||||
}
|
25
core/src/dsp/convert/complex_to_stereo.h
Normal file
25
core/src/dsp/convert/complex_to_stereo.h
Normal file
@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
#include "../processor.h"
|
||||
|
||||
namespace dsp::convert {
|
||||
class ComplexToStereo : public Processor<complex_t, stereo_t> {
|
||||
using base_type = Processor<complex_t, stereo_t>;
|
||||
public:
|
||||
ComplexToStereo() {}
|
||||
|
||||
ComplexToStereo(stream<complex_t>* in) { init(in); }
|
||||
|
||||
void init(stream<complex_t>* in) { base_type::init(in); }
|
||||
|
||||
int run() {
|
||||
int count = base_type::_in->read();
|
||||
if (count < 0) { return -1; }
|
||||
|
||||
memcpy(base_type::out.writeBuf, base_type::_in->readBuf, count * sizeof(complex_t));
|
||||
|
||||
base_type::_in->flush();
|
||||
if (!base_type::out.swap(count)) { return -1; }
|
||||
return count;
|
||||
}
|
||||
};
|
||||
}
|
44
core/src/dsp/convert/l_r_to_stereo.h
Normal file
44
core/src/dsp/convert/l_r_to_stereo.h
Normal file
@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
#include "../operator.h"
|
||||
|
||||
namespace dsp::convert {
|
||||
class LRToStereo : public Operator<float, float, stereo_t> {
|
||||
using base_type = Operator<float, float, stereo_t>;
|
||||
public:
|
||||
LRToStereo() {}
|
||||
|
||||
LRToStereo(stream<float>* l, stream<float>* r) { init(l, r); }
|
||||
|
||||
void init(stream<float>* l, stream<float>* r) { base_type::init(l, r); }
|
||||
|
||||
void setInputs(stream<float>* l, stream<float>* r) { base_type::setInputs(l, r); }
|
||||
|
||||
void setInputL(stream<float>* l) { base_type::setInputA(l); }
|
||||
|
||||
void setInputR(stream<float>* r) { base_type::setInputB(r); }
|
||||
|
||||
static inline int process(int count, const float* l, const float* r, stereo_t* out) {
|
||||
volk_32f_x2_interleave_32fc((lv_32fc_t*)out, l, r, count);
|
||||
return count;
|
||||
}
|
||||
|
||||
int run() {
|
||||
int a_count = base_type::_a->read();
|
||||
if (a_count < 0) { return -1; }
|
||||
int b_count = base_type::_b->read();
|
||||
if (b_count < 0) { return -1; }
|
||||
if (a_count != b_count) {
|
||||
base_type::_a->flush();
|
||||
base_type::_b->flush();
|
||||
return 0;
|
||||
}
|
||||
|
||||
process(a_count, base_type::_a->readBuf, base_type::_b->readBuf, base_type::out.writeBuf);
|
||||
|
||||
base_type::_a->flush();
|
||||
base_type::_b->flush();
|
||||
if (!base_type::out.swap(a_count)) { return -1; }
|
||||
return a_count;
|
||||
}
|
||||
};
|
||||
}
|
28
core/src/dsp/convert/mono_to_stereo.h
Normal file
28
core/src/dsp/convert/mono_to_stereo.h
Normal file
@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
#include "../processor.h"
|
||||
|
||||
namespace dsp::convert {
|
||||
class MonoToStereo : public Processor<float, stereo_t> {
|
||||
using base_type = Processor<float, stereo_t>;
|
||||
public:
|
||||
MonoToStereo() {}
|
||||
|
||||
MonoToStereo(stream<float>* in) { base_type::init(in); }
|
||||
|
||||
inline static int process(int count, const float* in, stereo_t* out) {
|
||||
volk_32f_x2_interleave_32fc((lv_32fc_t*)out, in, in, count);
|
||||
return count;
|
||||
}
|
||||
|
||||
int run() {
|
||||
int count = base_type::_in->read();
|
||||
if (count < 0) { return -1; }
|
||||
|
||||
process(count, base_type::_in->readBuf, base_type::out.writeBuf);
|
||||
|
||||
base_type::_in->flush();
|
||||
if (!base_type::out.swap(count)) { return -1; }
|
||||
return count;
|
||||
}
|
||||
};
|
||||
}
|
44
core/src/dsp/convert/real_to_complex.h
Normal file
44
core/src/dsp/convert/real_to_complex.h
Normal file
@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
#include "../processor.h"
|
||||
|
||||
namespace dsp::convert {
|
||||
class RealToComplex : public Processor<float, complex_t> {
|
||||
using base_type = Processor<float, complex_t>;
|
||||
public:
|
||||
RealToComplex() {}
|
||||
|
||||
RealToComplex(stream<float>* in) { init(in); }
|
||||
|
||||
~RealToComplex() {
|
||||
if (!base_type::_block_init) { return; }
|
||||
base_type::stop();
|
||||
buffer::free(nullBuf);
|
||||
}
|
||||
|
||||
void init(stream<float>* in) {
|
||||
nullBuf = buffer::alloc<float>(STREAM_BUFFER_SIZE);
|
||||
buffer::clear(nullBuf, STREAM_BUFFER_SIZE);
|
||||
base_type::init(in);
|
||||
}
|
||||
|
||||
inline int process(int count, const float* in, complex_t* out) {
|
||||
volk_32f_x2_interleave_32fc((lv_32fc_t*)out, in, nullBuf, count);
|
||||
return count;
|
||||
}
|
||||
|
||||
int run() {
|
||||
int count = base_type::_in->read();
|
||||
if (count < 0) { return -1; }
|
||||
|
||||
process(count, base_type::_in->readBuf, base_type::out.writeBuf);
|
||||
|
||||
base_type::_in->flush();
|
||||
if (!base_type::out.swap(count)) { return -1; }
|
||||
return count;
|
||||
}
|
||||
|
||||
private:
|
||||
float* nullBuf;
|
||||
|
||||
};
|
||||
}
|
30
core/src/dsp/convert/stereo_to_mono.h
Normal file
30
core/src/dsp/convert/stereo_to_mono.h
Normal file
@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
#include "../processor.h"
|
||||
|
||||
namespace dsp::convert {
|
||||
class StereoToMono : public Processor<stereo_t, float> {
|
||||
using base_type = Processor<stereo_t, float>;
|
||||
public:
|
||||
StereoToMono() {}
|
||||
|
||||
StereoToMono(stream<stereo_t>* in) { base_type::init(in); }
|
||||
|
||||
inline int process(int count, const stereo_t* in, float* out) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
out[i] = (in[i].l + in[i].r) / 2.0f;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
int run() {
|
||||
int count = base_type::_in->read();
|
||||
if (count < 0) { return -1; }
|
||||
|
||||
process(count, base_type::_in->readBuf, base_type::out.writeBuf);
|
||||
|
||||
base_type::_in->flush();
|
||||
if (!base_type::out.swap(count)) { return -1; }
|
||||
return count;
|
||||
}
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user