sphear_octa_af_calibrate.m 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. %% -*- mode: octave -*-
  2. %%
  3. %% *SpHEAR Project
  4. %%
  5. %% sphear_af_octa_calibrate: read reference microphone signal, filter with
  6. %% convolution kernel created by DRC and filter
  7. %% all recorded signals, calibrated A format files
  8. %% are written to disk
  9. %%
  10. %% usage:
  11. %% [] = sphear_af_octa_calibrate(measurements, keep, fade)
  12. %%
  13. %% keep: time to keep after main impulse in seconds
  14. %% fade: fade out time after keep in seconds
  15. %%
  16. %% Copyright 2016-2017, Fernando Lopez-Lezcano, All Rights Reserved
  17. %% nando@ccrma.stanford.edu
  18. %%
  19. %% This program is free software: you can redistribute it and/or modify
  20. %% it under the terms of the GNU General Public License as published by
  21. %% the Free Software Foundation, either version 3 of the License, or
  22. %% (at your option) any later version.
  23. %%
  24. %% This program is distributed in the hope that it will be useful,
  25. %% but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. %% GNU General Public License for more details.
  28. %%
  29. %% You should have received a copy of the GNU General Public License
  30. %% along with this program. If not, see <http://www.gnu.org/licenses/>.
  31. function [] = sphear_octa_af_calibrate(measurements, keep, fade, suffix);
  32. if (! exist("suffix"))
  33. suffix = "";
  34. end
  35. %% the measurement from the reference microphone is processed through
  36. %% DRC (Digital Room Correction) to create a convolution kernel that is
  37. %% used to equalize the measurements
  38. %%
  39. %% read the convolution kernel
  40. [ref, Fs] = wavread('../data/current/cal/drc-filter.wav');
  41. octanames = cellstr(['1'; '2'; '3'; '4'; '5'; '6'; '7'; '8']);
  42. loc_min = intmax;
  43. loc_max = 0;
  44. %% all requested measurements
  45. for m = measurements
  46. printf("processing measurement %d\n", m);
  47. %% read in capsule signals and normalize them
  48. for c = 1:8
  49. sig = wavread(["../data/current/af/a-format-" sprintf("%s%03d", suffix, m) "-" char(octanames(c)) ".wav"]);
  50. cal_sig(m,c,:) = conv(ref, sig);
  51. %% find first non-zero sample of convolved signal
  52. head = find(cal_sig(m,c,:)!=0, 1, 'first');
  53. if (head < loc_min)
  54. loc_min = head;
  55. end
  56. if (head > loc_max)
  57. loc_max = head;
  58. end
  59. end
  60. end
  61. %% now write all the calibrated impulse responses
  62. %% choose a arbitrary multiple of input size... sigh
  63. out_size = 4 * size(sig, 1);
  64. range = loc_min - 1:loc_min - 1 + out_size;
  65. %% 5% end window
  66. wend = tukeywin(2 * out_size, 0.9)(end/2:end)';
  67. printf("start sample: min = %f, max = %f, output size = %f\n", loc_min, loc_max, out_size);
  68. for m = measurements
  69. for c = 1:8
  70. wavwrite(cal_sig(m,c,:)(range) .* wend, Fs, ["../data/current/af/a-format-cal-" sprintf("%s%03d", suffix, m) "-" char(octanames(c)) ".wav"]);
  71. end
  72. %% wavwrite(cal_sig, Fs, ["../data/current/af/a-format-cal-" sprintf("%s%03d", suffix, m) ".wav"]);
  73. end
  74. end