more files

This commit is contained in:
Joseph Eagar
2010-01-13 08:16:14 +00:00
parent 47c88f92bc
commit d2e6e2a67e
28 changed files with 2014 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
/*
* $Id: AUD_AccumulatorFactory.cpp 25656 2010-01-01 18:45:21Z nexyon $
*
* ***** BEGIN LGPL LICENSE BLOCK *****
*
* Copyright 2009 Jörg Hermann Müller
*
* This file is part of AudaSpace.
*
* AudaSpace 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 3 of the License, or
* (at your option) any later version.
*
* AudaSpace 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 AudaSpace. If not, see <http://www.gnu.org/licenses/>.
*
* ***** END LGPL LICENSE BLOCK *****
*/
#include "AUD_AccumulatorFactory.h"
#include "AUD_AccumulatorReader.h"
AUD_AccumulatorFactory::AUD_AccumulatorFactory(AUD_IFactory* factory,
bool additive) :
AUD_EffectFactory(factory),
m_additive(additive) {}
AUD_AccumulatorFactory::AUD_AccumulatorFactory(bool additive) :
AUD_EffectFactory(0),
m_additive(additive) {}
AUD_IReader* AUD_AccumulatorFactory::createReader()
{
AUD_IReader* reader = getReader();
if(reader != 0)
{
reader = new AUD_AccumulatorReader(reader, m_additive);
AUD_NEW("reader")
}
return reader;
}

View File

@@ -0,0 +1,59 @@
/*
* $Id: AUD_AccumulatorFactory.h 25656 2010-01-01 18:45:21Z nexyon $
*
* ***** BEGIN LGPL LICENSE BLOCK *****
*
* Copyright 2009 Jörg Hermann Müller
*
* This file is part of AudaSpace.
*
* AudaSpace 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 3 of the License, or
* (at your option) any later version.
*
* AudaSpace 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 AudaSpace. If not, see <http://www.gnu.org/licenses/>.
*
* ***** END LGPL LICENSE BLOCK *****
*/
#ifndef AUD_ACCUMULATORFACTORY
#define AUD_ACCUMULATORFACTORY
#include "AUD_EffectFactory.h"
/**
* This factory creates an accumulator reader.
*/
class AUD_AccumulatorFactory : public AUD_EffectFactory
{
private:
/**
* Whether the accumulator is additive.
*/
bool m_additive;
public:
/**
* Creates a new accumulator factory.
* \param factory The input factory.
* \param additive Whether the accumulator is additive.
*/
AUD_AccumulatorFactory(AUD_IFactory* factory, bool additive = false);
/**
* Creates a new accumulator factory.
* \param additive Whether the accumulator is additive.
*/
AUD_AccumulatorFactory(bool additive = false);
virtual AUD_IReader* createReader();
};
#endif //AUD_ACCUMULATORFACTORY

View File

@@ -0,0 +1,99 @@
/*
* $Id: AUD_AccumulatorReader.cpp 25656 2010-01-01 18:45:21Z nexyon $
*
* ***** BEGIN LGPL LICENSE BLOCK *****
*
* Copyright 2009 Jörg Hermann Müller
*
* This file is part of AudaSpace.
*
* AudaSpace 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 3 of the License, or
* (at your option) any later version.
*
* AudaSpace 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 AudaSpace. If not, see <http://www.gnu.org/licenses/>.
*
* ***** END LGPL LICENSE BLOCK *****
*/
#include "AUD_AccumulatorReader.h"
#include "AUD_Buffer.h"
#include <cstring>
#define CC specs.channels + channel
AUD_AccumulatorReader::AUD_AccumulatorReader(AUD_IReader* reader,
bool additive) :
AUD_EffectReader(reader),
m_additive(additive)
{
AUD_Specs specs = reader->getSpecs();
int samplesize = AUD_SAMPLE_SIZE(specs);
m_buffer = new AUD_Buffer(); AUD_NEW("buffer")
m_sums = new AUD_Buffer(samplesize); AUD_NEW("buffer")
memset(m_sums->getBuffer(), 0, samplesize);
m_prevs = new AUD_Buffer(samplesize); AUD_NEW("buffer")
memset(m_prevs->getBuffer(), 0, samplesize);
}
AUD_AccumulatorReader::~AUD_AccumulatorReader()
{
delete m_buffer; AUD_DELETE("buffer")
delete m_sums; AUD_DELETE("buffer")
delete m_prevs; AUD_DELETE("buffer")
}
void AUD_AccumulatorReader::read(int & length, sample_t* & buffer)
{
sample_t* buf;
sample_t* sums;
sample_t* prevs;
sums = m_sums->getBuffer();
prevs = m_prevs->getBuffer();
AUD_Specs specs = m_reader->getSpecs();
m_reader->read(length, buf);
if(m_buffer->getSize() < length * AUD_SAMPLE_SIZE(specs))
m_buffer->resize(length * AUD_SAMPLE_SIZE(specs));
buffer = m_buffer->getBuffer();
if(m_additive)
{
for(int channel = 0; channel < specs.channels; channel++)
{
for(int i = 0; i < length; i++)
{
if(buf[i * CC] > prevs[channel])
sums[channel] += buf[i * CC] - prevs[channel];
buffer[i * CC] = sums[channel] + buf[i * CC];
prevs[channel] = buf[i * CC];
}
}
}
else
{
for(int channel = 0; channel < specs.channels; channel++)
{
for(int i = 0; i < length * specs.channels; i++)
{
if(buf[i * CC] > prevs[channel])
sums[channel] += buf[i * CC] - prevs[channel];
buffer[i * CC] = sums[channel];
prevs[channel] = buf[i * CC];
}
}
}
}

View File

