Add Chromium-only Blender WebEngine parity work

This commit is contained in:
mes123456
2026-08-12 04:47:48 -04:00
commit 9fd26010f6
18225 changed files with 11622124 additions and 0 deletions

View File

@@ -0,0 +1,185 @@
/*******************************************************************************
* 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
/**
* \def AUD_NOEXCEPT
* Compatibility macro for noexcept.
*/
#ifdef _MSC_VER
#define AUD_NOEXCEPT
#else
#define AUD_NOEXCEPT noexcept
#endif
/**
* @file Exception.h
* @ingroup general
* Defines the Exception class as well as the AUD_THROW macro for easy throwing.
*/
#include "Audaspace.h"
#include <exception>
#include <string>
/// Throws a Exception with the provided error code.
#define AUD_THROW(exception, message) { throw exception(message, __FILE__, __LINE__); }
AUD_NAMESPACE_BEGIN
/**
* The Exception class is the general exception base class.
*/
class AUD_API Exception : public std::exception
{
protected:
/// A message describing the problem.
const std::string m_message;
/// The source code file in which the exception was thrown.
const std::string m_file;
/// The source code line from which the exception was thrown.
const int m_line;
/**
* Copy constructor.
* @param exception The exception to be copied.
*/
Exception(const Exception& exception);
/**
* Creates a new Exception object.
* @param message A message describing the problem.
* @param file The source code file in which the exception was thrown.
* @param line The source code line from which the exception was thrown.
*/
Exception(const std::string &message, const std::string &file, int line);
public:
/**
* Destroys the object.
*/
virtual ~Exception() AUD_NOEXCEPT;
/**
* Returns the error message.
* @return A C string error message.
*/
virtual const char* what() const AUD_NOEXCEPT;
/**
* Returns the error message plus file and line number for debugging purposes.
* @return The error message including debug information.
*/
virtual std::string getDebugMessage() const;
/**
* Returns the error message.
* @return The error message as string.
*/
const std::string& getMessage() const;
/**
* Returns the file in which the exception was thrown.
* @return The name of the file in which the exception was thrown.
*/
const std::string& getFile() const;
/**
* Returns the line where the exception was originally thrown.
* @return The line of the source file where the exception was generated.
*/
int getLine() const;
};
/**
* The FileException class is used for error cases in which files cannot
* be read or written due to unknown containers or codecs.
*/
class AUD_API FileException : public Exception
{
public:
/**
* Creates a new FileException object.
* @param message A message describing the problem.
* @param file The source code file in which the exception was thrown.
* @param line The source code line from which the exception was thrown.
*/
FileException(const std::string &message, const std::string &file, int line);
/**
* Copy constructor.
* @param exception The exception to be copied.
*/
FileException(const FileException& exception);
~FileException() AUD_NOEXCEPT;
};
/**
* The DeviceException class is used for error cases in connection with
* devices, which usually happens when specific features or requests
* cannot be fulfilled by a device, for example when the device is opened.
*/
class AUD_API DeviceException : public Exception
{
public:
/**
* Creates a new DeviceException object.
* @param message A message describing the problem.
* @param file The source code file in which the exception was thrown.
* @param line The source code line from which the exception was thrown.
*/
DeviceException(const std::string &message, const std::string &file, int line);
/**
* Copy constructor.
* @param exception The exception to be copied.
*/
DeviceException(const DeviceException& exception);
~DeviceException() AUD_NOEXCEPT;
};
/**
* The StateException class is used for error cases of sounds or readers
* with illegal states or requirements for states of dependent classes.
* It is used for example when an effect reader needs a specific
* specification from its input.
*/
class AUD_API StateException : public Exception
{
public:
/**
* Creates a new StateException object.
* @param message A message describing the problem.
* @param file The source code file in which the exception was thrown.
* @param line The source code line from which the exception was thrown.
*/
StateException(const std::string &message, const std::string &file, int line);
/**
* Copy constructor.
* @param exception The exception to be copied.
*/
StateException(const StateException& exception);
~StateException() AUD_NOEXCEPT;
};
AUD_NAMESPACE_END

View File

@@ -0,0 +1,92 @@
/*******************************************************************************
* 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 IReader.h
* @ingroup general
* The IReader interface.
*/
#include "respec/Specification.h"
AUD_NAMESPACE_BEGIN
/**
* @interface IReader
* This class represents a sound source as stream or as buffer which can be read
* for example by another reader, a device or whatever.
*/
class AUD_API IReader
{
public:
/**
* Destroys the reader.
*/
virtual ~IReader() {}
/**
* Tells whether the source provides seeking functionality or not.
* \warning This doesn't mean that the seeking always has to succeed.
* \return Always returns true for readers of buffering types.
*/
virtual bool isSeekable() const=0;
/**
* Seeks to a specific position in the source.
* \param position The position to seek for measured in samples. To get
* from a given time to the samples you simply have to multiply the
* time value in seconds with the sample rate of the reader.
* \warning This may work or not, depending on the actual reader.
*/
virtual void seek(int position)=0;
/**
* Returns an approximated length of the source in samples.
* \return The length as sample count. May be negative if unknown.
*/
virtual int getLength() const=0;
/**
* Returns the position of the source as a sample count value.
* \return The current position in the source. A negative value indicates
* that the position is unknown.
* \warning The value returned doesn't always have to be correct for readers,
* especially after seeking.
*/
virtual int getPosition() const=0;
/**
* Returns the specification of the reader.
* \return The Specs structure.
*/
virtual Specs getSpecs() const=0;
/**
* Request to read the next length samples out of the source.
* The buffer supplied has the needed size.
* \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 reader.
* \param[out] eos End of stream, whether the end is reached or not.
* \param[in] buffer The pointer to the buffer to read into.
*/
virtual void read(int& length, bool& eos, sample_t* buffer)=0;
};
AUD_NAMESPACE_END

View File

@@ -0,0 +1,57 @@
/*******************************************************************************
* 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 ISound.h
* @ingroup general
* The ISound interface.
*/
#include "Audaspace.h"
#include <memory>
AUD_NAMESPACE_BEGIN
class IReader;
/**
* @interface ISound
* This class represents a type of sound source and saves the necessary values
* for it. It is able to create a reader that is actually usable for playback
* of the respective sound source through the factory method createReader.
*/
class AUD_API ISound
{
public:
/**
* Destroys the sound.
*/
virtual ~ISound() {}
/**
* Creates a reader for playback of the sound source.
* \return A pointer to an IReader object or nullptr if there has been an
* error.
* \exception Exception An exception may be thrown if there has been
* a more unexpected error during reader creation.
*/
virtual std::shared_ptr<IReader> createReader()=0;
};
AUD_NAMESPACE_END

View File

@@ -0,0 +1,165 @@
/*******************************************************************************
* 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 DeviceManager.h
* @ingroup devices
* The DeviceManager class.
*/
#include "Audaspace.h"
#include "respec/Specification.h"
#include <memory>
#include <vector>
#include <unordered_map>
#include <string>
AUD_NAMESPACE_BEGIN
class IDevice;
class IDeviceFactory;
class ICaptureDeviceFactory;
class I3DDevice;
class IReader;
/**
* This class manages all device plugins and maintains a device if asked to do so.
*
* This enables applications to access their output device without having to carry
* it through the whole application.
*/
class AUD_API DeviceManager
{
private:
static std::unordered_map<std::string, std::shared_ptr<IDeviceFactory>> m_factories;
static std::shared_ptr<IDevice> m_device;
static std::unordered_map<std::string, std::shared_ptr<ICaptureDeviceFactory>> m_capture_factories;
// delete copy constructor and operator=
DeviceManager(const DeviceManager&) = delete;
DeviceManager& operator=(const DeviceManager&) = delete;
DeviceManager() = delete;
public:
/**
* Registers a device factory.
*
* This method is mostly used by plugin developers to add their device implementation
* for general use by the library end users.
* @param name A representative name for the device.
* @param factory The factory that creates the device.
*/
static void registerDevice(const std::string &name, std::shared_ptr<IDeviceFactory> factory);
/**
* Returns the factory for a specific device.
* @param name The representative name of the device.
* @return The factory if it was found, or nullptr otherwise.
*/
static std::shared_ptr<IDeviceFactory> getDeviceFactory(const std::string &name);
/**
* Returns the default device based on the priorities of the registered factories.
* @return The default device or nullptr if no factory has been registered.
*/
static std::shared_ptr<IDeviceFactory> getDefaultDeviceFactory();
/**
* Sets a device that should be handled by the manager.
*
* If a device is currently being handled it will be released.
* @param device The device the manager should take care of.
*/
static void setDevice(std::shared_ptr<IDevice> device);
/**
* Opens a device which will then be handled by the manager.
*
* If a device is currently being handled it will be released.
* @param name The representative name of the device.
*/
static void openDevice(const std::string &name);
/**
* Opens the default device which will then be handled by the manager.
*
* The device to open is selected based on the priority of the registered factories.
* If a device is currently being handled it will be released.
*/
static void openDefaultDevice();
/**
* Releases the currently handled device.
*/
static void releaseDevice();
/**
* Returns the currently handled device.
* @return The handled device or nullptr if no device has been registered.
*/
static std::shared_ptr<IDevice> getDevice();
/**
* Returns the currently handled 3D device.
* @return The handled device or nullptr if no device has been registered
* or the registered device is not an I3DDevice.
*/
static std::shared_ptr<I3DDevice> get3DDevice();
/**
* Returns a list of available devices.
* @return A list of strings with the names of available devices.
*/
static std::vector<std::string> getAvailableDeviceNames();
/**
* Returns a list of available capture devices.
* @return A list of strings with the names of available capture devices.
*/
static std::vector<std::string> getAvailableCaptureDeviceNames();
/**
* Returns the factory for a specific capture device.
* @param name The representative name of the capture device.
* @return The factory if it was found, or nullptr otherwise.
*/
static std::shared_ptr<ICaptureDeviceFactory> getCaptureDeviceFactory(const std::string& name);
/**
* Registers a capture device factory.
* @param name A representative name for the capture device.
* @param factory The factory that creates the capture reader.
*/
static void registerCaptureDevice(const std::string& name, std::shared_ptr<ICaptureDeviceFactory> factory);
/**
* Opens an input capture reader.
* @param name The capture device name.
* @param specs The desired specification.
* @param buffersize The capture buffer size in samples.
*/
static std::shared_ptr<IReader> openCaptureDevice(const std::string& name,
Specs specs,
int buffersize = AUD_DEFAULT_BUFFER_SIZE);
};
AUD_NAMESPACE_END

View File

