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