void processing_build_standing_wave(Processing* p, float* wave, float* light, size_t length, float thickness) { double f = p->peakFrequency; if(f < 40) f = 40; if(f > 16000) f = 16000; double waveLength = p->fd / f; size_t index = p->previewLength - waveLength * 2; double* src = &p->preview[index]; double re = 0; double im = 0; for (size_t i = 0; i < waveLength*2; i++) { double t = (double)2.0 * M_PI * i / waveLength; re += src[i] * cos(t); im += src[i] * sin(t); } double phase = get_phase(re, im); double shift = waveLength * phase / (2.0 * M_PI); // here something wrong !!! // p->previewLength - waveLength * 2 - (size_t)(waveLength - shift) - (size_t)waveLength // p->previewLength - waveLength * 4 + (0 .. waveLength) double* shiftedSrc = &p->preview[index - (size_t)(waveLength - shift) - (size_t)waveLength]; approximate_sinc(p->points, shiftedSrc, p->pointCount, 2*waveLength); double avr = data_avr(p->points, p->pointCount); data_shift(p->points, p->pointCount, -avr); double dev = data_dev(p->points, p->pointCount); if(dev != 0){ data_scale(p->points, p->pointCount, 0.2/dev); } double dx = (double)2.0 / p->pointCount; float* dest = wave; for (size_t j = 0; j < p->pointCount-1; j ++) { float x0 = dx * j - 1.0; float y0 = p->points[j]; float x1 = dx*(j + 1) - 1.0; float y1 = p->points[j+1]; dest = build_edge(dest, x0, y0, x1, y1, thickness); for (int i = 0; i < 12; i++) { light = write_point4D(light, x0, y0, x1, y1); } } }
int graph_build_vertices_edges (struct graph_list** my_graph, char* filename) { FILE* fp; fp = fopen(filename, "r"); if (fp != NULL) { printf("the transit file has been opened, oh yeah...\n"); } else { printf("nope, can't open file. Nice try though"); } int trip_id = 0; char arrival_time[30]; char departure_time[30]; int stop_id = 0; int stop_seq = 0; float shape_dist_traveled = 0; int got = 0; long file_pos = 0; char first_letter; struct vertex_storage* vertices = build_vertex_storage(); if (vertices == NULL) { printf("storage couldn't be built"); fclose(fp); return 0; } else { while((first_letter = getc(fp)) != '\n') { }; //advances the pointer to the first character of the second line unsigned long line_number = 1; struct vertex* previous_vertex = NULL; float previous_dist_traveled = 0; struct vertex* current_vertex = NULL; float current_dist_traveled = 0; for (unsigned long i = 0; i < 1476913; i++) { //this is the last line of the san antonio bus file, need to fix to stop at EOF line_number++; got = fscanf(fp, "%d,%[^,],%[^,],%d,%d,,,,", &trip_id, arrival_time, departure_time, &stop_id, &stop_seq); if (got != 5) { printf("error reading file at line %lu", i); return 0; //now we need to back up } else { file_pos = ftell(fp); if ((first_letter = getc(fp)) == '\r') { shape_dist_traveled = 0.000; } else { fseek(fp, file_pos, SEEK_SET); got = fscanf(fp, "%f\n", &shape_dist_traveled); if (got != 1) { //printf("error reading distance traveled at line &d\n", i); return 0; } } } if ((i == 0) || (stop_seq == 1)) { //this is the first line of the document and there is no previous vertex, and perhaps I need to check if the sequence is 1 previous_vertex = build_vertex(stop_id, 0, 0, 0); previous_dist_traveled = shape_dist_traveled; } else { current_vertex = build_vertex(stop_id, 0, 0, 0); //build the vertex from the line, and store it in current current_dist_traveled = shape_dist_traveled; //now we need to try to add the edge made up of previous_vertex and current_vertex struct edge* new_edge = build_edge(previous_vertex, current_vertex, current_dist_traveled - previous_dist_traveled, trip_id); //the edge has been successfully created if (new_edge != NULL) { if(graph_add_edge(new_edge, my_graph) == 1) { previous_vertex = current_vertex; previous_dist_traveled = current_dist_traveled; } else { printf("failed to add to graph\n"); } } else { printf("new edge not created\n"); } } } } fclose(fp); return 1; }