@@ -0,0 +1,75 @@
/*
* $Id: AUD_AccumulatorReader.h 25656 2010-01-01 18:45:21Z nexyon $
*
* ***** BEGIN LGPL LICENSE BLOCK *****
*
* Copyright 2009 Jörg Hermann Müller
*
* This file is part of AudaSpace.
*
* AudaSpace 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 3 of the License, or
* (at your option) any later version.
*
* AudaSpace 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 AudaSpace. If not, see <http://www.gnu.org/licenses/>.
*
* ***** END LGPL LICENSE BLOCK *****
*/
#ifndef AUD_ACCUMULATORREADER
#define AUD_ACCUMULATORREADER
#include "AUD_EffectReader.h"
class AUD_Buffer;
/**
* This class represents an accumulator.
*/
class AUD_AccumulatorReader : public AUD_EffectReader
{
private:
/**
* The playback buffer.
*/
AUD_Buffer *m_buffer;
/**
* The sums of the specific channels.
*/
AUD_Buffer *m_sums;
/**
* The previous results of the specific channels.
*/
AUD_Buffer *m_prevs;
/**
* Whether the accumulator is additive.
*/
bool m_additive;
public:
/**
* Creates a new accumulator reader.
* \param reader The reader to read from.
* \param additive Whether the accumulator is additive.
* \exception AUD_Exception Thrown if the reader specified is NULL.
*/
AUD_AccumulatorReader(AUD_IReader* reader, bool additive);
/**
* Destroys the reader.
*/
virtual ~AUD_AccumulatorReader();
virtual void read(int & length, sample_t* & buffer);
};
#endif //AUD_ACCUMULATORREADER

View File

@@ -0,0 +1,49 @@
/*
* $Id: AUD_ButterworthFactory.cpp 25643 2010-01-01 05:09:30Z nexyon $
*
* ***** BEGIN LGPL LICENSE BLOCK *****
*
* Copyright 2009 Jörg Hermann Müller
*
* This file is part of AudaSpace.
*
* AudaSpace 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 3 of the License, or
* (at your option) any later version.
*
* AudaSpace 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 AudaSpace. If not, see <http://www.gnu.org/licenses/>.
*
* ***** END LGPL LICENSE BLOCK *****
*/
#include "AUD_ButterworthFactory.h"
#include "AUD_ButterworthReader.h"
AUD_ButterworthFactory::AUD_ButterworthFactory(AUD_IFactory* factory,
float frequency) :
AUD_EffectFactory(factory),
m_frequency(frequency) {}
AUD_ButterworthFactory::AUD_ButterworthFactory(float frequency) :
AUD_EffectFactory(0),
m_frequency(frequency) {}
AUD_IReader* AUD_ButterworthFactory::createReader()
{
AUD_IReader* reader = getReader();
if(reader != 0)
{
reader = new AUD_ButterworthReader(reader, m_frequency);
AUD_NEW("reader")
}
return reader;
}

View File

@@ -0,0 +1,59 @@
/*
* $Id: AUD_ButterworthFactory.h 25643 2010-01-01 05:09:30Z nexyon $
*
* ***** BEGIN LGPL LICENSE BLOCK *****
*
* Copyright 2009 Jörg Hermann Müller
*
* This file is part of AudaSpace.
*
* AudaSpace 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 3 of the License, or
* (at your option) any later version.
*
* AudaSpace 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 AudaSpace. If not, see <http://www.gnu.org/licenses/>.
*
* ***** END LGPL LICENSE BLOCK *****
*/
#ifndef AUD_BUTTERWORTHFACTORY
#define AUD_BUTTERWORTHFACTORY
#include "AUD_EffectFactory.h"
/**
* This factory creates a butterworth filter reader.
*/
class AUD_ButterworthFactory : public AUD_EffectFactory
{
private:
/**
* The attack value in seconds.
*/
float m_frequency;
public:
/**
* Creates a new butterworth factory.
* \param factory The input factory.
* \param frequency The cutoff frequency.
*/
AUD_ButterworthFactory(AUD_IFactory* factory, float frequency);
/**
* Creates a new butterworth factory.
* \param frequency The cutoff frequency.
*/
AUD_ButterworthFactory(float frequency);
virtual AUD_IReader* createReader();
};
#endif //AUD_BUTTERWORTHFACTORY

View File

@@ -0,0 +1,124 @@
/*
* $Id: AUD_ButterworthReader.cpp 25645 2010-01-01 11:40:48Z nexyon $
*
* ***** BEGIN LGPL LICENSE BLOCK *****
*
* Copyright 2009 Jörg Hermann Müller
*
* This file is part of AudaSpace.
*
* AudaSpace 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 3 of the License, or
* (at your option) any later version.
*
* AudaSpace 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 AudaSpace. If not, see <http://www.gnu.org/licenses/>.
*
* ***** END LGPL LICENSE BLOCK *****
*/
#include "AUD_ButterworthReader.h"
#include "AUD_Buffer.h"
#include <cstring>
#include <cmath>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#define BWPB41 0.76536686473
#define BWPB42 1.84775906502
#define CC channels + channel
AUD_ButterworthReader::AUD_ButterworthReader(AUD_IReader* reader,
float frequency) :
AUD_EffectReader(reader)
{
AUD_Specs specs = reader->getSpecs();
int samplesize = AUD_SAMPLE_SIZE(specs);
m_buffer = new AUD_Buffer(); AUD_NEW("buffer")
m_outvalues = new AUD_Buffer(samplesize * 5); AUD_NEW("buffer")
memset(m_outvalues->getBuffer(), 0, samplesize * 5);
m_invalues = new AUD_Buffer(samplesize * 5); AUD_NEW("buffer")
memset(m_invalues->getBuffer(), 0, samplesize * 5);
m_position = 0;
// calculate coefficients
float omega = 2 * tan(frequency * M_PI / specs.rate);
float o2 = omega * omega;
float o4 = o2 * o2;
float x1 = o2 + 2 * BWPB41 * omega + 4;
float x2 = o2 + 2 * BWPB42 * omega + 4;
float y1 = o2 - 2 * BWPB41 * omega + 4;
float y2 = o2 - 2 * BWPB42 * omega + 4;
float o228 = 2 * o2 - 8;
float norm = x1 * x2;
m_coeff[0][0] = 0;
m_coeff[0][1] = (x1 + x2) * o228 / norm;
m_coeff[0][2] = (x1 * y2 + x2 * y1 + o228 * o228) / norm;
m_coeff[0][3] = (y1 + y2) * o228 / norm;
m_coeff[0][4] = y1 * y2 / norm;
m_coeff[1][4] = m_coeff[1][0] = o4 / norm;
m_coeff[1][3] = m_coeff[1][1] = 4 * o4 / norm;
m_coeff[1][2] = 6 * o4 / norm;
}
AUD_ButterworthReader::~AUD_ButterworthReader()
{
delete m_buffer; AUD_DELETE("buffer")
delete m_outvalues; AUD_DELETE("buffer")
delete m_invalues; AUD_DELETE("buffer");
}
void AUD_ButterworthReader::read(int & length, sample_t* & buffer)
{
sample_t* buf;
sample_t* outvalues;
sample_t* invalues;
outvalues = m_outvalues->getBuffer();
invalues = m_invalues->getBuffer();
AUD_Specs specs = m_reader->getSpecs();
m_reader->read(length, buf);
if(m_buffer->getSize() < length * AUD_SAMPLE_SIZE(specs))
m_buffer->resize(length * AUD_SAMPLE_SIZE(specs));
buffer = m_buffer->getBuffer();
int channels = specs.channels;
for(int channel = 0; channel < channels; channel++)
{
for(int i = 0; i < length; i++)
{
invalues[m_position * CC] = buf[i * CC];
outvalues[m_position * CC] = 0;
for(int j = 0; j < 4; j++)
{
outvalues[m_position * CC] += m_coeff[1][j] *
invalues[((m_position + j) % 5) * CC] -
m_coeff[0][j] *
outvalues[((m_position + j) % 5) * CC];
}
buffer[i * CC] = outvalues[m_position * CC];
m_position = (m_position + 4) % 5;
}
}
}