@@ -0,0 +1,142 @@
/*******************************************************************************
* 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 I3DDevice.h
* @ingroup devices
* Defines the I3DDevice interface as well as the different distance models.
*/
#include "util/Math3D.h"
AUD_NAMESPACE_BEGIN
/**
* Possible distance models for the 3D device.
*
* The distance models supported are the same as documented in the [OpenAL Specification](http://openal.org/).
*/
enum DistanceModel
{
DISTANCE_MODEL_INVALID = 0,
DISTANCE_MODEL_INVERSE,
DISTANCE_MODEL_INVERSE_CLAMPED,
DISTANCE_MODEL_LINEAR,
DISTANCE_MODEL_LINEAR_CLAMPED,
DISTANCE_MODEL_EXPONENT,
DISTANCE_MODEL_EXPONENT_CLAMPED
};
/**
* @interface I3DDevice
* The I3DDevice interface represents an output device for 3D sound.
*
* The interface has been modelled after the OpenAL 1.1 API,
* see the [OpenAL Specification](http://openal.org/) for lots of details.
*/
class AUD_API I3DDevice
{
public:
/**
* Retrieves the listener location.
* \return The listener location.
*/
virtual Vector3 getListenerLocation() const=0;
/**
* Sets the listener location.
* \param location The new location.
* \note The location is not updated with the velocity and
* remains constant until the next call of this method.
*/
virtual void setListenerLocation(const Vector3& location)=0;
/**
* Retrieves the listener velocity.
* \return The listener velocity.
*/
virtual Vector3 getListenerVelocity() const=0;
/**
* Sets the listener velocity.
* \param velocity The new velocity.
* \note This velocity does not change the position of the listener
* over time, it is simply used for the calculation of the doppler effect.
*/
virtual void setListenerVelocity(const Vector3& velocity)=0;
/**
* Retrieves the listener orientation.
* \return The listener orientation as quaternion.
*/
virtual Quaternion getListenerOrientation() const=0;
/**
* Sets the listener orientation.
* \param orientation The new orientation as quaternion.
* \note The coordinate system used is right handed and the listener
* by default is oriented looking in the negative z direction with the
* positive y axis as up direction.
*/
virtual void setListenerOrientation(const Quaternion& orientation)=0;
/**
* Retrieves the speed of sound.
* This value is needed for doppler effect calculation.
* \return The speed of sound.
*/
virtual float getSpeedOfSound() const=0;
/**
* Sets the speed of sound.
* This value is needed for doppler effect calculation.
* \param speed The new speed of sound.
*/
virtual void setSpeedOfSound(float speed)=0;
/**
* Retrieves the doppler factor.
* This value is a scaling factor for the velocity vectors of sources and
* listener which is used while calculating the doppler effect.
* \return The doppler factor.
*/
virtual float getDopplerFactor() const=0;
/**
* Sets the doppler factor.
* This value is a scaling factor for the velocity vectors of sources and
* listener which is used while calculating the doppler effect.
* \param factor The new doppler factor.
*/
virtual void setDopplerFactor(float factor)=0;
/**
* Retrieves the distance model.
* \return The distance model.
*/
virtual DistanceModel getDistanceModel() const=0;
/**
* Sets the distance model.
* \param model distance model.
*/
virtual void setDistanceModel(DistanceModel model)=0;
};
AUD_NAMESPACE_END

View File

@@ -0,0 +1,232 @@
/*******************************************************************************
* 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 I3DHandle.h
* @ingroup devices
* The I3DHandle interface.
*/
#include "util/Math3D.h"
AUD_NAMESPACE_BEGIN
/**
* @interface I3DHandle
* The I3DHandle interface represents a playback handle for 3D sources.
* If the playback IDevice class also implements the I3DDevice interface
* then all playback IHandle instances also implement this interface.
*
* The interface has been modelled after the OpenAL 1.1 API,
* see the [OpenAL Specification](http://openal.org/) for lots of details.
*/
class AUD_API I3DHandle
{
public:
/**
* Destroys the handle.
*/
virtual ~I3DHandle() {}
/**
* Retrieves the location of the source.
* \return The location.
*/
virtual Vector3 getLocation()=0;
/**
* Sets the location of the source.
* \param location The new location.
* \return Whether the action succeeded.
* \note The location is not updated with the velocity and
* remains constant until the next call of this method.
*/
virtual bool setLocation(const Vector3& location)=0;
/**
* Retrieves the velocity of the source.
* \return The velocity.
*/
virtual Vector3 getVelocity()=0;
/**
* Sets the velocity of the source.
* \param velocity The new velocity.
* \return Whether the action succeeded.
* \note This velocity does not change the position of the listener
* over time, it is simply used for the calculation of the doppler effect.
*/
virtual bool setVelocity(const Vector3& velocity)=0;
/**
* Retrieves the orientation of the source.
* \return The orientation as quaternion.
*/
virtual Quaternion getOrientation()=0;
/**
* Sets the orientation of the source.
* \param orientation The new orientation as quaternion.
* \return Whether the action succeeded.
* \note The coordinate system used is right handed and the source
* by default is oriented looking in the negative z direction with the
* positive y axis as up direction.
* \note This setting currently only affects sounds with non-default cone settings.
*/
virtual bool setOrientation(const Quaternion& orientation)=0;
/**
* Checks whether the source location, velocity and orientation are relative
* to the listener.
* \return Whether the source is relative.
*/
virtual bool isRelative()=0;
/**
* Sets whether the source location, velocity and orientation are relative
* to the listener.
* \param relative Whether the source is relative.
* \return Whether the action succeeded.
* \note The default value is true as this setting is used to play sounds ordinarily without 3D.
*/
virtual bool setRelative(bool relative)=0;
/**
* Retrieves the maximum volume of a source.
* \return The maximum volume.
*/
virtual float getVolumeMaximum()=0;
/**
* Sets the maximum volume of a source.
* \param volume The new maximum volume.
* \return Whether the action succeeded.
*/
virtual bool setVolumeMaximum(float volume)=0;
/**
* Retrieves the minimum volume of a source.
* \return The minimum volume.
*/
virtual float getVolumeMinimum()=0;
/**
* Sets the minimum volume of a source.
* \param volume The new minimum volume.
* \return Whether the action succeeded.
*/
virtual bool setVolumeMinimum(float volume)=0;
/**
* Retrieves the maximum distance of a source.
* If a source is further away from the reader than this distance, the
* volume will automatically be set to 0.
* \return The maximum distance.
*/
virtual float getDistanceMaximum()=0;
/**
* Sets the maximum distance of a source.
* If a source is further away from the reader than this distance, the
* volume will automatically be set to 0.
* \param distance The new maximum distance.
* \return Whether the action succeeded.
*/
virtual bool setDistanceMaximum(float distance)=0;
/**
* Retrieves the reference distance of a source.
* \return The reference distance.
*/
virtual float getDistanceReference()=0;
/**
* Sets the reference distance of a source.
* \param distance The new reference distance.
* \return Whether the action succeeded.
*/
virtual bool setDistanceReference(float distance)=0;
/**
* Retrieves the attenuation of a source.
* \return The attenuation.
*/
virtual float getAttenuation()=0;
/**
* Sets the attenuation of a source.
* This value is used for distance calculation.
* \param factor The new attenuation.
* \return Whether the action succeeded.
*/
virtual bool setAttenuation(float factor)=0;
/**
* Retrieves the outer opening angle of the cone of a source.
* \return The outer angle of the cone.
* \note This angle is defined in degrees.
*/
virtual float getConeAngleOuter()=0;
/**
* Sets the outer opening angle of the cone of a source.
* \param angle The new outer angle of the cone.
* \return Whether the action succeeded.
* \note This angle is defined in degrees.
*/
virtual bool setConeAngleOuter(float angle)=0;
/**
* Retrieves the inner opening angle of the cone of a source.
* The volume inside this cone is unaltered.
* \return The inner angle of the cone.
* \note This angle is defined in degrees.
*/
virtual float getConeAngleInner()=0;
/**
* Sets the inner opening angle of the cone of a source.
* The volume inside this cone is unaltered.
* \param angle The new inner angle of the cone.
* \return Whether the action succeeded.
* \note This angle is defined in degrees.
*/
virtual bool setConeAngleInner(float angle)=0;
/**
* Retrieves the outer volume of the cone of a source.
* The volume between inner and outer angle is interpolated between inner
* volume and this value.
* \return The outer volume of the cone.
* \note The general volume of the handle still applies on top of this.
*/
virtual float getConeVolumeOuter()=0;
/**
* Sets the outer volume of the cone of a source.
* The volume between inner and outer angle is interpolated between inner
* volume and this value.
* \param volume The new outer volume of the cone.
* \return Whether the action succeeded.
* \note The general volume of the handle still applies on top of this.
*/
virtual bool setConeVolumeOuter(float volume)=0;
};
AUD_NAMESPACE_END

View File

@@ -0,0 +1,46 @@
#pragma once
/**
* @file ICaptureDeviceFactory.h
* @ingroup devices
* The ICaptureDeviceFactory interface.
*/
#include "Audaspace.h"
#include "respec/Specification.h"
#include <memory>
#include <string>
AUD_NAMESPACE_BEGIN
class IReader;
/**
* @interface ICaptureDeviceFactory
* The ICaptureDeviceFactory interface opens an input capture device.
*/
class AUD_API ICaptureDeviceFactory
{
public:
/**
* Destroys the capture device factory.
*/
virtual ~ICaptureDeviceFactory() {}
/**
* Opens an audio capture device.
* \param specs The desired specification.
* \param buffersize The capture buffer size in samples.
* \exception Exception Thrown if the audio device cannot be opened.
*/
virtual std::shared_ptr<IReader> openDevice(Specs specs, int buffersize)=0;
/**
* Sets a name for the capture device.
* \param name The internal name for the capture device.
*/
virtual void setName(const std::string &name)=0;
};
AUD_NAMESPACE_END

View File

@@ -0,0 +1,130 @@
/*******************************************************************************
* 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 IDevice.h
* @ingroup devices
* The IDevice interface.
*/
#include <memory>
#include "respec/Specification.h"
#include "util/ILockable.h"
AUD_NAMESPACE_BEGIN
class IHandle;
class IReader;
class ISound;
/**
* @interface IDevice
* The IDevice interface represents an output device for sound sources.
* Output devices may be several backends such as platform independand like
* SDL or OpenAL or platform specific like ALSA, but they may also be
* files, RAM buffers or other types of streams.
* \warning Thread safety must be insured so that no reader is being called
* twice at the same time.
*/
class IDevice : public ILockable
{
public:
/**
* Destroys the device.
*/
virtual ~IDevice() {}
/**
* Returns the specification of the device.
*/
virtual DeviceSpecs getSpecs() const=0;
/**
* Plays a sound source.
* \param reader The reader to play.
* \param keep When keep is true the sound source will not be deleted but
* set to paused when its end has been reached.
* \return Returns a handle with which the playback can be controlled.
* This is nullptr if the sound couldn't be played back.
* \exception Exception Thrown if there's an unexpected (from the
* device side) error during creation of the reader.
*/
virtual std::shared_ptr<IHandle> play(std::shared_ptr<IReader> reader, bool keep = false)=0;
/**
* Plays a sound source.
* \param sound The sound to create the reader for the sound source.
* \param keep When keep is true the sound source will not be deleted but
* set to paused when its end has been reached.
* \return Returns a handle with which the playback can be controlled.
* This is nullptr if the sound couldn't be played back.
* \exception Exception Thrown if there's an unexpected (from the
* device side) error during creation of the reader.
*/
virtual std::shared_ptr<IHandle> play(std::shared_ptr<ISound> sound, bool keep = false)=0;
/**
* Stops all playing sounds.
*/
virtual void stopAll()=0;
/**
* Locks the device.
* Used to make sure that between lock and unlock, no buffers are read, so
* that it is possible to start, resume, pause, stop or seek several
* playback handles simultaneously.
* \warning Make sure the locking time is as small as possible to avoid
* playback delays that result in unexpected noise and cracks.
*/
virtual void lock()=0;
/**
* Unlocks the previously locked device.
*/
virtual void unlock()=0;
/**
* Retrieves the overall device volume.
* \return The overall device volume.
*/
virtual float getVolume() const=0;
/**
* Sets the overall device volume.
* \param volume The overall device volume.
*/
virtual void setVolume(float volume) = 0;
/**
* The syncFunction is called when a synchronization event happens.
* The function awaits three parameters. The first one is a user defined
* pointer, the second informs about whether playback is on and the third
* is the current playback time in seconds.
*/
typedef void (*syncFunction)(void*, int, float);
virtual void seekSynchronizer(double time) = 0;
virtual double getSynchronizerPosition() = 0;
virtual void playSynchronizer() = 0;
virtual void stopSynchronizer() = 0;
virtual void setSyncCallback(syncFunction function, void* data) = 0;
virtual int isSynchronizerPlaying() = 0;
};
AUD_NAMESPACE_END

View File

