X-Git-Url: http://sraa.de/git/?a=blobdiff_plain;f=dol%2Fexamples%2Fexample5%2Fsrc%2Fgenerator.c;fp=dol%2Fexamples%2Fexample5%2Fsrc%2Fgenerator.c;h=9d160cfe7b68ddd11f6a3ba95d6bc613d6f9e5d3;hb=8c411cf24ed0eb889191aaeafd8fa1e69081df42;hp=0000000000000000000000000000000000000000;hpb=dea7a4fb1ed110d3ce6e6d9255103d724bd66c0e;p=jump.git diff --git a/dol/examples/example5/src/generator.c b/dol/examples/example5/src/generator.c new file mode 100644 index 0000000..9d160cf --- /dev/null +++ b/dol/examples/example5/src/generator.c @@ -0,0 +1,47 @@ +#include + +#include "generator.h" + +/** + * Returns a random integer in the range between lower_bound and + * upper_bound, where the bounding values are included in the interval. + */ +int getRandomNumber(int lower_bound, int upper_bound) +{ + return (rand() % (upper_bound - lower_bound + 1)) + lower_bound; +} + + +void generator_init(DOLProcess *p) +{ + ; //nothing to be done here +} + + +int generator_fire(DOLProcess *p) +{ + CREATEPORTVAR(output_port); + + srand(0); //initialize random number generator + + //generate input coefficients and write them to output ports + for (p->local->index = 0; + p->local->index < NUMBER_OF_FFT_POINTS; + p->local->index++) { + p->local->coeffs[p->local->index].real = (float)getRandomNumber(-9, 9); + p->local->coeffs[p->local->index].imag = (float)getRandomNumber(-9, 9); + + CREATEPORT(output_port, PORT_INPUT_COEFFICIENTS, 1, + p->local->index, NUMBER_OF_FFT_POINTS); + printf("%15s: Write to input_coefficients_%d: %9f + j * %9f\n", + "input_generator", p->local->index, + p->local->coeffs[p->local->index].real, + p->local->coeffs[p->local->index].imag); + DOL_write((void*)output_port, &(p->local->coeffs[p->local->index]), + sizeof(ComplexNumber), p); + } + + DOL_detach(p); + return -1; +} +