View File

@@ -0,0 +1,83 @@
/*
* $Id: AUD_ButterworthReader.h 25643 2010-01-01 05:09:30Z nexyon $
*
* ***** BEGIN LGPL LICENSE BLOCK *****
*
* Copyright 2009 Jörg Hermann Müller
*
* This file is part of AudaSpace.
*
* AudaSpace 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 3 of the License, or
* (at your option) any later version.
*
* AudaSpace 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 AudaSpace. If not, see <http://www.gnu.org/licenses/>.
*
* ***** END LGPL LICENSE BLOCK *****
*/
#ifndef AUD_BUTTERWORTHREADER
#define AUD_BUTTERWORTHREADER
#include "AUD_EffectReader.h"
class AUD_Buffer;
/**
* This class represents a butterworth filter.
*/
class AUD_ButterworthReader : public AUD_EffectReader
{
private:
/**
* The playback buffer.
*/
AUD_Buffer *m_buffer;
/**
* The last out values buffer.
*/
AUD_Buffer *m_outvalues;
/**
* The last in values buffer.
*/
AUD_Buffer *m_invalues;
/**
* The position for buffer cycling.
*/
int m_position;
/**
* Filter coefficients.
*/
float m_coeff[2][5];
public:
/**
* Creates a new butterworth reader.
* \param reader The reader to read from.
* \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.
* \exception AUD_Exception Thrown if the reader specified is NULL.
*/
AUD_ButterworthReader(AUD_IReader* reader, float frequency);
/**
* Destroys the reader.
*/
virtual ~AUD_ButterworthReader();
virtual void read(int & length, sample_t* & buffer);
};
#endif //AUD_BUTTERWORTHREADER

View File

@@ -0,0 +1,58 @@
/*
* $Id: AUD_EnvelopeFactory.cpp 25643 2010-01-01 05:09:30Z nexyon $
*
* ***** BEGIN LGPL LICENSE BLOCK *****
*
* Copyright 2009 Jörg Hermann Müller
*
* This file is part of AudaSpace.
*
* AudaSpace 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 3 of the License, or
* (at your option) any later version.
*
* AudaSpace 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 AudaSpace. If not, see <http://www.gnu.org/licenses/>.
*
* ***** END LGPL LICENSE BLOCK *****
*/
#include "AUD_EnvelopeFactory.h"
#include "AUD_EnvelopeReader.h"
AUD_EnvelopeFactory::AUD_EnvelopeFactory(AUD_IFactory* factory, float attack,
float release, float threshold,
float arthreshold) :
AUD_EffectFactory(factory),
m_attack(attack),
m_release(release),
m_threshold(threshold),
m_arthreshold(arthreshold) {}
AUD_EnvelopeFactory::AUD_EnvelopeFactory(float attack, float release,
float threshold, float arthreshold) :
AUD_EffectFactory(0),
m_attack(attack),
m_release(release),
m_threshold(threshold),
m_arthreshold(arthreshold) {}
AUD_IReader* AUD_EnvelopeFactory::createReader()
{
AUD_IReader* reader = getReader();
if(reader != 0)
{
reader = new AUD_EnvelopeReader(reader, m_attack, m_release,
m_threshold, m_arthreshold);
AUD_NEW("reader")
}
return reader;
}

View File

@@ -0,0 +1,82 @@
/*
* $Id: AUD_EnvelopeFactory.h 25643 2010-01-01 05:09:30Z nexyon $
*
* ***** BEGIN LGPL LICENSE BLOCK *****
*
* Copyright 2009 Jörg Hermann Müller
*
* This file is part of AudaSpace.
*
* AudaSpace 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 3 of the License, or
* (at your option) any later version.
*
* AudaSpace 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 AudaSpace. If not, see <http://www.gnu.org/licenses/>.
*
* ***** END LGPL LICENSE BLOCK *****
*/
#ifndef AUD_ENVELOPEFACTORY
#define AUD_ENVELOPEFACTORY
#include "AUD_EffectFactory.h"
/**
* This factory creates an envelope follower reader.
*/
class AUD_EnvelopeFactory : public AUD_EffectFactory
{
private:
/**
* The attack value in seconds.
*/
float m_attack;
/**
* The release value in seconds.
*/
float m_release;
/**
* The threshold value.
*/
float m_threshold;
/**
* The attack/release threshold value.
*/
float m_arthreshold;
public:
/**
* Creates a new envelope factory.
* \param factory The input factory.
* \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.
*/
AUD_EnvelopeFactory(AUD_IFactory* factory, float attack, float release,
float threshold, float arthreshold);
/**
* Creates a new envelope factory.
* \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.
*/
AUD_EnvelopeFactory(float attack, float release, float threshold,
float arthreshold);
virtual AUD_IReader* createReader();
};
#endif //AUD_ENVELOPEFACTORY

View File

