1
0

sphear_a2b_soundfile.m 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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)
  7. %%
  8. %% FIR: A2B matrix of FIR filters
  9. %%
  10. %% Copyright 2016, Fernando Lopez-Lezcano, All Rights Reserved
  11. %% nando@ccrma.stanford.edu
  12. %%
  13. %% This program is free software: you can redistribute it and/or modify
  14. %% it under the terms of the GNU General Public License as published by
  15. %% the Free Software Foundation, either version 3 of the License, or
  16. %% (at your option) any later version.
  17. %%
  18. %% This program is distributed in the hope that it will be useful,
  19. %% but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. %% GNU General Public License for more details.
  22. %%
  23. %% You should have received a copy of the GNU General Public License
  24. %% along with this program. If not, see <http://www.gnu.org/licenses/>.
  25. function [BF] = sphear_a2b_soundfile(FIR, ifile, ofile, start, duration, Fs, Nfft)
  26. [AF, FS, BPS] = wavread(ifile, [start, (start + duration)] .* Fs);
  27. printf("sr = %d, bits = %d\n", FS, BPS);
  28. w1 = fftfilt(reshape(FIR(1,1,:), 1, [])', AF(:,1), Nfft);
  29. x1 = fftfilt(reshape(FIR(2,1,:), 1, [])', AF(:,1), Nfft);
  30. y1 = fftfilt(reshape(FIR(3,1,:), 1, [])', AF(:,1), Nfft);
  31. z1 = fftfilt(reshape(FIR(4,1,:), 1, [])', AF(:,1), Nfft);
  32. w2 = fftfilt(reshape(FIR(1,2,:), 1, [])', AF(:,2), Nfft);
  33. x2 = fftfilt(reshape(FIR(2,2,:), 1, [])', AF(:,2), Nfft);
  34. y2 = fftfilt(reshape(FIR(3,2,:), 1, [])', AF(:,2), Nfft);
  35. z2 = fftfilt(reshape(FIR(4,2,:), 1, [])', AF(:,2), Nfft);
  36. w3 = fftfilt(reshape(FIR(1,3,:), 1, [])', AF(:,3), Nfft);
  37. x3 = fftfilt(reshape(FIR(2,3,:), 1, [])', AF(:,3), Nfft);
  38. y3 = fftfilt(reshape(FIR(3,3,:), 1, [])', AF(:,3), Nfft);
  39. z3 = fftfilt(reshape(FIR(4,3,:), 1, [])', AF(:,3), Nfft);
  40. w4 = fftfilt(reshape(FIR(1,4,:), 1, [])', AF(:,4), Nfft);
  41. x4 = fftfilt(reshape(FIR(2,4,:), 1, [])', AF(:,4), Nfft);
  42. y4 = fftfilt(reshape(FIR(3,4,:), 1, [])', AF(:,4), Nfft);
  43. z4 = fftfilt(reshape(FIR(4,4,:), 1, [])', AF(:,4), Nfft);
  44. wc = (w1 + w2 + w3 + w4) ./ (2 * sqrt(2)/2);
  45. xc = (x1 + x2 + x3 + x4);
  46. yc = (y1 + y2 + y3 + y4);
  47. zc = (z1 + z2 + z3 + z4);
  48. BF(:,1) = wc;
  49. BF(:,2) = xc;
  50. BF(:,3) = yc;
  51. BF(:,4) = zc;
  52. att = 0.01;
  53. wavwrite(BF * att, Fs, 32, ["mattness-b-format-w.wav"]);
  54. end