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