@@ -0,0 +1,86 @@
/*
* $Id: AUD_EnvelopeReader.cpp 25646 2010-01-01 11:55:56Z nexyon $
*
* ***** BEGIN LGPL LICENSE BLOCK *****
*
* Copyright 2009 Jörg Hermann Müller
*
* This file is part of AudaSpace.
*
* AudaSpace 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 3 of the License, or
* (at your option) any later version.
*
* AudaSpace 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 AudaSpace. If not, see <http://www.gnu.org/licenses/>.
*
* ***** END LGPL LICENSE BLOCK *****
*/
#include "AUD_EnvelopeReader.h"
#include "AUD_Buffer.h"
#include <cstring>
#include <cmath>
AUD_EnvelopeReader::AUD_EnvelopeReader(AUD_IReader* reader, float attack,
float release, float threshold,
float arthreshold) :
AUD_EffectReader(reader),
m_threshold(threshold)
{
AUD_Specs specs = reader->getSpecs();
int samplesize = AUD_SAMPLE_SIZE(specs);
m_buffer = new AUD_Buffer(); AUD_NEW("buffer")
m_envelopes = new AUD_Buffer(samplesize);
AUD_NEW("buffer")
memset(m_envelopes->getBuffer(), 0, samplesize);
m_bAttack = pow(arthreshold, 1.0f/(specs.rate * attack));
m_bRelease = pow(arthreshold, 1.0f/(specs.rate * release));
}
AUD_EnvelopeReader::~AUD_EnvelopeReader()
{
delete m_buffer; AUD_DELETE("buffer")
delete m_envelopes; AUD_DELETE("buffer")
}
void AUD_EnvelopeReader::read(int & length, sample_t* & buffer)
{
sample_t* buf;
sample_t* envelopes;
envelopes = m_envelopes->getBuffer();
AUD_Specs specs = m_reader->getSpecs();
m_reader->read(length, buf);
if(m_buffer->getSize() < length * AUD_SAMPLE_SIZE(specs))
m_buffer->resize(length * AUD_SAMPLE_SIZE(specs));
buffer = m_buffer->getBuffer();
sample_t value;
for(int channel = 0; channel < specs.channels; channel++)
{
for(int i = 0; i < length; i++)
{
value = fabs(buf[i * specs.channels + channel]);
if(value < m_threshold)
value = 0.0f;
buffer[i * specs.channels + channel] = envelopes[channel] =
((value > envelopes[channel]) ? m_bAttack : m_bRelease) *
(envelopes[channel] - value) + value;
}
}
}

View File

@@ -0,0 +1,84 @@
/*
* $Id: AUD_EnvelopeReader.h 25643 2010-01-01 05:09:30Z nexyon $
*
* ***** BEGIN LGPL LICENSE BLOCK *****
*
* Copyright 2009 Jörg Hermann Müller
*
* This file is part of AudaSpace.
*
* AudaSpace 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 3 of the License, or
* (at your option) any later version.
*
* AudaSpace 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 AudaSpace. If not, see <http://www.gnu.org/licenses/>.
*
* ***** END LGPL LICENSE BLOCK *****
*/
#ifndef AUD_ENVELOPEREADER
#define AUD_ENVELOPEREADER
#include "AUD_EffectReader.h"
class AUD_Buffer;
/**
* This class represents an envelope follower.
*/
class AUD_EnvelopeReader : public AUD_EffectReader
{
private:
/**
* The playback buffer.
*/
AUD_Buffer *m_buffer;
/**
* The last envelopes buffer.
*/
AUD_Buffer *m_envelopes;
/**
* Attack b value.
*/
float m_bAttack;
/**
* Release b value.
*/
float m_bRelease;
/**
* Threshold value.
*/
float m_threshold;
public:
/**
* Creates a new envelope reader.
* \param reader The reader to read from.
* \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.
* \exception AUD_Exception Thrown if the reader specified is NULL.
*/
AUD_EnvelopeReader(AUD_IReader* reader, float attack, float release,
float threshold, float arthreshold);
/**
* Destroys the reader.
*/
virtual ~AUD_EnvelopeReader();
virtual void read(int & length, sample_t* & buffer);
};
#endif //AUD_ENVELOPEREADER

View File

@@ -0,0 +1,51 @@
/*
* $Id: AUD_HighpassFactory.cpp 25643 2010-01-01 05:09:30Z nexyon $
*
* ***** BEGIN LGPL LICENSE BLOCK *****
*
* Copyright 2009 Jörg Hermann Müller
*
* This file is part of AudaSpace.
*
* AudaSpace 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 3 of the License, or
* (at your option) any later version.
*
* AudaSpace 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 AudaSpace. If not, see <http://www.gnu.org/licenses/>.
*
* ***** END LGPL LICENSE BLOCK *****
*/
#include "AUD_HighpassFactory.h"
#include "AUD_HighpassReader.h"
AUD_HighpassFactory::AUD_HighpassFactory(AUD_IFactory* factory, float frequency,
float Q) :
AUD_EffectFactory(factory),
m_frequency(frequency),
m_Q(Q) {}
AUD_HighpassFactory::AUD_HighpassFactory(float frequency, float Q) :
AUD_EffectFactory(0),
m_frequency(frequency),
m_Q(Q) {}
AUD_IReader* AUD_HighpassFactory::createReader()
{
AUD_IReader* reader = getReader();
if(reader != 0)
{
reader = new AUD_HighpassReader(reader, m_frequency, m_Q);
AUD_NEW("reader")
}
return reader;
}

View File

@@ -0,0 +1,66 @@
/*
* $Id: AUD_HighpassFactory.h 25646 2010-01-01 11:55:56Z nexyon $
*
* ***** BEGIN LGPL LICENSE BLOCK *****
*
* Copyright 2009 Jörg Hermann Müller
*
* This file is part of AudaSpace.
*
* AudaSpace 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 3 of the License, or
* (at your option) any later version.
*
* AudaSpace 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 AudaSpace. If not, see <http://www.gnu.org/licenses/>.
*
* ***** END LGPL LICENSE BLOCK *****
*/
#ifndef AUD_HIGHPASSFACTORY
#define AUD_HIGHPASSFACTORY
#include "AUD_EffectFactory.h"
/**
* This factory creates a highpass filter reader.
*/
class AUD_HighpassFactory : public AUD_EffectFactory
{
private:
/**
* The attack value in seconds.
*/
float m_frequency;
/**
* The Q factor.
*/
float m_Q;
public:
/**
* Creates a new highpass factory.
* \param factory The input factory.
* \param frequency The cutoff frequency.
* \param Q The Q factor.
*/
AUD_HighpassFactory(AUD_IFactory* factory, float frequency, float Q = 1.0f);
/**
* Creates a new highpass factory.
* \param frequency The cutoff frequency.
* \param Q The Q factor.
*/
AUD_HighpassFactory(float frequency, float Q = 1.0f);
virtual AUD_IReader* createReader();
};
#endif //AUD_HIGHPASSFACTORY

