Audaspace: HUGE Refactor.
authorJoerg Mueller <nexyon@gmail.com>
Wed, 28 Jul 2010 09:36:03 +0000 (09:36 +0000)
committerJoerg Mueller <nexyon@gmail.com>
Wed, 28 Jul 2010 09:36:03 +0000 (09:36 +0000)
Some points of the refactor not sorted by importance:

* Fixed immutability of readers and factories (there are exceptions...)
* Fixed copy constructors and = operators
* Removed messaging system
* Removed reader types
* Added const where possible
* Using initalisers when possible
* Avoided use of pointers when possible
* Removed AUD_NEW and AUD_DELETE macros
* Removed useless NULL pointer checks
* Fixed exception catching
* Fixed some yet unknown bugs
* Lots of other stuff

139 files changed:
intern/audaspace/FX/AUD_AccumulatorFactory.cpp
intern/audaspace/FX/AUD_AccumulatorFactory.h
intern/audaspace/FX/AUD_AccumulatorReader.cpp
intern/audaspace/FX/AUD_AccumulatorReader.h
intern/audaspace/FX/AUD_ButterworthFactory.cpp
intern/audaspace/FX/AUD_ButterworthFactory.h
intern/audaspace/FX/AUD_ButterworthReader.cpp
intern/audaspace/FX/AUD_ButterworthReader.h
intern/audaspace/FX/AUD_DelayFactory.cpp
intern/audaspace/FX/AUD_DelayFactory.h
intern/audaspace/FX/AUD_DelayReader.cpp
intern/audaspace/FX/AUD_DelayReader.h
intern/audaspace/FX/AUD_DoubleFactory.cpp
intern/audaspace/FX/AUD_DoubleFactory.h
intern/audaspace/FX/AUD_DoubleReader.cpp
intern/audaspace/FX/AUD_DoubleReader.h
intern/audaspace/FX/AUD_EffectFactory.cpp
intern/audaspace/FX/AUD_EffectFactory.h
intern/audaspace/FX/AUD_EffectReader.cpp
intern/audaspace/FX/AUD_EffectReader.h
intern/audaspace/FX/AUD_EnvelopeFactory.cpp
intern/audaspace/FX/AUD_EnvelopeFactory.h
intern/audaspace/FX/AUD_EnvelopeReader.cpp
intern/audaspace/FX/AUD_EnvelopeReader.h
intern/audaspace/FX/AUD_FaderFactory.cpp
intern/audaspace/FX/AUD_FaderFactory.h
intern/audaspace/FX/AUD_FaderReader.cpp
intern/audaspace/FX/AUD_FaderReader.h
intern/audaspace/FX/AUD_HighpassFactory.cpp
intern/audaspace/FX/AUD_HighpassFactory.h
intern/audaspace/FX/AUD_HighpassReader.cpp
intern/audaspace/FX/AUD_HighpassReader.h
intern/audaspace/FX/AUD_LimiterFactory.cpp
intern/audaspace/FX/AUD_LimiterFactory.h
intern/audaspace/FX/AUD_LimiterReader.cpp
intern/audaspace/FX/AUD_LimiterReader.h
intern/audaspace/FX/AUD_LoopFactory.cpp
intern/audaspace/FX/AUD_LoopFactory.h
intern/audaspace/FX/AUD_LoopReader.cpp
intern/audaspace/FX/AUD_LoopReader.h
intern/audaspace/FX/AUD_LowpassFactory.cpp
intern/audaspace/FX/AUD_LowpassFactory.h
intern/audaspace/FX/AUD_LowpassReader.cpp
intern/audaspace/FX/AUD_LowpassReader.h
intern/audaspace/FX/AUD_PingPongFactory.cpp
intern/audaspace/FX/AUD_PingPongFactory.h
intern/audaspace/FX/AUD_PitchFactory.cpp
intern/audaspace/FX/AUD_PitchFactory.h
intern/audaspace/FX/AUD_PitchReader.cpp
intern/audaspace/FX/AUD_PitchReader.h
intern/audaspace/FX/AUD_RectifyFactory.cpp
intern/audaspace/FX/AUD_RectifyFactory.h
intern/audaspace/FX/AUD_RectifyReader.cpp
intern/audaspace/FX/AUD_RectifyReader.h
intern/audaspace/FX/AUD_ReverseFactory.cpp
intern/audaspace/FX/AUD_ReverseFactory.h
intern/audaspace/FX/AUD_ReverseReader.cpp
intern/audaspace/FX/AUD_ReverseReader.h
intern/audaspace/FX/AUD_SquareFactory.cpp
intern/audaspace/FX/AUD_SquareFactory.h
intern/audaspace/FX/AUD_SquareReader.cpp
intern/audaspace/FX/AUD_SquareReader.h
intern/audaspace/FX/AUD_SumFactory.cpp
intern/audaspace/FX/AUD_SumFactory.h
intern/audaspace/FX/AUD_SumReader.cpp
intern/audaspace/FX/AUD_SumReader.h
intern/audaspace/FX/AUD_SuperposeFactory.cpp
intern/audaspace/FX/AUD_SuperposeFactory.h
intern/audaspace/FX/AUD_SuperposeReader.cpp
intern/audaspace/FX/AUD_SuperposeReader.h
intern/audaspace/FX/AUD_VolumeFactory.cpp
intern/audaspace/FX/AUD_VolumeFactory.h
intern/audaspace/FX/AUD_VolumeReader.cpp
intern/audaspace/FX/AUD_VolumeReader.h
intern/audaspace/OpenAL/AUD_OpenALDevice.cpp
intern/audaspace/OpenAL/AUD_OpenALDevice.h
intern/audaspace/Python/AUD_PyAPI.cpp
intern/audaspace/SDL/AUD_SDLDevice.h
intern/audaspace/SRC/AUD_SRCResampleFactory.cpp
intern/audaspace/SRC/AUD_SRCResampleFactory.h
intern/audaspace/SRC/AUD_SRCResampleReader.cpp
intern/audaspace/SRC/AUD_SRCResampleReader.h
intern/audaspace/ffmpeg/AUD_FFMPEGFactory.cpp
intern/audaspace/ffmpeg/AUD_FFMPEGFactory.h
intern/audaspace/ffmpeg/AUD_FFMPEGReader.cpp
intern/audaspace/ffmpeg/AUD_FFMPEGReader.h
intern/audaspace/fftw/AUD_BandPassReader.h
intern/audaspace/intern/AUD_Buffer.cpp
intern/audaspace/intern/AUD_Buffer.h
intern/audaspace/intern/AUD_BufferReader.cpp
intern/audaspace/intern/AUD_BufferReader.h
intern/audaspace/intern/AUD_C-API.cpp
intern/audaspace/intern/AUD_ChannelMapperFactory.cpp
intern/audaspace/intern/AUD_ChannelMapperFactory.h
intern/audaspace/intern/AUD_ChannelMapperReader.cpp
intern/audaspace/intern/AUD_ChannelMapperReader.h
intern/audaspace/intern/AUD_ConverterFactory.cpp
intern/audaspace/intern/AUD_ConverterFactory.h
intern/audaspace/intern/AUD_ConverterReader.cpp
intern/audaspace/intern/AUD_ConverterReader.h
intern/audaspace/intern/AUD_DefaultMixer.cpp [new file with mode: 0644]
intern/audaspace/intern/AUD_DefaultMixer.h [new file with mode: 0644]
intern/audaspace/intern/AUD_FileFactory.cpp
intern/audaspace/intern/AUD_FileFactory.h
intern/audaspace/intern/AUD_IDevice.h
intern/audaspace/intern/AUD_IFactory.h
intern/audaspace/intern/AUD_IReader.h
intern/audaspace/intern/AUD_LinearResampleFactory.cpp
intern/audaspace/intern/AUD_LinearResampleFactory.h
intern/audaspace/intern/AUD_LinearResampleReader.cpp
intern/audaspace/intern/AUD_LinearResampleReader.h
intern/audaspace/intern/AUD_Mixer.cpp
intern/audaspace/intern/AUD_Mixer.h
intern/audaspace/intern/AUD_MixerFactory.cpp
intern/audaspace/intern/AUD_MixerFactory.h
intern/audaspace/intern/AUD_NULLDevice.cpp
intern/audaspace/intern/AUD_NULLDevice.h
intern/audaspace/intern/AUD_ReadDevice.cpp
intern/audaspace/intern/AUD_ReadDevice.h
intern/audaspace/intern/AUD_Reference.h
intern/audaspace/intern/AUD_SequencerFactory.cpp
intern/audaspace/intern/AUD_SequencerFactory.h
intern/audaspace/intern/AUD_SequencerReader.cpp
intern/audaspace/intern/AUD_SequencerReader.h
intern/audaspace/intern/AUD_SinusFactory.cpp
intern/audaspace/intern/AUD_SinusFactory.h
intern/audaspace/intern/AUD_SinusReader.cpp
intern/audaspace/intern/AUD_SinusReader.h
intern/audaspace/intern/AUD_SoftwareDevice.cpp
intern/audaspace/intern/AUD_SoftwareDevice.h
intern/audaspace/intern/AUD_Space.h
intern/audaspace/intern/AUD_StreamBufferFactory.cpp
intern/audaspace/intern/AUD_StreamBufferFactory.h
intern/audaspace/jack/AUD_JackDevice.cpp
intern/audaspace/jack/AUD_JackDevice.h
intern/audaspace/sndfile/AUD_SndFileFactory.cpp
intern/audaspace/sndfile/AUD_SndFileFactory.h
intern/audaspace/sndfile/AUD_SndFileReader.cpp
intern/audaspace/sndfile/AUD_SndFileReader.h

index 20709c57ee5ee7a2304f82a0b3fc1fe4bc22a9a5..6e9130d174bd0cdf2fa42d4c5ec1d2a41aacbb6f 100644 (file)
 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()
+               m_additive(additive)
 {
-       AUD_IReader* reader = getReader();
-
-       if(reader != 0)
-       {
-               reader = new AUD_AccumulatorReader(reader, m_additive);
-               AUD_NEW("reader")
-       }
+}
 
-       return reader;
+AUD_IReader* AUD_AccumulatorFactory::createReader() const
+{
+       return new AUD_AccumulatorReader(getReader(), m_additive);
 }
index e475a19ccf62fee2710f2c25e15c3111c16cfd6e..2b90fa43bdfdbc659b4f3dd214f43e860fd57c2a 100644 (file)
@@ -37,7 +37,11 @@ private:
        /**
         * Whether the accumulator is additive.
         */
-       bool m_additive;
+       const bool m_additive;
+
+       // hide copy constructor and operator=
+       AUD_AccumulatorFactory(const AUD_AccumulatorFactory&);
+       AUD_AccumulatorFactory& operator=(const AUD_AccumulatorFactory&);
 
 public:
        /**
@@ -47,13 +51,7 @@ public:
         */
        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();
+       virtual AUD_IReader* createReader() const;
 };
 
 #endif //AUD_ACCUMULATORFACTORY
index 67ab4157f9c824661bf564024106480be1fbce3a..a8964edcac78d84b979908395e26b67e1707c5b4 100644 (file)
@@ -24,7 +24,6 @@
  */
 
 #include "AUD_AccumulatorReader.h"
-#include "AUD_Buffer.h"
 
 #include <cstring>
 
 AUD_AccumulatorReader::AUD_AccumulatorReader(AUD_IReader* reader,
                                                                                         bool additive) :
                AUD_EffectReader(reader),
-               m_additive(additive)
+               m_additive(additive),
+               m_sums(AUD_SAMPLE_SIZE(reader->getSpecs())),
+               m_prevs(AUD_SAMPLE_SIZE(reader->getSpecs()))
 {
-       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")
+       memset(m_sums.getBuffer(), 0, m_sums.getSize());
+       memset(m_prevs.getBuffer(), 0, m_prevs.getSize());
 }
 
 void AUD_AccumulatorReader::read(int & length, sample_t* & buffer)
@@ -59,16 +45,16 @@ 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();
+       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));
+       if(m_buffer.getSize() < length * AUD_SAMPLE_SIZE(specs))
+               m_buffer.resize(length * AUD_SAMPLE_SIZE(specs));
 
-       buffer = m_buffer->getBuffer();
+       buffer = m_buffer.getBuffer();
 
        if(m_additive)
        {
@@ -87,7 +73,7 @@ void AUD_AccumulatorReader::read(int & length, sample_t* & buffer)
        {
                for(int channel = 0; channel < specs.channels; channel++)
                {
-                       for(int i = 0; i < length * specs.channels; i++)
+                       for(int i = 0; i < length; i++)
                        {
                                if(buf[i * CC] > prevs[channel])
                                        sums[channel] += buf[i * CC] - prevs[channel];
index 8ad1dda30f6b0bec4c660f547fd16a7679025d7f..68c1360731db48dd387956c75877a4b0b6e07a07 100644 (file)
@@ -27,7 +27,7 @@
 #define AUD_ACCUMULATORREADER
 
 #include "AUD_EffectReader.h"
-class AUD_Buffer;
+#include "AUD_Buffer.h"
 
 /**
  * This class represents an accumulator.
@@ -35,40 +35,38 @@ class AUD_Buffer;
 class AUD_AccumulatorReader : public AUD_EffectReader
 {
 private:
+       /**
+        * Whether the accumulator is additive.
+        */
+       const bool m_additive;
+
        /**
         * The playback buffer.
         */
-       AUD_Buffer *m_buffer;
+       AUD_Buffer m_buffer;
 
        /**
         * The sums of the specific channels.
         */
-       AUD_Buffer *m_sums;
+       AUD_Buffer m_sums;
 
        /**
         * The previous results of the specific channels.
         */
-       AUD_Buffer *m_prevs;
+       AUD_Buffer m_prevs;
 
-       /**
-        * Whether the accumulator is additive.
-        */
-       bool m_additive;
+       // hide copy constructor and operator=
+       AUD_AccumulatorReader(const AUD_AccumulatorReader&);
+       AUD_AccumulatorReader& operator=(const AUD_AccumulatorReader&);
 
 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);
 };
 
index fd0a53def7cfd603b273886f18d9e8c5474e3b27..1bb1d726a9831a845bbb0b801820100081721cba 100644 (file)
 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()
+               m_frequency(frequency)
 {
-       AUD_IReader* reader = getReader();
-
-       if(reader != 0)
-       {
-               reader = new AUD_ButterworthReader(reader, m_frequency);
-               AUD_NEW("reader")
-       }
+}
 
-       return reader;
+AUD_IReader* AUD_ButterworthFactory::createReader() const
+{
+       return new AUD_ButterworthReader(getReader(), m_frequency);
 }
index 69169531d7070681fa662c644f94982fa3cb6d61..30b7a402c574ae20e3f08a2521edb43312ea7128 100644 (file)
@@ -37,7 +37,11 @@ private:
        /**
         * The attack value in seconds.
         */
-       float m_frequency;
+       const float m_frequency;
+
+       // hide copy constructor and operator=
+       AUD_ButterworthFactory(const AUD_ButterworthFactory&);
+       AUD_ButterworthFactory& operator=(const AUD_ButterworthFactory&);
 
 public:
        /**
@@ -47,13 +51,7 @@ public:
         */
        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();
+       virtual AUD_IReader* createReader() const;
 };
 
 #endif //AUD_BUTTERWORTHFACTORY
index 2129dfef7984c242f2bc31b872e24b36384a2a5d..cfe4205c7f883bd31df49c4e7b9547b10e1816c1 100644 (file)
@@ -24,7 +24,6 @@
  */
 
 #include "AUD_ButterworthReader.h"
-#include "AUD_Buffer.h"
 
 #include <cstring>
 #include <cmath>
 
 AUD_ButterworthReader::AUD_ButterworthReader(AUD_IReader* reader,
                                                                                         float frequency) :
-               AUD_EffectReader(reader)
+               AUD_EffectReader(reader),
+               m_outvalues(AUD_SAMPLE_SIZE(reader->getSpecs()) * 5),
+               m_invalues(AUD_SAMPLE_SIZE(reader->getSpecs()) * 5),
+               m_position(0)
 {
        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;
+       memset(m_outvalues.getBuffer(), 0, m_outvalues.getSize());
+       memset(m_invalues.getBuffer(), 0, m_invalues.getSize());
 
        // calculate coefficients
        float omega = 2 * tan(frequency * M_PI / specs.rate);
@@ -74,31 +67,23 @@ AUD_ButterworthReader::AUD_ButterworthReader(AUD_IReader* reader,
        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();
+       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));
+       if(m_buffer.getSize() < length * AUD_SAMPLE_SIZE(specs))
+               m_buffer.resize(length * AUD_SAMPLE_SIZE(specs));
 
-       buffer = m_buffer->getBuffer();
+       buffer = m_buffer.getBuffer();
        int channels = specs.channels;
 
        for(int channel = 0; channel < channels; channel++)
index b1cbd4e3820c5291d320b3ceb1d5669ac2fee862..52cbb6425406b0a14c570095a1dc5fe69f062cf4 100644 (file)
@@ -27,7 +27,7 @@
 #define AUD_BUTTERWORTHREADER
 
 #include "AUD_EffectReader.h"
-class AUD_Buffer;
+#include "AUD_Buffer.h"
 
 /**
  * This class represents a butterworth filter.
@@ -38,17 +38,17 @@ private:
        /**
         * The playback buffer.
         */
-       AUD_Buffer *m_buffer;
+       AUD_Buffer m_buffer;
 
        /**
         * The last out values buffer.
         */
-       AUD_Buffer *m_outvalues;
+       AUD_Buffer m_outvalues;
 
        /**
         * The last in values buffer.
         */
-       AUD_Buffer *m_invalues;
+       AUD_Buffer m_invalues;
 
        /**
         * The position for buffer cycling.
@@ -60,6 +60,10 @@ private:
         */
        float m_coeff[2][5];
 
+       // hide copy constructor and operator=
+       AUD_ButterworthReader(const AUD_ButterworthReader&);
+       AUD_ButterworthReader& operator=(const AUD_ButterworthReader&);
+
 public:
        /**
         * Creates a new butterworth reader.
@@ -68,15 +72,9 @@ public:
         * \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);
 };
 
index 25ce4faed4c93a74d030c6f5270b5096225af088..f98743d6fb74efcd18216cb25332aadfcfa8327d 100644 (file)
 
 AUD_DelayFactory::AUD_DelayFactory(AUD_IFactory* factory, float delay) :
                AUD_EffectFactory(factory),
-               m_delay(delay) {}
-
-AUD_DelayFactory::AUD_DelayFactory(float delay) :
-               AUD_EffectFactory(0),
-               m_delay(delay) {}
-
-float AUD_DelayFactory::getDelay()
+               m_delay(delay)
 {
-       return m_delay;
 }
 
-void AUD_DelayFactory::setDelay(float delay)
+float AUD_DelayFactory::getDelay() const
 {
-       m_delay = delay;
+       return m_delay;
 }
 
-AUD_IReader* AUD_DelayFactory::createReader()
+AUD_IReader* AUD_DelayFactory::createReader() const
 {
-       AUD_IReader* reader = getReader();
-
-       if(reader != 0)
-       {
-               reader = new AUD_DelayReader(reader, m_delay); AUD_NEW("reader")
-       }
-
-       return reader;
+       return new AUD_DelayReader(getReader(), m_delay);
 }
index 5ad4b9ab99611185a7da0158b8fcdf9814b7ff3f..721262fb73f368e92490f9cd44869fe18d82c8b4 100644 (file)
@@ -37,7 +37,11 @@ private:
        /**
         * The delay in samples.
         */
-       float m_delay;
+       const float m_delay;
+
+       // hide copy constructor and operator=
+       AUD_DelayFactory(const AUD_DelayFactory&);
+       AUD_DelayFactory& operator=(const AUD_DelayFactory&);
 
 public:
        /**
@@ -45,26 +49,14 @@ public:
         * \param factory The input factory.
         * \param delay The desired delay in seconds.
         */
-       AUD_DelayFactory(AUD_IFactory* factory = 0, float delay = 0);
-
-       /**
-        * Creates a new delay factory.
-        * \param delay The desired delay in seconds.
-        */
-       AUD_DelayFactory(float delay);
+       AUD_DelayFactory(AUD_IFactory* factory, float delay = 0);
 
        /**
         * Returns the delay in seconds.
         */
-       float getDelay();
-
-       /**
-        * Sets the delay.
-        * \param delay The new delay value in seconds.
-        */
-       void setDelay(float delay);
+       float getDelay() const;
 
-       virtual AUD_IReader* createReader();
+       virtual AUD_IReader* createReader() const;
 };
 
 #endif //AUD_DELAYFACTORY
index f2521f645aa9f8a8251a04b01bc50f327edb0f2a..e9f0c15b9b417922105ec2f111979bf3c9cc158f 100644 (file)
  */
 
 #include "AUD_DelayReader.h"
-#include "AUD_Buffer.h"
 
 #include <cstring>
 
 AUD_DelayReader::AUD_DelayReader(AUD_IReader* reader, float delay) :
-               AUD_EffectReader(reader)
+               AUD_EffectReader(reader),
+               m_delay(int(delay * reader->getSpecs().rate)),
+               m_remdelay(int(delay * reader->getSpecs().rate)),
+               m_empty(true)
 {
-       m_delay = (int)(delay * reader->getSpecs().rate);
-       m_remdelay = m_delay;
-       m_buffer = new AUD_Buffer(); AUD_NEW("buffer")
-}
-
-AUD_DelayReader::~AUD_DelayReader()
-{
-       delete m_buffer; AUD_DELETE("buffer")
 }
 
 void AUD_DelayReader::seek(int position)
 {
-       if(position < 0)
-               return;
-
        if(position < m_delay)
        {
                m_remdelay = m_delay - position;
@@ -58,18 +49,18 @@ void AUD_DelayReader::seek(int position)
        }
 }
 
-int AUD_DelayReader::getLength()
+int AUD_DelayReader::getLength() const
 {
        int len = m_reader->getLength();
        if(len < 0)
                return len;
-       return len+m_delay;
+       return len + m_delay;
 }
 
-int AUD_DelayReader::getPosition()
+int AUD_DelayReader::getPosition() const
 {
        if(m_remdelay > 0)
-               return m_delay-m_remdelay;
+               return m_delay - m_remdelay;
        return m_reader->getPosition() + m_delay;
 }
 
@@ -80,26 +71,41 @@ void AUD_DelayReader::read(int & length, sample_t* & buffer)
                AUD_Specs specs = m_reader->getSpecs();
                int samplesize = AUD_SAMPLE_SIZE(specs);
 
-               if(m_buffer->getSize() < length * samplesize)
-                       m_buffer->resize(length * samplesize);
+               if(m_buffer.getSize() < length * samplesize)
+               {
+                       m_buffer.resize(length * samplesize);
+                       m_empty = false;
+               }
+
+               buffer = m_buffer.getBuffer();
 
                if(length > m_remdelay)
                {
-                       memset(m_buffer->getBuffer(), 0, m_remdelay * samplesize);
+                       if(!m_empty)
+                               memset(buffer, 0, m_remdelay * samplesize);
+
                        int len = length - m_remdelay;
-                       m_reader->read(len, buffer);
-                       memcpy(m_buffer->getBuffer() + m_remdelay * specs.channels,
-                                  buffer, len * samplesize);
+                       sample_t* buf;
+                       m_reader->read(len, buf);
+
+                       memcpy(buffer + m_remdelay * specs.channels,
+                                  buf, len * samplesize);
+
                        if(len < length-m_remdelay)
                                length = m_remdelay + len;
+
                        m_remdelay = 0;
+                       m_empty = false;
                }
                else
                {
-                       memset(m_buffer->getBuffer(), 0, length * samplesize);
+                       if(!m_empty)
+                       {
+                               memset(buffer, 0, length * samplesize);
+                               m_empty = true;
+                       }
                        m_remdelay -= length;
                }
-               buffer = m_buffer->getBuffer();
        }
        else
                m_reader->read(length, buffer);
index 4662b455dfca8e907c84eae1f5de1751432511a8..121842b0c6b6792102fc967dc750b7f9dea4a63c 100644 (file)
@@ -27,7 +27,7 @@
 #define AUD_DELAYREADER
 
 #include "AUD_EffectReader.h"
-class AUD_Buffer;
+#include "AUD_Buffer.h"
 
 /**
  * This class reads another reader and changes it's delay.
@@ -38,35 +38,38 @@ private:
        /**
         * The playback buffer.
         */
-       AUD_Buffer *m_buffer;
+       AUD_Buffer m_buffer;
 
        /**
         * The delay level.
         */
-       int m_delay;
+       const int m_delay;
 
        /**
         * The remaining delay for playback.
         */
        int m_remdelay;
 
+       /**
+        * Whether the buffer is currently filled with zeros.
+        */
+       bool m_empty;
+
+       // hide copy constructor and operator=
+       AUD_DelayReader(const AUD_DelayReader&);
+       AUD_DelayReader& operator=(const AUD_DelayReader&);
+
 public:
        /**
         * Creates a new delay reader.
         * \param reader The reader to read from.
         * \param delay The delay in seconds.
-        * \exception AUD_Exception Thrown if the reader specified is NULL.
         */
        AUD_DelayReader(AUD_IReader* reader, float delay);
 
-       /**
-        * Destroys the reader.
-        */
-       virtual ~AUD_DelayReader();
-
        virtual void seek(int position);
-       virtual int getLength();
-       virtual int getPosition();
+       virtual int getLength() const;
+       virtual int getPosition() const;
        virtual void read(int & length, sample_t* & buffer);
 };
 
index 402d884be9fa796c781755fd365e5d0da899c1f1..9f625d0763f4413829e0ff32b756aa639f91cb9f 100644 (file)
 #include "AUD_DoubleReader.h"
 
 AUD_DoubleFactory::AUD_DoubleFactory(AUD_IFactory* factory1, AUD_IFactory* factory2) :
