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