@@ -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 IDeviceFactory.h
* @ingroup devices
* The IDeviceFactory interface.
*/
#include "respec/Specification.h"
#include <memory>
AUD_NAMESPACE_BEGIN
/**
* @interface IDeviceFactory
* The IDeviceFactory interface opens an output device.
*/
class AUD_API IDeviceFactory
{
public:
/**
* Destroys the device factory.
*/
virtual ~IDeviceFactory() {}
/**
* Opens an audio device for playback.
* \exception Exception Thrown if the audio device cannot be opened.
*/
virtual std::shared_ptr<IDevice> openDevice()=0;
/**
* Returns the priority of the device to be the default device for a system.
* The higher the priority the more likely it is for this device to be used as the default device.
* \return Priority to be the default device.
*/
virtual int getPriority()=0;
/**
* Sets the wanted device specifications for opening the device.
* \param specs The wanted audio specification.
*/
virtual void setSpecs(DeviceSpecs specs)=0;
/**
* Sets the size for the internal playback buffers.
* The bigger the buffersize, the less likely clicks happen,
* but the latency increases too.
* \param buffersize The size of the internal buffer.
*/
virtual void setBufferSize(int buffersize)=0;
/**
* Sets a name for the device.
* \param name The internal name for the device.
*/
virtual void setName(const std::string &name)=0;
};
AUD_NAMESPACE_END

View File

@@ -0,0 +1,189 @@
/*******************************************************************************
* 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 IHandle.h
* @ingroup devices
* Defines the IHandle interface as well as possible states of the handle.
*/
#include "Audaspace.h"
AUD_NAMESPACE_BEGIN
/// Status of a playback handle.
enum Status
{
STATUS_INVALID = 0, /// Invalid handle. Maybe due to stopping.
STATUS_PLAYING, /// Sound is playing.
STATUS_PAUSED, /// Sound is being paused.
STATUS_STOPPED /// Sound is stopped but kept in the device.
};
/**
* The stopCallback is called when a handle reaches the end of the stream and
* thus gets stopped. A user defined pointer is supplied to the callback.
*/
typedef void (*stopCallback)(void*);
/**
* @interface IHandle
* The IHandle interface represents a playback handles of a specific device.
*/
class AUD_API IHandle
{
public:
/**
* Destroys the handle.
*/
virtual ~IHandle() {}
/**
* Pauses a played back sound.
* \return
* - true if the sound has been paused.
* - false if the sound isn't playing back or the handle is invalid.
*/
virtual bool pause()=0;
/**
* Resumes a paused sound.
* \return
* - true if the sound has been resumed.
* - false if the sound isn't paused or the handle is invalid.
*/
virtual bool resume()=0;
/**
* Stops a played back or paused sound. The handle is definitely invalid
* afterwards.
* \return
* - true if the sound has been stopped.
* - false if the handle is invalid.
*/
virtual bool stop()=0;
/**
* Gets the behaviour of the device for a played back sound when the sound
* doesn't return any more samples.
* \return
* - true if the source will be paused when it's end is reached
* - false if the handle won't kept or is invalid.
*/
virtual bool getKeep()=0;
/**
* Sets the behaviour of the device for a played back sound when the sound
* doesn't return any more samples.
* \param keep True when the source should be paused and not deleted.
* \return
* - true if the behaviour has been changed.
* - false if the handle is invalid.
*/
virtual bool setKeep(bool keep)=0;
/**
* Seeks in a 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.
*/
virtual bool seek(double position)=0;
/**
* Retrieves the current playback position of a sound.
* \return The playback position in seconds, or 0.0 if the handle is
* invalid.
*/
virtual double getPosition()=0;
/**
* Returns the status of a 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
*/
virtual Status getStatus()=0;
/**
* Retrieves the volume of a playing sound.
* \return The volume.
*/
virtual float getVolume()=0;
/**
* Sets the volume of a playing sound.
* \param volume The volume.
* \return
* - true if the handle is valid.
* - false if the handle is invalid.
*/
virtual bool setVolume(float volume)=0;
/**
* Retrieves the pitch of a playing sound.
* \return The pitch.
*/
virtual float getPitch()=0;
/**
* Sets the pitch of a playing sound.
* \param pitch The pitch.
* \return
* - true if the handle is valid.
* - false if the handle is invalid.
*/
virtual bool setPitch(float pitch)=0;
/**
* Retrieves the loop count of a playing sound.
* A negative value indicates infinity.
* \return The remaining loop count.
*/
virtual int getLoopCount()=0;
/**
* Sets the loop count of a playing sound.
* A negative value indicates infinity.
* \param count The new loop count.
* \return
* - true if the handle is valid.
* - false if the handle is invalid.
*/
virtual bool setLoopCount(int count)=0;
/**
* Sets the callback function that's called when the end of a playing sound
* is reached.
* \param callback The callback function.
* \param data The data that should be passed to the callback function.
* \return
* - true if the handle is valid.
* - false if the handle is invalid.
*/
virtual bool setStopCallback(stopCallback callback = 0, void* data = 0)=0;
};
AUD_NAMESPACE_END

View File

@@ -0,0 +1,131 @@
/*******************************************************************************
* 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 MixingThreadDevice.h
* @ingroup device
* The MixingThreadDevice class.
*/
#include <condition_variable>
#include <thread>
#include "devices/SoftwareDevice.h"
#include "util/RingBuffer.h"
AUD_NAMESPACE_BEGIN
/**
* This device extends the SoftwareDevice with code for running mixing in a separate thread.
*/
class AUD_PLUGIN_API MixingThreadDevice : public SoftwareDevice
{
private:
/**
* Whether there is currently playback.
*/
volatile bool m_playback{false};
/**
* The deinterleaving buffer.
*/
Buffer m_mixingBuffer;
/**
* The mixing ring buffer.
*/
RingBuffer m_ringBuffer;
/**
* Whether the device is valid.
*/
bool m_valid{false};
/**
* The mixing thread.
*/
std::thread m_mixingThread;
/**
* Mutex for mixing.
*/
std::mutex m_mixingLock;
/**
* Condition for mixing.
*/
std::condition_variable m_mixingCondition;
/**
* Updates the ring buffer.
*/
AUD_LOCAL void updateRingBuffer();
// delete copy constructor and operator=
MixingThreadDevice(const MixingThreadDevice&) = delete;
MixingThreadDevice& operator=(const MixingThreadDevice&) = delete;
protected:
/**
* Starts the streaming thread.
* @param buffersize Size of the ring buffer in bytes.
*/
void startMixingThread(size_t buffersize);
/**
* Notify the mixing thread.
*/
void notifyMixingThread();
/**
* Get ring buffer for reading.
*/
inline RingBuffer& getRingBuffer()
{
return m_ringBuffer;
}
/**
* Returns whether the thread is running or not.
*/
inline bool isMixingThreadRunning()
{
return m_valid;
}
virtual void playing(bool playing);
/**
* Called every iteration in the mixing thread before mixing.
*/
virtual void preMixingWork(bool playing);
/**
* Empty default constructor. To setup the device call the function create()
* and to uninitialize call destroy().
*/
MixingThreadDevice();
/**
* Stops all playback and notifies the mixing thread to stop.
* \warning The device has to be unlocked to not run into a deadlock.
*/
void stopMixingThread();
};
AUD_NAMESPACE_END

View File

@@ -0,0 +1,102 @@
/*******************************************************************************
* 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 NULLDevice.h
* @ingroup devices
* The NULLDevice class.
*/
#include "devices/IDevice.h"
#include "devices/IHandle.h"
AUD_NAMESPACE_BEGIN
class IReader;
/**
* This device plays nothing.
* It is similar to the linux device /dev/null.
*/
class AUD_API NULLDevice : public IDevice
{
private:
class AUD_LOCAL NULLHandle : public IHandle
{
private:
// delete copy constructor and operator=
NULLHandle(const NULLHandle&) = delete;
NULLHandle& operator=(const NULLHandle&) = delete;
public:
NULLHandle();
virtual ~NULLHandle() {}
virtual bool pause();
virtual bool resume();
virtual bool stop();
virtual bool getKeep();
virtual bool setKeep(bool keep);
virtual bool seek(double position);
virtual double getPosition();
virtual Status getStatus();
virtual float getVolume();
virtual bool setVolume(float volume);
virtual float getPitch();
virtual bool setPitch(float pitch);
virtual int getLoopCount();
virtual bool setLoopCount(int count);
virtual bool setStopCallback(stopCallback callback = 0, void* data = 0);
};
// delete copy constructor and operator=
NULLDevice(const NULLDevice&) = delete;
NULLDevice& operator=(const NULLDevice&) = delete;
public:
/**
* Creates a new NULLDevice.
*/
NULLDevice();
virtual ~NULLDevice();
virtual DeviceSpecs getSpecs() const;
virtual std::shared_ptr<IHandle> play(std::shared_ptr<IReader> reader, bool keep = false);
virtual std::shared_ptr<IHandle> play(std::shared_ptr<ISound> sound, bool keep = false);
virtual void stopAll();
virtual void lock();
virtual void unlock();
virtual float getVolume() const;
virtual void setVolume(float volume);
virtual void seekSynchronizer(double time);
virtual double getSynchronizerPosition();
virtual void playSynchronizer();
virtual void stopSynchronizer();
virtual void setSyncCallback(syncFunction function, void* data);
virtual int isSynchronizerPlaying();
/**
* Registers this plugin.
*/
static void registerPlugin();
};
AUD_NAMESPACE_END

View File

@@ -0,0 +1,82 @@
/*******************************************************************************
* 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 ReadDevice.h
* @ingroup devices
* The ReadDevice class.
*/
#include "devices/SoftwareDevice.h"
AUD_NAMESPACE_BEGIN
/**
* This device enables to let the user read raw data out of it.
*/
class AUD_API ReadDevice : public SoftwareDevice
{
private:
/**
* Whether the device is currently playing back.
*/
bool m_playing;
// delete copy constructor and operator=
ReadDevice(const ReadDevice&) = delete;
ReadDevice& operator=(const ReadDevice&) = delete;
protected:
virtual void AUD_LOCAL playing(bool playing);
public:
/**
* Creates a new read device.
* \param specs The wanted audio specification.
*/
ReadDevice(DeviceSpecs specs);
/**
* Creates a new read device.
* \param specs The wanted audio specification.
*/
ReadDevice(Specs specs);
/**
* Closes the device.
*/
virtual ~ReadDevice();
/**
* Reads the next bytes into the supplied buffer.
* \param buffer The target buffer.
* \param length The length in samples to be filled.
* \return True if the reading succeeded, false if there are no sounds
* played back currently, in that case the buffer is filled with
* silence.
*/
bool read(data_t* buffer, int length);
/**
* Changes the output specification.
* \param specs The new audio data specification.
*/
void changeSpecs(Specs specs);
};
AUD_NAMESPACE_END

View File