-               m_factory1(factory1), m_factory2(factory2) {}
+               m_factory1(factory1), m_factory2(factory2)
+{
+}
 
-AUD_IReader* AUD_DoubleFactory::createReader()
+AUD_IReader* AUD_DoubleFactory::createReader() const
 {
        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")
+               delete reader1;
                throw;
        }
 
-       AUD_IReader* reader = new AUD_DoubleReader(reader1, reader2);
-       return reader;
+       return new AUD_DoubleReader(reader1, reader2);
 }
index 03c7de19f069171fcb984988c0dc6a587c051cfb..f2e83b2e27a0589a85d3cbada0c74070a70f4c8c 100644 (file)
@@ -45,6 +45,10 @@ private:
         */
        AUD_IFactory* m_factory2;
 
+       // hide copy constructor and operator=
+       AUD_DoubleFactory(const AUD_DoubleFactory&);
+       AUD_DoubleFactory& operator=(const AUD_DoubleFactory&);
+
 public:
        /**
         * Creates a new double factory.
@@ -53,7 +57,7 @@ public:
         */
        AUD_DoubleFactory(AUD_IFactory* factory1, AUD_IFactory* factory2);
 
-       virtual AUD_IReader* createReader();
+       virtual AUD_IReader* createReader() const;
 };
 
 #endif //AUD_DOUBLEFACTORY
index 1e51a094427e5b507cc525166eb9f6122880b408..6b39e01270fbaac465cc8def92eb55b50cfa17f4 100644 (file)
  */
 
 #include "AUD_DoubleReader.h"
-#include "AUD_Buffer.h"
 
 #include <cstring>
 
 AUD_DoubleReader::AUD_DoubleReader(AUD_IReader* reader1,
                                                                   AUD_IReader* reader2) :
-               m_reader1(reader1), m_reader2(reader2)
+               m_reader1(reader1), m_reader2(reader2), m_finished1(false)
 {
-       try
+       AUD_Specs s1, s2;
+       s1 = reader1->getSpecs();
+       s2 = reader2->getSpecs();
+       if(memcmp(&s1, &s2, sizeof(AUD_Specs)) != 0)
        {
-               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;
+               delete reader1;
+               delete reader2;
+               AUD_THROW(AUD_ERROR_READER);
        }
-
-       m_buffer = new AUD_Buffer(); AUD_NEW("buffer")
-       m_finished1 = false;
 }
 
 AUD_DoubleReader::~AUD_DoubleReader()
 {
-       delete m_reader1; AUD_DELETE("reader")
-       delete m_reader2; AUD_DELETE("reader")
-       delete m_buffer; AUD_DELETE("buffer")
+       delete m_reader1;
+       delete m_reader2;
 }
 
-bool AUD_DoubleReader::isSeekable()
+bool AUD_DoubleReader::isSeekable() const
 {
-       return false;
+       return m_reader1->isSeekable() && m_reader2->isSeekable();
 }
 
 void AUD_DoubleReader::seek(int position)
 {
-       int length1 = m_reader1->getLength();
+       m_reader1->seek(position);
 
-       if(position < 0)
-               position = 0;
+       int pos1 = m_reader1->getPosition();
 
-       if(position < length1)
-       {
-               m_reader1->seek(position);
-               m_reader2->seek(0);
-               m_finished1 = false;
-       }
+       if((m_finished1 = (pos1 < position)))
+               m_reader2->seek(position - pos1);
        else
-       {
-               m_reader2->seek(position-length1);
-               m_finished1 = true;
-       }
+               m_reader2->seek(0);
 }
 
-int AUD_DoubleReader::getLength()
+int AUD_DoubleReader::getLength() const
 {
        int len1 = m_reader1->getLength();
        int len2 = m_reader2->getLength();
@@ -106,49 +74,45 @@ int AUD_DoubleReader::getLength()
        return len1 + len2;
 }
 
-int AUD_DoubleReader::getPosition()
+int AUD_DoubleReader::getPosition() const
 {
        return m_reader1->getPosition() + m_reader2->getPosition();
 }
 
-AUD_Specs AUD_DoubleReader::getSpecs()
+AUD_Specs AUD_DoubleReader::getSpecs() const
 {
        return m_reader1->getSpecs();
 }
 
-AUD_ReaderType AUD_DoubleReader::getType()
-{
-       if(m_reader1->getType() == AUD_TYPE_BUFFER &&
-          m_reader2->getType() == AUD_TYPE_BUFFER)
-               return AUD_TYPE_BUFFER;
-       return AUD_TYPE_STREAM;
-}
-
-bool AUD_DoubleReader::notify(AUD_Message &message)
-{
-       return m_reader1->notify(message) | m_reader2->notify(message);
-}
-
 void AUD_DoubleReader::read(int & length, sample_t* & buffer)
 {
        if(!m_finished1)
        {
                int len = length;
                m_reader1->read(len, buffer);
+
                if(len < length)
                {
                        AUD_Specs specs = m_reader1->getSpecs();
                        int samplesize = AUD_SAMPLE_SIZE(specs);
-                       if(m_buffer->getSize() < length * samplesize)
-                               m_buffer->resize(length * samplesize);
-                       memcpy(m_buffer->getBuffer(), buffer, len * samplesize);
+
+                       if(m_buffer.getSize() < length * samplesize)
+                               m_buffer.resize(length * samplesize);
+
+                       sample_t* buf = buffer;
+                       buffer = m_buffer.getBuffer();
+
+                       memcpy(buffer, buf, len * samplesize);
+
                        len = length - len;
                        length -= len;
-                       m_reader2->read(len, buffer);
-                       memcpy(m_buffer->getBuffer() + length * specs.channels, buffer,
+                       m_reader2->read(len, buf);
+
+                       memcpy(buffer + length * specs.channels, buf,
                                   len * samplesize);
+
                        length += len;
-                       buffer = m_buffer->getBuffer();
+
                        m_finished1 = true;
                }
        }
index d82b81ec0baa93b61afdd80567ec1f0ca5e95670..d80ba33dfe3af263b2774c52f22e53ec37734b99 100644 (file)
@@ -27,7 +27,7 @@
 #define AUD_DOUBLEREADER
 
 #include "AUD_IReader.h"
-class AUD_Buffer;
+#include "AUD_Buffer.h"
 
 /**
  * This reader plays two readers with the same specs sequently.
@@ -53,15 +53,18 @@ private:
        /**
         * The playback buffer for the intersecting part.
         */
-       AUD_Buffer* m_buffer;
+       AUD_Buffer m_buffer;
+
+       // hide copy constructor and operator=
+       AUD_DoubleReader(const AUD_DoubleReader&);
+       AUD_DoubleReader& operator=(const AUD_DoubleReader&);
 
 public:
        /**
         * Creates a new ping pong 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.
+        * \exception AUD_Exception Thrown if the specs from the readers differ.
         */
        AUD_DoubleReader(AUD_IReader* reader1, AUD_IReader* reader2);
 
@@ -70,13 +73,11 @@ public:
         */
        virtual ~AUD_DoubleReader();
 
-       virtual bool isSeekable();
+       virtual bool isSeekable() const;
        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 int getLength() const;
+       virtual int getPosition() const;
+       virtual AUD_Specs getSpecs() const;
        virtual void read(int & length, sample_t* & buffer);
 };
 
index 882499416b7cd49424ce723765b7469687fec444..eda4e4e04b2ea7c87340189645a5328ecbd66e3d 100644 (file)
 #include "AUD_EffectFactory.h"
 #include "AUD_IReader.h"
 
-AUD_IReader* AUD_EffectFactory::getReader()
-{
-       if(m_factory != 0)
-               return m_factory->createReader();
-
-       return 0;
-}
-
 AUD_EffectFactory::AUD_EffectFactory(AUD_IFactory* factory)
 {
        m_factory = factory;
 }
 
-void AUD_EffectFactory::setFactory(AUD_IFactory* factory)
+AUD_EffectFactory::~AUD_EffectFactory()
 {
-       m_factory = factory;
 }
 
-AUD_IFactory* AUD_EffectFactory::getFactory()
+AUD_IFactory* AUD_EffectFactory::getFactory() const
 {
        return m_factory;
 }
index 67259b9e6c3dffd0f9e636bcb633b39e918c1283..fd3746d0da3f5189f8f00b84c56aea4469ff1afb 100644 (file)
  */
 class AUD_EffectFactory : public AUD_IFactory
 {
+private:
+       // hide copy constructor and operator=
+       AUD_EffectFactory(const AUD_EffectFactory&);
+       AUD_EffectFactory& operator=(const AUD_EffectFactory&);
+
 protected:
        /**
         * If there is no reader it is created out of this factory.
@@ -44,9 +49,12 @@ protected:
         * Returns the reader created out of the factory.
         * This method can be used for the createReader function of the implementing
         * classes.
-        * \return The reader created out of the factory or NULL if there is none.
+        * \return The reader created out of the factory.
         */
-       AUD_IReader* getReader();
+       inline AUD_IReader* getReader() const
+       {
+               return m_factory->createReader();
+       }
 
 public:
        /**
@@ -58,19 +66,13 @@ public:
        /**
         * Destroys the factory.
         */
-       virtual ~AUD_EffectFactory() {}
-
-       /**
-        * Sets the input factory.
-        * \param factory The input factory.
-        */
-       void setFactory(AUD_IFactory* factory);
+       virtual ~AUD_EffectFactory();
 
        /**
         * Returns the saved factory.
         * \return The factory or NULL if there has no factory been saved.
         */
-       AUD_IFactory* getFactory();
+       AUD_IFactory* getFactory() const;
 };
 
 #endif //AUD_EFFECTFACTORY
index 47026b88440b3fabdac7c559961d433cf6ad111e..b54ca279088fe62718b2e82afa6349c2418e651d 100644 (file)
 
 AUD_EffectReader::AUD_EffectReader(AUD_IReader* reader)
 {
-       if(!reader)
-               AUD_THROW(AUD_ERROR_READER);
        m_reader = reader;
 }
 
 AUD_EffectReader::~AUD_EffectReader()
 {
-       delete m_reader; AUD_DELETE("reader")
+       delete m_reader;
 }
 
-bool AUD_EffectReader::isSeekable()
+bool AUD_EffectReader::isSeekable() const
 {
        return m_reader->isSeekable();
 }
@@ -47,31 +45,21 @@ void AUD_EffectReader::seek(int position)
        m_reader->seek(position);
 }
 
-int AUD_EffectReader::getLength()
+int AUD_EffectReader::getLength() const
 {
        return m_reader->getLength();
 }
 
-int AUD_EffectReader::getPosition()
+int AUD_EffectReader::getPosition() const
 {
        return m_reader->getPosition();
 }
 
-AUD_Specs AUD_EffectReader::getSpecs()
+AUD_Specs AUD_EffectReader::getSpecs() const
 {
        return m_reader->getSpecs();
 }
 
-AUD_ReaderType AUD_EffectReader::getType()
-{
-       return m_reader->getType();
-}
-
-bool AUD_EffectReader::notify(AUD_Message &message)
-{
-       return m_reader->notify(message);
-}
-
 void AUD_EffectReader::read(int & length, sample_t* & buffer)
 {
        m_reader->read(length, buffer);
index f64bf34077ddd579398dd61b5bcd8f91d219674d..c447f79bc6ec8d39f8b7283352af5f233c561f1d 100644 (file)
  */
 class AUD_EffectReader : public AUD_IReader
 {
+private:
+       // hide copy constructor and operator=
+       AUD_EffectReader(const AUD_EffectReader&);
+       AUD_EffectReader& operator=(const AUD_EffectReader&);
+
 protected:
        /**
         * The reader to read from.
@@ -44,7 +49,6 @@ public:
        /**
         * Creates a new effect reader.
         * \param reader The reader to read from.
-        * \exception AUD_Exception Thrown if the reader specified is NULL.
         */
        AUD_EffectReader(AUD_IReader* reader);
 
@@ -53,13 +57,11 @@ public:
         */
        virtual ~AUD_EffectReader();
 
-       virtual bool isSeekable();
+       virtual bool isSeekable() const;
        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 int getLength() const;
+       virtual int getPosition() const;
+       virtual AUD_Specs getSpecs() const;
        virtual void read(int & length, sample_t* & buffer);
 };
 
index c3b2c3f24fe4b0867e7be421c5cca8d5804fc369..1c625067f1c59ff88520f063536cecb71bd2d8b9 100644 (file)
@@ -33,26 +33,12 @@ AUD_EnvelopeFactory::AUD_EnvelopeFactory(AUD_IFactory* factory, float attack,
                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()
+               m_arthreshold(arthreshold)
 {
-       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;
+AUD_IReader* AUD_EnvelopeFactory::createReader() const
+{
+       return new AUD_EnvelopeReader(getReader(), m_attack, m_release, m_threshold,
+                                                                 m_arthreshold);
 }
index c79e5472e30609ab4f81aa8863d229d872090729..c31c6727d0370a827202ce1c9be65ab3ceb2c5f0 100644 (file)
@@ -37,22 +37,26 @@ private:
        /**
         * The attack value in seconds.
         */
-       float m_attack;
+       const float m_attack;
 
        /**
         * The release value in seconds.
         */
-       float m_release;
+       const float m_release;
 
        /**
         * The threshold value.
         */
-       float m_threshold;
+       const float m_threshold;
 
        /**
         * The attack/release threshold value.
         */
-       float m_arthreshold;
+       const float m_arthreshold;
+
+       // hide copy constructor and operator=
+       AUD_EnvelopeFactory(const AUD_EnvelopeFactory&);
+       AUD_EnvelopeFactory& operator=(const AUD_EnvelopeFactory&);
 
 public:
        /**
@@ -66,17 +70,7 @@ public:
        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();
+       virtual AUD_IReader* createReader() const;
 };
 
 #endif //AUD_ENVELOPEFACTORY
index 71ccbfd6503d4f4dbe4882755a8e3fe7fa07b71a..ef64b6fa4eb4342f195e4a45e78b19f8a854271b 100644 (file)
@@ -24,7 +24,6 @@
  */
 
 #include "AUD_EnvelopeReader.h"
-#include "AUD_Buffer.h"
 
 #include <cstring>
 #include <cmath>
@@ -33,40 +32,27 @@ AUD_EnvelopeReader::AUD_EnvelopeReader(AUD_IReader* reader, float attack,
                                                                           float release, float threshold,
                                                                           float arthreshold) :
                AUD_EffectReader(reader),
-               m_threshold(threshold)
+               m_bAttack(pow(arthreshold, 1.0f/(reader->getSpecs().rate * attack))),
+               m_bRelease(pow(arthreshold, 1.0f/(reader->getSpecs().rate * release))),
+               m_threshold(threshold),
+               m_envelopes(AUD_SAMPLE_SIZE(reader->getSpecs()))
 {
-       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")
+       memset(m_envelopes.getBuffer(), 0, m_envelopes.getSize());
 }
 
 void AUD_EnvelopeReader::read(int & length, sample_t* & buffer)
 {
        sample_t* buf;
        sample_t* envelopes;
-       envelopes = m_envelopes->getBuffer();
+       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));
+       if(m_buffer.getSize() < length * AUD_SAMPLE_SIZE(specs))
+               m_buffer.resize(length * AUD_SAMPLE_SIZE(specs));
 
-       buffer = m_buffer->getBuffer();
+       buffer = m_buffer.getBuffer();
 
        sample_t value;
 
index ff9dd23d34cd224edd1e407b63d3146934bce07c..b452ee2119a18a60e7ee037b1554abaecde60d11 100644 (file)
@@ -27,7 +27,7 @@
 #define AUD_ENVELOPEREADER
 
 #include "AUD_EffectReader.h"
-class AUD_Buffer;
+#include "AUD_Buffer.h"
 
 /**
  * This class represents an envelope follower.
@@ -36,29 +36,33 @@ class AUD_EnvelopeReader : public AUD_EffectReader
 {
 private:
        /**
-        * The playback buffer.
+        * Attack b value.
         */
-       AUD_Buffer *m_buffer;
+       const float m_bAttack;
 
        /**
-        * The last envelopes buffer.
+        * Release b value.
         */
-       AUD_Buffer *m_envelopes;
+       const float m_bRelease;
 
        /**
-        * Attack b value.
+        * Threshold value.
         */
-       float m_bAttack;
+       const float m_threshold;
 
        /**
-        * Release b value.
+        * The playback buffer.
         */
-       float m_bRelease;
+       AUD_Buffer m_buffer;
 
        /**
-        * Threshold value.
+        * The last envelopes buffer.
         */
-       float m_threshold;
+       AUD_Buffer m_envelopes;
+
+       // hide copy constructor and operator=
+       AUD_EnvelopeReader(const AUD_EnvelopeReader&);
+       AUD_EnvelopeReader& operator=(const AUD_EnvelopeReader&);
 
 public:
        /**
@@ -68,16 +72,10 @@ public:
         * \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);
 };
 
index 4357e11bd4396d76dbdce211bcf3c44315a99f3a..bbe9319c928cf927215fee5ea8f6b51c151ea373 100644 (file)
@@ -31,54 +31,26 @@ AUD_FaderFactory::AUD_FaderFactory(AUD_IFactory* factory, AUD_FadeType type,
                AUD_EffectFactory(factory),
                m_type(type),
                m_start(start),
-               m_length(length) {}
-
-AUD_FaderFactory::AUD_FaderFactory(AUD_FadeType type,
-                                                                  float start, float length) :
-               AUD_EffectFactory(0),
-               m_type(type),
-               m_start(start),
-               m_length(length) {}
-
-AUD_FadeType AUD_FaderFactory::getType()
+               m_length(length)
 {
-       return m_type;
 }
 
-void AUD_FaderFactory::setType(AUD_FadeType type)
+AUD_FadeType AUD_FaderFactory::getType() const
 {
-       m_type = type;
+       return m_type;
 }
 
-float AUD_FaderFactory::getStart()
+float AUD_FaderFactory::getStart() const
 {
        return m_start;
 }
 
-void AUD_FaderFactory::setStart(float start)
-{
-       m_start = start;
-}
-
-float AUD_FaderFactory::getLength()
+float AUD_FaderFactory::getLength() const
 {
        return m_length;
 }
 
-void AUD_FaderFactory::setLength(float length)
+AUD_IReader* AUD_FaderFactory::createReader() const
 {
-       m_length = length;
-}
-
-AUD_IReader* AUD_FaderFactory::createReader()
-{
-       AUD_IReader* reader = getReader();
-
-       if(reader != 0)
-       {
-               reader = new AUD_FaderReader(reader, m_type, m_start, m_length);
-               AUD_NEW("reader")
-       }
-
-       return reader;
+       return new AUD_FaderReader(getReader(), m_type, m_start, m_length);
 }
index 4999ccac8f1135ca9b7b21a672ee72efa1ffc8d8..af5d18538eae625fea7845ec752407a8261fe250 100644 (file)
@@ -39,17 +39,21 @@ private:
        /**
         * The fading type.
         */
-       AUD_FadeType m_type;
+       const AUD_FadeType m_type;
 
        /**
         * The fading start.
         */
-       float m_start;
+       const float m_start;
 
        /**
         * The fading length.
         */
-       float m_length;
+       const float m_length;
+
+       // hide copy constructor and operator=
+       AUD_FaderFactory(const AUD_FaderFactory&);
+       AUD_FaderFactory& operator=(const AUD_FaderFactory&);
 
 public:
        /**
@@ -59,53 +63,26 @@ public:
         * \param start The time where fading should start in seconds.
         * \param length How long fading should last in seconds.
         */
-       AUD_FaderFactory(AUD_IFactory* factory = 0,
+       AUD_FaderFactory(AUD_IFactory* factory,
                                          AUD_FadeType type = AUD_FADE_IN,
                                          float start = 0.0f, float length = 1.0f);
 
-       /**
-        * Creates a new fader factory.
-        * \param type The fading type.
-        * \param start The time where fading should start in seconds.
-        * \param length How long fading should last in seconds.
-        */
-       AUD_FaderFactory(AUD_FadeType type = AUD_FADE_IN,
-                                         float start = 0.0f, float length = 1.0f);
-
        /**
         * Returns the fading type.
         */
-       AUD_FadeType getType();
-
-       /**
-        * Sets the fading type.
-        * \param type The new fading type: AUD_FADE_IN or AUD_FADE_OUT.
-        */
-       void setType(AUD_FadeType type);
+       AUD_FadeType getType() const;
 
        /**
         * Returns the fading start.
         */
-       float getStart();
-
-       /**
-        * Sets the fading start.
-        * \param start The new fading start.
-        */
-       void setStart(float start);
+       float getStart() const;
 
        /**
         * Returns the fading length.
         */
-       float getLength();
-
-       /**
-        * Sets the fading length.
-        * \param start The new fading length.
-        */
-       void setLength(float length);
+       float getLength() const;
 
-       virtual AUD_IReader* createReader();
+       virtual AUD_IReader* createReader() const;
 };
 
 #endif //AUD_FADERFACTORY
index 4e919fff323f86e60c10937933012292969d5671..2292fa06102f97b635a179c8c174712e6f22da6a 100644 (file)
@@ -24,7 +24,6 @@
  */
 
 #include "AUD_FaderReader.h"
-#include "AUD_Buffer.h"
 
 #include <cstring>
 
@@ -33,19 +32,9 @@ AUD_FaderReader::AUD_FaderReader(AUD_IReader* reader, AUD_FadeType type,
                AUD_EffectReader(reader),
                m_type(type),
                m_start(start),
-               m_length(length)
+               m_length(length),
+               m_empty(true)
 {
-       m_buffer = new AUD_Buffer(); AUD_NEW("buffer")
-}
-
-AUD_FaderReader::~AUD_FaderReader()
-{
-       delete m_buffer; AUD_DELETE("buffer")
-}
-
-bool AUD_FaderReader::notify(AUD_Message &message)
-{
-       return m_reader->notify(message);
 }
 
 void AUD_FaderReader::read(int & length, sample_t* & buffer)
@@ -56,28 +45,50 @@ void AUD_FaderReader::read(int & length, sample_t* & buffer)
 
        m_reader->read(length, buffer);
 
-       if(m_buffer->getSize() < length * samplesize)
-               m_buffer->resize(length * samplesize);
-
        if((position + length) / (float)specs.rate <= m_start)
        {
                if(m_type != AUD_FADE_OUT)
                {
-                       buffer = m_buffer->getBuffer();
-                       memset(buffer, 0, length * samplesize);
+                       if(m_buffer.getSize() < length * samplesize)
+                       {
+                               m_buffer.resize(length * samplesize);
+                               m_empty = false;
+                       }
+
+                       buffer = m_buffer.getBuffer();
+
+                       if(!m_empty)
+                       {
+                               memset(buffer, 0, length * samplesize);
+                               m_empty = true;
+                       }
                }
        }
        else if(position / (float)specs.rate >= m_start+m_length)
        {
                if(m_type == AUD_FADE_OUT)
                {
-                       buffer = m_buffer->getBuffer();
-                       memset(buffer, 0, length * samplesize);
+                       if(m_buffer.getSize() < length * samplesize)
+                       {
+                               m_buffer.resize(length * samplesize);
+                               m_empty = false;
+                       }
+
+                       buffer = m_buffer.getBuffer();
+
+                       if(!m_empty)
+                       {
+                               memset(buffer, 0, length * samplesize);
+                               m_empty = true;
+                       }
                }
        }
        else
        {
-               sample_t* buf = m_buffer->getBuffer();
+               if(m_buffer.getSize() < length * samplesize)
+                       m_buffer.resize(length * samplesize);
+
+               sample_t* buf = m_buffer.getBuffer();
                float volume = 1.0f;
 
                for(int i = 0; i < length * specs.channels; i++)
@@ -98,5 +109,6 @@ void AUD_FaderReader::read(int & length, sample_t* & buffer)
                }
 
                buffer = buf;
+               m_empty = false;
        }
 }
index a75ac6e7a47553da010ed79e9aa68d80a142a3a1..d9d685af956b605f53398b81cda127d2224a7714 100644 (file)
@@ -27,7 +27,7 @@
 #define AUD_FADERREADER
 
 #include "AUD_EffectReader.h"
-class AUD_Buffer;
+#include "AUD_Buffer.h"
 
 /**
  * This class fades another reader.
@@ -37,25 +37,34 @@ class AUD_Buffer;
 class AUD_FaderReader : public AUD_EffectReader
 {
 private:
-       /**
-        * The playback buffer.
-        */
-       AUD_Buffer *m_buffer;
-
        /**
         * The fading type.
         */
-       AUD_FadeType m_type;
+       const AUD_FadeType m_type;
 
        /**
         * The fading start.
         */
-       float m_start;
+       const float m_start;
 
        /**
         * The fading length.
         */
-       float m_length;
+       const float m_length;
+
+       /**
+        * The playback buffer.
+        */
+       AUD_Buffer m_buffer;
+
+       /**
+        * Whether the buffer is empty.
+        */
+       bool m_empty;
+
+       // hide copy constructor and operator=
+       AUD_FaderReader(const AUD_FaderReader&);
+       AUD_FaderReader& operator=(const AUD_FaderReader&);
 
 public:
        /**
@@ -63,17 +72,10 @@ public:
         * \param type The fading type.
         * \param start The time where fading should start in seconds.
         * \param length How long fading should last in seconds.
-        * \exception AUD_Exception Thrown if the reader specified is NULL.
         */
        AUD_FaderReader(AUD_IReader* reader, AUD_FadeType type,
                                        float start,float length);
 
-       /**
-        * Destroys the reader.
-        */
-       virtual ~AUD_FaderReader();
-
-       virtual bool notify(AUD_Message &message);
        virtual void read(int & length, sample_t* & buffer);
 };
 