View File

@@ -0,0 +1,116 @@
/*
* $Id: AUD_HighpassReader.cpp 25646 2010-01-01 11:55:56Z nexyon $
*
* ***** BEGIN LGPL LICENSE BLOCK *****
*
* Copyright 2009 Jörg Hermann Müller
*
* This file is part of AudaSpace.
*
* AudaSpace 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 3 of the License, or
* (at your option) any later version.
*
* AudaSpace 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 AudaSpace. If not, see <http://www.gnu.org/licenses/>.
*
* ***** END LGPL LICENSE BLOCK *****
*/
#include "AUD_HighpassReader.h"
#include "AUD_Buffer.h"
#include <cstring>
#include <cmath>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#define CC channels + channel
AUD_HighpassReader::AUD_HighpassReader(AUD_IReader* reader, float frequency,
float Q) :
AUD_EffectReader(reader)
{
AUD_Specs specs = reader->getSpecs();
int samplesize = AUD_SAMPLE_SIZE(specs);
m_buffer = new AUD_Buffer(); AUD_NEW("buffer")
m_outvalues = new AUD_Buffer(samplesize * AUD_HIGHPASS_ORDER);
AUD_NEW("buffer")
memset(m_outvalues->getBuffer(), 0, samplesize * AUD_HIGHPASS_ORDER);
m_invalues = new AUD_Buffer(samplesize * AUD_HIGHPASS_ORDER);
AUD_NEW("buffer")
memset(m_invalues->getBuffer(), 0, samplesize * AUD_HIGHPASS_ORDER);
m_position = 0;
// calculate coefficients
float w0 = 2 * M_PI * frequency / specs.rate;
float alpha = sin(w0) / (2 * Q);
float norm = 1 + alpha;
m_coeff[0][0] = 0;
m_coeff[0][1] = -2 * cos(w0) / norm;
m_coeff[0][2] = (1 - alpha) / norm;
m_coeff[1][2] = m_coeff[1][0] = (1 + cos(w0)) / (2 * norm);
m_coeff[1][1] = (-1 - cos(w0)) / norm;
}
AUD_HighpassReader::~AUD_HighpassReader()
{
delete m_buffer; AUD_DELETE("buffer")
delete m_outvalues; AUD_DELETE("buffer")
delete m_invalues; AUD_DELETE("buffer");
}
void AUD_HighpassReader::read(int & length, sample_t* & buffer)
{
sample_t* buf;
sample_t* outvalues;
sample_t* invalues;
outvalues = m_outvalues->getBuffer();
invalues = m_invalues->getBuffer();
AUD_Specs specs = m_reader->getSpecs();
m_reader->read(length, buf);
if(m_buffer->getSize() < length * AUD_SAMPLE_SIZE(specs))
m_buffer->resize(length * AUD_SAMPLE_SIZE(specs));
buffer = m_buffer->getBuffer();
int channels = specs.channels;
for(int channel = 0; channel < channels; channel++)
{
for(int i = 0; i < length; i++)
{
invalues[m_position * CC] = buf[i * CC];
outvalues[m_position * CC] = 0;
for(int j = 0; j < AUD_HIGHPASS_ORDER; j++)
{
outvalues[m_position * CC] += m_coeff[1][j] *
invalues[((m_position + j) % AUD_HIGHPASS_ORDER) * CC] -
m_coeff[0][j] *
outvalues[((m_position + j) % AUD_HIGHPASS_ORDER) * CC];
}
buffer[i * CC] = outvalues[m_position * CC];
m_position = (m_position + AUD_HIGHPASS_ORDER-1) %
AUD_HIGHPASS_ORDER;
}
}
}

View File

@@ -0,0 +1,83 @@
/*
* $Id: AUD_HighpassReader.h 25643 2010-01-01 05:09:30Z nexyon $
*
* ***** BEGIN LGPL LICENSE BLOCK *****
*
* Copyright 2009 Jörg Hermann Müller
*
* This file is part of AudaSpace.
*
* AudaSpace 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 3 of the License, or
* (at your option) any later version.
*
* AudaSpace 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 AudaSpace. If not, see <http://www.gnu.org/licenses/>.
*
* ***** END LGPL LICENSE BLOCK *****
*/
#ifndef AUD_HIGHPASSREADER
#define AUD_HIGHPASSREADER
#include "AUD_EffectReader.h"
class AUD_Buffer;
#define AUD_HIGHPASS_ORDER 3
/**
* This class represents a highpass filter.
*/
class AUD_HighpassReader : public AUD_EffectReader
{
private:
/**
* The playback buffer.
*/
AUD_Buffer *m_buffer;
/**
* The last out values buffer.
*/
AUD_Buffer *m_outvalues;
/**
* The last in values buffer.
*/
AUD_Buffer *m_invalues;
/**
* The position for buffer cycling.
*/
int m_position;
/**
* Filter coefficients.
*/
float m_coeff[2][AUD_HIGHPASS_ORDER];
public:
/**
* Creates a new highpass reader.
* \param reader The reader to read from.
* \param frequency The cutoff frequency.
* \param Q The Q factor.
* \exception AUD_Exception Thrown if the reader specified is NULL.
*/
AUD_HighpassReader(AUD_IReader* reader, float frequency, float Q);
/**
* Destroys the reader.
*/
virtual ~AUD_HighpassReader();
virtual void read(int & length, sample_t* & buffer);
};
#endif //AUD_HIGHPASSREADER

View File

