hrtf.m 839 B

12345678910111213141516171819202122232425262728293031323334353637
  1. % Load HRTF (Head Related Transfer Functions) for a given azimuth.
  2. % B. Gardner and K. Martin. Head Related Transfer Functions of a Dummy Head
  3. % http://sound.media.mit.edu/ica-bench/.
  4. function f = hrtf( az)
  5. % Bring in 0-360 degrees region
  6. while az > 360
  7. az = az - 360;
  8. end
  9. while az < 0
  10. az = az + 360;
  11. end
  12. % 180+x = flipped x
  13. flip = 0;
  14. if az > 180
  15. az = az - 180;
  16. flip = 1;
  17. end
  18. % Load filters
  19. fname = sprintf( 'hrtf/H0e%.3da.dat', az);
  20. fid = fopen( fname, 'r', 'ieee-be');
  21. if fid == -1
  22. error( sprintf( 'Cannot open file %s', fname));
  23. end
  24. tmp = fread( fid, inf, 'short');
  25. fclose( fid);
  26. % Assign to output and scale
  27. % filters are at 44100, decimate to the default 22050
  28. if ~flip
  29. f = [decimate( tmp(1:2:end), 2)' ; decimate( tmp(2:2:end), 2)']/32767;
  30. else
  31. f = [decimate( tmp(2:2:end), 2)' ; decimate( tmp(1:2:end), 2)']/32767;
  32. end