index 384d36beab729ddf5835c91d1bc1ea11f16a091f..1ab5237c8ffb29e8f36ca23c382ee75313e0d5b2 100644 (file)
@@ -30,22 +30,11 @@ 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()
+               m_Q(Q)
 {
-       AUD_IReader* reader = getReader();
-
-       if(reader != 0)
-       {
-               reader = new AUD_HighpassReader(reader, m_frequency, m_Q);
-               AUD_NEW("reader")
-       }
+}
 
-       return reader;
+AUD_IReader* AUD_HighpassFactory::createReader() const
+{
+       return new AUD_HighpassReader(getReader(), m_frequency, m_Q);
 }
index 5e31053ed6c809677bee12cd6133faaf485eec15..1220157a776bf7d8d6cacbe49b8aac6f6efb4296 100644 (file)
@@ -37,12 +37,16 @@ private:
        /**
         * The attack value in seconds.
         */
-       float m_frequency;
+       const float m_frequency;
 
        /**
         * The Q factor.
         */
-       float m_Q;
+       const float m_Q;
+
+       // hide copy constructor and operator=
+       AUD_HighpassFactory(const AUD_HighpassFactory&);
+       AUD_HighpassFactory& operator=(const AUD_HighpassFactory&);
 
 public:
        /**
@@ -53,14 +57,7 @@ public:
         */
        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();
+       virtual AUD_IReader* createReader() const;
 };
 
 #endif //AUD_HIGHPASSFACTORY
index 36b1bb8082e8b2e3b684cb21d25b4e7fd0eaaf6c..904d6a95867f46d386fa876ac36c23bcb8a23f46 100644 (file)
@@ -24,7 +24,6 @@
  */
 
 #include "AUD_HighpassReader.h"
-#include "AUD_Buffer.h"
 
 #include <cstring>
 #include <cmath>
 
 AUD_HighpassReader::AUD_HighpassReader(AUD_IReader* reader, float frequency,
                                                                           float Q) :
-               AUD_EffectReader(reader)
+               AUD_EffectReader(reader),
+               m_outvalues(AUD_SAMPLE_SIZE(reader->getSpecs()) * AUD_HIGHPASS_ORDER),
+               m_invalues(AUD_SAMPLE_SIZE(reader->getSpecs()) * AUD_HIGHPASS_ORDER),
+               m_position(0)
 {
-       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);
+       memset(m_outvalues.getBuffer(), 0, m_outvalues.getSize());
+       memset(m_invalues.getBuffer(), 0, m_invalues.getSize());
 
-       m_invalues = new AUD_Buffer(samplesize * AUD_HIGHPASS_ORDER);
-       AUD_NEW("buffer")
-       memset(m_invalues->getBuffer(), 0, samplesize * AUD_HIGHPASS_ORDER);
-
-       m_position = 0;
+       AUD_Specs specs = reader->getSpecs();
 
        // calculate coefficients
        float w0 = 2 * M_PI * frequency / specs.rate;
@@ -65,31 +57,23 @@ AUD_HighpassReader::AUD_HighpassReader(AUD_IReader* reader, float frequency,
        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();
+       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));
+       if(m_buffer.getSize() < length * AUD_SAMPLE_SIZE(specs))
+               m_buffer.resize(length * AUD_SAMPLE_SIZE(specs));
 
-       buffer = m_buffer->getBuffer();
+       buffer = m_buffer.getBuffer();
        int channels = specs.channels;
 
        for(int channel = 0; channel < channels; channel++)
index dc28a62e45bd46fde0f7196b8925095efb4ee4bc..845e764ac9f0d5474c7ac8082411f1da08c6e2b2 100644 (file)
@@ -27,7 +27,7 @@
 #define AUD_HIGHPASSREADER
 
 #include "AUD_EffectReader.h"
-class AUD_Buffer;
+#include "AUD_Buffer.h"
 
 #define AUD_HIGHPASS_ORDER 3
 
@@ -40,17 +40,17 @@ private:
        /**
         * The playback buffer.
         */
-       AUD_Buffer *m_buffer;
+       AUD_Buffer m_buffer;
 
        /**
         * The last out values buffer.
         */
-       AUD_Buffer *m_outvalues;
+       AUD_Buffer m_outvalues;
 
        /**
         * The last in values buffer.
         */
-       AUD_Buffer *m_invalues;
+       AUD_Buffer m_invalues;
 
        /**
         * The position for buffer cycling.
@@ -62,21 +62,19 @@ private:
         */
        float m_coeff[2][AUD_HIGHPASS_ORDER];
 
+       // hide copy constructor and operator=
+       AUD_HighpassReader(const AUD_HighpassReader&);
+       AUD_HighpassReader& operator=(const AUD_HighpassReader&);
+
 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);
 };
 
index 6f19575240a9ccf2e25eed4338f3b41f13f93fe8..75501afcec329d0f62421cbc627e23c93de3d3f8 100644 (file)
@@ -31,37 +31,21 @@ AUD_LimiterFactory::AUD_LimiterFactory(AUD_IFactory* factory,
                                                                           float start, float end) :
                AUD_EffectFactory(factory),
                m_start(start),
-               m_end(end) {}
-
-float AUD_LimiterFactory::getStart()
+               m_end(end)
 {
-       return m_start;
 }
 
-void AUD_LimiterFactory::setStart(float start)
+float AUD_LimiterFactory::getStart() const
 {
-       m_start = start;
+       return m_start;
 }
 
-float AUD_LimiterFactory::getEnd()
+float AUD_LimiterFactory::getEnd() const
 {
        return m_end;
 }
 
-void AUD_LimiterFactory::setEnd(float end)
-{
-       m_end = end;
-}
-
-AUD_IReader* AUD_LimiterFactory::createReader()
+AUD_IReader* AUD_LimiterFactory::createReader() const
 {
-       AUD_IReader* reader = getReader();
-
-       if(reader != 0)
-       {
-               reader = new AUD_LimiterReader(reader, m_start, m_end);
-               AUD_NEW("reader")
-       }
-
-       return reader;
+       return new AUD_LimiterReader(getReader(), m_start, m_end);
 }
index 588fea6eb4b3176c63fc0a1ed8d5d4db70ac568e..5d9491f60aaf7e00d477e35647cdf8d5102336bb 100644 (file)
@@ -37,12 +37,16 @@ private:
        /**
         * The start time.
         */
-       float m_start;
+       const float m_start;
 
        /**
         * The end time.
         */
-       float m_end;
+       const float m_end;
+
+       // hide copy constructor and operator=
+       AUD_LimiterFactory(const AUD_LimiterFactory&);
+       AUD_LimiterFactory& operator=(const AUD_LimiterFactory&);
 
 public:
        /**
@@ -52,33 +56,20 @@ public:
         * \param end The desired end time, a negative value signals that it should
         *            play to the end.
         */
-       AUD_LimiterFactory(AUD_IFactory* factory = 0,
+       AUD_LimiterFactory(AUD_IFactory* factory,
                                           float start = 0, float end = -1);
 
        /**
         * Returns the start time.
         */
-       float getStart();
-
-       /**
-        * Sets the start time.
-        * \param start The new start time.
-        */
-       void setStart(float start);
+       float getStart() const;
 
        /**
         * Returns the end time.
         */
-       float getEnd();
-
-       /**
-        * Sets the end time.
-        * \param end The new end time, a negative value signals that it should play
-        *            to the end.
-        */
-       void setEnd(float end);
+       float getEnd() const;
 
-       virtual AUD_IReader* createReader();
+       virtual AUD_IReader* createReader() const;
 };
 
 #endif //AUD_LIMITERFACTORY
index 05882369001804c258c703a657c6ddb2a681ba55..dd7301213c938e7d855812bb6b03e44faed3286f 100644 (file)
 
 AUD_LimiterReader::AUD_LimiterReader(AUD_IReader* reader,
                                                                         float start, float end) :
-               AUD_EffectReader(reader)
+               AUD_EffectReader(reader),
+               m_start(int(start * reader->getSpecs().rate)),
+               m_end(int(end * reader->getSpecs().rate))
 {
-       m_end = (int)(end * reader->getSpecs().rate);
-
-       if(start <= 0)
-               m_start = 0;
-       else
+       if(m_start > 0)
        {
-               m_start = (int)(start * reader->getSpecs().rate);
                if(m_reader->isSeekable())
                        m_reader->seek(m_start);
                else
                {
                        // skip first m_start samples by reading them
-                       int length;
+                       int length = AUD_DEFAULT_BUFFER_SIZE;
                        sample_t* buffer;
-                       for(int i = m_start;
-                               i >= AUD_DEFAULT_BUFFER_SIZE;
-                               i -= AUD_DEFAULT_BUFFER_SIZE)
+                       for(int len = m_start;
+                               length == AUD_DEFAULT_BUFFER_SIZE;
+                               len -= AUD_DEFAULT_BUFFER_SIZE)
                        {
-                               length = AUD_DEFAULT_BUFFER_SIZE;
+                               if(len < AUD_DEFAULT_BUFFER_SIZE)
+                                       length = len;
                                m_reader->read(length, buffer);
-                               length = i;
                        }
-                       m_reader->read(length, buffer);
                }
        }
 }
@@ -64,18 +60,18 @@ void AUD_LimiterReader::seek(int position)
        m_reader->seek(position + m_start);
 }
 
-int AUD_LimiterReader::getLength()
+int AUD_LimiterReader::getLength() const
 {
        int len = m_reader->getLength();
-       if(m_reader->getType() != AUD_TYPE_BUFFER || len < 0 ||
-          (len > m_end && m_end >= 0))
+       if(len < 0 || (len > m_end && m_end >= 0))
                len = m_end;
        return len - m_start;
 }
 
-int AUD_LimiterReader::getPosition()
+int AUD_LimiterReader::getPosition() const
 {
-       return m_reader->getPosition() - m_start;
+       int pos = m_reader->getPosition();
+       return AUD_MIN(pos, m_end) - m_start;
 }
 
 void AUD_LimiterReader::read(int & length, sample_t* & buffer)
@@ -83,7 +79,7 @@ void AUD_LimiterReader::read(int & length, sample_t* & buffer)
        if(m_end >= 0)
        {
                int position = m_reader->getPosition();
-               if(position+length > m_end)
+               if(position + length > m_end)
                        length = m_end - position;
                if(length < 0)
                {
index 9921f5ee1b0f580386556d71c7898801f9473c2e..59d6096dcba26f703850bcedfbc40bcb6674f685 100644 (file)
@@ -37,12 +37,16 @@ private:
        /**
         * The start sample: inclusive.
         */
-       int m_start;
+       const int m_start;
 
        /**
         * The end sample: exlusive.
         */
-       int m_end;
+       const int m_end;
+
+       // hide copy constructor and operator=
+       AUD_LimiterReader(const AUD_LimiterReader&);
+       AUD_LimiterReader& operator=(const AUD_LimiterReader&);
 
 public:
        /**
@@ -51,13 +55,12 @@ public:
         * \param start The desired start sample (inclusive).
         * \param end The desired end sample (exklusive), a negative value signals
         *            that it should play to the end.
-        * \exception AUD_Exception Thrown if the reader specified is NULL.
         */
        AUD_LimiterReader(AUD_IReader* reader, float start = 0, float end = -1);
 
        virtual void seek(int position);
-       virtual int getLength();
-       virtual int getPosition();
+       virtual int getLength() const;
+       virtual int getPosition() const;
        virtual void read(int & length, sample_t* & buffer);
 };
 
index 90186f623ffd5a308b7512253ca83f090ad52b23..6805a8e4b426243daca32276e58e165b13483bf2 100644 (file)
 
 AUD_LoopFactory::AUD_LoopFactory(AUD_IFactory* factory, int loop) :
                AUD_EffectFactory(factory),
-               m_loop(loop) {}
-
-AUD_LoopFactory::AUD_LoopFactory(int loop) :
-               AUD_EffectFactory(0),
-               m_loop(loop) {}
-
-int AUD_LoopFactory::getLoop()
+               m_loop(loop)
 {
-       return m_loop;
 }
 
-void AUD_LoopFactory::setLoop(int loop)
+int AUD_LoopFactory::getLoop() const
 {
-       m_loop = loop;
+       return m_loop;
 }
 
-AUD_IReader* AUD_LoopFactory::createReader()
+AUD_IReader* AUD_LoopFactory::createReader() const
 {
-       AUD_IReader* reader = getReader();
-
-       if(reader != 0)
-       {
-               reader = new AUD_LoopReader(reader, m_loop); AUD_NEW("reader")
-       }
-
-       return reader;
+       return new AUD_LoopReader(getReader(), m_loop);
 }
index c81d906b82e61b54e8351d39cb02370dce7c35d9..f9e358af52d555e6ce68db22b7185f0fc3d6297b 100644 (file)
@@ -38,7 +38,11 @@ private:
        /**
         * The loop count.
         */
-       int m_loop;
+       const int m_loop;
+
+       // hide copy constructor and operator=
+       AUD_LoopFactory(const AUD_LoopFactory&);
+       AUD_LoopFactory& operator=(const AUD_LoopFactory&);
 
 public:
        /**
@@ -47,28 +51,14 @@ public:
         * \param loop The desired loop count, negative values result in endless
         *        looping.
         */
-       AUD_LoopFactory(AUD_IFactory* factory = 0, int loop = -1);
-
-       /**
-        * Creates a new loop factory.
-        * \param loop The desired loop count, negative values result in endless
-        *        looping.
-        */
-       AUD_LoopFactory(int loop);
+       AUD_LoopFactory(AUD_IFactory* factory, int loop = -1);
 
        /**
         * Returns the loop count.
         */
-       int getLoop();
-
-       /**
-        * Sets the loop count.
-        * \param loop The desired loop count, negative values result in endless
-        *        looping.
-        */
-       void setLoop(int loop);
+       int getLoop() const;
 
-       virtual AUD_IReader* createReader();
+       virtual AUD_IReader* createReader() const;
 };
 
 #endif //AUD_LOOPFACTORY
index 3bcd8c2f9d32e4484bc117b1569dd315dbeb0848..7521f914a5c3bf7f61abf0c98e4e387e1c0553ab 100644 (file)
 #include <cstring>
 
 AUD_LoopReader::AUD_LoopReader(AUD_IReader* reader, int loop) :
-               AUD_EffectReader(reader), m_loop(loop)
+               AUD_EffectReader(reader), m_count(loop), m_left(loop)
 {
-       m_samples = -1;
-       m_buffer = new AUD_Buffer(); AUD_NEW("buffer")
 }
 
-AUD_LoopReader::~AUD_LoopReader()
+void AUD_LoopReader::seek(int position)
 {
-       delete m_buffer; AUD_DELETE("buffer")
+       int len = m_reader->getLength();
+       if(len < 0)
+               m_reader->seek(position);
+       else
+       {
+               if(m_count >= 0)
+               {
+                       m_left = m_count - (position / len);
+                       if(m_left < 0)
+                               m_left = 0;
+               }
+               m_reader->seek(position % len);
+       }
 }
 
-AUD_ReaderType AUD_LoopReader::getType()
+int AUD_LoopReader::getLength() const
 {
-       if(m_loop < 0)
-               return AUD_TYPE_STREAM;
-       return m_reader->getType();
+       if(m_count < 0)
+               return -1;
+       return m_reader->getLength() * m_count;
 }
 
-bool AUD_LoopReader::notify(AUD_Message &message)
+int AUD_LoopReader::getPosition() const
 {
-       if(message.type == AUD_MSG_LOOP)
-       {
-               m_loop = message.loopcount;
-               m_samples = message.time * m_reader->getSpecs().rate;
-
-               m_reader->notify(message);
-
-               return true;
-       }
-       return m_reader->notify(message);
+       return m_reader->getPosition() * (m_count < 0 ? 1 : m_count);
 }
 
 void AUD_LoopReader::read(int & length, sample_t* & buffer)
@@ -66,50 +67,44 @@ void AUD_LoopReader::read(int & length, sample_t* & buffer)
        AUD_Specs specs = m_reader->getSpecs();
        int samplesize = AUD_SAMPLE_SIZE(specs);
 
-       if(m_samples >= 0)
-       {
-               if(length > m_samples)
-                       length = m_samples;
-               m_samples -= length;
-       }
-
        int len = length;
 
        m_reader->read(len, buffer);
 
-       if(len < length && m_loop != 0)
+       if(len < length && m_left)
        {
                int pos = 0;
 
-               if(m_buffer->getSize() < length * samplesize)
-                       m_buffer->resize(length * samplesize);
+               if(m_buffer.getSize() < length * samplesize)
+                       m_buffer.resize(length * samplesize);
+
+               sample_t* buf = m_buffer.getBuffer();
 
-               memcpy(m_buffer->getBuffer() + pos * specs.channels,
-                          buffer, len * samplesize);
+               memcpy(buf + pos * specs.channels, buffer, len * samplesize);
 
                pos += len;
 
-               while(pos < length && m_loop != 0)
+               while(pos < length && m_left)
                {
-                       if(m_loop > 0)
-                               m_loop--;
+                       if(m_left > 0)
+                               m_left--;
 
                        m_reader->seek(0);
 
                        len = length - pos;
                        m_reader->read(len, buffer);
+
                        // prevent endless loop
                        if(!len)
                                break;
 
-                       memcpy(m_buffer->getBuffer() + pos * specs.channels,
-                                  buffer, len * samplesize);
+                       memcpy(buf + pos * specs.channels, buffer, len * samplesize);
 
                        pos += len;
                }
 
                length = pos;
-               buffer = m_buffer->getBuffer();
+               buffer = buf;
        }
        else
                length = len;
index e61a49cb0db39c4c13c1a7c4c7dc259f9ae4e6b0..e0ed4cb6bf33f0f9ace7ee83f97f7ccdec8c3a1e 100644 (file)
@@ -27,7 +27,7 @@
 #define AUD_LOOPREADER
 
 #include "AUD_EffectReader.h"
-class AUD_Buffer;
+#include "AUD_Buffer.h"
 
 /**
  * This class reads another reader and loops it.
@@ -39,17 +39,21 @@ private:
        /**
         * The playback buffer.
         */
-       AUD_Buffer *m_buffer;
+       AUD_Buffer m_buffer;
 
        /**
-        * The left loop count.
+        * The loop count.
         */
-       int m_loop;
+       const int m_count;
 
        /**
-        * The left samples.
+        * The left loop count.
         */
-       int m_samples;
+       int m_left;
+
+       // hide copy constructor and operator=
+       AUD_LoopReader(const AUD_LoopReader&);
+       AUD_LoopReader& operator=(const AUD_LoopReader&);
 
 public:
        /**
@@ -57,17 +61,12 @@ public:
         * \param reader The reader to read from.
         * \param loop The desired loop count, negative values result in endless
         *        looping.
-        * \exception AUD_Exception Thrown if the reader specified is NULL.
         */
        AUD_LoopReader(AUD_IReader* reader, int loop);
 
-       /**
-        * Destroys the reader.
-        */
-       virtual ~AUD_LoopReader();
-
-       virtual AUD_ReaderType getType();
-       virtual bool notify(AUD_Message &message);
+       virtual void seek(int position);
+       virtual int getLength() const;
+       virtual int getPosition() const;
        virtual void read(int & length, sample_t* & buffer);
 };
 
index 05dc5ff3994d0617031e0655b4d78f48b972c60d..dfef0f6f7c3aa1a3b4f8c756709f6e872ce67309 100644 (file)
@@ -30,22 +30,11 @@ 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()
+               m_Q(Q)
 {
-       AUD_IReader* reader = getReader();
-
-       if(reader != 0)
-       {
-               reader = new AUD_LowpassReader(reader, m_frequency, m_Q);
-               AUD_NEW("reader")
-       }
+}
 
-       return reader;
+AUD_IReader* AUD_LowpassFactory::createReader() const
+{
+       return new AUD_LowpassReader(getReader(), m_frequency, m_Q);
 }
index 8a419823de02edc1b2274996c26ead7a6b87faa8..61b76510a9e2e3f53b45643284f12b3780f289fc 100644 (file)
@@ -37,12 +37,16 @@ private:
        /**
         * The attack value in seconds.
         */
-       float m_frequency;
+       const float m_frequency;
 
        /**
         * The Q factor.
         */
-       float m_Q;
+       const float m_Q;
+
+       // hide copy constructor and operator=
+       AUD_LowpassFactory(const AUD_LowpassFactory&);
+       AUD_LowpassFactory& operator=(const AUD_LowpassFactory&);
 
 public:
        /**
@@ -53,14 +57,7 @@ public:
         */
        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();
+       virtual AUD_IReader* createReader() const;
 };
 
 #endif //AUD_LOWPASSFACTORY
index 6dc0bf66a961d35bde0bd00ff27770f85a40ab8c..71b5de1234d1424b09a3fe23de3b167a51e1b157 100644 (file)
@@ -24,7 +24,6 @@
  */
 
 #include "AUD_LowpassReader.h"
-#include "AUD_Buffer.h"
 
 #include <cstring>
 #include <cmath>
 
 AUD_LowpassReader::AUD_LowpassReader(AUD_IReader* reader, float frequency,
                                                                         float Q) :
-               AUD_EffectReader(reader)
+               AUD_EffectReader(reader),
+               m_outvalues(AUD_SAMPLE_SIZE(reader->getSpecs()) * AUD_LOWPASS_ORDER),
+               m_invalues(AUD_SAMPLE_SIZE(reader->getSpecs()) * AUD_LOWPASS_ORDER),
+               m_position(0)
 {
-       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);
+       memset(m_outvalues.getBuffer(), 0, m_outvalues.getSize());
+       memset(m_invalues.getBuffer(), 0, m_invalues.getSize());
 
-       m_invalues = new AUD_Buffer(samplesize * AUD_LOWPASS_ORDER);
-       AUD_NEW("buffer")
-       memset(m_invalues->getBuffer(), 0, samplesize * AUD_LOWPASS_ORDER);
-
-       m_position = 0;
+       AUD_Specs specs = reader->getSpecs();
 
        // calculate coefficients
        float w0 = 2 * M_PI * frequency / specs.rate;
@@ -65,31 +57,23 @@ AUD_LowpassReader::AUD_LowpassReader(AUD_IReader* reader, float frequency,
        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();
+       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));
+       if(m_buffer.getSize() < length * AUD_SAMPLE_SIZE(specs))
+               m_buffer.resize(length * AUD_SAMPLE_SIZE(specs));
 
-       buffer = m_buffer->getBuffer();
+       buffer = m_buffer.getBuffer();
        int channels = specs.channels;
 
        for(int channel = 0; channel < channels; channel++)
index a490ba52c1cfb05886386f7eaa55b6b45f6ab42e..66e4b91b78329c23eb1eea7ba5170316204c6051 100644 (file)
@@ -27,7 +27,7 @@
 #define AUD_LOWPASSREADER
 
 #include "AUD_EffectReader.h"
-class AUD_Buffer;
+#include "AUD_Buffer.h"
 
 #define AUD_LOWPASS_ORDER 3
 
@@ -40,17 +40,17 @@ private:
        /**
         * The playback buffer.
         */
-       AUD_Buffer *m_buffer;
+       AUD_Buffer m_buffer;
 
        /**
         * The last out values buffer.
         */
-       AUD_Buffer *m_outvalues;
+       AUD_Buffer m_outvalues;
 
        /**
         * The last in values buffer.
         */
-       AUD_Buffer *m_invalues;
+       AUD_Buffer m_invalues;
 
        /**
         * The position for buffer cycling.
@@ -62,21 +62,19 @@ private:
         */
        float m_coeff[2][AUD_LOWPASS_ORDER];
 
+       // hide copy constructor and operator=
+       AUD_LowpassReader(const AUD_LowpassReader&);
+       AUD_LowpassReader& operator=(const AUD_LowpassReader&);
+
 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);
 };
 
index 8b72afe05e72468c56036e02b5b6b9224155a77f..b3aaa9e80a45aaeb64321b1453d6c0247c29dd0e 100644 (file)
 #include "AUD_ReverseFactory.h"
 
 AUD_PingPongFactory::AUD_PingPongFactory(AUD_IFactory* factory) :
-               AUD_EffectFactory(factory) {}
-
-AUD_IReader* AUD_PingPongFactory::createReader()
+               AUD_EffectFactory(factory)
 {
-       if(m_factory == 0)
-               return 0;
+}
 
-       AUD_IReader* reader = m_factory->createReader();
+AUD_IReader* AUD_PingPongFactory::createReader() const
+{
+       AUD_IReader* reader = getReader();
+       AUD_IReader* reader2;
+       AUD_ReverseFactory factory(m_factory);
 
-       if(reader != 0)
+       try
        {
-               AUD_IReader* reader2;
-               AUD_ReverseFactory factory(m_factory);
-
-               try
-               {
-                       reader2 = factory.createReader();
-               }
-               catch(AUD_Exception)
-               {
-                       reader2 = 0;
-               }
-
-               if(reader2 != 0)
-               {
-                       reader = new AUD_DoubleReader(reader, reader2);
-                       AUD_NEW("reader")
-               }
-               else
-               {
-                       delete reader; AUD_DELETE("reader")
-                       reader = 0;
-               }
+               reader2 = factory.createReader();
+       }
+       catch(AUD_Exception&)
+       {
+               delete reader;
+               throw;
        }
 
-       return reader;
+       return new AUD_DoubleReader(reader, reader2);
 }
index 1bf5d5e2508011caae0393274c8c9aa4f254f6f9..82aedca8f7f7825cf23f81295adbd426457701d6 100644 (file)
  */
 class AUD_PingPongFactory : public AUD_EffectFactory
 {
+private:
+       // hide copy constructor and operator=
+       AUD_PingPongFactory(const AUD_PingPongFactory&);
+       AUD_PingPongFactory& operator=(const AUD_PingPongFactory&);
+
 public:
        /**
         * Creates a new ping pong factory.
         * \param factory The input factory.
         */
-       AUD_PingPongFactory(AUD_IFactory* factory = 0);
+       AUD_PingPongFactory(AUD_IFactory* factory);
 
-       virtual AUD_IReader* createReader();
+       virtual AUD_IReader* createReader() const;
 };
 
 #endif //AUD_PINGPONGFACTORY
