diff --git a/FMPX generator/FMPX generator.cpp b/FMPX generator/FMPX generator.cpp index 7620cde..e435f44 100644 --- a/FMPX generator/FMPX generator.cpp +++ b/FMPX generator/FMPX generator.cpp @@ -76,7 +76,7 @@ int main() { return -1; } - const int framesPerBuffer = 4096; + const int framesPerBuffer = 19200; float* buffer = new float[framesPerBuffer * inputParameters.channelCount]; std::vector bands = { {137, -20.2, 1, 3, 1, 100}, // Example parameters for Band 1 @@ -86,8 +86,9 @@ int main() { }; float* piloToneBuffer = new float[framesPerBuffer]; float* stereoToneBuffer = new float[framesPerBuffer]; - generateSineWave(piloToneBuffer, framesPerBuffer, 192000, 19000, 0.08f); - generateSineWave(stereoToneBuffer, framesPerBuffer, 192000, 38000, 1); + SignalGenerator::GenerateSineWave(piloToneBuffer, framesPerBuffer, 19000, 0.08f); + SignalGenerator::GenerateSineWave(stereoToneBuffer, framesPerBuffer, 38000, 1); + while (true) { diff --git a/FMPX generator/PaMPXFunc.cpp b/FMPX generator/PaMPXFunc.cpp index cd3993f..d192c5d 100644 --- a/FMPX generator/PaMPXFunc.cpp +++ b/FMPX generator/PaMPXFunc.cpp @@ -1,16 +1,18 @@ +#include "PaMPXFunc.h" #include +#include -void generateSineWave(float* buffer, int frames, int sampleRate, float frequency, float amplitude = 0.5f) { - const float twoPi = 2.0f * 3.14159f; - float phaseIncrement = (frequency / sampleRate) * twoPi; - float phase = 0.0f; +void SignalGenerator::GenerateSineWave(float* buffer, unsigned long frames, float frequency, float amplitude, int samplerate) { + const double phaseIncrement = frequency / samplerate; + const double cycles = frames / samplerate; // Number of cycles in the buffer + double phase = 0.0; + + for (unsigned long i = 0; i < frames; ++i) { + buffer[i] = amplitude * sin(2.0 * M_PI * phase); - for (int i = 0; i < frames; ++i) { - buffer[i] = amplitude * sin(phase); phase += phaseIncrement; - if (phase > twoPi) { - phase -= twoPi; - } + + } } diff --git a/FMPX generator/PaMPXFunc.h b/FMPX generator/PaMPXFunc.h index d3407d9..491e745 100644 --- a/FMPX generator/PaMPXFunc.h +++ b/FMPX generator/PaMPXFunc.h @@ -1,9 +1,15 @@ #ifndef PAMPXFUNC_H #define PAMPXFUNC_H - +#define M_PI 3.14159265358979323846 #include +#include + +class SignalGenerator { +public: + static void GenerateSineWave(float* buffer, unsigned long frames, float frequency, float amplitude, int samplerate=192000); +}; + -void generateSineWave(float* buffer, int frames, int sampleRate, float frequency, float amplitude = 0.5f); void mix(float* mixedBuffer, const float* buffers[], int numBuffers, int frames);