38 unsigned int binaural_index_start;
39 unsigned int binaural_index_end;
45 unsigned int impulse_response_index_start;
46 unsigned int impulse_response_index_end;
52 puts(
"HRIR database to C header file converter.");
53 puts(
"Usage: conf_bridge_binaural_hrir_importer HRIR.wav INDEX_START INDEX_END > OUTPUT.h");
54 puts(
"Example: conf_bridge_binaural_hrir_importer hrirs.wav 0 180 > ../bridges/bridge_softmix/include/hrirs.h");
60 hrir_filename = argv[1];
61 binaural_index_start = atoi(argv[2]);
62 binaural_index_end = atoi(argv[3]);
65 hrir_file = sf_open(hrir_filename, SFM_READ, &hrir_info);
66 if(hrir_file ==
NULL) {
67 fprintf(stderr,
"ERROR: Could not open HRIR database (%s).\n", hrir_filename);
71 fprintf(stderr,
"INFO: Opened HRIR database (%s) with: number channels: %d; samplerate: %d; samples per channel: %ld\n", hrir_filename, hrir_info.channels, hrir_info.samplerate, hrir_info.frames);
73 hrir_data = (
float *)
malloc(hrir_info.channels * hrir_info.frames *
sizeof(
float));
74 if(hrir_data ==
NULL) {
75 fprintf(stderr,
"ERROR: Out of memory!");
81 sf_read_float(hrir_file, hrir_data, hrir_info.channels * hrir_info.frames);
84 if(binaural_index_start >= binaural_index_end) {
85 fprintf(stderr,
"ERROR: INDEX_START (%d) must be smaller than INDEX_END (%d).", binaural_index_start, binaural_index_end);
91 if (binaural_index_end * 2 >= hrir_info.channels) {
92 fprintf(stderr,
"ERROR: END_INDEX (%d) is out of range for HRIR database (%s).\n", binaural_index_end, hrir_filename);
99 impulse_response_index_start = 2 * binaural_index_start;
100 impulse_response_index_end = (binaural_index_end + 1) * 2;
103 printf(
FILE_HEADER, hrir_filename, binaural_index_start, binaural_index_end);
105 printf(
"#define HRIRS_IMPULSE_LEN %ld\n", hrir_info.frames);
106 printf(
"#define HRIRS_IMPULSE_SIZE %d\n", binaural_index_end - binaural_index_start + 1);
107 printf(
"#define HRIRS_SAMPLE_RATE %d\n\n", hrir_info.samplerate);
109 printf(
"float hrirs_left[HRIRS_IMPULSE_SIZE][HRIRS_IMPULSE_LEN] = {\n");
110 for (ir_current = impulse_response_index_start; ir_current < impulse_response_index_end; ir_current += 2) {
113 for (j = 0; j < hrir_info.frames - 1; j++) {
114 printf(
"%.16f,%s", hrir_data[ir_current * hrir_info.frames + j], ((j + 1) % 4 ?
" " :
"\n"));
117 printf(
"%.16f", hrir_data[ir_current * hrir_info.frames + hrir_info.frames - 1]);
119 if (ir_current + 2 < impulse_response_index_end) {
126 printf(
"\nfloat hrirs_right[HRIRS_IMPULSE_SIZE][HRIRS_IMPULSE_LEN] = {\n");
127 for (ir_current = impulse_response_index_start + 1; ir_current < impulse_response_index_end + 1; ir_current += 2) {
130 for (j = 0; j < hrir_info.frames - 1; j++) {
131 printf(
"%.16f,%s", hrir_data[ir_current * hrir_info.frames + j], ((j + 1) % 4 ?
" " :
"\n"));
134 printf(
"%.16f", hrir_data[ir_current * hrir_info.frames + hrir_info.frames - 1]);
136 if (ir_current + 2 < impulse_response_index_end) {
143 fprintf(stderr,
"INFO: Successfully converted: imported %d impulse responses.\n", impulse_response_index_end - impulse_response_index_start);