forked from bartvdbraak/blender
Audaspace:
* Comment fix for PingPongFactory * Added 2 new factory types: Superpose and Double
This commit is contained in:
parent
3cef95cd93
commit
5460994095
55
intern/audaspace/FX/AUD_DoubleFactory.cpp
Normal file
55
intern/audaspace/FX/AUD_DoubleFactory.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* $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_DoubleFactory.h"
|
||||
#include "AUD_DoubleReader.h"
|
||||
|
||||
AUD_DoubleFactory::AUD_DoubleFactory(AUD_IFactory* factory1, AUD_IFactory* factory2) :
|
||||
m_factory1(factory1), m_factory2(factory2) {}
|
||||
|
||||
AUD_IReader* AUD_DoubleFactory::createReader()
|
||||
{
|
||||
AUD_IReader* reader1 = m_factory1->createReader();
|
||||
if(!reader1)
|
||||
return 0;
|
||||
AUD_IReader* reader2;
|
||||
try
|
||||
{
|
||||
reader2 = m_factory2->createReader();
|
||||
if(!reader2)
|
||||
{
|
||||
delete reader1; AUD_DELETE("reader")
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
catch(AUD_Exception&)
|
||||
{
|
||||
delete reader1; AUD_DELETE("reader")
|
||||
throw;
|
||||
}
|
||||
|
||||
AUD_IReader* reader = new AUD_DoubleReader(reader1, reader2);
|
||||
return reader;
|
||||
}
|
59
intern/audaspace/FX/AUD_DoubleFactory.h
Normal file
59
intern/audaspace/FX/AUD_DoubleFactory.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_DOUBLEFACTORY
|
||||
#define AUD_DOUBLEFACTORY
|
||||
|
||||
#include "AUD_IFactory.h"
|
||||
|
||||
/**
|
||||
* This factory plays two other factories behind each other.
|
||||
* \note Readers from the underlying factories must have the same sample rate and channel count.
|
||||
*/
|
||||
class AUD_DoubleFactory : public AUD_IFactory
|
||||
{
|
||||
private:
|
||||
/**
|
||||
* First played factory.
|
||||
*/
|
||||
AUD_IFactory* m_factory1;
|
||||
|
||||
/**
|
||||
* Second played factory.
|
||||
*/
|
||||
AUD_IFactory* m_factory2;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Creates a new double factory.
|
||||
* \param factory1 The first input factory.
|
||||
* \param factory2 The second input factory.
|
||||
*/
|
||||
AUD_DoubleFactory(AUD_IFactory* factory1, AUD_IFactory* factory2);
|
||||
|
||||
virtual AUD_IReader* createReader();
|
||||
};
|
||||
|
||||
#endif //AUD_DOUBLEFACTORY
|
@ -41,10 +41,6 @@ public:
|
||||
*/
|
||||
AUD_PingPongFactory(AUD_IFactory* factory = 0);
|
||||
|
||||
/**
|
||||
* Destroys the factory.
|
||||
*/
|
||||
|
||||
virtual AUD_IReader* createReader();
|
||||
};
|
||||
|
||||
|
55
intern/audaspace/FX/AUD_SuperposeFactory.cpp
Normal file
55
intern/audaspace/FX/AUD_SuperposeFactory.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* $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_SuperposeFactory.h"
|
||||
#include "AUD_SuperposeReader.h"
|
||||
|
||||
AUD_SuperposeFactory::AUD_SuperposeFactory(AUD_IFactory* factory1, AUD_IFactory* factory2) :
|
||||
m_factory1(factory1), m_factory2(factory2) {}
|
||||
|
||||
AUD_IReader* AUD_SuperposeFactory::createReader()
|
||||
{
|
||||
AUD_IReader* reader1 = m_factory1->createReader();
|
||||
if(!reader1)
|
||||
return 0;
|
||||
AUD_IReader* reader2;
|
||||
try
|
||||
{
|
||||
reader2 = m_factory2->createReader();
|
||||
if(!reader2)
|
||||
{
|
||||
delete reader1; AUD_DELETE("reader")
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
catch(AUD_Exception&)
|
||||
{
|
||||
delete reader1; AUD_DELETE("reader")
|
||||
throw;
|
||||
}
|
||||
|
||||
AUD_IReader* reader = new AUD_SuperposeReader(reader1, reader2);
|
||||
return reader;
|
||||
}
|
59
intern/audaspace/FX/AUD_SuperposeFactory.h
Normal file
59
intern/audaspace/FX/AUD_SuperposeFactory.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_SUPERPOSEFACTORY
|
||||
#define AUD_SUPERPOSEFACTORY
|
||||
|
||||
#include "AUD_IFactory.h"
|
||||
|
||||
/**
|
||||
* This factory plays two other factories behind each other.
|
||||
* \note Readers from the underlying factories must have the same sample rate and channel count.
|
||||
*/
|
||||
class AUD_SuperposeFactory : public AUD_IFactory
|
||||
{
|
||||
private:
|
||||
/**
|
||||
* First played factory.
|
||||
*/
|
||||
AUD_IFactory* m_factory1;
|
||||
|
||||
/**
|
||||
* Second played factory.
|
||||
*/
|
||||
AUD_IFactory* m_factory2;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Creates a new superpose factory.
|
||||
* \param factory1 The first input factory.
|
||||
* \param factory2 The second input factory.
|
||||
*/
|
||||
AUD_SuperposeFactory(AUD_IFactory* factory1, AUD_IFactory* factory2);
|
||||
|
||||
virtual AUD_IReader* createReader();
|
||||
};
|
||||
|
||||
#endif //AUD_SUPERPOSEFACTORY
|
144
intern/audaspace/FX/AUD_SuperposeReader.cpp
Normal file
144
intern/audaspace/FX/AUD_SuperposeReader.cpp
Normal file
@ -0,0 +1,144 @@
|
||||
/*
|
||||
* $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_SuperposeReader.h"
|
||||
#include "AUD_Buffer.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
AUD_SuperposeReader::AUD_SuperposeReader(AUD_IReader* reader1, AUD_IReader* reader2) :
|
||||
m_reader1(reader1), m_reader2(reader2)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(!reader1)
|
||||
AUD_THROW(AUD_ERROR_READER);
|
||||
|
||||
if(!reader2)
|
||||
AUD_THROW(AUD_ERROR_READER);
|
||||
|
||||
AUD_Specs s1, s2;
|
||||
s1 = reader1->getSpecs();
|
||||
s2 = reader2->getSpecs();
|
||||
if(memcmp(&s1, &s2, sizeof(AUD_Specs)) != 0)
|
||||
AUD_THROW(AUD_ERROR_READER);
|
||||
}
|
||||
|
||||
catch(AUD_Exception)
|
||||
{
|
||||
if(reader1)
|
||||
{
|
||||
delete reader1; AUD_DELETE("reader")
|
||||
}
|
||||
if(reader2)
|
||||
{
|
||||
delete reader2; AUD_DELETE("reader")
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
|
||||
m_buffer = new AUD_Buffer(); AUD_NEW("buffer")
|
||||
}
|
||||
|
||||
AUD_SuperposeReader::~AUD_SuperposeReader()
|
||||
{
|
||||
delete m_reader1; AUD_DELETE("reader")
|
||||
delete m_reader2; AUD_DELETE("reader")
|
||||
delete m_buffer; AUD_DELETE("buffer")
|
||||
}
|
||||
|
||||
bool AUD_SuperposeReader::isSeekable()
|
||||
{
|
||||
return m_reader1->isSeekable() && m_reader2->isSeekable();
|
||||
}
|
||||
|
||||
void AUD_SuperposeReader::seek(int position)
|
||||
{
|
||||
m_reader1->seek(position);
|
||||
m_reader2->seek(position);
|
||||
}
|
||||
|
||||
int AUD_SuperposeReader::getLength()
|
||||
{
|
||||
int len1 = m_reader1->getLength();
|
||||
int len2 = m_reader2->getLength();
|
||||
if((len1 < 0) || (len2 < 0))
|
||||
return -1;
|
||||
if(len1 < len2)
|
||||
return len2;
|
||||
return len1;
|
||||
}
|
||||
|
||||
int AUD_SuperposeReader::getPosition()
|
||||
{
|
||||
int pos1 = m_reader1->getPosition();
|
||||
int pos2 = m_reader2->getPosition();
|
||||
return AUD_MAX(pos1, pos2);
|
||||
}
|
||||
|
||||
AUD_Specs AUD_SuperposeReader::getSpecs()
|
||||
{
|
||||
return m_reader1->getSpecs();
|
||||
}
|
||||
|
||||
AUD_ReaderType AUD_SuperposeReader::getType()
|
||||
{
|
||||
if(m_reader1->getType() == AUD_TYPE_BUFFER &&
|
||||
m_reader2->getType() == AUD_TYPE_BUFFER)
|
||||
return AUD_TYPE_BUFFER;
|
||||
return AUD_TYPE_STREAM;
|
||||
}
|
||||
|
||||
bool AUD_SuperposeReader::notify(AUD_Message &message)
|
||||
{
|
||||
return m_reader1->notify(message) | m_reader2->notify(message);
|
||||
}
|
||||
|
||||
void AUD_SuperposeReader::read(int & length, sample_t* & buffer)
|
||||
{
|
||||
AUD_Specs specs = m_reader1->getSpecs();
|
||||
int samplesize = AUD_SAMPLE_SIZE(specs);
|
||||
|
||||
if(m_buffer->getSize() < length * samplesize)
|
||||
m_buffer->resize(length * samplesize);
|
||||
buffer = m_buffer->getBuffer();
|
||||
|
||||
int len1 = length;
|
||||
sample_t* buf;
|
||||
m_reader1->read(len1, buf);
|
||||
memcpy(buffer, buf, len1 * samplesize);
|
||||
|
||||
if(len1 < length)
|
||||
memset(buffer + len1 * specs.channels, 0, (length - len1) * samplesize);
|
||||
|
||||
int len2 = length;
|
||||
m_reader2->read(len2, buf);
|
||||
|
||||
for(int i = 0; i < len2 * specs.channels; i++)
|
||||
buffer[i] += buf[i];
|
||||
|
||||
length = AUD_MAX(len1, len2);
|
||||
}
|
78
intern/audaspace/FX/AUD_SuperposeReader.h
Normal file
78
intern/audaspace/FX/AUD_SuperposeReader.h
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* $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_SUPERPOSEREADER
|
||||
#define AUD_SUPERPOSEREADER
|
||||
|
||||
#include "AUD_IReader.h"
|
||||
class AUD_Buffer;
|
||||
|
||||
/**
|
||||
* This reader plays two readers with the same specs sequently.
|
||||
*/
|
||||
class AUD_SuperposeReader : public AUD_IReader
|
||||
{
|
||||
private:
|
||||
/**
|
||||
* The first reader.
|
||||
*/
|
||||
AUD_IReader* m_reader1;
|
||||
|
||||
/**
|
||||
* The second reader.
|
||||
*/
|
||||
AUD_IReader* m_reader2;
|
||||
|
||||
/**
|
||||
* The playback buffer for the intersecting part.
|
||||
*/
|
||||
AUD_Buffer* m_buffer;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Creates a new superpose reader.
|
||||
* \param reader1 The first reader to read from.
|
||||
* \param reader2 The second reader to read from.
|
||||
* \exception AUD_Exception Thrown if one of the reader specified is NULL
|
||||
* or the specs from the readers differ.
|
||||
*/
|
||||
AUD_SuperposeReader(AUD_IReader* reader1, AUD_IReader* reader2);
|
||||
|
||||
/**
|
||||
* Destroys the reader.
|
||||
*/
|
||||
virtual ~AUD_SuperposeReader();
|
||||
|
||||
virtual bool isSeekable();
|
||||
virtual void seek(int position);
|
||||
virtual int getLength();
|
||||
virtual int getPosition();
|
||||
virtual AUD_Specs getSpecs();
|
||||
virtual AUD_ReaderType getType();
|
||||
virtual bool notify(AUD_Message &message);
|
||||
virtual void read(int & length, sample_t* & buffer);
|
||||
};
|
||||
|
||||
#endif //AUD_SUPERPOSEREADER
|
Loading…
Reference in New Issue
Block a user