#include #include #include #include #include #include #include #include #define ONE_AXIS_X 0x01 #define ONE_AXIS_Y 0x02 #define ONE_AXIS_WIDTH ONE_AXIS_X #define ONE_AXIS_HIGHT ONE_AXIS_Y /* width,hight result base scale: 200*200 0,0 = top left or -1,1 200,0 ConvertPair: 1.000000, 1.000000 (correct) 0,200 ConvertPair: -1.000000, -1.000000 (correct) 200,200 ConvertPair: 1.000000, -1.000000 (correct) 0,0 hight ( -1, 1) | ( 0, 1) ( 1, 1) | | | | | | | | ( -1, 0) | ( 0, 0) ( 1, 0) ---------------------+--------------------- width | | | | | | | | | ( -1, -1) | ( 0, -1) ( 1, -1) */ void addr(float * name, const char * _name) { printf("address of %s is %014p, size is %zu\n", _name, name, sizeof(name)); printf("address of &%s is %014p, size is %zu\n", _name, &name, sizeof(&name)); //printf("address of *%s is %014p, size is %zu\n", _name, *name, sizeof(*name)); } float inverse(float num) { return num<0?-num:-(num); } short inverseshort(short num) { return num<0?-num:-(num); } float convert(short num, int hw) { //converts axis to 2d float coordinate return (float) (num-(hw/2))/(hw/2); } int inversesint(int num) { return num<0?-num:-(num); } float convertint(int num, int hw) { //converts axis to 2d float coordinate return (float) (num-(hw/2))/(hw/2); } struct coordinates { float x; float y; }; struct coordinates convertPair(short w, short h, int hw, int FLAGS) { struct coordinates xy; if ((w > hw || w < 0) && (FLAGS != ONE_AXIS_X && FLAGS != ONE_AXIS_Y)) printf("x is out of bounds (expected %hi, got %hi)\n", hw, w); else if ((h > hw || h < 0) && (FLAGS != ONE_AXIS_X && FLAGS != ONE_AXIS_Y)) printf("y is out of bounds (expected %hi, got %hi)\n", hw, h); else { //converts axis pair to 2d float coordinate xy.x = FLAGS==ONE_AXIS_X?0:convert(w, hw); // x xy.y = FLAGS==ONE_AXIS_Y&&h<0?inverse(inverse(convert(inverseshort(h), hw))):inverse(convert(h, hw)); // y printf("%hi, %hi, ConvertPair: %f, %f\n", w, h, xy.x, xy.y); } return xy; } int reverseBool(int val) { if (val == 1 || val == 0) return val^1; else return val; } // short line_xy[] = { 800, 800, 400, 400 }; // should generate: data[] = { 1.000000, -1.000000, 0.000000, 0.000000 }; float * convert_array_type_short_to_vertex(short * data, int size, int scale, int * s, int FLAGS) { if (FLAGS == ONE_AXIS_X || FLAGS == ONE_AXIS_Y) { *s=size*2; scale = scale*2; } else *s=size; // data only has hight data, width is i // format is h,w printf("beginning conversion with a scale of %i and size of %i, with a transformation size of %i\n", scale, size, *s); float * data_new = malloc(*s*sizeof(float)); //memset(data_new, 0, size*(sizeof(float)*2)); int i, z; float * y = malloc(*s/2); float * x = malloc(*s/2); struct coordinates pos; for (i = 0; i < size; i++) { pos = convertPair(FLAGS==ONE_AXIS_X?data[i]:i, FLAGS==ONE_AXIS_Y?(scale/2)+data[i+1]:i, scale, FLAGS); data_new[i] = pos.x; data_new[i+1] = pos.y; if (FLAGS != ONE_AXIS_X && FLAGS != ONE_AXIS_Y) i++; //usleep(150); } printf("finished conversion with a scale of %i and size of %i, with a transformation size of %i\n", scale, size, *s); printf("data[] = { "); for(int k = 0;k #include #include #include int h; int w; int colour; SDL_Renderer * renderer; SDL_Texture * texture; SDL_Window * window; Uint32 *pixels; SDL_Rect SrcR; SDL_Rect DestR; int zoom; int pitch; int base = 2; void init() { SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, 0); audioSampleSize = SampleSize * length; // h and w may be the problem, not sure h = 1000; w = 1000; pitch = w*sizeof(Uint32); colour = 111; // pixel[7] and pixel[9] should be at the top and bottom of the window with no gaps in between, zoom level is valid from 51 to 52 zoom = 275; // 3*3 pixel grid is zoom 275 DestR.x = 0; DestR.y = 0; DestR.w = w; DestR.h = h; SrcR.x = 0; SrcR.y = base-1;//((h/2) - (h * 0.5) / zoom)+1; SrcR.w = w/zoom; SrcR.h = h/zoom; SDL_Init(SDL_INIT_VIDEO); window=SDL_CreateWindow("a", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, w, h, 0); renderer=SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); texture=SDL_CreateTexture(renderer,SDL_PIXELFORMAT_ARGB8888,SDL_TEXTUREACCESS_STREAMING,w,h); pixels=malloc(sizeof(Uint32) * w * h); memset(pixels,255,w*h*4); // create preview SDL_RenderClear(renderer); SDL_UpdateTexture(texture,0,pixels,pitch); SDL_RenderCopy(renderer,texture, &SrcR, &DestR); SDL_RenderPresent(renderer); printf("DestR.x = %i\nDestR.y = %i\nDestR.w = %i\nDestR.h = %i\nSrcR.x = %i\nSrcR.y = %i\nSrcR.w = %i\nSrcR.h = %i\nzoom = %i\n", DestR.x, DestR.y, DestR.w, DestR.h, SrcR.x, SrcR.y, SrcR.w, SrcR.h, zoom); } void putpixel(int x, int y, int colour) { if (x > w || x < 0) printf("x is out of bounds\n"); else if (y > h || y < 0) printf("y is out of bounds\n"); else { int location = (y * w) + x; pixels[location]=colour; printf("pixels[%i] = %i\n", location, colour) ; } } int len; int draw(short * data) { // draw graph int i = 0; SDL_RenderClear(renderer); while (i