@@ -0,0 +1,384 @@
/*******************************************************************************
* 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 SoftwareDevice.h
* @ingroup devices
* The SoftwareDevice class.
*/
#include "devices/IDevice.h"
#include "devices/IHandle.h"
#include "devices/I3DDevice.h"
#include "devices/I3DHandle.h"
#include "util/Buffer.h"
#include <list>
#include <mutex>
AUD_NAMESPACE_BEGIN
class Mixer;
class PitchReader;
class ResampleReader;
class ChannelMapperReader;
/**
* The software device is a generic device with software mixing.
* It is a base class for all software mixing classes.
* Classes implementing this have to:
* - Implement the playing function.
* - Prepare the m_specs, m_mixer variables.
* - Call the create and destroy functions.
* - Call the mix function to retrieve their audio data.
*/
class AUD_API SoftwareDevice : public IDevice, public I3DDevice
{
protected:
/// Saves the data for playback.
class AUD_API SoftwareHandle : public IHandle, public I3DHandle
{
private:
// delete copy constructor and operator=
SoftwareHandle(const SoftwareHandle&) = delete;
SoftwareHandle& operator=(const SoftwareHandle&) = delete;
public:
/// The reader source.
std::shared_ptr<IReader> m_reader;
/// The pitch reader in between.
std::shared_ptr<PitchReader> m_pitch;
/// The resample reader in between.
std::shared_ptr<ResampleReader> m_resampler;
/// The channel mapper reader in between.
std::shared_ptr<ChannelMapperReader> m_mapper;
/// Whether the source is being read for the first time.
bool m_first_reading;
/// Whether to keep the source if end of it is reached.
bool m_keep;
/// The user set pitch of the source.
float m_user_pitch;
/// The user set volume of the source.
float m_user_volume;
/// The user set panning for non-3D sources
float m_user_pan;
/// The calculated final volume of the source.
float m_volume;
/// The previous calculated final volume of the source.
float m_old_volume;
/// The loop count of the source.
int m_loopcount;
/// Location in 3D Space.
Vector3 m_location;
/// Velocity in 3D Space.
Vector3 m_velocity;
/// Orientation in 3D Space.
Quaternion m_orientation;
/// Whether the position to the listener is relative or absolute
bool m_relative;
/// Maximum volume.
float m_volume_max;
/// Minimum volume.
float m_volume_min;
/// Maximum distance.
float m_distance_max;
/// Reference distance;
float m_distance_reference;
/// Attenuation
float m_attenuation;
/// Cone outer angle.
float m_cone_angle_outer;
/// Cone inner angle.
float m_cone_angle_inner;
/// Cone outer volume.
float m_cone_volume_outer;
/// Rendering flags
int m_flags;
/// The stop callback.
stopCallback m_stop;
/// Stop callback data.
void* m_stop_data;
/// Current status of the handle
Status m_status;
/// Own device.
SoftwareDevice* m_device;
/**
* This method is for internal use only.
* @param keep Whether the sound should be marked stopped or paused.
* @return Whether the action succeeded.
*/
bool pause(bool keep);
public:
/**
* Creates a new software handle.
* \param device The device this handle is from.
* \param reader The reader to play.
* \param pitch The pitch reader.
* \param resampler The resampling reader.
* \param mapper The channel mapping reader.
* \param keep Whether to keep the handle when the sound ends.
*/
SoftwareHandle(SoftwareDevice* device, std::shared_ptr<IReader> reader, std::shared_ptr<PitchReader> pitch, std::shared_ptr<ResampleReader> resampler, std::shared_ptr<ChannelMapperReader> mapper, bool keep);
/**
* Updates the handle's playback parameters.
*/
void update();
/**
* Sets the audio output specification of the readers.
* \param specs The output specification.
*/
void setSpecs(Specs specs);
virtual ~SoftwareHandle() {}
virtual bool pause();
virtual bool resume();
virtual bool stop();
virtual bool getKeep();
virtual bool setKeep(bool keep);
virtual bool seek(double position);
virtual double getPosition();
virtual Status getStatus();
virtual float getVolume();
virtual bool setVolume(float volume);
virtual float getPitch();
virtual bool setPitch(float pitch);
virtual int getLoopCount();
virtual bool setLoopCount(int count);
virtual bool setStopCallback(stopCallback callback = 0, void* data = 0);
virtual Vector3 getLocation();
virtual bool setLocation(const Vector3& location);
virtual Vector3 getVelocity();
virtual bool setVelocity(const Vector3& velocity);
virtual Quaternion getOrientation();
virtual bool setOrientation(const Quaternion& orientation);
virtual bool isRelative();
virtual bool setRelative(bool relative);
virtual float getVolumeMaximum();
virtual bool setVolumeMaximum(float volume);
virtual float getVolumeMinimum();
virtual bool setVolumeMinimum(float volume);
virtual float getDistanceMaximum();
virtual bool setDistanceMaximum(float distance);
virtual float getDistanceReference();
virtual bool setDistanceReference(float distance);
virtual float getAttenuation();
virtual bool setAttenuation(float factor);
virtual float getConeAngleOuter();
virtual bool setConeAngleOuter(float angle);
virtual float getConeAngleInner();
virtual bool setConeAngleInner(float angle);
virtual float getConeVolumeOuter();
virtual bool setConeVolumeOuter(float volume);
};
/**
* The specification of the device.
*/
DeviceSpecs m_specs;
/**
* The mixer.
*/
std::shared_ptr<Mixer> m_mixer;
/**
* Resampling quality.
*/
ResampleQuality m_quality;
/**
* Initializes member variables.
*/
void create();
/**
* Uninitializes member variables.
*/
void destroy();
/**
* Mixes the next samples into the buffer.
* \param buffer The target buffer.
* \param length The length in samples to be filled.
*/
void mix(data_t* buffer, int length);
/**
* This function tells the device, to start or pause playback.
* \param playing True if device should playback.
* \note This method is only called when the device is locked.
*/
virtual void playing(bool playing)=0;
/**
* Sets the audio output specification of the device.
* \param specs The output specification.
*/
void setSpecs(Specs specs);
/**
* Sets the audio output specification of the device.
* \param specs The output specification.
*/
void setSpecs(DeviceSpecs specs);
/**
* Empty default constructor. To setup the device call the function create()
* and to uninitialize call destroy().
*/
SoftwareDevice();
private:
/**
* The reading buffer.
*/
Buffer m_buffer;
/**
* The list of sounds that are currently playing.
*/
std::list<std::shared_ptr<SoftwareHandle> > m_playingSounds;
/**
* The list of sounds that are currently paused.
*/
std::list<std::shared_ptr<SoftwareHandle> > m_pausedSounds;
/**
* Whether there is currently playback.
*/
bool m_playback;
/**
* The mutex for locking.
*/
std::recursive_mutex m_mutex;
/**
* The overall volume of the device.
*/
float m_volume;
/// Listener location.
Vector3 m_location;
/// Listener velocity.
Vector3 m_velocity;
/// Listener orientation.
Quaternion m_orientation;
/// Speed of Sound.
float m_speed_of_sound;
/// Doppler factor.
float m_doppler_factor;
/// Distance model.
DistanceModel m_distance_model;
/// Rendering flags
int m_flags;
/// Synchronizer.
uint64_t m_synchronizerPosition{0};
int m_synchronizerState{0};
// delete copy constructor and operator=
SoftwareDevice(const SoftwareDevice&) = delete;
SoftwareDevice& operator=(const SoftwareDevice&) = delete;
public:
/**
* Sets the panning of a specific handle.
* \param handle The handle to set the panning from.
* \param pan The new panning value, should be in the range [-2, 2].
*/
static void setPanning(IHandle* handle, float pan);
/**
* Sets the resampling quality.
* \param quality Resampling quality vs performance setting.
*/
void setQuality(ResampleQuality quality);
virtual DeviceSpecs getSpecs() const;
virtual std::shared_ptr<IHandle> play(std::shared_ptr<IReader> reader, bool keep = false);
virtual std::shared_ptr<IHandle> play(std::shared_ptr<ISound> sound, bool keep = false);
virtual void stopAll();
virtual void lock();
virtual void unlock();
virtual float getVolume() const;
virtual void setVolume(float volume);
virtual Vector3 getListenerLocation() const;
virtual void setListenerLocation(const Vector3& location);
virtual Vector3 getListenerVelocity() const;
virtual void setListenerVelocity(const Vector3& velocity);
virtual Quaternion getListenerOrientation() const;
virtual void setListenerOrientation(const Quaternion& orientation);
virtual float getSpeedOfSound() const;
virtual void setSpeedOfSound(float speed);
virtual float getDopplerFactor() const;
virtual void setDopplerFactor(float factor);
virtual DistanceModel getDistanceModel() const;
virtual void setDistanceModel(DistanceModel model);
virtual void seekSynchronizer(double time);
virtual double getSynchronizerPosition();
virtual void playSynchronizer();
virtual void stopSynchronizer();
virtual void setSyncCallback(syncFunction function, void* data);
virtual int isSynchronizerPlaying();
};
AUD_NAMESPACE_END

View File

@@ -0,0 +1,95 @@
/*******************************************************************************
* 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 ThreadedDevice.h
* @ingroup plugin
* The ThreadedDevice class.
*/
#include "devices/SoftwareDevice.h"
#include <thread>
AUD_NAMESPACE_BEGIN
/**
* This device extends the SoftwareDevice with code for running mixing in a separate thread.
*/
class AUD_PLUGIN_API ThreadedDevice : public SoftwareDevice
{
private:
/**
* Whether there is currently playback.
*/
bool m_playing;
/**
* Whether the current playback should stop.
*/
bool m_stop;
/**
* The streaming thread.
*/
std::thread m_thread;
/**
* Starts the streaming thread.
*/
AUD_LOCAL void start();
/**
* Streaming thread main function.
*/
AUD_LOCAL virtual void runMixingThread()=0;
// delete copy constructor and operator=
ThreadedDevice(const ThreadedDevice&) = delete;
ThreadedDevice& operator=(const ThreadedDevice&) = delete;
protected:
virtual void playing(bool playing);
/**
* Empty default constructor. To setup the device call the function create()
* and to uninitialize call destroy().
*/
ThreadedDevice();
/**
* Indicates that the mixing thread should be stopped.
* \return Whether the mixing thread should be stopping.
* \warning For thread safety, the device needs to be locked, when this method is called.
*/
inline bool shouldStop() { return m_stop; }
/**
* This method needs to be called when the mixing thread is stopping.
* \warning For thread safety, the device needs to be locked, when this method is called.
*/
inline void doStop() { m_stop = m_playing = false; }
/**
* Stops all playback and notifies the mixing thread to stop.
* \warning The device has to be unlocked to not run into a deadlock.
*/
void stopMixingThread();
};
AUD_NAMESPACE_END

View File

@@ -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 File.h
* @ingroup file
* The File class.
*/
#include "ISound.h"
#include "FileInfo.h"
#include <string>
#include <memory>
#include <vector>
AUD_NAMESPACE_BEGIN
class Buffer;
/**
* The File sound tries to read a sound file via all available file inputs
* that have been registered in the FileManager class.
*/
class AUD_API File : public ISound
{
private:
/**
* The filename of the sound source file.
*/
std::string m_filename;
/**
* The buffer to read from.
*/
std::shared_ptr<Buffer> m_buffer;
/**
* The index of the stream within the file if it contains multiple.
* The first audio stream in the file has index 0 and the index increments by one
* for every other audio stream in the file. Other types of streams in the file
* do not count.
*/
int m_stream;
// delete copy constructor and operator=
File(const File&) = delete;
File& operator=(const File&) = delete;
public:
/**
* Creates a new sound.
* The file is read from the file system using the given path.
* \param filename The sound file path.
* \param stream The index of the audio stream within the file if it contains multiple audio streams.
*/
File(const std::string &filename, int stream = 0);
/**
* Creates a new sound.
* The file is read from memory using the supplied buffer.
* \param buffer The buffer to read from.
* \param size The size of the buffer.
* \param stream The index of the audio stream within the file if it contains multiple audio streams.
*/
File(const data_t* buffer, int size, int stream = 0);
/**
* Queries the streams of the file.
* \return A vector with as many streams as there are in the file.
* \exception Exception Thrown if the file specified cannot be read.
*/
std::vector<StreamInfo> queryStreams();
virtual std::shared_ptr<IReader> createReader();
};
AUD_NAMESPACE_END

View File

@@ -0,0 +1,42 @@
/*******************************************************************************
* 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 FileInfo.h
* @ingroup file
* The FileInfo data structures.
*/
#include "respec/Specification.h"
AUD_NAMESPACE_BEGIN
/// Specification of a sound source.
struct StreamInfo
{
/// Start time in seconds.
double start;
/// Duration in seconds. May be estimated or 0 if unknown.
double duration;
/// Audio data parameters.
DeviceSpecs specs;
};
AUD_NAMESPACE_END

View File

