diff options
Diffstat (limited to 'extern/audaspace/include/fx')
53 files changed, 4767 insertions, 0 deletions
diff --git a/extern/audaspace/include/fx/ADSR.h b/extern/audaspace/include/fx/ADSR.h new file mode 100644 index 00000000000..c453f2477e1 --- /dev/null +++ b/extern/audaspace/include/fx/ADSR.h @@ -0,0 +1,121 @@ +/******************************************************************************* + * Copyright 2009-2016 Jörg Müller + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +#pragma once + +/** + * @file ADSR.h + * @ingroup fx + * The ADSR class. + */ + +#include "fx/Effect.h" + +AUD_NAMESPACE_BEGIN + +/** + * The ADSR effect implements the Attack-Delay-Sustain-Release behaviour of a sound. + */ +class AUD_API ADSR : public Effect +{ +private: + /** + * Attack time. + */ + float m_attack; + + /** + * Decay time. + */ + float m_decay; + + /** + * Sustain level. + */ + float m_sustain; + + /** + * Release time. + */ + float m_release; + + // delete copy constructor and operator= + ADSR(const ADSR&) = delete; + ADSR& operator=(const ADSR&) = delete; + +public: + /** + * Creates a new ADSR object. + * @param sound The sound to apply this effect to. + * @param attack The attack time in seconds. + * @param decay The decay time in seconds. + * @param sustain The sustain level as linear volume. + * @param release The release time in seconds. + */ + ADSR(std::shared_ptr<ISound> sound, float attack, float decay, float sustain, float release); + + /** + * Returns the attack time. + * @return The attack time in seconds. + */ + float getAttack() const; + + /** + * Sets the attack time. + * @param attack The attack time in seconds. + */ + void setAttack(float attack); + + /** + * Returns the decay time. + * @return The decay time in seconds. + */ + float getDecay() const; + + /** + * Sets the decay time. + * @param decay The decay time in seconds. + */ + void setDecay(float decay); + + /** + * Returns the sustain level. + * @return The sustain level in linear volume. + */ + float getSustain() const; + + /** + * Sets the sustain level. + * @param sustain The sustain level in linear volume. + */ + void setSustain(float sustain); + + /** + * Returns the release time. + * @return The release time in seconds. + */ + float getRelease() const; + + /** + * Sets the release time. + * @param release The release time in seconds. + */ + void setRelease(float release); + + virtual std::shared_ptr<IReader> createReader(); +}; + +AUD_NAMESPACE_END diff --git a/extern/audaspace/include/fx/ADSRReader.h b/extern/audaspace/include/fx/ADSRReader.h new file mode 100644 index 00000000000..a9ec076a1c5 --- /dev/null +++ b/extern/audaspace/include/fx/ADSRReader.h @@ -0,0 +1,101 @@ +/******************************************************************************* + * Copyright 2009-2016 Jörg Müller + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +#pragma once + +/** + * @file ADSRReader.h + * @ingroup fx + * The ADSRReader class. + */ + +#include "fx/EffectReader.h" + +AUD_NAMESPACE_BEGIN + +/** + * This class is an ADSR filters. + */ +class AUD_API ADSRReader : public EffectReader +{ +private: + enum ADSRState + { + ADSR_STATE_INVALID = 0, /// Invalid ADSR state or finished. + ADSR_STATE_ATTACK = 1, /// Initial attack state. + ADSR_STATE_DECAY = 2, /// Decay state. + ADSR_STATE_SUSTAIN = 3, /// Sustain state. + ADSR_STATE_RELEASE = 4 /// Release state. + }; + + /** + * Attack time. + */ + float m_attack; + + /** + * Decay time. + */ + float m_decay; + + /** + * Sustain level. + */ + float m_sustain; + + /** + * Release time. + */ + float m_release; + + /** + * Current state. + */ + ADSRState m_state; + + /** + * Current level. + */ + float m_level; + + // delete copy constructor and operator= + ADSRReader(const ADSRReader&) = delete; + ADSRReader& operator=(const ADSRReader&) = delete; + + void AUD_LOCAL nextState(ADSRState state); + +public: + /** + * Creates a new ADSR reader. + * \param reader The reader to read from. + * \param attack The attack time in seconds. + * \param decay The decay time in seconds. + * \param sustain The sustain level, should be in range [0 - 1]. + * \param release The release time in seconds. + */ + ADSRReader(std::shared_ptr<IReader> reader, float attack, float decay, float sustain, float release); + + virtual ~ADSRReader(); + + virtual void read(int& length, bool& eos, sample_t* buffer); + + /** + * Triggers the release. + */ + void release(); +}; + +AUD_NAMESPACE_END diff --git a/extern/audaspace/include/fx/Accumulator.h b/extern/audaspace/include/fx/Accumulator.h new file mode 100644 index 00000000000..d0c635d663c --- /dev/null +++ b/extern/audaspace/include/fx/Accumulator.h @@ -0,0 +1,79 @@ +/******************************************************************************* + * Copyright 2009-2016 Jörg Müller + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +#pragma once + +/** + * @file Accumulator.h + * @ingroup fx + * The Accumulator class. + */ + +#include "fx/Effect.h" + +AUD_NAMESPACE_BEGIN + +class CallbackIIRFilterReader; + +/** + * This sound creates an accumulator reader. + * + * The accumulator adds the difference at the input to the last output in case + * it's positive. In additive mode it additionaly adds the difference always. + * So in case the difference is positive, it's added twice. + */ +class AUD_API Accumulator : public Effect +{ +private: + /** + * Whether the accumulator is additive. + */ + const bool m_additive; + + // delete copy constructor and operator= + Accumulator(const Accumulator&) = delete; + Accumulator& operator=(const Accumulator&) = delete; + +public: + /** + * Creates a new accumulator sound. + * \param sound The input sound. + * \param additive Whether the accumulator is additive. + */ + Accumulator(std::shared_ptr<ISound> sound, bool additive = false); + + virtual std::shared_ptr<IReader> createReader(); + + /** + * The accumulatorFilterAdditive function implements the doFilterIIR callback + * for the additive accumulator filter. + * @param reader The CallbackIIRFilterReader that executes the callback. + * @param useless A user defined pointer that is not needed for this filter. + * @return The filtered sample. + */ + static sample_t AUD_LOCAL accumulatorFilterAdditive(CallbackIIRFilterReader* reader, void* useless); + + /** + * The accumulatorFilter function implements the doFilterIIR callback + * for the non-additive accumulator filter. + * @param reader The CallbackIIRFilterReader that executes the callback. + * @param useless A user defined pointer that is not needed for this filter. + * @return The filtered sample. + */ + static sample_t AUD_LOCAL accumulatorFilter(CallbackIIRFilterReader* reader, void* useless); +}; + +AUD_NAMESPACE_END diff --git a/extern/audaspace/include/fx/BaseIIRFilterReader.h b/extern/audaspace/include/fx/BaseIIRFilterReader.h new file mode 100644 index 00000000000..193b98578de --- /dev/null +++ b/extern/audaspace/include/fx/BaseIIRFilterReader.h @@ -0,0 +1,133 @@ +/******************************************************************************* + * Copyright 2009-2016 Jörg Müller + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +#pragma once + +/** + * @file BaseIIRFilterReader.h + * @ingroup fx + * The BaseIIRFilterReader class. + */ + +#include "fx/EffectReader.h" + +AUD_NAMESPACE_BEGIN + +/** + * This class is a base class for infinite impulse response filters. + */ +class AUD_API BaseIIRFilterReader : public EffectReader +{ +private: + /** + * Specs. + */ + Specs m_specs; + + /** + * Length of input samples needed. + */ + int m_xlen; + + /** + * Length of output samples needed. + */ + int m_ylen; + + /** + * The last in samples array. + */ + sample_t* m_x; + + /** + * The last out samples array. + */ + sample_t* m_y; + + /** + * Position of the current input sample in the input array. + */ + int m_xpos; + + /** + * Position of the current output sample in the output array. + */ + int m_ypos; + + /** + * Current channel. + */ + int m_channel; + + // delete copy constructor and operator= + BaseIIRFilterReader(const BaseIIRFilterReader&) = delete; + BaseIIRFilterReader& operator=(const BaseIIRFilterReader&) = delete; + +protected: + /** + * Creates a new base IIR filter reader. + * \param reader The reader to read from. + * \param in The count of past input samples needed. + * \param out The count of past output samples needed. + */ + BaseIIRFilterReader(std::shared_ptr<IReader> reader, int in, int out); + + /** + * Sets the length for the required input and output samples of the IIR filter. + * @param in The amount of past input samples needed, including the current one. + * @param out The amount of past output samples needed. + */ + void setLengths(int in, int out); + +public: + /** + * Retrieves the last input samples. + * \param pos The position, valid are 0 (current) or negative values. + * \return The sample value. + */ + inline sample_t x(int pos) + { + return m_x[(m_xpos + pos + m_xlen) % m_xlen * m_specs.channels + m_channel]; + } + + /** + * Retrieves the last output samples. + * \param pos The position, valid are negative values. + * \return The sample value. + */ + inline sample_t y(int pos) + { + return m_y[(m_ypos + pos + m_ylen) % m_ylen * m_specs.channels + m_channel]; + } + + virtual ~BaseIIRFilterReader(); + + virtual void read(int& length, bool& eos, sample_t* buffer); + + /** + * Runs the filtering function. + * \return The current output sample value. + */ + virtual sample_t filter()=0; + + /** + * Notifies the filter about a sample rate change. + * \param rate The new sample rate. + */ + virtual void sampleRateChanged(SampleRate rate); +}; + +AUD_NAMESPACE_END diff --git a/extern/audaspace/include/fx/BinauralReader.h b/extern/audaspace/include/fx/BinauralReader.h new file mode 100644 index 00000000000..f5667a093f6 --- /dev/null +++ b/extern/audaspace/include/fx/BinauralReader.h @@ -0,0 +1,223 @@ +/******************************************************************************* +* Copyright 2015-2016 Juan Francisco Crespo Galán +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +******************************************************************************/ + +#pragma once + +/** +* @file BinauralReader.h +* @ingroup fx +* The BinauralReader class. +*/ + +#include "IReader.h" +#include "ISound.h" +#include "Convolver.h" +#include "HRTF.h" +#include "Source.h" +#include "util/FFTPlan.h" +#include "util/ThreadPool.h" + +#include <memory> +#include <vector> +#include <future> + +AUD_NAMESPACE_BEGIN + +/** +* This class represents a reader for a sound that can sound different depending on its realtive position with the listener. +*/ +class AUD_API BinauralReader : public IReader +{ +private: + /** + * The current position. + */ + int m_position; + + /** + * The reader of the input sound. + */ + std::shared_ptr<IReader> m_reader; + + /** + * The HRTF set. + */ + std::shared_ptr<HRTF> m_hrtfs; + + /** + * A Source object that will be used to change the source position of the sound. + */ + std::shared_ptr<Source> m_source; + + /** + * The intended azimuth. + */ + float m_Azimuth; + + /** + * The intended elevation. + */ + float m_Elevation; + + /** + * The real azimuth being used. + */ + float m_RealAzimuth; + + /** + * The real elevation being used. + */ + float m_RealElevation; + + /** + * The FFT size, given by the FFTPlan. + */ + int m_N; + + /** + * The length of the impulse response fragments, m_N/2 will be used. + */ + int m_M; + + /** + * The max length of the input slices, m_N/2 will be used. + */ + int m_L; + + /** + * The array of convolvers that will be used, one per channel. + */ + std::vector<std::unique_ptr<Convolver>> m_convolvers; + + /** + * True if a transition is happening. + */ + bool m_transition; + + /** + * The position of the current transition (decreasing) + */ + int m_transPos; + + /** + * The output buffer in which the convolved data will be written and from which the reader will read. + */ + sample_t* m_outBuffer; + + /** + * The input buffer that will hold the data to be convolved. + */ + sample_t* m_inBuffer; + + /** + * Current position in which the m_outBuffer is being read. + */ + int m_outBufferPos; + + /** + * Length of rhe m_outBuffer. + */ + int m_outBufLen; + + /** + * Effective length of rhe m_outBuffer. + */ + int m_eOutBufLen; + + /** + * Flag indicating whether the end of the sound has been reached or not. + */ + bool m_eosReader; + + /** + * Flag indicating whether the end of the extra data generated in the convolution has been reached or not. + */ + bool m_eosTail; + + /** + * A vector of buffers (one per channel) on which the audio signal will be separated per channel so it can be convolved. + */ + std::vector<sample_t*> m_vecOut; + + /** + * A shared ptr to a thread pool. + */ + std::shared_ptr<ThreadPool> m_threadPool; + + /** + * Length of the input data to be used by the channel threads. + */ + int m_lastLengthIn; + + /** + * A vector of futures to sync tasks. + */ + std::vector<std::future<int>> m_futures; + + // delete copy constructor and operator= + BinauralReader(const BinauralReader&) = delete; + BinauralReader& operator=(const BinauralReader&) = delete; + +public: + /** + * Creates a new convolver reader. + * \param reader A reader of the input sound to be assigned to this reader. It must have one channel. + * \param hrtfs A shared pointer to an HRTF object that will be used to get a particular impulse response depending on the source. + * \param source A shared pointer to a Source object that will be used to change the source position of the sound. + * \param threadPool A shared pointer to a ThreadPool object with 1 or more threads. + * \param plan A shared pointer to and FFT plan that will be used for convolution. + * \exception Exception thrown if the specs of the HRTFs and the sound don't match or if the provided HRTF object is empty. + */ + BinauralReader(std::shared_ptr<IReader> reader, std::shared_ptr<HRTF> hrtfs, std::shared_ptr<Source> source, std::shared_ptr<ThreadPool> threadPool, std::shared_ptr<FFTPlan> plan); + virtual ~BinauralReader(); + + virtual bool isSeekable() const; + virtual void seek(int position); + virtual int getLength() const; + virtual int getPosition() const; + virtual Specs getSpecs() const; + virtual void read(int& length, bool& eos, sample_t* buffer); + +private: + /** + * Joins several buffers (one per channel) into the m_outBuffer. + * \param start The starting position from which the m_outBuffer will be written. + * \param len The amout of samples that will be joined. + * \param nConvolvers The number of convolvers that have been used. Only use 2 or 4 as possible values. + If the value is 4 the result will be interpolated. + */ + void joinByChannel(int start, int len, int nConvolvers); + + /** + * Loads the m_outBuffer with data. + * \param nConvolvers The number of convolver objects that will be used. Only 2 or 4 should be used. + */ + void loadBuffer(int nConvolvers); + + /** + * The function that the threads will run. It will process a subset of channels. + * \param id An id number that will determine which subset of channels will be processed. + * \param input A flag that will indicate if thare is input data. + * -If true there is new input data. + * -If false there isn't new input data. + * \return The number of samples obtained. + */ + int threadFunction(int id, bool input); + + bool checkSource(); +}; + +AUD_NAMESPACE_END
\ No newline at end of file diff --git a/extern/audaspace/include/fx/BinauralSound.h b/extern/audaspace/include/fx/BinauralSound.h new file mode 100644 index 00000000000..733e111dc2b --- /dev/null +++ b/extern/audaspace/include/fx/BinauralSound.h @@ -0,0 +1,119 @@ +/******************************************************************************* +* Copyright 2015-2016 Juan Francisco Crespo Galán +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +******************************************************************************/ + +#pragma once + +/** +* @file BinauralSound.h +* @ingroup fx +* The BinauralSound class. +*/ + +#include "ISound.h" +#include "HRTF.h" +#include "Source.h" +#include "util/ThreadPool.h" +#include "util/FFTPlan.h" + +#include <memory> +#include <vector> + +AUD_NAMESPACE_BEGIN + +/** +* This class represents a sound that can sound different depending on its realtive position with the listener. +*/ +class AUD_API BinauralSound : public ISound +{ +private: + /** + * A pointer to the imput sound. + */ + std::shared_ptr<ISound> m_sound; + + /** + * A pointer to an HRTF object with a collection of impulse responses. + */ + std::shared_ptr<HRTF> m_hrtfs; + + /** + * A pointer to a Source object which represents the source of the sound. + */ + std::shared_ptr<Source> m_source; + + /** + * A shared ptr to a thread pool. + */ + std::shared_ptr<ThreadPool> m_threadPool; + + /** + * A shared ponter to an FFT plan. + */ + std::shared_ptr<FFTPlan> m_plan; + + // delete copy constructor and operator= + BinauralSound(const BinauralSound&) = delete; + BinauralSound& operator=(const BinauralSound&) = delete; + +public: + /** + * Creates a new ConvolverSound. + * \param sound The sound that will be convolved. It must have only one channel. + * \param hrtfs The HRTF set that will be used. + * \param source A shared pointer to a Source object that contains the source of the sound. + * \param threadPool A shared pointer to a ThreadPool object with 1 or more threads. + * \param plan A shared pointer to a FFTPlan object that will be used for convolution. + * \warning The same FFTPlan object must be used to construct both this and the HRTF object provided. + */ + 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); + + /** + * Creates a new BinauralSound. A default FFT plan will be created. + * \param sound The sound that will be convolved. Must have only one channel. + * \param hrtfs The HRTF set that will be used. + * \param source A shared pointer to a Source object that contains the source of the sound. + * \param threadPool A shared pointer to a ThreadPool object with 1 or more threads. + * \warning To use this constructor no FFTPlan object must have been provided to the hrtfs. + */ + BinauralSound(std::shared_ptr<ISound> sound, std::shared_ptr<HRTF> hrtfs, std::shared_ptr<Source> source, std::shared_ptr<ThreadPool> threadPool); + + virtual std::shared_ptr<IReader> createReader(); + + /** + * Retrieves the HRTF set being used. + * \return A shared pointer to the current HRTF object being used. + */ + std::shared_ptr<HRTF> getHRTFs(); + + /** + * Changes the set of HRTFs used for convolution, it'll only affect newly created readers. + * \param hrtfs A shared pointer to the new HRTF object. + */ + void setHRTFs(std::shared_ptr<HRTF> hrtfs); + + /** + * Retrieves the Source object being used. + * \return A shared pointer to the current Source object being used. + */ + std::shared_ptr<Source> getSource(); + + /** + * Changes the Source object used to change the source position of the sound. + * \param source A shared pointer to the new Source object. + */ + void setSource(std::shared_ptr<Source> source); +}; +AUD_NAMESPACE_END
\ No newline at end of file diff --git a/extern/audaspace/include/fx/Butterworth.h b/extern/audaspace/include/fx/Butterworth.h new file mode 100644 index 00000000000..db2ad743863 --- /dev/null +++ b/extern/audaspace/include/fx/Butterworth.h @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright 2009-2016 Jörg Müller + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +#pragma once + +/** + * @file Butterworth.h + * @ingroup fx + * The Butterworth class. + */ + +#include "fx/DynamicIIRFilter.h" + +AUD_NAMESPACE_BEGIN + +/** + * This sound creates a butterworth lowpass filter reader. + */ +class AUD_API Butterworth : public DynamicIIRFilter +{ +private: + // delete copy constructor and operator= + Butterworth(const Butterworth&) = delete; + Butterworth& operator=(const Butterworth&) = delete; + +public: + /** + * Creates a new butterworth sound. + * \param sound The input sound. + * \param frequency The cutoff frequency. + */ + Butterworth(std::shared_ptr<ISound> sound, float frequency); +}; + +AUD_NAMESPACE_END diff --git a/extern/audaspace/include/fx/ButterworthCalculator.h b/extern/audaspace/include/fx/ButterworthCalculator.h new file mode 100644 index 00000000000..f4d4894c8b8 --- /dev/null +++ b/extern/audaspace/include/fx/ButterworthCalculator.h @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright 2009-2016 Jörg Müller + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +#pragma once + +/** + * @file ButterworthCalculator.h + * @ingroup fx + * The ButterworthCalculator class. + */ + +#include "fx/IDynamicIIRFilterCalculator.h" + +AUD_NAMESPACE_BEGIN + +/** + * The ButterworthCalculator class calculates fourth order Butterworth low pass + * filter coefficients for a dynamic DynamicIIRFilter. + */ +class AUD_LOCAL ButterworthCalculator : public IDynamicIIRFilterCalculator +{ +private: + /** + * The attack value in seconds. + */ + const float m_frequency; + + // delete copy constructor and operator= + ButterworthCalculator(const ButterworthCalculator&) = delete; + ButterworthCalculator& operator=(const ButterworthCalculator&) = delete; + +public: + /** + * Creates a ButterworthCalculator object. + * @param frequency The cutoff frequency. + */ + ButterworthCalculator(float frequency); + + virtual void recalculateCoefficients(SampleRate rate, std::vector<float> &b, std::vector<float> &a); +}; + +AUD_NAMESPACE_END diff --git a/extern/audaspace/include/fx/CallbackIIRFilterReader.h b/extern/audaspace/include/fx/CallbackIIRFilterReader.h new file mode 100644 index 00000000000..f1dfab70d7f --- /dev/null +++ b/extern/audaspace/include/fx/CallbackIIRFilterReader.h @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright 2009-2016 Jörg Müller + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +#pragma once + +/** + * @file CallbackIIRFilterReader.h + * @ingroup fx + * The CallbackIIRFilterReader class. + */ + +#include "fx/BaseIIRFilterReader.h" + +AUD_NAMESPACE_BEGIN + +class CallbackIIRFilterReader; + +/** + * The doFilterIIR callback is executed when a new sample of a callback filter + * should be calculated. For sample access the CallbackIIRFilterReader is + * provided. Furthermore a user defined pointer is also handed to the callback. + */ +typedef sample_t (*doFilterIIR)(CallbackIIRFilterReader*, void*); + +/** + * The endFilterIIR callback is called when the callback filter is not needed + * anymore. The goal of this function should be to clean up the data behind the + * user supplied pointer which is handed to the callback. + */ +typedef void (*endFilterIIR)(void*); + +/** + * This class provides an interface for infinite impulse response filters via a + * callback filter function. + */ +class AUD_API CallbackIIRFilterReader : public BaseIIRFilterReader +{ +private: + /** + * Filter function. + */ + const doFilterIIR m_filter; + + /** + * End filter function. + */ + const endFilterIIR m_endFilter; + + /** + * Data pointer. + */ + void* m_data; + + // delete copy constructor and operator= + CallbackIIRFilterReader(const CallbackIIRFilterReader&) = delete; + CallbackIIRFilterReader& operator=(const CallbackIIRFilterReader&) = delete; + +public: + /** + * Creates a new callback IIR filter reader. + * \param reader The reader to read from. + * \param in The count of past input samples needed. + * \param out The count of past output samples needed. + * \param doFilter The filter callback. + * \param endFilter The finishing callback. + * \param data Data pointer for the callbacks. + */ + CallbackIIRFilterReader(std::shared_ptr<IReader> reader, int in, int out, doFilterIIR doFilter, endFilterIIR endFilter = 0, void* data = nullptr); + + virtual ~CallbackIIRFilterReader(); + + virtual sample_t filter(); +}; + +AUD_NAMESPACE_END diff --git a/extern/audaspace/include/fx/Convolver.h b/extern/audaspace/include/fx/Convolver.h new file mode 100644 index 00000000000..5ce134839f6 --- /dev/null +++ b/extern/audaspace/include/fx/Convolver.h @@ -0,0 +1,177 @@ +/******************************************************************************* +* Copyright 2015-2016 Juan Francisco Crespo Galán +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +******************************************************************************/ + +#pragma once + +/** +* @file Convolver.h +* @ingroup fx +* The Convolver class. +*/ + +#include "FFTConvolver.h" +#include "util/ThreadPool.h" +#include "util/FFTPlan.h" + +#include <memory> +#include <vector> +#include <mutex> +#include <future> +#include <atomic> +#include <deque> + +AUD_NAMESPACE_BEGIN +/** +* This class allows to convolve a sound with a very large impulse response. +*/ +class AUD_API Convolver +{ +private: + /** + * The FFT size, must be at least M+L-1. + */ + int m_N; + + /** + * The length of the impulse response parts. + */ + int m_M; + + /** + * The max length of the input slices. + */ + int m_L; + + /** + * The impulse response divided in parts. + */ + std::shared_ptr<std::vector<std::shared_ptr<std::vector<std::complex<sample_t>>>>> m_irBuffers; + + /** + * Accumulation buffers for the threads. + */ + std::vector<fftwf_complex*> m_threadAccBuffers; + + /** + * A vector of FFTConvolvers used to calculate the partial convolutions. + */ + std::vector<std::unique_ptr<FFTConvolver>> m_fftConvolvers; + + /** + * The actual number of threads being used. + */ + int m_numThreads; + + /** + * A pool of threads that will be used for convolution. + */ + std::shared_ptr<ThreadPool> m_threadPool; + + /** + * A vector of futures used for thread sync + */ + std::vector<std::future<bool>> m_futures; + + /** + * A mutex for the sum of thread accumulators. + */ + std::mutex m_sumMutex; + + /** + * A flag to control thread execution when a reset is scheduled. + */ + std::atomic_bool m_resetFlag; + + /** + * Global accumulation buffer. + */ + fftwf_complex* m_accBuffer; + + /** + * Delay line. + */ + std::deque<fftwf_complex*> m_delayLine; + + /** + * The complete length of the impulse response. + */ + int m_irLength; + + /** + * Counter for the tail; + */ + int m_tailCounter; + + /** + * Flag end of sound; + */ + bool m_eos; + + // delete copy constructor and operator= + Convolver(const Convolver&) = delete; + Convolver& operator=(const Convolver&) = delete; + +public: + + /** + * Creates a new FFTConvolver. + * \param ir A shared pointer to a vector with the data of the various impulse response parts in the frequency domain (see ImpulseResponse class for an easy way to obtain it). + * \param irLength The length of the full impulse response. + * \param threadPool A shared pointer to a ThreadPool object with 1 or more threads. + * \param plan A shared pointer to a FFT plan that will be used for convolution. + */ + Convolver(std::shared_ptr<std::vector<std::shared_ptr<std::vector<std::complex<sample_t>>>>> ir, int irLength, std::shared_ptr<ThreadPool> threadPool, std::shared_ptr<FFTPlan> plan); + + virtual ~Convolver(); + + /** + * Convolves the data that is provided with the inpulse response. + * Given a plan of size N, the amount of samples convolved by one call to this method will be N/2. + * \param[in] inBuffer A buffer with the input data to be convolved, nullptr if the source sound has ended (the convolved sound is larger than the source sound). + * \param[in] outBuffer A buffer in which the convolved data will be written. Its size must be at least N/2. + * \param[in,out] length The number of samples you wish to obtain. If an inBuffer is provided this argument must match its length. + * When this method returns, the value of length represents the number of samples written into the outBuffer. + * \param[out] eos True if the end of the sound is reached, false otherwise. + */ + void getNext(sample_t* inBuffer, sample_t* outBuffer, int& length, bool& eos); + + /** + * Resets all the internally stored data so the convolution of a new sound can be started. + */ + void reset(); + + /** + * Retrieves the current impulse response being used. + * \return The current impulse response. + */ + std::shared_ptr<std::vector<std::shared_ptr<std::vector<std::complex<sample_t>>>>> getImpulseResponse(); + + /** + * Changes the impulse response and resets the convolver. + * \param ir A shared pointer to a vector with the data of the various impulse response parts in the frequency domain (see ImpulseResponse class for an easy way to obtain it). + */ + void setImpulseResponse(std::shared_ptr<std::vector<std::shared_ptr<std::vector<std::complex<sample_t>>>>> ir); + +private: + + /** + * This function will be enqueued into the thread pool, and will process the input signal with a subset of the impulse response parts. + * \param id The id of the thread, starting with 0. + */ + bool threadFunction(int id); +}; + +AUD_NAMESPACE_END diff --git a/extern/audaspace/include/fx/ConvolverReader.h b/extern/audaspace/include/fx/ConvolverReader.h new file mode 100644 index 00000000000..2ce917daec5 --- /dev/null +++ b/extern/audaspace/include/fx/ConvolverReader.h @@ -0,0 +1,198 @@ +/******************************************************************************* +* Copyright 2015-2016 Juan Francisco Crespo Galán +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +******************************************************************************/ + +#pragma once + +/** +* @file ConvolverReader.h +* @ingroup fx +* The ConvolverReader class. +*/ + +#include "IReader.h" +#include "ISound.h" +#include "Convolver.h" +#include "ImpulseResponse.h" +#include "util/FFTPlan.h" +#include "util/ThreadPool.h" + +#include <memory> +#include <vector> +#include <future> + +AUD_NAMESPACE_BEGIN + +/** +* This class represents a reader for a sound that can be modified depending on a given impulse response. +*/ +class AUD_API ConvolverReader : public IReader +{ +private: + /** + * The current position. + */ + int m_position; + + /** + * The reader of the input sound. + */ + std::shared_ptr<IReader> m_reader; + + /** + * The impulse response in the frequency domain. + */ + std::shared_ptr<ImpulseResponse> m_ir; + + /** + * The FFT size, given by the FFTPlan. + */ + int m_N; + + /** + * The length of the impulse response fragments, m_N/2 will be used. + */ + int m_M; + + /** + * The max length of the input slices, m_N/2 will be used. + */ + int m_L; + + /** + * The array of convolvers that will be used, one per channel. + */ + std::vector<std::unique_ptr<Convolver>> m_convolvers; + + /** + * The output buffer in which the convolved data will be written and from which the reader will read. + */ + sample_t* m_outBuffer; + + /** + * A vector of buffers (one per channel) on which the audio signal will be separated per channel so it can be convolved. + */ + std::vector<sample_t*> m_vecInOut; + + /** + * Current position in which the m_outBuffer is being read. + */ + int m_outBufferPos; + + /** + * Effective length of the m_outBuffer. + */ + int m_eOutBufLen; + + /** + * Real length of the m_outBuffer. + */ + int m_outBufLen; + + /** + * Flag indicating whether the end of the sound has been reached or not. + */ + bool m_eosReader; + + /** + * Flag indicating whether the end of the extra data generated in the convolution has been reached or not. + */ + bool m_eosTail; + + /** + * The number of channels of the sound to be convolved. + */ + int m_inChannels; + + /** + * The number of channels of the impulse response. + */ + int m_irChannels; + + /** + * The number of threads used for channels. + */ + int m_nChannelThreads; + + /** + * Length of the input data to be used by the channel threads. + */ + int m_lastLengthIn; + + /** + * A shared ptr to a thread pool. + */ + std::shared_ptr<ThreadPool> m_threadPool; + + /** + * A vector of futures to sync tasks. + */ + std::vector<std::future<int>> m_futures; + + // delete copy constructor and operator= + ConvolverReader(const ConvolverReader&) = delete; + ConvolverReader& operator=(const ConvolverReader&) = delete; + +public: + /** + * Creates a new convolver reader. + * \param reader A reader of the input sound to be assigned to this reader. + * \param ir A shared pointer to an impulseResponse object that will be used to convolve the sound. + * \param threadPool A shared pointer to a ThreadPool object with 1 or more threads. + * \param plan A shared pointer to and FFT plan that will be used for convolution. + * \exception Exception thrown if impulse response doesn't match the specs (number fo channels and rate) of the input reader. + */ + ConvolverReader(std::shared_ptr<IReader> reader, std::shared_ptr<ImpulseResponse> ir, std::shared_ptr<ThreadPool> threadPool, std::shared_ptr<FFTPlan> plan); + virtual ~ConvolverReader(); + + virtual bool isSeekable() const; + virtual void seek(int position); + virtual int getLength() const; + virtual int getPosition() const; + virtual Specs getSpecs() const; + virtual void read(int& length, bool& eos, sample_t* buffer); + +private: + /** + * Divides a sound buffer in several buffers, one per channel. + * \param buffer The buffer that will be divided. + * \param len The length of the buffer. + */ + void divideByChannel(const sample_t* buffer, int len); + + /** + * Joins several buffers (one per channel) into the m_outBuffer. + * \param start The starting position from which the m_outBuffer will be written. + * \param len The amout of samples that will be joined. + */ + void joinByChannel(int start, int len); + + /** + * Loads the m_outBuffer with data. + */ + void loadBuffer(); + + /** + * The function that the threads will run. It will process a subset of channels. + * \param id An id number that will determine which subset of channels will be processed. + * \param input A flag that will indicate if thare is input data. + * -If true there is new input data. + * -If false there isn't new input data. + * \return The number of samples obtained. + */ + int threadFunction(int id, bool input); +}; + +AUD_NAMESPACE_END
\ No newline at end of file diff --git a/extern/audaspace/include/fx/ConvolverSound.h b/extern/audaspace/include/fx/ConvolverSound.h new file mode 100644 index 00000000000..957e3b8af1c --- /dev/null +++ b/extern/audaspace/include/fx/ConvolverSound.h @@ -0,0 +1,100 @@ +/******************************************************************************* +* Copyright 2015-2016 Juan Francisco Crespo Galán +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +******************************************************************************/ + +#pragma once + +/** +* @file ConvolverSound.h +* @ingroup fx +* The ConvolverSound class. +*/ + +#include "ISound.h" +#include "ImpulseResponse.h" +#include "util/ThreadPool.h" +#include "util/FFTPlan.h" + +#include <memory> +#include <vector> + +AUD_NAMESPACE_BEGIN + +/** +* This class represents a sound that can be modified depending on a given impulse response. +*/ +class AUD_API ConvolverSound : public ISound +{ +private: + /** + * A pointer to the imput sound. + */ + std::shared_ptr<ISound> m_sound; + + /** + * A pointer to the impulse response. + */ + std::shared_ptr<ImpulseResponse> m_impulseResponse; + + /** + * A shared ptr to a thread pool. + */ + std::shared_ptr<ThreadPool> m_threadPool; + + /** + * A shared ponter to an FFT plan. + */ + std::shared_ptr<FFTPlan> m_plan; + + // delete copy constructor and operator= + ConvolverSound(const ConvolverSound&) = delete; + ConvolverSound& operator=(const ConvolverSound&) = delete; + +public: + /** + * Creates a new ConvolverSound. + * \param sound The sound that will be convolved. + * \param impulseResponse The impulse response sound. + * \param threadPool A shared pointer to a ThreadPool object with 1 or more threads. + * \param plan A shared pointer to a FFTPlan object that will be used for convolution. + * \warning The same FFTPlan object must be used to construct both this and the ImpulseResponse object provided. + */ + ConvolverSound(std::shared_ptr<ISound> sound, std::shared_ptr<ImpulseResponse> impulseResponse, std::shared_ptr<ThreadPool> threadPool, std::shared_ptr<FFTPlan> plan); + + /** + * Creates a new ConvolverSound. A default FFT plan will be created. + * \param sound The sound that will be convolved. + * \param impulseResponse The impulse response sound. + * \param threadPool A shared pointer to a ThreadPool object with 1 or more threads. + * \warning To use this constructor no FFTPlan object must have been provided to the inpulseResponse. + */ + ConvolverSound(std::shared_ptr<ISound> sound, std::shared_ptr<ImpulseResponse> impulseResponse, std::shared_ptr<ThreadPool> threadPool); + + virtual std::shared_ptr<IReader> createReader(); + + /** + * Retrieves the impulse response sound being used. + * \return A shared pointer to the current impulse response being used. + */ + std::shared_ptr<ImpulseResponse> getImpulseResponse(); + + /** + * Changes the inpulse response used for convolution, it'll only affect newly created readers. + * \param impulseResponse A shared pointer to the new impulse response sound. + */ + void setImpulseResponse(std::shared_ptr<ImpulseResponse> impulseResponse); +}; + +AUD_NAMESPACE_END
\ No newline at end of file diff --git a/extern/audaspace/include/fx/Delay.h b/extern/audaspace/include/fx/Delay.h new file mode 100644 index 00000000000..d6ab93ca351 --- /dev/null +++ b/extern/audaspace/include/fx/Delay.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright 2009-2016 Jörg Müller + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +#pragma once + +/** + * @file Delay.h + * @ingroup fx + * The Delay class. + */ + +#include "fx/Effect.h" + +AUD_NAMESPACE_BEGIN + +/** + * This sound plays another sound delayed. + */ +class AUD_API Delay : public Effect +{ +private: + /** + * The delay in samples. + */ + const float m_delay; + + // delete copy constructor and operator= + Delay(const Delay&) = delete; + Delay& operator=(const Delay&) = delete; + +public: + /** + * Creates a new delay sound. + * \param sound The input sound. + * \param delay The desired delay in seconds. + */ + Delay(std::shared_ptr<ISound> sound, float delay = 0); + + /** + * Returns the delay in seconds. + */ + float getDelay() const; + + virtual std::shared_ptr<IReader> createReader(); +}; + +AUD_NAMESPACE_END diff --git a/extern/audaspace/include/fx/DelayReader.h b/extern/audaspace/include/fx/DelayReader.h new file mode 100644 index 00000000000..fe37e56d83e --- /dev/null +++ b/extern/audaspace/include/fx/DelayReader.h @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright 2009-2016 Jörg Müller + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +#pragma once + +/** + * @file DelayReader.h + * @ingroup fx + * The DelayReader class. + */ + +#include "fx/EffectReader.h" + +AUD_NAMESPACE_BEGIN + +/** + * This class reads another reader and delays it. + */ +class AUD_API DelayReader : public EffectReader +{ +private: + /** + * The delay level. + */ + const int m_delay; + + /** + * The remaining delay for playback. + */ + int m_remdelay; + + // delete copy constructor and operator= + DelayReader(const DelayReader&) = delete; + DelayReader& operator=(const DelayReader&) = delete; + +public: + /** + * Creates a new delay reader. + * \param reader The reader to read from. + * \param delay The delay in seconds. + */ + DelayReader(std::shared_ptr<IReader> reader, float delay); + + virtual void seek(int position); + virtual int getLength() const; + virtual int getPosition() const; + virtual void read(int& length, bool& eos, sample_t* buffer); +}; + +AUD_NAMESPACE_END diff --git a/extern/audaspace/include/fx/DynamicIIRFilter.h b/extern/audaspace/include/fx/DynamicIIRFilter.h new file mode 100644 index 00000000000..5528e7c7b9b --- /dev/null +++ b/extern/audaspace/include/fx/DynamicIIRFilter.h @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright 2009-2016 Jörg Müller + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +#pragma once + +/** + * @file DynamicIIRFilter.h + * @ingroup fx + * The DynamicIIRFilter class. + */ + +#include "fx/Effect.h" + +AUD_NAMESPACE_BEGIN + +class IDynamicIIRFilterCalculator; + +/** + * This sound creates a IIR filter reader. + * + * This means that on sample rate change the filter recalculates its + * coefficients. + */ +class AUD_API DynamicIIRFilter : public Effect +{ +protected: + /// The IDynamicIIRFilterCalculator that calculates the dynamic filter coefficients. + std::shared_ptr<IDynamicIIRFilterCalculator> m_calculator; + +public: + /** + * Creates a new Dynmic IIR filter sound. + * \param sound The input sound. + * \param calculator The calculator which recalculates the dynamic filter coefficients. + */ + DynamicIIRFilter(std::shared_ptr<ISound> sound, std::shared_ptr<IDynamicIIRFilterCalculator> calculator); + + virtual std::shared_ptr<IReader> createReader(); +}; + +AUD_NAMESPACE_END diff --git a/extern/audaspace/include/fx/DynamicIIRFilterReader.h b/extern/audaspace/include/fx/DynamicIIRFilterReader.h new file mode 100644 index 00000000000..9e2267243ce --- /dev/null +++ b/extern/audaspace/include/fx/DynamicIIRFilterReader.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright 2009-2016 Jörg Müller + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +#pragma once + +/** + * @file DynamicIIRFilterReader.h + * @ingroup fx + * The DynamicIIRFilterReader class. + */ + +#include "fx/IIRFilterReader.h" + +AUD_NAMESPACE_BEGIN + +class IDynamicIIRFilterCalculator; + +/** + * This class is for dynamic infinite impulse response filters with simple + * coefficients that change depending on the sample rate. + */ +class AUD_API DynamicIIRFilterReader : public IIRFilterReader +{ +private: + /** + * The sound for dynamically recalculating filter coefficients. + */ + std::shared_ptr<IDynamicIIRFilterCalculator> m_calculator; + +public: + /** + * Creates a new DynamicIIRFilterReader. + * @param reader The reader the filter is applied on. + * @param calculator The IDynamicIIRFilterCalculator that recalculates the filter coefficients. + */ + DynamicIIRFilterReader(std::shared_ptr<IReader> reader, + std::shared_ptr<IDynamicIIRFilterCalculator> calculator); + + /** + * The function sampleRateChanged is called whenever the sample rate of the + * underlying reader changes and thus updates the filter coefficients. + * @param rate The new sample rate. + */ + virtual void sampleRateChanged(SampleRate rate); +}; + +AUD_NAMESPACE_END diff --git a/extern/audaspace/include/fx/DynamicMusic.h b/extern/audaspace/include/fx/DynamicMusic.h new file mode 100644 index 00000000000..5d59f77401a --- /dev/null +++ b/extern/audaspace/include/fx/DynamicMusic.h @@ -0,0 +1,235 @@ +/******************************************************************************* +* Copyright 2015-2016 Juan Francisco Crespo Galán +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +******************************************************************************/ + +#pragma once + +/** +* @file DynamicMusic.h +* @ingroup fx +* The DynamicMusic class. +*/ + +#include "devices/IHandle.h" +#include "devices/IDevice.h" +#include "ISound.h" + +#include <memory> +#include <vector> +#include <thread> +#include <atomic> +#include <condition_variable> +#include <mutex> + +AUD_NAMESPACE_BEGIN + +/** +* This class allows to play music depending on a current "scene", scene changes are managed by the class. +* The default scene is silent and has id 0. +*/ +class AUD_API DynamicMusic +{ +private: + /** + * Matrix of pointers which will store the sounds of the scenes and the transitions between them. + */ + std::vector<std::vector<std::shared_ptr<ISound>>> m_scenes; + + /** + * Id of the current scene. + */ + std::atomic_int m_id; + + /** + * Length of the crossfade transition in seconds, used when no custom transition has been set. + */ + float m_fadeTime; + + /** + * Handle to the playback of the current scene. + */ + std::shared_ptr<IHandle> m_currentHandle; + + /** + * Handle used during transitions. + */ + std::shared_ptr<IHandle> m_transitionHandle; + + /** + * Device used for playback. + */ + std::shared_ptr<IDevice> m_device; + + /** + * Flag that is true when a transition is happening. + */ + std::atomic_bool m_transitioning; + + /** + * Flag that is true when the music is paused. + */ + std::atomic_bool m_stopThread; + + /** + * Id of the sound that will play with the next transition. + */ + std::atomic_int m_soundTarget; + + /** + * Volume of the scenes. + */ + float m_volume; + + /** + * A thread that manages the crossfade transition. + */ + std::thread m_fadeThread; + + // delete copy constructor and operator= + DynamicMusic(const DynamicMusic&) = delete; + DynamicMusic& operator=(const DynamicMusic&) = delete; + +public: + /** + * Creates a new dynamic music manager with the default silent scene (id: 0). + * \param device The device that will be used to play sounds. + */ + DynamicMusic(std::shared_ptr<IDevice> device); + + virtual ~DynamicMusic(); + + /** + * Adds a new scene to the manager. + * \param sound The sound that will play when the scene is selected with the changeScene(). + * \return The identifier of the new scene. + */ + int addScene(std::shared_ptr<ISound> sound); + + /** + * Changes to another scene. + * \param id The id of the scene which should start playing the changeScene method. + * \return + * - true if the change has been scheduled succesfully. + * - false if there already is a transition in course or the scene selected doesnt exist. + */ + bool changeScene(int id); + + /** + * Retrieves the scene currently selected. + * \return The identifier of the current scene. + */ + int getScene(); + + /** + * Adds a new transition between scenes + * \param init The id of the initial scene that will allow the transition to play. + * \param end The id if the target scene for the transition. + * \param sound The sound that will play when the scene changes from init to end. + * \return false if the init or end scenes don't exist. + */ + bool addTransition(int init, int end, std::shared_ptr<ISound> sound); + + /** + * Sets the length of the crossfade transition (default 1 second). + * \param seconds The time in seconds. + */ + void setFadeTime(float seconds); + + /** + * Gets the length of the crossfade transition (default 1 second). + * \return The length of the cressfade transition in seconds. + */ + float getFadeTime(); + + /** + * Resumes a paused sound. + * \return + * - true if the sound has been resumed. + * - false if the sound isn't paused or the handle is invalid. + */ + bool resume(); + + /** + * Pauses the current played back sound. + * \return + * - true if the sound has been paused. + * - false if the sound isn't playing back or the handle is invalid. + */ + bool pause(); + + /** + * Seeks in the current played back sound. + * \param position The new position from where to play back, in seconds. + * \return + * - true if the handle is valid. + * - false if the handle is invalid. + * \warning Whether the seek works or not depends on the sound source. + */ + bool seek(float position); + + /** + * Retrieves the current playback position of a sound. + * \return The playback position in seconds, or 0.0 if the handle is + * invalid. + */ + float getPosition(); + + /** + * Retrieves the volume of the scenes. + * \return The volume. + */ + float getVolume(); + + /** + * Sets the volume for the scenes. + * \param volume The volume. + * \return + * - true if the handle is valid. + * - false if the handle is invalid. + */ + bool setVolume(float volume); + + /** + * Returns the status of the current played back sound. + * \return + * - STATUS_INVALID if the sound has stopped or the handle is + *. invalid + * - STATUS_PLAYING if the sound is currently played back. + * - STATUS_PAUSED if the sound is currently paused. + * - STATUS_STOPPED if the sound finished playing and is still + * kept in the device. + * \see Status + */ + Status getStatus(); + + /** + * Stops any played back or paused sound and sets the dynamic music player to default silent state (scene 0) + * \return + * - true if the sound has been stopped. + * - false if the handle is invalid. + */ + bool stop(); + + private: + //Callbacks used to schedule transitions after a sound ends. + static void transitionCallback(void* player); + static void sceneCallback(void* player); + //These functions can fade sounds in and out if used with a thread. + void crossfadeThread(); + void fadeInThread(); + void fadeOutThread(); +}; + +AUD_NAMESPACE_END diff --git a/extern/audaspace/include/fx/Effect.h b/extern/audaspace/include/fx/Effect.h new file mode 100644 index 00000000000..471e37b5ecf --- /dev/null +++ b/extern/audaspace/include/fx/Effect.h @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright 2009-2016 Jörg Müller + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +#pragma once + +/** + * @file Effect.h + * @ingroup fx + * The Effect class. + */ + +#include "ISound.h" + +AUD_NAMESPACE_BEGIN + +/** + * This sound is a base class for all effect factories that take one other + * sound as input. + */ +class AUD_API Effect : public ISound +{ +private: + // delete copy constructor and operator= + Effect(const Effect&) = delete; + Effect& operator=(const Effect&) = delete; + +protected: + /** + * If there is no reader it is created out of this sound. + */ + std::shared_ptr<ISound> m_sound; + + /** + * Returns the reader created out of the sound. + * This method can be used for the createReader function of the implementing + * classes. + * \return The reader created out of the sound. + */ + inline std::shared_ptr<IReader> getReader() const + { + return m_sound->createReader(); + } + +public: + /** + * Creates a new sound. + * \param sound The input sound. + */ + Effect(std::shared_ptr<ISound> sound); + + /** + * Destroys the sound. + */ + virtual ~Effect(); + + /** + * Returns the saved sound. + * \return The sound or nullptr if there has no sound been saved. + */ + std::shared_ptr<ISound> getSound() const; +}; + +AUD_NAMESPACE_END diff --git a/extern/audaspace/include/fx/EffectReader.h b/extern/audaspace/include/fx/EffectReader.h new file mode 100644 index 00000000000..85eff6a8ab9 --- /dev/null +++ b/extern/audaspace/include/fx/EffectReader.h @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright 2009-2016 Jörg Müller + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +#pragma once + +/** + * @file EffectReader.h + * @ingroup fx + * The EffectReader class. + */ + +#include "IReader.h" + +#include <memory> + +AUD_NAMESPACE_BEGIN + +/** + * This reader is a base class for all effect readers that take one other reader + * as input. + */ +class AUD_API EffectReader : public IReader +{ +private: + // delete copy constructor and operator= + EffectReader(const EffectReader&) = delete; + EffectReader& operator=(const EffectReader&) = delete; + +protected: + /** + * The reader to read from. + */ + std::shared_ptr<IReader> m_reader; + +public: + /** + * Creates a new effect reader. + * \param reader The reader to read from. + */ + EffectReader(std::shared_ptr<IReader> reader); + + /** + * Destroys the reader. + */ + virtual ~EffectReader(); + + virtual bool isSeekable() const; + virtual void seek(int position); + virtual int getLength() const; + virtual int getPosition() const; + virtual Specs getSpecs() const; + virtual void read(int& length, bool& eos, sample_t* buffer); +}; + +AUD_NAMESPACE_END diff --git a/extern/audaspace/include/fx/Envelope.h b/extern/audaspace/include/fx/Envelope.h new file mode 100644 index 00000000000..3d44e897b3a --- /dev/null +++ b/extern/audaspace/include/fx/Envelope.h @@ -0,0 +1,93 @@ +/******************************************************************************* + * Copyright 2009-2016 Jörg Müller + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +#pragma once + +/** + * @file Envelope.h + * @ingroup fx + * The Envelope class. + */ + +#include "fx/Effect.h" + +AUD_NAMESPACE_BEGIN + +class CallbackIIRFilterReader; +struct EnvelopeParameters; + +/** + * This sound creates an envelope follower reader. + */ +class AUD_API Envelope : public Effect +{ +private: + /** + * The attack value in seconds. + */ + const float m_attack; + + /** + * The release value in seconds. + */ + const float m_release; + + /** + * The threshold value. + */ + const float m_threshold; + + /** + * The attack/release threshold value. + */ + const float m_arthreshold; + + // delete copy constructor and operator= + Envelope(const Envelope&) = delete; + Envelope& operator=(const Envelope&) = delete; + +public: + /** + * Creates a new envelope sound. + * \param sound The input sound. + * \param attack The attack value in seconds. + * \param release The release value in seconds. + * \param threshold The threshold value. + * \param arthreshold The attack/release threshold value. + */ + Envelope(std::shared_ptr<ISound> sound, float attack, float release, + float threshold, float arthreshold); + + virtual std::shared_ptr<IReader> createReader(); + + /** + * The envelopeFilter function implements the doFilterIIR callback + * for the callback IIR filter. + * @param reader The CallbackIIRFilterReader that executes the callback. + * @param param The envelope parameters. + * @return The filtered sample. + */ + static sample_t AUD_LOCAL envelopeFilter(CallbackIIRFilterReader* reader, EnvelopeParameters* param); + + /** + * The endEnvelopeFilter function implements the endFilterIIR callback + * for the callback IIR filter. + * @param param The envelope parameters. + */ + static void AUD_LOCAL endEnvelopeFilter(EnvelopeParameters* param); +}; + +AUD_NAMESPACE_END diff --git a/extern/audaspace/include/fx/FFTConvolver.h b/extern/audaspace/include/fx/FFTConvolver.h new file mode 100644 index 00000000000..62ce1cbf5ad --- /dev/null +++ b/extern/audaspace/include/fx/FFTConvolver.h @@ -0,0 +1,196 @@ +/******************************************************************************* +* Copyright 2015-2016 Juan Francisco Crespo Galán +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +******************************************************************************/ + +#pragma once + +/** +* @file FFTConvolver.h +* @ingroup fx +* The FFTConvolver class. +*/ + +#include "IReader.h" +#include "ISound.h" +#include "util/FFTPlan.h" + +#include <memory> +#include <vector> + +AUD_NAMESPACE_BEGIN +/** +* This class allows to easily convolve a sound using the Fourier transform. +*/ +class AUD_API FFTConvolver +{ +private: + /** + * A shared pointer to an FFT plan. + */ + std::shared_ptr<FFTPlan> m_plan; + + /** + * The FFT size, must be at least M+L-1. + */ + int m_N; + + /** + * The length of the impulse response. + */ + int m_M; + + /** + * The max length of the input slices. + */ + int m_L; + + /** + * The real length of the internal buffer in fftwf_complex elements. + */ + int m_realBufLen; + + /** + * The internal buffer for the FFTS. + */ + std::complex<sample_t>* m_inBuffer; + + /** + * A shift buffer for the FDL method + */ + sample_t* m_shiftBuffer; + + /** + * A buffer to store the extra data obtained after each partial convolution. + */ + float* m_tail; + + /** + * The provided impulse response. + */ + std::shared_ptr<std::vector<std::complex<sample_t>>> m_irBuffer; + + /** + * If the tail is being read, this marks the current position. + */ + int m_tailPos; + + // delete copy constructor and operator= + FFTConvolver(const FFTConvolver&) = delete; + FFTConvolver& operator=(const FFTConvolver&) = delete; + +public: + /** + * Creates a new FFTConvolver. + * \param ir A shared pointer to a vector with the impulse response data in the frequency domain (see ImpulseResponse class for an easy way to obtain it). + * \param plan A shared pointer to and FFT plan. + */ + FFTConvolver(std::shared_ptr<std::vector<std::complex<sample_t>>> ir, std::shared_ptr<FFTPlan> plan); + virtual ~FFTConvolver(); + + /** + * Convolves the data that is provided with the inpulse response. + * \param[in] inBuffer A buffer with the input data to be convolved. + * \param[in] outBuffer A pointer to the buffer in which the convolution result will be written. + * \param[in,out] length The number of samples to be convolved (the length of both the inBuffer and the outBuffer). + * The convolution output should be larger than the input, but since this class uses the overlap + * add method, the extra length will be saved internally. + * It must be equal or lower than N/2 (N=size of the FFTPlan) or the call will fail, setting this variable to 0 since no data would be + * written in the outBuffer. + */ + void getNext(const sample_t* inBuffer, sample_t* outBuffer, int& length); + + /** + * Convolves the data that is provided with the inpulse response. + * \param[in] inBuffer A buffer with the input data to be convolved. + * \param[in] outBuffer A pointer to the buffer in which the convolution result will be written. + * \param[in,out] length The number of samples to be convolved (the length of both the inBuffer and the outBuffer). + * The convolution output should be larger than the input, but since this class uses the overlap + * add method, the extra length will be saved internally. + * It must be equal or lower than N/2 (N=size of the FFTPlan) or the call will fail, setting this variable to 0 since no data would be + * written in the outBuffer. + * \param[in] transformedData A pointer to a buffer in which the Fourier transform of the input will be written. + */ + void getNext(const sample_t* inBuffer, sample_t* outBuffer, int& length, fftwf_complex* transformedData); + + /** + * Convolves the data that is provided with the inpulse response. + * \param[in] inBuffer A buffer with the input data to be convolved. Its length must be N/2 + 1 + * \param[in] outBuffer A pointer to the buffer in which the convolution result will be written. + * \param[in,out] length The number of samples to be convolved and the length of the outBuffer. + * The convolution output should be larger than the input, but since this class uses the overlap + * add method, the extra length will be saved internally. + * It must be equal or lower than N/2 (N=size of the FFTPlan) or the call will fail and set the value of length to 0 since no data would be + * written in the outBuffer. + */ + void getNext(const fftwf_complex* inBuffer, sample_t* outBuffer, int& length); + + /** + * Gets the internally stored extra data which is result of the convolution. + * \param[in,out] length The count of samples that should be read. Shall + * contain the real count of samples after reading, in case + * there were only fewer samples available. + * A smaller value also indicates the end of the data. + * \param[out] eos End of stream, whether the end is reached or not. + * \param[in] buffer The pointer to the buffer to read into. + */ + void getTail(int& length, bool& eos, sample_t* buffer); + + /** + * Resets the internally stored data so a new convolution can be started. + */ + void clear(); + + /** + * Calculates the Inverse Fast Fourier Transform of the input array. + * \param[in] inBuffer A buffer with the input data to be transformed. Its length must be N/2 + 1 + * \param[in] outBuffer A pointer to the buffer in which the transform result will be written. + * \param[in,out] length The number of samples to be transformed and the length of the outBuffer. + * It must be equal or lower than N, but tipically N/2 should be used (N=size of the FFTPlan) or the call will fail and the value + * of length will be setted to 0, since no data would be written in the outBuffer. + */ + void IFFT_FDL(const fftwf_complex* inBuffer, sample_t* outBuffer, int& length); + + /** + * Multiplicates a frequency domain input by the impulse response and accumulates the result to a buffer. + * \param[in] inBuffer A buffer of complex numbers, samples in the frequency domain, that will be multiplied by the impulse response. Its length must be N/2 + 1 + * \param[in] accBuffer A pointer to the buffer into which the result of the multiplication will be summed. Its length must be N/2 + 1 + */ + void getNextFDL(const std::complex<sample_t>* inBuffer, std::complex<sample_t>* accBuffer); + + /** + * Transforms an input array of real data to the frequency domain and multiplies it by the impulse response. The result is accumulated to a buffer. + * \param[in] inBuffer A buffer of real numbers, samples in the time domain, that will be multiplied by the impulse response. + * \param[in] accBuffer A pointer to the buffer into which the result of the multiplication will be summed. Its length must be N/2 + 1. + * \param[in,out] length The number of samples to be transformed and the length of the inBuffer. + * It must be equal or lower than N/2 (N=size of the FFTPlan) or the call will fail and the value + * of length will be setted to 0, since no data would be written in the outBuffer. + * \param[in] transformedData A pointer to a buffer in which the Fourier transform of the input will be written. + */ + void getNextFDL(const sample_t* inBuffer, std::complex<sample_t>* accBuffer, int& length, fftwf_complex* transformedData); + + /** + * Changes the impulse response and resets the FFTConvolver. + * \param ir A shared pointer to a vector with the data of the impulse response in the frequency domain. + */ + void setImpulseResponse(std::shared_ptr<std::vector<std::complex<sample_t>>> ir); + + /** + * Retrieves the current impulse response being used. + * \return The current impulse response. + */ + std::shared_ptr<std::vector<std::complex<sample_t>>> getImpulseResponse(); +}; + +AUD_NAMESPACE_END diff --git a/extern/audaspace/include/fx/Fader.h b/extern/audaspace/include/fx/Fader.h new file mode 100644 index 00000000000..63280aec292 --- /dev/null +++ b/extern/audaspace/include/fx/Fader.h @@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright 2009-2016 Jörg Müller + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +#pragma once + +/** + * @file Fader.h + * @ingroup fx + * The Fader class. + */ + +#include "fx/Effect.h" +#include "fx/FaderReader.h" + +AUD_NAMESPACE_BEGIN + +/** + * This sound fades another sound. + * If the fading type is FADE_IN, everything before the fading start will be + * silenced, for FADE_OUT that's true for everything after fading ends. + */ +class AUD_API Fader : public Effect +{ +private: + /** + * The fading type. + */ + const FadeType m_type; + + /** + * The fading start. + */ + const float m_start; + + /** + * The fading length. + */ + const float m_length; + + // delete copy constructor and operator= + Fader(const Fader&) = delete; + Fader& operator=(const Fader&) = delete; + +public: + /** + * Creates a new fader sound. + * \param sound The input sound. + * \param type The fading type. + * \param start The time where fading should start in seconds. + * \param length How long fading should last in seconds. + */ + Fader(std::shared_ptr<ISound> sound, + FadeType type = FADE_IN, + float start = 0.0f, float length = 1.0f); + + /** + * Returns the fading type. + */ + FadeType getType() const; + + /** + * Returns the fading start. + */ + float getStart() const; + + /** + * Returns the fading length. + */ + float getLength() const; + + virtual std::shared_ptr<IReader> createReader(); +}; + +AUD_NAMESPACE_END diff --git a/extern/audaspace/include/fx/FaderReader.h b/extern/audaspace/include/fx/FaderReader.h new file mode 100644 index 00000000000..99ea3d28938 --- /dev/null +++ b/extern/audaspace/include/fx/FaderReader.h @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright 2009-2016 Jörg Müller + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +#pragma once + +/** + * @file FaderReader.h + * @ingroup fx + * Defines the FaderReader class as well as the two fading types. + */ + +#include "fx/EffectReader.h" + +AUD_NAMESPACE_BEGIN + +/// Fading types. +enum FadeType +{ + FADE_IN, + FADE_OUT +}; + +/** + * This class fades another reader. + * If the fading type is FADE_IN, everything before the fading start will be + * silenced, for FADE_OUT that's true for everything after fading ends. + */ +class AUD_API FaderReader : public EffectReader +{ +private: + /** + * The fading type. + */ + const FadeType m_type; + + /** + * The fading start. + */ + const float m_start; + + /** + * The fading length. + */ + const float m_length; + + // delete copy constructor and operator= + FaderReader(const FaderReader&) = delete; + FaderReader& operator=(const FaderReader&) = delete; + +public: + /** + * Creates a new fader reader. + * \param reader The reader that this effect is applied on. + * \param type The fading type. + * \param start The time where fading should start in seconds. + * \param length How long fading should last in seconds. + */ + FaderReader(std::shared_ptr<IReader> reader, FadeType type, + float start,float length); + + virtual void read(int& length, bool& eos, sample_t* buffer); +}; + +AUD_NAMESPACE_END diff --git a/extern/audaspace/include/fx/HRTF.h b/extern/audaspace/include/fx/HRTF.h new file mode 100644 index 00000000000..750d5f18991 --- /dev/null +++ b/extern/audaspace/include/fx/HRTF.h @@ -0,0 +1,108 @@ +/******************************************************************************* +* Copyright 2015-2016 Juan Francisco Crespo Galán +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +******************************************************************************/ + +#pragma once + +/** +* @file HRTF.h +* @ingroup fx +* The HRTF class. +*/ + +#include "util/StreamBuffer.h" +#include "util/FFTPlan.h" +#include "ImpulseResponse.h" + +#include <memory> +#include <vector> +#include <unordered_map> +#include <utility> + +AUD_NAMESPACE_BEGIN + +/** +* This class represents a complete set of HRTFs. +*/ +class AUD_API HRTF +{ +private: + /** + * An unordered map of unordered maps containing the ImpulseResponse objects of the HRTFs. + */ + std::unordered_map<float, std::unordered_map<float, std::shared_ptr<ImpulseResponse>>> m_hrtfs; + + /** + * The FFTPlan used to create the ImpulseResponses. + */ + std::shared_ptr<FFTPlan> m_plan; + + /** + * The specifications of the HRTFs. + */ + Specs m_specs; + + /** + * True if the HRTF object is empty. + */ + bool m_empty; + + // delete copy constructor and operator= + HRTF(const HRTF&) = delete; + HRTF& operator=(const HRTF&) = delete; + +public: + /** + * Creates a new empty HRTF object that will instance it own FFTPlan with default size. + */ + HRTF(); + + /** + * Creates a new empty HRTF object. + * \param plan A shared pointer to a FFT plan used to transform the impulse responses added. + */ + HRTF(std::shared_ptr<FFTPlan> plan); + + /** + * Adds a new HRTF to the class. + * \param impulseResponse A shared pointer to an StreamBuffer with the HRTF. + * \param azimuth The azimuth angle of the HRTF. Interval [0,360). + * \param elevation The elevation angle of the HRTF. + * \return True if the impulse response was added successfully, false otherwise (the specs weren't correct). + */ + bool addImpulseResponse(std::shared_ptr<StreamBuffer> impulseResponse, float azimuth, float elevation); + + /** + * 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). + * \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) + * \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. + * \return A pair of shared pointers to ImpulseResponse objects containing the HRTFs for the left (first element) and right (second element) ears. + */ + std::pair<std::shared_ptr<ImpulseResponse>, std::shared_ptr<ImpulseResponse>> getImpulseResponse(float &azimuth, float &elevation); + + /** + * Retrieves the specs shared by all the HRTFs. + * \return The shared specs of all the HRTFs. + */ + Specs getSpecs(); + + /** + * Retrieves the state of the HRTF object. + * \return True if it is empty, false otherwise. + */ + bool isEmpty(); +}; + +AUD_NAMESPACE_END diff --git a/extern/audaspace/include/fx/HRTFLoader.h b/extern/audaspace/include/fx/HRTFLoader.h new file mode 100644 index 00000000000..893184ae909 --- /dev/null +++ b/extern/audaspace/include/fx/HRTFLoader.h @@ -0,0 +1,99 @@ +/******************************************************************************* +* Copyright 2015-2016 Juan Francisco Crespo Galán +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +******************************************************************************/ + +#pragma once + +/** +* @file HRTFLoader.h +* @ingroup fx +* The HRTFLoader class. +*/ + +#include "Audaspace.h" +#include "fx/HRTF.h" +#include "util/FFTPlan.h" + +#include <string> +#include <memory> + +AUD_NAMESPACE_BEGIN + +/** +* This loader provides a method to load all the HRTFs in one directory, provided they follow the following naming scheme: +* Example: L-10e210a.wav +* The first character refers to the ear from which the HRTF was recorded: 'L' for a left ear and 'R' for a right ear. +* Next is the elevation angle followed by the 'e' character. [-90, 90] +* Then is the azimuth angle followed by the 'a' character. [0, 360) +* For a sound source situated at the left of the listener the azimuth angle regarding the left ear is 90 while the angle regarding the right ear is 270. +* KEMAR HRTFs use this naming scheme. +*/ +class AUD_API HRTFLoader +{ +private: + // delete normal constructor, copy constructor and operator= + HRTFLoader(const HRTFLoader&) = delete; + HRTFLoader& operator=(const HRTFLoader&) = delete; + HRTFLoader() = delete; + +public: + /** + * Loads all the left ear HRTFs in the directory.Onle one ear HRTFs for all azimuths [0,360) are needed for binaural sound. + * \param plan The plan that will be used to create the HRTF object. + * \param fileExtension The extension of the HRTF files. + * \param path The path to the folder containing the HRTFs. + * \return A shared pointer to a loaded HRTF object. + */ + static std::shared_ptr<HRTF> loadLeftHRTFs(std::shared_ptr<FFTPlan> plan, const std::string& fileExtension, const std::string& path = ""); + + /** + * Loads all the right ear HRTFs in the directory. Onle one ear HRTFs for all azimuths [0,360) are needed for binaural sound. + * \param plan The plan that will be used to create the HRTF object. + * \param fileExtension The extension of the HRTF files. + * \param path The path to the folder containing the HRTFs. + * \return A shared pointer to a loaded HRTF object. + */ + static std::shared_ptr<HRTF> loadRightHRTFs(std::shared_ptr<FFTPlan> plan, const std::string& fileExtension, const std::string& path = ""); + + /** + * Loads all the left ear HRTFs in the directory.Onle one ear HRTFs for all azimuths [0,360) are needed for binaural sound. + * \param fileExtension The extension of the HRTF files. + * \param path The path to the folder containing the HRTFs. + * \return A shared pointer to a loaded HRTF object. + */ + static std::shared_ptr<HRTF> loadLeftHRTFs(const std::string& fileExtension, const std::string& path = ""); + + /** + * Loads all the right ear HRTFs in the directory. Onle one ear HRTFs for all azimuths [0,360) are needed for binaural sound. + * \param fileExtension The extension of the HRTF files. + * \param path The path to the folder containing the HRTFs. + * \return A shared pointer to a loaded HRTF object. + */ + static std::shared_ptr<HRTF> loadRightHRTFs(const std::string& fileExtension, const std::string& path = ""); + + +private: + + /** + * Loads all the HRTFs in the directory and subdirectories. + * \param hrtfs An HRTF object in which to load the HRTFs. + * \param ear 'L' to load left ear HRTFs, 'R' to load right ear HRTFs. + * \param fileExtension The extension of the HRTF files. + * \param path The path to the folder containing the HRTFs. + */ + static void loadHRTFs(std::shared_ptr<HRTF>hrtfs, char ear, const std::string& fileExtension, const std::string& path = ""); +}; + +AUD_NAMESPACE_END diff --git a/extern/audaspace/include/fx/Highpass.h b/extern/audaspace/include/fx/Highpass.h new file mode 100644 index 00000000000..6bfb6d7885d --- /dev/null +++ b/extern/audaspace/include/fx/Highpass.h @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright 2009-2016 Jörg Müller + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +#pragma once + +/** + * @file Highpass.h + * @ingroup fx + * The Highpass class. + */ + +#include "fx/DynamicIIRFilter.h" + +AUD_NAMESPACE_BEGIN + +/** + * This sound creates a highpass filter reader. + */ +class AUD_API Highpass : public DynamicIIRFilter +{ +private: + // delete copy constructor and operator= + Highpass(const Highpass&) = delete; + Highpass& operator=(const Highpass&) = delete; + +public: + /** + * Creates a new highpass sound. + * \param sound The input sound. + * \param frequency The cutoff frequency. + * \param Q The Q factor. + */ + Highpass(std::shared_ptr<ISound> sound, float frequency, float Q = 1.0f); +}; + +AUD_NAMESPACE_END diff --git a/extern/audaspace/include/fx/HighpassCalculator.h b/extern/audaspace/include/fx/HighpassCalculator.h new file mode 100644 index 00000000000..9306a3d20e5 --- /dev/null +++ b/extern/audaspace/include/fx/HighpassCalculator.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright 2009-2016 Jörg Müller + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +#pragma once + +/** + * @file HighpassCalculator.h + * @ingroup fx + * The HighpassCalculator class. + */ + +#include "fx/IDynamicIIRFilterCalculator.h" + +AUD_NAMESPACE_BEGIN + +/** + * The HighpassCalculator class calculates high pass filter coefficients for a + * dynamic DynamicIIRFilter. + */ +class AUD_LOCAL HighpassCalculator : public IDynamicIIRFilterCalculator +{ +private: + /** + * The cutoff frequency. + */ + const float m_frequency; + + /** + * The Q factor. + */ + const float m_Q; + + // delete copy constructor and operator= + HighpassCalculator(const HighpassCalculator&) = delete; + HighpassCalculator& operator=(const HighpassCalculator&) = delete; + +public: + /** + * Creates a HighpassCalculator object. + * @param frequency The cutoff frequency. + * @param Q The Q factor of the filter. If unsure, use 1.0 as default. + */ + HighpassCalculator(float frequency, float Q); + + virtual void recalculateCoefficients(SampleRate rate, std::vector<float> &b, std::vector<float> &a); +}; + +AUD_NAMESPACE_END diff --git a/extern/audaspace/include/fx/IDynamicIIRFilterCalculator.h b/extern/audaspace/include/fx/IDynamicIIRFilterCalculator.h new file mode 100644 index 00000000000..6c890b313b4 --- /dev/null +++ b/extern/audaspace/include/fx/IDynamicIIRFilterCalculator.h @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright 2009-2016 Jörg Müller + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +#pragma once + +/** + * @file IDynamicIIRFilterCalculator.h + * @ingroup fx + * The IDynamicIIRFilterCalculator interface. + */ + +#include "respec/Specification.h" + +#include <vector> + +AUD_NAMESPACE_BEGIN + +/** + * @interface IDynamicIIRFilterCalculator + * This interface calculates dynamic filter coefficients which depend on the + * sampling rate for DynamicIIRFilterReaders. + */ +class AUD_API IDynamicIIRFilterCalculator +{ +public: + virtual ~IDynamicIIRFilterCalculator() {} + + /** + * Recalculates the filter coefficients. + * \param rate The sample rate of the audio data. + * \param[out] b The input filter coefficients. + * \param[out] a The output filter coefficients. + */ + virtual void recalculateCoefficients(SampleRate rate, std::vector<float>& b, std::vector<float>& a)=0; +}; + +AUD_NAMESPACE_END diff --git a/extern/audaspace/include/fx/IIRFilter.h b/extern/audaspace/include/fx/IIRFilter.h new file mode 100644 index 00000000000..74099a30dc5 --- /dev/null +++ b/extern/audaspace/include/fx/IIRFilter.h @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright 2009-2016 Jörg Müller + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +#pragma once + +/** + * @file IIRFilter.h + * @ingroup fx + * The IIRFilter class. + */ + +#include "fx/Effect.h" + +#include <vector> + +AUD_NAMESPACE_BEGIN + +/** + * This sound creates a IIR filter reader. + */ +class AUD_API IIRFilter : public Effect +{ +private: + /** + * Output filter coefficients. + */ + std::vector<float> m_a; + + /** + * Input filter coefficients. + */ + std::vector<float> m_b; + + // delete copy constructor and operator= + IIRFilter(const IIRFilter&) = delete; + IIRFilter& operator=(const IIRFilter&) = delete; + +public: + /** + * Creates a new IIR filter sound. + * \param sound The input sound. + * \param b The input filter coefficients. + * \param a The output filter coefficients. + */ + IIRFilter(std::shared_ptr<ISound> sound, const std::vector<float>& b, const std::vector<float>& a); + + virtual std::shared_ptr<IReader> createReader(); +}; + +AUD_NAMESPACE_END diff --git a/extern/audaspace/include/fx/IIRFilterReader.h b/extern/audaspace/include/fx/IIRFilterReader.h new file mode 100644 index 00000000000..34518ce69c6 --- /dev/null +++ b/extern/audaspace/include/fx/IIRFilterReader.h @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright 2009-2016 Jörg Müller + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +#pragma once + +/** + * @file IIRFilterReader.h + * @ingroup fx + * The IIRFilterReader class. + */ + +#include "fx/BaseIIRFilterReader.h" + +#include <vector> + +AUD_NAMESPACE_BEGIN + +/** + * This class is for infinite impulse response filters with simple coefficients. + */ +class AUD_API IIRFilterReader : public BaseIIRFilterReader +{ +private: + /** + * Output filter coefficients. + */ + std::vector<float> m_a; + + /** + * Input filter coefficients. + */ + std::vector<float> m_b; + + // delete copy constructor and operator= + IIRFilterReader(const IIRFilterReader&) = delete; + IIRFilterReader& operator=(const IIRFilterReader&) = delete; + +public: + /** + * Creates a new IIR filter reader. + * \param reader The reader to read from. + * \param b The input filter coefficients. + * \param a The output filter coefficients. + */ + IIRFilterReader(std::shared_ptr<IReader> reader, const std::vector<float>& b, const std::vector<float>& a); + + virtual sample_t filter(); + + /** + * Sets new filter coefficients. + * @param b The input filter coefficients. + * @param a The output filter coefficients. + */ + void setCoefficients(const std::vector<float>& b, const std::vector<float>& a); +}; + +AUD_NAMESPACE_END diff --git a/extern/audaspace/include/fx/ImpulseResponse.h b/extern/audaspace/include/fx/ImpulseResponse.h new file mode 100644 index 00000000000..3cdb807ff99 --- /dev/null +++ b/extern/audaspace/include/fx/ImpulseResponse.h @@ -0,0 +1,108 @@ +/******************************************************************************* +* Copyright 2015-2016 Juan Francisco Crespo Galán +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +******************************************************************************/ + +#pragma once + +/** +* @file ImpulseResponse.h +* @ingroup fx +* The ImpulseResponse class. +*/ + +#include "util/StreamBuffer.h" +#include "util/FFTPlan.h" +#include "IReader.h" + +#include <memory> +#include <vector> + +AUD_NAMESPACE_BEGIN + +/** +* This class represents an impulse response that can be used in convolution. +* When this class is instanced, the impulse response is divided in channels and those channels are divided in parts of N/2 samples (N being the size of the FFT plan used). +* The main objetive of this class is to allow the reutilization of an impulse response in various sounds without having to process it more than one time. +* \warning The size of the FFTPlan used to process the impulse response must be the same as the one used in the convolver classes. +*/ +class AUD_API ImpulseResponse +{ +private: + /** + * A tri-dimensional array (channels, parts, values) The impulse response is divided in channels and those channels are divided + * in parts of N/2 samples. Those parts are transformed to the frequency domain transform which generates uni-dimensional + * arrays of fftwtf_complex data (complex numbers). + */ + std::vector<std::shared_ptr<std::vector<std::shared_ptr<std::vector<std::complex<sample_t>>>>>> m_processedIR; + + /** + * The specification of the samples. + */ + Specs m_specs; + + /** + * The length of the impulse response. + */ + int m_length; + + // delete copy constructor and operator= + ImpulseResponse(const ImpulseResponse&) = delete; + ImpulseResponse& operator=(const ImpulseResponse&) = delete; + +public: + /** + * Creates a new ImpulseResponse object. + * The impulse response will be split and transformed to the frequency domain. + * \param impulseResponse The impulse response sound. + * \param plan A shared pointer to a FFT plan used to transform the impulse response. + */ + ImpulseResponse(std::shared_ptr<StreamBuffer> impulseResponse, std::shared_ptr<FFTPlan> plan); + + /** + * Creates a new ImpulseResponse object. This overload instances its own FFTPlan with default size. + * The impulse response will be split and transformed to the frequency domain. + * \param impulseResponse The impulse response sound. + */ + ImpulseResponse(std::shared_ptr<StreamBuffer> impulseResponse); + + /** + * Returns the specification of the impulse response. + * \return The specification of the impulse response. + */ + Specs getSpecs(); + + /** + * Retrieves the length of the impulse response. + * \return The length of the impulse response. + */ + int getLength(); + + /** + * Retrieves one channel of the impulse response. + * \param n The desired channel number (from 0 to channels-1). + * \return The desired channel of the impulse response. + */ + std::shared_ptr<std::vector<std::shared_ptr<std::vector<std::complex<sample_t>>>>> getChannel(int n); + +private: + /** + * Processes the impulse response sound for its use in the convovler classes. + * \param A shared pointer to a reader of the desired sound. + * \param plan A shared pointer to a FFT plan used to transform the impulse response. + */ + void processImpulseResponse(std::shared_ptr<IReader> reader, std::shared_ptr<FFTPlan> plan); +}; + +AUD_NAMESPACE_END diff --git a/extern/audaspace/include/fx/Limiter.h b/extern/audaspace/include/fx/Limiter.h new file mode 100644 index 00000000000..0b5451b4eed --- /dev/null +++ b/extern/audaspace/include/fx/Limiter.h @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright 2009-2016 Jörg Müller + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +#pragma once + +/** + * @file Limiter.h + * @ingroup fx + * The Limiter class. + */ + +#include "fx/Effect.h" + +AUD_NAMESPACE_BEGIN + +/** + * This sound limits another sound in start and end time. + */ +class AUD_API Limiter : public Effect +{ +private: + /** + * The start time. + */ + const float m_start; + + /** + * The end time. + */ + const float m_end; + + // delete copy constructor and operator= + Limiter(const Limiter&) = delete; + Limiter& operator=(const Limiter&) = delete; + +public: + /** + * Creates a new limiter sound. + * \param sound The input sound. + * \param start The desired start time. + * \param end The desired end time, a negative value signals that it should + * play to the end. + */ + Limiter(std::shared_ptr<ISound> sound, + float start = 0, float end = -1); + + /** + * Returns the start time. + */ + float getStart() const; + + /** + * Returns the end time. + */ + float getEnd() const; + + virtual std::shared_ptr<IReader> createReader(); +}; + +AUD_NAMESPACE_END diff --git a/extern/audaspace/include/fx/LimiterReader.h b/extern/audaspace/include/fx/LimiterReader.h new file mode 100644 index 00000000000..49a07b5c29e --- /dev/null +++ b/extern/audaspace/include/fx/LimiterReader.h @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright 2009-2016 Jörg Müller + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +#pragma once + +/** + * @file LimiterReader.h + * @ingroup fx + * The LimiterReader class. + */ + +#include "fx/EffectReader.h" + +AUD_NAMESPACE_BEGIN + +/** + * This reader limits another reader in start and end times. + */ +class AUD_API LimiterReader : public EffectReader +{ +private: + /** + * The start sample: inclusive. + */ + const float m_start; + + /** + * The end sample: exlusive. + */ + const float m_end; + + // delete copy constructor and operator= + LimiterReader(const LimiterReader&) = delete; + LimiterReader& operator=(const LimiterReader&) = delete; + +public: + /** + * Creates a new limiter reader. + * \param reader The reader to read from. + * \param start The desired start time (inclusive). + * \param end The desired end time (sample exklusive), a negative value + * signals that it should play to the end. + */ + LimiterReader(std::shared_ptr<IReader> reader, float start = 0, float end = -1); + + virtual void seek(int position); + virtual int getLength() const; + virtual int getPosition() const; + virtual void read(int& length, bool& eos, sample_t* buffer); +}; + +AUD_NAMESPACE_END diff --git a/extern/audaspace/include/fx/Loop.h b/extern/audaspace/include/fx/Loop.h new file mode 100644 index 00000000000..c8ba7609f23 --- /dev/null +++ b/extern/audaspace/include/fx/Loop.h @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright 2009-2016 Jörg Müller + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +#pragma once + +/** + * @file Loop.h + * @ingroup fx + * The Loop class. + */ + +#include "fx/Effect.h" + +AUD_NAMESPACE_BEGIN + +/** + * This sound loops another sound. + * \note The reader has to be seekable. + */ +class AUD_API Loop : public Effect +{ +private: + /** + * The loop count. + */ + const int m_loop; + + // delete copy constructor and operator= + Loop(const Loop&) = delete; + Loop& operator=(const Loop&) = delete; + +public: + /** + * Creates a new loop sound. + * \param sound The input sound. + * \param loop The desired loop count, negative values result in endless + * looping. + */ + Loop(std::shared_ptr<ISound> sound, int loop = -1); + + /** + * Returns the loop count. + */ + int getLoop() const; + + virtual std::shared_ptr<IReader> createReader(); +}; + +AUD_NAMESPACE_END diff --git a/extern/audaspace/include/fx/LoopReader.h b/extern/audaspace/include/fx/LoopReader.h new file mode 100644 index 00000000000..72bb92c8b8f --- /dev/null +++ b/extern/audaspace/include/fx/LoopReader.h @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright 2009-2016 Jörg Müller + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +#pragma once + +/** + * @file LoopReader.h + * @ingroup fx + * The LoopReader class. + */ + +#include "fx/EffectReader.h" + +AUD_NAMESPACE_BEGIN + +/** + * This class reads another reader and loops it. + * \note The other reader must be seekable. + */ +class AUD_API LoopReader : public EffectReader +{ +private: + /** + * The loop count. + */ + const int m_count; + + /** + * The left loop count. + */ + int m_left; + + // delete copy constructor and operator= + LoopReader(const LoopReader&) = delete; + LoopReader& operator=(const LoopReader&) = delete; + +public: + /** + * Creates a new loop reader. + * \param reader The reader to read from. + * \param loop The desired loop count, negative values result in endless + * looping. + */ + LoopReader(std::shared_ptr<IReader> reader, int loop); + + virtual void seek(int position); + virtual int getLength() const; + virtual int getPosition() const; + virtual void read(int& length, bool& eos, sample_t* buffer); +}; + +AUD_NAMESPACE_END diff --git a/extern/audaspace/include/fx/Lowpass.h b/extern/audaspace/include/fx/Lowpass.h new file mode 100644 index 00000000000..c14e5e8e0e2 --- /dev/null +++ b/extern/audaspace/include/fx/Lowpass.h @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright 2009-2016 Jörg Müller + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +#pragma once + +/** + * @file Lowpass.h + * @ingroup fx + * The Lowpass class. + */ + +#include "fx/DynamicIIRFilter.h" + +AUD_NAMESPACE_BEGIN + +/** + * This sound creates a lowpass filter reader. + */ +class AUD_API Lowpass : public DynamicIIRFilter +{ +private: + // delete copy constructor and operator= + Lowpass(const Lowpass&) = delete; + Lowpass& operator=(const Lowpass&) = delete; + +public: + /** + * Creates a new lowpass sound. + * \param sound The input sound. + * \param frequency The cutoff frequency. + * \param Q The Q factor. + */ + Lowpass(std::shared_ptr<ISound> sound, float frequency, float Q = 1.0f); +}; + +AUD_NAMESPACE_END diff --git a/extern/audaspace/include/fx/LowpassCalculator.h b/extern/audaspace/include/fx/LowpassCalculator.h new file mode 100644 index 00000000000..477adfb5b5b --- /dev/null +++ b/extern/audaspace/include/fx/LowpassCalculator.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright 2009-2016 Jörg Müller + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +#pragma once + +/** + * @file LowpassCalculator.h + * @ingroup fx + * The LowpassCalculator class. + */ + +#include "fx/IDynamicIIRFilterCalculator.h" + +AUD_NAMESPACE_BEGIN + +/** + * The LowpassCalculator class calculates low pass filter coefficients for a + * dynamic DynamicIIRFilter. + */ +class AUD_LOCAL LowpassCalculator : public IDynamicIIRFilterCalculator +{ +private: + /** + * The cutoff frequency. + */ + const float m_frequency; + + /** + * The Q factor. + */ + const float m_Q; + + // delete copy constructor and operator= + LowpassCalculator(const LowpassCalculator&) = delete; + LowpassCalculator& operator=(const LowpassCalculator&) = delete; + +public: + /** + * Creates a LowpassCalculator object. + * @param frequency The cutoff frequency. + * @param Q The Q factor of the filter. If unsure, use 1.0 as default. + */ + LowpassCalculator(float frequency, float Q); + + virtual void recalculateCoefficients(SampleRate rate, std::vector<float> &b, std::vector<float> &a); +}; + +AUD_NAMESPACE_END diff --git a/extern/audaspace/include/fx/MutableReader.h b/extern/audaspace/include/fx/MutableReader.h new file mode 100644 index 00000000000..217dd2aa5d4 --- /dev/null +++ b/extern/audaspace/include/fx/MutableReader.h @@ -0,0 +1,71 @@ +/******************************************************************************* +* Copyright 2015-2016 Juan Francisco Crespo Galán +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +******************************************************************************/ + +#pragma once + +/** +* @file MutableReader.h +* @ingroup fx +* The MutableReader class. +*/ + +#include "IReader.h" +#include "ISound.h" + +#include <memory> + +AUD_NAMESPACE_BEGIN + +/** +* This class represents a reader for a sound that can change with each playback. The change will occur when trying to seek backwards +* If the sound doesn't support that, it will be restarted. +* \warning Notice that if a SoundList object is assigned to several MutableReaders, sequential playback won't work correctly. +* To prevent this the SoundList must be copied. +*/ +class AUD_API MutableReader : public IReader +{ +private: + /** + * The current reader. + */ + std::shared_ptr<IReader> m_reader; + + /** + * A sound from which to get the reader. + */ + std::shared_ptr<ISound> m_sound; + + + // delete copy constructor and operator= + MutableReader(const MutableReader&) = delete; + MutableReader& operator=(const MutableReader&) = delete; + +public: + /** + * Creates a new mutable reader. + * \param sound A of sound you want to assign to this reader. + */ + MutableReader(std::shared_ptr<ISound> sound); + + virtual bool isSeekable() const; + virtual void seek(int position); + virtual int getLength() const; + virtual int getPosition() const; + virtual Specs getSpecs() const; + virtual void read(int& length, bool& eos, sample_t* buffer); +}; + +AUD_NAMESPACE_END diff --git a/extern/audaspace/include/fx/MutableSound.h b/extern/audaspace/include/fx/MutableSound.h new file mode 100644 index 00000000000..9b5aa95cf18 --- /dev/null +++ b/extern/audaspace/include/fx/MutableSound.h @@ -0,0 +1,58 @@ +/******************************************************************************* +* Copyright 2015-2016 Juan Francisco Crespo Galán +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +******************************************************************************/ + +#pragma once + +/** +* @file MutableSound.h +* @ingroup fx +* The MutableSound class. +*/ + +#include "ISound.h" + +#include <memory> + +AUD_NAMESPACE_BEGIN + +/** +* Ths class allows to create MutableReaders for any sound. +*/ +class AUD_API MutableSound : public ISound +{ +private: + /** + * A pointer to a sound. + */ + std::shared_ptr<ISound> m_sound; + + // delete copy constructor and operator= + MutableSound(const MutableSound&) = delete; + MutableSound& operator=(const MutableSound&) = delete; + +public: + /** + * Creates a new MutableSound. + * \param sound The sound in which the MutabeReaders created with the createReader() method will be based. + * If shared pointer to a SoundList object is used in several mutable sounds the sequential + * playback will not work properly. A copy of the SoundList object must be made in this case. + */ + MutableSound(std::shared_ptr<ISound> sound); + + virtual std::shared_ptr<IReader> createReader(); +}; + +AUD_NAMESPACE_END
\ No newline at end of file diff --git a/extern/audaspace/include/fx/Pitch.h b/extern/audaspace/include/fx/Pitch.h new file mode 100644 index 00000000000..570366be549 --- /dev/null +++ b/extern/audaspace/include/fx/Pitch.h @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright 2009-2016 Jörg Müller + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +#pragma once + +/** + * @file Pitch.h + * @ingroup fx + * The Pitch class. + */ + +#include "fx/Effect.h" + +AUD_NAMESPACE_BEGIN + +/** + * This sound changes the pitch of another sound. + */ +class AUD_API Pitch : public Effect +{ +private: + /** + * The pitch. + */ + const float m_pitch; + + // delete copy constructor and operator= + Pitch(const Pitch&) = delete; + Pitch& operator=(const Pitch&) = delete; + +public: + /** + * Creates a new pitch sound. + * \param sound The input sound. + * \param pitch The desired pitch. + */ + Pitch(std::shared_ptr<ISound> sound, float pitch); + + virtual std::shared_ptr<IReader> createReader(); +}; + +AUD_NAMESPACE_END diff --git a/extern/audaspace/include/fx/PitchReader.h b/extern/audaspace/include/fx/PitchReader.h new file mode 100644 index 00000000000..c82f71b61bf --- /dev/null +++ b/extern/audaspace/include/fx/PitchReader.h @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright 2009-2016 Jörg Müller + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +#pragma once + +/** + * @file PitchReader.h + * @ingroup fx + * The PitchReader class. + */ + +#include "fx/EffectReader.h" + +AUD_NAMESPACE_BEGIN + +/** + * This class reads another reader and changes it's pitch. + */ +class AUD_API PitchReader : public EffectReader +{ +private: + /** + * The pitch level. + */ + float m_pitch; + + // delete copy constructor and operator= + PitchReader(const PitchReader&) = delete; + PitchReader& operator=(const PitchReader&) = delete; + +public: + /** + * Creates a new pitch reader. + * \param reader The reader to read from. + * \param pitch The pitch value. + */ + PitchReader(std::shared_ptr<IReader> reader, float pitch); + + virtual Specs getSpecs() const; + + /** + * Retrieves the pitch. + * \return The current pitch value. + */ + float getPitch() const; + + /** + * Sets the pitch. + * \param pitch The new pitch value. + */ + void setPitch(float pitch); +}; + +AUD_NAMESPACE_END diff --git a/extern/audaspace/include/fx/PlaybackCategory.h b/extern/audaspace/include/fx/PlaybackCategory.h new file mode 100644 index 00000000000..7721623359f --- /dev/null +++ b/extern/audaspace/include/fx/PlaybackCategory.h @@ -0,0 +1,127 @@ +/******************************************************************************* +* Copyright 2015-2016 Juan Francisco Crespo Galán +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +******************************************************************************/ + +#pragma once + +/** +* @file PlaybackCategory.h +* @ingroup fx +* The PlaybackCategory class. +*/ + +#include "devices/IHandle.h" +#include "devices/IDevice.h" +#include "VolumeStorage.h" + +#include <unordered_map> +#include <memory> + +AUD_NAMESPACE_BEGIN + +/** +* This class represents a category of related sounds which are currently playing and allows to control them easily. +*/ +class AUD_API PlaybackCategory +{ +private: + /** + * Next handle ID to be assigned. + */ + unsigned int m_currentID; + + /** + * Vector of handles that belong to the category. + */ + std::unordered_map<unsigned int, std::shared_ptr<IHandle>> m_handles; + + /** + * Device that will play the sounds. + */ + std::shared_ptr<IDevice> m_device; + + /** + * Status of the category. + */ + Status m_status; + + /** + * Volume of all the sounds of the category. + */ + std::shared_ptr<VolumeStorage> m_volumeStorage; + + // delete copy constructor and operator= + PlaybackCategory(const PlaybackCategory&) = delete; + PlaybackCategory& operator=(const PlaybackCategory&) = delete; + +public: + /** + * Creates a new PlaybackCategory. + * \param device A shared pointer to the device which will be used for playback. + */ + PlaybackCategory(std::shared_ptr<IDevice> device); + ~PlaybackCategory(); + + /** + * Plays a new sound in the category. + * \param sound The sound to be played. + * \return A handle for the playback. If the playback failed, nullptr will be returned. + */ + std::shared_ptr<IHandle> play(std::shared_ptr<ISound> sound); + + /** + * Resumes all the paused sounds of the category. + */ + void resume(); + + /** + * Pauses all current played back sounds of the category. + */ + void pause(); + + /** + * Retrieves the volume of the category. + * \return The volume. + */ + float getVolume(); + + /** + * Sets the volume for the category. + * \param volume The volume. + */ + void setVolume(float volume); + + /** + * Stops all the playing back or paused sounds. + */ + void stop(); + + /** + * Retrieves the shared volume of the category. + * \return A shared pointer to the VolumeStorage object that represents the shared volume of the category. + */ + std::shared_ptr<VolumeStorage> getSharedVolume(); + + /** + * Cleans the category erasing all the invalid handles. + * Only needed if individual sounds are stopped with their handles. + */ + void cleanHandles(); + +private: + static void cleanHandleCallback(void* data); +}; + +AUD_NAMESPACE_END diff --git a/extern/audaspace/include/fx/PlaybackManager.h b/extern/audaspace/include/fx/PlaybackManager.h new file mode 100644 index 00000000000..f660568b8db --- /dev/null +++ b/extern/audaspace/include/fx/PlaybackManager.h @@ -0,0 +1,156 @@ +/******************************************************************************* +* Copyright 2015-2016 Juan Francisco Crespo Galán +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +******************************************************************************/ + +#pragma once + +/** +* @file PlaybackManager.h +* @ingroup fx +* The PlaybackManager class. +*/ + +#include "PlaybackCategory.h" +#include "devices/IDevice.h" +#include "ISound.h" + +#include <unordered_map> +#include <memory> + +AUD_NAMESPACE_BEGIN + +/** +* This class allows to control groups of playing sounds easily. +* The sounds are part of categories. +*/ +class AUD_API PlaybackManager +{ +private: + /** + * Unordered map of categories, each category has different name. + */ + std::unordered_map<unsigned int, std::shared_ptr<PlaybackCategory>> m_categories; + + /** + * Device used for playback. + */ + std::shared_ptr<IDevice> m_device; + + /** + * The current key used for new categories. + */ + unsigned int m_currentKey; + + // delete copy constructor and operator= + PlaybackManager(const PlaybackManager&) = delete; + PlaybackManager& operator=(const PlaybackManager&) = delete; + +public: + /** + * Creates a new PlaybackManager. + * \param device A shared pointer to the device which will be used for playback. + */ + PlaybackManager(std::shared_ptr<IDevice> device); + + /** + * Adds an existent category to the manager and returns a key to access it. + * \param category The category to be added. + * \return The category key. + */ + unsigned int addCategory(std::shared_ptr<PlaybackCategory> category); + + /** + * Adds an existent category to the manager and returns a key to access it. + * \param volume The volume of the new category. + * \return The category key. + */ + unsigned int addCategory(float volume); + + /** + * Plays a sound and adds it to a new or existent category. + * \param sound The sound to be played and added to a category. + * \param catKey Key of the category. + * \return The handle of the playback; nullptr if the sound couldn't be played. + */ + std::shared_ptr<IHandle> play(std::shared_ptr<ISound> sound, unsigned int catKey); + + /** + * Resumes all the paused sounds of a category. + * \param catKey Key of the category. + * \return + * - true if succesful. + * - false if the category doesn't exist. + */ + bool resume(unsigned int catKey); + + /** + * Pauses all current playing sounds of a category. + * \param catKey Key of the category. + * \return + * - true if succesful. + * - false if the category doesn't exist. + */ + bool pause(unsigned int catKey); + + /** + * Retrieves the volume of a category. + * \param catKey Key of the category. + * \return The volume value of the category. If the category doesn't exist it returns a negative number. + */ + float getVolume(unsigned int catKey); + + /** + * Sets the volume for a category. + * \param volume The volume. + * \param catKey Key of the category. + * \return + * - true if succesful. + * - false if the category doesn't exist. + */ + bool setVolume(float volume, unsigned int catKey); + + /** + * Stops and erases a category of sounds. + * \param catKey Key of the category. + * \return + * - true if succesful. + * - false if the category doesn't exist. + */ + bool stop(unsigned int catKey); + + /** + * Removes all the invalid handles of all the categories. + * Only needed if individual sounds are stopped with their handles. + */ + void clean(); + + /** + * Removes all the invalid handles of a category. + * Only needed if individual sounds are stopped with their handles. + * \param catKey Key of the category. + * \return + * - true if succesful. + * - false if the category doesn't exist. + */ + bool clean(unsigned int catKey); + + /** + * Retrieves the device of the PlaybackManager. + * \return A shared pointer to the device used by the playback manager. + */ + std::shared_ptr<IDevice> getDevice(); +}; + +AUD_NAMESPACE_END diff --git a/extern/audaspace/include/fx/Reverse.h b/extern/audaspace/include/fx/Reverse.h new file mode 100644 index 00000000000..32227da977a --- /dev/null +++ b/extern/audaspace/include/fx/Reverse.h @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright 2009-2016 Jörg Müller + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +#pragma once + +/** + * @file Reverse.h + * @ingroup fx + * The Reverse class. + */ + +#include "fx/Effect.h" + +AUD_NAMESPACE_BEGIN + +/** + * This sound reads another sound reverted. + * \note Readers from the underlying sound must be seekable. + */ +class AUD_API Reverse : public Effect +{ +private: + // delete copy constructor and operator= + Reverse(const Reverse&) = delete; + Reverse& operator=(const Reverse&) = delete; + +public: + /** + * Creates a new reverse sound. + * \param sound The input sound. + */ + Reverse(std::shared_ptr<ISound> sound); + + virtual std::shared_ptr<IReader> createReader(); +}; + +AUD_NAMESPACE_END diff --git a/extern/audaspace/include/fx/ReverseReader.h b/extern/audaspace/include/fx/ReverseReader.h new file mode 100644 index 00000000000..a02608e1378 --- /dev/null +++ b/extern/audaspace/include/fx/ReverseReader.h @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright 2009-2016 Jörg Müller + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +#pragma once + +/** + * @file ReverseReader.h + * @ingroup fx + * The ReverseReader class. + */ + +#include "fx/EffectReader.h" + +AUD_NAMESPACE_BEGIN + +/** + * This class reads another reader from back to front. + * \note The underlying reader must be seekable. + */ +class AUD_API ReverseReader : public EffectReader +{ +private: + /** + * The sample count. + */ + const int m_length; + + /** + * The current position. + */ + int m_position; + + // delete copy constructor and operator= + ReverseReader(const ReverseReader&) = delete; + ReverseReader& operator=(const ReverseReader&) = delete; + +public: + /** + * Creates a new reverse reader. + * \param reader The reader to read from. + * \exception Exception Thrown if the reader specified has an + * undeterminable/infinite length or is not seekable. + */ + ReverseReader(std::shared_ptr<IReader> reader); + + virtual void seek(int position); + virtual int getLength() const; + virtual int getPosition() const; + virtual void read(int& length, bool& eos, sample_t* buffer); +}; + +AUD_NAMESPACE_END diff --git a/extern/audaspace/include/fx/SoundList.h b/extern/audaspace/include/fx/SoundList.h new file mode 100644 index 00000000000..ce3cb386969 --- /dev/null +++ b/extern/audaspace/include/fx/SoundList.h @@ -0,0 +1,110 @@ +/******************************************************************************* +* Copyright 2015-2016 Juan Francisco Crespo Galán +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +******************************************************************************/ + +#pragma once + +/** +* @file SoundList.h +* @ingroup fx +* The SoundList class. +*/ + +#include "ISound.h" + +#include <vector> +#include <memory> +#include <mutex> + +AUD_NAMESPACE_BEGIN + +/** +* This class allows to have a list of sound that will play sequentially or randomly with each playback. +*/ +class AUD_API SoundList : public ISound +{ +private: + /** + * The list of sounds that will play. + */ + std::vector<std::shared_ptr<ISound>> m_list; + + /** + * Flag for random playback + */ + bool m_random = false; + + /** + * Current sound index. -1 if no reader has been created. + */ + int m_index = -1; + + /** + * Mutex to prevent multithreading crashes. + */ + std::recursive_mutex m_mutex; + + // delete copy constructor and operator= + SoundList(const SoundList&) = delete; + SoundList& operator=(const SoundList&) = delete; + +public: + /** + * Creates a new, empty sound list. + * Sounds must be added to the list using the addSound() method. + * \param random False if the sounds int he list must be played sequentially. True if random. + */ + SoundList(bool random = false); + + /** + * Creates a new sound list and initializes it. + * \param list A vector with sounds to initialize the list. + * \param random False if the sounds int he list must be played sequentially. True if random. + */ + SoundList(std::vector<std::shared_ptr<ISound>>& list, bool random = false); + + virtual std::shared_ptr<IReader> createReader(); + + /** + * Adds a sound to the list. + * The added sounds can be played sequentially or randomly dependig + * on the m_random flag + * \param sound A shared_ptr to the sound. + */ + void addSound(std::shared_ptr<ISound> sound); + + /** + * Sets the playback mode of the sound list. + * There are two posible modes, random and sequential. + * \param random True to activate the random mode, false to activate sequential mode. + */ + void setRandomMode(bool random); + + /** + * Returns the playback mode of the sound list. + * The two posible modes are random and sequential. + * \return True if the random mode is activated, false otherwise. + */ + bool getRandomMode(); + + /** + * Returns the amount of sounds in the list. + * \return The amount of sounds in the list. + */ + int getSize(); + +}; + +AUD_NAMESPACE_END diff --git a/extern/audaspace/include/fx/Source.h b/extern/audaspace/include/fx/Source.h new file mode 100644 index 00000000000..84448aa669d --- /dev/null +++ b/extern/audaspace/include/fx/Source.h @@ -0,0 +1,109 @@ +/******************************************************************************* +* Copyright 2015-2016 Juan Francisco Crespo Galán +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +******************************************************************************/ + +#pragma once + +/** +* @file Source.h +* @ingroup fx +* The Source class. +*/ + +#include "Audaspace.h" + +#include <atomic> + +AUD_NAMESPACE_BEGIN + +/** +* This class stores the azimuth and elevation angles of a sound and allows to change them dynamically. +* The azimuth angle goes clockwise. For a sound source situated at the right of the listener the azimuth angle is 90. +*/ +class AUD_API Source +{ +private: + /** + * Azimuth value. + */ + std::atomic<float> m_azimuth; + + /** + * Elevation value. + */ + std::atomic<float> m_elevation; + + /** + * Distance value. Between 0 and 1. + */ + std::atomic<float> m_distance; + + // delete copy constructor and operator= + Source(const Source&) = delete; + Source& operator=(const Source&) = delete; + +public: + /** + * Creates a Source instance with an initial value. + * \param azimuth The value of the azimuth. + * \param elevation The value of the elevation. + * \param distance The distance from the listener. Max distance is 1, min distance is 0. + */ + Source(float azimuth, float elevation, float distance = 0.0); + + /** + * Retrieves the current azimuth value. + * \return The current azimuth. + */ + float getAzimuth(); + + /** + * Retrieves the current elevation value. + * \return The current elevation. + */ + float getElevation(); + + /** + * Retrieves the current distance value. + * \return The current distance. + */ + float getDistance(); + + /** + * Retrieves the current volume value based on the distance. + * \return The current volume based on the Distance. + */ + float getVolume(); + + /** + * Changes the azimuth value. + * \param azimuth The new value for the azimuth. + */ + void setAzimuth(float azimuth); + + /** + * Changes the elevation value. + * \param elevation The new value for the elevation. + */ + void setElevation(float elevation); + + /** + * Changes the distance value. + * \param distance The new value for the distance. Max distance is 1, min distance is 0. + */ + void setDistance(float distance); +}; + +AUD_NAMESPACE_END
\ No newline at end of file diff --git a/extern/audaspace/include/fx/Sum.h b/extern/audaspace/include/fx/Sum.h new file mode 100644 index 00000000000..b590aa7fcd1 --- /dev/null +++ b/extern/audaspace/include/fx/Sum.h @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright 2009-2016 Jörg Müller + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +#pragma once + +/** + * @file Sum.h + * @ingroup fx + * The Sum class. + */ + +#include "fx/Effect.h" + +AUD_NAMESPACE_BEGIN + +/** + * This sound creates a sum reader. + */ +class AUD_API Sum : public Effect +{ +private: + // delete copy constructor and operator= + Sum(const Sum&) = delete; + Sum& operator=(const Sum&) = delete; + +public: + /** + * Creates a new sum sound. + * \param sound The input sound. + */ + Sum(std::shared_ptr<ISound> sound); + + virtual std::shared_ptr<IReader> createReader(); +}; + +AUD_NAMESPACE_END diff --git a/extern/audaspace/include/fx/Threshold.h b/extern/audaspace/include/fx/Threshold.h new file mode 100644 index 00000000000..10baef1714d --- /dev/null +++ b/extern/audaspace/include/fx/Threshold.h @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright 2009-2016 Jörg Müller + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +#pragma once + +/** + * @file Threshold.h + * @ingroup fx + * The Threshold class. + */ + +#include "fx/Effect.h" + +AUD_NAMESPACE_BEGIN + +class CallbackIIRFilterReader; + +/** + * This sound Transforms any signal to a square signal by thresholding. + */ +class AUD_API Threshold : public Effect +{ +private: + /** + * The threshold. + */ + const float m_threshold; + + // delete copy constructor and operator= + Threshold(const Threshold&) = delete; + Threshold& operator=(const Threshold&) = delete; + +public: + /** + * Creates a new threshold sound. + * \param sound The input sound. + * \param threshold The threshold. + */ + Threshold(std::shared_ptr<ISound> sound, float threshold = 0.0f); + + /** + * Returns the threshold. + */ + float getThreshold() const; + + virtual std::shared_ptr<IReader> createReader(); + + /** + * The thresholdFilter function implements the doFilterIIR callback + * for the callback IIR filter. + * @param reader The CallbackIIRFilterReader that executes the callback. + * @param threshold The threshold value. + * @return The filtered sample. + */ + static sample_t AUD_LOCAL thresholdFilter(CallbackIIRFilterReader* reader, float* threshold); + + /** + * The endThresholdFilter function implements the endFilterIIR callback + * for the callback IIR filter. + * @param threshold The threshold value. + */ + static void AUD_LOCAL endThresholdFilter(float* threshold); +}; + +AUD_NAMESPACE_END diff --git a/extern/audaspace/include/fx/Volume.h b/extern/audaspace/include/fx/Volume.h new file mode 100644 index 00000000000..0e56e8efd9b --- /dev/null +++ b/extern/audaspace/include/fx/Volume.h @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright 2009-2016 Jörg Müller + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +#pragma once + +/** + * @file Volume.h + * @ingroup fx + * The Volume class. + */ + +#include "fx/Effect.h" + +AUD_NAMESPACE_BEGIN + +/** + * This sound changes the volume of another sound. + * The set volume should be a value between 0.0 and 1.0, higher values at your + * own risk! + */ +class AUD_API Volume : public Effect +{ +private: + /** + * The volume. + */ + const float m_volume; + + // delete copy constructor and operator= + Volume(const Volume&) = delete; + Volume& operator=(const Volume&) = delete; + +public: + /** + * Creates a new volume sound. + * \param sound The input sound. + * \param volume The desired volume. + */ + Volume(std::shared_ptr<ISound> sound, float volume); + + /** + * Returns the volume. + * \return The current volume. + */ + float getVolume() const; + + virtual std::shared_ptr<IReader> createReader(); +}; + +AUD_NAMESPACE_END diff --git a/extern/audaspace/include/fx/VolumeReader.h b/extern/audaspace/include/fx/VolumeReader.h new file mode 100644 index 00000000000..13b6845e931 --- /dev/null +++ b/extern/audaspace/include/fx/VolumeReader.h @@ -0,0 +1,70 @@ +/******************************************************************************* +* Copyright 2015-2016 Juan Francisco Crespo Galán +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +******************************************************************************/ + +#pragma once + +/** +* @file VolumeReader.h +* @ingroup fx +* The VolumeReader class. +*/ + +#include "IReader.h" +#include "ISound.h" +#include "VolumeStorage.h" + +#include <memory> + +AUD_NAMESPACE_BEGIN + +/** +* This class represents a reader for a sound that has its own shared volume +*/ +class AUD_API VolumeReader : public IReader +{ +private: + /** + * The current reader. + */ + std::shared_ptr<IReader> m_reader; + + /** + * A sound from which to get the reader. + */ + std::shared_ptr<VolumeStorage> m_volumeStorage; + + + // delete copy constructor and operator= + VolumeReader(const VolumeReader&) = delete; + VolumeReader& operator=(const VolumeReader&) = delete; + +public: + /** + * Creates a new volume reader. + * \param reader A reader of the sound to be assigned to this reader. + * \param volumeStorage A shared pointer to a VolumeStorage object. + */ + VolumeReader(std::shared_ptr<IReader> reader, std::shared_ptr<VolumeStorage> volumeStorage); + + virtual bool isSeekable() const; + virtual void seek(int position); + virtual int getLength() const; + virtual int getPosition() const; + virtual Specs getSpecs() const; + virtual void read(int& length, bool& eos, sample_t* buffer); +}; + +AUD_NAMESPACE_END
\ No newline at end of file diff --git a/extern/audaspace/include/fx/VolumeSound.h b/extern/audaspace/include/fx/VolumeSound.h new file mode 100644 index 00000000000..0aeffd53e87 --- /dev/null +++ b/extern/audaspace/include/fx/VolumeSound.h @@ -0,0 +1,74 @@ +/******************************************************************************* +* Copyright 2015-2016 Juan Francisco Crespo Galán +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +******************************************************************************/ + +#pragma once + +/** +* @file VolumeSound.h +* @ingroup fx +* The VolumeSound class. +*/ + +#include "ISound.h" +#include "VolumeStorage.h" +#include <memory> + +AUD_NAMESPACE_BEGIN + +/** +* This class allows to create a sound with its own volume. +*/ +class AUD_API VolumeSound : public ISound +{ +private: + /** + * A pointer to a sound. + */ + std::shared_ptr<ISound> m_sound; + + /** + * A pointer to the shared volume being used. + */ + std::shared_ptr<VolumeStorage> m_volumeStorage; + + // delete copy constructor and operator= + VolumeSound(const VolumeSound&) = delete; + VolumeSound& operator=(const VolumeSound&) = delete; + +public: + /** + * Creates a new VolumeSound. + * \param sound The sound in which shall have its own volume. + * \param volumeStorage A shared pointer to a VolumeStorage object. It allows to change the volume of various sound in one go. + */ + VolumeSound(std::shared_ptr<ISound> sound, std::shared_ptr<VolumeStorage> volumeStorage); + + virtual std::shared_ptr<IReader> createReader(); + + /** + * Retrieves the shared volume of this sound. + * \return A shared pointer to the VolumeStorage object that this sound is using. + */ + std::shared_ptr<VolumeStorage> getSharedVolume(); + + /** + * Changes the shared volume of this sound, it'll only affect newly created readers. + * \param volumeStorage A shared pointer to the new VolumeStorage object. + */ + void setSharedVolume(std::shared_ptr<VolumeStorage> volumeStorage); +}; + +AUD_NAMESPACE_END
\ No newline at end of file diff --git a/extern/audaspace/include/fx/VolumeStorage.h b/extern/audaspace/include/fx/VolumeStorage.h new file mode 100644 index 00000000000..5088a5e2ba9 --- /dev/null +++ b/extern/audaspace/include/fx/VolumeStorage.h @@ -0,0 +1,71 @@ +/******************************************************************************* +* Copyright 2015-2016 Juan Francisco Crespo Galán +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +******************************************************************************/ + +#pragma once + +/** +* @file VolumeStorage.h +* @ingroup fx +* The VolumeStorage class. +*/ + +#include "Audaspace.h" + +#include <atomic> + +AUD_NAMESPACE_BEGIN + +/** +* This class stores a volume value and allows to change if for a number of sounds in one go. +*/ +class AUD_API VolumeStorage +{ +private: + /** + * Volume value. + */ + std::atomic<float> m_volume; + + // delete copy constructor and operator= + VolumeStorage(const VolumeStorage&) = delete; + VolumeStorage& operator=(const VolumeStorage&) = delete; + +public: + /** + * Creates a new VolumeStorage instance with volume 1 + */ + VolumeStorage(); + + /** + * Creates a VolumeStorage instance with an initial value. + * \param volume The value of the volume. + */ + VolumeStorage(float volume); + + /** + * Retrieves the current volume value. + * \return The current volume. + */ + float getVolume(); + + /** + * Changes the volume value. + * \param volume The new value for the volume. + */ + void setVolume(float volume); +}; + +AUD_NAMESPACE_END |