HRTFLoader.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*******************************************************************************
  2. * Copyright 2015-2016 Juan Francisco Crespo Galán
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. ******************************************************************************/
  16. #pragma once
  17. /**
  18. * @file HRTFLoader.h
  19. * @ingroup fx
  20. * The HRTFLoader class.
  21. */
  22. #include "Audaspace.h"
  23. #include "fx/HRTF.h"
  24. #include "util/FFTPlan.h"
  25. #include <string>
  26. #include <memory>
  27. AUD_NAMESPACE_BEGIN
  28. /**
  29. * This loader provides a method to load all the HRTFs in one directory, provided they follow the following naming scheme:
  30. * Example: L-10e210a.wav
  31. * The first character refers to the ear from which the HRTF was recorded: 'L' for a left ear and 'R' for a right ear.
  32. * Next is the elevation angle followed by the 'e' character. [-90, 90]
  33. * Then is the azimuth angle followed by the 'a' character. [0, 360)
  34. * For a sound source situated at the left of the listener the azimuth angle regarding the left ear is 90 while the angle regarding the right ear is 270.
  35. * KEMAR HRTFs use this naming scheme.
  36. */
  37. class AUD_API HRTFLoader
  38. {
  39. private:
  40. // delete normal constructor, copy constructor and operator=
  41. HRTFLoader(const HRTFLoader&) = delete;
  42. HRTFLoader& operator=(const HRTFLoader&) = delete;
  43. HRTFLoader() = delete;
  44. public:
  45. /**
  46. * Loads all the left ear HRTFs in the directory.Onle one ear HRTFs for all azimuths [0,360) are needed for binaural sound.
  47. * \param plan The plan that will be used to create the HRTF object.
  48. * \param fileExtension The extension of the HRTF files.
  49. * \param path The path to the folder containing the HRTFs.
  50. * \return A shared pointer to a loaded HRTF object.
  51. */
  52. static std::shared_ptr<HRTF> loadLeftHRTFs(std::shared_ptr<FFTPlan> plan, const std::string& fileExtension, const std::string& path = "");
  53. /**
  54. * Loads all the right ear HRTFs in the directory. Onle one ear HRTFs for all azimuths [0,360) are needed for binaural sound.
  55. * \param plan The plan that will be used to create the HRTF object.
  56. * \param fileExtension The extension of the HRTF files.
  57. * \param path The path to the folder containing the HRTFs.
  58. * \return A shared pointer to a loaded HRTF object.
  59. */
  60. static std::shared_ptr<HRTF> loadRightHRTFs(std::shared_ptr<FFTPlan> plan, const std::string& fileExtension, const std::string& path = "");
  61. /**
  62. * Loads all the left ear HRTFs in the directory.Onle one ear HRTFs for all azimuths [0,360) are needed for binaural sound.
  63. * \param fileExtension The extension of the HRTF files.
  64. * \param path The path to the folder containing the HRTFs.
  65. * \return A shared pointer to a loaded HRTF object.
  66. */
  67. static std::shared_ptr<HRTF> loadLeftHRTFs(const std::string& fileExtension, const std::string& path = "");
  68. /**
  69. * Loads all the right ear HRTFs in the directory. Onle one ear HRTFs for all azimuths [0,360) are needed for binaural sound.
  70. * \param fileExtension The extension of the HRTF files.
  71. * \param path The path to the folder containing the HRTFs.
  72. * \return A shared pointer to a loaded HRTF object.
  73. */
  74. static std::shared_ptr<HRTF> loadRightHRTFs(const std::string& fileExtension, const std::string& path = "");
  75. private:
  76. /**
  77. * Loads all the HRTFs in the directory and subdirectories.
  78. * \param hrtfs An HRTF object in which to load the HRTFs.
  79. * \param ear 'L' to load left ear HRTFs, 'R' to load right ear HRTFs.
  80. * \param fileExtension The extension of the HRTF files.
  81. * \param path The path to the folder containing the HRTFs.
  82. */
  83. static void loadHRTFs(std::shared_ptr<HRTF>hrtfs, char ear, const std::string& fileExtension, const std::string& path = "");
  84. };
  85. AUD_NAMESPACE_END