// Jack | Process Callback int process(jack_nframes_t nframes, void *arg) { sample_t * in = (sample_t *) jack_port_get_buffer(input_port, nframes); sample_t * out = (sample_t *) jack_port_get_buffer(output_port, nframes); if (aubio_fvec == NULL || aubio_fvec->data == NULL) { init_aubio(sample_rate); } // jack_nframes_t i; for (i = 0; i < nframes; i++) { // ???: What is the significance of `framecount == hopsize`? if (framecount == hopsize) { image_tones_index++; if (image_tones_index >= image_tones_size) { image_tones_index = 0; } // Build waveform for the next pixel of our original image // TODO: Consider a "feedback" mode. build_tone(image_tones[image_tones_index], 1 - image_tones_amp[image_tones_index], waveform_type); // Write_to_image() according to analyzed samples // TODO: How often are the vars below redeclared? float H, S, L, R, G, B; Sound2Hsl(&H, &S, &L, aubio_pitchdetection(aubio, aubio_fvec), max_amp, pitch_scale, lower_bounds); Hsl2Rgb(&R, &G, &B, H, S, 1 - L); write_to_image(dest_image, R, G, B); framecount = 0; max_amp = 0; } out[i] = cycle[offset]; // !!!: aubio_fvec->data[0][framecount] = (smpl_t) in[i]; if (fabs(in[i]) > max_amp) { max_amp = fabs(in[i]); } offset++; if (offset == samples_per_cycle) { offset = 0; } framecount++; } return 0; }
int main(int argc, char* argv[]) { char* recvBuff = malloc(512); if(argc<3) { perror("Incorrect number of arguments\n"); exit(0); } struct stat s; int err = stat("images",&s); if(-1==err) { if(ENOENT == errno) { printf("Directory for images does not exist, creating it\n"); mkdir("images",0777); printf("Directory created\n"); } } else { if(S_ISDIR(s.st_mode)) { printf("Directory for images exists\n"); } } struct stat st = {0}; if(stat("images/catalog.csv",&st)!=-1) { perror("Catalog exists. Deleting it..\n"); remove("images/catalog.csv"); } htmlpath = malloc(200); strcpy(htmlpath,"images/"); strcat(htmlpath,"download.html"); int sockfd; struct sockaddr_in serv_addr; if((sockfd = socket(AF_INET,SOCK_STREAM,0)) < 0) { perror("Could not create socket connection\n"); exit(0); } serv_addr.sin_family = AF_INET; serv_addr.sin_port = htons(atoi(argv[2])); serv_addr.sin_addr.s_addr = inet_addr(argv[1]); if(connect(sockfd, (struct sockaddr*)&serv_addr,sizeof(serv_addr))<0) { perror("Connection failed\n"); exit(0); } char* logpath = malloc(200); strcpy(logpath,"images/catalog.csv"); write_to_image(logpath,sockfd); FILE* fp; fp = fopen(logpath,"r"); char ch; int lines=0; while(!feof(fp)) { ch = fgetc(fp); if(ch == '\n') //Get the number of lines in log file. { lines++; } } fclose(fp); char* line = NULL; size_t len = 0; fp = fopen(logpath,"r"); getline(&line,&len,fp); //Read log file line by line. printf("Dumping catalog.csv content\n"); int i = 1; int j; int k; int m; int n; for(k = 0;k<lines-1;k++) { strcpy(file_array[file_count],"images/"); printf("[%d] ",i); getline(&line,&len,fp); for(j=0;line[j]!=',';j++) { file_array[file_count][j+7] = line[j]; printf("%c",line[j]); } char* name = strtok(line,","); char* size = strtok(NULL,","); char* sum = strtok(NULL,","); strcpy(checksums[file_count],sum); //printf("%s\n",checksums[file_count]); file_count++; i++; printf(" \n"); } fclose(fp); for(i=0;i<file_count;i++) { addToArray(file_array[i],i); } if(argv[3]!=NULL) //Arg[3] present. Passive mode. { printf("Passive mode\n"); write(sockfd,argv[3],11); write(sockfd,"ready",5); if(is_jpg(argv[3])) { //Write jpg images for(i=0;i<jpg_count;i++) write_to_image(jpg_array[i],sockfd); } if(is_png(argv[3])) { for(i=0;i<png_count;i++) //Write png images. write_to_image(png_array[i],sockfd); } if(is_gif(argv[3])) { //Write gif files. for(i=0;i<gif_count;i++) write_to_image(gif_array[i],sockfd); } if(is_tiff(argv[3])) { //Write tiff files. for(i=0;i<tiff_count;i++) write_to_image(tiff_array[i],sockfd); } } else { //argv[3] not present. interactive mode. inter = 1; printf("Interactive mode\n"); write(sockfd,"interactive",11); char input[1]; while(1) { printf("Enter the file number to download\n"); scanf("%s",input); if(atoi(input)==0) { write(sockfd,input,2); printf("Entered 0. Exiting...\n"); close(sockfd); break; } printf("File number entered:%d\n",atoi(input)); write(sockfd,input,2); write_to_image(file_array[atoi(input)-1],sockfd); } } printf("Done\n"); //Create html file. FILE* html; html = fopen("./images/download.html","w+"); fprintf(html,"<html><head>Downloaded Images</head>"); fprintf(html,"<title>Downloaded Images</title>\n"); fprintf(html,"<p>"); /* For each file in the downloaded(images) folder, look for the file in the file_array,get the index, see if checksums are equal. Accordingly write to html. */ DIR* dir; struct dirent* file; dir = opendir("./images/"); while((file = readdir(dir))!=NULL) { int i; int j; if(file->d_name[0] == '.') continue; if(strcmp(file->d_name,"catalog.csv")==0) continue; char* path = malloc(200); strcpy(path,"images/"); strcat(path,file->d_name); unsigned char sum[MD5_DIGEST_LENGTH]; char convertedsum[(MD5_DIGEST_LENGTH*2)+1]; md5sum(path,sum); /**stackoverflow.com/questions/7627723/how-to-create-a-md5-hash-of-a-string-in-c**/ for(j=0;j<MD5_DIGEST_LENGTH;j++) { sprintf(convertedsum+(j*2),"%02x",sum[j]); } convertedsum[2*MD5_DIGEST_LENGTH]='\0'; char* other_name = malloc(200); for(i=0;i<file_count;i++) { if(strstr(path,file_array[i])) { if(strncmp(convertedsum,checksums[i],MD5_DIGEST_LENGTH)==0) { fprintf(html,"Checksum match!\n"); fprintf(html, " "); fprintf(html, "<a href = \""); fprintf(html,"%s\">",file->d_name); fprintf(html,"%s",file->d_name); fprintf(html,"</a></p>\n"); } else { fprintf(html,"Checksum mismatch"); fprintf(html," "); fprintf(html,"%s",file->d_name); fprintf(html,"</p>"); } } } } fprintf(html,"</body></html>"); fclose(html); return 0; }