//___________________________________________________________________________________ void ReadTT_timestamps(char* fn, int nSpikes, double *t) { double t0; double wv0[128]; // open file FILE *fp = fopen(fn, "rb"); if (!fp) mexErrMsgTxt("ERROR: Could not open file."); // skip header //int new_NT_format = SkipHeader(fp); // flag for new NT_format TT files (0=old SUN, 1=new NT) //if (!new_NT_format) // mexErrMsgTxt("Old sun format not supported by this loading engine."); //SkipCheetahNTHeader(fp); // Skip standard Neuralynx header if present (Cheetah versions >= 1.3) //long postHeaderPos = ftell(fp); int start_found = FindDataStart(fp); long postHeaderPos = ftell(fp); // read records and convert all to double fseek(fp, postHeaderPos, SEEK_SET); for (int i = 0; i < nSpikes; i++) { //mexPrintf("Attempting to get record %d\n",i); GetOneRecord(fp,t0,wv0); t[i] = t0; } fclose(fp); }
//___________________________________________________________________________________ void ReadTT(char* fn, int nSpikes, double *t, double *wv){ double t0; double wv0[128]; // open file FILE *fp = fopen(fn, "rb"); if (!fp) mexErrMsgTxt("ERROR: Could not open file."); // skip header //int new_NT_format = SkipHeader(fp); // flag for new NT_format TT files (0=old SUN, 1=new NT) //if (!new_NT_format) // mexErrMsgTxt("Old sun format not supported by this loading engine."); //SkipCheetahNTHeader(fp); // Skip standard Neuralynx header if present (Cheetah versions >= 1.3) //long postHeaderPos = ftell(fp); int start_found = FindDataStart(fp); long postHeaderPos = ftell(fp); // read records and convert all to double fseek(fp, postHeaderPos, SEEK_SET); for (int i = 0; i < nSpikes; i++){ GetOneRecord(fp,t0,wv0); t[i] = t0; for (int j = 0; j<4; j++) for(int k = 0; k<32; k++) wv[i + nSpikes*j + nSpikes*4*k] = (double) wv0[j + 4*k]; } fclose(fp); }
//___________________________________________________________________________________ int GetNumberOfSpikes(char* fn){ // open file FILE* fp = fopen(fn, "rb"); if (!fp) mexErrMsgTxt("Could not open file."); //skip header and determine file record size int start_found = FindDataStart(fp); if (!start_found) { mexErrMsgTxt("data_start not found."); return(0); } // get filesize int postHeaderPos = ftell(fp); // beginnig of file after header (if any) fseek(fp,0,2); // goto end of file int nbytes = ftell(fp) - postHeaderPos - 10; // 10 because of data_end0D0A int nSpikes = nbytes/recSize; // no need to skip last record for NT_cheetah files mexPrintf("Reading file %s:\nRecordSize = %d, %d spikes, %d bytes.\n", fn, recSize, nSpikes, nbytes); // cleanup fclose(fp); return nSpikes; }
//_________________________________________________________________________________________________ void ReadTTByRecord(char* fn, double *records_to_get, int n_records_to_get, double *t, double *wv) // Open the file and fseek to just those record number passed in // in the array: records_to_get. The last record of records to get // indicates the end of records. It's code is END_OF_RECORDS. { int i = 0; double t0; double wv0[128]; // open file FILE *fp = fopen(fn, "rb"); if (!fp) mexErrMsgTxt("ERROR: Could not open file."); // skip header //int new_NT_format = SkipHeader(fp); // flag for new NT_format TT files (0=old SUN, 1=new NT) //if (!new_NT_format) // mexErrMsgTxt("Old sun format not supported by this loading engine."); //SkipCheetahNTHeader(fp); // Skip standard Neuralynx header if present (Cheetah versions >= 1.3) //long postHeaderPos = ftell(fp); int start_found = FindDataStart(fp); long postHeaderPos = ftell(fp); // read records and convert all to double while(i < n_records_to_get) { // Go directly to the record in question. Do not pass go. NO $200. fseek(fp, postHeaderPos+sizeof(char)*(recSize)*((long)records_to_get[i] - 1), SEEK_SET); GetOneRecord(fp,t0,wv0); t[i] = t0; for (int j = 0; j<4; j++) for(int k = 0; k<32; k++) wv[i + n_records_to_get*j + n_records_to_get*4*k] = (double) wv0[j + 4*k]; i++; } fclose(fp); }
int32_t main (int32_t argc, char * argv[]) { char * inputFileName = argv[1]; char * outputFileName = argv[2]; FILE * inputFile = NULL; FILE * outputFile = NULL; bool malformed = argc < 2; // Parse the commandline and open the necessary files for (int32_t i = 1; i < argc; ++i) { if (strcmp (argv[i], "-h") == 0) { malformed = true; } else { if (argv[i][0] == '-') { printf ("unknown option: %s\n", argv[i]); malformed = true; } else { if (inputFile == NULL) inputFile = fopen (inputFileName, "rb"); // the b is necessary for Windows -- ignored by Unix if(inputFile == NULL) { fprintf(stderr," Cannot open file \"%s\"\n", inputFileName); exit (1); } if (outputFile == NULL) outputFile = fopen (outputFileName, "w+b"); // the b is necessary for Windows -- ignored by Unix if(outputFile == NULL) { fprintf(stderr," Cannot open file \"%s\"\n", outputFileName); exit (1); } } } if (malformed) { break; } } if (!malformed) { printf("Input file: %s\n", inputFileName); printf("Output file: %s\n", outputFileName); // So at this point we have the input and output files open. Need to determine what we're dealing with int32_t theError = 0; AudioFormatDescription inputFormat; AudioFormatDescription outputFormat; int32_t inputDataPos = 0, inputDataSize = 0; uint32_t inputFileType = 0; // 'caff' or 'WAVE' uint32_t outputFileType = 0; // 'caff' or 'WAVE' theError = GetInputFormat(inputFile, &inputFormat, &inputFileType); if (theError) { fprintf(stderr," Cannot determine what format file \"%s\" is\n", inputFileName); exit (1); } if (inputFileType != 'WAVE' && inputFileType != 'caff') { fprintf(stderr," File \"%s\" is of an unsupported type\n", outputFileName); exit (1); } if (inputFormat.mFormatID != kALACFormatAppleLossless && inputFormat.mFormatID != kALACFormatLinearPCM) { fprintf(stderr," File \"%s\'s\" data format is of an unsupported type\n", outputFileName); exit (1); } SetOutputFormat(inputFormat, &outputFormat); if (theError) { fprintf(stderr," Cannot determine what format file \"%s\" is\n", outputFileName); exit (1); } FindDataStart(inputFile, inputFileType, &inputDataPos, &inputDataSize); fseek(inputFile, inputDataPos, SEEK_SET); // We know where we are and we know what we're doing if (outputFormat.mFormatID == kALACFormatAppleLossless) { // encoding EncodeALAC(inputFile, outputFile, inputFormat, outputFormat, inputDataSize); } else { // decoding GetOutputFileType(outputFileName, &outputFileType); if (outputFileType == 'WAVE' && outputFormat.mChannelsPerFrame > 2) { // we don't support WAVE because we don't want to reinterleave on output fprintf(stderr," Cannot decode more than two channels to WAVE\n"); exit (1); } DecodeALAC(inputFile, outputFile, inputFormat, outputFormat, inputDataSize, outputFileType); } } if (malformed) { printf ("Usage:\n"); printf ("Encode:\n"); printf (" alacconvert <input wav or caf file> <output caf file>\n"); printf ("Decode:\n"); printf (" alacconvert <input caf file> <output wav or caf file>\n"); printf ("\n"); return 1; } if (inputFile) fclose(inputFile); if (outputFile) fclose(outputFile); return 0; }