@@ -0,0 +1,116 @@
/*******************************************************************************
* 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 FileManager.h
* @ingroup file
* The FileManager class.
*/
#include "FileInfo.h"
#include "respec/Specification.h"
#include "IWriter.h"
#include <list>
#include <memory>
#include <string>
#include <vector>
AUD_NAMESPACE_BEGIN
class IFileInput;
class IFileOutput;
class IReader;
class Buffer;
/**
* The FileManager manages all file input and output plugins.
*/
class AUD_API FileManager
{
private:
static std::list<std::shared_ptr<IFileInput>>& inputs();
static std::list<std::shared_ptr<IFileOutput>>& outputs();
// delete copy constructor and operator=
FileManager(const FileManager&) = delete;
FileManager& operator=(const FileManager&) = delete;
FileManager() = delete;
public:
/**
* Registers a file input used to create an IReader to read from a file.
* @param input The IFileInput to register.
*/
static void registerInput(std::shared_ptr<IFileInput> input);
/**
* Registers a file output used to create an IWriter to write to a file.
* @param output The IFileOutput to register.
*/
static void registerOutput(std::shared_ptr<IFileOutput> output);
/**
* Creates a file reader for the given filename if a registed IFileInput is able to read it.
* @param filename The path to the file.
* @param stream The index of the audio stream within the file if it contains multiple audio streams.
* @return The reader created.
* @exception Exception If no file input can read the file an exception is thrown.
*/
static std::shared_ptr<IReader> createReader(const std::string &filename, int stream = 0);
/**
* Creates a file reader for the given buffer if a registed IFileInput is able to read it.
* @param buffer The buffer to read the file from.
* @param stream The index of the audio stream within the file if it contains multiple audio streams.
* @return The reader created.
* @exception Exception If no file input can read the file an exception is thrown.
*/
static std::shared_ptr<IReader> createReader(std::shared_ptr<Buffer> buffer, int stream = 0);
/**
* Queries the streams of a sound file.
* \param filename Path to the file to be read.
* \return A vector with as many streams as there are in the file.
* \exception Exception Thrown if the file specified cannot be read.
*/
static std::vector<StreamInfo> queryStreams(const std::string &filename);
/**
* Queries the streams of a sound file.
* \param buffer The in-memory file buffer.
* \return A vector with as many streams as there are in the file.
* \exception Exception Thrown if the file specified cannot be read.
*/
static std::vector<StreamInfo> queryStreams(std::shared_ptr<Buffer> buffer);
/**
* Creates a file writer that writes a sound to the given file path.
* Existing files will be overwritten.
* @param filename The file path to write to.
* @param specs The output specification.
* @param format The container format for the file.
* @param codec The codec used inside the container.
* @param bitrate The bitrate to write with.
* @return A writer that creates the file.
* @exception Exception If no file output can write the file with the given specification an exception is thrown.
*/
static std::shared_ptr<IWriter> createWriter(const std::string &filename, DeviceSpecs specs, Container format, Codec codec, unsigned int bitrate);
};
AUD_NAMESPACE_END

View File

@@ -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 FileWriter.h
* @ingroup file
* The FileWriter class.
*/
#include "respec/Specification.h"
#include "file/IWriter.h"
#include <string>
#include <vector>
#include <memory>
AUD_NAMESPACE_BEGIN
class IReader;
/**
* The FileWriter class is able to create IWriter classes as well as write readers to them.
*/
class AUD_API FileWriter
{
private:
// hide default constructor, copy constructor and operator=
FileWriter() = delete;
FileWriter(const FileWriter&) = delete;
FileWriter& operator=(const FileWriter&) = delete;
public:
/**
* Creates a new IWriter.
* \param filename The file to write to.
* \param specs The file's audio specification.
* \param format The file's container format.
* \param codec The codec used for encoding the audio data.
* \param bitrate The bitrate for encoding.
* \return The writer to write data to.
*/
static std::shared_ptr<IWriter> createWriter(const std::string &filename, DeviceSpecs specs, Container format, Codec codec, unsigned int bitrate);
/**
* Writes a reader to a writer.
* \param reader The reader to read from.
* \param writer The writer to write to.
* \param length How many samples should be transferred.
* \param buffersize How many samples should be transferred at once.
*/
static void writeReader(std::shared_ptr<IReader> reader, std::shared_ptr<IWriter> writer, unsigned int length, unsigned int buffersize, bool(*callback)(float, void*) = nullptr, void* data = nullptr);
/**
* Writes a reader to several writers.
* \param reader The reader to read from.
* \param writers The writers to write to.
* \param length How many samples should be transferred.
* \param buffersize How many samples should be transferred at once.
*/
static void writeReader(std::shared_ptr<IReader> reader, std::vector<std::shared_ptr<IWriter> >& writers, unsigned int length, unsigned int buffersize, bool(*callback)(float, void*) = nullptr, void* data = nullptr);
};
AUD_NAMESPACE_END

View File

@@ -0,0 +1,85 @@
/*******************************************************************************
* 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 IFileInput.h
* @ingroup file
* The IFileInput interface.
*/
#include "Audaspace.h"
#include "FileInfo.h"
#include <memory>
#include <string>
#include <vector>
AUD_NAMESPACE_BEGIN
class IReader;
class Buffer;
/**
* @interface IFileInput
* The IFileInput interface represents a file input plugin that can create file
* input readers from filenames or buffers.
*/
class AUD_API IFileInput
{
public:
/**
* Destroys the file input.
*/
virtual ~IFileInput() {}
/**
* Creates a reader for a file to be read.
* \param filename Path to the file to be read.
* \param stream The index of the audio stream within the file if it contains multiple audio streams.
* \return The reader that reads the file.
* \exception Exception Thrown if the file specified cannot be read.
*/
virtual std::shared_ptr<IReader> createReader(const std::string &filename, int stream = 0)=0;
/**
* Creates a reader for a file to be read from memory.
* \param buffer The in-memory file buffer.
* \param stream The index of the audio stream within the file if it contains multiple audio streams.
* \return The reader that reads the file.
* \exception Exception Thrown if the file specified cannot be read.
*/
virtual std::shared_ptr<IReader> createReader(std::shared_ptr<Buffer> buffer, int stream = 0)=0;
/**
* Queries the streams of a sound file.
* \param filename Path to the file to be read.
* \return A vector with as many streams as there are in the file.
* \exception Exception Thrown if the file specified cannot be read.
*/
virtual std::vector<StreamInfo> queryStreams(const std::string &filename)=0;
/**
* Queries the streams of a sound file.
* \param buffer The in-memory file buffer.
* \return A vector with as many streams as there are in the file.
* \exception Exception Thrown if the file specified cannot be read.
*/
virtual std::vector<StreamInfo> queryStreams(std::shared_ptr<Buffer> buffer)=0;
};
AUD_NAMESPACE_END

View File

@@ -0,0 +1,52 @@
/*******************************************************************************
* 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 IFileOutput.h
* @ingroup file
* The IFileOutput interface.
*/
#include "file/IWriter.h"
#include "respec/Specification.h"
#include <memory>
#include <string>
AUD_NAMESPACE_BEGIN
/**
* @interface IFileOutput
* The IFileOutput interface represents a file output plugin that can write files.
*/
class AUD_API IFileOutput
{
public:
/**
* Creates a new file writer.
* \param filename The path to the file to be written.
* \param specs The file's audio specification.
* \param format The file's container format.
* \param codec The codec used for encoding the audio data.
* \param bitrate The bitrate for encoding.
* \exception Exception Thrown if the file specified cannot be written.
*/
virtual std::shared_ptr<IWriter> createWriter(const std::string &filename, DeviceSpecs specs, Container format, Codec codec, unsigned int bitrate)=0;
};
AUD_NAMESPACE_END

View File

@@ -0,0 +1,90 @@
/*******************************************************************************
* 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 IWriter.h
* @ingroup file
* Defines the IWriter interface as well as Container and Codec types.
*/
#include "respec/Specification.h"
AUD_NAMESPACE_BEGIN
/// Container formats for writers.
enum Container
{
CONTAINER_INVALID = 0,
CONTAINER_AC3,
CONTAINER_FLAC,
CONTAINER_MATROSKA,
CONTAINER_MP2,
CONTAINER_MP3,
CONTAINER_OGG,
CONTAINER_WAV,
CONTAINER_AAC
};
/// Audio codecs for writers.
enum Codec
{
CODEC_INVALID = 0,
CODEC_AAC,
CODEC_AC3,
CODEC_FLAC,
CODEC_MP2,
CODEC_MP3,
CODEC_PCM,
CODEC_VORBIS,
CODEC_OPUS
};
/**
* @interface IWriter
* This class represents a sound sink where audio data can be written to.
*/
class AUD_API IWriter
{
public:
/**
* Destroys the writer.
*/
virtual ~IWriter() {}
/**
* Returns how many samples have been written so far.
* \return The writing position as sample count. May be negative if unknown.
*/
virtual int getPosition() const=0;
/**
* Returns the specification of the audio data being written into the sink.
* \return The DeviceSpecs structure.
* \note Regardless of the format the input still has to be float!
*/
virtual DeviceSpecs getSpecs() const=0;
/**
* Request to write the next length samples out into the sink.
* \param length The count of samples to write.
* \param buffer The pointer to the buffer containing the data.
*/
virtual void write(unsigned int length, sample_t* buffer)=0;
};
AUD_NAMESPACE_END

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -0,0 +1,123 @@
/*******************************************************************************
* Copyright 2009-2025 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 AnimateableTimeStretchPitchScale.h
* @ingroup fx
* The AnimateableTimeStretchPitchScale class.
*/
#include "fx/Effect.h"
#include "fx/TimeStretchPitchScale.h"
#include "sequence/AnimateableProperty.h"
AUD_NAMESPACE_BEGIN
/**
* This sound allows a sound to be time-stretched and pitch scaled with animation support
* \note The reader has to be seekable.
*/
class AUD_API AnimateableTimeStretchPitchScale : public Effect
{
private:
/**
* The FPS of the animation system.
*/
float m_fps;
/**
* The animateable time-stretch property.
*/
std::shared_ptr<AnimateableProperty> m_timeStretch;
/**
* The animateable pitch-scale property.
*/
std::shared_ptr<AnimateableProperty> m_pitchScale;
/**
* Rubberband stretcher quality options.
*/
StretcherQuality m_quality;
/**
* Whether to preserve the vocal formants for the stretcher.
*/
bool m_preserveFormant;
// delete copy constructor and operator=
AnimateableTimeStretchPitchScale(const AnimateableTimeStretchPitchScale&) = delete;
AnimateableTimeStretchPitchScale& operator=(const AnimateableTimeStretchPitchScale&) = delete;
public:
/**
* Creates a new time-stretch, pitch-scaled sound that can be animated.
* \param sound The input sound.
* \param fps The fps of the animation system.
* \param timeRatio The starting factor by which to stretch or compress time.
* \param pitchScale The starting factor by which to adjust the pitch.
* \param quality The processing quality level of the stretcher.
* \param preserveFormant Whether to preserve the vocal formants for the stretcher.
*/
AnimateableTimeStretchPitchScale(std::shared_ptr<ISound> sound, float fps, float timeStretch, float pitchScale, StretcherQuality quality, bool preserveFormant);
/**
* Creates a new time-stretch, pitch-scaled sound that can be animated.
* \param sound The input sound.
* \param fps The fps of the anumation system.
* \param timeRatio The animateable time-stretch property.
* \param pitchScale The animateable pitch-scale property.
* \param quality The processing quality level of the stretcher.
* \param preserveFormant Whether to preserve the vocal formants for the stretcher.
*/
AnimateableTimeStretchPitchScale(std::shared_ptr<ISound> sound, float fps, std::shared_ptr<AnimateableProperty> timeStretch, std::shared_ptr<AnimateableProperty> pitchScale,
StretcherQuality quality, bool preserveFormant);
/**
* Returns whether formant preservation is enabled.
*/
bool getPreserveFormant() const;
/**
* Returns the quality of the stretcher.
*/
StretcherQuality getStretcherQuality() const;
/**
* Retrieves one of the animated properties of the sound.
* \param type Which animated property to retrieve.
* \return A shared pointer to the animated property
*/
std::shared_ptr<AnimateableProperty> getAnimProperty(AnimateablePropertyType type);
/**
* Retrieves the animation system's FPS.
* \return The animation system's FPS.
*/
float getFPS() const;
/**
* Sets the animation system's FPS.
* \param fps The new FPS.
*/
void setFPS(float fps);
virtual std::shared_ptr<IReader> createReader();
};
AUD_NAMESPACE_END

