X-Git-Url: http://sraa.de/git/?a=blobdiff_plain;f=dol%2Fexamples%2Fexample6%2Fsrc%2Fproducer.c;fp=dol%2Fexamples%2Fexample6%2Fsrc%2Fproducer.c;h=58e161ad2a19c71a03776b33984dde8826ee39bb;hb=8c411cf24ed0eb889191aaeafd8fa1e69081df42;hp=0000000000000000000000000000000000000000;hpb=dea7a4fb1ed110d3ce6e6d9255103d724bd66c0e;p=jump.git diff --git a/dol/examples/example6/src/producer.c b/dol/examples/example6/src/producer.c new file mode 100644 index 0000000..58e161a --- /dev/null +++ b/dol/examples/example6/src/producer.c @@ -0,0 +1,52 @@ +#include +#include + +#include "producer.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 producer_init(DOLProcess *p) +{ + ; //nothing to be done here +} + + +int producer_fire(DOLProcess *p) +{ + static int index; + + srand(0); //initialize random number generator + + //generate input samples and display them + printf("producer: samples = { "); + + for (index = 0; index < 10; index++) { + p->local->sample[index] = (float) getRandomNumber(-9, 9); + if (index < 9) { + printf("%+3.1f, ", p->local->sample[index]); + } + else { + printf("%+3.1f }\n", p->local->sample[index]); + } + } + + //write samples to output port + for (index = 0; index < 10; index++) { + printf("%8s: Write sample[%02d]: %+6.4f\n", + "producer", index, p->local->sample[index]); + DOL_write((void*)PORT_OUT, &(p->local->sample[index]), + sizeof(float), p); + } + + DOL_detach(p); + return -1; +} +