1
0

sphear_a2b_soundfile.m 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. %%
  2. %% *SpHEAR Project
  3. %% sphear_a2b_soundfile: read in A format soundfiles and render B format outputs
  4. %%
  5. %% usage:
  6. %% [] = sphear_a2b_soundfile(FIR, ifile, ofile, start, duration, Fs, Nfft)
  7. %%
  8. %% FIR: A2B matrix of FIR filters
  9. %% ifile: input soundfile (first four channels are the A-format signal)
  10. %% ofile: output soundfile, currently ignored
  11. %% start: start time in seconds from the beginning of the file
  12. %% duration: duration in seconds of processed segment
  13. %% Fs: sampling rate
  14. %% Nfft: size of the FFT used to do the filtering
  15. %%
  16. %% Copyright 2016, 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 [BF] = sphear_a2b_soundfile(FIR, ifile, ofile, start, duration, Fs, Nfft)
  32. [AF, FS, BPS] = wavread(ifile, [start, (start + duration)] .* Fs);
  33. printf("sr = %d, bits = %d\n", FS, BPS);
  34. w1 = fftfilt(reshape(FIR(1,1,:), 1, [])', AF(:,1), Nfft);
  35. x1 = fftfilt(reshape(FIR(2,1,:), 1, [])', AF(:,1), Nfft);
  36. y1 = fftfilt(reshape(FIR(3,1,:), 1, [])', AF(:,1), Nfft);
  37. z1 = fftfilt(reshape(FIR(4,1,:), 1, [])', AF(:,1), Nfft);
  38. w2 = fftfilt(reshape(FIR(1,2,:), 1, [])', AF(:,2), Nfft);
  39. x2 = fftfilt(reshape(FIR(2,2,:), 1, [])', AF(:,2), Nfft);
  40. y2 = fftfilt(reshape(FIR(3,2,:), 1, [])', AF(:,2), Nfft);
  41. z2 = fftfilt(reshape(FIR(4,2,:), 1, [])', AF(:,2), Nfft);
  42. w3 = fftfilt(reshape(FIR(1,3,:), 1, [])', AF(:,3), Nfft);
  43. x3 = fftfilt(reshape(FIR(2,3,:), 1, [])', AF(:,3), Nfft);
  44. y3 = fftfilt(reshape(FIR(3,3,:), 1, [])', AF(:,3), Nfft);
  45. z3 = fftfilt(reshape(FIR(4,3,:), 1, [])', AF(:,3), Nfft);
  46. w4 = fftfilt(reshape(FIR(1,4,:), 1, [])', AF(:,4), Nfft);
  47. x4 = fftfilt(reshape(FIR(2,4,:), 1, [])', AF(:,4), Nfft);
  48. y4 = fftfilt(reshape(FIR(3,4,:), 1, [])', AF(:,4), Nfft);
  49. z4 = fftfilt(reshape(FIR(4,4,:), 1, [])', AF(:,4), Nfft);
  50. wc = (w1 + w2 + w3 + w4) ./ (sqrt(2)/2);
  51. xc = (x1 + x2 + x3 + x4);
  52. yc = (y1 + y2 + y3 + y4);
  53. zc = (z1 + z2 + z3 + z4);
  54. BF(:,1) = wc;
  55. BF(:,2) = xc;
  56. BF(:,3) = yc;
  57. BF(:,4) = zc;
  58. att = 0.005;
  59. wavwrite(BF * att, Fs, 32, ["mattness-b-format-w.wav"]);
  60. end