View File

@@ -0,0 +1,72 @@
/*******************************************************************************
* Copyright 2009-2025 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 AnimateableTimeStretchPitchScaleReader.h
* @ingroup fx
* The AnimateableTimeStretchPitchScaleReader class.
*/
#include "fx/AnimateableTimeStretchPitchScale.h"
#include "fx/TimeStretchPitchScaleReader.h"
AUD_NAMESPACE_BEGIN
/**
* This class reads from another reader and applies time-stretching and pitch scaling with support for animating both properties.
*/
class AUD_API AnimateableTimeStretchPitchScaleReader : public TimeStretchPitchScaleReader
{
private:
/**
* The FPS of the animation system.
*/
float m_fps;
/**
* The animateable time-stretch property.
*/
std::shared_ptr<AnimateableProperty> m_timeStretch;
/**
* The animateable pitch-scale property.
*/
std::shared_ptr<AnimateableProperty> m_pitchScale;
// delete copy constructor and operator=
AnimateableTimeStretchPitchScaleReader(const AnimateableTimeStretchPitchScaleReader&) = delete;
AnimateableTimeStretchPitchScaleReader& operator=(const AnimateableTimeStretchPitchScaleReader&) = delete;
public:
/**
* Creates a new animateable time-stretch, pitch scale reader.
* \param reader The input reader.
* \param fps The FPS of the animation system.
* \param timeStretch The animateable time-stretch property.
* \param pitchScale The animateable pitch-scale property.
* \param quality The stretcher quality options.
* \param preserveFormant Whether to preserve vocal formants.
*/
AnimateableTimeStretchPitchScaleReader(std::shared_ptr<IReader> reader, float fp, std::shared_ptr<AnimateableProperty> timeStretch,
std::shared_ptr<AnimateableProperty> pitchScale, StretcherQuality quality, bool preserveFormant);
virtual void read(int& length, bool& eos, sample_t* buffer) override;
virtual void seek(int position) override;
};
AUD_NAMESPACE_END

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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 double 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, double delay = 0);
/**
* Returns the delay in seconds.
*/
double getDelay() const;
virtual std::shared_ptr<IReader> createReader();
};
AUD_NAMESPACE_END

View File

@@ -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, double 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

View File

@@ -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

View File

@@ -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

View File

@@ -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.
*/
double 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(double seconds);
/**
* Gets the length of the crossfade transition (default 1 second).
* \return The length of the cressfade transition in seconds.
*/
double 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(double position);
/**
* Retrieves the current playback position of a sound.
* \return The playback position in seconds, or 0.0 if the handle is
* invalid.
*/
double 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

View File

@@ -0,0 +1,27 @@
#pragma once
/**
* @file Echo.h
* @ingroup fx
* The Echo class.
*/
#include "fx/Effect.h"
AUD_NAMESPACE_BEGIN
class AUD_API Echo : public Effect
{
private:
float m_delay; /* Delay time in seconds */
float m_feedback; /* Feedback amount */
float m_mix; /* Wet/dry mix */
bool m_resetBuffer; /* Whether to reset the delay buffer */
public:
Echo(std::shared_ptr<ISound> sound, float delay, float feedback, float mix, bool resetBuffer = true);
virtual std::shared_ptr<IReader> createReader();
};
AUD_NAMESPACE_END

View File

@@ -0,0 +1,53 @@
/*******************************************************************************
* Copyright 2009-2025 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 EchoReader.h
* @ingroup fx
* The EchoReader class.
*/
#include <memory>
#include "fx/EffectReader.h"
#include "util/Buffer.h"
AUD_NAMESPACE_BEGIN
class AUD_API EchoReader : public EffectReader
{
private:
float m_delay;
float m_feedback;
float m_mix;
bool m_resetBuffer;
Buffer m_inBuffer;
Buffer m_delayBuffer;
int m_writePosition{0};
int m_samplesAvailable{0};
public:
EchoReader(std::shared_ptr<IReader> reader, float delay, float feedback, float mix, bool resetBuffer = true);
virtual void read(int& length, bool& eos, sample_t* buffer) override;
virtual void seek(int position) override;
};
AUD_NAMESPACE_END

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -0,0 +1,106 @@
/*******************************************************************************
* Copyright 2022 Marcos Perez Gonzalez
*
* 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 Equalizer.h
* @ingroup fx
* The Equalizer class.
*/
#include <memory>
#include <vector>
#include "ISound.h"
#include "ImpulseResponse.h"
AUD_NAMESPACE_BEGIN
class Buffer;
class ImpulseResponse;
/**
* This class represents a sound that can be modified depending on a given impulse response.
*/
class AUD_API Equalizer : public ISound
{
private:
/**
* A pointer to the imput sound.
*/
std::shared_ptr<ISound> m_sound;
/**
* Local definition of Equalizer
*/
std::shared_ptr<Buffer> m_bufEQ;
/**
* A pointer to the impulse response.
*/
std::shared_ptr<ImpulseResponse> m_impulseResponse;
/**
* delete copy constructor and operator=
*/
Equalizer(const Equalizer&) = delete;
Equalizer& operator=(const Equalizer&) = delete;
/**
* Create ImpulseResponse from the definition in the Buffer,
* using at the end a minimum phase change
*/
std::shared_ptr<ImpulseResponse> createImpulseResponse();
/**
* Create an Impulse Response with minimum phase distortion using Homomorphic
* The input is an Impulse Response
*/
std::shared_ptr<Buffer> minimumPhaseFilterHomomorphic(std::shared_ptr<Buffer> original, int lOriginal, int lWork);
/**
* Create an Impulse Response with minimum phase distortion using Hilbert
* The input is an Impulse Response
*/
std::shared_ptr<Buffer> minimumPhaseFilterHilbert(std::shared_ptr<Buffer> original, int lOriginal, int lWork);
public:
/**
* Creates a new Equalizer.
* \param sound The sound that will be equalized
*/
Equalizer(std::shared_ptr<ISound> sound, std::shared_ptr<Buffer> bufEQ, int externalSizeEq, float maxFreqEq, int sizeConversion);
virtual ~Equalizer();
virtual std::shared_ptr<IReader> createReader();
/*
* Length of the external equalizer definition. It must be the number of "float" positions of the Buffer
*/
int external_size_eq;
/*
* Length of the internal equalizer definition
*/
int filter_length;
/*
* Maximum frequency used in the equalizer definition
*/
float maxFreqEq;
};
AUD_NAMESPACE_END

View File

@@ -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

View File

@@ -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 double m_start;
/**
* The fading length.
*/
const double 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,
double start = 0, double length = 1);
/**
* Returns the fading type.
*/
FadeType getType() const;
/**
* Returns the fading start.
*/
double getStart() const;
/**
* Returns the fading length.
*/
double getLength() const;
virtual std::shared_ptr<IReader> createReader();
};
AUD_NAMESPACE_END

View File

@@ -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 double m_start;
/**
* The fading length.
*/
const double 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,
double start,double length);
virtual void read(int& length, bool& eos, sample_t* buffer);
};
AUD_NAMESPACE_END

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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 double m_start;
/**
* The end time.
*/
const double 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,
double start = 0, double end = -1);
/**
* Returns the start time.
*/
double getStart() const;
/**
* Returns the end time.
*/
double getEnd() const;
virtual std::shared_ptr<IReader> createReader();
};
AUD_NAMESPACE_END

View File

@@ -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 double m_start;
/**
* The end sample: exlusive.
*/
const double 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, double start = 0, double 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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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 Modulator.h
* @ingroup fx
* The Modulator class.
*/
#include "ISound.h"
AUD_NAMESPACE_BEGIN
/**
* This sound plays two other factories, playing them the same time and modulating/multiplying them.
* \note Readers from the underlying factories must have the same sample rate
* and channel count.
*/
class AUD_API Modulator : public ISound
{
private:
/**
* First played sound.
*/
std::shared_ptr<ISound> m_sound1;
/**
* Second played sound.
*/
std::shared_ptr<ISound> m_sound2;
// delete copy constructor and operator=
Modulator(const Modulator&) = delete;
Modulator& operator=(const Modulator&) = delete;
public:
/**
* Creates a new modulator sound.
* \param sound1 The first input sound.
* \param sound2 The second input sound.
*/
Modulator(std::shared_ptr<ISound> sound1, std::shared_ptr<ISound> sound2);
virtual std::shared_ptr<IReader> createReader();
};
AUD_NAMESPACE_END

View File

