[DEV] update new ETK

This commit is contained in:
Edouard DUPIN 2017-09-26 15:57:44 +02:00
parent 3e2ef8ce59
commit 09889ba745
20 changed files with 93 additions and 100 deletions

View File

@ -17,8 +17,8 @@ audio::drain::Algo::Algo() :
void audio::drain::Algo::init() { void audio::drain::Algo::init() {
// set notification callback : // set notification callback :
m_input.setCallback(std::bind(&audio::drain::Algo::configurationChangeLocal, this)); m_input.setCallback([=](){audio::drain::Algo::configurationChangeLocal();});
m_output.setCallback(std::bind(&audio::drain::Algo::configurationChangeLocal, this)); m_output.setCallback([=](){audio::drain::Algo::configurationChangeLocal();});
// first configure ==> update the internal parameters // first configure ==> update the internal parameters
configurationChange(); configurationChange();
} }
@ -62,13 +62,13 @@ void audio::drain::Algo::configurationChange() {
etk::String audio::drain::Algo::getDotDesc() { etk::String audio::drain::Algo::getDotDesc() {
etk::String out; etk::String out;
if (m_input.getFormat() != m_output.getFormat()) { if (m_input.getFormat() != m_output.getFormat()) {
out += "\\nformat: " + etk::toString(m_input.getFormat()) + "->" + etk::to_string(m_output.getFormat()); out += "\\nformat: " + etk::toString(m_input.getFormat()) + "->" + etk::toString(m_output.getFormat());
} }
if (m_input.getMap() != m_output.getMap()) { if (m_input.getMap() != m_output.getMap()) {
out += "\\nmap: " + etk::toString(m_input.getMap()) + "->" + etk::to_string(m_output.getMap()); out += "\\nmap: " + etk::toString(m_input.getMap()) + "->" + etk::toString(m_output.getMap());
} }
if (m_input.getFrequency() != m_output.getFrequency()) { if (m_input.getFrequency() != m_output.getFrequency()) {
out += "\\nsamplerate: " + etk::toString(m_input.getFrequency()) + "->" + etk::to_string(m_output.getFrequency()); out += "\\nsamplerate: " + etk::toString(m_input.getFrequency()) + "->" + etk::toString(m_output.getFrequency());
} }
return out; return out;
} }

View File

@ -7,10 +7,9 @@
#include <etk/String.hpp> #include <etk/String.hpp>
#include <etk/Vector.hpp> #include <etk/Vector.hpp>
#include <cstdint>
#include <audio/format.hpp> #include <audio/format.hpp>
#include <audio/channel.hpp> #include <audio/channel.hpp>
#include <chrono> #include <echrono/Steady.hpp>
#include <etk/Function.hpp> #include <etk/Function.hpp>
#include <ememory/memory.hpp> #include <ememory/memory.hpp>
#include "AutoLogInOut.hpp" #include "AutoLogInOut.hpp"

View File

@ -5,7 +5,6 @@
*/ */
#include <audio/drain/ChannelReorder.hpp> #include <audio/drain/ChannelReorder.hpp>
#include <iostream>
#include "debug.hpp" #include "debug.hpp"

View File

@ -75,9 +75,9 @@ void audio::drain::CircularBuffer::setCapacity(size_t _capacity, size_t _chunkSi
m_write = &m_data[0]; m_write = &m_data[0];
} }
void audio::drain::CircularBuffer::setCapacity(std::chrono::milliseconds _capacity, size_t _chunkSize, uint32_t _frequency) { void audio::drain::CircularBuffer::setCapacity(echrono::Duration _capacity, size_t _chunkSize, uint32_t _frequency) {
uint32_t nbSampleNeeded = _frequency*_capacity.count()/1000; uint32_t nbSampleNeeded = _frequency*_capacity.get()/1000000000LL;
DRAIN_DEBUG("buffer setCapacity(" << _capacity.count() << "ms ," << _chunkSize << ")"); DRAIN_DEBUG("buffer setCapacity(" << _capacity << " ," << _chunkSize << ")");
setCapacity(nbSampleNeeded, _chunkSize, _frequency); setCapacity(nbSampleNeeded, _chunkSize, _frequency);
} }
@ -191,11 +191,11 @@ size_t audio::drain::CircularBuffer::read(void* _data, size_t _nbChunk, const au
if (0 < m_size) { if (0 < m_size) {
// check the time of the read : // check the time of the read :
audio::Duration deltaTime = m_timeRead - _time; audio::Duration deltaTime = m_timeRead - _time;
if (deltaTime.count() == 0) { if (deltaTime.get() == 0) {
// nothing to do ==> just copy data ... // nothing to do ==> just copy data ...
} else if (deltaTime.count() > 0) { } else if (deltaTime.get() > 0) {
// Add empty sample in the output buffer ... // Add empty sample in the output buffer ...
size_t nbSampleEmpty = m_frequency*deltaTime.count()/100000000; size_t nbSampleEmpty = m_frequency*deltaTime.get()/1000000000LL;
nbSampleEmpty = etk::min(nbSampleEmpty, _nbChunk); nbSampleEmpty = etk::min(nbSampleEmpty, _nbChunk);
DRAIN_WARNING("add Empty sample in the output buffer " << nbSampleEmpty << " / " << _nbChunk); DRAIN_WARNING("add Empty sample in the output buffer " << nbSampleEmpty << " / " << _nbChunk);
memset(_data, 0, nbSampleEmpty * m_sizeChunk); memset(_data, 0, nbSampleEmpty * m_sizeChunk);
@ -212,7 +212,7 @@ size_t audio::drain::CircularBuffer::read(void* _data, size_t _nbChunk, const au
DRAIN_VERBOSE("crop nb sample : m_size=" << m_size << " _nbChunk=" << _nbChunk); DRAIN_VERBOSE("crop nb sample : m_size=" << m_size << " _nbChunk=" << _nbChunk);
_nbChunk = m_size; _nbChunk = m_size;
} }
m_timeRead += std::chrono::microseconds(_nbChunk*1000000/m_frequency); m_timeRead += echrono::microseconds(_nbChunk*1000000/m_frequency);
if (usedSizeBeforeEnd >= _nbChunk) { if (usedSizeBeforeEnd >= _nbChunk) {
// all Data will be copy // all Data will be copy
memcpy(_data, m_read, _nbChunk * m_sizeChunk); memcpy(_data, m_read, _nbChunk * m_sizeChunk);
@ -257,11 +257,11 @@ void audio::drain::CircularBuffer::setReadPosition(const audio::Time& _time) {
if (0 < m_size) { if (0 < m_size) {
// check the time of the read : // check the time of the read :
audio::Duration deltaTime = _time - m_timeRead; audio::Duration deltaTime = _time - m_timeRead;
size_t nbSampleToRemove = int64_t(m_frequency)*int64_t(deltaTime.count())/1000000000LL; size_t nbSampleToRemove = int64_t(m_frequency)*int64_t(deltaTime.get())/1000000000LL;
nbSampleToRemove = etk::min(nbSampleToRemove, m_size); nbSampleToRemove = etk::min(nbSampleToRemove, m_size);
DRAIN_VERBOSE("Remove sample in the buffer " << nbSampleToRemove << " / " << m_size); DRAIN_VERBOSE("Remove sample in the buffer " << nbSampleToRemove << " / " << m_size);
audio::Duration updateTime(0,(int64_t(nbSampleToRemove)*1000000000LL)/int64_t(m_frequency)); audio::Duration updateTime(0,(int64_t(nbSampleToRemove)*1000000000LL)/int64_t(m_frequency));
DRAIN_VERBOSE(" add time : " << updateTime.count() << "ns / " << deltaTime.count() << "ns"); DRAIN_VERBOSE(" add time : " << updateTime << " / " << deltaTime);
if (usedSizeBeforeEnd >= nbSampleToRemove) { if (usedSizeBeforeEnd >= nbSampleToRemove) {
usedSizeBeforeEnd -= nbSampleToRemove; usedSizeBeforeEnd -= nbSampleToRemove;
m_size -= nbSampleToRemove; m_size -= nbSampleToRemove;

View File

@ -7,7 +7,7 @@
#include <etk/types.hpp> #include <etk/types.hpp>
#include <etk/Vector.hpp> #include <etk/Vector.hpp>
#include <chrono> #include <echrono/Steady.hpp>
#include <audio/Time.hpp> #include <audio/Time.hpp>
#include <audio/Duration.hpp> #include <audio/Duration.hpp>
@ -71,14 +71,11 @@ namespace audio {
void setCapacity(size_t _capacity, size_t _chunkSize, uint32_t _frequency); void setCapacity(size_t _capacity, size_t _chunkSize, uint32_t _frequency);
/** /**
* @brief set the capacity of the circular buffer. * @brief set the capacity of the circular buffer.
* @param[in] _capacity time in millisecond stored in the buffer. * @param[in] _capacity Duration stored in the buffer.
* @param[in] _chunkSize Size of one chunk. * @param[in] _chunkSize Size of one chunk.
* @param[in] _frequency Frequency of the buffer * @param[in] _frequency Frequency of the buffer
*/ */
void setCapacity(std::chrono::milliseconds _capacity, size_t _chunkSize, uint32_t _frequency); void setCapacity(echrono::Duration _capacity, size_t _chunkSize, uint32_t _frequency);
void setCapacity(std::chrono::microseconds _capacity, size_t _chunkSize, uint32_t _frequency) {
setCapacity(std::chrono::milliseconds(_capacity.count()/1000), _chunkSize, _frequency);
}
/** /**
* @brief get free size of the buffer. * @brief get free size of the buffer.
* @return Number of free chunk. * @return Number of free chunk.

View File

@ -43,7 +43,7 @@ void audio::drain::EndPointRead::setBufferSize(size_t _nbChunk) {
DRAIN_TODO("..."); DRAIN_TODO("...");
} }
void audio::drain::EndPointRead::setBufferSize(const std::chrono::microseconds& _time) { void audio::drain::EndPointRead::setBufferSize(const echrono::microseconds& _time) {
DRAIN_TODO("..."); DRAIN_TODO("...");
} }
@ -52,9 +52,9 @@ size_t audio::drain::EndPointRead::getBufferSize() {
return 0; return 0;
} }
std::chrono::microseconds audio::drain::EndPointRead::getBufferSizeMicrosecond() { echrono::microseconds audio::drain::EndPointRead::getBufferSizeMicrosecond() {
DRAIN_TODO("..."); DRAIN_TODO("...");
return std::chrono::microseconds(0); return echrono::microseconds(0);
} }
size_t audio::drain::EndPointRead::getBufferFillSize() { size_t audio::drain::EndPointRead::getBufferFillSize() {
@ -62,8 +62,8 @@ size_t audio::drain::EndPointRead::getBufferFillSize() {
return 0; return 0;
} }
std::chrono::microseconds audio::drain::EndPointRead::getBufferFillSizeMicrosecond() { echrono::microseconds audio::drain::EndPointRead::getBufferFillSizeMicrosecond() {
DRAIN_TODO("..."); DRAIN_TODO("...");
return std::chrono::microseconds(0); return echrono::microseconds(0);
} }

View File

@ -37,7 +37,7 @@ namespace audio {
* @brief Set buffer size size of the buffer with the stored time in µs * @brief Set buffer size size of the buffer with the stored time in µs
* @param[in] _time Time in microsecond of the buffer * @param[in] _time Time in microsecond of the buffer
*/ */
virtual void setBufferSize(const std::chrono::microseconds& _time); virtual void setBufferSize(const echrono::microseconds& _time);
/** /**
* @brief get buffer size in chunk number * @brief get buffer size in chunk number
* @return Number of chunk that can be written in the buffer * @return Number of chunk that can be written in the buffer
@ -47,7 +47,7 @@ namespace audio {
* @brief Set buffer size size of the buffer with the stored time in µs * @brief Set buffer size size of the buffer with the stored time in µs
* @return Time in microsecond that can be written in the buffer * @return Time in microsecond that can be written in the buffer
*/ */
virtual std::chrono::microseconds getBufferSizeMicrosecond(); virtual echrono::microseconds getBufferSizeMicrosecond();
/** /**
* @brief Get buffer size filled in chunk number * @brief Get buffer size filled in chunk number
* @return Number of chunk in the buffer (that might be read/write) * @return Number of chunk in the buffer (that might be read/write)
@ -57,7 +57,7 @@ namespace audio {
* @brief Set buffer size size of the buffer with the stored time in µs * @brief Set buffer size size of the buffer with the stored time in µs
* @return Time in microsecond of the buffer (that might be read/write) * @return Time in microsecond of the buffer (that might be read/write)
*/ */
virtual std::chrono::microseconds getBufferFillSizeMicrosecond(); virtual echrono::microseconds getBufferFillSizeMicrosecond();
}; };
} }
} }

View File

@ -37,7 +37,7 @@ void audio::drain::EndPointWrite::configurationChange() {
// update the buffer size ... // update the buffer size ...
if ( audio::getFormatBytes(m_output.getFormat())*m_output.getMap().size() != 0 if ( audio::getFormatBytes(m_output.getFormat())*m_output.getMap().size() != 0
&& m_output.getFrequency() != 0) { && m_output.getFrequency() != 0) {
if (std::chrono::microseconds(0) != m_bufferSizeMicroseconds) { if (m_bufferSizeMicroseconds.get() != 0) {
m_buffer.setCapacity(m_bufferSizeMicroseconds, m_buffer.setCapacity(m_bufferSizeMicroseconds,
audio::getFormatBytes(m_output.getFormat())*m_output.getMap().size(), audio::getFormatBytes(m_output.getFormat())*m_output.getMap().size(),
m_output.getFrequency()); m_output.getFrequency());
@ -119,7 +119,7 @@ void audio::drain::EndPointWrite::write(const void* _value, size_t _nbChunk) {
} }
void audio::drain::EndPointWrite::setBufferSize(size_t _nbChunk) { void audio::drain::EndPointWrite::setBufferSize(size_t _nbChunk) {
m_bufferSizeMicroseconds = std::chrono::microseconds(0); m_bufferSizeMicroseconds = echrono::microseconds(0);
m_bufferSizeChunk = _nbChunk; m_bufferSizeChunk = _nbChunk;
if ( audio::getFormatBytes(m_output.getFormat())*m_output.getMap().size() != 0 if ( audio::getFormatBytes(m_output.getFormat())*m_output.getMap().size() != 0
&& m_output.getFrequency() != 0) { && m_output.getFrequency() != 0) {
@ -129,7 +129,7 @@ void audio::drain::EndPointWrite::setBufferSize(size_t _nbChunk) {
} }
} }
void audio::drain::EndPointWrite::setBufferSize(const std::chrono::microseconds& _time) { void audio::drain::EndPointWrite::setBufferSize(const echrono::microseconds& _time) {
m_bufferSizeMicroseconds = _time; m_bufferSizeMicroseconds = _time;
m_bufferSizeChunk = 0; m_bufferSizeChunk = 0;
m_buffer.setCapacity(_time, m_buffer.setCapacity(_time,
@ -141,20 +141,20 @@ size_t audio::drain::EndPointWrite::getBufferSize() {
if (m_bufferSizeChunk != 0) { if (m_bufferSizeChunk != 0) {
return m_bufferSizeChunk; return m_bufferSizeChunk;
} }
return (int64_t(m_output.getFrequency())*m_bufferSizeMicroseconds.count())/1000000LL; return (int64_t(m_output.getFrequency())*m_bufferSizeMicroseconds.get())/1000000000LL;
} }
std::chrono::microseconds audio::drain::EndPointWrite::getBufferSizeMicrosecond() { echrono::microseconds audio::drain::EndPointWrite::getBufferSizeMicrosecond() {
if (m_bufferSizeMicroseconds != std::chrono::microseconds(0) ) { if (m_bufferSizeMicroseconds.get() != 0) {
return m_bufferSizeMicroseconds; return m_bufferSizeMicroseconds;
} }
return std::chrono::microseconds(m_bufferSizeChunk*1000000LL/int64_t(m_output.getFrequency())); return echrono::microseconds(m_bufferSizeChunk*1000000LL/int64_t(m_output.getFrequency()));
} }
size_t audio::drain::EndPointWrite::getBufferFillSize() { size_t audio::drain::EndPointWrite::getBufferFillSize() {
return m_buffer.getSize()/(audio::getFormatBytes(m_output.getFormat())*m_output.getMap().size()); return m_buffer.getSize()/(audio::getFormatBytes(m_output.getFormat())*m_output.getMap().size());
} }
std::chrono::microseconds audio::drain::EndPointWrite::getBufferFillSizeMicrosecond() { echrono::microseconds audio::drain::EndPointWrite::getBufferFillSizeMicrosecond() {
return std::chrono::microseconds(getBufferFillSize()*1000000LL/int64_t(m_output.getFrequency())); return echrono::microseconds(getBufferFillSize()*1000000LL/int64_t(m_output.getFrequency()));
} }

View File

@ -45,7 +45,7 @@ namespace audio {
m_function = _function; m_function = _function;
} }
protected: protected:
std::chrono::microseconds m_bufferSizeMicroseconds; // 0 if m_bufferSizeChunk != 0 echrono::microseconds m_bufferSizeMicroseconds; // 0 if m_bufferSizeChunk != 0
size_t m_bufferSizeChunk; // 0 if m_bufferSizeMicroseconds != 0 size_t m_bufferSizeChunk; // 0 if m_bufferSizeMicroseconds != 0
size_t m_bufferUnderFlowSize; //!< Limit display of underflow in the write callback size_t m_bufferUnderFlowSize; //!< Limit display of underflow in the write callback
public: public:
@ -58,7 +58,7 @@ namespace audio {
* @brief Set buffer size size of the buffer with the stored time in µs * @brief Set buffer size size of the buffer with the stored time in µs
* @param[in] _time Time in microsecond of the buffer * @param[in] _time Time in microsecond of the buffer
*/ */
virtual void setBufferSize(const std::chrono::microseconds& _time); virtual void setBufferSize(const echrono::microseconds& _time);
/** /**
* @brief get buffer size in chunk number * @brief get buffer size in chunk number
* @return Number of chunk that can be written in the buffer * @return Number of chunk that can be written in the buffer
@ -68,7 +68,7 @@ namespace audio {
* @brief Set buffer size size of the buffer with the stored time in µs * @brief Set buffer size size of the buffer with the stored time in µs
* @return Time in microsecond that can be written in the buffer * @return Time in microsecond that can be written in the buffer
*/ */
virtual std::chrono::microseconds getBufferSizeMicrosecond(); virtual echrono::microseconds getBufferSizeMicrosecond();
/** /**
* @brief Get buffer size filled in chunk number * @brief Get buffer size filled in chunk number
* @return Number of chunk in the buffer (that might be read/write) * @return Number of chunk in the buffer (that might be read/write)
@ -78,7 +78,7 @@ namespace audio {
* @brief Set buffer size size of the buffer with the stored time in µs * @brief Set buffer size size of the buffer with the stored time in µs
* @return Time in microsecond of the buffer (that might be read/write) * @return Time in microsecond of the buffer (that might be read/write)
*/ */
virtual std::chrono::microseconds getBufferFillSizeMicrosecond(); virtual echrono::microseconds getBufferFillSizeMicrosecond();
}; };
} }
} }

View File

@ -5,7 +5,6 @@
*/ */
#include <audio/drain/FormatUpdate.hpp> #include <audio/drain/FormatUpdate.hpp>
#include <iostream>
#include <audio/drain/debug.hpp> #include <audio/drain/debug.hpp>
#ifndef INT16_MAX #ifndef INT16_MAX

View File

@ -7,10 +7,9 @@
#include <etk/String.hpp> #include <etk/String.hpp>
#include <etk/Vector.hpp> #include <etk/Vector.hpp>
#include <cstdint>
#include <audio/format.hpp> #include <audio/format.hpp>
#include <audio/channel.hpp> #include <audio/channel.hpp>
#include <chrono> #include <echrono/Steady.hpp>
#include <etk/Function.hpp> #include <etk/Function.hpp>
#include <ememory/memory.hpp> #include <ememory/memory.hpp>
#include "AutoLogInOut.hpp" #include "AutoLogInOut.hpp"

View File

@ -6,7 +6,6 @@
#include <etk/String.hpp> #include <etk/String.hpp>
#include <etk/Vector.hpp> #include <etk/Vector.hpp>
#include <cstdint>
#include <audio/format.hpp> #include <audio/format.hpp>
#include <audio/channel.hpp> #include <audio/channel.hpp>
#include <audio/drain/Process.hpp> #include <audio/drain/Process.hpp>
@ -39,24 +38,25 @@ bool audio::drain::Process::pull(audio::Time& _time,
void* _data, void* _data,
size_t _nbChunk, size_t _nbChunk,
size_t _chunkSize) { size_t _chunkSize) {
while(m_data.size()<_nbChunk*_chunkSize) { //DRAIN_DEBUG("Execute:");
void* in = NULL; while(m_data.size() < _nbChunk*_chunkSize) {
void* in = nullptr;
size_t nbChunkIn = _nbChunk - m_data.size()/_chunkSize; size_t nbChunkIn = _nbChunk - m_data.size()/_chunkSize;
void* out = NULL; void* out = nullptr;
size_t nbChunkOut; size_t nbChunkOut;
if (nbChunkIn < 128) { if (nbChunkIn < 128) {
nbChunkIn = 128; nbChunkIn = 128;
} }
// TODO : maybe remove this for input data ... // TODO : maybe remove this for input data ...
for (int32_t iii=m_listAlgo.size()-1; iii >=0; --iii) { for (int32_t iii=m_listAlgo.size()-1; iii >=0; --iii) {
if (m_listAlgo[iii] != NULL) { if (m_listAlgo[iii] != nullptr) {
nbChunkIn = m_listAlgo[iii]->needInputData(nbChunkIn); nbChunkIn = m_listAlgo[iii]->needInputData(nbChunkIn);
} }
} }
if (nbChunkIn < 32) { if (nbChunkIn < 32) {
nbChunkIn = 32; nbChunkIn = 32;
} }
//DRAIN_DEBUG(" process:" << _time << " in=" << in << " nbChunkIn=" << nbChunkIn << " out=" << out << " nbChunkOut=" << nbChunkOut);
// get data from the upstream // get data from the upstream
process(_time, in, nbChunkIn, out, nbChunkOut); process(_time, in, nbChunkIn, out, nbChunkOut);
if (nbChunkOut > 0) { if (nbChunkOut > 0) {
@ -91,7 +91,7 @@ bool audio::drain::Process::process(audio::Time& _time,
} }
DRAIN_VERBOSE(" process : " << m_listAlgo.size() << " algos nbChunk=" << _inNbChunk); DRAIN_VERBOSE(" process : " << m_listAlgo.size() << " algos nbChunk=" << _inNbChunk);
for (size_t iii=0; iii<m_listAlgo.size(); ++iii) { for (size_t iii=0; iii<m_listAlgo.size(); ++iii) {
//std::cout << " Algo " << iii+1 << "/" << m_listAlgo.size() << std::endl; DRAIN_VERBOSE(" Algo " << iii+1 << "/" << m_listAlgo.size());
if (m_listAlgo[iii] != nullptr) { if (m_listAlgo[iii] != nullptr) {
m_listAlgo[iii]->process(_time, _inData, _inNbChunk, _outData, _outNbChunk); m_listAlgo[iii]->process(_time, _inData, _inNbChunk, _outData, _outNbChunk);
_inData = _outData; _inData = _outData;
@ -103,18 +103,19 @@ bool audio::drain::Process::process(audio::Time& _time,
void audio::drain::Process::pushBack(ememory::SharedPtr<audio::drain::Algo> _algo) { void audio::drain::Process::pushBack(ememory::SharedPtr<audio::drain::Algo> _algo) {
removeAlgoDynamic(); removeAlgoDynamic();
_algo->setStatusFunction(std::bind(&audio::drain::Process::generateStatus, this, std::placeholders::_1, std::placeholders::_2)); _algo->setStatusFunction([=](const etk::String& _origin, const etk::String& _status) { generateStatus(_origin, _status);});
m_listAlgo.pushBack(_algo); m_listAlgo.pushBack(_algo);
} }
void audio::drain::Process::pushFront(ememory::SharedPtr<audio::drain::Algo> _algo) { void audio::drain::Process::pushFront(ememory::SharedPtr<audio::drain::Algo> _algo) {
removeAlgoDynamic(); removeAlgoDynamic();
_algo->setStatusFunction(std::bind(&audio::drain::Process::generateStatus, this, std::placeholders::_1, std::placeholders::_2)); _algo->setStatusFunction([=](const etk::String& _origin, const etk::String& _status) { generateStatus(_origin, _status);});
m_listAlgo.insert(m_listAlgo.begin(), _algo); m_listAlgo.pushFront(_algo);
} }
template<typename T> etk::Vector<T> getUnion(const etk::Vector<T>& _out, const std::vector<T>& _in) { template<typename DRAIN_TYPE>
etk::Vector<T> out; etk::Vector<DRAIN_TYPE> getUnion(const etk::Vector<DRAIN_TYPE>& _out, const etk::Vector<DRAIN_TYPE>& _in) {
etk::Vector<DRAIN_TYPE> out;
if (_out.size() == 0) { if (_out.size() == 0) {
// Last is ok for all format // Last is ok for all format
// ==> set the limit with the next element // ==> set the limit with the next element
@ -203,7 +204,7 @@ void audio::drain::Process::updateAlgo(size_t _position) {
} else { } else {
mapIn = m_listAlgo[_position]->getMapSupportedInput(); mapIn = m_listAlgo[_position]->getMapSupportedInput();
} }
etk::Vector<etk::Vector<audio::channel> > map = getUnion<std::vector<audio::channel> >(mapOut, mapIn); etk::Vector<etk::Vector<audio::channel> > map = getUnion<etk::Vector<audio::channel> >(mapOut, mapIn);
DRAIN_VERBOSE(" map out :" << mapOut); DRAIN_VERBOSE(" map out :" << mapOut);
DRAIN_VERBOSE(" map in :" << mapIn); DRAIN_VERBOSE(" map in :" << mapIn);
DRAIN_VERBOSE(" map union :" << map); DRAIN_VERBOSE(" map union :" << map);
@ -339,7 +340,7 @@ void audio::drain::Process::updateAlgo(size_t _position) {
algo->setInputFormat(out); algo->setInputFormat(out);
out.setFormat(audio::format_int16); out.setFormat(audio::format_int16);
algo->setOutputFormat(out); algo->setOutputFormat(out);
algo->setStatusFunction(std::bind(&audio::drain::Process::generateStatus, this, std::placeholders::_1, std::placeholders::_2)); algo->setStatusFunction([=](const etk::String& _origin, const etk::String& _status) { generateStatus(_origin, _status);});
m_listAlgo.insert(m_listAlgo.begin()+_position, algo); m_listAlgo.insert(m_listAlgo.begin()+_position, algo);
DRAIN_VERBOSE("convert " << out.getFormat() << " -> " << in.getFormat()); DRAIN_VERBOSE("convert " << out.getFormat() << " -> " << in.getFormat());
_position++; _position++;
@ -350,7 +351,7 @@ void audio::drain::Process::updateAlgo(size_t _position) {
algo->setInputFormat(out); algo->setInputFormat(out);
out.setFrequency(in.getFrequency()); out.setFrequency(in.getFrequency());
algo->setOutputFormat(out); algo->setOutputFormat(out);
algo->setStatusFunction(std::bind(&audio::drain::Process::generateStatus, this, std::placeholders::_1, std::placeholders::_2)); algo->setStatusFunction([=](const etk::String& _origin, const etk::String& _status) { generateStatus(_origin, _status);});
m_listAlgo.insert(m_listAlgo.begin()+_position, algo); m_listAlgo.insert(m_listAlgo.begin()+_position, algo);
DRAIN_VERBOSE("convert " << out.getFrequency() << " -> " << in.getFrequency()); DRAIN_VERBOSE("convert " << out.getFrequency() << " -> " << in.getFrequency());
out.setFrequency(in.getFrequency()); out.setFrequency(in.getFrequency());
@ -363,7 +364,7 @@ void audio::drain::Process::updateAlgo(size_t _position) {
algo->setInputFormat(out); algo->setInputFormat(out);
out.setMap(in.getMap()); out.setMap(in.getMap());
algo->setOutputFormat(out); algo->setOutputFormat(out);
algo->setStatusFunction(std::bind(&audio::drain::Process::generateStatus, this, std::placeholders::_1, std::placeholders::_2)); algo->setStatusFunction([=](const etk::String& _origin, const etk::String& _status) { generateStatus(_origin, _status);});
m_listAlgo.insert(m_listAlgo.begin()+_position, algo); m_listAlgo.insert(m_listAlgo.begin()+_position, algo);
DRAIN_VERBOSE("convert " << out.getMap() << " -> " << in.getMap()); DRAIN_VERBOSE("convert " << out.getMap() << " -> " << in.getMap());
_position++; _position++;
@ -375,7 +376,7 @@ void audio::drain::Process::updateAlgo(size_t _position) {
algo->setInputFormat(out); algo->setInputFormat(out);
out.setFormat(in.getFormat()); out.setFormat(in.getFormat());
algo->setOutputFormat(out); algo->setOutputFormat(out);
algo->setStatusFunction(std::bind(&audio::drain::Process::generateStatus, this, std::placeholders::_1, std::placeholders::_2)); algo->setStatusFunction([=](const etk::String& _origin, const etk::String& _status) { generateStatus(_origin, _status);});
m_listAlgo.insert(m_listAlgo.begin()+_position, algo); m_listAlgo.insert(m_listAlgo.begin()+_position, algo);
DRAIN_VERBOSE("convert " << out.getFormat() << " -> " << in.getFormat()); DRAIN_VERBOSE("convert " << out.getFormat() << " -> " << in.getFormat());
_position++; _position++;
@ -486,7 +487,7 @@ void audio::drain::Process::generateDot(etk::FSNode& _node,
if (m_listAlgo[iii] == nullptr) { if (m_listAlgo[iii] == nullptr) {
continue; continue;
} }
etk::String connectStringSecond = "ALGO_" + etk::toString(_basicID) + "__" + etk::to_string(iii); etk::String connectStringSecond = "ALGO_" + etk::toString(_basicID) + "__" + etk::toString(iii);
_node << " " << connectStringSecond << " [label=\"ALGO\\ntype='" << m_listAlgo[iii]->getType() << "'"; _node << " " << connectStringSecond << " [label=\"ALGO\\ntype='" << m_listAlgo[iii]->getType() << "'";
if (m_listAlgo[iii]->getName() != "") { if (m_listAlgo[iii]->getName() != "") {
_node << "\\nname='" << m_listAlgo[iii]->getName() << "'"; _node << "\\nname='" << m_listAlgo[iii]->getName() << "'";
@ -535,7 +536,7 @@ void audio::drain::Process::generateDot(etk::FSNode& _node,
if (m_listAlgo[iii] == nullptr) { if (m_listAlgo[iii] == nullptr) {
continue; continue;
} }
etk::String connectStringSecond = "ALGO_" + etk::toString(_basicID) + "__" + etk::to_string(iii); etk::String connectStringSecond = "ALGO_" + etk::toString(_basicID) + "__" + etk::toString(iii);
_node << " " << connectStringSecond << " [label=\"ALGO\\ntype='" << m_listAlgo[iii]->getType() << "'"; _node << " " << connectStringSecond << " [label=\"ALGO\\ntype='" << m_listAlgo[iii]->getType() << "'";
if (m_listAlgo[iii]->getName() != "") { if (m_listAlgo[iii]->getName() != "") {
_node << "\\nname='" << m_listAlgo[iii]->getName() << "'"; _node << "\\nname='" << m_listAlgo[iii]->getName() << "'";
@ -592,7 +593,7 @@ void audio::drain::Process::generateDotProcess(etk::FSNode& _node, int32_t _offs
if (m_listAlgo[iii] == nullptr) { if (m_listAlgo[iii] == nullptr) {
continue; continue;
} }
etk::String connectStringSecond = "ALGO_" + etk::toString(_basicID) + "__" + etk::to_string(iii); etk::String connectStringSecond = "ALGO_" + etk::toString(_basicID) + "__" + etk::toString(iii);
_node << " " << connectStringSecond << " [label=\"ALGO\\ntype='" << m_listAlgo[iii]->getType() << "'"; _node << " " << connectStringSecond << " [label=\"ALGO\\ntype='" << m_listAlgo[iii]->getType() << "'";
if (m_listAlgo[iii]->getName() != "") { if (m_listAlgo[iii]->getName() != "") {
_node << "\\nname='" << m_listAlgo[iii]->getName() << "'"; _node << "\\nname='" << m_listAlgo[iii]->getName() << "'";
@ -611,7 +612,7 @@ void audio::drain::Process::generateDotProcess(etk::FSNode& _node, int32_t _offs
if (m_listAlgo[iii] == nullptr) { if (m_listAlgo[iii] == nullptr) {
continue; continue;
} }
etk::String connectStringSecond = "ALGO_" + etk::toString(_basicID) + "__" + etk::to_string(iii); etk::String connectStringSecond = "ALGO_" + etk::toString(_basicID) + "__" + etk::toString(iii);
_node << " " << connectStringSecond << " [label=\"ALGO\\ntype='" << m_listAlgo[iii]->getType() << "'"; _node << " " << connectStringSecond << " [label=\"ALGO\\ntype='" << m_listAlgo[iii]->getType() << "'";
if (m_listAlgo[iii]->getName() != "") { if (m_listAlgo[iii]->getName() != "") {
_node << "\\nname='" << m_listAlgo[iii]->getName() << "'"; _node << "\\nname='" << m_listAlgo[iii]->getName() << "'";

View File

@ -7,11 +7,10 @@
#include <etk/String.hpp> #include <etk/String.hpp>
#include <etk/Vector.hpp> #include <etk/Vector.hpp>
#include <cstdint>
#include <audio/format.hpp> #include <audio/format.hpp>
#include <audio/channel.hpp> #include <audio/channel.hpp>
#include <audio/drain/Algo.hpp> #include <audio/drain/Algo.hpp>
#include <chrono> #include <echrono/Steady.hpp>
#include <ememory/memory.hpp> #include <ememory/memory.hpp>
#include <etk/os/FSNode.hpp> #include <etk/os/FSNode.hpp>
@ -105,10 +104,10 @@ namespace audio {
size_t size() { size_t size() {
return m_listAlgo.size(); return m_listAlgo.size();
} }
etk::Vector<ememory::SharedPtr<drain::Algo> >::iterator begin() { etk::Vector<ememory::SharedPtr<drain::Algo>>::Iterator begin() {
return m_listAlgo.begin(); return m_listAlgo.begin();
} }
etk::Vector<ememory::SharedPtr<drain::Algo> >::iterator end() { etk::Vector<ememory::SharedPtr<drain::Algo>>::Iterator end() {
return m_listAlgo.end(); return m_listAlgo.end();
} }
ememory::SharedPtr<drain::Algo> operator[](int32_t _id) { ememory::SharedPtr<drain::Algo> operator[](int32_t _id) {

View File

@ -5,7 +5,6 @@
*/ */
#include <audio/drain/Resampler.hpp> #include <audio/drain/Resampler.hpp>
#include <iostream>
#include <audio/drain/debug.hpp> #include <audio/drain/debug.hpp>
audio::drain::Resampler::Resampler() : audio::drain::Resampler::Resampler() :
@ -146,12 +145,12 @@ bool audio::drain::Resampler::process(audio::Time& _time,
_outputNbChunk = nbChunkOutput; _outputNbChunk = nbChunkOutput;
DRAIN_VERBOSE(" process chunk=" << nbChunkInput << " out=" << nbChunkOutput); DRAIN_VERBOSE(" process chunk=" << nbChunkInput << " out=" << nbChunkOutput);
audio::Duration outTime(0, (int64_t(_outputNbChunk)*1000000000LL) / int64_t(m_output.getFrequency())); audio::Duration outTime(0, (int64_t(_outputNbChunk)*1000000000LL) / int64_t(m_output.getFrequency()));
DRAIN_VERBOSE("convert " << _inputNbChunk << " ==> " << _outputNbChunk << " " << inTime.count() << " => " << outTime.count()); DRAIN_VERBOSE("convert " << _inputNbChunk << " ==> " << _outputNbChunk << " " << inTime << " => " << outTime);
// correct time : // correct time :
m_residualTimeInResampler -= outTime; m_residualTimeInResampler -= outTime;
/* /*
if (m_residualTimeInResampler.count() < 0) { if (m_residualTimeInResampler.get() < 0) {
DRAIN_TODO("manage this case ... residual time in resampler : " << m_residualTimeInResampler.count() << "ns"); DRAIN_TODO("manage this case ... residual time in resampler : " << m_residualTimeInResampler << "ns");
} }
*/ */
return true; return true;

View File

@ -5,8 +5,9 @@
*/ */
#include <audio/drain/Volume.hpp> #include <audio/drain/Volume.hpp>
#include <iostream> extern "C" {
#include <cmath> #include <math.h>
}
#include <audio/drain/debug.hpp> #include <audio/drain/debug.hpp>
audio::drain::Volume::Volume() : audio::drain::Volume::Volume() :
@ -180,7 +181,7 @@ void audio::drain::Volume::volumeChange() {
#if (defined(__STDCPP_LLVM__) || __cplusplus < 201103L) #if (defined(__STDCPP_LLVM__) || __cplusplus < 201103L)
m_volumeAppli = pow(10.0f, volumedB/20.0f); m_volumeAppli = pow(10.0f, volumedB/20.0f);
#else #else
m_volumeAppli = std::pow(10.0f, volumedB/20.0f); m_volumeAppli = etk::pow(10.0f, volumedB/20.0f);
#endif #endif
switch (m_input.getFormat()) { switch (m_input.getFormat()) {
default: default:

View File

@ -8,7 +8,7 @@
#include <etk/String.hpp> #include <etk/String.hpp>
#include <audio/format.hpp> #include <audio/format.hpp>
#include <audio/drain/channel.hpp> #include <audio/drain/channel.hpp>
#include <chrono> #include <echrono/Steady.hpp>
namespace audio { namespace audio {
namespace drain { namespace drain {

View File

@ -275,7 +275,7 @@ void appl::Windows::onCallbackStart16() {
for (size_t iii=800; iii<data.size()-200; ++iii) { for (size_t iii=800; iii<data.size()-200; ++iii) {
value = etk::max(value, data[iii]); value = etk::max(value, data[iii]);
} }
gain = 20.0 * std::log10(value.getDouble()/32000.0); gain = 20.0 * etk::log10(value.getDouble()/32000.0);
APPL_VERBOSE("LEVEL " << iii << " out = " << value << " % : " << gain); APPL_VERBOSE("LEVEL " << iii << " out = " << value << " % : " << gain);
pratic.pushBack(etk::makePair<float, float>(float(freq),float(gain))); pratic.pushBack(etk::makePair<float, float>(float(freq),float(gain)));
} }
@ -314,7 +314,7 @@ void appl::Windows::onCallbackStartFloat() {
for (size_t iii=800; iii<data.size()-200; ++iii) { for (size_t iii=800; iii<data.size()-200; ++iii) {
value = etk::max(value, data[iii]); value = etk::max(value, data[iii]);
} }
gain = 20.0 * std::log10(value.getDouble()/1.0); gain = 20.0 * etk::log10(value.getDouble()/1.0);
APPL_VERBOSE("LEVEL " << iii << " out = " << value << " % : " << gain); APPL_VERBOSE("LEVEL " << iii << " out = " << value << " % : " << gain);
pratic.pushBack(etk::makePair<float, float>(float(freq),float(gain))); pratic.pushBack(etk::makePair<float, float>(float(freq),float(gain)));
} }

View File

@ -83,23 +83,23 @@ void appl::widget::DisplayFrequency::onRegenerateDisplay() {
bool displayLog = true; bool displayLog = true;
for (size_t kkk=0; kkk<m_data.size(); kkk++) { for (size_t kkk=0; kkk<m_data.size(); kkk++) {
for (size_t iii=0; iii<m_data[kkk].size(); ++iii) { for (size_t iii=0; iii<m_data[kkk].size(); ++iii) {
if (etk::abs(m_data[kkk][iii].second) != std::numeric_limits<float>::infinity()) { if (isinf(etk::abs(m_data[kkk][iii].second)) == false) {
m_gainMax = etk::max(m_gainMax, m_data[kkk][iii].second); m_gainMax = etk::max(m_gainMax, m_data[kkk][iii].second);
m_gainMin = etk::min(m_gainMin, m_data[kkk][iii].second); m_gainMin = etk::min(m_gainMin, m_data[kkk][iii].second);
} }
if (displayLog == false) { if (displayLog == false) {
if (etk::abs(m_data[kkk][iii].first) != std::numeric_limits<float>::infinity()) { if (isinf(etk::abs(m_data[kkk][iii].first)) == false) {
m_frequencyMax = etk::max(m_frequencyMax, m_data[kkk][iii].first); m_frequencyMax = etk::max(m_frequencyMax, m_data[kkk][iii].first);
m_frequencyMin = etk::min(m_frequencyMin, m_data[kkk][iii].first); m_frequencyMin = etk::min(m_frequencyMin, m_data[kkk][iii].first);
} }
} else { } else {
if (etk::abs(m_data[kkk][iii].first) != std::numeric_limits<float>::infinity()) { if (isinf(etk::abs(m_data[kkk][iii].first)) == false) {
if (m_data[kkk][iii].first == 0) { if (m_data[kkk][iii].first == 0) {
continue; continue;
} }
m_frequencyMax = etk::max(m_frequencyMax, std::log(m_data[kkk][iii].first)); m_frequencyMax = etk::max(m_frequencyMax, etk::log(m_data[kkk][iii].first));
m_frequencyMin = etk::min(m_frequencyMin, std::log(m_data[kkk][iii].first)); m_frequencyMin = etk::min(m_frequencyMin, etk::log(m_data[kkk][iii].first));
APPL_INFO("plop " << m_data[kkk][iii].first << " " << std::log(m_data[kkk][iii].first)); APPL_INFO("plop " << m_data[kkk][iii].first << " " << etk::log(m_data[kkk][iii].first));
} }
} }
} }
@ -137,12 +137,12 @@ void appl::widget::DisplayFrequency::onRegenerateDisplay() {
} }
} else { } else {
m_draw.setPos( m_borderSize m_draw.setPos( m_borderSize
+ vec2(ratioX*(std::log(m_data[kkk][0].first) - m_frequencyMin), + vec2(ratioX*(etk::log(m_data[kkk][0].first) - m_frequencyMin),
ratioY*(m_data[kkk][0].second - m_gainMin))); ratioY*(m_data[kkk][0].second - m_gainMin)));
float baseX = 0; float baseX = 0;
for (size_t iii=1; iii<m_data[kkk].size(); ++iii) { for (size_t iii=1; iii<m_data[kkk].size(); ++iii) {
m_draw.lineTo( m_borderSize m_draw.lineTo( m_borderSize
+ vec2(ratioX*(std::log(m_data[kkk][iii].first) - m_frequencyMin), + vec2(ratioX*(etk::log(m_data[kkk][iii].first) - m_frequencyMin),
ratioY*(m_data[kkk][iii].second - m_gainMin))); ratioY*(m_data[kkk][iii].second - m_gainMin)));
} }
} }

View File

@ -212,7 +212,7 @@ void appl::Windows::onCallbackStart16() {
for (size_t iii=800; iii<outputNbChunk-200; ++iii) { for (size_t iii=800; iii<outputNbChunk-200; ++iii) {
value = etk::max(value, output[iii]); value = etk::max(value, output[iii]);
} }
gain = 20.0 * std::log10(double(value)/32000.0); gain = 20.0 * etk::log10(double(value)/32000.0);
APPL_VERBOSE("LEVEL " << iii << " out = " << value << " % : " << gain); APPL_VERBOSE("LEVEL " << iii << " out = " << value << " % : " << gain);
pratic.pushBack(etk::makePair<float, float>(float(freq),float(gain))); pratic.pushBack(etk::makePair<float, float>(float(freq),float(gain)));
} }
@ -253,7 +253,7 @@ void appl::Windows::onCallbackStartFloat() {
for (size_t iii=800; iii<outputNbChunk-200; ++iii) { for (size_t iii=800; iii<outputNbChunk-200; ++iii) {
value = etk::max(value, output[iii]); value = etk::max(value, output[iii]);
} }
gain = 20.0 * std::log10(double(value)/1.0); gain = 20.0 * etk::log10(double(value)/1.0);
APPL_VERBOSE("LEVEL " << iii << " out = " << value << " % : " << gain); APPL_VERBOSE("LEVEL " << iii << " out = " << value << " % : " << gain);
pratic.pushBack(etk::makePair<float, float>(float(freq),float(gain))); pratic.pushBack(etk::makePair<float, float>(float(freq),float(gain)));
} }

View File

@ -83,24 +83,24 @@ void appl::widget::DisplayFrequency::onRegenerateDisplay() {
bool displayLog = true; bool displayLog = true;
for (size_t kkk=0; kkk<m_data.size(); kkk++) { for (size_t kkk=0; kkk<m_data.size(); kkk++) {
for (size_t iii=0; iii<m_data[kkk].size(); ++iii) { for (size_t iii=0; iii<m_data[kkk].size(); ++iii) {
if (etk::abs(m_data[kkk][iii].second) != std::numeric_limits<float>::infinity()) { if (isinf(etk::abs(m_data[kkk][iii].second)) == false) {
m_gainMax = etk::max(m_gainMax, m_data[kkk][iii].second); m_gainMax = etk::max(m_gainMax, m_data[kkk][iii].second);
m_gainMin = etk::min(m_gainMin, m_data[kkk][iii].second); m_gainMin = etk::min(m_gainMin, m_data[kkk][iii].second);
//APPL_INFO("plop " << m_data[kkk][iii].second); //APPL_INFO("plop " << m_data[kkk][iii].second);
} }
if (displayLog == false) { if (displayLog == false) {
if (etk::abs(m_data[kkk][iii].first) != std::numeric_limits<float>::infinity()) { if (isinf(etk::abs(m_data[kkk][iii].first)) == false) {
m_frequencyMax = etk::max(m_frequencyMax, m_data[kkk][iii].first); m_frequencyMax = etk::max(m_frequencyMax, m_data[kkk][iii].first);
m_frequencyMin = etk::min(m_frequencyMin, m_data[kkk][iii].first); m_frequencyMin = etk::min(m_frequencyMin, m_data[kkk][iii].first);
} }
} else { } else {
if (etk::abs(m_data[kkk][iii].first) != std::numeric_limits<float>::infinity()) { if (isinf(etk::abs(m_data[kkk][iii].first))) == false) {
if (m_data[kkk][iii].first == 0) { if (m_data[kkk][iii].first == 0) {
continue; continue;
} }
m_frequencyMax = etk::max(m_frequencyMax, std::log(m_data[kkk][iii].first)); m_frequencyMax = etk::max(m_frequencyMax, etk::log(m_data[kkk][iii].first));
m_frequencyMin = etk::min(m_frequencyMin, std::log(m_data[kkk][iii].first)); m_frequencyMin = etk::min(m_frequencyMin, etk::log(m_data[kkk][iii].first));
//APPL_INFO("plop " << m_data[kkk][iii].first << " " << std::log(m_data[kkk][iii].first)); //APPL_INFO("plop " << m_data[kkk][iii].first << " " << etk::log(m_data[kkk][iii].first));
} }
} }
} }
@ -144,12 +144,12 @@ void appl::widget::DisplayFrequency::onRegenerateDisplay() {
} }
} else { } else {
m_draw.setPos( m_borderSize m_draw.setPos( m_borderSize
+ vec2(ratioX*(std::log(m_data[kkk][0].first) - m_frequencyMin), + vec2(ratioX*(etk::log(m_data[kkk][0].first) - m_frequencyMin),
ratioY*(m_data[kkk][0].second - m_gainMin))); ratioY*(m_data[kkk][0].second - m_gainMin)));
float baseX = 0; float baseX = 0;
for (size_t iii=1; iii<m_data[kkk].size(); ++iii) { for (size_t iii=1; iii<m_data[kkk].size(); ++iii) {
m_draw.lineTo( m_borderSize m_draw.lineTo( m_borderSize
+ vec2(ratioX*(std::log(m_data[kkk][iii].first) - m_frequencyMin), + vec2(ratioX*(etk::log(m_data[kkk][iii].first) - m_frequencyMin),
ratioY*(m_data[kkk][iii].second - m_gainMin))); ratioY*(m_data[kkk][iii].second - m_gainMin)));
} }
} }