index 5f814283c12a17b3c0a2d7dd82e2d063dc00403e..be285562db3711615c4e97c8166ff0e8afbd4d33 100644 (file)
 
 AUD_PitchFactory::AUD_PitchFactory(AUD_IFactory* factory, float pitch) :
                AUD_EffectFactory(factory),
-               m_pitch(pitch) {}
-
-AUD_PitchFactory::AUD_PitchFactory(float pitch) :
-               AUD_EffectFactory(0),
-               m_pitch(pitch) {}
-
-AUD_IReader* AUD_PitchFactory::createReader()
+               m_pitch(pitch)
 {
-       AUD_IReader* reader = getReader();
-
-       if(reader != 0)
-       {
-               reader = new AUD_PitchReader(reader, m_pitch); AUD_NEW("reader")
-       }
+}
 
-       return reader;
+AUD_IReader* AUD_PitchFactory::createReader() const
+{
+       return new AUD_PitchReader(getReader(), m_pitch);
 }
index 96c4d0d7e9209832675b5596889b56d585c6969c..52b9b7d99e5ebfa44ddcee808d5d3e2c644fc742 100644 (file)
@@ -37,7 +37,11 @@ private:
        /**
         * The pitch.
         */
-       float m_pitch;
+       const float m_pitch;
+
+       // hide copy constructor and operator=
+       AUD_PitchFactory(const AUD_PitchFactory&);
+       AUD_PitchFactory& operator=(const AUD_PitchFactory&);
 
 public:
        /**
@@ -45,26 +49,9 @@ public:
         * \param factory The input factory.
         * \param pitch The desired pitch.
         */
-       AUD_PitchFactory(AUD_IFactory* factory = 0, float pitch = 1.0f);
-
-       /**
-        * Creates a new pitch factory.
-        * \param pitch The desired pitch.
-        */
-       AUD_PitchFactory(float pitch);
-
-       /**
-        * Returns the pitch.
-        */
-       float getPitch();
-
-       /**
-        * Sets the pitch.
-        * \param pitch The new pitch value. Should be between 0.0 and 1.0.
-        */
-       void setPitch(float pitch);
+       AUD_PitchFactory(AUD_IFactory* factory, float pitch);
 
-       virtual AUD_IReader* createReader();
+       virtual AUD_IReader* createReader() const;
 };
 
 #endif //AUD_PITCHFACTORY
index c53264e1350a72d22a55c96339ae39b92ef51d8b..19c3be31968eb8ef682bcc0b23837855410a08ef 100644 (file)
 #include "AUD_PitchReader.h"
 
 AUD_PitchReader::AUD_PitchReader(AUD_IReader* reader, float pitch) :
-               AUD_EffectReader(reader)
+               AUD_EffectReader(reader), m_pitch(pitch)
 {
-       m_pitch = pitch;
 }
 
-AUD_Specs AUD_PitchReader::getSpecs()
+AUD_Specs AUD_PitchReader::getSpecs() const
 {
        AUD_Specs specs = m_reader->getSpecs();
        specs.rate = (AUD_SampleRate)((int)(specs.rate * m_pitch));
index 440e9cc843c08e7dfe7ef8f97e7954d90ec39d0d..cc188cf0ee4a1fc28c6be3b6a86abdd426fe3478 100644 (file)
@@ -37,18 +37,21 @@ private:
        /**
         * The pitch level.
         */
-       float m_pitch;
+       const float m_pitch;
+
+       // hide copy constructor and operator=
+       AUD_PitchReader(const AUD_PitchReader&);
+       AUD_PitchReader& operator=(const AUD_PitchReader&);
 
 public:
        /**
         * Creates a new pitch reader.
         * \param reader The reader to read from.
         * \param pitch The size of the buffer.
-        * \exception AUD_Exception Thrown if the reader specified is NULL.
         */
        AUD_PitchReader(AUD_IReader* reader, float pitch);
 
-       virtual AUD_Specs getSpecs();
+       virtual AUD_Specs getSpecs() const;
 };
 
 #endif //AUD_PITCHREADER
index f97defd793b6dd8bb92f521aac69612b4f1379a7..52608c3177b6ab21c113e899ddae0af7af817cf0 100644 (file)
 #include "AUD_RectifyReader.h"
 
 AUD_RectifyFactory::AUD_RectifyFactory(AUD_IFactory* factory) :
-               AUD_EffectFactory(factory) {}
-
-AUD_RectifyFactory::AUD_RectifyFactory() :
-               AUD_EffectFactory(0) {}
-
-AUD_IReader* AUD_RectifyFactory::createReader()
+               AUD_EffectFactory(factory)
 {
-       AUD_IReader* reader = getReader();
-
-       if(reader != 0)
-       {
-               reader = new AUD_RectifyReader(reader); AUD_NEW("reader")
-       }
+}
 
-       return reader;
+AUD_IReader* AUD_RectifyFactory::createReader() const
+{
+       return new AUD_RectifyReader(getReader());
 }
index ed00620d3183e99dd8608de37c4566a4a482b278..d8b39e83fdfca7dba12090d4dddcef866a88c86f 100644 (file)
  */
 class AUD_RectifyFactory : public AUD_EffectFactory
 {
+private:
+       // hide copy constructor and operator=
+       AUD_RectifyFactory(const AUD_RectifyFactory&);
+       AUD_RectifyFactory& operator=(const AUD_RectifyFactory&);
+
 public:
        /**
         * Creates a new rectify factory.
         * \param factory The input factory.
         */
-       AUD_RectifyFactory(AUD_IFactory* factory = 0);
-
-       /**
-        * Creates a new rectify factory.
-        */
-       AUD_RectifyFactory();
+       AUD_RectifyFactory(AUD_IFactory* factory);
 
-       virtual AUD_IReader* createReader();
+       virtual AUD_IReader* createReader() const;
 };
 
 #endif //AUD_RECTIFYFACTORY
index 5d3ce80e811e58f6eaedc8d34860b8e05d6c7c66..c5bf73fac0316d27758434580254a84f4ee16ec3 100644 (file)
  */
 
 #include "AUD_RectifyReader.h"
-#include "AUD_Buffer.h"
 
 #include <cmath>
 
 AUD_RectifyReader::AUD_RectifyReader(AUD_IReader* reader) :
                AUD_EffectReader(reader)
 {
-       m_buffer = new AUD_Buffer(); AUD_NEW("buffer")
-}
-
-AUD_RectifyReader::~AUD_RectifyReader()
-{
-       delete m_buffer; AUD_DELETE("buffer")
 }
 
 void AUD_RectifyReader::read(int & length, sample_t* & buffer)
@@ -45,10 +38,10 @@ void AUD_RectifyReader::read(int & length, sample_t* & buffer)
        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));
+       if(m_buffer.getSize() < length * AUD_SAMPLE_SIZE(specs))
+               m_buffer.resize(length * AUD_SAMPLE_SIZE(specs));
 
-       buffer = m_buffer->getBuffer();
+       buffer = m_buffer.getBuffer();
 
        for(int i = 0; i < length * specs.channels; i++)
                buffer[i] = fabs(buf[i]);
index afbe2e59cabc1cf466c60e2e18695e2e8dc0ec2e..498f18e50411b2c65ea37970bfd6d2992ec0e24f 100644 (file)
@@ -27,7 +27,7 @@
 #define AUD_RECTIFYREADER
 
 #include "AUD_EffectReader.h"
-class AUD_Buffer;
+#include "AUD_Buffer.h"
 
 /**
  * This class reads another reader and rectifies it.
@@ -38,21 +38,19 @@ private:
        /**
         * The playback buffer.
         */
-       AUD_Buffer *m_buffer;
+       AUD_Buffer m_buffer;
+
+       // hide copy constructor and operator=
+       AUD_RectifyReader(const AUD_RectifyReader&);
+       AUD_RectifyReader& operator=(const AUD_RectifyReader&);
 
 public:
        /**
         * Creates a new rectify reader.
         * \param reader The reader to read from.
-        * \exception AUD_Exception Thrown if the reader specified is NULL.
         */
        AUD_RectifyReader(AUD_IReader* reader);
 
-       /**
-        * Destroys the reader.
-        */
-       virtual ~AUD_RectifyReader();
-
        virtual void read(int & length, sample_t* & buffer);
 };
 
index 1242641c350928fded7f271ec4f6eac4b26cef00..1002e2de87eb0956305e9e9ad0d13570abfc65d0 100644 (file)
 #include "AUD_Space.h"
 
 AUD_ReverseFactory::AUD_ReverseFactory(AUD_IFactory* factory) :
-               AUD_EffectFactory(factory) {}
-
-AUD_IReader* AUD_ReverseFactory::createReader()
+               AUD_EffectFactory(factory)
 {
-       AUD_IReader* reader = getReader();
-
-       if(reader != 0)
-       {
-               reader = new AUD_ReverseReader(reader); AUD_NEW("reader")
-       }
+}
 
-       return reader;
+AUD_IReader* AUD_ReverseFactory::createReader() const
+{
+       return new AUD_ReverseReader(getReader());
 }
index 4b664c47281db5b5c7e54fdda1d1cf991b8f3c5e..a1995ee68f92c9ca616c4247eae20bf9b4b3bb72 100644 (file)
  */
 class AUD_ReverseFactory : public AUD_EffectFactory
 {
+private:
+       // hide copy constructor and operator=
+       AUD_ReverseFactory(const AUD_ReverseFactory&);
+       AUD_ReverseFactory& operator=(const AUD_ReverseFactory&);
+
 public:
        /**
         * Creates a new reverse factory.
         * \param factory The input factory.
         */
-       AUD_ReverseFactory(AUD_IFactory* factory = 0);
+       AUD_ReverseFactory(AUD_IFactory* factory);
 
-       /**
-        * Destroys the factory.
-        */
-       virtual AUD_IReader* createReader();
+       virtual AUD_IReader* createReader() const;
 };
 
 #endif //AUD_REVERSEFACTORY
index 82d6c70ce53fa48eafaabddf556286d01aad5cd8..a17a4a64a18ee701960bdb81a4d221e136f2b7f6 100644 (file)
  */
 
 #include "AUD_ReverseReader.h"
-#include "AUD_Buffer.h"
 
 #include <cstring>
 
 AUD_ReverseReader::AUD_ReverseReader(AUD_IReader* reader) :
-               AUD_EffectReader(reader)
+               AUD_EffectReader(reader),
+               m_length(reader->getLength()),
+               m_position(0)
 {
-       if(reader->getType() != AUD_TYPE_BUFFER)
+       if(m_length < 0 || !reader->isSeekable())
                AUD_THROW(AUD_ERROR_READER);
-
-       m_length = reader->getLength();
-       if(m_length < 0)
-               AUD_THROW(AUD_ERROR_READER);
-
-       m_position = 0;
-       m_buffer = new AUD_Buffer(); AUD_NEW("buffer")
-}
-
-AUD_ReverseReader::~AUD_ReverseReader()
-{
-       delete m_buffer; AUD_DELETE("buffer")
 }
 
 void AUD_ReverseReader::seek(int position)
@@ -52,12 +41,12 @@ void AUD_ReverseReader::seek(int position)
        m_position = position;
 }
 
-int AUD_ReverseReader::getLength()
+int AUD_ReverseReader::getLength() const
 {
        return m_length;
 }
 
-int AUD_ReverseReader::getPosition()
+int AUD_ReverseReader::getPosition() const
 {
        return m_position;
 }
@@ -66,7 +55,7 @@ void AUD_ReverseReader::read(int & length, sample_t* & buffer)
 {
        // first correct the length
        if(m_position + length > m_length)
-               length = m_length-m_position;
+               length = m_length - m_position;
 
        if(length <= 0)
        {
@@ -78,10 +67,10 @@ void AUD_ReverseReader::read(int & length, sample_t* & buffer)
        int samplesize = AUD_SAMPLE_SIZE(specs);
 
        // resize buffer if needed
-       if(m_buffer->getSize() < length * samplesize)
-               m_buffer->resize(length * samplesize);
+       if(m_buffer.getSize() < length * samplesize)
+               m_buffer.resize(length * samplesize);
 
-       buffer = m_buffer->getBuffer();
+       buffer = m_buffer.getBuffer();
 
        sample_t* buf;
        int len = length;
@@ -105,5 +94,5 @@ void AUD_ReverseReader::read(int & length, sample_t* & buffer)
 
        m_position += length;
 
-       buffer = m_buffer->getBuffer();
+       buffer = m_buffer.getBuffer();
 }
index 045d2ac5a8ec714c3e5179f14a31f968afbfc7c4..8eb960a5dee7bd89aa33ad051b66f64fcb27bb4f 100644 (file)
@@ -27,7 +27,7 @@
 #define AUD_REVERSEREADER
 
 #include "AUD_EffectReader.h"
-class AUD_Buffer;
+#include "AUD_Buffer.h"
 
 /**
  * This class reads another reader from back to front.
@@ -37,37 +37,36 @@ class AUD_ReverseReader : public AUD_EffectReader
 {
 private:
        /**
-        * The current position.
+        * The sample count.
         */
-       int m_position;
+       const int m_length;
 
        /**
-        * The sample count.
+        * The current position.
         */
-       int m_length;
+       int m_position;
 
        /**
         * The playback buffer.
         */
-       AUD_Buffer* m_buffer;
+       AUD_Buffer m_buffer;
+
+       // hide copy constructor and operator=
+       AUD_ReverseReader(const AUD_ReverseReader&);
+       AUD_ReverseReader& operator=(const AUD_ReverseReader&);
 
 public:
        /**
         * Creates a new reverse reader.
         * \param reader The reader to read from.
-        * \exception AUD_Exception Thrown if the reader specified is NULL or not
-        *            a buffer.
+        * \exception AUD_Exception Thrown if the reader specified has an
+        *            undeterminable/infinite length or is not seekable.
         */
        AUD_ReverseReader(AUD_IReader* reader);
 
-       /**
-        * Destroys the reader.
-        */
-       virtual ~AUD_ReverseReader();
-
        virtual void seek(int position);
-       virtual int getLength();
-       virtual int getPosition();
+       virtual int getLength() const;
+       virtual int getPosition() const;
        virtual void read(int & length, sample_t* & buffer);
 };
 
index 638acaa9a327a3c3403f853ee06516fa00d7fdee..b95c9d9bb0f95fa039008406f13722978e2109f0 100644 (file)
 
 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()
+               m_threshold(threshold)
 {
-       return m_threshold;
 }
 
-void AUD_SquareFactory::setThreshold(float threshold)
+float AUD_SquareFactory::getThreshold() const
 {
-       m_threshold = threshold;
+       return m_threshold;
 }
 
-AUD_IReader* AUD_SquareFactory::createReader()
+AUD_IReader* AUD_SquareFactory::createReader() const
 {
-       AUD_IReader* reader = getReader();
-
-       if(reader != 0)
-       {
-               reader = new AUD_SquareReader(reader, m_threshold); AUD_NEW("reader")
-       }
-
-       return reader;
+       return new AUD_SquareReader(getReader(), m_threshold);
 }
index dfbe5ae2887f9bc4e66d734afcd64d8d112b76d4..da87dc6f8889735b3ed9371df640b2d33df4ebe8 100644 (file)
@@ -37,7 +37,11 @@ private:
        /**
         * The threshold.
         */
-       float m_threshold;
+       const float m_threshold;
+
+       // hide copy constructor and operator=
+       AUD_SquareFactory(const AUD_SquareFactory&);
+       AUD_SquareFactory& operator=(const AUD_SquareFactory&);
 
 public:
        /**
@@ -45,26 +49,14 @@ public:
         * \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);
+       AUD_SquareFactory(AUD_IFactory* factory, float threshold = 0.0f);
 
        /**
         * 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);
+       float getThreshold() const;
 
-       virtual AUD_IReader* createReader();
+       virtual AUD_IReader* createReader() const;
 };
 
 #endif //AUD_SQUAREFACTORY
index 2d4dc52fe27ec430fa989a7285cd60462c1edd8b..4bf0d87f99b6fcfd2e87ee6b8c06b0716b00459b 100644 (file)
@@ -24,7 +24,6 @@
  */
 
 #include "AUD_SquareReader.h"
-#include "AUD_Buffer.h"
 
 #include <cstring>
 
@@ -32,12 +31,6 @@ 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)
@@ -46,10 +39,11 @@ void AUD_SquareReader::read(int & length, sample_t* & buffer)
        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_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++)
        {
index 63dda351445acd0f4996c670c099e38817b6b44f..d3a5331b0e8892e2f16607b4d66de4e80ddc61ff 100644 (file)
@@ -27,7 +27,7 @@
 #define AUD_SQUAREREADER
 
 #include "AUD_EffectReader.h"
-class AUD_Buffer;
+#include "AUD_Buffer.h"
 
 /**
  * This class changes another signal into a square signal.
@@ -38,27 +38,25 @@ private:
        /**
         * The playback buffer.
         */
-       AUD_Buffer *m_buffer;
+       AUD_Buffer m_buffer;
 
        /**
         * The threshold level.
         */
-       float m_threshold;
+       const float m_threshold;
+
+       // hide copy constructor and operator=
+       AUD_SquareReader(const AUD_SquareReader&);
+       AUD_SquareReader& operator=(const AUD_SquareReader&);
 
 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);
 };
 
index f7990aab8a162ba2fa5ee8da9760e0cb23475ba6..96ad286bf5c8ffaddd7d700409d5a8f588f879d3 100644 (file)
 #include "AUD_SumReader.h"
 
 AUD_SumFactory::AUD_SumFactory(AUD_IFactory* factory) :
-               AUD_EffectFactory(factory) {}
-
-AUD_IReader* AUD_SumFactory::createReader()
+               AUD_EffectFactory(factory)
 {
-       AUD_IReader* reader = getReader();
-
-       if(reader != 0)
-       {
-               reader = new AUD_SumReader(reader);
-               AUD_NEW("reader")
-       }
+}
 
-       return reader;
+AUD_IReader* AUD_SumFactory::createReader() const
+{
+       return new AUD_SumReader(getReader());
 }
index 5cb48e26b1042101c4436c742dc8deb2c2d9a14d..045a0a3a625c0fb1fd54620622e5f91e1d67dca3 100644 (file)
  */
 class AUD_SumFactory : public AUD_EffectFactory
 {
+private:
+       // hide copy constructor and operator=
+       AUD_SumFactory(const AUD_SumFactory&);
+       AUD_SumFactory& operator=(const AUD_SumFactory&);
+
 public:
        /**
         * Creates a new sum factory.
         * \param factory The input factory.
         */
-       AUD_SumFactory(AUD_IFactory* factory = 0);
+       AUD_SumFactory(AUD_IFactory* factory);
 
-       virtual AUD_IReader* createReader();
+       virtual AUD_IReader* createReader() const;
 };
 
 #endif //AUD_SUMFACTORY
index 08747790fc91b6b100543df934714fa7fde0f8c8..13f0e2271a6a61876b5a9e86d348f7214c711d0d 100644 (file)
  */
 
 #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_EffectReader(reader),
+               m_sums(AUD_SAMPLE_SIZE(reader->getSpecs()))
 {
-       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")
+       memset(m_sums.getBuffer(), 0, m_sums.getSize());
 }
 
 void AUD_SumReader::read(int & length, sample_t* & buffer)
 {
        sample_t* buf;
        sample_t* sums;
-       sums = m_sums->getBuffer();
+       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();
+       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++)
index 76ccf2f863a0f82db799fdaad94f7eb8db3660ea..0bb470bac97c8f3c51f2323900cf596c1a6a55c2 100644 (file)
@@ -27,7 +27,7 @@
 #define AUD_SUMREADER
 
 #include "AUD_EffectReader.h"
-class AUD_Buffer;
+#include "AUD_Buffer.h"
 
 /**
  * This class represents an summer.
@@ -38,26 +38,24 @@ private:
        /**
         * The playback buffer.
         */
-       AUD_Buffer *m_buffer;
+       AUD_Buffer m_buffer;
 
        /**
         * The sums of the specific channels.
         */
-       AUD_Buffer *m_sums;
+       AUD_Buffer m_sums;
+
+       // hide copy constructor and operator=
+       AUD_SumReader(const AUD_SumReader&);
+       AUD_SumReader& operator=(const AUD_SumReader&);
 
 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);
 };
 
index afd1ec18efba45711f48843c7eae07a010b19abd..6bfc1125ca6cf454320969447d293134a4d5bef7 100644 (file)
 #include "AUD_SuperposeReader.h"
 
 AUD_SuperposeFactory::AUD_SuperposeFactory(AUD_IFactory* factory1, AUD_IFactory* factory2) :
-               m_factory1(factory1), m_factory2(factory2) {}
+               m_factory1(factory1), m_factory2(factory2)
+{
+}
 
-AUD_IReader* AUD_SuperposeFactory::createReader()
+AUD_IReader* AUD_SuperposeFactory::createReader() const
 {
        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")
+               delete reader1;
                throw;
        }
 
-       AUD_IReader* reader = new AUD_SuperposeReader(reader1, reader2);
-       return reader;
+       return new AUD_SuperposeReader(reader1, reader2);
 }
index 44e79d768876d62bdf343d718c831beee9746e56..a7fde2c182f33c84e9fac6a17d39996f2d418ccb 100644 (file)
@@ -45,6 +45,10 @@ private:
         */
        AUD_IFactory* m_factory2;
 
+       // hide copy constructor and operator=
+       AUD_SuperposeFactory(const AUD_SuperposeFactory&);
+       AUD_SuperposeFactory& operator=(const AUD_SuperposeFactory&);
+
 public:
        /**
         * Creates a new superpose factory.
@@ -53,7 +57,7 @@ public:
         */
        AUD_SuperposeFactory(AUD_IFactory* factory1, AUD_IFactory* factory2);
 
-       virtual AUD_IReader* createReader();
+       virtual AUD_IReader* createReader() const;
 };
 
 #endif //AUD_SUPERPOSEFACTORY
index 6519f2721102b16f5ffa3942092ef3ebd4b6edff..c24b01b35b312cb735e539210ac009956eb7f3bc 100644 (file)
@@ -24,7 +24,6 @@
  */
 
 #include "AUD_SuperposeReader.h"
-#include "AUD_Buffer.h"
 
 #include <cstring>
 
@@ -33,44 +32,28 @@ AUD_SuperposeReader::AUD_SuperposeReader(AUD_IReader* reader1, AUD_IReader* read
 {
        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)
+               if(memcmp(&s1, &s2, sizeof(AUD_Specs)))
                        AUD_THROW(AUD_ERROR_READER);
        }
-
-       catch(AUD_Exception)
+       catch(AUD_Exception&)
        {
-               if(reader1)
-               {
-                       delete reader1; AUD_DELETE("reader")
-               }
-               if(reader2)
-               {
-                       delete reader2; AUD_DELETE("reader")
-               }
+               delete reader1;
+               delete reader2;
 
                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")
+       delete m_reader1;
+       delete m_reader2;
 }
 
-bool AUD_SuperposeReader::isSeekable()
+bool AUD_SuperposeReader::isSeekable() const
 {
        return m_reader1->isSeekable() && m_reader2->isSeekable();
 }
@@ -81,50 +64,35 @@ void AUD_SuperposeReader::seek(int position)
        m_reader2->seek(position);
 }
 
-int AUD_SuperposeReader::getLength()
+int AUD_SuperposeReader::getLength() const
 {
        int len1 = m_reader1->getLength();
        int len2 = m_reader2->getLength();
        if((len1 < 0) || (len2 < 0))
                return -1;
-       if(len1 < len2)
-               return len2;
-       return len1;
+       return AUD_MIN(len1, len2);
 }
 
-int AUD_SuperposeReader::getPosition()
+int AUD_SuperposeReader::getPosition() const
 {
        int pos1 = m_reader1->getPosition();
        int pos2 = m_reader2->getPosition();
        return AUD_MAX(pos1, pos2);
 }
 
-AUD_Specs AUD_SuperposeReader::getSpecs()
+AUD_Specs AUD_SuperposeReader::getSpecs() const
 {
        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();
+       if(m_buffer.getSize() < length * samplesize)
+               m_buffer.resize(length * samplesize);
+       buffer = m_buffer.getBuffer();
 
        int len1 = length;
        sample_t* buf;
index 71392b1133bdfc242e497a2bd8cfd9858840802e..eeceb9adfebfd91e7e50019cb8cafc59a86f74f6 100644 (file)
@@ -27,7 +27,7 @@
 #define AUD_SUPERPOSEREADER
 
 #include "AUD_IReader.h"
-class AUD_Buffer;
+#include "AUD_Buffer.h"
 
 /**
  * This reader plays two readers with the same specs sequently.
@@ -48,15 +48,18 @@ private:
        /**
         * The playback buffer for the intersecting part.
         */
-       AUD_Buffer* m_buffer;
+       AUD_Buffer m_buffer;
+
+       // hide copy constructor and operator=
+       AUD_SuperposeReader(const AUD_SuperposeReader&);
+       AUD_SuperposeReader& operator=(const AUD_SuperposeReader&);
 
 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.
+        * \exception AUD_Exception Thrown if the specs from the readers differ.
         */
        AUD_SuperposeReader(AUD_IReader* reader1, AUD_IReader* reader2);
 
@@ -65,13 +68,11 @@ public:
         */
        virtual ~AUD_SuperposeReader();
 
-       virtual bool isSeekable();
+       virtual bool isSeekable() const;
        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 int getLength() const;
+       virtual int getPosition() const;
+       virtual AUD_Specs getSpecs() const;
        virtual void read(int & length, sample_t* & buffer);
 };
 
