Kubke Lab:Research/ABR/Notebook/2013/11/05

From OpenWetWare

Jump to: navigation, search
Hearing development in barn owls Main project page
Previous entry      Next entry

Contents


General Entries

  • Insert content here.

Personal Entries

Fabiana

  • trying to open the actual .ABR files - getting nowhere. Noticed the log files that were extracted dont have the info I need and need to see what info is in the actual data files.

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

Andy

Following 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.


typedef struct

   {
   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


typedef struct /**** SUB STRUCTURE ****/

   {
   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;


// …………………………………………………………………………………………………………………………………………………………………………………………………………… includes

  1. include <Windows.h>
  2. include <Fonts.h>
  3. include <Menus.h>
  4. include <TextEdit.h>
  5. include <Dialogs.h>
  6. include <SegLoad.h>
  7. include <ToolUtils.h>
  8. include <Devices.h>
  9. include <AppleEvents.h>
  10. include <StandardFile.h>
  11. include <Folders.h>
  12. include <Resources.h>
  13. include <Script.h>
  14. include <stdlib.h>
  15. include <string.h>
  16. include <StandardFile.h> /* 9/23/96 */
  17. include <stdio.h>
  18. include <math.h>
  19. include <Strings.h>
  1. include "abr.h"

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];

  1. if 1

/* For the Dialog */ short type; Handle item; Rect box; DialogPtr dialog1, dialog2; /* - - - - - - - */

  1. endif

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 ? */


short *analog_left, *analog_right, *analog_binaural[10], *analog_spontaneous; short *sdev_l,*sdev_r,*sdev_b[10],*sdev_s; short which_test,delay[14],delay_cnt,n_reps;


if (1) /*inits*/ { MaxApplZone(); MoreMasters();

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");


osError = FSpOpenDF(&fileReply.sfFile,fsRdPerm,&fileRefNum);

/* 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);


while (1) { /*While Loop*/ count = header_size; osError = FSRead(fileRefNum,&count,&header); if (count < header_size) break; count = info_size; osError = FSRead(fileRefNum,&count,&info);


/* Get the Experiment's HEADER into the log */ fprintf(f_out_log,"Owl\tDate\tTime\tClock_kHz\tn_reps\tfreq\tversion\n"); fprintf(f_out_log,"%s\t%s\t%s\t%i\t%i\t%i\t%5.2f\n", header.owl_id,header.date,header.time, pc2mac(info.input.clock), pc2mac(info.input.avg_reps), pc2mac(info.left.carrier.freq), pc2mac(header.version)/100.0 ); fprintf(f_out_log,"\tComment line: "); fputs(header.comments,f_out_log); if (num_chan >1) fprintf(f_out_log,"\nChannel 0 data, only\n"); fprintf(f_out_log,"\n\n"); fprintf(f_out_log,"delay\n");


//Check Experiment Type (should = 'abr') to confirm good data... // And be sure the INPUT SIZE is less than or equal 2000 if ((header.exp_id[0]!='a') && (header.exp_id[0]!='A') && (pc2mac(info.input.size) > 2000)) { fprintf(f_out_log,"\nDATA FILE CORRUPTED - execution aborted\n"); fprintf(f_out,"DATA FILE CORRUPTED - execution aborted"); fclose(f_out); fclose(f_out_log); osError = FSClose(fileRefNum); exit(0); }

//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)); //-----------------------------------

  1. if 1

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));


ModalDialog(NULL, &type); //DrawDialog(dialog1); //CloseDialog(dialog1);

//dialog2 = GetNewDialog(129,0L, NULL); //ModalDialog(NULL, &type); //CloseDialog(dialog2); CloseDialog(dialog1);

  1. endif


//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]); } }


for (i=0; i<num_tests; i++) { count = header_size; osError = FSRead(fileRefNum,&count,&header); count = info_size; osError = FSRead(fileRefNum,&count,&info);

/* 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]); } }


// - - - PRINT OUT THE TEXT FILE HERE - - - fprintf(f_out,"msec\tleft\tright\tspont\t"); for (j=0; j<num_tests; j++) fprintf(f_out,"bin#%i\t",j); if (version >=300) { fprintf(f_out,"sdev_l\tsdev_r\tsdev_spont\t"); for (j=0; j<num_tests; j++) fprintf(f_out,"sd_bin#%i\t",j); } fprintf(f_out,"\n");


for (i=0; i<input_size; i+=num_chan) /* DO ONLY 0 CHANNEL for NOW. +1 index for other CHANNEL */ { /* For Each Data Element */ fprintf(f_out,"%8.2f\t",0.020*(float)(i/num_chan)); /* 0.020 msecs per point at 50kHz */ fprintf(f_out,"%6i\t",analog_left[i]); fprintf(f_out,"%6i\t",analog_right[i]); fprintf(f_out,"%6i\t",analog_spontaneous[i]); for (j=0; j<num_tests; j++) fprintf(f_out,"%6i\t",analog_binaural[j][i]);

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)); }


fprintf(f_out,"\n"); } fprintf(f_out,"\n\n");


//----------------------------------- // Free arrays free(analog_left); free(analog_right); free(analog_spontaneous); free(sdev_l); free(sdev_r); for (i=0; i<num_tests; i++)

   {
   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);

}


/*************/ short pc2mac(unsigned x) /* Flip HIGH and LOW to convert PC to MAC */ { unsigned high, low, result;

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

  • Enter content here


Personal tools