ConvolverSound.h 3.2 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 ConvolverSound.h
  19. * @ingroup fx
  20. * The ConvolverSound class.
  21. */
  22. #include "ISound.h"
  23. #include "ImpulseResponse.h"
  24. #include "util/ThreadPool.h"
  25. #include "util/FFTPlan.h"
  26. #include <memory>
  27. #include <vector>
  28. AUD_NAMESPACE_BEGIN
  29. /**
  30. * This class represents a sound that can be modified depending on a given impulse response.
  31. */
  32. class AUD_API ConvolverSound : public ISound
  33. {
  34. private:
  35. /**
  36. * A pointer to the imput sound.
  37. */
  38. std::shared_ptr<ISound> m_sound;
  39. /**
  40. * A pointer to the impulse response.
  41. */
  42. std::shared_ptr<ImpulseResponse> m_impulseResponse;
  43. /**
  44. * A shared ptr to a thread pool.
  45. */
  46. std::shared_ptr<ThreadPool> m_threadPool;
  47. /**
  48. * A shared ponter to an FFT plan.
  49. */
  50. std::shared_ptr<FFTPlan> m_plan;
  51. // delete copy constructor and operator=
  52. ConvolverSound(const ConvolverSound&) = delete;
  53. ConvolverSound& operator=(const ConvolverSound&) = delete;
  54. public:
  55. /**
  56. * Creates a new ConvolverSound.
  57. * \param sound The sound that will be convolved.
  58. * \param impulseResponse The impulse response sound.
  59. * \param threadPool A shared pointer to a ThreadPool object with 1 or more threads.
  60. * \param plan A shared pointer to a FFTPlan object that will be used for convolution.
  61. * \warning The same FFTPlan object must be used to construct both this and the ImpulseResponse object provided.
  62. */
  63. ConvolverSound(std::shared_ptr<ISound> sound, std::shared_ptr<ImpulseResponse> impulseResponse, std::shared_ptr<ThreadPool> threadPool, std::shared_ptr<FFTPlan> plan);
  64. /**
  65. * Creates a new ConvolverSound. A default FFT plan will be created.
  66. * \param sound The sound that will be convolved.
  67. * \param impulseResponse The impulse response sound.
  68. * \param threadPool A shared pointer to a ThreadPool object with 1 or more threads.
  69. * \warning To use this constructor no FFTPlan object must have been provided to the inpulseResponse.
  70. */
  71. ConvolverSound(std::shared_ptr<ISound> sound, std::shared_ptr<ImpulseResponse> impulseResponse, std::shared_ptr<ThreadPool> threadPool);
  72. virtual std::shared_ptr<IReader> createReader();
  73. /**
  74. * Retrieves the impulse response sound being used.
  75. * \return A shared pointer to the current impulse response being used.
  76. */
  77. std::shared_ptr<ImpulseResponse> getImpulseResponse();
  78. /**
  79. * Changes the inpulse response used for convolution, it'll only affect newly created readers.
  80. * \param impulseResponse A shared pointer to the new impulse response sound.
  81. */
  82. void setImpulseResponse(std::shared_ptr<ImpulseResponse> impulseResponse);
  83. };
  84. AUD_NAMESPACE_END