BinauralSound.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 BinauralSound.h
  19. * @ingroup fx
  20. * The BinauralSound class.
  21. */
  22. #include "ISound.h"
  23. #include "HRTF.h"
  24. #include "Source.h"
  25. #include "util/ThreadPool.h"
  26. #include "util/FFTPlan.h"
  27. #include <memory>
  28. #include <vector>
  29. AUD_NAMESPACE_BEGIN
  30. /**
  31. * This class represents a sound that can sound different depending on its realtive position with the listener.
  32. */
  33. class AUD_API BinauralSound : public ISound
  34. {
  35. private:
  36. /**
  37. * A pointer to the imput sound.
  38. */
  39. std::shared_ptr<ISound> m_sound;
  40. /**
  41. * A pointer to an HRTF object with a collection of impulse responses.
  42. */
  43. std::shared_ptr<HRTF> m_hrtfs;
  44. /**
  45. * A pointer to a Source object which represents the source of the sound.
  46. */
  47. std::shared_ptr<Source> m_source;
  48. /**
  49. * A shared ptr to a thread pool.
  50. */
  51. std::shared_ptr<ThreadPool> m_threadPool;
  52. /**
  53. * A shared ponter to an FFT plan.
  54. */
  55. std::shared_ptr<FFTPlan> m_plan;
  56. // delete copy constructor and operator=
  57. BinauralSound(const BinauralSound&) = delete;
  58. BinauralSound& operator=(const BinauralSound&) = delete;
  59. public:
  60. /**
  61. * Creates a new ConvolverSound.
  62. * \param sound The sound that will be convolved. It must have only one channel.
  63. * \param hrtfs The HRTF set that will be used.
  64. * \param source A shared pointer to a Source object that contains the source of the sound.
  65. * \param threadPool A shared pointer to a ThreadPool object with 1 or more threads.
  66. * \param plan A shared pointer to a FFTPlan object that will be used for convolution.
  67. * \warning The same FFTPlan object must be used to construct both this and the HRTF object provided.
  68. */
  69. BinauralSound(std::shared_ptr<ISound> sound, std::shared_ptr<HRTF> hrtfs, std::shared_ptr<Source> source, std::shared_ptr<ThreadPool> threadPool, std::shared_ptr<FFTPlan> plan);
  70. /**
  71. * Creates a new BinauralSound. A default FFT plan will be created.
  72. * \param sound The sound that will be convolved. Must have only one channel.
  73. * \param hrtfs The HRTF set that will be used.
  74. * \param source A shared pointer to a Source object that contains the source of the sound.
  75. * \param threadPool A shared pointer to a ThreadPool object with 1 or more threads.
  76. * \warning To use this constructor no FFTPlan object must have been provided to the hrtfs.
  77. */
  78. BinauralSound(std::shared_ptr<ISound> sound, std::shared_ptr<HRTF> hrtfs, std::shared_ptr<Source> source, std::shared_ptr<ThreadPool> threadPool);
  79. virtual std::shared_ptr<IReader> createReader();
  80. /**
  81. * Retrieves the HRTF set being used.
  82. * \return A shared pointer to the current HRTF object being used.
  83. */
  84. std::shared_ptr<HRTF> getHRTFs();
  85. /**
  86. * Changes the set of HRTFs used for convolution, it'll only affect newly created readers.
  87. * \param hrtfs A shared pointer to the new HRTF object.
  88. */
  89. void setHRTFs(std::shared_ptr<HRTF> hrtfs);
  90. /**
  91. * Retrieves the Source object being used.
  92. * \return A shared pointer to the current Source object being used.
  93. */
  94. std::shared_ptr<Source> getSource();
  95. /**
  96. * Changes the Source object used to change the source position of the sound.
  97. * \param source A shared pointer to the new Source object.
  98. */
  99. void setSource(std::shared_ptr<Source> source);
  100. };
  101. AUD_NAMESPACE_END