Tuesday, August 24, 2010

write_nsp_head

Digital Signal Processing Library

Voice Lab

write_nsp_head


void write_nsp_head(FILE *out_file, int data_size, int sample_rate, int data_length)
{
int header_length;
int size, i;
time_t now;
struct tm *times;
char month[20], date_string[30], txt[120];

fwrite("FORM", 1, sizeof("FORM")-1, out_file);
fwrite("DS16", 1, sizeof("DS16")-1, out_file);

/* This size should be the blocks from here to the end of the file */
/* it should be the HEDR chunk(40) + Note Chunk(8 + note_string) + SDA chunk(8 + data_length) */
/* Calculate size.... */
strcpy(txt, "Repackaged by RRB. File downsampled to 25000");
size = strlen(txt);
if(size%2) size++;
size += 40 + 8 + 8 + data_length;
write_data(out_file, size, 4);

fwrite("HEDR", 1, sizeof("HEDR")-1, out_file);

size = 32;
write_data(out_file, size, 4);

time(&now);
times = localtime(&now);
switch(times->tm_mon) {
case 0:
strcpy(month, "Jan");
break;
case 1:
strcpy(month, "Feb");
break;
case 2:
strcpy(month, "Mar");
break;
case 3:
strcpy(month, "Apr");
break;
case 4:
strcpy(month, "May");
break;
case 5:
strcpy(month, "Jun");
break;
case 6:
strcpy(month, "Jul");
break;
case 7:
strcpy(month, "Aug");
break;
case 8:
strcpy(month, "Sep");
break;
case 9:
strcpy(month, "Oct");
break;
case 10:
strcpy(month, "Nov");
break;
case 11:
strcpy(month, "Dec");
break;
}
sprintf(date_string, "%s %2d %2d:%2d:%2d %4d", month, times->tm_mday,
times->tm_hour, times->tm_min, times->tm_sec, 1900+times->tm_year);
fwrite(date_string, 20, sizeof(char), out_file);

printf("Date: %s\n", date_string);

write_data(out_file, sample_rate, 4);
printf("Sample Rate: %d\n", sample_rate);

write_data(out_file, data_size, 4);
write_data(out_file, 0xFFFF, 2);
write_data(out_file, 0xFFFF, 2);

fwrite("NOTE", 1, sizeof("NOTE")-1, out_file);

size = strlen(txt);
write_data(out_file, size, 4);

fwrite(txt, size, sizeof(char), out_file);
if(size%2) {
write_data(out_file, 0, 1);
}

fwrite("SDA_", 1, sizeof("SDA_")-1, out_file);

size = data_length;
write_data(out_file, size, 4);
printf("Data length: %d\n", data_length);

size = ftell(out_file);
}


No comments:

Post a Comment