HRTF.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 HRTF.h
  19. * @ingroup fx
  20. * The HRTF class.
  21. */
  22. #include "util/StreamBuffer.h"
  23. #include "util/FFTPlan.h"
  24. #include "ImpulseResponse.h"
  25. #include <memory>
  26. #include <vector>
  27. #include <unordered_map>
  28. #include <utility>
  29. AUD_NAMESPACE_BEGIN
  30. /**
  31. * This class represents a complete set of HRTFs.
  32. */
  33. class AUD_API HRTF
  34. {
  35. private:
  36. /**
  37. * An unordered map of unordered maps containing the ImpulseResponse objects of the HRTFs.
  38. */
  39. std::unordered_map<float, std::unordered_map<float, std::shared_ptr<ImpulseResponse>>> m_hrtfs;
  40. /**
  41. * The FFTPlan used to create the ImpulseResponses.
  42. */
  43. std::shared_ptr<FFTPlan> m_plan;
  44. /**
  45. * The specifications of the HRTFs.
  46. */
  47. Specs m_specs;
  48. /**
  49. * True if the HRTF object is empty.
  50. */
  51. bool m_empty;
  52. // delete copy constructor and operator=
  53. HRTF(const HRTF&) = delete;
  54. HRTF& operator=(const HRTF&) = delete;
  55. public:
  56. /**
  57. * Creates a new empty HRTF object that will instance it own FFTPlan with default size.
  58. */
  59. HRTF();
  60. /**
  61. * Creates a new empty HRTF object.
  62. * \param plan A shared pointer to a FFT plan used to transform the impulse responses added.
  63. */
  64. HRTF(std::shared_ptr<FFTPlan> plan);
  65. /**
  66. * Adds a new HRTF to the class.
  67. * \param impulseResponse A shared pointer to an StreamBuffer with the HRTF.
  68. * \param azimuth The azimuth angle of the HRTF. Interval [0,360).
  69. * \param elevation The elevation angle of the HRTF.
  70. * \return True if the impulse response was added successfully, false otherwise (the specs weren't correct).
  71. */
  72. bool addImpulseResponse(std::shared_ptr<StreamBuffer> impulseResponse, float azimuth, float elevation);
  73. /**
  74. * Retrieves a pair of HRTFs for a certain azimuth and elevation. If no exact match is found, the closest ones will be chosen (the elevation has priority over the azimuth).
  75. * \param[in,out] azimuth The desired azimuth angle. If no exact match is found, the value of azimuth will represent the actual azimuth elevation of the chosen HRTF. Interval [0,360)
  76. * \param[in,out] elevation The desired elevation angle. If no exact match is found, the value of elevation will represent the actual elevation angle of the chosen HRTF.
  77. * \return A pair of shared pointers to ImpulseResponse objects containing the HRTFs for the left (first element) and right (second element) ears.
  78. */
  79. std::pair<std::shared_ptr<ImpulseResponse>, std::shared_ptr<ImpulseResponse>> getImpulseResponse(float &azimuth, float &elevation);
  80. /**
  81. * Retrieves the specs shared by all the HRTFs.
  82. * \return The shared specs of all the HRTFs.
  83. */
  84. Specs getSpecs();
  85. /**
  86. * Retrieves the state of the HRTF object.
  87. * \return True if it is empty, false otherwise.
  88. */
  89. bool isEmpty();
  90. };
  91. AUD_NAMESPACE_END