@@ -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 ModulatorReader.h
* @ingroup fx
* The ModulatorReader class.
*/
#include "IReader.h"
#include "util/Buffer.h"
#include <memory>
AUD_NAMESPACE_BEGIN
/**
* This reader plays two readers with the same specs in parallel multiplying their samples.
*/
class AUD_API ModulatorReader : public IReader
{
private:
/**
* The first reader.
*/
std::shared_ptr<IReader> m_reader1;
/**
* The second reader.
*/
std::shared_ptr<IReader> m_reader2;
/**
* Buffer used for mixing.
*/
Buffer m_buffer;
// delete copy constructor and operator=
ModulatorReader(const ModulatorReader&) = delete;
ModulatorReader& operator=(const ModulatorReader&) = delete;
public:
/**
* Creates a new modulator reader.
* \param reader1 The first reader to read from.
* \param reader2 The second reader to read from.
* \exception Exception Thrown if the specs from the readers differ.
*/
ModulatorReader(std::shared_ptr<IReader> reader1, std::shared_ptr<IReader> reader2);
/**
* Destroys the reader.
*/
virtual ~ModulatorReader();
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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -0,0 +1,101 @@
/*******************************************************************************
* Copyright 2009-2025 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 TimeStretchPitchScale.h
* @ingroup fx
* The TimeStretchPitchScale class.
*/
#include "fx/Effect.h"
AUD_NAMESPACE_BEGIN
enum class StretcherQuality
{
HIGH = 0, // Prioritize high-quality pitch processing
FAST = 1, // Prioritize speed over audio quality
CONSISTENT = 2 // Prioritize consistency for dynamic pitch changes
};
/**
* This sound allows a sound to be time-stretched and pitch scaled.
* \note The reader has to be seekable.
*/
class AUD_API TimeStretchPitchScale : public Effect
{
private:
/**
* The factor by which to stretch or compress time.
*/
double m_timeRatio;
/**
* The factor by which to adjust the pitch.
*/
double m_pitchScale;
/**
* Rubberband stretcher quality.
*/
StretcherQuality m_quality;
/**
* Whether to preserve the vocal formants during pitch-shifting
*/
bool m_preserveFormant;
// delete copy constructor and operator=
TimeStretchPitchScale(const TimeStretchPitchScale&) = delete;
TimeStretchPitchScale& operator=(const TimeStretchPitchScale&) = delete;
public:
/**
* Creates a new time-stretch, pitch scaled sound.
* \param sound The input sound.
* \param timeRatio The factor by which to stretch or compress time.
* \param pitchScale The factor by which to adjust the pitch.
* \param quality The processing quality level.
* \param preserveFormant Whether to preserve the vocal formants for the stretcher.
*/
TimeStretchPitchScale(std::shared_ptr<ISound> sound, double timeRatio, double pitchScale, StretcherQuality quality, bool preserveFormant);
/**
* Returns the time ratio.
*/
double getTimeRatio() const;
/**
* Returns the pitch scale.
*/
double getPitchScale() const;
/**
* Returns whether formant preservation is enabled.
*/
bool getPreserveFormant() const;
/**
* Returns the quality of the stretcher.
*/
StretcherQuality getStretcherQuality() const;
virtual std::shared_ptr<IReader> createReader();
};
AUD_NAMESPACE_END

View File

@@ -0,0 +1,126 @@
/*******************************************************************************
* Copyright 2009-2025 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 TimeStretchPitchScaleReader.h
* @ingroup fx
* The TimeStretchPitchScaleReader class.
*/
#include "TimeStretchPitchScale.h"
#include "fx/EffectReader.h"
#include "rubberband/RubberBandStretcher.h"
#include "util/Buffer.h"
using namespace RubberBand;
AUD_NAMESPACE_BEGIN
/**
* This class reads from another reader and applies time-stretching and pitch scaling.
*/
class AUD_API TimeStretchPitchScaleReader : public EffectReader
{
private:
/**
* The input buffer for the reader.
*/
Buffer m_buffer;
/**
* The input/output deinterleaved buffers for each channel.
*/
std::vector<Buffer> m_deinterleaved;
/**
* The pointers to the input/output deinterleaved buffer data for processing/retrieving.
*/
std::vector<sample_t*> m_channelData;
/**
* Number of samples that need to be dropped at the beginning or after a seek.
*/
int m_samplesToDrop;
// delete copy constructor and operator=
TimeStretchPitchScaleReader(const TimeStretchPitchScaleReader&) = delete;
TimeStretchPitchScaleReader& operator=(const TimeStretchPitchScaleReader&) = delete;
protected:
/**
* Feeds the number of required zero samples to the stretcher and queries the amount of samples to drop.
*/
void reset();
/**
* Rubberband stretcher.
*/
std::unique_ptr<RubberBandStretcher> m_stretcher;
/**
* The current position.
*/
int m_position;
/**
* Whether the reader has reached the end of stream.
*/
bool m_finishedReader;
public:
/**
* Creates a new stretcher reader.
* \param reader The reader to read from.
* \param timeRatio The factor by which to stretch or compress time.
* \param pitchScale The factor by which to adjust the pitch.
* \param quality The processing quality level of the stretcher.
* \param preserveFormant Whether to preserve the vocal formants for the stretcher.
*/
TimeStretchPitchScaleReader(std::shared_ptr<IReader> reader, double timeRatio, double pitchScale, StretcherQuality quality, bool preserveFormant);
virtual void read(int& length, bool& eos, sample_t* buffer);
virtual void seek(int position);
virtual int getLength() const;
virtual int getPosition() const;
/**
* Retrieves the current time ratio for the stretcher.
* \return The current time ratio value.
*/
double getTimeRatio() const;
/**
* Sets the time ratio for the stretcher.
*/
void setTimeRatio(double timeRatio);
/**
* Retrieves the pitch scale for the stretcher.
* \return The current pitch scale value.
*/
double getPitchScale() const;
/**
* Sets the pitch scale for the stretcher.
*/
void setPitchScale(double pitchScale);
};
AUD_NAMESPACE_END

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -0,0 +1,66 @@
/*******************************************************************************
* 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 Sawtooth.h
* @ingroup generator
* The Sawtooth class.
*/
#include "ISound.h"
#include "respec/Specification.h"
AUD_NAMESPACE_BEGIN
/**
* This sound creates a reader that plays a sawtooth tone.
*/
class AUD_API Sawtooth : public ISound
{
private:
/**
* The frequence of the sawtooth wave.
*/
const float m_frequency;
/**
* The target sample rate for output.
*/
const SampleRate m_sampleRate;
// delete copy constructor and operator=
Sawtooth(const Sawtooth&) = delete;
Sawtooth& operator=(const Sawtooth&) = delete;
public:
/**
* Creates a new sawtooth sound.
* \param frequency The desired frequency.
* \param sampleRate The target sample rate for playback.
*/
Sawtooth(float frequency, SampleRate sampleRate = RATE_48000);
/**
* Returns the frequency of the sawtooth wave.
*/
float getFrequency() const;
virtual std::shared_ptr<IReader> createReader();
};
AUD_NAMESPACE_END

View File

@@ -0,0 +1,86 @@
/*******************************************************************************
* 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 SawtoothReader.h
* @ingroup generator
* The SawtoothReader class.
*/
#include "IReader.h"
AUD_NAMESPACE_BEGIN
/**
* This class is used for sawtooth tone playback.
* The output format is in the 16 bit format and stereo, the sample rate can be
* specified.
* As the two channels both play the same the output could also be mono, but
* in most cases this will result in having to resample for output, so stereo
* sound is created directly.
*/
class AUD_API SawtoothReader : public IReader
{
private:
/**
* The frequency of the sine wave.
*/
float m_frequency;
/**
* The current position in samples.
*/
int m_position;
/**
* The value of the current sample.
*/
float m_sample;
/**
* The sample rate for the output.
*/
const SampleRate m_sampleRate;
// delete copy constructor and operator=
SawtoothReader(const SawtoothReader&) = delete;
SawtoothReader& operator=(const SawtoothReader&) = delete;
public:
/**
* Creates a new reader.
* \param frequency The frequency of the sine wave.
* \param sampleRate The output sample rate.
*/
SawtoothReader(float frequency, SampleRate sampleRate);
/**
* Sets the frequency of the wave.
* @param frequency The new frequency in Hertz.
*/
void setFrequency(float frequency);
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

View File

@@ -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 Silence.h
* @ingroup generator
* The Silence class.
*/
#include "ISound.h"
#include "respec/Specification.h"
AUD_NAMESPACE_BEGIN
/**
* This sound creates a reader that plays silence.
*/
class AUD_API Silence : public ISound
{
private:
/**
* The target sample rate for output.
*/
const SampleRate m_sampleRate;
// delete copy constructor and operator=
Silence(const Silence&) = delete;
Silence& operator=(const Silence&) = delete;
public:
/**
* Creates a new silence sound.
* \param sampleRate The target sample rate for playback.
*/
Silence(SampleRate sampleRate = RATE_48000);
virtual std::shared_ptr<IReader> createReader();
};
AUD_NAMESPACE_END

View File

@@ -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 SilenceReader.h
* @ingroup generator
* The SilenceReader class.
*/
#include "IReader.h"
AUD_NAMESPACE_BEGIN
/**
* This class is used for silence playback.
* The signal generated is 44.1kHz mono.
*/
class AUD_API SilenceReader : public IReader
{
private:
/**
* The current position in samples.
*/
int m_position;
/**
* The sample rate for the output.
*/
const SampleRate m_sampleRate;
// delete copy constructor and operator=
SilenceReader(const SilenceReader&) = delete;
SilenceReader& operator=(const SilenceReader&) = delete;
public:
/**
* Creates a new reader.
* \param sampleRate The output sample rate.
*/
SilenceReader(SampleRate sampleRate);
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

View File

@@ -0,0 +1,66 @@
/*******************************************************************************
* 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 Sine.h
* @ingroup generator
* The Sine class.
*/
#include "ISound.h"
#include "respec/Specification.h"
AUD_NAMESPACE_BEGIN
/**
* This sound creates a reader that plays a sine tone.
*/
class AUD_API Sine : public ISound
{
private:
/**
* The frequence of the sine wave.
*/
const float m_frequency;
/**
* The target sample rate for output.
*/
const SampleRate m_sampleRate;
// delete copy constructor and operator=
Sine(const Sine&) = delete;
Sine& operator=(const Sine&) = delete;
public:
/**
* Creates a new sine sound.
* \param frequency The desired frequency.
* \param sampleRate The target sample rate for playback.
*/
Sine(float frequency, SampleRate sampleRate = RATE_48000);
/**
* Returns the frequency of the sine wave.
*/
float getFrequency() const;
virtual std::shared_ptr<IReader> createReader();
};
AUD_NAMESPACE_END

View File

@@ -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 SineReader.h
* @ingroup generator
* The SineReader class.
*/
#include "IReader.h"
AUD_NAMESPACE_BEGIN
/**
* This class is used for sine tone playback.
* The sample rate can be specified, the signal is mono.
*/
class AUD_API SineReader : public IReader
{
private:
/**
* The frequency of the sine wave.
*/
float m_frequency;
/**
* The current position in samples.
*/
int m_position;
/**
* The sample rate for the output.
*/
const SampleRate m_sampleRate;
// delete copy constructor and operator=
SineReader(const SineReader&) = delete;
SineReader& operator=(const SineReader&) = delete;
public:
/**
* Creates a new reader.
* \param frequency The frequency of the sine wave.
* \param sampleRate The output sample rate.
*/
SineReader(float frequency, SampleRate sampleRate);
/**
* Sets the frequency of the wave.
* @param frequency The new frequency in Hertz.
*/
void setFrequency(float frequency);
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

View File

@@ -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 Square.h
* @ingroup generator
* The Square class.
*/
#include "ISound.h"
#include "respec/Specification.h"
AUD_NAMESPACE_BEGIN
/**
* This sound creates a reader that plays a square tone.
*/
class AUD_API Square : public ISound
{
private:
/**
* The frequence of the square wave.
*/
const float m_frequency;
/**
* The target sample rate for output.
*/
const SampleRate m_sampleRate;
// delete copy constructor and operator=
Square(const Square&) = delete;
Square& operator=(const Square&) = delete;
public:
/**
* Creates a new square sound.
* \param frequency The desired frequency.
* \param sampleRate The target sample rate for playback.
*/
Square(float frequency,
SampleRate sampleRate = RATE_48000);
/**
* Returns the frequency of the square wave.
*/
float getFrequency() const;
virtual std::shared_ptr<IReader> createReader();
};
AUD_NAMESPACE_END

View File

@@ -0,0 +1,86 @@
/*******************************************************************************
* 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 SquareReader.h
* @ingroup generator
* The SquareReader class.
*/
#include "IReader.h"
AUD_NAMESPACE_BEGIN
/**
* This class is used for square tone playback.
* The output format is in the 16 bit format and stereo, the sample rate can be
* specified.
* As the two channels both play the same the output could also be mono, but
* in most cases this will result in having to resample for output, so stereo
* sound is created directly.
*/
class AUD_API SquareReader : public IReader
{
private:
/**
* The frequency of the sine wave.
*/
float m_frequency;
/**
* The current position in samples.
*/
int m_position;
/**
* The value of the current sample.
*/
float m_sample;
/**
* The sample rate for the output.
*/
const SampleRate m_sampleRate;
// delete copy constructor and operator=
SquareReader(const SquareReader&) = delete;
SquareReader& operator=(const SquareReader&) = delete;
public:
/**
* Creates a new reader.
* \param frequency The frequency of the sine wave.
* \param sampleRate The output sample rate.
*/
SquareReader(float frequency, SampleRate sampleRate);
/**
* Sets the frequency of the wave.
* @param frequency The new frequency in Hertz.
*/
void setFrequency(float frequency);
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

View File

@@ -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 Triangle.h
* @ingroup generator
* The Triangle class.
*/
#include "ISound.h"
#include "respec/Specification.h"
AUD_NAMESPACE_BEGIN
/**
* This sound creates a reader that plays a triangle tone.
*/
class AUD_API Triangle : public ISound
{
private:
/**
* The frequence of the triangle wave.
*/
const float m_frequency;
/**
* The target sample rate for output.
*/
const SampleRate m_sampleRate;
// delete copy constructor and operator=
Triangle(const Triangle&) = delete;
Triangle& operator=(const Triangle&) = delete;
public:
/**
* Creates a new triangle sound.
* \param frequency The desired frequency.
* \param sampleRate The target sample rate for playback.
*/
Triangle(float frequency,
SampleRate sampleRate = RATE_48000);
/**
* Returns the frequency of the triangle wave.
*/
float getFrequency() const;
virtual std::shared_ptr<IReader> createReader();
};
AUD_NAMESPACE_END

View File

@@ -0,0 +1,86 @@
/*******************************************************************************
* 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 TriangleReader.h
* @ingroup generator
* The TriangleReader class.
*/
#include "IReader.h"
AUD_NAMESPACE_BEGIN
/**
* This class is used for sawtooth tone playback.
* The output format is in the 16 bit format and stereo, the sample rate can be
* specified.
* As the two channels both play the same the output could also be mono, but
* in most cases this will result in having to resample for output, so stereo
* sound is created directly.
*/
class AUD_API TriangleReader : public IReader
{
private:
/**
* The frequency of the sine wave.
*/
float m_frequency;
/**
* The current position in samples.
*/
int m_position;
/**
* The value of the current sample.
*/
float m_sample;
/**
* The sample rate for the output.
*/
const SampleRate m_sampleRate;
// delete copy constructor and operator=
TriangleReader(const TriangleReader&) = delete;
TriangleReader& operator=(const TriangleReader&) = delete;
public:
/**
* Creates a new reader.
* \param frequency The frequency of the sine wave.
* \param sampleRate The output sample rate.
*/
TriangleReader(float frequency, SampleRate sampleRate);
/**
* Sets the frequency of the wave.
* @param frequency The new frequency in Hertz.
*/
void setFrequency(float frequency);
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

View File

@@ -0,0 +1,81 @@
/*******************************************************************************
* 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 PluginManager.h
* @ingroup plugin
* The PluginManager class.
*/
#include "Audaspace.h"
#include <unordered_map>
#include <string>
AUD_NAMESPACE_BEGIN
/**
* This manager provides utilities for plugin loading.
*/
class AUD_API PluginManager
{
private:
static std::unordered_map<std::string, void*> m_plugins;
// delete copy constructor and operator=
PluginManager(const PluginManager&) = delete;
PluginManager& operator=(const PluginManager&) = delete;
PluginManager() = delete;
public:
/**
* Opens a shared library.
* @param path The path to the file.
* @return A handle to the library or nullptr if opening failed.
*/
static void* openLibrary(const std::string& path);
/**
* Looks up a symbol from an opened library.
* @param handle The handle to the opened library.
* @param name The name of the symbol to look up.
* @return The symbol or nullptr if the symbol was not found.
*/
static void* lookupLibrary(void* handle, const std::string& name);
/**
* Closes an opened shared library.
* @param handle The handle to the library to be closed.
*/
static void closeLibrary(void* handle);
/**
* Loads a plugin from a file.
* @param path The path to the file.
* @return Whether the file could successfully be loaded.
*/
static bool loadPlugin(const std::string& path);
/**
* Loads all plugins found in a folder.
* @param path The path to the folder containing the plugins.
*/
static void loadPlugins(const std::string& path = "");
};
AUD_NAMESPACE_END

View File

@@ -0,0 +1,51 @@
/*******************************************************************************
* 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 ChannelMapper.h
* @ingroup respec
* The ChannelMapper class.
*/
#include "respec/SpecsChanger.h"
AUD_NAMESPACE_BEGIN
/**
* This sound creates a reader that maps a sound source's channels to a
* specific output channel count.
*/
class AUD_API ChannelMapper : public SpecsChanger
{
private:
// delete copy constructor and operator=
ChannelMapper(const ChannelMapper&) = delete;
ChannelMapper& operator=(const ChannelMapper&) = delete;
public:
/**
* Creates a new sound.
* \param sound The input sound.
* \param specs The target specifications.
*/
ChannelMapper(std::shared_ptr<ISound> sound, DeviceSpecs specs);
virtual std::shared_ptr<IReader> createReader();
};
AUD_NAMESPACE_END

View File

@@ -0,0 +1,151 @@
/*******************************************************************************
* 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 ChannelMapperReader.h
* @ingroup respec
* The ChannelMapperReader class.
*/
#include "fx/EffectReader.h"
#include "util/Buffer.h"
AUD_NAMESPACE_BEGIN
/**
* This class maps a sound source's channels to a specific output channel count.
* \note The input sample format must be float.
*/
class AUD_API ChannelMapperReader : public EffectReader
{
private:
/**
* The sound reading buffer.
*/
Buffer m_buffer;
/**
* The output specification.
*/
Channels m_target_channels;
/**
* The channel count of the reader.
*/
Channels m_source_channels;
/**
* The mapping specification.
*/
float* m_mapping;
/**
* The size of the mapping.
*/
int m_map_size;
/**
* The mono source angle.
*/
float m_mono_angle;
static const Channel MONO_MAP[];
static const Channel STEREO_MAP[];
static const Channel STEREO_LFE_MAP[];
static const Channel SURROUND4_MAP[];
static const Channel SURROUND5_MAP[];
static const Channel SURROUND51_MAP[];
static const Channel SURROUND61_MAP[];
static const Channel SURROUND71_MAP[];
static const Channel* CHANNEL_MAPS[];
static const float MONO_ANGLES[];
static const float STEREO_ANGLES[];
static const float STEREO_LFE_ANGLES[];
static const float SURROUND4_ANGLES[];
static const float SURROUND5_ANGLES[];
static const float SURROUND51_ANGLES[];
static const float SURROUND61_ANGLES[];
static const float SURROUND71_ANGLES[];
static const float* CHANNEL_ANGLES[];
// delete copy constructor and operator=
ChannelMapperReader(const ChannelMapperReader&) = delete;
ChannelMapperReader& operator=(const ChannelMapperReader&) = delete;
/**
* Calculates the mapping matrix.
*/
void AUD_LOCAL calculateMapping();
/**
* Calculates the distance between two angles.
*/
float AUD_LOCAL angleDistance(float alpha, float beta);
public:
/**
* Creates a channel mapper reader.
* \param reader The reader to map.
* \param channels The target channel count this reader should map to.
*/
ChannelMapperReader(std::shared_ptr<IReader> reader, Channels channels);
/**
* Destroys the reader.
*/
~ChannelMapperReader();
/**
* Returns the channel configuration of the source reader.
* @return The channel configuration of the reader.
*/
Channels getSourceChannels() const;
/**
* Returns the target channel configuration.
* Equals getSpecs().channels.
* @return The target channel configuration.
*/
Channels getChannels() const;
/**
* Sets the requested channel output count.
* \param channels The channel output count.
*/
void setChannels(Channels channels);
/**
* Returns the mapping of the source channel to the target channel.
* @param source The number of the source channel. Should be in the range [0, source channels).
* @param target The number of the target channel. Should be in the range [0, target channels).
* @return The mapping value which should be between 0.0 and 1.0. If source or target are out of range, NaN is returned.
*/
float getMapping(int source, int target);
/**
* Sets the angle for mono sources.
* \param angle The angle for mono sources.
*/
void setMonoAngle(float angle);
virtual Specs getSpecs() const;
virtual void read(int& length, bool& eos, sample_t* buffer);
};
AUD_NAMESPACE_END

View File

@@ -0,0 +1,51 @@
/*******************************************************************************
* 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 Converter.h
* @ingroup respec
* The Converter class.
*/
#include "respec/SpecsChanger.h"
AUD_NAMESPACE_BEGIN
/**
* This sound creates a converter reader that is able to convert from one
* audio format to another.
*/
class AUD_API Converter : public SpecsChanger
{
private:
// delete copy constructor and operator=
Converter(const Converter&) = delete;
Converter& operator=(const Converter&) = delete;
public:
/**
* Creates a new sound.
* \param sound The input sound.
* \param specs The target specifications.
*/
Converter(std::shared_ptr<ISound> sound, DeviceSpecs specs);
virtual std::shared_ptr<IReader> createReader();
};
AUD_NAMESPACE_END

View File

@@ -0,0 +1,377 @@
/*******************************************************************************
* 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 ConverterFunctions.h
* @ingroup respec
* Defines several conversion functions between different sample formats.
*/
#include "Audaspace.h"
#include <cstring>
AUD_NAMESPACE_BEGIN
/**
* The function template for functions converting from one sample format
* to another, having the same parameter order as std::memcpy.
*/
typedef void (*convert_f)(data_t* target, data_t* source, int length);
/**
* The copy conversion function simply calls std::memcpy.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
template <class T>
void convert_copy(data_t* target, data_t* source, int length)
{
std::memcpy(target, source, length*sizeof(T));
}
/**
* @brief Converts from FORMAT_U8 to FORMAT_S16.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_u8_s16(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_U8 to FORMAT_S24 big endian.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_u8_s24_be(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_U8 to FORMAT_S24 little endian.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_u8_s24_le(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_U8 to FORMAT_S32.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_u8_s32(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_U8 to FORMAT_FLOAT32.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_u8_float(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_U8 to FORMAT_FLOAT64.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_u8_double(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S16 to FORMAT_U8.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s16_u8(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S16 to FORMAT_S24 big endian.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s16_s24_be(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S16 to FORMAT_S24 little endian.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s16_s24_le(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S16 to FORMAT_S32.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s16_s32(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S16 to FORMAT_FLOAT32.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s16_float(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S16 to FORMAT_FLOAT64.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s16_double(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S24 big endian to FORMAT_U8.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s24_u8_be(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S24 little endian to FORMAT_U8.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s24_u8_le(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S24 big endian to FORMAT_S16.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s24_s16_be(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S24 little endian to FORMAT_S16.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s24_s16_le(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S24 to FORMAT_S24 simply using std::memcpy.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s24_s24(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S24 big endian to FORMAT_S32.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s24_s32_be(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S24 little endian to FORMAT_S32.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s24_s32_le(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S24 big endian to FORMAT_FLOAT32.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s24_float_be(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S24 little endian to FORMAT_FLOAT32.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s24_float_le(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S24 big endian to FORMAT_FLOAT64.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s24_double_be(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S24 little endian to FORMAT_FLOAT64.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s24_double_le(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S32 to FORMAT_U8.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s32_u8(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S32 to FORMAT_S16.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s32_s16(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S32 to FORMAT_S24 big endian.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s32_s24_be(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S32 to FORMAT_S24 little endian.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s32_s24_le(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S32 to FORMAT_FLOAT32.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s32_float(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S32 to FORMAT_FLOAT64.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s32_double(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_FLOAT32 to FORMAT_U8.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_float_u8(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_FLOAT32 to FORMAT_S16.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_float_s16(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_FLOAT32 to FORMAT_S24 big endian.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_float_s24_be(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_FLOAT32 to FORMAT_S24 little endian.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_float_s24_le(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_FLOAT32 to FORMAT_S32.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_float_s32(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_FLOAT32 to FORMAT_FLOAT64.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_float_double(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_FLOAT64 to FORMAT_U8.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_double_u8(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_FLOAT64 to FORMAT_S16.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_double_s16(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_FLOAT64 to FORMAT_S24 big endian.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_double_s24_be(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_FLOAT64 to FORMAT_S24 little endian.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_double_s24_le(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_FLOAT64 to FORMAT_S32.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_double_s32(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_FLOAT64 to FORMAT_FLOAT32.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_double_float(data_t* target, data_t* source, int length);
AUD_NAMESPACE_END

View File

@@ -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 ConverterReader.h
* @ingroup respec
* The ConverterReader class.
*/
#include "fx/EffectReader.h"
#include "respec/ConverterFunctions.h"
#include "util/Buffer.h"
AUD_NAMESPACE_BEGIN
/**
* This class converts a sound source from one to another format.
*/
class AUD_API ConverterReader : public EffectReader
{
private:
/**
* The sound output buffer.
*/
Buffer m_buffer;
/**
* The target specification.
*/
SampleFormat m_format;
/**
* Converter function.
*/
convert_f m_convert;
// delete copy constructor and operator=
ConverterReader(const ConverterReader&) = delete;
ConverterReader& operator=(const ConverterReader&) = delete;
public:
/**
* Creates a converter reader.
* \param reader The reader to convert.
* \param specs The target specification.
*/
ConverterReader(std::shared_ptr<IReader> reader, DeviceSpecs specs);
virtual void read(int& length, bool& eos, sample_t* buffer);
};
AUD_NAMESPACE_END

Some files were not shown because too many files have changed in this diff Show More