Kubke Lab:Research/ABR/Notebook/2013/11/05
Hearing development in barn owls | <html><img src="/images/9/94/Report.png" border="0" /></html> Main project page <html><img src="/images/c/c3/Resultset_previous.png" border="0" /></html>Previous entry<html> </html>Next entry<html><img src="/images/5/5c/Resultset_next.png" border="0" /></html> |
General Entries
Personal EntriesFabiana
Andy says it is an intel file - over skype trying to figure out the structure so we can read it - extracting info from abr.h and abr_4_mac.c According to andy need to Read the first 1128 bytes then read the next 1000 2-byte int skip 52 read next 1000 points, and so on AndyFollowing file is from the ABR.H header file that was used for the original files. File layout is probably: <Master_Header><Sub_Structure><1000 2-byte INT><Sub_Structure><1000 2-byte INT> ... This structure needs to be confirmed.
{ short freq; /* frequency in Hz */ short amp; /* amplitude in D/A units */ short dur; /* duration in clock ticks */ short rise_fall; /* rise_fall in clock ticks */ } SIGNAL; // 8 bytes typedef struct { SIGNAL carrier; SIGNAL envelope; } STIMULUS; typedef struct { short left_delay; /* microseconds to left onset */ short right_delay; /* microseconds to right onset */ short rep_shorterval; /* interval in millseconds */ } TIMING; //6 bytes typedef struct { short clock; /* clock frequency in kHz */ short max_size; /* maximum size of each array */ short channels; /* 1 for carrier only, 2 for carrier & envelope */ } DA_INFO; //6 bytes typedef struct { short clock; /* in kHz */ short size; /* number of elements (per channel) */ short channels; /* number of channels */ short avg_reps; /* number of reps making up the average */ } AD_INFO; //8 bytes typedef struct { char date[12]; char time[12]; char owl_id[12]; char exp_id[12]; char comments[80]; short depth; short version; char side; short num_chan; short num_tests; short gain; char extra_room[1024-(12+12+12+12+80+2+2+1+2+2+2)];/* Add two more to correct CHAR */ // char extra_room[1024-(12+12+12+12+80+2+2+1)];/* Add two more to correct CHAR */ } HEADER_INFO, EXPERIMENT_HEADER; // Bytes 1024 typedef struct /**** THE MASTER STRUCTURE ****/ { HEADER_INFO header; //1024 STIMULUS left; // 16 STIMULUS right; // 16 TIMING delay; // 6 DA_INFO output; // 6 AD_INFO input; // 8 } EXPERIMENT; // 1076 bytes
{ STIMULUS left; // 16 STIMULUS right; // 16 TIMING delay; // 6 DA_INFO output; // 6 AD_INFO input; // 8 } EXPERIMENT_INFO; // 52 bytes
ABR converter SFTypeList fileTypes; /* 9/23/96 */ StandardFileReply fileReply; /* 9/23/96 */ OSType documentType; /* 9/23/96 */ OSErr osError = 0; /* 9/23/96 */ SInt16 fileRefNum;
short pc2mac(unsigned); EXPERIMENT data; /* Break into parts to solve problems with version compatibility */ EXPERIMENT_HEADER header; EXPERIMENT_INFO info; FILE * f_in, * f_out, * f_out_log; short i,j,k, return_code; char line[80];
/* For the Dialog */ short type; Handle item; Rect box; DialogPtr dialog1, dialog2; /* - - - - - - - */
main(void) { long count; short refNum; char databuf[100]; char filename[80], txt_name[80], log_name[80]; short name_length; short version, num_chan, input_size, num_tests; unsigned header_size, info_size; /* Size of structure varies for version < 4 ? */
InitGraf(&qd.thePort); InitFonts(); InitWindows(); InitMenus(); TEInit(); InitDialogs(NULL); InitCursor(); FlushEvents(everyEvent,0); } StandardGetFile(NULL,NULL,fileTypes,&fileReply); /* 9/23/96 */ if (fileReply.sfGood != TRUE) { exit(0); } // name is: fileReply.sfFile.name name_length = (char)fileReply.sfFile.name[0]; /* First byte is Pascal SIZE of string */ strncpy(filename,(char *)&fileReply.sfFile.name[1],name_length); /*Limit size to PASCAL size */ filename[name_length] = NULL; /* Null as the last byte */ strncpy(txt_name, filename, 80); strncpy(log_name, filename, 80); strcat(txt_name, ".txt"); strcat(log_name, ".log"); f_out_log = fopen(log_name,"w"); f_out = fopen(txt_name,"w");
/* Read in the structure to establish the version then start again... */ count = sizeof(EXPERIMENT_HEADER); osError = FSRead(fileRefNum,&count,&header); version = pc2mac(header.version); /* Get the version */ if (version <400) header_size = sizeof(EXPERIMENT_HEADER) - 2; /* Correct for CHAR offset */ else header_size = sizeof(EXPERIMENT_HEADER); osError = SetFPos(fileRefNum,fsFromStart,0L); /* Reset to file beginning */ info_size = sizeof(EXPERIMENT_INFO);
//If we get here its time to process the data //Set up special conditions to make older files compatible... //Convert important 'constants' to Mac format for use in this program... input_size = pc2mac(info.input.size); num_tests = pc2mac(header.num_tests); num_chan = pc2mac(header.num_chan); n_reps = pc2mac(info.input.avg_reps); if (version < 400) num_chan = 1; /* Older files are only 1 channel */ if (version < 500) { num_tests = 1; /* Only 1 binaural test */ input_size = 1000; /* This should be in header, but its here in case needed */ } //Allocate necessary array space... analog_left = (short *) malloc(input_size * sizeof(short) ); analog_right = (short *) malloc(input_size * sizeof(short) ); for (i=0; i<num_tests; i++) { analog_binaural[i] = (short *) malloc(input_size * sizeof(short) ); sdev_b[i] = (short *) malloc (input_size * sizeof(short)); } analog_spontaneous = (short *) malloc(input_size * sizeof(short) ); sdev_l = (short *) malloc (input_size * sizeof(short)); sdev_r = (short *) malloc (input_size * sizeof(short)); sdev_s = (short *) malloc (input_size * sizeof(short)); //-----------------------------------
dialog1 = GetNewDialog(128,0L, NULL); GetDItem(dialog1, 2, &type, &item, &box); SetIText(item,c2pstr(header.owl_id)); GetDItem(dialog1, 3, &type, &item, &box); SetIText(item,c2pstr(header.date)); GetDItem(dialog1, 4, &type, &item, &box); SetIText(item,c2pstr(header.time)); GetDItem(dialog1, 5, &type, &item, &box); SetIText(item,c2pstr(header.comments)); sprintf(line,"%5i\0",version); GetDItem(dialog1, 6, &type, &item, &box); SetIText(item,c2pstr(line)); sprintf(line,"%2i\0",num_chan); GetDItem(dialog1, 7, &type, &item, &box); SetIText(item,c2pstr(line)); sprintf(line,"%2i\0",num_tests); GetDItem(dialog1, 8, &type, &item, &box); SetIText(item,c2pstr(line)); sprintf(line,"%3i\0",pc2mac(info.input.clock)); GetDItem(dialog1, 9, &type, &item, &box); SetIText(item,c2pstr(line)); sprintf(line,"%6i\0",pc2mac(info.left.carrier.freq)); GetDItem(dialog1, 10, &type, &item, &box); SetIText(item,c2pstr(line)); sprintf(line,"%3i\0",pc2mac(info.input.avg_reps)); GetDItem(dialog1, 11, &type, &item, &box); SetIText(item,c2pstr(line)); GetDItem(dialog1, 12, &type, &item, &box); SetIText(item,c2pstr(filename));
//dialog2 = GetNewDialog(129,0L, NULL); //ModalDialog(NULL, &type); //CloseDialog(dialog2); CloseDialog(dialog1);
//read analog left (sdev if version > 300) // then analog right (sdev if version > 300) // CONVERT to MAC after reading... /* first time we already did the EXPT read */ count = input_size * sizeof(short); osError = FSRead(fileRefNum,&count,analog_left); for (j=0; j<input_size; j++) analog_left[j] = pc2mac(analog_left[j]); if (version >= 300) { count = input_size * sizeof(short); osError = FSRead(fileRefNum,&count,sdev_l); for (j=0; j<input_size; j++) sdev_l[j] = pc2mac(sdev_l[j]); } count = header_size; osError = FSRead(fileRefNum,&count,&header); count = info_size; osError = FSRead(fileRefNum,&count,&info); count = input_size * sizeof(short); osError = FSRead(fileRefNum,&count,analog_right); for (j=0; j<input_size; j++) analog_right[j] = pc2mac(analog_right[j]); if (version >= 300) { count = input_size * sizeof(short); osError = FSRead(fileRefNum,&count,sdev_r); for (j=0; j<input_size; j++) sdev_r[j] = pc2mac(sdev_r[j]); } if (version >= 400) /* Spontaneous is done third for >400, fourth for <400 */ { count = header_size; osError = FSRead(fileRefNum,&count,&header); count = info_size; osError = FSRead(fileRefNum,&count,&info); count = input_size * sizeof(short); osError = FSRead(fileRefNum,&count,analog_spontaneous); for (j=0; j<input_size; j++) analog_spontaneous[j] = pc2mac(analog_spontaneous[j]); if (version >= 300) { count = input_size * sizeof(short); osError = FSRead(fileRefNum,&count,sdev_s); for (j=0; j<input_size; j++) sdev_s[j] = pc2mac(sdev_s[j]); } }
/* CHECK THE FOLLOWING */ /* Delay WAS right-left but on 9/25/96 I flipped them so that (-) measn Left Leads */ fprintf(f_out_log,"%i\n",pc2mac(info.delay.left_delay)-pc2mac(info.delay.right_delay)); count = input_size * sizeof(short); osError = FSRead(fileRefNum,&count,analog_binaural[i]); for (j=0; j<input_size; j++) analog_binaural[i][j] = pc2mac(analog_binaural[i][j]); if (version >= 300) { count = input_size * sizeof(short); osError = FSRead(fileRefNum,&count,sdev_b[i]); for (j=0; j<input_size; j++) sdev_b[i][j] = pc2mac(sdev_b[i][j]); } } if (version < 400) /* Spontaneous is done third for >400, fourth for <400 */ { count = header_size; osError = FSRead(fileRefNum,&count,&header); count = info_size; osError = FSRead(fileRefNum,&count,&info); count = input_size * sizeof(short); osError = FSRead(fileRefNum,&count,analog_spontaneous); for (j=0; j<input_size; j++) analog_spontaneous[j] = pc2mac(analog_spontaneous[j]); if (version >= 300) { count = input_size * sizeof(short); osError = FSRead(fileRefNum,&count,sdev_s); for (j=0; j<input_size; j++) sdev_s[j] = pc2mac(sdev_s[j]); } }
if (version >=320) { /* sdev has 95% confidence intervals */ fprintf(f_out,"%6i\t",sdev_l[i]); fprintf(f_out,"%6i\t",sdev_r[i]); fprintf(f_out,"%6i\t",sdev_s[i]); for (j=0; j<num_tests; j++) fprintf(f_out,"%6i\t",sdev_b[j][i]); } else if ((version < 320) && (version >= 300)) { /* Convert top 95% confidence intervals */ fprintf(f_out,"%6i\t",(short) (1.96 * (float)sdev_l[i]/(float)n_reps)); fprintf(f_out,"%6i\t",(short) (1.96 * (float)sdev_r[i]/(float)n_reps)); fprintf(f_out,"%6i\t",(short) (1.96 * (float)sdev_s[i]/(float)n_reps)); for (j=0; j<num_tests; j++) fprintf(f_out,"%6i\t",(short) (1.96 * (float)sdev_b[j][i]/(float)n_reps)); }
{ free(analog_binaural[i]); free(sdev_b[i]); } free(sdev_s); } /*End WHILE loop */ //Close Files fclose(f_out); fclose(f_out_log); osError = FSClose(fileRefNum); }
high = x/256; /* Integer math returns upper 8 bits */ low = x%256; /* Returns the lower 8 bits */ result = low * 256 + high; /* Flips the Bits */ return((short)result); } /*************/ Oris
|