@@ -0,0 +1,51 @@
/*
* $Id: AUD_LowpassFactory.cpp 25643 2010-01-01 05:09:30Z nexyon $
*
* ***** BEGIN LGPL LICENSE BLOCK *****
*
* Copyright 2009 Jörg Hermann Müller
*
* This file is part of AudaSpace.
*
* AudaSpace 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 3 of the License, or
* (at your option) any later version.
*
* AudaSpace 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 AudaSpace. If not, see <http://www.gnu.org/licenses/>.
*
* ***** END LGPL LICENSE BLOCK *****
*/
#include "AUD_LowpassFactory.h"
#include "AUD_LowpassReader.h"
AUD_LowpassFactory::AUD_LowpassFactory(AUD_IFactory* factory, float frequency,
float Q) :
AUD_EffectFactory(factory),
m_frequency(frequency),
m_Q(Q) {}
AUD_LowpassFactory::AUD_LowpassFactory(float frequency, float Q) :
AUD_EffectFactory(0),
m_frequency(frequency),
m_Q(Q) {}
AUD_IReader* AUD_LowpassFactory::createReader()
{
AUD_IReader* reader = getReader();
if(reader != 0)
{
reader = new AUD_LowpassReader(reader, m_frequency, m_Q);
AUD_NEW("reader")
}
return reader;
}

View File

@@ -0,0 +1,66 @@
/*
* $Id: AUD_LowpassFactory.h 25646 2010-01-01 11:55:56Z nexyon $
*
* ***** BEGIN LGPL LICENSE BLOCK *****
*
* Copyright 2009 Jörg Hermann Müller
*
* This file is part of AudaSpace.
*
* AudaSpace 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 3 of the License, or
* (at your option) any later version.
*
* AudaSpace 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 AudaSpace. If not, see <http://www.gnu.org/licenses/>.
*
* ***** END LGPL LICENSE BLOCK *****
*/
#ifndef AUD_LOWPASSFACTORY
#define AUD_LOWPASSFACTORY
#include "AUD_EffectFactory.h"
/**
* This factory creates a lowpass filter reader.
*/
class AUD_LowpassFactory : public AUD_EffectFactory
{
private:
/**
* The attack value in seconds.
*/
float m_frequency;
/**
* The Q factor.
*/
float m_Q;
public:
/**
* Creates a new lowpass factory.
* \param factory The input factory.
* \param frequency The cutoff frequency.
* \param Q The Q factor.
*/
AUD_LowpassFactory(AUD_IFactory* factory, float frequency, float Q = 1.0f);
/**
* Creates a new lowpass factory.
* \param frequency The cutoff frequency.
* \param Q The Q factor.
*/
AUD_LowpassFactory(float frequency, float Q = 1.0f);
virtual AUD_IReader* createReader();
};
#endif //AUD_LOWPASSFACTORY

View File

@@ -0,0 +1,115 @@
/*
* $Id: AUD_LowpassReader.cpp 25646 2010-01-01 11:55:56Z nexyon $
*
* ***** BEGIN LGPL LICENSE BLOCK *****
*
* Copyright 2009 Jörg Hermann Müller
*
* This file is part of AudaSpace.
*
* AudaSpace 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 3 of the License, or
* (at your option) any later version.
*
* AudaSpace 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 AudaSpace. If not, see <http://www.gnu.org/licenses/>.
*
* ***** END LGPL LICENSE BLOCK *****
*/
#include "AUD_LowpassReader.h"
#include "AUD_Buffer.h"
#include <cstring>
#include <cmath>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#define CC channels + channel
AUD_LowpassReader::AUD_LowpassReader(AUD_IReader* reader, float frequency,
float Q) :
AUD_EffectReader(reader)
{
AUD_Specs specs = reader->getSpecs();
int samplesize = AUD_SAMPLE_SIZE(specs);
m_buffer = new AUD_Buffer(); AUD_NEW("buffer")
m_outvalues = new AUD_Buffer(samplesize * AUD_LOWPASS_ORDER);
AUD_NEW("buffer")
memset(m_outvalues->getBuffer(), 0, samplesize * AUD_LOWPASS_ORDER);
m_invalues = new AUD_Buffer(samplesize * AUD_LOWPASS_ORDER);
AUD_NEW("buffer")
memset(m_invalues->getBuffer(), 0, samplesize * AUD_LOWPASS_ORDER);
m_position = 0;
// calculate coefficients
float w0 = 2 * M_PI * frequency / specs.rate;
float alpha = sin(w0) / (2 * Q);
float norm = 1 + alpha;
m_coeff[0][0] = 0;
m_coeff[0][1] = -2 * cos(w0) / norm;
m_coeff[0][2] = (1 - alpha) / norm;
m_coeff[1][2] = m_coeff[1][0] = (1 - cos(w0)) / (2 * norm);
m_coeff[1][1] = (1 - cos(w0)) / norm;
}
AUD_LowpassReader::~AUD_LowpassReader()
{
delete m_buffer; AUD_DELETE("buffer")
delete m_outvalues; AUD_DELETE("buffer")
delete m_invalues; AUD_DELETE("buffer");
}
void AUD_LowpassReader::read(int & length, sample_t* & buffer)
{
sample_t* buf;
sample_t* outvalues;
sample_t* invalues;
outvalues = m_outvalues->getBuffer();
invalues = m_invalues->getBuffer();
AUD_Specs specs = m_reader->getSpecs();
m_reader->read(length, buf);
if(m_buffer->getSize() < length * AUD_SAMPLE_SIZE(specs))
m_buffer->resize(length * AUD_SAMPLE_SIZE(specs));
buffer = m_buffer->getBuffer();
int channels = specs.channels;
for(int channel = 0; channel < channels; channel++)
{
for(int i = 0; i < length; i++)
{
invalues[m_position * CC] = buf[i * CC];
outvalues[m_position * CC] = 0;
for(int j = 0; j < AUD_LOWPASS_ORDER; j++)
{
outvalues[m_position * CC] += m_coeff[1][j] *
invalues[((m_position + j) % AUD_LOWPASS_ORDER) * CC] -
m_coeff[0][j] *
outvalues[((m_position + j) % AUD_LOWPASS_ORDER) * CC];
}
buffer[i * CC] = outvalues[m_position * CC];
m_position = (m_position + AUD_LOWPASS_ORDER-1) % AUD_LOWPASS_ORDER;
}
}
}

View File

