/* Audio File Library Copyright (C) 2010, Michael Pruett This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "config.h" #include "SimpleModule.h" #include void SimpleModule::runPull() { pull(m_outChunk->frameCount); run(*m_inChunk, *m_outChunk); } void SimpleModule::runPush() { m_outChunk->frameCount = m_inChunk->frameCount; run(*m_inChunk, *m_outChunk); push(m_outChunk->frameCount); } ApplyChannelMatrix::ApplyChannelMatrix(FormatCode format, bool isReading, int inChannels, int outChannels, double minClip, double maxClip, const double *matrix) : m_format(format), m_inChannels(inChannels), m_outChannels(outChannels), m_minClip(minClip), m_maxClip(maxClip), m_matrix(NULL) { m_matrix = new double[m_inChannels * m_outChannels]; if (matrix) { if (isReading) { // Copy channel matrix for reading. std::copy(matrix, matrix + m_inChannels * m_outChannels, m_matrix); } else { // Transpose channel matrix for writing. for (int i=0; i < inChannels; i++) for (int j=0; j < outChannels; j++) m_matrix[j*inChannels + i] = matrix[i*outChannels + j]; } } else { initDefaultMatrix(); } } ApplyChannelMatrix::~ApplyChannelMatrix() { delete [] m_matrix; } const char *ApplyChannelMatrix::name() const { return "channelMatrix"; } void ApplyChannelMatrix::describe() { m_outChunk->f.channelCount = m_outChannels; m_outChunk->f.pcm.minClip = m_minClip; m_outChunk->f.pcm.maxClip = m_maxClip; } void ApplyChannelMatrix::run(Chunk &inChunk, Chunk &outChunk) { switch (m_format) { case kInt8: run(inChunk.buffer, outChunk.buffer, inChunk.frameCount); break; case kInt16: run(inChunk.buffer, outChunk.buffer, inChunk.frameCount); break; case kInt24: case kInt32: run(inChunk.buffer, outChunk.buffer, inChunk.frameCount); break; case kFloat: run(inChunk.buffer, outChunk.buffer, inChunk.frameCount); break; case kDouble: run(inChunk.buffer, outChunk.buffer, inChunk.frameCount); break; default: assert(false); } } template void ApplyChannelMatrix::run(const void *inputData, void *outputData, int frameCount) { const T *input = reinterpret_cast(inputData); T *output = reinterpret_cast(outputData); for (int frame=0; frame