index fbde608aa122c69f92d6d1772cd4d2a4c82cc3b3..9f0fd5821fd41bc028b1f3509a386f24c7a764d0 100644 (file)
 
 AUD_VolumeFactory::AUD_VolumeFactory(AUD_IFactory* factory, float volume) :
                AUD_EffectFactory(factory),
-               m_volume(volume) {}
-
-AUD_VolumeFactory::AUD_VolumeFactory(float volume) :
-               AUD_EffectFactory(0),
-               m_volume(volume) {}
-
-float AUD_VolumeFactory::getVolume()
+               m_volume(volume)
 {
-       return m_volume;
 }
 
-void AUD_VolumeFactory::setVolume(float volume)
+float AUD_VolumeFactory::getVolume() const
 {
-       m_volume = volume;
+       return m_volume;
 }
 
-AUD_IReader* AUD_VolumeFactory::createReader()
+AUD_IReader* AUD_VolumeFactory::createReader() const
 {
-       AUD_IReader* reader = getReader();
-
-       if(reader != 0)
-       {
-               reader = new AUD_VolumeReader(reader, m_volume); AUD_NEW("reader")
-       }
-
-       return reader;
+       return new AUD_VolumeReader(getReader(), m_volume);
 }
index 09f91241b4705c483a508236e89b191ff89a0187..a086aab4640ab4e74e4ff9d4a1f710d7faa5c537 100644 (file)
@@ -39,7 +39,11 @@ private:
        /**
         * The volume.
         */
-       float m_volume;
+       const float m_volume;
+
+       // hide copy constructor and operator=
+       AUD_VolumeFactory(const AUD_VolumeFactory&);
+       AUD_VolumeFactory& operator=(const AUD_VolumeFactory&);
 
 public:
        /**
@@ -47,26 +51,14 @@ public:
         * \param factory The input factory.
         * \param volume The desired volume.
         */
-       AUD_VolumeFactory(AUD_IFactory* factory = 0, float volume = 1.0f);
-
-       /**
-        * Creates a new volume factory.
-        * \param volume The desired volume.
-        */
-       AUD_VolumeFactory(float volume);
+       AUD_VolumeFactory(AUD_IFactory* factory, float volume);
 
        /**
         * Returns the volume.
         */
-       float getVolume();
-
-       /**
-        * Sets the volume.
-        * \param volume The new volume value. Should be between 0.0 and 1.0.
-        */
-       void setVolume(float volume);
+       float getVolume() const;
 
-       virtual AUD_IReader* createReader();
+       virtual AUD_IReader* createReader() const;
 };
 
 #endif //AUD_VOLUMEFACTORY
index f094c1e4ea3bdbcf43a6362201acda28a1985562..7401b508b28596f0ea900d736f77accb12133438 100644 (file)
@@ -24,7 +24,6 @@
  */
 
 #include "AUD_VolumeReader.h"
-#include "AUD_Buffer.h"
 
 #include <cstring>
 
@@ -32,25 +31,6 @@ AUD_VolumeReader::AUD_VolumeReader(AUD_IReader* reader, float volume) :
                AUD_EffectReader(reader),
                m_volume(volume)
 {
-       m_buffer = new AUD_Buffer(); AUD_NEW("buffer")
-}
-
-AUD_VolumeReader::~AUD_VolumeReader()
-{
-       delete m_buffer; AUD_DELETE("buffer")
-}
-
-bool AUD_VolumeReader::notify(AUD_Message &message)
-{
-       if(message.type == AUD_MSG_VOLUME)
-       {
-               m_volume = message.volume;
-
-               m_reader->notify(message);
-
-               return true;
-       }
-       return m_reader->notify(message);
 }
 
 void AUD_VolumeReader::read(int & length, sample_t* & buffer)
@@ -59,10 +39,10 @@ void AUD_VolumeReader::read(int & length, sample_t* & buffer)
        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));
+       if(m_buffer.getSize() < length * AUD_SAMPLE_SIZE(specs))
+               m_buffer.resize(length * AUD_SAMPLE_SIZE(specs));
 
-       buffer = m_buffer->getBuffer();
+       buffer = m_buffer.getBuffer();
 
        for(int i = 0; i < length * specs.channels; i++)
                buffer[i] = buf[i] * m_volume;
index 489f85b10f214d63d364b95eea0566b3ebde7b3d..0e96a27e2879223ee93775a110dec421fdb3ff3d 100644 (file)
@@ -27,7 +27,7 @@
 #define AUD_VOLUMEREADER
 
 #include "AUD_EffectReader.h"
-class AUD_Buffer;
+#include "AUD_Buffer.h"
 
 /**
  * This class reads another reader and changes it's volume.
@@ -38,28 +38,25 @@ private:
        /**
         * The playback buffer.
         */
-       AUD_Buffer *m_buffer;
+       AUD_Buffer m_buffer;
 
        /**
         * The volume level.
         */
-       float m_volume;
+       const float m_volume;
+
+       // hide copy constructor and operator=
+       AUD_VolumeReader(const AUD_VolumeReader&);
+       AUD_VolumeReader& operator=(const AUD_VolumeReader&);
 
 public:
        /**
         * Creates a new volume reader.
         * \param reader The reader to read from.
         * \param volume The size of the buffer.
-        * \exception AUD_Exception Thrown if the reader specified is NULL.
         */
        AUD_VolumeReader(AUD_IReader* reader, float volume);
 
-       /**
-        * Destroys the reader.
-        */
-       virtual ~AUD_VolumeReader();
-
-       virtual bool notify(AUD_Message &message);
        virtual void read(int & length, sample_t* & buffer);
 };
 
index 796764989ba22d58bae29b682d696a91a7694de0..729d4acc077788283d8ba2d05c8cff6d49a8aafb 100644 (file)
@@ -24,8 +24,9 @@
  */
 
 #include "AUD_OpenALDevice.h"
+#include "AUD_IFactory.h"
 #include "AUD_IReader.h"
-#include "AUD_ConverterFactory.h"
+#include "AUD_ConverterReader.h"
 #include "AUD_SourceCaps.h"
 
 #include <cstring>
@@ -302,12 +303,7 @@ AUD_OpenALDevice::AUD_OpenALDevice(AUD_DeviceSpecs specs, int buffersize)
 
        // check for specific formats and channel counts to be played back
        if(alIsExtensionPresent("AL_EXT_FLOAT32") == AL_TRUE)
-       {
                specs.format = AUD_FORMAT_FLOAT32;
-               m_converter = NULL;
-       }
-       else
-               m_converter = new AUD_ConverterFactory(specs); AUD_NEW("factory")
 
        m_useMC = alIsExtensionPresent("AL_EXT_MCFORMATS") == AL_TRUE;
 
@@ -317,10 +313,9 @@ AUD_OpenALDevice::AUD_OpenALDevice(AUD_DeviceSpecs specs, int buffersize)
        m_buffersize = buffersize;
        m_playing = false;
 
-       m_playingSounds = new std::list<AUD_OpenALHandle*>(); AUD_NEW("list")
-       m_pausedSounds = new std::list<AUD_OpenALHandle*>(); AUD_NEW("list")
+       m_playingSounds = new std::list<AUD_OpenALHandle*>();
+       m_pausedSounds = new std::list<AUD_OpenALHandle*>();
        m_bufferedFactories = new std::list<AUD_OpenALBufferedFactory*>();
-       AUD_NEW("list")
 
        pthread_mutexattr_t attr;
        pthread_mutexattr_init(&attr);
@@ -345,10 +340,10 @@ AUD_OpenALDevice::~AUD_OpenALDevice()
                alDeleteSources(1, &sound->source);
                if(!sound->isBuffered)
                {
-                       delete sound->reader; AUD_DELETE("reader")
+                       delete sound->reader;
                        alDeleteBuffers(AUD_OPENAL_CYCLE_BUFFERS, sound->buffers);
                }
-               delete sound; AUD_DELETE("handle")
+               delete sound;
                m_playingSounds->erase(m_playingSounds->begin());
        }
 
@@ -359,10 +354,10 @@ AUD_OpenALDevice::~AUD_OpenALDevice()
                alDeleteSources(1, &sound->source);
                if(!sound->isBuffered)
                {
-                       delete sound->reader; AUD_DELETE("reader")
+                       delete sound->reader;
                        alDeleteBuffers(AUD_OPENAL_CYCLE_BUFFERS, sound->buffers);
                }
-               delete sound; AUD_DELETE("handle")
+               delete sound;
                m_pausedSounds->erase(m_pausedSounds->begin());
        }
 
@@ -370,7 +365,7 @@ AUD_OpenALDevice::~AUD_OpenALDevice()
        while(!m_bufferedFactories->empty())
        {
                alDeleteBuffers(1, &(*(m_bufferedFactories->begin()))->buffer);
-               delete *m_bufferedFactories->begin(); AUD_DELETE("bufferedfactory");
+               delete *m_bufferedFactories->begin();
                m_bufferedFactories->erase(m_bufferedFactories->begin());
        }
 
@@ -385,22 +380,19 @@ AUD_OpenALDevice::~AUD_OpenALDevice()
        else
                unlock();
 
-       delete m_playingSounds; AUD_DELETE("list")
-       delete m_pausedSounds; AUD_DELETE("list")
-       delete m_bufferedFactories; AUD_DELETE("list")
+       delete m_playingSounds;
+       delete m_pausedSounds;
+       delete m_bufferedFactories;
 
        // quit OpenAL
        alcMakeContextCurrent(NULL);
        alcDestroyContext(m_context);
        alcCloseDevice(m_device);
 
-       if(m_converter)
-               delete m_converter; AUD_DELETE("factory")
-
        pthread_mutex_destroy(&m_mutex);
 }
 
-AUD_DeviceSpecs AUD_OpenALDevice::getSpecs()
+AUD_DeviceSpecs AUD_OpenALDevice::getSpecs() const
 {
        return m_specs;
 }
@@ -511,7 +503,7 @@ AUD_Handle* AUD_OpenALDevice::play(AUD_IFactory* factory, bool keep)
                        if((*i)->factory == factory)
                        {
                                // create the handle
-                               sound = new AUD_OpenALHandle; AUD_NEW("handle")
+                               sound = new AUD_OpenALHandle;
                                sound->keep = keep;
                                sound->current = -1;
                                sound->isBuffered = true;
@@ -532,15 +524,15 @@ AUD_Handle* AUD_OpenALDevice::play(AUD_IFactory* factory, bool keep)
                                                if(alGetError() != AL_NO_ERROR)
                                                        AUD_THROW(AUD_ERROR_OPENAL);
                                        }
-                                       catch(AUD_Exception)
+                                       catch(AUD_Exception&)
                                        {
                                                alDeleteSources(1, &sound->source);
                                                throw;
                                        }
                                }
-                               catch(AUD_Exception)
+                               catch(AUD_Exception&)
                                {
-                                       delete sound; AUD_DELETE("handle")
+                                       delete sound;
                                        alcProcessContext(m_context);
                                        throw;
                                }
@@ -555,7 +547,7 @@ AUD_Handle* AUD_OpenALDevice::play(AUD_IFactory* factory, bool keep)
                        }
                }
        }
-       catch(AUD_Exception)
+       catch(AUD_Exception&)
        {
                unlock();
                throw;
@@ -577,14 +569,11 @@ AUD_Handle* AUD_OpenALDevice::play(AUD_IFactory* factory, bool keep)
        // check format
        bool valid = specs.channels != AUD_CHANNELS_INVALID;
 
-       if(m_converter)
-       {
-               m_converter->setReader(reader);
-               reader = m_converter->createReader();
-       }
+       if(m_specs.format != AUD_FORMAT_FLOAT32)
+               reader = new AUD_ConverterReader(reader, m_specs);
 
        // create the handle
-       sound = new AUD_OpenALHandle; AUD_NEW("handle")
+       sound = new AUD_OpenALHandle;
        sound->keep = keep;
        sound->reader = reader;
        sound->current = 0;
@@ -595,8 +584,8 @@ AUD_Handle* AUD_OpenALDevice::play(AUD_IFactory* factory, bool keep)
 
        if(!valid)
        {
-               delete sound; AUD_DELETE("handle")
-               delete reader; AUD_DELETE("reader")
+               delete sound;
+               delete reader;
                return NULL;
        }
 
@@ -637,22 +626,22 @@ AUD_Handle* AUD_OpenALDevice::play(AUD_IFactory* factory, bool keep)
                                if(alGetError() != AL_NO_ERROR)
                                        AUD_THROW(AUD_ERROR_OPENAL);
                        }
-                       catch(AUD_Exception)
+                       catch(AUD_Exception&)
                        {
                                alDeleteSources(1, &sound->source);
                                throw;
                        }
                }
-               catch(AUD_Exception)
+               catch(AUD_Exception&)
                {
                        alDeleteBuffers(AUD_OPENAL_CYCLE_BUFFERS, sound->buffers);
                        throw;
                }
        }
-       catch(AUD_Exception)
+       catch(AUD_Exception&)
        {
-               delete sound; AUD_DELETE("handle")
-               delete reader; AUD_DELETE("reader")
+               delete sound;
+               delete reader;
                alcProcessContext(m_context);
                unlock();
                throw;
@@ -737,10 +726,10 @@ bool AUD_OpenALDevice::stop(AUD_Handle* handle)
                        alDeleteSources(1, &sound->source);
                        if(!sound->isBuffered)
                        {
-                               delete sound->reader; AUD_DELETE("reader")
+                               delete sound->reader;
                                alDeleteBuffers(AUD_OPENAL_CYCLE_BUFFERS, sound->buffers);
                        }
-                       delete *i; AUD_DELETE("handle")
+                       delete *i;
                        m_playingSounds->erase(i);
                        result = true;
                        break;
@@ -757,10 +746,10 @@ bool AUD_OpenALDevice::stop(AUD_Handle* handle)
                                alDeleteSources(1, &sound->source);
                                if(!sound->isBuffered)
                                {
-                                       delete sound->reader; AUD_DELETE("reader")
+                                       delete sound->reader;
                                        alDeleteBuffers(AUD_OPENAL_CYCLE_BUFFERS, sound->buffers);
                                }
-                               delete *i; AUD_DELETE("handle")
+                               delete *i;
                                m_pausedSounds->erase(i);
                                result = true;
                                break;
@@ -790,32 +779,6 @@ bool AUD_OpenALDevice::setKeep(AUD_Handle* handle, bool keep)
        return result;
 }
 
-bool AUD_OpenALDevice::sendMessage(AUD_Handle* handle, AUD_Message &message)
-{
-       bool result = false;
-
-       lock();
-
-       if(handle == 0)
-       {
-               for(AUD_HandleIterator i = m_playingSounds->begin();
-                       i != m_playingSounds->end(); i++)
-                       if(!(*i)->isBuffered)
-                               result |= (*i)->reader->notify(message);
-               for(AUD_HandleIterator i = m_pausedSounds->begin();
-                       i != m_pausedSounds->end(); i++)
-                       if(!(*i)->isBuffered)
-                               result |= (*i)->reader->notify(message);
-       }
-       else if(isValid(handle))
-               if(!((AUD_OpenALHandle*)handle)->isBuffered)
-                       result = ((AUD_OpenALHandle*)handle)->reader->notify(message);
-
-       unlock();
-
-       return result;
-}
-
 bool AUD_OpenALDevice::seek(AUD_Handle* handle, float position)
 {
        bool result = false;
@@ -1024,26 +987,14 @@ bool AUD_OpenALDevice::setCapability(int capability, void *value)
                                AUD_DeviceSpecs specs = m_specs;
                                specs.specs = reader->getSpecs();
 
-                               // determine format
-                               bool valid = reader->getType() == AUD_TYPE_BUFFER;
-
-                               if(valid)
-                               {
-                                       if(m_converter)
-                                       {
-                                               m_converter->setReader(reader);
-                                               reader = m_converter->createReader();
-                                       }
-                               }
+                               if(m_specs.format != AUD_FORMAT_FLOAT32)
+                                       reader = new AUD_ConverterReader(reader, m_specs);
 
                                ALenum format;
 
-                               if(valid)
-                                       valid = getFormat(format, specs.specs);
-
-                               if(!valid)
+                               if(!getFormat(format, specs.specs))
                                {
-                                       delete reader; AUD_DELETE("reader")
+                                       delete reader;
                                        return false;
                                }
 
@@ -1052,7 +1003,6 @@ bool AUD_OpenALDevice::setCapability(int capability, void *value)
                                alcSuspendContext(m_context);
 
                                AUD_OpenALBufferedFactory* bf = new AUD_OpenALBufferedFactory;
-                               AUD_NEW("bufferedfactory");
                                bf->factory = factory;
 
                                try
@@ -1073,16 +1023,16 @@ bool AUD_OpenALDevice::setCapability(int capability, void *value)
                                                if(alGetError() != AL_NO_ERROR)
                                                        AUD_THROW(AUD_ERROR_OPENAL);
                                        }
-                                       catch(AUD_Exception)
+                                       catch(AUD_Exception&)
                                        {
                                                alDeleteBuffers(1, &bf->buffer);
                                                throw;
                                        }
                                }
-                               catch(AUD_Exception)
+                               catch(AUD_Exception&)
                                {
-                                       delete bf; AUD_DELETE("bufferedfactory")
-                                       delete reader; AUD_DELETE("reader")
+                                       delete bf;
+                                       delete reader;
                                        alcProcessContext(m_context);
                                        unlock();
                                        return false;
@@ -1116,7 +1066,6 @@ bool AUD_OpenALDevice::setCapability(int capability, void *value)
                                        alDeleteBuffers(1,
                                                                        &(*(m_bufferedFactories->begin()))->buffer);
                                        delete *m_bufferedFactories->begin();
-                                       AUD_DELETE("bufferedfactory");
                                        m_bufferedFactories->erase(m_bufferedFactories->begin());
                                }
                                unlock();
index cb8c83ab810e247e5bfdf972d543a9e997bfc9aa..c36f89209d3dacefd2712c851c3d47297ede9891 100644 (file)
@@ -30,7 +30,6 @@
 #include "AUD_I3DDevice.h"
 struct AUD_OpenALHandle;
 struct AUD_OpenALBufferedFactory;
-class AUD_ConverterFactory;
 
 #include <AL/al.h>
 #include <AL/alc.h>
@@ -63,11 +62,6 @@ private:
         */
        bool m_useMC;
 
-       /**
-       * The converter factory for readers with wrong input format.
-       */
-       AUD_ConverterFactory* m_converter;
-
        /**
         * The list of sounds that are currently playing.
         */
@@ -123,6 +117,10 @@ private:
         */
        bool getFormat(ALenum &format, AUD_Specs specs);
 
