00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "scripts.h"
00010
00011 void datagen_script(void)
00012 {
00013 mgk_data_type type;
00014 datagen_script_context *cxt = mgk_node_context(mgk_current_node(),&type);
00015 printf("gen\n");
00016 fflush(stdout);
00017 if(cxt && (type & T_BUFFER)) {
00018 double samp;
00019 double sfreq;
00020 double namp;
00021 float *data;
00022 char cname[100];
00023 sprintf(cname,CT_SINAMP,cxt->Channel);
00024 samp = gui_get_control_value(cname);
00025 sprintf(cname,CT_SINFREQ,cxt->Channel);
00026 sfreq = gui_get_control_value(cname);
00027 sprintf(cname,CT_NOISEAMP,cxt->Channel);
00028 namp = gui_get_control_value(cname);
00029 data = mgk_allocate_buffer((sizeof(float) * cxt->Size),0);
00030 if(data) {
00031 int i;
00032 for(i = 0; i < cxt->Size; i++) {
00033 data[i] = (float)(
00034 samp * cos(2.0 * M_PI * sfreq * i / cxt->Frequency) +
00035 namp * (double)(rand() - (RAND_MAX / 2)) * (2.0 / RAND_MAX));
00036 }
00037 mgk_propagate(0,data,(T_FLOAT | T_BUFFER));
00038 }
00039 }
00040 }
00041