forked from bartvdbraak/blender
Added another three effects that you can use with the Sound to F-Curve modifier, have fun!
This commit is contained in:
parent
d0ec3f428c
commit
637873deb0
49
intern/audaspace/FX/AUD_AccumulatorFactory.cpp
Normal file
49
intern/audaspace/FX/AUD_AccumulatorFactory.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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;
|
||||
}
|
59
intern/audaspace/FX/AUD_AccumulatorFactory.h
Normal file
59
intern/audaspace/FX/AUD_AccumulatorFactory.h
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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
|
99
intern/audaspace/FX/AUD_AccumulatorReader.cpp
Normal file
99
intern/audaspace/FX/AUD_AccumulatorReader.cpp
Normal file
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
75
intern/audaspace/FX/AUD_AccumulatorReader.h
Normal file
75
intern/audaspace/FX/AUD_AccumulatorReader.h
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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
|
57
intern/audaspace/FX/AUD_SquareFactory.cpp
Normal file
57
intern/audaspace/FX/AUD_SquareFactory.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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;
|
||||
}
|
70
intern/audaspace/FX/AUD_SquareFactory.h
Normal file
70
intern/audaspace/FX/AUD_SquareFactory.h
Normal file
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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
|
63
intern/audaspace/FX/AUD_SquareReader.cpp
Normal file
63
intern/audaspace/FX/AUD_SquareReader.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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;
|
||||
}
|
||||
}
|
65
intern/audaspace/FX/AUD_SquareReader.h
Normal file
65
intern/audaspace/FX/AUD_SquareReader.h
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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
|
43
intern/audaspace/FX/AUD_SumFactory.cpp
Normal file
43
intern/audaspace/FX/AUD_SumFactory.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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;
|
||||
}
|
46
intern/audaspace/FX/AUD_SumFactory.h
Normal file
46
intern/audaspace/FX/AUD_SumFactory.h
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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
|
68
intern/audaspace/FX/AUD_SumReader.cpp
Normal file
68
intern/audaspace/FX/AUD_SumReader.cpp
Normal file
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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];
|
||||
}
|
64
intern/audaspace/FX/AUD_SumReader.h
Normal file
64
intern/audaspace/FX/AUD_SumReader.h
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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
|
@ -39,6 +39,9 @@
|
||||
#include "AUD_LinearResampleFactory.h"
|
||||
#include "AUD_LowpassFactory.h"
|
||||
#include "AUD_HighpassFactory.h"
|
||||
#include "AUD_AccumulatorFactory.h"
|
||||
#include "AUD_SumFactory.h"
|
||||
#include "AUD_SquareFactory.h"
|
||||
#include "AUD_ChannelMapperFactory.h"
|
||||
#include "AUD_Buffer.h"
|
||||
#include "AUD_ReadDevice.h"
|
||||
@ -611,12 +614,14 @@ void AUD_closeReadDevice(AUD_Device* device)
|
||||
|
||||
float* AUD_readSoundBuffer(const char* filename, float low, float high,
|
||||
float attack, float release, float threshold,
|
||||
int samplerate, int* length)
|
||||
int accumulate, int additive, int square,
|
||||
float sthreshold, int samplerate, int* length)
|
||||
{
|
||||
AUD_Buffer buffer;
|
||||
AUD_DeviceSpecs specs;
|
||||
specs.channels = AUD_CHANNELS_MONO;
|
||||
specs.rate = (AUD_SampleRate)samplerate;
|
||||
AUD_Sound* sound;
|
||||
|
||||
AUD_FileFactory file(filename);
|
||||
AUD_ChannelMapperFactory mapper(&file, specs);
|
||||
@ -624,8 +629,18 @@ float* AUD_readSoundBuffer(const char* filename, float low, float high,
|
||||
AUD_HighpassFactory highpass(&lowpass, low);
|
||||
AUD_EnvelopeFactory envelope(&highpass, attack, release, threshold, 0.1f);
|
||||
AUD_LinearResampleFactory resampler(&envelope, specs);
|
||||
sound = &resampler;
|
||||
AUD_SquareFactory squaref(sound, sthreshold);
|
||||
if(square)
|
||||
sound = &squaref;
|
||||
AUD_AccumulatorFactory accumulator(sound, additive);
|
||||
AUD_SumFactory sum(sound);
|
||||
if(accumulate)
|
||||
sound = &accumulator;
|
||||
else if(additive)
|
||||
sound = ∑
|
||||
|
||||
AUD_IReader* reader = resampler.createReader();
|
||||
AUD_IReader* reader = sound->createReader();
|
||||
|
||||
if(reader == NULL)
|
||||
return NULL;
|
||||
|
@ -356,7 +356,9 @@ extern void AUD_closeReadDevice(AUD_Device* device);
|
||||
*/
|
||||
extern float* AUD_readSoundBuffer(const char* filename, float low, float high,
|
||||
float attack, float release, float threshold,
|
||||
int samplerate, int* length);
|
||||
int accumulate, int additive, int square,
|
||||
float sthreshold, int samplerate,
|
||||
int* length);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -1052,6 +1052,10 @@ static int graphkeys_sound_bake_exec(bContext *C, wmOperator *op)
|
||||
RNA_float_get(op->ptr, "attack"),
|
||||
RNA_float_get(op->ptr, "release"),
|
||||
RNA_float_get(op->ptr, "threshold"),
|
||||
RNA_boolean_get(op->ptr, "accumulate"),
|
||||
RNA_boolean_get(op->ptr, "additive"),
|
||||
RNA_boolean_get(op->ptr, "square"),
|
||||
RNA_float_get(op->ptr, "sthreshold"),
|
||||
FPS, &sbi.length);
|
||||
|
||||
if (sbi.samples == NULL) {
|
||||
@ -1123,6 +1127,10 @@ void GRAPH_OT_sound_bake (wmOperatorType *ot)
|
||||
RNA_def_float(ot->srna, "attack", 0.005, 0.0, 2.0, "Attack time", "", 0.01, 0.1);
|
||||
RNA_def_float(ot->srna, "release", 0.2, 0.0, 5.0, "Release time", "", 0.01, 0.2);
|
||||
RNA_def_float(ot->srna, "threshold", 0.0, 0.0, 1.0, "Threshold", "", 0.01, 0.1);
|
||||
RNA_def_boolean(ot->srna, "accumulate", 0, "Accumulate", "");
|
||||
RNA_def_boolean(ot->srna, "additive", 0, "Additive", "");
|
||||
RNA_def_boolean(ot->srna, "square", 0, "Square", "");
|
||||
RNA_def_float(ot->srna, "sthreshold", 0.1, 0.0, 1.0, "Square Threshold", "", 0.01, 0.1);
|
||||
}
|
||||
|
||||
/* ******************** Sample Keyframes Operator *********************** */
|
||||
|
Loading…
Reference in New Issue
Block a user