+       // hide copy constructor and operator=
+       AUD_OpenALDevice(const AUD_OpenALDevice&);
+       AUD_OpenALDevice& operator=(const AUD_OpenALDevice&);
+
 public:
        /**
         * Opens the OpenAL audio device for playback.
@@ -142,13 +140,12 @@ public:
 
        virtual ~AUD_OpenALDevice();
 
-       virtual AUD_DeviceSpecs getSpecs();
+       virtual AUD_DeviceSpecs getSpecs() const;
        virtual AUD_Handle* play(AUD_IFactory* factory, bool keep = false);
        virtual bool pause(AUD_Handle* handle);
        virtual bool resume(AUD_Handle* handle);
        virtual bool stop(AUD_Handle* handle);
        virtual bool setKeep(AUD_Handle* handle, bool keep);
-       virtual bool sendMessage(AUD_Handle* handle, AUD_Message &message);
        virtual bool seek(AUD_Handle* handle, float position);
        virtual float getPosition(AUD_Handle* handle);
        virtual AUD_Status getStatus(AUD_Handle* handle);
index f1c41bf20096ecb669502049f18b962536cfb148..30e4bf5b9fd13e78e3f6ca065aafb1b9ab905762 100644 (file)
@@ -425,10 +425,10 @@ static PyTypeObject SoundType = {
 static PyObject *
 Sound_sine(PyObject* nothing, PyObject* args)
 {
-       double frequency;
+       float frequency;
        int rate = 44100;
 
-       if(!PyArg_ParseTuple(args, "d|i", &frequency, &rate))
+       if(!PyArg_ParseTuple(args, "f|i", &frequency, &rate))
                return NULL;
 
        Sound *self;
@@ -1266,13 +1266,14 @@ Handle_set_loop_count(Handle *self, PyObject* args, void* nothing)
 
        try
        {
+               /* AUD_XXX Doesn't work atm, will come back
                AUD_Message message;
                message.loopcount = loops;
                message.type = AUD_MSG_LOOP;
                if(device->device->sendMessage(self->handle, message))
                {
                        return 0;
-               }
+               }*/
        }
        catch(AUD_Exception&)
        {
index 4b7de1996e8fe28ac5fa19bbf6a87ab66bd2c9de..af713b27480417064fb2c578e9acb1a19036ad3c 100644 (file)
@@ -44,6 +44,10 @@ private:
         */
        static void SDL_mix(void *data, Uint8* buffer, int length);
 
+       // hide copy constructor and operator=
+       AUD_SDLDevice(const AUD_SDLDevice&);
+       AUD_SDLDevice& operator=(const AUD_SDLDevice&);
+
 protected:
        virtual void playing(bool playing);
 
index caafbd1432799908afaf4e790a54a4f4d3177453..b421bb777e1dbb1ac9a422df5dcaf532e0fbd967 100644 (file)
 #include "AUD_SRCResampleFactory.h"
 #include "AUD_SRCResampleReader.h"
 
-AUD_SRCResampleFactory::AUD_SRCResampleFactory(AUD_IReader* reader,
-                                                                                          AUD_DeviceSpecs specs) :
-               AUD_ResampleFactory(reader, specs) {}
-
 AUD_SRCResampleFactory::AUD_SRCResampleFactory(AUD_IFactory* factory,
                                                                                           AUD_DeviceSpecs specs) :
-               AUD_ResampleFactory(factory, specs) {}
-
-AUD_SRCResampleFactory::AUD_SRCResampleFactory(AUD_DeviceSpecs specs) :
-               AUD_ResampleFactory(specs) {}
+               AUD_ResampleFactory(factory, specs)
+{
+}
 
-AUD_IReader* AUD_SRCResampleFactory::createReader()
+AUD_IReader* AUD_SRCResampleFactory::createReader() const
 {
        AUD_IReader* reader = getReader();
 
-       if(reader != 0)
-       {
-               if(reader->getSpecs().rate != m_specs.rate)
-               {
-                       reader = new AUD_SRCResampleReader(reader, m_specs.specs);
-                       AUD_NEW("reader")
-               }
-       }
+       if(reader->getSpecs().rate != m_specs.rate)
+               reader = new AUD_SRCResampleReader(reader, m_specs.specs);
+
        return reader;
 }
index 4b16c70169cefe1e90271dd07753178fa600f488..4edb0e76181c014d2b7cccc9334d5b3ffe9a3c9f 100644 (file)
  */
 class AUD_SRCResampleFactory : public AUD_ResampleFactory
 {
+private:
+       // hide copy constructor and operator=
+       AUD_SRCResampleFactory(const AUD_SRCResampleFactory&);
+       AUD_SRCResampleFactory& operator=(const AUD_SRCResampleFactory&);
+
 public:
-       AUD_SRCResampleFactory(AUD_IReader* reader, AUD_DeviceSpecs specs);
        AUD_SRCResampleFactory(AUD_IFactory* factory, AUD_DeviceSpecs specs);
-       AUD_SRCResampleFactory(AUD_DeviceSpecs specs);
 
-       virtual AUD_IReader* createReader();
+       virtual AUD_IReader* createReader() const;
 };
 
 #endif //AUD_SRCRESAMPLEFACTORY
index e89857635dec99c573cb090a499c1c8b651a487e..553a020e76d902353ea12987d1280a87904af1fc 100644 (file)
@@ -24,7 +24,6 @@
  */
 
 #include "AUD_SRCResampleReader.h"
-#include "AUD_Buffer.h"
 
 #include <cmath>
 #include <cstring>
@@ -37,14 +36,13 @@ static long src_callback(void *cb_data, float **data)
 
 AUD_SRCResampleReader::AUD_SRCResampleReader(AUD_IReader* reader,
                                                                                         AUD_Specs specs) :
-               AUD_EffectReader(reader)
+               AUD_EffectReader(reader),
+               m_sspecs(reader->getSpecs()),
+               m_factor(double(specs.rate) / double(m_sspecs.rate)),
+               m_tspecs(specs),
+               m_position(0)
 {
-       m_sspecs = reader->getSpecs();
-
-       m_tspecs = specs;
        m_tspecs.channels = m_sspecs.channels;
-       m_factor = (double)m_tspecs.rate / (double)m_sspecs.rate;
-       m_position = 0;
 
        int error;
        m_src = src_callback_new(src_callback,
@@ -56,23 +54,19 @@ AUD_SRCResampleReader::AUD_SRCResampleReader(AUD_IReader* reader,
        if(!m_src)
        {
                // XXX printf("%s\n", src_strerror(error));
-               delete m_reader; AUD_DELETE("reader")
+               delete m_reader;
                AUD_THROW(AUD_ERROR_READER);
        }
-
-       m_buffer = new AUD_Buffer(); AUD_NEW("buffer")
 }
 
 AUD_SRCResampleReader::~AUD_SRCResampleReader()
 {
        src_delete(m_src);
-
-       delete m_buffer; AUD_DELETE("buffer")
 }
 
 long AUD_SRCResampleReader::doCallback(float** data)
 {
-       int length = m_buffer->getSize() / AUD_SAMPLE_SIZE(m_tspecs);
+       int length = m_buffer.getSize() / AUD_SAMPLE_SIZE(m_tspecs);
        sample_t* buffer;
 
        m_reader->read(length, buffer);
@@ -88,17 +82,17 @@ void AUD_SRCResampleReader::seek(int position)
        m_position = position;
 }
 
-int AUD_SRCResampleReader::getLength()
+int AUD_SRCResampleReader::getLength() const
 {
        return m_reader->getLength() * m_factor;
 }
 
-int AUD_SRCResampleReader::getPosition()
+int AUD_SRCResampleReader::getPosition() const
 {
        return m_position;
 }
 
-AUD_Specs AUD_SRCResampleReader::getSpecs()
+AUD_Specs AUD_SRCResampleReader::getSpecs() const
 {
        return m_tspecs;
 }
@@ -107,10 +101,10 @@ void AUD_SRCResampleReader::read(int & length, sample_t* & buffer)
 {
        int size = length * AUD_SAMPLE_SIZE(m_tspecs);
 
-       if(m_buffer->getSize() < size)
-               m_buffer->resize(size);
+       if(m_buffer.getSize() < size)
+               m_buffer.resize(size);
 
-       buffer = m_buffer->getBuffer();
+       buffer = m_buffer.getBuffer();
 
        length = src_callback_read(m_src, m_factor, length, buffer);
 
index e09d1b66f13c72cc6315b4be1a142e744e7397eb..5e3dafb359beca3112d45fc29d417a697a2c7c9c 100644 (file)
@@ -27,7 +27,7 @@
 #define AUD_SRCRESAMPLEREADER
 
 #include "AUD_EffectReader.h"
-class AUD_Buffer;
+#include "AUD_Buffer.h"
 
 #include <samplerate.h>
 
@@ -37,26 +37,26 @@ class AUD_Buffer;
 class AUD_SRCResampleReader : public AUD_EffectReader
 {
 private:
+       /**
+        * The sample specification of the source.
+        */
+       const AUD_Specs m_sspecs;
+
        /**
         * The resampling factor.
         */
-       double m_factor;
+       const double m_factor;
 
        /**
         * The sound output buffer.
         */
-       AUD_Buffer *m_buffer;
+       AUD_Buffer m_buffer;
 
        /**
         * The target specification.
         */
        AUD_Specs m_tspecs;
 
-       /**
-        * The sample specification of the source.
-        */
-       AUD_Specs m_sspecs;
-
        /**
         * The src state structure.
         */
@@ -67,14 +67,17 @@ private:
         */
        int m_position;
 
+       // hide copy constructor and operator=
+       AUD_SRCResampleReader(const AUD_SRCResampleReader&);
+       AUD_SRCResampleReader& operator=(const AUD_SRCResampleReader&);
+
 public:
        /**
         * Creates a resampling reader.
         * \param reader The reader to mix.
         * \param specs The target specification.
         * \exception AUD_Exception Thrown if the source specification cannot be
-        *            mixed to the target specification or if the reader is
-        *            NULL.
+        *            resampled to the target specification.
         */
        AUD_SRCResampleReader(AUD_IReader* reader, AUD_Specs specs);
 
@@ -92,9 +95,9 @@ public:
        long doCallback(float** data);
 
        virtual void seek(int position);
-       virtual int getLength();
-       virtual int getPosition();
-       virtual AUD_Specs getSpecs();
+       virtual int getLength() const;
+       virtual int getPosition() const;
+       virtual AUD_Specs getSpecs() const;
        virtual void read(int & length, sample_t* & buffer);
 };
 
index 8e71c97baec891829df9d24bcb333d8ea730f14c..cad64d70790471f70a56a67fc62237c235438f0c 100644 (file)
  */
 
 // needed for INT64_C
+#ifndef __STDC_CONSTANT_MACROS
 #define __STDC_CONSTANT_MACROS
+#endif
 
 #include "AUD_FFMPEGFactory.h"
 #include "AUD_FFMPEGReader.h"
 #include "AUD_Buffer.h"
 
-AUD_FFMPEGFactory::AUD_FFMPEGFactory(const char* filename)
+AUD_FFMPEGFactory::AUD_FFMPEGFactory(std::string filename) :
+               m_filename(filename)
 {
-       if(filename != NULL)
-       {
-               m_filename = new char[strlen(filename)+1]; AUD_NEW("string")
-               strcpy(m_filename, filename);
-       }
-       else
-               m_filename = NULL;
 }
 
-AUD_FFMPEGFactory::AUD_FFMPEGFactory(unsigned char* buffer, int size)
+AUD_FFMPEGFactory::AUD_FFMPEGFactory(const data_t* buffer, int size) :
+               m_buffer(new AUD_Buffer(size))
 {
-       m_filename = NULL;
-       m_buffer = AUD_Reference<AUD_Buffer>(new AUD_Buffer(size));
        memcpy(m_buffer.get()->getBuffer(), buffer, size);
 }
 
-AUD_FFMPEGFactory::~AUD_FFMPEGFactory()
-{
-       if(m_filename)
-       {
-               delete[] m_filename; AUD_DELETE("string")
-       }
-}
-
-AUD_IReader* AUD_FFMPEGFactory::createReader()
+AUD_IReader* AUD_FFMPEGFactory::createReader() const
 {
-       AUD_IReader* reader;
-       if(m_filename)
-               reader = new AUD_FFMPEGReader(m_filename);
+       if(m_buffer.get())
+               return new AUD_FFMPEGReader(m_buffer);
        else
-               reader = new AUD_FFMPEGReader(m_buffer);
-       AUD_NEW("reader")
-       return reader;
+               return new AUD_FFMPEGReader(m_filename);
 }
index 22560303a738c3e4e57d3ab217daff5bc7c226cf..43a6ce68ca777f13bbdf01ddb4750bd738d1a78f 100644 (file)
@@ -30,6 +30,8 @@
 #include "AUD_Reference.h"
 class AUD_Buffer;
 
+#include <string>
+
 /**
  * This factory reads a sound file via ffmpeg.
  * \warning Notice that the needed formats and codecs have to be registered
@@ -41,33 +43,32 @@ private:
        /**
         * The filename of the sound source file.
         */
-       char* m_filename;
+       const std::string m_filename;
 
        /**
         * The buffer to read from.
         */
        AUD_Reference<AUD_Buffer> m_buffer;
 
+       // hide copy constructor and operator=
+       AUD_FFMPEGFactory(const AUD_FFMPEGFactory&);
+       AUD_FFMPEGFactory& operator=(const AUD_FFMPEGFactory&);
+
 public:
        /**
         * Creates a new factory.
         * \param filename The sound file path.
         */
-       AUD_FFMPEGFactory(const char* filename);
+       AUD_FFMPEGFactory(std::string filename);
 
        /**
         * Creates a new factory.
         * \param buffer The buffer to read from.
         * \param size The size of the buffer.
         */
-       AUD_FFMPEGFactory(unsigned char* buffer, int size);
-
-       /**
-        * Destroys the factory.
-        */
-       ~AUD_FFMPEGFactory();
+       AUD_FFMPEGFactory(const data_t* buffer, int size);
 
-       virtual AUD_IReader* createReader();
+       virtual AUD_IReader* createReader() const;
 };
 
 #endif //AUD_FFMPEGFACTORY
index 313ea52e892a284a8590fbf33efc5a78b3e80b0e..717838bc982f4ff7e03e6de306b59c061e2a2ecb 100644 (file)
  */
 
 // needed for INT64_C
+#ifndef __STDC_CONSTANT_MACROS
 #define __STDC_CONSTANT_MACROS
+#endif
 
 #include "AUD_FFMPEGReader.h"
-#include "AUD_Buffer.h"
 
 extern "C" {
 #include <libavcodec/avcodec.h>
 #include <libavformat/avformat.h>
 }
 
-int AUD_FFMPEGReader::decode(AVPacket* packet, AUD_Buffer* buffer)
+int AUD_FFMPEGReader::decode(AVPacket* packet, AUD_Buffer& buffer)
 {
        // save packet parameters
        uint8_t *audio_pkg_data = packet->data;
        int audio_pkg_size = packet->size;
 
-       int buf_size = buffer->getSize();
+       int buf_size = buffer.getSize();
        int buf_pos = 0;
 
        int read_length, data_size;
@@ -51,21 +52,16 @@ int AUD_FFMPEGReader::decode(AVPacket* packet, AUD_Buffer* buffer)
                // resize buffer if needed
                if(buf_size - buf_pos < AVCODEC_MAX_AUDIO_FRAME_SIZE)
                {
-                       buffer->resize(buf_size + AVCODEC_MAX_AUDIO_FRAME_SIZE, true);
+                       buffer.resize(buf_size + AVCODEC_MAX_AUDIO_FRAME_SIZE, true);
                        buf_size += AVCODEC_MAX_AUDIO_FRAME_SIZE;
                }
 
                // read samples from the packet
                data_size = buf_size - buf_pos;
-               /*read_length = avcodec_decode_audio3(m_codecCtx,
-                       (int16_t*)(((data_t*)buffer->getBuffer())+buf_pos),
+               read_length = avcodec_decode_audio3(m_codecCtx,
+                       (int16_t*)(((data_t*)buffer.getBuffer())+buf_pos),
                        &data_size,
-                       packet);*/
-               read_length = avcodec_decode_audio2(m_codecCtx,
-                       (int16_t*)(((data_t*)buffer->getBuffer())+buf_pos),
-                       &data_size,
-                       audio_pkg_data,
-                       audio_pkg_size);
+                       packet);
 
                // read error, next packet!
                if(read_length < 0)
@@ -93,12 +89,15 @@ void AUD_FFMPEGReader::init()
        m_stream = -1;
 
        for(unsigned int i = 0; i < m_formatCtx->nb_streams; i++)
+       {
                if((m_formatCtx->streams[i]->codec->codec_type == CODEC_TYPE_AUDIO)
                        && (m_stream < 0))
                {
                        m_stream=i;
                        break;
                }
+       }
+
        if(m_stream == -1)
                AUD_THROW(AUD_ERROR_FFMPEG);
 
@@ -144,41 +143,39 @@ void AUD_FFMPEGReader::init()
        }
 
        m_specs.rate = (AUD_SampleRate) m_codecCtx->sample_rate;
-
-       // last but not least if there hasn't been any error, create the buffers
-       m_buffer = new AUD_Buffer(); AUD_NEW("buffer")
-       m_pkgbuf = new AUD_Buffer(AVCODEC_MAX_AUDIO_FRAME_SIZE<<1);
-       AUD_NEW("buffer")
 }
 
-AUD_FFMPEGReader::AUD_FFMPEGReader(const char* filename)
+AUD_FFMPEGReader::AUD_FFMPEGReader(std::string filename) :
+       m_pkgbuf(AVCODEC_MAX_AUDIO_FRAME_SIZE<<1),
+       m_byteiocontext(NULL)
 {
-       m_byteiocontext = NULL;
-
        // open file
-       if(av_open_input_file(&m_formatCtx, filename, NULL, 0, NULL)!=0)
+       if(av_open_input_file(&m_formatCtx, filename.c_str(), NULL, 0, NULL)!=0)
                AUD_THROW(AUD_ERROR_FILE);
 
        try
        {
                init();
        }
-       catch(AUD_Exception)
+       catch(AUD_Exception&)
        {
                av_close_input_file(m_formatCtx);
                throw;
        }
 }
 
-AUD_FFMPEGReader::AUD_FFMPEGReader(AUD_Reference<AUD_Buffer> buffer)
+AUD_FFMPEGReader::AUD_FFMPEGReader(AUD_Reference<AUD_Buffer> buffer) :
+               m_pkgbuf(AVCODEC_MAX_AUDIO_FRAME_SIZE<<1),
+               m_membuffer(buffer)
 {
        m_byteiocontext = (ByteIOContext*)av_mallocz(sizeof(ByteIOContext));
-       AUD_NEW("byteiocontext")
-       m_membuffer = buffer;
 
        if(init_put_byte(m_byteiocontext, (data_t*)buffer.get()->getBuffer(),
                                         buffer.get()->getSize(), 0, NULL, NULL, NULL, NULL) != 0)
+       {
+               av_free(m_byteiocontext);
                AUD_THROW(AUD_ERROR_FILE);
+       }
 
        AVProbeData probe_data;
        probe_data.filename = "";
@@ -188,16 +185,19 @@ AUD_FFMPEGReader::AUD_FFMPEGReader(AUD_Reference<AUD_Buffer> buffer)
 
        // open stream
        if(av_open_input_stream(&m_formatCtx, m_byteiocontext, "", fmt, NULL)!=0)
+       {
+               av_free(m_byteiocontext);
                AUD_THROW(AUD_ERROR_FILE);
+       }
 
        try
        {
                init();
        }
-       catch(AUD_Exception)
+       catch(AUD_Exception&)
        {
                av_close_input_stream(m_formatCtx);
-               av_free(m_byteiocontext); AUD_DELETE("byteiocontext")
+               av_free(m_byteiocontext);
                throw;
        }
 }
@@ -209,16 +209,13 @@ AUD_FFMPEGReader::~AUD_FFMPEGReader()
        if(m_byteiocontext)
        {
                av_close_input_stream(m_formatCtx);
-               av_free(m_byteiocontext); AUD_DELETE("byteiocontext")
+               av_free(m_byteiocontext);
        }
        else
                av_close_input_file(m_formatCtx);
-
-       delete m_buffer; AUD_DELETE("buffer")
-       delete m_pkgbuf; AUD_DELETE("buffer")
 }
 
-bool AUD_FFMPEGReader::isSeekable()
+bool AUD_FFMPEGReader::isSeekable() const
 {
        return true;
 }
@@ -260,9 +257,17 @@ void AUD_FFMPEGReader::seek(int position)
 
                                                if(m_position < position)
                                                {
-                                                       sample_t* buf;
-                                                       int length = position - m_position;
-                                                       read(length, buf);
+                                                       // read until we're at the right position
+                                                       int length = AUD_DEFAULT_BUFFER_SIZE;
+                                                       sample_t* buffer;
+                                                       for(int len = position - m_position;
+                                                               length == AUD_DEFAULT_BUFFER_SIZE;
+                                                               len -= AUD_DEFAULT_BUFFER_SIZE)
+                                                       {
+                                                               if(len < AUD_DEFAULT_BUFFER_SIZE)
+                                                                       length = len;
+                                                               read(length, buffer);
+                                                       }
                                                }
                                        }
                                }
@@ -276,33 +281,23 @@ void AUD_FFMPEGReader::seek(int position)
        }
 }
 
-int AUD_FFMPEGReader::getLength()
+int AUD_FFMPEGReader::getLength() const
 {
        // return approximated remaning size
        return (int)((m_formatCtx->duration * m_codecCtx->sample_rate)
                                 / AV_TIME_BASE)-m_position;
 }
 
-int AUD_FFMPEGReader::getPosition()
+int AUD_FFMPEGReader::getPosition() const
 {
        return m_position;
 }
 
-AUD_Specs AUD_FFMPEGReader::getSpecs()
+AUD_Specs AUD_FFMPEGReader::getSpecs() const
 {
        return m_specs.specs;
 }
 
-AUD_ReaderType AUD_FFMPEGReader::getType()
-{
-       return AUD_TYPE_STREAM;
-}
-
-bool AUD_FFMPEGReader::notify(AUD_Message &message)
-{
-       return false;
-}
-
 void AUD_FFMPEGReader::read(int & length, sample_t* & buffer)
 {
        // read packages and decode them
@@ -313,10 +308,10 @@ void AUD_FFMPEGReader::read(int & length, sample_t* & buffer)
        int sample_size = AUD_DEVICE_SAMPLE_SIZE(m_specs);
 
        // resize output buffer if necessary
-       if(m_buffer->getSize() < length * AUD_SAMPLE_SIZE(m_specs))
-               m_buffer->resize(length * AUD_SAMPLE_SIZE(m_specs));
+       if(m_buffer.getSize() < length * AUD_SAMPLE_SIZE(m_specs))
+               m_buffer.resize(length * AUD_SAMPLE_SIZE(m_specs));
 
-       buffer = m_buffer->getBuffer();
+       buffer = m_buffer.getBuffer();
        pkgbuf_pos = m_pkgbuf_left;
        m_pkgbuf_left = 0;
 
@@ -324,7 +319,7 @@ void AUD_FFMPEGReader::read(int & length, sample_t* & buffer)
        if(pkgbuf_pos > 0)
        {
                data_size = AUD_MIN(pkgbuf_pos, left * sample_size);
-               m_convert((data_t*) buffer, (data_t*) m_pkgbuf->getBuffer(),
+               m_convert((data_t*) buffer, (data_t*) m_pkgbuf.getBuffer(),
                                  data_size / AUD_FORMAT_SIZE(m_specs.format));
                buffer += data_size / AUD_FORMAT_SIZE(m_specs.format);
                left -= data_size/sample_size;
@@ -341,7 +336,7 @@ void AUD_FFMPEGReader::read(int & length, sample_t* & buffer)
 
                        // copy to output buffer
                        data_size = AUD_MIN(pkgbuf_pos, left * sample_size);
-                       m_convert((data_t*) buffer, (data_t*) m_pkgbuf->getBuffer(),
+                       m_convert((data_t*) buffer, (data_t*) m_pkgbuf.getBuffer(),
                                          data_size / AUD_FORMAT_SIZE(m_specs.format));
                        buffer += data_size / AUD_FORMAT_SIZE(m_specs.format);
                        left -= data_size/sample_size;
@@ -352,12 +347,12 @@ void AUD_FFMPEGReader::read(int & length, sample_t* & buffer)
        if(pkgbuf_pos > data_size)
        {
                m_pkgbuf_left = pkgbuf_pos-data_size;
-               memmove(m_pkgbuf->getBuffer(),
-                               ((data_t*)m_pkgbuf->getBuffer())+data_size,
+               memmove(m_pkgbuf.getBuffer(),
+                               ((data_t*)m_pkgbuf.getBuffer())+data_size,
                                pkgbuf_pos-data_size);
        }
 
-       buffer = m_buffer->getBuffer();
+       buffer = m_buffer.getBuffer();
 
        if(left > 0)
                length -= left;
index f992fdf7a340997bda1c6ab6f9b93f8b7da1438c..8ebf5b45cdcc6810a46e9a17ac43bc99ffc5815b 100644 (file)
@@ -29,7 +29,9 @@
 #include "AUD_ConverterFunctions.h"
 #include "AUD_IReader.h"
 #include "AUD_Reference.h"
-class AUD_Buffer;
+#include "AUD_Buffer.h"
+
+#include <string>
 
 struct AVCodecContext;
 extern "C" {
@@ -55,7 +57,7 @@ private:
        /**
         * The playback buffer.
         */
-       AUD_Buffer *m_buffer;
+       AUD_Buffer m_buffer;
 
        /**
         * The specification of the audio data.
@@ -65,7 +67,7 @@ private:
        /**
         * The buffer for package reading.
         */
-       AUD_Buffer *m_pkgbuf;
+       AUD_Buffer m_pkgbuf;
 
        /**
         * The count of samples still available from the last read package.
@@ -108,13 +110,17 @@ private:
         * \param buffer The target buffer.
         * \return The count of read bytes.
         */
-       int decode(AVPacket* packet, AUD_Buffer* buffer);
+       int decode(AVPacket* packet, AUD_Buffer& buffer);
 
        /**
         * Initializes the object.
         */
        void init();
 
+       // hide copy constructor and operator=
+       AUD_FFMPEGReader(const AUD_FFMPEGReader&);
+       AUD_FFMPEGReader& operator=(const AUD_FFMPEGReader&);
+
 public:
        /**
         * Creates a new reader.
@@ -122,7 +128,7 @@ public:
         * \exception AUD_Exception Thrown if the file specified does not exist or
         *            cannot be read with ffmpeg.
         */
-       AUD_FFMPEGReader(const char* filename);
+       AUD_FFMPEGReader(std::string filename);
 
        /**
         * Creates a new reader.
@@ -137,13 +143,11 @@ public:
         */
        virtual ~AUD_FFMPEGReader();
 
-       virtual bool isSeekable();
+       virtual bool isSeekable() const;
        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 int getLength() const;
+       virtual int getPosition() const;
+       virtual AUD_Specs getSpecs() const;
        virtual void read(int & length, sample_t* & buffer);
 };
 
index 7a8fd3b94d52cca4c15bb37a7af43429fd0e9721..bb63a3ec818a73652458ce790ce74e6d889c0419 100644 (file)
@@ -83,7 +83,6 @@ public:
         * \param reader The reader to read from.
         * \param low The lowest passed frequency.
         * \param high The highest passed frequency.
-        * \exception AUD_Exception Thrown if the reader specified is NULL.
         */
        AUD_BandPassReader(AUD_IReader* reader, float low, float high);
 
index a8e74a023bf91fad03ab4d595c43ac69b6f31708..11eed399ca5abbed89e002b282f98da3fa66dbc4 100644 (file)
 AUD_Buffer::AUD_Buffer(int size)
 {
        m_size = size;
-       m_buffer = (data_t*) malloc(size+16); AUD_NEW("buffer")
+       m_buffer = (data_t*) malloc(size+16);
 }
 
 AUD_Buffer::~AUD_Buffer()
 {
-       free(m_buffer); AUD_DELETE("buffer")
+       free(m_buffer);
 }
 
-sample_t* AUD_Buffer::getBuffer()
+sample_t* AUD_Buffer::getBuffer() const
 {
        return (sample_t*) AUD_ALIGN(m_buffer);
 }
 
-int AUD_Buffer::getSize()
+int AUD_Buffer::getSize() const
 {
        return m_size;
 }
 
 void AUD_Buffer::resize(int size, bool keep)
 {
-       data_t* buffer = (data_t*) malloc(size+16); AUD_NEW("buffer")
-
-       // copy old data over if wanted
        if(keep)
+       {
+               data_t* buffer = (data_t*) malloc(size + 16);
+
                memcpy(AUD_ALIGN(buffer), AUD_ALIGN(m_buffer), AUD_MIN(size, m_size));
 
-       free(m_buffer); AUD_DELETE("buffer")
+               free(m_buffer);
+               m_buffer = buffer;
+       }
+       else
+               m_buffer = (data_t*) realloc(m_buffer, size + 16);
 
-       m_buffer = buffer;
        m_size = size;
 }
index f745ee6154b773a7dc6325a84fc13f5cf5e4865d..b3889b35ffecd6fc515b456e38f06619923b59e6 100644 (file)
@@ -41,6 +41,10 @@ private:
        /// The pointer to the buffer memory.
        data_t* m_buffer;
 
+       // hide copy constructor and operator=
+       AUD_Buffer(const AUD_Buffer&);
+       AUD_Buffer& operator=(const AUD_Buffer&);
+
 public:
        /**
         * Creates a new buffer.
@@ -56,12 +60,12 @@ public:
        /**
         * Returns the pointer to the buffer in memory.
         */
-       sample_t* getBuffer();
+       sample_t* getBuffer() const;
 
        /**
         * Returns the size of the buffer in bytes.
         */
-       int getSize();
+       int getSize() const;
 
        /**
         * Resizes the buffer.
index 0101de338bdf233f6da19d736f6710aec2541d04..d3af549a868f6ef2ed9a7e5c1fb617dc71642b4b 100644 (file)
 #include "AUD_Space.h"
 
 AUD_BufferReader::AUD_BufferReader(AUD_Reference<AUD_Buffer> buffer,
-                                                                  AUD_Specs specs)
+                                                                  AUD_Specs specs) :
+       m_position(0), m_buffer(buffer), m_specs(specs)
 {
-       m_position = 0;
-       m_buffer = buffer;
-       m_specs = specs;
 }
 
-bool AUD_BufferReader::isSeekable()
+bool AUD_BufferReader::isSeekable() const
 {
        return true;
 }
 
 void AUD_BufferReader::seek(int position)
 {
-       if(position < 0)
-               m_position = 0;
-       else if(position > m_buffer.get()->getSize() / AUD_SAMPLE_SIZE(m_specs))
-               m_position = m_buffer.get()->getSize() / AUD_SAMPLE_SIZE(m_specs);
-       else
-               m_position = position;
+       m_position = position;
 }
 
-int AUD_BufferReader::getLength()
+int AUD_BufferReader::getLength() const
 {
-       return m_buffer.get()->getSize()/AUD_SAMPLE_SIZE(m_specs);
+       return m_buffer.get()->getSize() / AUD_SAMPLE_SIZE(m_specs);
 }
 
-int AUD_BufferReader::getPosition()
+int AUD_BufferReader::getPosition() const
 {
        return m_position;
 }
 
-AUD_Specs AUD_BufferReader::getSpecs()
+AUD_Specs AUD_BufferReader::getSpecs() const
 {
        return m_specs;
 }
 
-AUD_ReaderType AUD_BufferReader::getType()
-{
-       return AUD_TYPE_BUFFER;
-}
-
-bool AUD_BufferReader::notify(AUD_Message &message)
-{
-       return false;
-}
-
 void AUD_BufferReader::read(int & length, sample_t* & buffer)
 {
        int sample_size = AUD_SAMPLE_SIZE(m_specs);
index f2d8ff6b57d77a36c088be2a18c7e12e6bfa98ae..a8bd89060b04b2a2a70747a040a5f141f8f33034 100644 (file)
@@ -53,6 +53,10 @@ private:
         */
        AUD_Specs m_specs;
 
+       // hide copy constructor and operator=
+       AUD_BufferReader(const AUD_BufferReader&);
+       AUD_BufferReader& operator=(const AUD_BufferReader&);
+
 public:
        /**
         * Creates a new buffer reader.
@@ -61,13 +65,11 @@ public:
         */
        AUD_BufferReader(AUD_Reference<AUD_Buffer> buffer, AUD_Specs specs);
 
-       virtual bool isSeekable();
+       virtual bool isSeekable() const;
        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 int getLength() const;
+       virtual int getPosition() const;
+       virtual AUD_Specs getSpecs() const;
        virtual void read(int & length, sample_t* & buffer);
 };
 
index eb0e4fba8e914c8064c13cec80bb55321b13c225..905212531d17906b3eed060ae6c853ccc2547cf5 100644 (file)
@@ -155,7 +155,7 @@ int AUD_init(AUD_DeviceType device, AUD_DeviceSpecs specs, int buffersize)
 
                return true;
        }
-       catch(AUD_Exception)
+       catch(AUD_Exception&)
        {
                return false;
        }
@@ -284,7 +284,7 @@ AUD_Sound* AUD_bufferSound(AUD_Sound* sound)
        {
                return new AUD_StreamBufferFactory(sound);
        }
-       catch(AUD_Exception)
+       catch(AUD_Exception&)
        {
                return NULL;
        }
@@ -298,7 +298,7 @@ AUD_Sound* AUD_delaySound(AUD_Sound* sound, float delay)
        {
                return new AUD_DelayFactory(sound, delay);
        }
-       catch(AUD_Exception)
+       catch(AUD_Exception&)
        {
                return NULL;
        }
@@ -312,7 +312,7 @@ AUD_Sound* AUD_limitSound(AUD_Sound* sound, float start, float end)
        {
                return new AUD_LimiterFactory(sound, start, end);
        }
-       catch(AUD_Exception)
+       catch(AUD_Exception&)
        {
                return NULL;
        }
@@ -326,7 +326,7 @@ AUD_Sound* AUD_pingpongSound(AUD_Sound* sound)
        {
                return new AUD_PingPongFactory(sound);
        }
-       catch(AUD_Exception)
+       catch(AUD_Exception&)
        {
                return NULL;
        }
@@ -340,7 +340,7 @@ AUD_Sound* AUD_loopSound(AUD_Sound* sound)
        {
                return new AUD_LoopFactory(sound);
        }
-       catch(AUD_Exception)
+       catch(AUD_Exception&)
        {
                return NULL;
        }
@@ -350,6 +350,8 @@ int AUD_setLoop(AUD_Channel* handle, int loops, float time)
 {
        if(handle)
        {
+               /* AUD_XXX Doesn't work atm, will come back
+
                AUD_Message message;
                message.type = AUD_MSG_LOOP;
                message.loopcount = loops;
@@ -359,9 +361,9 @@ int AUD_setLoop(AUD_Channel* handle, int loops, float time)
                {
                        return AUD_device->sendMessage(handle, message);
                }
-               catch(AUD_Exception)
+               catch(AUD_Exception&)
                {
-               }
+               }*/
        }
        return false;
 }
@@ -374,7 +376,7 @@ AUD_Sound* AUD_rectifySound(AUD_Sound* sound)
        {
                return new AUD_RectifyFactory(sound);
        }
-       catch(AUD_Exception)
+       catch(AUD_Exception&)
        {
                return NULL;
        }
@@ -394,7 +396,7 @@ AUD_Channel* AUD_play(AUD_Sound* sound, int keep)
        {
                return AUD_device->play(sound, keep);
        }
-       catch(AUD_Exception)
+       catch(AUD_Exception&)
        {
                return NULL;
        }
@@ -455,7 +457,7 @@ AUD_Channel* AUD_play3D(AUD_Sound* sound, int keep)
                else
                        return AUD_device->play(sound, keep);
        }
-       catch(AUD_Exception)
+       catch(AUD_Exception&)
        {
                return NULL;
        }
@@ -471,7 +473,7 @@ int AUD_updateListener(AUD_3DData* data)
                if(AUD_3ddevice)
                        return AUD_3ddevice->updateListener(*data);
        }
-       catch(AUD_Exception)
+       catch(AUD_Exception&)
        {
        }
        return false;
@@ -486,7 +488,7 @@ int AUD_set3DSetting(AUD_3DSetting setting, float value)
                if(AUD_3ddevice)
                        return AUD_3ddevice->setSetting(setting, value);
        }