@@ -0,0 +1,83 @@
/*
* $Id: AUD_LowpassReader.h 25643 2010-01-01 05:09:30Z nexyon $
*
* ***** BEGIN LGPL LICENSE BLOCK *****
*
* Copyright 2009 Jörg Hermann Müller
*
* This file is part of AudaSpace.
*
* AudaSpace 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 3 of the License, or
* (at your option) any later version.
*
* AudaSpace 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 AudaSpace. If not, see <http://www.gnu.org/licenses/>.
*
* ***** END LGPL LICENSE BLOCK *****
*/
#ifndef AUD_LOWPASSREADER
#define AUD_LOWPASSREADER
#include "AUD_EffectReader.h"
class AUD_Buffer;
#define AUD_LOWPASS_ORDER 3
/**
* This class represents a lowpass filter.
*/
class AUD_LowpassReader : public AUD_EffectReader
{
private:
/**
* The playback buffer.
*/
AUD_Buffer *m_buffer;
/**
* The last out values buffer.
*/
AUD_Buffer *m_outvalues;
/**
* The last in values buffer.
*/
AUD_Buffer *m_invalues;
/**
* The position for buffer cycling.
*/
int m_position;
/**
* Filter coefficients.
*/
float m_coeff[2][AUD_LOWPASS_ORDER];
public:
/**
* Creates a new lowpass reader.
* \param reader The reader to read from.
* \param frequency The cutoff frequency.
* \param Q The Q factor.
* \exception AUD_Exception Thrown if the reader specified is NULL.
*/
AUD_LowpassReader(AUD_IReader* reader, float frequency, float Q);
/**
* Destroys the reader.
*/
virtual ~AUD_LowpassReader();
virtual void read(int & length, sample_t* & buffer);
};
#endif //AUD_LOWPASSREADER

View File

@@ -0,0 +1,57 @@
/*
* $Id: AUD_SquareFactory.cpp 25656 2010-01-01 18:45:21Z nexyon $
*
* ***** BEGIN LGPL LICENSE BLOCK *****
*
* Copyright 2009 Jörg Hermann Müller
*
* This file is part of AudaSpace.
*
* AudaSpace 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 3 of the License, or
* (at your option) any later version.
*
* AudaSpace 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 AudaSpace. If not, see <http://www.gnu.org/licenses/>.
*
* ***** END LGPL LICENSE BLOCK *****
*/
#include "AUD_SquareFactory.h"
#include "AUD_SquareReader.h"
AUD_SquareFactory::AUD_SquareFactory(AUD_IFactory* factory, float threshold) :
AUD_EffectFactory(factory),
m_threshold(threshold) {}
AUD_SquareFactory::AUD_SquareFactory(float threshold) :
AUD_EffectFactory(0),
m_threshold(threshold) {}
float AUD_SquareFactory::getThreshold()
{
return m_threshold;
}
void AUD_SquareFactory::setThreshold(float threshold)
{
m_threshold = threshold;
}
AUD_IReader* AUD_SquareFactory::createReader()
{
AUD_IReader* reader = getReader();
if(reader != 0)
{
reader = new AUD_SquareReader(reader, m_threshold); AUD_NEW("reader")
}
return reader;
}

View File

@@ -0,0 +1,70 @@
/*
* $Id: AUD_SquareFactory.h 25656 2010-01-01 18:45:21Z nexyon $
*
* ***** BEGIN LGPL LICENSE BLOCK *****
*
* Copyright 2009 Jörg Hermann Müller
*
* This file is part of AudaSpace.
*
* AudaSpace 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 3 of the License, or
* (at your option) any later version.
*
* AudaSpace 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 AudaSpace. If not, see <http://www.gnu.org/licenses/>.
*
* ***** END LGPL LICENSE BLOCK *****
*/
#ifndef AUD_SQUAREFACTORY
#define AUD_SQUAREFACTORY
#include "AUD_EffectFactory.h"
/**
* This factory Transforms any signal to a square signal.
*/
class AUD_SquareFactory : public AUD_EffectFactory
{
private:
/**
* The threshold.
*/
float m_threshold;
public:
/**
* Creates a new square factory.
* \param factory The input factory.
* \param threshold The threshold.
*/
AUD_SquareFactory(AUD_IFactory* factory = 0, float threshold = 0.0f);
/**
* Creates a new square factory.
* \param threshold The threshold.
*/
AUD_SquareFactory(float threshold);
/**
* Returns the threshold.
*/
float getThreshold();
/**
* Sets the threshold.
* \param threshold The new threshold value. Should be between 0.0 and 1.0.
*/
void setThreshold(float threshold);
virtual AUD_IReader* createReader();
};
#endif //AUD_SQUAREFACTORY

View File

@@ -0,0 +1,63 @@
/*
* $Id: AUD_SquareReader.cpp 25656 2010-01-01 18:45:21Z nexyon $
*
* ***** BEGIN LGPL LICENSE BLOCK *****
*
* Copyright 2009 Jörg Hermann Müller
*
* This file is part of AudaSpace.
*
* AudaSpace 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 3 of the License, or
* (at your option) any later version.
*
* AudaSpace 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 AudaSpace. If not, see <http://www.gnu.org/licenses/>.
*
* ***** END LGPL LICENSE BLOCK *****
*/
#include "AUD_SquareReader.h"
#include "AUD_Buffer.h"
#include <cstring>
AUD_SquareReader::AUD_SquareReader(AUD_IReader* reader, float threshold) :
AUD_EffectReader(reader),
m_threshold(threshold)
{
m_buffer = new AUD_Buffer(); AUD_NEW("buffer")
}
AUD_SquareReader::~AUD_SquareReader()
{
delete m_buffer; AUD_DELETE("buffer")
}
void AUD_SquareReader::read(int & length, sample_t* & buffer)
{
sample_t* buf;
AUD_Specs specs = m_reader->getSpecs();
m_reader->read(length, buf);
if(m_buffer->getSize() < length * AUD_SAMPLE_SIZE(specs))
m_buffer->resize(length * AUD_SAMPLE_SIZE(specs));
buffer = m_buffer->getBuffer();
for(int i = 0; i < length * specs.channels; i++)
{
if(buf[i] >= m_threshold)
buffer[i] = 1.0f;
else if(buf[i] <= -m_threshold)
buffer[i] = -1.0f;
else
buffer[i] = 0.0f;
}
}

View File

