2025-12-23 10:56:59 +01:00

28 lines
721 B
C

#include "system/task_sine.h"
#include "system/data_channel.h"
#include "system/float_word.h"
#include <math.h>
#include <limits.h>
int task_sine_run( void * data ) {
sine_config *task = (sine_config *)data;
uint32_t data_channel_base = task->base.sink;
uint32_t samples_per_period = task->samples_per_periode;
float phase = task->phase;
float amplitude = task->amplitude;
float step = ( 2.0f * (float)M_PI ) / (float)samples_per_period;
for ( uint32_t i = 0; i < 1024; ++i ) {
float_word sample;
float angle = phase + (float)i * step;
sample.value = amplitude * sinf( angle );
data_channel_write( data_channel_base, sample.word );
}
return 0;
}