-       catch(AUD_Exception)
+       catch(AUD_Exception&)
        {
        }
        return false;
@@ -501,7 +503,7 @@ float AUD_get3DSetting(AUD_3DSetting setting)
                if(AUD_3ddevice)
                        return AUD_3ddevice->getSetting(setting);
        }
-       catch(AUD_Exception)
+       catch(AUD_Exception&)
        {
        }
        return 0.0f;
@@ -519,7 +521,7 @@ int AUD_update3DSource(AUD_Channel* handle, AUD_3DData* data)
                        if(AUD_3ddevice)
                                return AUD_3ddevice->updateSource(handle, *data);
                }
-               catch(AUD_Exception)
+               catch(AUD_Exception&)
                {
                }
        }
@@ -538,7 +540,7 @@ int AUD_set3DSourceSetting(AUD_Channel* handle,
                        if(AUD_3ddevice)
                                return AUD_3ddevice->setSourceSetting(handle, setting, value);
                }
-               catch(AUD_Exception)
+               catch(AUD_Exception&)
                {
                }
        }
@@ -556,7 +558,7 @@ float AUD_get3DSourceSetting(AUD_Channel* handle, AUD_3DSourceSetting setting)
                        if(AUD_3ddevice)
                                return AUD_3ddevice->getSourceSetting(handle, setting);
                }
-               catch(AUD_Exception)
+               catch(AUD_Exception&)
                {
                }
        }
@@ -576,7 +578,7 @@ int AUD_setSoundVolume(AUD_Channel* handle, float volume)
                {
                        return AUD_device->setCapability(AUD_CAPS_SOURCE_VOLUME, &caps);
                }
-               catch(AUD_Exception) {}
+               catch(AUD_Exception&) {}
        }
        return false;
 }
@@ -594,7 +596,7 @@ int AUD_setSoundPitch(AUD_Channel* handle, float pitch)
                {
                        return AUD_device->setCapability(AUD_CAPS_SOURCE_PITCH, &caps);
                }
-               catch(AUD_Exception) {}
+               catch(AUD_Exception&) {}
        }
        return false;
 }
@@ -605,7 +607,7 @@ AUD_Device* AUD_openReadDevice(AUD_DeviceSpecs specs)
        {
                return new AUD_ReadDevice(specs);
        }
-       catch(AUD_Exception)
+       catch(AUD_Exception&)
        {
                return NULL;
        }
@@ -622,7 +624,7 @@ AUD_Channel* AUD_playDevice(AUD_Device* device, AUD_Sound* sound, float seek)
                device->seek(handle, seek);
                return handle;
        }
-       catch(AUD_Exception)
+       catch(AUD_Exception&)
        {
                return NULL;
        }
@@ -636,7 +638,7 @@ int AUD_setDeviceVolume(AUD_Device* device, float volume)
        {
                return device->setCapability(AUD_CAPS_VOLUME, &volume);
        }
-       catch(AUD_Exception) {}
+       catch(AUD_Exception&) {}
        
        return false;
 }
@@ -655,7 +657,7 @@ int AUD_setDeviceSoundVolume(AUD_Device* device, AUD_Channel* handle,
                {
                        return device->setCapability(AUD_CAPS_SOURCE_VOLUME, &caps);
                }
-               catch(AUD_Exception) {}
+               catch(AUD_Exception&) {}
        }
        return false;
 }
@@ -669,7 +671,7 @@ int AUD_readDevice(AUD_Device* device, data_t* buffer, int length)
        {
                return device->read(buffer, length);
        }
-       catch(AUD_Exception)
+       catch(AUD_Exception&)
        {
                return false;
        }
@@ -683,7 +685,7 @@ void AUD_closeReadDevice(AUD_Device* device)
        {
                delete device;
        }
-       catch(AUD_Exception)
+       catch(AUD_Exception&)
        {
        }
 }
@@ -782,23 +784,16 @@ void AUD_muteSequencer(AUD_Sound* sequencer, AUD_SequencerEntry* entry, char mut
 
 int AUD_readSound(AUD_Sound* sound, sample_t* buffer, int length)
 {
-       AUD_IReader* reader = sound->createReader();
        AUD_DeviceSpecs specs;
        sample_t* buf;
 
-       specs.specs = reader->getSpecs();
+       specs.rate = AUD_RATE_INVALID;
        specs.channels = AUD_CHANNELS_MONO;
-       specs.format = AUD_FORMAT_FLOAT32;
-
-       AUD_ChannelMapperFactory mapper(reader, specs);
-
-       if(!reader || reader->getType() != AUD_TYPE_BUFFER)
-               return -1;
+       specs.format = AUD_FORMAT_INVALID;
 
-       reader = mapper.createReader();
+       AUD_ChannelMapperFactory mapper(sound, specs);
 
-       if(!reader)
-               return -1;
+       AUD_IReader* reader = mapper.createReader();
 
        int len = reader->getLength();
        float samplejump = (float)len / (float)length;
@@ -827,7 +822,7 @@ int AUD_readSound(AUD_Sound* sound, sample_t* buffer, int length)
                }
        }
 
-       delete reader; AUD_DELETE("reader")
+       delete reader;
 
        return length;
 }
@@ -894,16 +889,3 @@ int AUD_doesPlayback()
 #endif
        return -1;
 }
-
-#ifdef AUD_DEBUG_MEMORY
-int AUD_References(int count, const char* text)
-{
-       static int m_count = 0;
-       m_count += count;
-       if(count > 0)
-               printf("+%s\n", text);
-       if(count < 0)
-               printf("-%s\n", text);
-       return m_count;
-}
-#endif
index 3420ed166496459ae92517b41d0769364ca49a74..b3d5434b1e32601d07784b038c4657e220034c0a 100644 (file)
 
 #include <cstring>
 
-AUD_ChannelMapperFactory::AUD_ChannelMapperFactory(AUD_IReader* reader,
-                                                                                                  AUD_DeviceSpecs specs) :
-               AUD_MixerFactory(reader, specs)
-{
-       memset(m_mapping, 0, sizeof(m_mapping));
-}
-
 AUD_ChannelMapperFactory::AUD_ChannelMapperFactory(AUD_IFactory* factory,
                                                                                                   AUD_DeviceSpecs specs) :
                AUD_MixerFactory(factory, specs)
@@ -42,12 +35,6 @@ AUD_ChannelMapperFactory::AUD_ChannelMapperFactory(AUD_IFactory* factory,
        memset(m_mapping, 0, sizeof(m_mapping));
 }
 
-AUD_ChannelMapperFactory::AUD_ChannelMapperFactory(AUD_DeviceSpecs specs) :
-               AUD_MixerFactory(specs)
-{
-       memset(m_mapping, 0, sizeof(m_mapping));
-}
-
 AUD_ChannelMapperFactory::~AUD_ChannelMapperFactory()
 {
        for(int i = 1; i < 10; i++)
@@ -72,12 +59,12 @@ float** AUD_ChannelMapperFactory::getMapping(int ic)
        {
                int channels = m_specs.channels;
 
-               m_mapping[ic] = new float*[channels+1]; AUD_NEW("mapping")
+               m_mapping[ic] = new float*[channels+1];
                m_mapping[ic][channels] = 0;
 
                for(int i = 0; i < channels; i++)
                {
-                       m_mapping[ic][i] = new float[ic+1]; AUD_NEW("mapping")
+                       m_mapping[ic][i] = new float[ic+1];
                        for(int j = 0; j <= ic; j++)
                                m_mapping[ic][i][j] = ((i == j) || (channels == 1) ||
                                                                           (ic == 0)) ? 1.0f : 0.0f;
@@ -99,27 +86,21 @@ void AUD_ChannelMapperFactory::deleteMapping(int ic)
                {
                        if(m_mapping[ic][i] != 0)
                        {
-                               delete[] m_mapping[ic][i]; AUD_DELETE("mapping")
+                               delete[] m_mapping[ic][i];
                        }
                        else
                                break;
                }
-               delete[] m_mapping[ic]; AUD_DELETE("mapping")
+               delete[] m_mapping[ic];
                m_mapping[ic] = 0;
        }
 }
 
-AUD_IReader* AUD_ChannelMapperFactory::createReader()
+AUD_IReader* AUD_ChannelMapperFactory::createReader() const
 {
        AUD_IReader* reader = getReader();
+       int ic = reader->getSpecs().channels;
 
-       if(reader != 0)
-       {
-               int ic = reader->getSpecs().channels;
-
-               reader = new AUD_ChannelMapperReader(reader, getMapping(ic));
-               AUD_NEW("reader")
-       }
-
-       return reader;
+       return new AUD_ChannelMapperReader(reader,
+                                  const_cast<AUD_ChannelMapperFactory*>(this)->getMapping(ic));
 }
index a67bfa12123a44079f72c70ab266f55a0164b0db..2f3158744214899e4035f91a31042e5c6f6d31c9 100644 (file)
@@ -40,10 +40,12 @@ private:
         */
        float **m_mapping[9];
 
+       // hide copy constructor and operator=
+       AUD_ChannelMapperFactory(const AUD_ChannelMapperFactory&);
+       AUD_ChannelMapperFactory& operator=(const AUD_ChannelMapperFactory&);
+
 public:
-       AUD_ChannelMapperFactory(AUD_IReader* reader, AUD_DeviceSpecs specs);
        AUD_ChannelMapperFactory(AUD_IFactory* factory, AUD_DeviceSpecs specs);
-       AUD_ChannelMapperFactory(AUD_DeviceSpecs specs);
 
        virtual ~AUD_ChannelMapperFactory();
 
@@ -59,7 +61,7 @@ public:
         */
        void deleteMapping(int ic);
 
-       virtual AUD_IReader* createReader();
+       virtual AUD_IReader* createReader() const;
 };
 
 #endif //AUD_CHANNELMAPPERFACTORY
index d78278219e80d13b131251206358db401bae2b1f..71b9f35b3a4081889b9d4237af43ece107fe40ca 100644 (file)
@@ -24,7 +24,6 @@
  */
 
 #include "AUD_ChannelMapperReader.h"
-#include "AUD_Buffer.h"
 
 AUD_ChannelMapperReader::AUD_ChannelMapperReader(AUD_IReader* reader,
                                                                                                 float **mapping) :
@@ -36,7 +35,7 @@ AUD_ChannelMapperReader::AUD_ChannelMapperReader(AUD_IReader* reader,
        m_rch = m_specs.channels;
        while(mapping[++channels] != 0);
 
-       m_mapping = new float*[channels]; AUD_NEW("mapping")
+       m_mapping = new float*[channels];
        m_specs.channels = (AUD_Channels)channels;
 
        float sum;
@@ -44,7 +43,7 @@ AUD_ChannelMapperReader::AUD_ChannelMapperReader(AUD_IReader* reader,
 
        while(channels--)
        {
-               m_mapping[channels] = new float[m_rch]; AUD_NEW("mapping")
+               m_mapping[channels] = new float[m_rch];
                sum = 0.0f;
                for(i=0; i < m_rch; i++)
                        sum += mapping[channels][i];
@@ -52,8 +51,6 @@ AUD_ChannelMapperReader::AUD_ChannelMapperReader(AUD_IReader* reader,
                        m_mapping[channels][i] = sum > 0.0f ?
                                                                         mapping[channels][i]/sum : 0.0f;
        }
-
-       m_buffer = new AUD_Buffer(); AUD_NEW("buffer")
 }
 
 AUD_ChannelMapperReader::~AUD_ChannelMapperReader()
@@ -62,42 +59,37 @@ AUD_ChannelMapperReader::~AUD_ChannelMapperReader()
 
        while(channels--)
        {
-               delete[] m_mapping[channels]; AUD_DELETE("mapping")
+               delete[] m_mapping[channels];
        }
 
-       delete[] m_mapping; AUD_DELETE("mapping")
-
-       delete m_buffer; AUD_DELETE("buffer")
+       delete[] m_mapping;
 }
 
-AUD_Specs AUD_ChannelMapperReader::getSpecs()
+AUD_Specs AUD_ChannelMapperReader::getSpecs() const
 {
        return m_specs;
 }
 
 void AUD_ChannelMapperReader::read(int & length, sample_t* & buffer)
 {
-       m_reader->read(length, buffer);
+       sample_t* in = buffer;
 
-       int channels = m_specs.channels;
+       m_reader->read(length, in);
 
-       if(m_buffer->getSize() < length * 4 * channels)
-               m_buffer->resize(length * 4 * channels);
+       if(m_buffer.getSize() < length * AUD_SAMPLE_SIZE(m_specs))
+               m_buffer.resize(length * AUD_SAMPLE_SIZE(m_specs));
 
-       sample_t* in = buffer;
-       sample_t* out = m_buffer->getBuffer();
+       buffer = m_buffer.getBuffer();
        sample_t sum;
 
        for(int i = 0; i < length; i++)
        {
-               for(int j = 0; j < channels; j++)
+               for(int j = 0; j < m_specs.channels; j++)
                {
                        sum = 0;
                        for(int k = 0; k < m_rch; k++)
                                sum += m_mapping[j][k] * in[i * m_rch + k];
-                       out[i * channels + j] = sum;
+                       buffer[i * m_specs.channels + j] = sum;
                }
        }
-
-       buffer = m_buffer->getBuffer();
 }
index fe79ab6edd6f80b52c404aa2dac7230ad1669f2f..398e14da55def608f4806a3d5e41f8d2b0d81cff 100644 (file)
@@ -27,7 +27,7 @@
 #define AUD_CHANNELMAPPERREADER
 
 #include "AUD_EffectReader.h"
-class AUD_Buffer;
+#include "AUD_Buffer.h"
 
 /**
  * This class maps a sound source's channels to a specific output channel count.
@@ -39,7 +39,7 @@ private:
        /**
         * The sound output buffer.
         */
-       AUD_Buffer *m_buffer;
+       AUD_Buffer m_buffer;
 
        /**
         * The output specification.
@@ -56,20 +56,24 @@ private:
         */
        float **m_mapping;
 
+       // hide copy constructor and operator=
+       AUD_ChannelMapperReader(const AUD_ChannelMapperReader&);
+       AUD_ChannelMapperReader& operator=(const AUD_ChannelMapperReader&);
+
 public:
        /**
         * Creates a channel mapper reader.
         * \param reader The reader to map.
         * \param mapping The mapping specification as two dimensional float array.
-        * \exception AUD_Exception Thrown if the reader is NULL.
         */
        AUD_ChannelMapperReader(AUD_IReader* reader, float **mapping);
+
        /**
         * Destroys the reader.
         */
        ~AUD_ChannelMapperReader();
 
-       virtual AUD_Specs getSpecs();
+       virtual AUD_Specs getSpecs() const;
        virtual void read(int & length, sample_t* & buffer);
 };
 
index 1c6d5468251c4dea6f4621cb7153fb631c3e17b4..057d97fe79460df1af7977db84c029abe6c73497 100644 (file)
 #include "AUD_ConverterFactory.h"
 #include "AUD_ConverterReader.h"
 
-AUD_ConverterFactory::AUD_ConverterFactory(AUD_IReader* reader,
-                                                                                  AUD_DeviceSpecs specs) :
-               AUD_MixerFactory(reader, specs) {}
-
 AUD_ConverterFactory::AUD_ConverterFactory(AUD_IFactory* factory,
                                                                                   AUD_DeviceSpecs specs) :
-               AUD_MixerFactory(factory, specs) {}
-
-AUD_ConverterFactory::AUD_ConverterFactory(AUD_DeviceSpecs specs) :
-               AUD_MixerFactory(specs) {}
+               AUD_MixerFactory(factory, specs)
+{
+}
 
-AUD_IReader* AUD_ConverterFactory::createReader()
+AUD_IReader* AUD_ConverterFactory::createReader() const
 {
        AUD_IReader* reader = getReader();
 
-       if(reader != 0)
-       {
-               if(m_specs.format != AUD_FORMAT_FLOAT32)
-               {
-                       reader = new AUD_ConverterReader(reader, m_specs);
-                       AUD_NEW("reader")
-               }
-       }
+       if(m_specs.format != AUD_FORMAT_FLOAT32)
+               reader = new AUD_ConverterReader(reader, m_specs);
 
        return reader;
 }
index 11ca6c9f0a89976c8471ac3e4e46fdf6760f79bc..3535616a4a608ce95cb26a51418807237eec6a40 100644 (file)
  */
 class AUD_ConverterFactory : public AUD_MixerFactory
 {
+private:
+       // hide copy constructor and operator=
+       AUD_ConverterFactory(const AUD_ConverterFactory&);
+       AUD_ConverterFactory& operator=(const AUD_ConverterFactory&);
+
 public:
-       AUD_ConverterFactory(AUD_IReader* reader, AUD_DeviceSpecs specs);
        AUD_ConverterFactory(AUD_IFactory* factory, AUD_DeviceSpecs specs);
-       AUD_ConverterFactory(AUD_DeviceSpecs specs);
 
-       virtual AUD_IReader* createReader();
+       virtual AUD_IReader* createReader() const;
 };
 
 #endif //AUD_CONVERTERFACTORY
index 808144085bbdb5bb4bbe416cc9de724d016e6ab4..379a7c858517794a564abf708895b4518b2f122a 100644 (file)
@@ -24,7 +24,6 @@
  */
 
 #include "AUD_ConverterReader.h"
-#include "AUD_Buffer.h"
 
 AUD_ConverterReader::AUD_ConverterReader(AUD_IReader* reader,
                                                                                 AUD_DeviceSpecs specs) :
@@ -63,16 +62,9 @@ AUD_ConverterReader::AUD_ConverterReader(AUD_IReader* reader,
        }
 
        m_specs.format = specs.format;
-
-       m_buffer = new AUD_Buffer(); AUD_NEW("buffer")
-}
-
-AUD_ConverterReader::~AUD_ConverterReader()
-{
-       delete m_buffer; AUD_DELETE("buffer")
 }
 
-AUD_Specs AUD_ConverterReader::getSpecs()
+AUD_Specs AUD_ConverterReader::getSpecs() const
 {
        return m_specs.specs;
 }
@@ -83,11 +75,11 @@ void AUD_ConverterReader::read(int & length, sample_t* & buffer)
 
        int samplesize = AUD_SAMPLE_SIZE(m_specs);
 
-       if(m_buffer->getSize() < length*samplesize)
-               m_buffer->resize(length*samplesize);
+       if(m_buffer.getSize() < length * samplesize)
+               m_buffer.resize(length * samplesize);
 
-       m_convert((data_t*)m_buffer->getBuffer(), (data_t*)buffer,
+       m_convert((data_t*)m_buffer.getBuffer(), (data_t*)buffer,
                          length * m_specs.channels);
 
-       buffer = m_buffer->getBuffer();
+       buffer = m_buffer.getBuffer();
 }
index ba49bbfd9ba693ffba10067d23b12039cbf7def8..64a46fd63e67f32b45f60adb44c143f768ec777a 100644 (file)
@@ -28,7 +28,7 @@
 
 #include "AUD_EffectReader.h"
 #include "AUD_ConverterFunctions.h"
-class AUD_Buffer;
+#include "AUD_Buffer.h"
 
 /**
  * This class converts a sound source from one to another format.
@@ -39,7 +39,7 @@ private:
        /**
         * The sound output buffer.
         */
-       AUD_Buffer *m_buffer;
+       AUD_Buffer m_buffer;
 
        /**
         * The target specification.
@@ -51,20 +51,19 @@ private:
         */
        AUD_convert_f m_convert;
 
+       // hide copy constructor and operator=
+       AUD_ConverterReader(const AUD_ConverterReader&);
+       AUD_ConverterReader& operator=(const AUD_ConverterReader&);
+
 public:
        /**
         * Creates a converter reader.
         * \param reader The reader to convert.
         * \param specs The target specification.
-        * \exception AUD_Exception Thrown if the reader is NULL.
         */
        AUD_ConverterReader(AUD_IReader* reader, AUD_DeviceSpecs specs);
-       /**
-        * Destroys the reader.
-        */
-       ~AUD_ConverterReader();
 
-       virtual AUD_Specs getSpecs();
+       virtual AUD_Specs getSpecs() const;
        virtual void read(int & length, sample_t* & buffer);
 };
 
diff --git a/intern/audaspace/intern/AUD_DefaultMixer.cpp b/intern/audaspace/intern/AUD_DefaultMixer.cpp
new file mode 100644 (file)
index 0000000..12faa10
--- /dev/null
@@ -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_DefaultMixer.h"
+#include "AUD_SRCResampleReader.h"
+#include "AUD_ChannelMapperReader.h"
+#include "AUD_ChannelMapperFactory.h"
+
+#include <cstring>
+
+AUD_DefaultMixer::AUD_DefaultMixer(AUD_DeviceSpecs specs) :
+       AUD_Mixer(specs)
+{
+}
+
+AUD_IReader* AUD_DefaultMixer::prepare(AUD_IReader* reader)
+{
+       // hacky for now, until a better channel mapper reader is available
+       AUD_ChannelMapperFactory cmf(NULL, m_specs);
+
+       AUD_Specs specs = reader->getSpecs();
+
+       // if channel count is lower in output, rechannel before resampling
+       if(specs.channels < m_specs.channels)
+       {
+               reader = new AUD_ChannelMapperReader(reader,
+                                                                                        cmf.getMapping(specs.channels));
+               specs.channels = m_specs.channels;
+       }
+
+       // resample
+       if(specs.rate != m_specs.rate)
+               reader = new AUD_SRCResampleReader(reader, m_specs.specs);
+
+       // rechannel
+       if(specs.channels != m_specs.channels)
+               reader = new AUD_ChannelMapperReader(reader,
+                                                                                        cmf.getMapping(specs.channels));
+
+       return reader;
+}
diff --git a/intern/audaspace/intern/AUD_DefaultMixer.h b/intern/audaspace/intern/AUD_DefaultMixer.h
new file mode 100644 (file)
index 0000000..c2f6962
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * $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_DEFAULTMIXER
+#define AUD_DEFAULTMIXER
+
+#include "AUD_Mixer.h"
+
+/**
+ * This class is able to mix audiosignals of different channel count and sample
+ * rate and convert it to a specific output format.
+ * It uses a default ChannelMapperFactory and a SRCResampleFactory for
+ * the perparation.
+ */
+class AUD_DefaultMixer : public AUD_Mixer
+{
+public:
+       /**
+        * Creates the mixer.
+        */
+       AUD_DefaultMixer(AUD_DeviceSpecs specs);
+
+       /**
+        * This funuction prepares a reader for playback.
+        * \param reader The reader to prepare.
+        * \return The reader that should be used for playback.
+        */
+       virtual AUD_IReader* prepare(AUD_IReader* reader);
+};
+
+#endif //AUD_DEFAULTMIXER
index 5888479a0bad4b8effc86ed2b06c5a903181e760..616b5ac2c18bd5adfe271e2325c572e9cef3ef55 100644 (file)
@@ -30,7 +30,9 @@
 
 #ifdef WITH_FFMPEG
 // needed for INT64_C
