// This is an example of reading in a .bbr file generated by a sweep recording in Spike // The general file structure of a .bbr file is below. // *Begin* // Header x1 // Sweep Time (sweep 1) // Sweep Min Array (sweep 1) // Sweep Max Array (sweep 1) // Sweep Time (sweep 2) // Sweep Min Array (sweep 2) // Sweep Max Array (sweep 2) // ... ( more sweeps ) // *End* #pragma warning(disable: 4996) #include #include typedef struct BBRHeader { unsigned short signature; unsigned short version; int sweep_count; // Number of sweeps in file unsigned short title[128]; // Sweep configuration set by user during the time of sweep capture double center_freq; double span; double rbw; double vbw; double ref_level; double div; int atten; int gain; int detector; // Size of sweep int trace_len; // Start frequency of first bin in sweep double trace_start_freq; // Frequency difference between bins in sweep double bin_size; } BBRHeader; void parse_bbr_file() { FILE *f = fopen("filename.bbr", "rb"); if(!f) { // Error } BBRHeader header; __int64 time; // Read in header fread(&header, sizeof(BBRHeader), 1, f); // Allocate arrays to hold sweep data float *min = (float*)malloc(sizeof(float) * header.trace_len); float *max = (float*)malloc(sizeof(float) * header.trace_len); // Read in sweeps for(int i = 0; i < header.sweep_count; i++) { // Get sweep time stamp, epoch time in milliseconds fread(&time, sizeof(__int64), 1, f); // Read the min and max sweep arrays // For average detectors, min array == max array fread(min, sizeof(float) * header.trace_len, 1, f); fread(max, sizeof(float) * header.trace_len, 1, f); // Do something with data // For most applications, the max sweep array is the useful array. // Use BBRHeader.trace_start_freq and BBRHeader.bin_size to get the frequency of a given // index into the sweep array. } // Done with file fclose(f); free(min); free(max); } int main(int argc, char **argv) { parse_bbr_file(); return 0; }