MCPcopy Create free account
hub / github.com/FastLED/FastLED / generateSine

Function generateSine

tests/fl/audio/test_helpers.h:88–98  ·  view source on GitHub ↗

Generate a sine wave as raw PCM vector @param freq Frequency in Hz @param count Number of samples (default: 512) @param sampleRate Sample rate in Hz (default: 44100) @param amplitude Peak amplitude (default: 16000) @return Vector of i16 samples

Source from the content-addressed store, hash-verified

86/// @param amplitude Peak amplitude (default: 16000)
87/// @return Vector of i16 samples
88inline fl::vector<fl::i16> generateSine(float freq, int count = 512,
89 float sampleRate = 44100.0f,
90 float amplitude = 16000.0f) {
91 fl::vector<fl::i16> samples;
92 samples.reserve(count);
93 for (int i = 0; i < count; ++i) {
94 float phase = 2.0f * FL_M_PI * freq * i / sampleRate;
95 samples.push_back(static_cast<fl::i16>(amplitude * fl::sinf(phase)));
96 }
97 return samples;
98}
99
100/// Generate a tone as raw PCM vector (in-place version)
101/// @param out Output vector to append samples to

Callers 1

generateToneFunction · 0.70

Calls 4

sinfFunction · 0.85
reserveMethod · 0.45
push_backMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected