Blender V2.61 - r43446

AUD_BaseIIRFilterReader.cpp

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * Copyright 2009-2011 Jörg Hermann Müller
00005  *
00006  * This file is part of AudaSpace.
00007  *
00008  * Audaspace is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * AudaSpace is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with Audaspace; if not, write to the Free Software Foundation,
00020  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00021  *
00022  * ***** END GPL LICENSE BLOCK *****
00023  */
00024 
00030 #include "AUD_BaseIIRFilterReader.h"
00031 
00032 #include <cstring>
00033 
00034 #define CC m_specs.channels + m_channel
00035 
00036 AUD_BaseIIRFilterReader::AUD_BaseIIRFilterReader(AUD_Reference<AUD_IReader> reader, int in,
00037                                                  int out) :
00038         AUD_EffectReader(reader),
00039         m_specs(reader->getSpecs()),
00040         m_xlen(in), m_ylen(out),
00041         m_xpos(0), m_ypos(0), m_channel(0)
00042 {
00043     m_x = new sample_t[m_xlen * m_specs.channels];
00044     m_y = new sample_t[m_ylen * m_specs.channels];
00045 
00046     memset(m_x, 0, sizeof(sample_t) * m_xlen * m_specs.channels);
00047     memset(m_y, 0, sizeof(sample_t) * m_ylen * m_specs.channels);
00048 }
00049 
00050 AUD_BaseIIRFilterReader::~AUD_BaseIIRFilterReader()
00051 {
00052     delete[] m_x;
00053     delete[] m_y;
00054 }
00055 
00056 void AUD_BaseIIRFilterReader::setLengths(int in, int out)
00057 {
00058     if(in != m_xlen)
00059     {
00060         sample_t* xn = new sample_t[in * m_specs.channels];
00061         memset(xn, 0, sizeof(sample_t) * in * m_specs.channels);
00062 
00063         for(m_channel = 0; m_channel < m_specs.channels; m_channel++)
00064         {
00065             for(int i = 1; i <= in && i <= m_xlen; i++)
00066             {
00067                 xn[(in - i) * CC] = x(-i);
00068             }
00069         }
00070 
00071         delete[] m_x;
00072         m_x = xn;
00073         m_xpos = 0;
00074         m_xlen = in;
00075     }
00076 
00077     if(out != m_ylen)
00078     {
00079         sample_t* yn = new sample_t[out * m_specs.channels];
00080         memset(yn, 0, sizeof(sample_t) * out * m_specs.channels);
00081 
00082         for(m_channel = 0; m_channel < m_specs.channels; m_channel++)
00083         {
00084             for(int i = 1; i <= out && i <= m_ylen; i++)
00085             {
00086                 yn[(out - i) * CC] = y(-i);
00087             }
00088         }
00089 
00090         delete[] m_y;
00091         m_y = yn;
00092         m_ypos = 0;
00093         m_ylen = out;
00094     }
00095 }
00096 
00097 void AUD_BaseIIRFilterReader::read(int& length, bool& eos, sample_t* buffer)
00098 {
00099     AUD_Specs specs = m_reader->getSpecs();
00100     if(specs.channels != m_specs.channels)
00101     {
00102         m_specs.channels = specs.channels;
00103 
00104         delete[] m_x;
00105         delete[] m_y;
00106 
00107         m_x = new sample_t[m_xlen * m_specs.channels];
00108         m_y = new sample_t[m_ylen * m_specs.channels];
00109 
00110         memset(m_x, 0, sizeof(sample_t) * m_xlen * m_specs.channels);
00111         memset(m_y, 0, sizeof(sample_t) * m_ylen * m_specs.channels);
00112     }
00113 
00114     if(specs.rate != m_specs.rate)
00115     {
00116         m_specs = specs;
00117         sampleRateChanged(m_specs.rate);
00118     }
00119 
00120     m_reader->read(length, eos, buffer);
00121 
00122     for(m_channel = 0; m_channel < m_specs.channels; m_channel++)
00123     {
00124         for(int i = 0; i < length; i++)
00125         {
00126             m_x[m_xpos * CC] = buffer[i * CC];
00127             m_y[m_ypos * CC] = buffer[i * CC] = filter();
00128 
00129             m_xpos = (m_xpos + 1) % m_xlen;
00130             m_ypos = (m_ypos + 1) % m_ylen;
00131         }
00132     }
00133 }
00134 
00135 void AUD_BaseIIRFilterReader::sampleRateChanged(AUD_SampleRate rate)
00136 {
00137 }