2015-01-30 21:36:11 +01:00
|
|
|
/** @file
|
|
|
|
* @author Edouard DUPIN
|
|
|
|
* @copyright 2011, Edouard DUPIN, all right reserved
|
|
|
|
* @license APACHE v2.0 (see license file)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __AIRT_ALGO_VOLUME_H__
|
|
|
|
#define __AIRT_ALGO_VOLUME_H__
|
|
|
|
|
2015-02-05 19:10:53 +01:00
|
|
|
#include <drain/Algo.h>
|
2015-01-30 21:36:11 +01:00
|
|
|
#ifdef HAVE_SPEEX_DSP_RESAMPLE
|
|
|
|
#include <speex/speex_resampler.h>
|
|
|
|
#endif
|
|
|
|
#include <memory>
|
|
|
|
|
2015-02-05 19:10:53 +01:00
|
|
|
namespace drain {
|
2015-02-03 21:29:23 +01:00
|
|
|
// data structure.
|
|
|
|
class VolumeElement {
|
|
|
|
public:
|
|
|
|
VolumeElement(const std::string& _name="ERROR-VOLUME-NAME", float _volumedB=0.0f) :
|
|
|
|
m_name(_name),
|
|
|
|
m_volumedB(_volumedB) {
|
|
|
|
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
std::string m_name;
|
|
|
|
public:
|
|
|
|
std::string getName() const {
|
|
|
|
return m_name;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
float m_volumedB;
|
|
|
|
public:
|
|
|
|
float getVolume() const {
|
|
|
|
return m_volumedB;
|
|
|
|
}
|
|
|
|
void setVolume(float _volumedB) {
|
|
|
|
m_volumedB = _volumedB;
|
|
|
|
}
|
|
|
|
};
|
2015-02-02 21:48:57 +01:00
|
|
|
// TODO: Optimisation
|
|
|
|
// TODO: Zero crossing
|
|
|
|
// TODO: Continuous update volume
|
|
|
|
// TODO: Manage multiple volume
|
|
|
|
// TODO: Manage set volume
|
2015-01-30 21:36:11 +01:00
|
|
|
class Volume : public Algo {
|
|
|
|
private:
|
2015-02-05 19:10:53 +01:00
|
|
|
std::vector<std::shared_ptr<drain::VolumeElement>> m_volumeList;
|
2015-02-02 21:48:57 +01:00
|
|
|
// for float input :
|
2015-01-30 21:36:11 +01:00
|
|
|
float m_volumeAppli;
|
2015-02-02 21:48:57 +01:00
|
|
|
// for integer input :
|
|
|
|
int32_t m_volumeDecalage; // Volume to apply is simple as : X * m_coef >> m_coef
|
|
|
|
int32_t m_volumeCoef;
|
|
|
|
// convertion function:
|
|
|
|
void (*m_functionConvert)(void* _input, void* _output, size_t _nbSample, int32_t _volumeCoef, int32_t _volumeDecalage, float _volumeAppli);
|
2015-01-30 21:36:11 +01:00
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* @brief Constructor
|
|
|
|
*/
|
|
|
|
Volume();
|
|
|
|
void init();
|
|
|
|
public:
|
|
|
|
static std::shared_ptr<Volume> create();
|
|
|
|
/**
|
|
|
|
* @brief Destructor
|
|
|
|
*/
|
|
|
|
virtual ~Volume();
|
|
|
|
protected:
|
|
|
|
virtual void configurationChange();
|
|
|
|
public:
|
|
|
|
virtual bool process(std::chrono::system_clock::time_point& _time,
|
|
|
|
void* _input,
|
|
|
|
size_t _inputNbChunk,
|
|
|
|
void*& _output,
|
|
|
|
size_t& _outputNbChunk);
|
2015-02-01 22:22:42 +01:00
|
|
|
public:
|
2015-02-04 22:39:05 +01:00
|
|
|
virtual std::vector<audio::format> getFormatSupportedInput();
|
|
|
|
virtual std::vector<audio::format> getFormatSupportedOutput();
|
2015-02-03 21:29:23 +01:00
|
|
|
public:
|
2015-02-05 19:10:53 +01:00
|
|
|
virtual void addVolumeStage(const std::shared_ptr<drain::VolumeElement>& _volume);
|
2015-02-03 21:29:23 +01:00
|
|
|
virtual bool setParameter(const std::string& _parameter, const std::string& _value);
|
|
|
|
virtual std::string getParameter(const std::string& _parameter) const;
|
|
|
|
virtual std::string getParameterProperty(const std::string& _parameter) const;
|
2015-02-04 21:08:06 +01:00
|
|
|
public:
|
|
|
|
void volumeChange();
|
2015-01-30 21:36:11 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|