+#ifndef __STDC_CONSTANT_MACROS
 #define __STDC_CONSTANT_MACROS
+#endif
 
 #include "AUD_FFMPEGReader.h"
 #endif
 #include "AUD_SndFileReader.h"
 #endif
 
-AUD_FileFactory::AUD_FileFactory(const char* filename)
+AUD_FileFactory::AUD_FileFactory(std::string filename) :
+       m_filename(filename)
 {
-       if(filename != NULL)
-       {
-               m_filename = new char[strlen(filename)+1]; AUD_NEW("string")
-               strcpy(m_filename, filename);
-       }
-       else
-               m_filename = NULL;
 }
 
-AUD_FileFactory::AUD_FileFactory(unsigned char* buffer, int size)
+AUD_FileFactory::AUD_FileFactory(const data_t* buffer, int size) :
+       m_buffer(new AUD_Buffer(size))
 {
-       m_filename = NULL;
-       m_buffer = AUD_Reference<AUD_Buffer>(new AUD_Buffer(size));
        memcpy(m_buffer.get()->getBuffer(), buffer, size);
 }
 
-AUD_FileFactory::~AUD_FileFactory()
+AUD_IReader* AUD_FileFactory::createReader() const
 {
-       if(m_filename)
-       {
-               delete[] m_filename; AUD_DELETE("string")
-       }
-}
-
-AUD_IReader* AUD_FileFactory::createReader()
-{
-       AUD_IReader* reader = 0;
-
 #ifdef WITH_SNDFILE
        try
        {
-               if(m_filename)
-                       reader = new AUD_SndFileReader(m_filename);
+               if(m_buffer.get())
+                       return new AUD_SndFileReader(m_buffer);
                else
-                       reader = new AUD_SndFileReader(m_buffer);
-               AUD_NEW("reader")
-               return reader;
+                       return new AUD_SndFileReader(m_filename);
        }
-       catch(AUD_Exception e) {}
+       catch(AUD_Exception&) {}
 #endif
 
 #ifdef WITH_FFMPEG
        try
        {
-               if(m_filename)
-                       reader = new AUD_FFMPEGReader(m_filename);
+               if(m_buffer.get())
+                       return new AUD_FFMPEGReader(m_buffer);
                else
-                       reader = new AUD_FFMPEGReader(m_buffer);
-               AUD_NEW("reader")
-               return reader;
+                       return new AUD_FFMPEGReader(m_filename);
        }
-       catch(AUD_Exception e) {}
+       catch(AUD_Exception&) {}
 #endif
 
-       return reader;
+       AUD_THROW(AUD_ERROR_FILE)
 }
index 6ab8f280534b0f72037927456688e27c1d930167..9182667d72e823725e955b57e3be3b0c86970a36 100644 (file)
@@ -30,6 +30,8 @@
 #include "AUD_Reference.h"
 class AUD_Buffer;
 
+#include <string>
+
 /**
  * This factory tries to read a sound file via all available file readers.
  */
@@ -39,33 +41,32 @@ private:
        /**
         * The filename of the sound source file.
         */
-       char* m_filename;
+       std::string m_filename;
 
        /**
         * The buffer to read from.
         */
        AUD_Reference<AUD_Buffer> m_buffer;
 
+       // hide copy constructor and operator=
+       AUD_FileFactory(const AUD_FileFactory&);
+       AUD_FileFactory& operator=(const AUD_FileFactory&);
+
 public:
        /**
         * Creates a new factory.
         * \param filename The sound file path.
         */
-       AUD_FileFactory(const char* filename);
+       AUD_FileFactory(std::string filename);
 
        /**
         * Creates a new factory.
         * \param buffer The buffer to read from.
         * \param size The size of the buffer.
         */
-       AUD_FileFactory(unsigned char* buffer, int size);
-
-       /**
-        * Destroys the factory.
-        */
-       ~AUD_FileFactory();
+       AUD_FileFactory(const data_t* buffer, int size);
 
-       virtual AUD_IReader* createReader();
+       virtual AUD_IReader* createReader() const;
 };
 
 #endif //AUD_FILEFACTORY
index e924f57cefc27ee1bcc3c1b7160ba434f8538d44..663d02e23bef351aafce9b51d168d3f9ed49fba3 100644 (file)
@@ -53,7 +53,7 @@ public:
        /**
         * Returns the specification of the device.
         */
-       virtual AUD_DeviceSpecs getSpecs()=0;
+       virtual AUD_DeviceSpecs getSpecs() const=0;
 
        /**
         * Plays a sound source.
@@ -106,16 +106,6 @@ public:
         */
        virtual bool setKeep(AUD_Handle* handle, bool keep)=0;
 
-       /**
-        * Sends a message to a sound or all sounds that are currently played or
-        * paused.
-        * \param handle The sound that should receive the message or NULL if all
-        *        sounds should receive it.
-        * \param message The message.
-        * \return True if the message has been read by at least one sound.
-        */
-       virtual bool sendMessage(AUD_Handle* handle, AUD_Message &message)=0;
-
        /**
         * Seeks in a played back sound.
         * \param handle The handle returned by the play function.
index f7f29c9e842ef5d11a2885789a6559024f5489f2..aed53cef7492355f9a1416722c2046ef372a86f0 100644 (file)
@@ -49,7 +49,7 @@ public:
         * \exception AUD_Exception An exception may be thrown if there has been
         *            a more unexpected error during reader creation.
         */
-       virtual AUD_IReader* createReader()=0;
+       virtual AUD_IReader* createReader() const=0;
 };
 
 #endif //AUD_IFACTORY
index 4b5631006598d916d260fb00f922f359688352be..baba587ea03ebf4d224429931c0472e680c29b29 100644 (file)
@@ -46,7 +46,7 @@ public:
         * \return Always returns true for readers of the buffer type.
         * \see getType
         */
-       virtual bool isSeekable()=0;
+       virtual bool isSeekable() const=0;
 
        /**
         * Seeks to a specific position in the source.
@@ -65,7 +65,7 @@ public:
         * \return The length as sample count. May be negative if unknown.
         * \see getType
         */
-       virtual int getLength()=0;
+       virtual int getLength() const=0;
 
        /**
         * Returns the position of the source as a sample count value.
@@ -76,30 +76,13 @@ public:
         *          the buffer ones.
         * \see getType
         */
-       virtual int getPosition()=0;
+       virtual int getPosition() const=0;
 
        /**
         * Returns the specification of the reader.
         * \return The AUD_Specs structure.
         */
-       virtual AUD_Specs getSpecs()=0;
-
-       /**
-        * Returns the type of the reader. There are special conditions for the
-        * readers of the buffer type. Those have to return correct position and
-        * length values as well as they must be seekable.
-        * \return AUD_TYPE_BUFFER or AUD_TYPE_STREAM.
-        */
-       virtual AUD_ReaderType getType()=0;
-
-       /**
-        * Sends a message to this reader and if it has subreaders it broadcasts
-        * the message to them.
-        * \param message The message.
-        * \return Whether the message has been read by the reader or one of his
-        *         subreaders.
-        */
-       virtual bool notify(AUD_Message &message)=0;
+       virtual AUD_Specs getSpecs() const=0;
 
        /**
         * Request to read the next length samples out of the source.
index e738fc17693bfa4445176f5e846a59c909ea3da9..91414c6a3922f014f29b04ecb675a30ce6569044 100644 (file)
 #include "AUD_LinearResampleFactory.h"
 #include "AUD_LinearResampleReader.h"
 
-AUD_LinearResampleFactory::AUD_LinearResampleFactory(AUD_IReader* reader,
-                                                                                                        AUD_DeviceSpecs specs) :
-               AUD_ResampleFactory(reader, specs) {}
-
 AUD_LinearResampleFactory::AUD_LinearResampleFactory(AUD_IFactory* factory,
                                                                                                         AUD_DeviceSpecs specs) :
-               AUD_ResampleFactory(factory, specs) {}
-
-AUD_LinearResampleFactory::AUD_LinearResampleFactory(AUD_DeviceSpecs specs) :
-               AUD_ResampleFactory(specs) {}
+               AUD_ResampleFactory(factory, specs)
+{
+}
 
-AUD_IReader* AUD_LinearResampleFactory::createReader()
+AUD_IReader* AUD_LinearResampleFactory::createReader() const
 {
        AUD_IReader* reader = getReader();
 
-       if(reader != 0)
-       {
-               if(reader->getSpecs().rate != m_specs.rate)
-               {
-                       reader = new AUD_LinearResampleReader(reader, m_specs.specs);
-                       AUD_NEW("reader")
-               }
-       }
+       if(reader->getSpecs().rate != m_specs.rate)
+               reader = new AUD_LinearResampleReader(reader, m_specs.specs);
+
        return reader;
 }
index 81a9d62381530fa477b846249623bfe2f9d19a40..426641f60999e15511ebe1d02478d4413cd7de73 100644 (file)
  */
 class AUD_LinearResampleFactory : public AUD_ResampleFactory
 {
+private:
+       // hide copy constructor and operator=
+       AUD_LinearResampleFactory(const AUD_LinearResampleFactory&);
+       AUD_LinearResampleFactory& operator=(const AUD_LinearResampleFactory&);
+
 public:
-       AUD_LinearResampleFactory(AUD_IReader* reader, AUD_DeviceSpecs specs);
        AUD_LinearResampleFactory(AUD_IFactory* factory, AUD_DeviceSpecs specs);
-       AUD_LinearResampleFactory(AUD_DeviceSpecs specs);
 
-       virtual AUD_IReader* createReader();
+       virtual AUD_IReader* createReader() const;
 };
 
 #endif //AUD_LINEARRESAMPLEFACTORY
index dcd5310575dd9c9a421141feb2183f1bea9457bb..cfe7561d3361cdba5fa27c8ab4de9893ea32721d 100644 (file)
@@ -24,7 +24,6 @@
  */
 
 #include "AUD_LinearResampleReader.h"
-#include "AUD_Buffer.h"
 
 #include <cmath>
 #include <cstring>
 
 AUD_LinearResampleReader::AUD_LinearResampleReader(AUD_IReader* reader,
                                                                                                   AUD_Specs specs) :
-               AUD_EffectReader(reader)
+       AUD_EffectReader(reader),
+       m_sspecs(reader->getSpecs()),
+       m_factor(float(specs.rate) / float(m_sspecs.rate)),
+       m_tspecs(specs),
+       m_position(0),
+       m_sposition(0)
 {
-       m_sspecs = reader->getSpecs();
-
-       m_tspecs = specs;
        m_tspecs.channels = m_sspecs.channels;
-       m_factor = (float)m_tspecs.rate / (float)m_sspecs.rate;
-
-       m_position = 0;
-       m_sposition = 0;
-
-       m_buffer = new AUD_Buffer(); AUD_NEW("buffer")
-       m_cache = new AUD_Buffer(2 * AUD_SAMPLE_SIZE(specs)); AUD_NEW("buffer")
-}
-
-AUD_LinearResampleReader::~AUD_LinearResampleReader()
-{
-       delete m_buffer; AUD_DELETE("buffer")
-       delete m_cache; AUD_DELETE("buffer")
+       m_cache.resize(2 * AUD_SAMPLE_SIZE(m_tspecs));
 }
 
 void AUD_LinearResampleReader::seek(int position)
@@ -61,17 +50,17 @@ void AUD_LinearResampleReader::seek(int position)
        m_reader->seek(m_sposition);
 }
 
-int AUD_LinearResampleReader::getLength()
+int AUD_LinearResampleReader::getLength() const
 {
        return m_reader->getLength() * m_factor;
 }
 
-int AUD_LinearResampleReader::getPosition()
+int AUD_LinearResampleReader::getPosition() const
 {
        return m_position;
 }
 
-AUD_Specs AUD_LinearResampleReader::getSpecs()
+AUD_Specs AUD_LinearResampleReader::getSpecs() const
 {
        return m_tspecs;
 }
@@ -81,13 +70,13 @@ void AUD_LinearResampleReader::read(int & length, sample_t* & buffer)
        int samplesize = AUD_SAMPLE_SIZE(m_tspecs);
        int size = length * samplesize;
 
-       if(m_buffer->getSize() < size)
-               m_buffer->resize(size);
+       if(m_buffer.getSize() < size)
+               m_buffer.resize(size);
 
        int need = ceil((m_position + length) / m_factor) + 1 - m_sposition;
        int len = need;
        sample_t* buf;
-       buffer = m_buffer->getBuffer();
+       buffer = m_buffer.getBuffer();
 
        m_reader->read(len, buf);
 
@@ -106,9 +95,9 @@ void AUD_LinearResampleReader::read(int & length, sample_t* & buffer)
 
                        if(floor(spos) < 0)
                        {
-                               low = m_cache->getBuffer()[(int)(floor(spos) + 2) * CC];
+                               low = m_cache.getBuffer()[(int)(floor(spos) + 2) * CC];
                                if(ceil(spos) < 0)
-                                       high = m_cache->getBuffer()[(int)(ceil(spos) + 2) * CC];
+                                       high = m_cache.getBuffer()[(int)(ceil(spos) + 2) * CC];
                                else
                                        high = buf[(int)ceil(spos) * CC];
                        }
@@ -122,11 +111,11 @@ void AUD_LinearResampleReader::read(int & length, sample_t* & buffer)
        }
 
        if(len > 1)
-               memcpy(m_cache->getBuffer(),
+               memcpy(m_cache.getBuffer(),
                           buf + (len - 2) * channels,
                           2 * samplesize);
        else if(len == 1)
-               memcpy(m_cache->getBuffer() + 1 * channels, buf, samplesize);
+               memcpy(m_cache.getBuffer() + 1 * channels, buf, samplesize);
 
        m_sposition += len;
        m_position += length;
index c86b8b76c59b7dfa5774633d3f3ca0fae207abe9..fbf562868575be9071143bf8eeb06963ab1108fc 100644 (file)
@@ -27,7 +27,7 @@
 #define AUD_LINEARRESAMPLEREADER
 
 #include "AUD_EffectReader.h"
-class AUD_Buffer;
+#include "AUD_Buffer.h"
 
 /**
  * This resampling reader uses libsamplerate for resampling.
@@ -35,10 +35,20 @@ class AUD_Buffer;
 class AUD_LinearResampleReader : public AUD_EffectReader
 {
 private:
+       /**
+        * The sample specification of the source.
+        */
+       const AUD_Specs m_sspecs;
+
        /**
         * The resampling factor.
         */
-       float m_factor;
+       const float m_factor;
+
+       /**
+        * The target specification.
+        */
+       AUD_Specs m_tspecs;
 
        /**
         * The current position.
@@ -53,41 +63,29 @@ private:
        /**
         * The sound output buffer.
         */
-       AUD_Buffer *m_buffer;
+       AUD_Buffer m_buffer;
 
        /**
         * The input caching buffer.
         */
-       AUD_Buffer *m_cache;
-
-       /**
-        * The target specification.
-        */
-       AUD_Specs m_tspecs;
+       AUD_Buffer m_cache;
 
-       /**
-        * The sample specification of the source.
-        */
-       AUD_Specs m_sspecs;
+       // hide copy constructor and operator=
+       AUD_LinearResampleReader(const AUD_LinearResampleReader&);
+       AUD_LinearResampleReader& operator=(const AUD_LinearResampleReader&);
 
 public:
        /**
         * Creates a resampling reader.
         * \param reader The reader to mix.
         * \param specs The target specification.
-        * \exception AUD_Exception Thrown if the reader is NULL.
         */
        AUD_LinearResampleReader(AUD_IReader* reader, AUD_Specs specs);
 
-       /**
-        * Destroys the reader.
-        */
-       ~AUD_LinearResampleReader();
-
        virtual void seek(int position);
-       virtual int getLength();
-       virtual int getPosition();
-       virtual AUD_Specs getSpecs();
+       virtual int getLength() const;
+       virtual int getPosition() const;
+       virtual AUD_Specs getSpecs() const;
        virtual void read(int & length, sample_t* & buffer);
 };
 
index e77d40fdbcab5cac64eed807ad1e4cd011480072..419ac3af6acc739ca6f4601c44a0ede88c11e529 100644 (file)
  */
 
 #include "AUD_Mixer.h"
-#include "AUD_SRCResampleFactory.h"
-#include "AUD_LinearResampleFactory.h"
-#include "AUD_ChannelMapperFactory.h"
 #include "AUD_IReader.h"
-#include "AUD_Buffer.h"
 
 #include <cstring>
 
-AUD_Mixer::AUD_Mixer()
+AUD_Mixer::AUD_Mixer(AUD_DeviceSpecs specs) :
+       m_specs(specs)
 {
-       m_buffer = new AUD_Buffer(); AUD_NEW("buffer")
-
-       m_resampler = NULL;
-       m_mapper = NULL;
-}
-
-AUD_Mixer::~AUD_Mixer()
-{
-       delete m_buffer; AUD_DELETE("buffer")
-
-
-       if(m_resampler)
-       {
-               delete m_resampler; AUD_DELETE("factory")
-       }
-       if(m_mapper)
-       {
-               delete m_mapper; AUD_DELETE("factory")
-       }
-}
-
-AUD_IReader* AUD_Mixer::prepare(AUD_IReader* reader)
-{
-       m_resampler->setReader(reader);
-       reader = m_resampler->createReader();
-
-       if(reader != NULL && reader->getSpecs().channels != m_specs.channels)
-       {
-               m_mapper->setReader(reader);
-               reader = m_mapper->createReader();
-       }
-
-       return reader;
-}
-
-AUD_DeviceSpecs AUD_Mixer::getSpecs()
-{
-       return m_specs;
-}
-
-void AUD_Mixer::setSpecs(AUD_DeviceSpecs specs)
-{
-       m_specs = specs;
-
-       if(m_resampler)
-       {
-               delete m_resampler; AUD_DELETE("factory")
-       }
-       if(m_mapper)
-       {
-               delete m_mapper; AUD_DELETE("factory")
-       }
-
-       m_resampler = new AUD_MIXER_RESAMPLER(specs); AUD_NEW("factory")
-       m_mapper = new AUD_ChannelMapperFactory(specs); AUD_NEW("factory")
-
        int bigendian = 1;
        bigendian = (((char*)&bigendian)[0]) ? 0: 1; // 1 if Big Endian
 
@@ -121,6 +62,11 @@ void AUD_Mixer::setSpecs(AUD_DeviceSpecs specs)
        }
 }
 
+AUD_DeviceSpecs AUD_Mixer::getSpecs() const
+{
+       return m_specs;
+}
+
 void AUD_Mixer::add(sample_t* buffer, int start, int length, float volume)
 {
        AUD_MixerBuffer buf;
@@ -137,10 +83,10 @@ void AUD_Mixer::superpose(data_t* buffer, int length, float volume)
 
        int channels = m_specs.channels;
 
-       if(m_buffer->getSize() < length * channels * 4)
-               m_buffer->resize(length * channels * 4);
+       if(m_buffer.getSize() < length * channels * 4)
+               m_buffer.resize(length * channels * 4);
 
-       sample_t* out = m_buffer->getBuffer();
+       sample_t* out = m_buffer.getBuffer();
        sample_t* in;
 
        memset(out, 0, length * channels * 4);
index 2e7ba7435413224c497d8c5263348d1bafbdb958..a7f5fb274f04022aee061a8cd76010dc2701de17 100644 (file)
 #ifndef AUD_MIXER
 #define AUD_MIXER
 
-#define AUD_MIXER_RESAMPLER AUD_SRCResampleFactory
-
 #include "AUD_ConverterFunctions.h"
-class AUD_ConverterFactory;
-class AUD_MIXER_RESAMPLER;
-class AUD_ChannelMapperFactory;
-class AUD_Buffer;
+#include "AUD_Buffer.h"
 class AUD_IReader;
 #include <list>
 
@@ -45,24 +40,12 @@ struct AUD_MixerBuffer
 };
 
 /**
- * This class is able to mix audiosignals of different channel count and sample
- * rate and convert it to a specific output format.
- * It uses a default ChannelMapperFactory and a SRCResampleFactory for
- * the perparation.
+ * This abstract class is able to mix audiosignals of different channel count
+ * and sample rate and convert it to a specific output format.
  */
 class AUD_Mixer
 {
-private:
-       /**
-        * The resampling factory that resamples all readers for superposition.
-        */
-       AUD_MIXER_RESAMPLER* m_resampler;
-
-       /**
-        * The channel mapper factory that maps all readers for superposition.
-        */
-       AUD_ChannelMapperFactory* m_mapper;
-
+protected:
        /**
         * The list of buffers to superpose.
         */
@@ -71,12 +54,12 @@ private:
        /**
         * The output specification.
         */
-       AUD_DeviceSpecs m_specs;
+       const AUD_DeviceSpecs m_specs;
 
        /**
         * The temporary mixing buffer.
         */
-       AUD_Buffer* m_buffer;
+       AUD_Buffer m_buffer;
 
        /**
         * Converter function.
@@ -87,31 +70,25 @@ public:
        /**
         * Creates the mixer.
         */
-       AUD_Mixer();
+       AUD_Mixer(AUD_DeviceSpecs specs);
 
        /**
         * Destroys the mixer.
         */
-       ~AUD_Mixer();
-
-       /**
-        * This funuction prepares a reader for playback.
-        * \param reader The reader to prepare.
-        * \return The reader that should be used for playback.
-        */
-       AUD_IReader* prepare(AUD_IReader* reader);
+       virtual ~AUD_Mixer() {}
 
        /**
         * Returns the target specification for superposing.
         * \return The target specification.
         */
-       AUD_DeviceSpecs getSpecs();
+       AUD_DeviceSpecs getSpecs() const;
 
        /**
-        * Sets the target specification for superposing.
-        * \param specs The target specification.
+        * This funuction prepares a reader for playback.
+        * \param reader The reader to prepare.
+        * \return The reader that should be used for playback.
         */
-       void setSpecs(AUD_DeviceSpecs specs);
+       virtual AUD_IReader* prepare(AUD_IReader* reader)=0;
 
        /**
         * Adds a buffer for superposition.
@@ -120,7 +97,7 @@ public:
         * \param length The length of the buffer in samples.
         * \param volume The mixing volume. Must be a value between 0.0 and 1.0.
         */
-       void add(sample_t* buffer, int start, int length, float volume);
+       virtual void add(sample_t* buffer, int start, int length, float volume);
 
        /**
         * Superposes all added buffers into an output buffer.
@@ -128,7 +105,7 @@ public:
         * \param length The length of the buffer in samples.
         * \param volume The mixing volume. Must be a value between 0.0 and 1.0.
         */
-       void superpose(data_t* buffer, int length, float volume);
+       virtual void superpose(data_t* buffer, int length, float volume);
 };
 
 #endif //AUD_MIXER
index e78818301fa3f4dd3e46019a1a1aa24fd39b536e..4370bed6ca673ed0d86bfd6f5e784293d3665ba5 100644 (file)
 #include "AUD_MixerFactory.h"
 #include "AUD_IReader.h"
 
-AUD_IReader* AUD_MixerFactory::getReader()
+AUD_IReader* AUD_MixerFactory::getReader() const
 {
-       AUD_IReader* reader;
-
-       // first check for an existing reader
-       if(m_reader != 0)
-       {
-               reader = m_reader;
-               m_reader = 0;
-               return reader;
-       }
-
-       // otherwise create a reader if there is a factory
-       if(m_factory != 0)
-       {
-               reader = m_factory->createReader();
-               return reader;
-       }
-
-       return 0;
-}
-
-AUD_MixerFactory::AUD_MixerFactory(AUD_IReader* reader,
-                                                                  AUD_DeviceSpecs specs)
-{
-       m_specs = specs;
-       m_reader = reader;
-       m_factory = 0;
+       return m_factory->createReader();
 }
 
 AUD_MixerFactory::AUD_MixerFactory(AUD_IFactory* factory,
-                                                                  AUD_DeviceSpecs specs)
+                                                                  AUD_DeviceSpecs specs) :
+       m_specs(specs), m_factory(factory)
 {
-       m_specs = specs;
-       m_reader = 0;
-       m_factory = factory;
 }
 
-AUD_MixerFactory::AUD_MixerFactory(AUD_DeviceSpecs specs)
-{
-       m_specs = specs;
-       m_reader = 0;
-       m_factory = 0;
-}
-
-AUD_MixerFactory::~AUD_MixerFactory()
-{
-       if(m_reader != 0)
-       {
-               delete m_reader; AUD_DELETE("reader")
-       }
-}
-
-AUD_DeviceSpecs AUD_MixerFactory::getSpecs()
+AUD_DeviceSpecs AUD_MixerFactory::getSpecs() const
 {
        return m_specs;
 }
 
-void AUD_MixerFactory::setSpecs(AUD_DeviceSpecs specs)
-{
-       m_specs = specs;
-}
-
-void AUD_MixerFactory::setReader(AUD_IReader* reader)
-{
-       if(m_reader != 0)
-       {
-               delete m_reader; AUD_DELETE("reader")
-       }
-       m_reader = reader;
-}
-
-void AUD_MixerFactory::setFactory(AUD_IFactory* factory)
-{
-       m_factory = factory;
-}