@@ -0,0 +1,65 @@
/*
* $Id: AUD_SquareReader.h 25656 2010-01-01 18:45:21Z nexyon $
*
* ***** BEGIN LGPL LICENSE BLOCK *****
*
* Copyright 2009 Jörg Hermann Müller
*
* This file is part of AudaSpace.
*
* AudaSpace 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 3 of the License, or
* (at your option) any later version.
*
* AudaSpace 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 AudaSpace. If not, see <http://www.gnu.org/licenses/>.
*
* ***** END LGPL LICENSE BLOCK *****
*/
#ifndef AUD_SQUAREREADER
#define AUD_SQUAREREADER
#include "AUD_EffectReader.h"
class AUD_Buffer;
/**
* This class changes another signal into a square signal.
*/
class AUD_SquareReader : public AUD_EffectReader
{
private:
/**
* The playback buffer.
*/
AUD_Buffer *m_buffer;
/**
* The threshold level.
*/
float m_threshold;
public:
/**
* Creates a new square reader.
* \param reader The reader to read from.
* \param threshold The size of the buffer.
* \exception AUD_Exception Thrown if the reader specified is NULL.
*/
AUD_SquareReader(AUD_IReader* reader, float threshold);
/**
* Destroys the reader.
*/
virtual ~AUD_SquareReader();
virtual void read(int & length, sample_t* & buffer);
};
#endif //AUD_SQUAREREADER

View File

@@ -0,0 +1,43 @@
/*
* $Id: AUD_SumFactory.cpp 25656 2010-01-01 18:45:21Z nexyon $
*
* ***** BEGIN LGPL LICENSE BLOCK *****
*
* Copyright 2009 Jörg Hermann Müller
*
* This file is part of AudaSpace.
*
* AudaSpace 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 3 of the License, or
* (at your option) any later version.
*
* AudaSpace 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 AudaSpace. If not, see <http://www.gnu.org/licenses/>.
*
* ***** END LGPL LICENSE BLOCK *****
*/
#include "AUD_SumFactory.h"
#include "AUD_SumReader.h"
AUD_SumFactory::AUD_SumFactory(AUD_IFactory* factory) :
AUD_EffectFactory(factory) {}
AUD_IReader* AUD_SumFactory::createReader()
{
AUD_IReader* reader = getReader();
if(reader != 0)
{
reader = new AUD_SumReader(reader);
AUD_NEW("reader")
}
return reader;
}

View File

@@ -0,0 +1,46 @@
/*
* $Id: AUD_SumFactory.h 25656 2010-01-01 18:45:21Z nexyon $
*
* ***** BEGIN LGPL LICENSE BLOCK *****
*
* Copyright 2009 Jörg Hermann Müller
*
* This file is part of AudaSpace.
*
* AudaSpace 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 3 of the License, or
* (at your option) any later version.
*
* AudaSpace 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 AudaSpace. If not, see <http://www.gnu.org/licenses/>.
*
* ***** END LGPL LICENSE BLOCK *****
*/
#ifndef AUD_SUMFACTORY
#define AUD_SUMFACTORY
#include "AUD_EffectFactory.h"
/**
* This factory creates a sum reader.
*/
class AUD_SumFactory : public AUD_EffectFactory
{
public:
/**
* Creates a new sum factory.
* \param factory The input factory.
*/
AUD_SumFactory(AUD_IFactory* factory = 0);
virtual AUD_IReader* createReader();
};
#endif //AUD_SUMFACTORY

View File

@@ -0,0 +1,68 @@
/*
* $Id: AUD_SumReader.cpp 25656 2010-01-01 18:45:21Z nexyon $
*
* ***** BEGIN LGPL LICENSE BLOCK *****
*
* Copyright 2009 Jörg Hermann Müller
*
* This file is part of AudaSpace.
*
* AudaSpace 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 3 of the License, or
* (at your option) any later version.
*
* AudaSpace 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 AudaSpace. If not, see <http://www.gnu.org/licenses/>.
*
* ***** END LGPL LICENSE BLOCK *****
*/
#include "AUD_SumReader.h"
#include "AUD_Buffer.h"
#include <cstring>
#define CC specs.channels + channel
AUD_SumReader::AUD_SumReader(AUD_IReader* reader) :
AUD_EffectReader(reader)
{
AUD_Specs specs = reader->getSpecs();
int samplesize = AUD_SAMPLE_SIZE(specs);
m_buffer = new AUD_Buffer(); AUD_NEW("buffer")
m_sums = new AUD_Buffer(samplesize); AUD_NEW("buffer")
memset(m_sums->getBuffer(), 0, samplesize);
}
AUD_SumReader::~AUD_SumReader()
{
delete m_buffer; AUD_DELETE("buffer")
delete m_sums; AUD_DELETE("buffer")
}
void AUD_SumReader::read(int & length, sample_t* & buffer)
{
sample_t* buf;
sample_t* sums;
sums = m_sums->getBuffer();
AUD_Specs specs = m_reader->getSpecs();
m_reader->read(length, buf);
if(m_buffer->getSize() < length * AUD_SAMPLE_SIZE(specs))
m_buffer->resize(length * AUD_SAMPLE_SIZE(specs));
buffer = m_buffer->getBuffer();
for(int channel = 0; channel < specs.channels; channel++)
for(int i = 0; i < length * specs.channels; i++)
buffer[i * CC] = sums[channel] = sums[channel] + buf[i * CC];
}

View File

@@ -0,0 +1,64 @@
/*
* $Id: AUD_SumReader.h 25656 2010-01-01 18:45:21Z nexyon $
*
* ***** BEGIN LGPL LICENSE BLOCK *****
*
* Copyright 2009 Jörg Hermann Müller
*
* This file is part of AudaSpace.
*
* AudaSpace 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 3 of the License, or
* (at your option) any later version.
*
* AudaSpace 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 AudaSpace. If not, see <http://www.gnu.org/licenses/>.
*
* ***** END LGPL LICENSE BLOCK *****
*/
#ifndef AUD_SUMREADER
#define AUD_SUMREADER
#include "AUD_EffectReader.h"
class AUD_Buffer;
/**
* This class represents an summer.
*/
class AUD_SumReader : public AUD_EffectReader
{
private:
/**
* The playback buffer.
*/
AUD_Buffer *m_buffer;
/**
* The sums of the specific channels.
*/
AUD_Buffer *m_sums;
public:
/**
* Creates a new sum reader.
* \param reader The reader to read from.
* \exception AUD_Exception Thrown if the reader specified is NULL.
*/
AUD_SumReader(AUD_IReader* reader);
/**
* Destroys the reader.
*/
virtual ~AUD_SumReader();
virtual void read(int & length, sample_t* & buffer);
};
#endif //AUD_SUMREADER