dspx 1.1.0 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -15
- package/binding.gyp +2 -1
- package/dist/bindings.js +1 -1
- package/dist/bindings.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -1
- package/package.json +4 -1
- package/prebuilds/darwin-arm64/dspx.node +0 -0
- package/prebuilds/win32-x64/dspx.node +0 -0
- package/scripts/install.js +98 -0
- package/scripts/postinstall-verify.js +32 -0
- package/scripts/test-install.js +82 -0
- package/scripts/test.js +24 -0
- package/src/native/DspPipeline.cc +38 -0
- package/src/native/adapters/FftStage.cc +441 -0
- package/src/native/adapters/FftStage.h +103 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FFT Stage Adapter
|
|
3
|
+
*
|
|
4
|
+
* Wraps FftEngine for use in the DSP pipeline.
|
|
5
|
+
* Supports forward/inverse transforms with multiple output formats.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#ifndef DSP_ADAPTERS_FFT_STAGE_H
|
|
9
|
+
#define DSP_ADAPTERS_FFT_STAGE_H
|
|
10
|
+
|
|
11
|
+
#include "../IDspStage.h"
|
|
12
|
+
#include "../core/FftEngine.h"
|
|
13
|
+
#include <memory>
|
|
14
|
+
#include <string>
|
|
15
|
+
|
|
16
|
+
namespace dsp
|
|
17
|
+
{
|
|
18
|
+
namespace adapters
|
|
19
|
+
{
|
|
20
|
+
|
|
21
|
+
class FftStage : public IDspStage
|
|
22
|
+
{
|
|
23
|
+
public:
|
|
24
|
+
enum class TransformType
|
|
25
|
+
{
|
|
26
|
+
FFT, // Complex FFT (power-of-2 only)
|
|
27
|
+
IFFT, // Inverse FFT
|
|
28
|
+
DFT, // Direct FT (any size)
|
|
29
|
+
IDFT, // Inverse DFT
|
|
30
|
+
RFFT, // Real FFT (power-of-2 only)
|
|
31
|
+
IRFFT, // Inverse RFFT
|
|
32
|
+
RDFT, // Real DFT (any size)
|
|
33
|
+
IRDFT // Inverse RDFT
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
enum class OutputFormat
|
|
37
|
+
{
|
|
38
|
+
COMPLEX, // Full complex output (interleaved real/imag)
|
|
39
|
+
MAGNITUDE, // |X[k]|
|
|
40
|
+
POWER, // |X[k]|²
|
|
41
|
+
PHASE // ∠X[k]
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Constructor
|
|
46
|
+
* @param size FFT size
|
|
47
|
+
* @param type Transform type (fft, dft, rfft, rdft, etc.)
|
|
48
|
+
* @param forward True for forward, false for inverse
|
|
49
|
+
* @param format Output format (complex, magnitude, power, phase)
|
|
50
|
+
*/
|
|
51
|
+
FftStage(size_t size, TransformType type, bool forward, OutputFormat format);
|
|
52
|
+
|
|
53
|
+
~FftStage() override = default;
|
|
54
|
+
|
|
55
|
+
const char *getType() const override { return "fft"; }
|
|
56
|
+
|
|
57
|
+
bool isResizing() const override { return true; }
|
|
58
|
+
|
|
59
|
+
size_t calculateOutputSize(size_t inputSize) const override;
|
|
60
|
+
|
|
61
|
+
void process(
|
|
62
|
+
float *buffer,
|
|
63
|
+
size_t numSamples,
|
|
64
|
+
int numChannels,
|
|
65
|
+
const float *timestamps = nullptr) override;
|
|
66
|
+
|
|
67
|
+
void processResizing(
|
|
68
|
+
const float *inputBuffer,
|
|
69
|
+
size_t inputSize,
|
|
70
|
+
float *outputBuffer,
|
|
71
|
+
size_t &outputSize,
|
|
72
|
+
int numChannels,
|
|
73
|
+
const float *timestamps = nullptr) override;
|
|
74
|
+
|
|
75
|
+
void reset() override;
|
|
76
|
+
|
|
77
|
+
// State serialization
|
|
78
|
+
Napi::Object serializeState(Napi::Env env) const override;
|
|
79
|
+
void deserializeState(const Napi::Object &state) override;
|
|
80
|
+
|
|
81
|
+
// Helper to parse transform type from string
|
|
82
|
+
static TransformType parseTransformType(const std::string &typeStr);
|
|
83
|
+
static OutputFormat parseOutputFormat(const std::string &formatStr);
|
|
84
|
+
|
|
85
|
+
private:
|
|
86
|
+
size_t m_fftSize;
|
|
87
|
+
TransformType m_type;
|
|
88
|
+
bool m_forward;
|
|
89
|
+
OutputFormat m_format;
|
|
90
|
+
|
|
91
|
+
// FFT engine instance
|
|
92
|
+
std::unique_ptr<core::FftEngine<float>> m_engine;
|
|
93
|
+
|
|
94
|
+
// Working buffers
|
|
95
|
+
std::vector<std::complex<float>> m_complexBuffer;
|
|
96
|
+
std::vector<std::complex<float>> m_tempComplexBuffer; // For DFT/IDFT in-place issue
|
|
97
|
+
std::vector<float> m_realBuffer;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
} // namespace adapters
|
|
101
|
+
} // namespace dsp
|
|
102
|
+
|
|
103
|
+
#endif // DSP_ADAPTERS_FFT_STAGE_H
|