3D Audio GSoC:
authorJoerg Mueller <nexyon@gmail.com>
Fri, 3 Jun 2011 23:28:57 +0000 (23:28 +0000)
committerJoerg Mueller <nexyon@gmail.com>
Fri, 3 Jun 2011 23:28:57 +0000 (23:28 +0000)
Memory management improvements.

117 files changed:
intern/audaspace/FX/AUD_AccumulatorFactory.cpp
intern/audaspace/FX/AUD_AccumulatorFactory.h
intern/audaspace/FX/AUD_BaseIIRFilterReader.cpp
intern/audaspace/FX/AUD_BaseIIRFilterReader.h
intern/audaspace/FX/AUD_ButterworthFactory.cpp
intern/audaspace/FX/AUD_ButterworthFactory.h
intern/audaspace/FX/AUD_CallbackIIRFilterReader.cpp
intern/audaspace/FX/AUD_CallbackIIRFilterReader.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_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_IIRFilterFactory.cpp
intern/audaspace/FX/AUD_IIRFilterFactory.h
intern/audaspace/FX/AUD_IIRFilterReader.cpp
intern/audaspace/FX/AUD_IIRFilterReader.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_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_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_SumFactory.cpp
intern/audaspace/FX/AUD_SumFactory.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/OpenAL/AUD_OpenALDevice.cpp
intern/audaspace/OpenAL/AUD_OpenALDevice.h
intern/audaspace/Python/AUD_PyAPI.cpp
intern/audaspace/Python/AUD_PyAPI.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/intern/AUD_BufferReader.cpp
intern/audaspace/intern/AUD_C-API.cpp
intern/audaspace/intern/AUD_C-API.h
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
intern/audaspace/intern/AUD_DefaultMixer.h
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_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.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_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_SilenceFactory.cpp
intern/audaspace/intern/AUD_SilenceFactory.h
intern/audaspace/intern/AUD_SinusFactory.cpp
intern/audaspace/intern/AUD_SinusFactory.h
intern/audaspace/intern/AUD_SoftwareDevice.cpp
intern/audaspace/intern/AUD_SoftwareDevice.h
intern/audaspace/intern/AUD_StreamBufferFactory.cpp
intern/audaspace/intern/AUD_StreamBufferFactory.h
intern/audaspace/sndfile/AUD_SndFileFactory.cpp
intern/audaspace/sndfile/AUD_SndFileFactory.h
intern/audaspace/sndfile/AUD_SndFileReader.cpp

index d60924958b162ea25af477a565db5d7bac25c66b..207c2ee502b4073b7af7af12273504514295fe68 100644 (file)
@@ -52,14 +52,14 @@ sample_t accumulatorFilter(AUD_CallbackIIRFilterReader* reader, void* useless)
        return out;
 }
 
-AUD_AccumulatorFactory::AUD_AccumulatorFactory(AUD_IFactory* factory,
+AUD_AccumulatorFactory::AUD_AccumulatorFactory(AUD_Reference<AUD_IFactory> factory,
                                                                                           bool additive) :
                AUD_EffectFactory(factory),
                m_additive(additive)
 {
 }
 
-AUD_IReader* AUD_AccumulatorFactory::createReader() const
+AUD_Reference<AUD_IReader> AUD_AccumulatorFactory::createReader() const
 {
        return new AUD_CallbackIIRFilterReader(getReader(), 2, 2,
                                                        m_additive ? accumulatorFilterAdditive : accumulatorFilter);
index 3c3b32ce0711d5c0b6f6a108515093accf54f41a..becd5d9aaee2ca1cf714b1b479fb79ddc660e063 100644 (file)
@@ -55,9 +55,9 @@ public:
         * \param factory The input factory.
         * \param additive Whether the accumulator is additive.
         */
-       AUD_AccumulatorFactory(AUD_IFactory* factory, bool additive = false);
+       AUD_AccumulatorFactory(AUD_Reference<AUD_IFactory> factory, bool additive = false);
 
-       virtual AUD_IReader* createReader() const;
+       virtual AUD_Reference<AUD_IReader> createReader() const;
 };
 
 #endif //AUD_ACCUMULATORFACTORY
index 563722d921397b00496e0310fba4b851c9f93900..5ad5903141bfc5c0f124975e18c871f939b2ad20 100644 (file)
@@ -35,7 +35,7 @@
 
 #define CC m_channels + m_channel
 
-AUD_BaseIIRFilterReader::AUD_BaseIIRFilterReader(AUD_IReader* reader, int in,
+AUD_BaseIIRFilterReader::AUD_BaseIIRFilterReader(AUD_Reference<AUD_IReader> reader, int in,
                                                                                                 int out) :
                AUD_EffectReader(reader),
                m_channels(reader->getSpecs().channels),
index 436e6469a58284ce86d875347878fc0e2fade4ee..9f81e2d8a255b34f92ab5c0f1e62bce7977b2b66 100644 (file)
@@ -97,7 +97,7 @@ protected:
         * \param in The count of past input samples needed.
         * \param out The count of past output samples needed.
         */
-       AUD_BaseIIRFilterReader(AUD_IReader* reader, int in, int out);
+       AUD_BaseIIRFilterReader(AUD_Reference<AUD_IReader> reader, int in, int out);
 
 public:
        inline sample_t x(int pos)
index ea957c81ed37733bae638771ce73de8110c6b174..1161a485fb17e96378fc7f22da36ed6b815fc470 100644 (file)
 #define BWPB41 0.76536686473
 #define BWPB42 1.84775906502
 
-AUD_ButterworthFactory::AUD_ButterworthFactory(AUD_IFactory* factory,
+AUD_ButterworthFactory::AUD_ButterworthFactory(AUD_Reference<AUD_IFactory> factory,
                                                                                           float frequency) :
                AUD_EffectFactory(factory),
                m_frequency(frequency)
 {
 }
 
-AUD_IReader* AUD_ButterworthFactory::createReader() const
+AUD_Reference<AUD_IReader> AUD_ButterworthFactory::createReader() const
 {
-       AUD_IReader* reader = getReader();
+       AUD_Reference<AUD_IReader> reader = getReader();
 
        // calculate coefficients
        float omega = 2 * tan(m_frequency * M_PI / reader->getSpecs().rate);
index c8b731449c4e90d04ca223cf6a77b35ff374436a..c211a6df2460f97ff9020ba18a5f78cc859dc1be 100644 (file)
@@ -55,9 +55,9 @@ public:
         * \param factory The input factory.
         * \param frequency The cutoff frequency.
         */
-       AUD_ButterworthFactory(AUD_IFactory* factory, float frequency);
+       AUD_ButterworthFactory(AUD_Reference<AUD_IFactory> factory, float frequency);
 
-       virtual AUD_IReader* createReader() const;
+       virtual AUD_Reference<AUD_IReader> createReader() const;
 };
 
 #endif //AUD_BUTTERWORTHFACTORY
index 2f9bb7762a04af704d08badcc550ed68a4afe19e..e6c83322435dc72a2d5226afd303bd587bb44013 100644 (file)
@@ -31,7 +31,7 @@
 
 #include "AUD_CallbackIIRFilterReader.h"
 
-AUD_CallbackIIRFilterReader::AUD_CallbackIIRFilterReader(AUD_IReader* reader,
+AUD_CallbackIIRFilterReader::AUD_CallbackIIRFilterReader(AUD_Reference<AUD_IReader> reader,
                                                                                                                 int in, int out,
                                                                                                                 doFilterIIR doFilter,
                                                                                                                 endFilterIIR endFilter,
index a969db7297ef0692adf236323b51d49be701ea0f..6d53edeecc2e1c90264db1701ca958a80727cc01 100644 (file)
@@ -76,7 +76,7 @@ public:
         * \param endFilter The finishing callback.
         * \param data Data pointer for the callbacks.
         */
-       AUD_CallbackIIRFilterReader(AUD_IReader* reader, int in, int out,
+       AUD_CallbackIIRFilterReader(AUD_Reference<AUD_IReader> reader, int in, int out,
                                                                doFilterIIR doFilter,
                                                                endFilterIIR endFilter = 0,
                                                                void* data = 0);
index 1d2d99adc03fcf12bf4003a72cd226c414fa61eb..ceecd7a63c99023700f2215516fd4b0023af6a18 100644 (file)
@@ -33,7 +33,7 @@
 #include "AUD_DelayReader.h"
 #include "AUD_Space.h"
 
-AUD_DelayFactory::AUD_DelayFactory(AUD_IFactory* factory, float delay) :
+AUD_DelayFactory::AUD_DelayFactory(AUD_Reference<AUD_IFactory> factory, float delay) :
                AUD_EffectFactory(factory),
                m_delay(delay)
 {
@@ -44,7 +44,7 @@ float AUD_DelayFactory::getDelay() const
        return m_delay;
 }
 
-AUD_IReader* AUD_DelayFactory::createReader() const
+AUD_Reference<AUD_IReader> AUD_DelayFactory::createReader() const
 {
        return new AUD_DelayReader(getReader(), m_delay);
 }
index 1e67cd689909c5dd7b3e8fb93903f7533cb65e6e..6362bd19a70e9e13e4785316355bc0e3137fada8 100644 (file)
@@ -55,14 +55,14 @@ public:
         * \param factory The input factory.
         * \param delay The desired delay in seconds.
         */
-       AUD_DelayFactory(AUD_IFactory* factory, float delay = 0);
+       AUD_DelayFactory(AUD_Reference<AUD_IFactory> factory, float delay = 0);
 
        /**
         * Returns the delay in seconds.
         */
        float getDelay() const;
 
-       virtual AUD_IReader* createReader() const;
+       virtual AUD_Reference<AUD_IReader> createReader() const;
 };
 
 #endif //AUD_DELAYFACTORY
index 374b876455d42f95a24aa238d21937564c5c689d..a2224caf28802a09386af825d7954340c941a7aa 100644 (file)
@@ -33,7 +33,7 @@
 
 #include <cstring>
 
-AUD_DelayReader::AUD_DelayReader(AUD_IReader* reader, float delay) :
+AUD_DelayReader::AUD_DelayReader(AUD_Reference<AUD_IReader> reader, float delay) :
                AUD_EffectReader(reader),
                m_delay(int(delay * reader->getSpecs().rate)),
                m_remdelay(int(delay * reader->getSpecs().rate)),
index 5f0af660bdf90bf5c36fa27d070b660754986119..695003a8c43580b3f755d1c808c213744fef30de 100644 (file)
@@ -71,7 +71,7 @@ public:
         * \param reader The reader to read from.
         * \param delay The delay in seconds.
         */
-       AUD_DelayReader(AUD_IReader* reader, float delay);
+       AUD_DelayReader(AUD_Reference<AUD_IReader> reader, float delay);
 
        virtual void seek(int position);
        virtual int getLength() const;
index 7a40f1f8c96b07def0543d307370adc0888109b1..5b72082f520cb8b9e4224da702be9662b68c5f00 100644 (file)
 #include "AUD_DoubleFactory.h"
 #include "AUD_DoubleReader.h"
 
-AUD_DoubleFactory::AUD_DoubleFactory(AUD_IFactory* factory1, AUD_IFactory* factory2) :
+AUD_DoubleFactory::AUD_DoubleFactory(AUD_Reference<AUD_IFactory> factory1, AUD_Reference<AUD_IFactory> factory2) :
                m_factory1(factory1), m_factory2(factory2)
 {
 }
 
-AUD_IReader* AUD_DoubleFactory::createReader() const
+AUD_Reference<AUD_IReader> AUD_DoubleFactory::createReader() const
 {
-       AUD_IReader* reader1 = m_factory1->createReader();
-       AUD_IReader* reader2;
-
-       try
-       {
-               reader2 = m_factory2->createReader();
-       }
-       catch(AUD_Exception&)
-       {
-               delete reader1;
-               throw;
-       }
+       AUD_Reference<AUD_IReader> reader1 = m_factory1->createReader();
+       AUD_Reference<AUD_IReader> reader2 = m_factory2->createReader();
 
        return new AUD_DoubleReader(reader1, reader2);
 }
index 52a299c7157dc79cdc4221d7e10240bff18f08d5..acc9997deea6764591f4ece31904a5b0d2676e47 100644 (file)
@@ -44,12 +44,12 @@ private:
        /**
         * First played factory.
         */
-       AUD_IFactory* m_factory1;
+       AUD_Reference<AUD_IFactory> m_factory1;
 
        /**
         * Second played factory.
         */
-       AUD_IFactory* m_factory2;
+       AUD_Reference<AUD_IFactory> m_factory2;
 
        // hide copy constructor and operator=
        AUD_DoubleFactory(const AUD_DoubleFactory&);
@@ -61,9 +61,9 @@ public:
         * \param factory1 The first input factory.
         * \param factory2 The second input factory.
         */
-       AUD_DoubleFactory(AUD_IFactory* factory1, AUD_IFactory* factory2);
+       AUD_DoubleFactory(AUD_Reference<AUD_IFactory> factory1, AUD_Reference<AUD_IFactory> factory2);
 
-       virtual AUD_IReader* createReader() const;
+       virtual AUD_Reference<AUD_IReader> createReader() const;
 };
 
 #endif //AUD_DOUBLEFACTORY
index 113bed14ce3a0bd5b25354ed9f2dd07242bf2311..bf1c770a2ed01d30e1cc6dba2f66bbae859bf236 100644 (file)
@@ -36,8 +36,8 @@
 static const char* specs_error = "AUD_DoubleReader: Both readers have to have "
                                                                 "the same specs.";
 
-AUD_DoubleReader::AUD_DoubleReader(AUD_IReader* reader1,
-                                                                  AUD_IReader* reader2) :
+AUD_DoubleReader::AUD_DoubleReader(AUD_Reference<AUD_IReader> reader1,
+                                                                  AUD_Reference<AUD_IReader> reader2) :
                m_reader1(reader1), m_reader2(reader2), m_finished1(false)
 {
        AUD_Specs s1, s2;
@@ -45,16 +45,12 @@ AUD_DoubleReader::AUD_DoubleReader(AUD_IReader* reader1,
        s2 = reader2->getSpecs();
        if(memcmp(&s1, &s2, sizeof(AUD_Specs)) != 0)
        {
-               delete reader1;
-               delete reader2;
                AUD_THROW(AUD_ERROR_SPECS, specs_error);
        }
 }
 
 AUD_DoubleReader::~AUD_DoubleReader()
 {
-       delete m_reader1;
-       delete m_reader2;
 }
 
 bool AUD_DoubleReader::isSeekable() const
index 7b3b812ef80f8f794b66ae31bc8869bb322980ea..4f01c47d05226780f2c1941cde3d9b269f4aa35c 100644 (file)
@@ -34,6 +34,7 @@
 
 #include "AUD_IReader.h"
 #include "AUD_Buffer.h"
+#include "AUD_Reference.h"
 
 /**
  * This reader plays two readers with the same specs sequently.
@@ -44,12 +45,12 @@ private:
        /**
         * The first reader.
         */
-       AUD_IReader* m_reader1;
+       AUD_Reference<AUD_IReader> m_reader1;
 
        /**
         * The second reader.
         */
-       AUD_IReader* m_reader2;
+       AUD_Reference<AUD_IReader> m_reader2;
 
        /**
         * Whether we've reached the end of the first reader.
@@ -72,7 +73,7 @@ public:
         * \param reader2 The second reader to read from.
         * \exception AUD_Exception Thrown if the specs from the readers differ.
         */
-       AUD_DoubleReader(AUD_IReader* reader1, AUD_IReader* reader2);
+       AUD_DoubleReader(AUD_Reference<AUD_IReader> reader1, AUD_Reference<AUD_IReader> reader2);
 
        /**
         * Destroys the reader.
index a0d9256e6911c94381deae8c96b76bcfbaeaacc3..6173ffb5a979a5bfcd3d2fc9188dacbd532274c2 100644 (file)
@@ -32,7 +32,7 @@
 #include "AUD_EffectFactory.h"
 #include "AUD_IReader.h"
 
-AUD_EffectFactory::AUD_EffectFactory(AUD_IFactory* factory)
+AUD_EffectFactory::AUD_EffectFactory(AUD_Reference<AUD_IFactory> factory)
 {
        m_factory = factory;
 }
@@ -41,7 +41,7 @@ AUD_EffectFactory::~AUD_EffectFactory()
 {
 }
 
-AUD_IFactory* AUD_EffectFactory::getFactory() const
+AUD_Reference<AUD_IFactory> AUD_EffectFactory::getFactory() const
 {
        return m_factory;
 }
index a6a28eea5770e4eee5338fa27886d949125c47b8..72fdb3f0833b968baea1a1d00fdc69c36ee49d12 100644 (file)
@@ -49,7 +49,7 @@ protected:
        /**
         * If there is no reader it is created out of this factory.
         */
-       AUD_IFactory* m_factory;
+       AUD_Reference<AUD_IFactory> m_factory;
 
        /**
         * Returns the reader created out of the factory.
@@ -57,7 +57,7 @@ protected:
         * classes.
         * \return The reader created out of the factory.
         */
-       inline AUD_IReader* getReader() const
+       inline AUD_Reference<AUD_IReader> getReader() const
        {
                return m_factory->createReader();
        }
@@ -67,7 +67,7 @@ public:
         * Creates a new factory.
         * \param factory The input factory.
         */
-       AUD_EffectFactory(AUD_IFactory* factory);
+       AUD_EffectFactory(AUD_Reference<AUD_IFactory> factory);
 
        /**
         * Destroys the factory.
@@ -78,7 +78,7 @@ public:
         * Returns the saved factory.
         * \return The factory or NULL if there has no factory been saved.
         */
-       AUD_IFactory* getFactory() const;
+       AUD_Reference<AUD_IFactory> getFactory() const;
 };
 
 #endif //AUD_EFFECTFACTORY
index 3ad9f67bfd6ce93794c5da8eb4c6299bddad0eb7..d7c4eeb2ee1405272da6b9350c3057c34f8b5bad 100644 (file)
 
 #include "AUD_EffectReader.h"
 
-AUD_EffectReader::AUD_EffectReader(AUD_IReader* reader)
+AUD_EffectReader::AUD_EffectReader(AUD_Reference<AUD_IReader> reader)
 {
        m_reader = reader;
 }
 
 AUD_EffectReader::~AUD_EffectReader()
 {
-       delete m_reader;
 }
 
 bool AUD_EffectReader::isSeekable() const
index fb8066f36d8c0a300104dd6574d139ca05e7309c..6aa185edcd04f96ff2595b44d7d28c6c4ded7acf 100644 (file)
@@ -33,6 +33,7 @@
 #define AUD_EFFECTREADER
 
 #include "AUD_IReader.h"
+#include "AUD_Reference.h"
 
 /**
  * This reader is a base class for all effect readers that take one other reader
@@ -49,14 +50,14 @@ protected:
        /**
         * The reader to read from.
         */
-       AUD_IReader* m_reader;
+       AUD_Reference<AUD_IReader> m_reader;
 
 public:
        /**
         * Creates a new effect reader.
         * \param reader The reader to read from.
         */
-       AUD_EffectReader(AUD_IReader* reader);
+       AUD_EffectReader(AUD_Reference<AUD_IReader> reader);
 
        /**
         * Destroys the reader.
index 069317d1c8b1a766ca49fdb57e356ebcdc74476a..e36091950a5d9b23c3e950e13f52aeca1bed49d0 100644 (file)
@@ -56,7 +56,7 @@ void endEnvelopeFilter(EnvelopeParameters* param)
        delete param;
 }
 
-AUD_EnvelopeFactory::AUD_EnvelopeFactory(AUD_IFactory* factory, float attack,
+AUD_EnvelopeFactory::AUD_EnvelopeFactory(AUD_Reference<AUD_IFactory> factory, float attack,
                                                                                 float release, float threshold,
                                                                                 float arthreshold) :
                AUD_EffectFactory(factory),
@@ -67,9 +67,9 @@ AUD_EnvelopeFactory::AUD_EnvelopeFactory(AUD_IFactory* factory, float attack,
 {
 }
 
-AUD_IReader* AUD_EnvelopeFactory::createReader() const
+AUD_Reference<AUD_IReader> AUD_EnvelopeFactory::createReader() const
 {
-       AUD_IReader* reader = getReader();
+       AUD_Reference<AUD_IReader> reader = getReader();
 
        EnvelopeParameters* param = new EnvelopeParameters();
        param->arthreshold = m_arthreshold;
index 45ee811b6e040274f765f33a91ecd19ed9ef0dc4..0a803f77aafe3d81cd789e27b5804e0af11c6fed 100644 (file)
@@ -73,10 +73,10 @@ public:
         * \param threshold The threshold value.
         * \param arthreshold The attack/release threshold value.
         */
-       AUD_EnvelopeFactory(AUD_IFactory* factory, float attack, float release,
+       AUD_EnvelopeFactory(AUD_Reference<AUD_IFactory> factory, float attack, float release,
                                                float threshold, float arthreshold);
 
-       virtual AUD_IReader* createReader() const;
+       virtual AUD_Reference<AUD_IReader> createReader() const;
 };
 
 #endif //AUD_ENVELOPEFACTORY
index d887e9e68d9cc69b65ac7e07a59c11c728bd866c..e7fe5098d7665902bbc9502eea60f897dd219b7d 100644 (file)
@@ -32,7 +32,7 @@
 #include "AUD_FaderFactory.h"
 #include "AUD_FaderReader.h"
 
-AUD_FaderFactory::AUD_FaderFactory(AUD_IFactory* factory, AUD_FadeType type,
+AUD_FaderFactory::AUD_FaderFactory(AUD_Reference<AUD_IFactory> factory, AUD_FadeType type,
                                                                   float start, float length) :
                AUD_EffectFactory(factory),
                m_type(type),
@@ -56,7 +56,7 @@ float AUD_FaderFactory::getLength() const
        return m_length;
 }
 
-AUD_IReader* AUD_FaderFactory::createReader() const
+AUD_Reference<AUD_IReader> AUD_FaderFactory::createReader() const
 {
        return new AUD_FaderReader(getReader(), m_type, m_start, m_length);
 }
index b85475bc5346dc710bd7c3a32e86f4dd24f053e4..cc20245a26758314c99a8e1938976e26d3aa40fb 100644 (file)
@@ -69,7 +69,7 @@ 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,
+       AUD_FaderFactory(AUD_Reference<AUD_IFactory> factory,
                                          AUD_FadeType type = AUD_FADE_IN,
                                          float start = 0.0f, float length = 1.0f);
 
@@ -88,7 +88,7 @@ public:
         */
        float getLength() const;
 
-       virtual AUD_IReader* createReader() const;
+       virtual AUD_Reference<AUD_IReader> createReader() const;
 };
 
 #endif //AUD_FADERFACTORY
index 6114bb486fce871784a94a0fe37d898ada54d70d..e319e205e5f3c0f94d750289568e2790bfeb0bb4 100644 (file)
@@ -33,7 +33,7 @@
 
 #include <cstring>
 
-AUD_FaderReader::AUD_FaderReader(AUD_IReader* reader, AUD_FadeType type,
+AUD_FaderReader::AUD_FaderReader(AUD_Reference<AUD_IReader> reader, AUD_FadeType type,
                                                                 float start,float length) :
                AUD_EffectReader(reader),
                m_type(type),
index fb927192b45ae310e91f1f17d41994d3f70d3dbd..b088477bce0d9f7184eab3c29b7d0aab3ce4a365 100644 (file)
@@ -79,7 +79,7 @@ public:
         * \param start The time where fading should start in seconds.
         * \param length How long fading should last in seconds.
         */
-       AUD_FaderReader(AUD_IReader* reader, AUD_FadeType type,
+       AUD_FaderReader(AUD_Reference<AUD_IReader> reader, AUD_FadeType type,
                                        float start,float length);
 
        virtual void read(int & length, sample_t* & buffer);
index 61008eea44e7162423630deeb83ec6f8801d913c..b8bfa6545ac160ffaf826b5ddc0469044f4f97b4 100644 (file)
@@ -38,7 +38,7 @@
 #define M_PI 3.14159265358979323846
 #endif
 
-AUD_HighpassFactory::AUD_HighpassFactory(AUD_IFactory* factory, float frequency,
+AUD_HighpassFactory::AUD_HighpassFactory(AUD_Reference<AUD_IFactory> factory, float frequency,
                                                                                 float Q) :
                AUD_EffectFactory(factory),
                m_frequency(frequency),
@@ -46,9 +46,9 @@ AUD_HighpassFactory::AUD_HighpassFactory(AUD_IFactory* factory, float frequency,
 {
 }
 
-AUD_IReader* AUD_HighpassFactory::createReader() const
+AUD_Reference<AUD_IReader> AUD_HighpassFactory::createReader() const
 {
-       AUD_IReader* reader = getReader();
+       AUD_Reference<AUD_IReader> reader = getReader();
 
        // calculate coefficients
        float w0 = 2 * M_PI * m_frequency / reader->getSpecs().rate;
index 48f4c1baefc4ccd7bc856f27e993a4449a042bd0..0089cc2c1399e243b0aed31b8a8c18d3ba64a536 100644 (file)
@@ -61,9 +61,9 @@ public:
         * \param frequency The cutoff frequency.
         * \param Q The Q factor.
         */
-       AUD_HighpassFactory(AUD_IFactory* factory, float frequency, float Q = 1.0f);
+       AUD_HighpassFactory(AUD_Reference<AUD_IFactory> factory, float frequency, float Q = 1.0f);
 
-       virtual AUD_IReader* createReader() const;
+       virtual AUD_Reference<AUD_IReader> createReader() const;
 };
 
 #endif //AUD_HIGHPASSFACTORY
index ff90ce6273910bff479d59bcbbaf624cdce02c8c..e24a10266c951757b5abf256f73d1b5895274702 100644 (file)
 #include "AUD_IIRFilterFactory.h"
 #include "AUD_IIRFilterReader.h"
 
-AUD_IIRFilterFactory::AUD_IIRFilterFactory(AUD_IFactory* factory,
+AUD_IIRFilterFactory::AUD_IIRFilterFactory(AUD_Reference<AUD_IFactory> factory,
                                                                                   std::vector<float> b,
                                                                                   std::vector<float> a) :
                AUD_EffectFactory(factory), m_a(a), m_b(b)
 {
 }
 
-AUD_IReader* AUD_IIRFilterFactory::createReader() const
+AUD_Reference<AUD_IReader> AUD_IIRFilterFactory::createReader() const
 {
        return new AUD_IIRFilterReader(getReader(), m_b, m_a);
 }
index d48ad453ee46c115fb679141d50afd3800f07f56..ffcc70a8ecb23258143fd44a2f7af2aca6ddba2d 100644 (file)
@@ -63,10 +63,10 @@ public:
         * \param b The input filter coefficients.
         * \param a The output filter coefficients.
         */
-       AUD_IIRFilterFactory(AUD_IFactory* factory, std::vector<float> b,
+       AUD_IIRFilterFactory(AUD_Reference<AUD_IFactory> factory, std::vector<float> b,
                                                 std::vector<float> a);
 
-       virtual AUD_IReader* createReader() const;
+       virtual AUD_Reference<AUD_IReader> createReader() const;
 };
 
 #endif //AUD_IIRFILTERFACTORY
index 0d55421d2b4965312456f0ff06c35f0a43ce9542..80252e68ce8598530e64d1effa88ec4fa3960cb1 100644 (file)
@@ -31,7 +31,7 @@
 
 #include "AUD_IIRFilterReader.h"
 
-AUD_IIRFilterReader::AUD_IIRFilterReader(AUD_IReader* reader,
+AUD_IIRFilterReader::AUD_IIRFilterReader(AUD_Reference<AUD_IReader> reader,
                                                                                 std::vector<float> b,
                                                                                 std::vector<float> a) :
        AUD_BaseIIRFilterReader(reader, b.size(), a.size()), m_a(a), m_b(b)
index af50b6f1cdc26a70adbac271467b455fe916dc72..db813d6bab6b890c81f5b441b31c79e03e4cf617 100644 (file)
@@ -63,7 +63,7 @@ public:
         * \param b The input filter coefficients.
         * \param a The output filter coefficients.
         */
-       AUD_IIRFilterReader(AUD_IReader* reader, std::vector<float> b,
+       AUD_IIRFilterReader(AUD_Reference<AUD_IReader> reader, std::vector<float> b,
                                                std::vector<float> a);
 
        virtual sample_t filter();
index 62ea01bb76191e58c2147a08c10969faf12eb651..e52cdd75d4d95677384b7b44c7495e1b710aff6e 100644 (file)
@@ -33,7 +33,7 @@
 #include "AUD_LimiterReader.h"
 #include "AUD_Space.h"
 
-AUD_LimiterFactory::AUD_LimiterFactory(AUD_IFactory* factory,
+AUD_LimiterFactory::AUD_LimiterFactory(AUD_Reference<AUD_IFactory> factory,
                                                                           float start, float end) :
                AUD_EffectFactory(factory),
                m_start(start),
@@ -51,7 +51,7 @@ float AUD_LimiterFactory::getEnd() const
        return m_end;
 }
 
-AUD_IReader* AUD_LimiterFactory::createReader() const
+AUD_Reference<AUD_IReader> AUD_LimiterFactory::createReader() const
 {
        return new AUD_LimiterReader(getReader(), m_start, m_end);
 }
index f93f4b3276c4d650e07e3fe683d415cd7a572371..c45b9da65fe37879b9b9601680641102ac51fdf0 100644 (file)
@@ -62,7 +62,7 @@ public:
         * \param end The desired end time, a negative value signals that it should
         *            play to the end.
         */
-       AUD_LimiterFactory(AUD_IFactory* factory,
+       AUD_LimiterFactory(AUD_Reference<AUD_IFactory> factory,
                                           float start = 0, float end = -1);
 
        /**
@@ -75,7 +75,7 @@ public:
         */
        float getEnd() const;
 
-       virtual AUD_IReader* createReader() const;
+       virtual AUD_Reference<AUD_IReader> createReader() const;
 };
 
 #endif //AUD_LIMITERFACTORY
index d67fbb4d0e52931c9e1aadf710d2b8a9669f44a5..d5a46568b3ef32d0974d931802437a0e8c1e5ffe 100644 (file)
@@ -34,7 +34,7 @@
 
 #include <iostream>
 
-AUD_LimiterReader::AUD_LimiterReader(AUD_IReader* reader,
+AUD_LimiterReader::AUD_LimiterReader(AUD_Reference<AUD_IReader> reader,
                                                                         float start, float end) :
                AUD_EffectReader(reader),
                m_start(int(start * reader->getSpecs().rate)),
index 4375ed9e10dc7f4ef46dfe8e857c80ed40f0af7d..f4502c33ae028a048cc06c013dd19cbd7aaf7c1a 100644 (file)
@@ -62,7 +62,7 @@ public:
         * \param end The desired end sample (exklusive), a negative value signals
         *            that it should play to the end.
         */
-       AUD_LimiterReader(AUD_IReader* reader, float start = 0, float end = -1);
+       AUD_LimiterReader(AUD_Reference<AUD_IReader> reader, float start = 0, float end = -1);
 
        virtual void seek(int position);
        virtual int getLength() const;
index 49d3481757fb89b4e8f5197d282aba0b4aa0b64b..021e69901b2f4a9a74a7b1d1ee7af687cd8f732f 100644 (file)
@@ -32,7 +32,7 @@
 #include "AUD_LoopFactory.h"
 #include "AUD_LoopReader.h"
 
-AUD_LoopFactory::AUD_LoopFactory(AUD_IFactory* factory, int loop) :
+AUD_LoopFactory::AUD_LoopFactory(AUD_Reference<AUD_IFactory> factory, int loop) :
                AUD_EffectFactory(factory),
                m_loop(loop)
 {
@@ -43,7 +43,7 @@ int AUD_LoopFactory::getLoop() const
        return m_loop;
 }
 
-AUD_IReader* AUD_LoopFactory::createReader() const
+AUD_Reference<AUD_IReader> AUD_LoopFactory::createReader() const
 {
        return new AUD_LoopReader(getReader(), m_loop);
 }
index dfbbbe4fd20d155a25f1b6d53bedc308ce217ebb..4d601d5a6057dc54448f45e73341ab9ba09a58ac 100644 (file)
@@ -57,14 +57,14 @@ public:
         * \param loop The desired loop count, negative values result in endless
         *        looping.
         */
-       AUD_LoopFactory(AUD_IFactory* factory, int loop = -1);
+       AUD_LoopFactory(AUD_Reference<AUD_IFactory> factory, int loop = -1);
 
        /**
         * Returns the loop count.
         */
        int getLoop() const;
 
-       virtual AUD_IReader* createReader() const;
+       virtual AUD_Reference<AUD_IReader> createReader() const;
 };
 
 #endif //AUD_LOOPFACTORY
index b2e8e97a60295cc679d5cbfdbe0033ff17919580..b7b8937abb83f75b8afefbb1a1a4a83f28554cf1 100644 (file)
@@ -34,7 +34,7 @@
 
 #include <cstring>
 
-AUD_LoopReader::AUD_LoopReader(AUD_IReader* reader, int loop) :
+AUD_LoopReader::AUD_LoopReader(AUD_Reference<AUD_IReader> reader, int loop) :
                AUD_EffectReader(reader), m_count(loop), m_left(loop)
 {
 }
index 45017901c568cf941a8785037e7eda72ac2b0d81..866d6f7885ff8c514f9bbb9a51e4aaf93234586a 100644 (file)
@@ -68,7 +68,7 @@ public:
         * \param loop The desired loop count, negative values result in endless
         *        looping.
         */
-       AUD_LoopReader(AUD_IReader* reader, int loop);
+       AUD_LoopReader(AUD_Reference<AUD_IReader> reader, int loop);
 
        virtual void seek(int position);
        virtual int getLength() const;
index d24a04b5a94d77a92483381d66039136c8d7a2f9..d0f33c120d9d68fbd3e8af0ecddcde610af92db1 100644 (file)
@@ -38,7 +38,7 @@
 #define M_PI 3.14159265358979323846
 #endif
 
-AUD_LowpassFactory::AUD_LowpassFactory(AUD_IFactory* factory, float frequency,
+AUD_LowpassFactory::AUD_LowpassFactory(AUD_Reference<AUD_IFactory> factory, float frequency,
                                                                           float Q) :
                AUD_EffectFactory(factory),
                m_frequency(frequency),
@@ -46,9 +46,9 @@ AUD_LowpassFactory::AUD_LowpassFactory(AUD_IFactory* factory, float frequency,
 {
 }
 
-AUD_IReader* AUD_LowpassFactory::createReader() const
+AUD_Reference<AUD_IReader> AUD_LowpassFactory::createReader() const
 {
-       AUD_IReader* reader = getReader();
+       AUD_Reference<AUD_IReader> reader = getReader();
 
        // calculate coefficients
        float w0 = 2 * M_PI * m_frequency / reader->getSpecs().rate;
index d60c0bd22d182c12d46a640f1929a2e7f025db07..efe4dafc4e198819b71e8711b831cee4840d0f7c 100644 (file)
@@ -61,9 +61,9 @@ public:
         * \param frequency The cutoff frequency.
         * \param Q The Q factor.
         */
-       AUD_LowpassFactory(AUD_IFactory* factory, float frequency, float Q = 1.0f);
+       AUD_LowpassFactory(AUD_Reference<AUD_IFactory> factory, float frequency, float Q = 1.0f);
 
-       virtual AUD_IReader* createReader() const;
+       virtual AUD_Reference<AUD_IReader> createReader() const;
 };
 
 #endif //AUD_LOWPASSFACTORY
index fa14055594358c2cd4cd10a7f600dc032f683b0a..4f0d2a207ac96563577e231eac400d1cb630c220 100644 (file)
 #include "AUD_DoubleReader.h"
 #include "AUD_ReverseFactory.h"
 
-AUD_PingPongFactory::AUD_PingPongFactory(AUD_IFactory* factory) :
+AUD_PingPongFactory::AUD_PingPongFactory(AUD_Reference<AUD_IFactory> factory) :
                AUD_EffectFactory(factory)
 {
 }
 
-AUD_IReader* AUD_PingPongFactory::createReader() const
+AUD_Reference<AUD_IReader> AUD_PingPongFactory::createReader() const
 {
-       AUD_IReader* reader = getReader();
-       AUD_IReader* reader2;
+       AUD_Reference<AUD_IReader> reader = getReader();
        AUD_ReverseFactory factory(m_factory);
-
-       try
-       {
-               reader2 = factory.createReader();
-       }
-       catch(AUD_Exception&)
-       {
-               delete reader;
-               throw;
-       }
+       AUD_Reference<AUD_IReader> reader2 = factory.createReader();
 
        return new AUD_DoubleReader(reader, reader2);
 }
index 4ae0c494eb7104b9290ae52d75f76c975bdc7bc1..1c88a5a71146a42562e1015a71413e81e9dbb190 100644 (file)
@@ -50,9 +50,9 @@ public:
         * Creates a new ping pong factory.
         * \param factory The input factory.
         */
-       AUD_PingPongFactory(AUD_IFactory* factory);
+       AUD_PingPongFactory(AUD_Reference<AUD_IFactory> factory);
 
-       virtual AUD_IReader* createReader() const;
+       virtual AUD_Reference<AUD_IReader> createReader() const;
 };
 
 #endif //AUD_PINGPONGFACTORY
index b4ae8582cafaa27bed3894351eee0cebff9be619..94a3fb8034eadf9917d8c160c442e2dbb27860d4 100644 (file)
 #include "AUD_PitchReader.h"
 #include "AUD_Space.h"
 
-AUD_PitchFactory::AUD_PitchFactory(AUD_IFactory* factory, float pitch) :
+AUD_PitchFactory::AUD_PitchFactory(AUD_Reference<AUD_IFactory> factory, float pitch) :
                AUD_EffectFactory(factory),
                m_pitch(pitch)
 {
 }
 
-AUD_IReader* AUD_PitchFactory::createReader() const
+AUD_Reference<AUD_IReader> AUD_PitchFactory::createReader() const
 {
        return new AUD_PitchReader(getReader(), m_pitch);
 }
index 8fa5be9293f6b82bd483c157d74faab1afb47bde..bbf08ef5993506528ed711216ab39f02e69bf1ae 100644 (file)
@@ -55,9 +55,9 @@ public:
         * \param factory The input factory.
         * \param pitch The desired pitch.
         */
-       AUD_PitchFactory(AUD_IFactory* factory, float pitch);
+       AUD_PitchFactory(AUD_Reference<AUD_IFactory> factory, float pitch);
 
-       virtual AUD_IReader* createReader() const;
+       virtual AUD_Reference<AUD_IReader> createReader() const;
 };
 
 #endif //AUD_PITCHFACTORY
index e2e89e2c45731e01d201476963b766b127ec857b..7f8b8b53105621b716a708d6eaaad446fb3e6658 100644 (file)
@@ -31,7 +31,7 @@
 
 #include "AUD_PitchReader.h"
 
-AUD_PitchReader::AUD_PitchReader(AUD_IReader* reader, float pitch) :
+AUD_PitchReader::AUD_PitchReader(AUD_Reference<AUD_IReader> reader, float pitch) :
                AUD_EffectReader(reader), m_pitch(pitch)
 {
 }
index 120cebc58beb42b2a2485f0be260345a5b5a0878..7939027dca9601d75bba05c4f8fa06578b850fbe 100644 (file)
@@ -55,7 +55,7 @@ public:
         * \param reader The reader to read from.
         * \param pitch The size of the buffer.
         */
-       AUD_PitchReader(AUD_IReader* reader, float pitch);
+       AUD_PitchReader(AUD_Reference<AUD_IReader> reader, float pitch);
 
        virtual AUD_Specs getSpecs() const;
 };
index 609d827cce49e51e8bafb16791367e74a3e0f4e9..3bacd033eb335520bc03134048ddce2ab2399076 100644 (file)
@@ -39,12 +39,12 @@ sample_t rectifyFilter(AUD_CallbackIIRFilterReader* reader, void* useless)
        return fabs(reader->x(0));
 }
 
-AUD_RectifyFactory::AUD_RectifyFactory(AUD_IFactory* factory) :
+AUD_RectifyFactory::AUD_RectifyFactory(AUD_Reference<AUD_IFactory> factory) :
                AUD_EffectFactory(factory)
 {
 }
 
-AUD_IReader* AUD_RectifyFactory::createReader() const
+AUD_Reference<AUD_IReader> AUD_RectifyFactory::createReader() const
 {
        return new AUD_CallbackIIRFilterReader(getReader(), 1, 1, rectifyFilter);
 }
index c3529c7beef6773d21a3ef2fecb439bf347fb7e3..d841118600141130be6ef98caf79756af4c7e0cc 100644 (file)
@@ -49,9 +49,9 @@ public:
         * Creates a new rectify factory.
         * \param factory The input factory.
         */
-       AUD_RectifyFactory(AUD_IFactory* factory);
+       AUD_RectifyFactory(AUD_Reference<AUD_IFactory> factory);
 
-       virtual AUD_IReader* createReader() const;
+       virtual AUD_Reference<AUD_IReader> createReader() const;
 };
 
 #endif //AUD_RECTIFYFACTORY
index 22b12e3142008b1dddde233d46e7e81c03039ff9..88d812d7f2a578f3e3c0fd5239f2f73750249b91 100644 (file)
 #include "AUD_ReverseReader.h"
 #include "AUD_Space.h"
 
-AUD_ReverseFactory::AUD_ReverseFactory(AUD_IFactory* factory) :
+AUD_ReverseFactory::AUD_ReverseFactory(AUD_Reference<AUD_IFactory> factory) :
                AUD_EffectFactory(factory)
 {
 }
 
-AUD_IReader* AUD_ReverseFactory::createReader() const
+AUD_Reference<AUD_IReader> AUD_ReverseFactory::createReader() const
 {
        return new AUD_ReverseReader(getReader());
 }
index 7b20546302e3efcc3de19a2364bba726cca9bd90..ae1fdd5a23324042e89d2d9afc5d00e27bfca539 100644 (file)
@@ -50,9 +50,9 @@ public:
         * Creates a new reverse factory.
         * \param factory The input factory.
         */
-       AUD_ReverseFactory(AUD_IFactory* factory);
+       AUD_ReverseFactory(AUD_Reference<AUD_IFactory> factory);
 
-       virtual AUD_IReader* createReader() const;
+       virtual AUD_Reference<AUD_IReader> createReader() const;
 };
 
 #endif //AUD_REVERSEFACTORY
index a4a03936c76743f1fdef172cf0036e18b736aa5a..8ca9f8609bb90bd543c5cca6cab8ac12625d9e43 100644 (file)
@@ -36,7 +36,7 @@
 static const char* props_error = "AUD_ReverseReader: The reader has to be "
                                                                 "seekable and a finite length.";
 
-AUD_ReverseReader::AUD_ReverseReader(AUD_IReader* reader) :
+AUD_ReverseReader::AUD_ReverseReader(AUD_Reference<AUD_IReader> reader) :
                AUD_EffectReader(reader),
                m_length(reader->getLength()),
                m_position(0)
index e12f2b2119191ab3bdcf09bdba1ecae85e13557b..d8086e0853417e2bd3b2cab350beb8d74a1cd783 100644 (file)
@@ -68,7 +68,7 @@ public:
         * \exception AUD_Exception Thrown if the reader specified has an
         *            undeterminable/infinite length or is not seekable.
         */
-       AUD_ReverseReader(AUD_IReader* reader);
+       AUD_ReverseReader(AUD_Reference<AUD_IReader> reader);
 
        virtual void seek(int position);
        virtual int getLength() const;
index a075773d2cba1d4c4a27a833a9a3de7a255757b9..a3ea088a25802aee45584f4044031840ff1abe2c 100644 (file)
@@ -48,7 +48,7 @@ void endSquareFilter(float* threshold)
        delete threshold;
 }
 
-AUD_SquareFactory::AUD_SquareFactory(AUD_IFactory* factory, float threshold) :
+AUD_SquareFactory::AUD_SquareFactory(AUD_Reference<AUD_IFactory> factory, float threshold) :
                AUD_EffectFactory(factory),
                m_threshold(threshold)
 {
@@ -59,7 +59,7 @@ float AUD_SquareFactory::getThreshold() const
        return m_threshold;
 }
 
-AUD_IReader* AUD_SquareFactory::createReader() const
+AUD_Reference<AUD_IReader> AUD_SquareFactory::createReader() const
 {
        return new AUD_CallbackIIRFilterReader(getReader(), 1, 1,
                                                                                   (doFilterIIR) squareFilter,
index 8060e98e2819f1ffd417926b3a630880b2965753..60db49c48e5fa0a1ec3e921b6bd0b4ffa08221c6 100644 (file)
@@ -55,14 +55,14 @@ public:
         * \param factory The input factory.
         * \param threshold The threshold.
         */
-       AUD_SquareFactory(AUD_IFactory* factory, float threshold = 0.0f);
+       AUD_SquareFactory(AUD_Reference<AUD_IFactory> factory, float threshold = 0.0f);
 
        /**
         * Returns the threshold.
         */
        float getThreshold() const;
 
-       virtual AUD_IReader* createReader() const;
+       virtual AUD_Reference<AUD_IReader> createReader() const;
 };
 
 #endif //AUD_SQUAREFACTORY
index 6d8368d6e3527dd11870d1a5f04f0af2e09a673c..582e2d75b7f4a1446556c7182d462849971d8086 100644 (file)
 #include "AUD_SumFactory.h"
 #include "AUD_IIRFilterReader.h"
 
-AUD_SumFactory::AUD_SumFactory(AUD_IFactory* factory) :
+AUD_SumFactory::AUD_SumFactory(AUD_Reference<AUD_IFactory> factory) :
                AUD_EffectFactory(factory)
 {
 }
 
-AUD_IReader* AUD_SumFactory::createReader() const
+AUD_Reference<AUD_IReader> AUD_SumFactory::createReader() const
 {
        std::vector<float> a, b;
        a.push_back(1);
index ed19a0f258a6075ee1665955986246d08a0d9417..948355e50fdcefc6681d3fbabc4bf06ff442075a 100644 (file)
@@ -49,9 +49,9 @@ public:
         * Creates a new sum factory.
         * \param factory The input factory.
         */
-       AUD_SumFactory(AUD_IFactory* factory);
+       AUD_SumFactory(AUD_Reference<AUD_IFactory> factory);
 
-       virtual AUD_IReader* createReader() const;
+       virtual AUD_Reference<AUD_IReader> createReader() const;
 };
 
 #endif //AUD_SUMFACTORY
index c13a0d0dd9532e369a64c1345d35148f0c543608..b5e816f66a8030a6d3dedc7b1e43ad0237c285ba 100644 (file)
 #include "AUD_SuperposeFactory.h"
 #include "AUD_SuperposeReader.h"
 
-AUD_SuperposeFactory::AUD_SuperposeFactory(AUD_IFactory* factory1, AUD_IFactory* factory2) :
+AUD_SuperposeFactory::AUD_SuperposeFactory(AUD_Reference<AUD_IFactory> factory1, AUD_Reference<AUD_IFactory> factory2) :
                m_factory1(factory1), m_factory2(factory2)
 {
 }
 
-AUD_IReader* AUD_SuperposeFactory::createReader() const
+AUD_Reference<AUD_IReader> AUD_SuperposeFactory::createReader() const
 {
-       AUD_IReader* reader1 = m_factory1->createReader();
-       AUD_IReader* reader2;
-       try
-       {
-               reader2 = m_factory2->createReader();
-       }
-       catch(AUD_Exception&)
-       {
-               delete reader1;
-               throw;
-       }
+       AUD_Reference<AUD_IReader> reader1 = m_factory1->createReader();
+       AUD_Reference<AUD_IReader> reader2 = m_factory2->createReader();
 
        return new AUD_SuperposeReader(reader1, reader2);
 }
index 32232012e4e3a0aea6227f5f6c24f2cbdd1a97ec..d302658097e3aadeb73c6e4c831ed3f20a945125 100644 (file)
@@ -44,12 +44,12 @@ private:
        /**
         * First played factory.
         */
-       AUD_IFactory* m_factory1;
+       AUD_Reference<AUD_IFactory> m_factory1;
 
        /**
         * Second played factory.
         */
-       AUD_IFactory* m_factory2;
+       AUD_Reference<AUD_IFactory> m_factory2;
 
        // hide copy constructor and operator=
        AUD_SuperposeFactory(const AUD_SuperposeFactory&);
@@ -61,9 +61,9 @@ public:
         * \param factory1 The first input factory.
         * \param factory2 The second input factory.
         */
-       AUD_SuperposeFactory(AUD_IFactory* factory1, AUD_IFactory* factory2);
+       AUD_SuperposeFactory(AUD_Reference<AUD_IFactory> factory1, AUD_Reference<AUD_IFactory> factory2);
 
-       virtual AUD_IReader* createReader() const;
+       virtual AUD_Reference<AUD_IReader> createReader() const;
 };
 
 #endif //AUD_SUPERPOSEFACTORY
index e64cf79188e09998ad23194e817c22e4e6311970..6f39dcadf405ef022b38c8cc67b97b85fd6e9e3c 100644 (file)
 static const char* specs_error = "AUD_SuperposeReader: Both readers have to "
                                                                 "have the same specs.";
 
-AUD_SuperposeReader::AUD_SuperposeReader(AUD_IReader* reader1, AUD_IReader* reader2) :
+AUD_SuperposeReader::AUD_SuperposeReader(AUD_Reference<AUD_IReader> reader1, AUD_Reference<AUD_IReader> reader2) :
        m_reader1(reader1), m_reader2(reader2)
 {
-       try
-       {
-               AUD_Specs s1, s2;
-               s1 = reader1->getSpecs();
-               s2 = reader2->getSpecs();
-               if(memcmp(&s1, &s2, sizeof(AUD_Specs)))
-                       AUD_THROW(AUD_ERROR_SPECS, specs_error);
-       }
-       catch(AUD_Exception&)
-       {
-               delete reader1;
-               delete reader2;
-
-               throw;
-       }
+       AUD_Specs s1, s2;
+       s1 = reader1->getSpecs();
+       s2 = reader2->getSpecs();
+       if(memcmp(&s1, &s2, sizeof(AUD_Specs)))
+               AUD_THROW(AUD_ERROR_SPECS, specs_error);
 }
 
 AUD_SuperposeReader::~AUD_SuperposeReader()
 {
-       delete m_reader1;
-       delete m_reader2;
 }
 
 bool AUD_SuperposeReader::isSeekable() const
index b256aade7ba7236a2dfb696a12c9e756287cd48f..26e4b138dfac1c68729faf0abc3269071e6841b0 100644 (file)
@@ -34,6 +34,7 @@
 
 #include "AUD_IReader.h"
 #include "AUD_Buffer.h"
+#include "AUD_Reference.h"
 
 /**
  * This reader plays two readers with the same specs sequently.
@@ -44,12 +45,12 @@ private:
        /**
         * The first reader.
         */
-       AUD_IReader* m_reader1;
+       AUD_Reference<AUD_IReader> m_reader1;
 
        /**
         * The second reader.
         */
-       AUD_IReader* m_reader2;
+       AUD_Reference<AUD_IReader> m_reader2;
 
        /**
         * The playback buffer for the intersecting part.
@@ -67,7 +68,7 @@ public:
         * \param reader2 The second reader to read from.
         * \exception AUD_Exception Thrown if the specs from the readers differ.
         */
-       AUD_SuperposeReader(AUD_IReader* reader1, AUD_IReader* reader2);
+       AUD_SuperposeReader(AUD_Reference<AUD_IReader> reader1, AUD_Reference<AUD_IReader> reader2);
 
        /**
         * Destroys the reader.
index 166fbf615122664f304e9e9b9846576b92db1329..1249c4ab9bd67a388af0dad7350678df9256c0c5 100644 (file)
@@ -32,7 +32,7 @@
 #include "AUD_VolumeFactory.h"
 #include "AUD_IIRFilterReader.h"
 
-AUD_VolumeFactory::AUD_VolumeFactory(AUD_IFactory* factory, float volume) :
+AUD_VolumeFactory::AUD_VolumeFactory(AUD_Reference<AUD_IFactory> factory, float volume) :
                AUD_EffectFactory(factory),
                m_volume(volume)
 {
@@ -43,7 +43,7 @@ float AUD_VolumeFactory::getVolume() const
        return m_volume;
 }
 
-AUD_IReader* AUD_VolumeFactory::createReader() const
+AUD_Reference<AUD_IReader> AUD_VolumeFactory::createReader() const
 {
        std::vector<float> a, b;
        a.push_back(1);
index fa40ca110826125a034430bf31e6dbff1611df6e..3cb8bc1da17f0d4b758006306259bb3ab52ab98d 100644 (file)
@@ -57,14 +57,14 @@ public:
         * \param factory The input factory.
         * \param volume The desired volume.
         */
-       AUD_VolumeFactory(AUD_IFactory* factory, float volume);
+       AUD_VolumeFactory(AUD_Reference<AUD_IFactory> factory, float volume);
 
        /**
         * Returns the volume.
         */
        float getVolume() const;
 
-       virtual AUD_IReader* createReader() const;
+       virtual AUD_Reference<AUD_IReader> createReader() const;
 };
 
 #endif //AUD_VOLUMEFACTORY
index b9e30bbf62aa94897b901f29962de288a8820859..a3b0bff316ed0f1ddbcf07bf992e1172d403e439 100644 (file)
@@ -52,7 +52,7 @@ struct AUD_OpenALHandle : AUD_Handle
        bool isBuffered;
 
        /// The reader source.
-       AUD_IReader* reader;
+       AUD_Reference<AUD_IReader> reader;
 
        /// Whether to keep the source if end of it is reached.
        bool keep;
@@ -382,7 +382,6 @@ AUD_OpenALDevice::~AUD_OpenALDevice()
                alDeleteSources(1, &sound->source);
                if(!sound->isBuffered)
                {
-                       delete sound->reader;
                        alDeleteBuffers(AUD_OPENAL_CYCLE_BUFFERS, sound->buffers);
                }
                delete sound;
@@ -396,7 +395,6 @@ AUD_OpenALDevice::~AUD_OpenALDevice()
                alDeleteSources(1, &sound->source);
                if(!sound->isBuffered)
                {
-                       delete sound->reader;
                        alDeleteBuffers(AUD_OPENAL_CYCLE_BUFFERS, sound->buffers);
                }
                delete sound;
@@ -539,7 +537,7 @@ static const char* queue_error = "AUD_OpenALDevice: Buffer couldn't be "
 static const char* bufferdata_error = "AUD_OpenALDevice: Buffer couldn't be "
                                                                          "filled with data.";
 
-AUD_Handle* AUD_OpenALDevice::play(AUD_IReader* reader, bool keep)
+AUD_Handle* AUD_OpenALDevice::play(AUD_Reference<AUD_IReader> reader, bool keep)
 {
        AUD_OpenALHandle* sound = NULL;
 
@@ -568,7 +566,6 @@ AUD_Handle* AUD_OpenALDevice::play(AUD_IReader* reader, bool keep)
        if(!valid)
        {
                delete sound;
-               delete reader;
                return NULL;
        }
 
@@ -624,7 +621,6 @@ AUD_Handle* AUD_OpenALDevice::play(AUD_IReader* reader, bool keep)
        catch(AUD_Exception&)
        {
                delete sound;
-               delete reader;
                alcProcessContext(m_context);
                unlock();
                throw;
@@ -642,8 +638,9 @@ AUD_Handle* AUD_OpenALDevice::play(AUD_IReader* reader, bool keep)
        return sound;
 }
 
-AUD_Handle* AUD_OpenALDevice::play(AUD_IFactory* factory, bool keep)
+AUD_Handle* AUD_OpenALDevice::play(AUD_Reference<AUD_IFactory> factory, bool keep)
 {
+       /* AUD_XXX disabled
        AUD_OpenALHandle* sound = NULL;
 
        lock();
@@ -713,7 +710,7 @@ AUD_Handle* AUD_OpenALDevice::play(AUD_IFactory* factory, bool keep)
        unlock();
 
        if(sound)
-               return sound;
+               return sound;*/
 
        return play(factory->createReader(), keep);
 }
@@ -785,7 +782,6 @@ bool AUD_OpenALDevice::stop(AUD_Handle* handle)
                        alDeleteSources(1, &sound->source);
                        if(!sound->isBuffered)
                        {
-                               delete sound->reader;
                                alDeleteBuffers(AUD_OPENAL_CYCLE_BUFFERS, sound->buffers);
                        }
                        delete *i;
@@ -805,7 +801,6 @@ bool AUD_OpenALDevice::stop(AUD_Handle* handle)
                                alDeleteSources(1, &sound->source);
                                if(!sound->isBuffered)
                                {
-                                       delete sound->reader;
                                        alDeleteBuffers(AUD_OPENAL_CYCLE_BUFFERS, sound->buffers);
                                }
                                delete *i;
@@ -1109,7 +1104,6 @@ bool AUD_OpenALDevice::bufferFactory(void *value)
 
                if(!getFormat(format, specs.specs))
                {
-                       delete reader;
                        return false;
                }
 
@@ -1147,7 +1141,6 @@ bool AUD_OpenALDevice::bufferFactory(void *value)
                catch(AUD_Exception&)
                {
                        delete bf;
-                       delete reader;
                        alcProcessContext(m_context);
                        unlock();
                        return false;
index 3bbbe85d7e6480930f6e3b11a0723f2621c68a8c..3bca47f18052a9012f527aab30050a9ee15a1f3e 100644 (file)
@@ -147,8 +147,8 @@ public:
        virtual ~AUD_OpenALDevice();
 
        virtual AUD_DeviceSpecs getSpecs() const;
-       virtual AUD_Handle* play(AUD_IReader* reader, bool keep = false);
-       virtual AUD_Handle* play(AUD_IFactory* factory, bool keep = false);
+       virtual AUD_Handle* play(AUD_Reference<AUD_IReader> reader, bool keep = false);
+       virtual AUD_Handle* play(AUD_Reference<AUD_IFactory> factory, bool keep = false);
        virtual bool pause(AUD_Handle* handle);
        virtual bool resume(AUD_Handle* handle);
        virtual bool stop(AUD_Handle* handle);
index 22376a2fcd147dd1e78ff2fbedb3bb9f1b1b6c77..53dfedee5eb4514016da980fae0e69718e36cde9 100644 (file)
@@ -91,7 +91,7 @@ static void
 Factory_dealloc(Factory* self)
 {
        if(self->factory)
-               delete self->factory;
+               delete reinterpret_cast<AUD_Reference<AUD_IFactory>*>(self->factory);
        Py_XDECREF(self->child_list);
        Py_TYPE(self)->tp_free((PyObject*)self);
 }
@@ -115,7 +115,7 @@ Factory_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 
                try
                {
-                       self->factory = new AUD_FileFactory(filename);
+                       self->factory = new AUD_Reference<AUD_IFactory>(new AUD_FileFactory(filename));
                }
                catch(AUD_Exception& e)
                {
@@ -155,7 +155,7 @@ Factory_sine(PyTypeObject* type, PyObject* args)
        {
                try
                {
-                       self->factory = new AUD_SinusFactory(frequency, (AUD_SampleRate)rate);
+                       self->factory = new AUD_Reference<AUD_IFactory>(new AUD_SinusFactory(frequency, (AUD_SampleRate)rate));
                }
                catch(AUD_Exception& e)
                {
@@ -194,7 +194,7 @@ Factory_file(PyTypeObject* type, PyObject* args)
        {
                try
                {
-                       self->factory = new AUD_FileFactory(filename);
+                       self->factory = new AUD_Reference<AUD_IFactory>(new AUD_FileFactory(filename));
                }
                catch(AUD_Exception& e)
                {
@@ -237,7 +237,7 @@ Factory_lowpass(Factory* self, PyObject* args)
 
                try
                {
-                       parent->factory = new AUD_LowpassFactory(self->factory, frequency, Q);
+                       parent->factory = new AUD_Reference<AUD_IFactory>(new AUD_LowpassFactory(*reinterpret_cast<AUD_Reference<AUD_IFactory>*>(self->factory), frequency, Q));
                }
                catch(AUD_Exception& e)
                {
@@ -278,7 +278,7 @@ Factory_delay(Factory* self, PyObject* args)
 
                try
                {
-                       parent->factory = new AUD_DelayFactory(self->factory, delay);
+                       parent->factory = new AUD_Reference<AUD_IFactory>(new AUD_DelayFactory(*reinterpret_cast<AUD_Reference<AUD_IFactory>*>(self->factory), delay));
                }
                catch(AUD_Exception& e)
                {
@@ -322,7 +322,7 @@ Factory_join(Factory* self, PyObject* object)
 
                try
                {
-                       parent->factory = new AUD_DoubleFactory(self->factory, child->factory);
+                       parent->factory = new AUD_Reference<AUD_IFactory>(new AUD_DoubleFactory(*reinterpret_cast<AUD_Reference<AUD_IFactory>*>(self->factory), *reinterpret_cast<AUD_Reference<AUD_IFactory>*>(child->factory)));
                }
                catch(AUD_Exception& e)
                {
@@ -365,7 +365,7 @@ Factory_highpass(Factory* self, PyObject* args)
 
                try
                {
-                       parent->factory = new AUD_HighpassFactory(self->factory, frequency, Q);
+                       parent->factory = new AUD_Reference<AUD_IFactory>(new AUD_HighpassFactory(*reinterpret_cast<AUD_Reference<AUD_IFactory>*>(self->factory), frequency, Q));
                }
                catch(AUD_Exception& e)
                {
@@ -406,7 +406,7 @@ Factory_limit(Factory* self, PyObject* args)
 
                try
                {
-                       parent->factory = new AUD_LimiterFactory(self->factory, start, end);
+                       parent->factory = new AUD_Reference<AUD_IFactory>(new AUD_LimiterFactory(*reinterpret_cast<AUD_Reference<AUD_IFactory>*>(self->factory), start, end));
                }
                catch(AUD_Exception& e)
                {
@@ -450,7 +450,7 @@ Factory_pitch(Factory* self, PyObject* args)
 
                try
                {
-                       parent->factory = new AUD_PitchFactory(self->factory, factor);
+                       parent->factory = new AUD_Reference<AUD_IFactory>(new AUD_PitchFactory(*reinterpret_cast<AUD_Reference<AUD_IFactory>*>(self->factory), factor));
                }
                catch(AUD_Exception& e)
                {
@@ -492,7 +492,7 @@ Factory_volume(Factory* self, PyObject* args)
 
                try
                {
-                       parent->factory = new AUD_VolumeFactory(self->factory, volume);
+                       parent->factory = new AUD_Reference<AUD_IFactory>(new AUD_VolumeFactory(*reinterpret_cast<AUD_Reference<AUD_IFactory>*>(self->factory), volume));
                }
                catch(AUD_Exception& e)
                {
@@ -535,7 +535,7 @@ Factory_fadein(Factory* self, PyObject* args)
 
                try
                {
-                       parent->factory = new AUD_FaderFactory(self->factory, AUD_FADE_IN, start, length);
+                       parent->factory = new AUD_Reference<AUD_IFactory>(new AUD_FaderFactory(*reinterpret_cast<AUD_Reference<AUD_IFactory>*>(self->factory), AUD_FADE_IN, start, length));
                }
                catch(AUD_Exception& e)
                {
@@ -579,7 +579,7 @@ Factory_fadeout(Factory* self, PyObject* args)
 
                try
                {
-                       parent->factory = new AUD_FaderFactory(self->factory, AUD_FADE_OUT, start, length);
+                       parent->factory = new AUD_Reference<AUD_IFactory>(new AUD_FaderFactory(*reinterpret_cast<AUD_Reference<AUD_IFactory>*>(self->factory), AUD_FADE_OUT, start, length));
                }
                catch(AUD_Exception& e)
                {
@@ -621,7 +621,7 @@ Factory_loop(Factory* self, PyObject* args)
 
                try
                {
-                       parent->factory = new AUD_LoopFactory(self->factory, loop);
+                       parent->factory = new AUD_Reference<AUD_IFactory>(new AUD_LoopFactory(*reinterpret_cast<AUD_Reference<AUD_IFactory>*>(self->factory), loop));
                }
                catch(AUD_Exception& e)
                {
@@ -664,7 +664,7 @@ Factory_mix(Factory* self, PyObject* object)
 
                try
                {
-                       parent->factory = new AUD_SuperposeFactory(self->factory, child->factory);
+                       parent->factory = new AUD_Reference<AUD_IFactory>(new AUD_SuperposeFactory(*reinterpret_cast<AUD_Reference<AUD_IFactory>*>(self->factory), *reinterpret_cast<AUD_Reference<AUD_IFactory>*>(child->factory)));
                }
                catch(AUD_Exception& e)
                {
@@ -697,7 +697,7 @@ Factory_pingpong(Factory* self)
 
                try
                {
-                       parent->factory = new AUD_PingPongFactory(self->factory);
+                       parent->factory = new AUD_Reference<AUD_IFactory>(new AUD_PingPongFactory(*reinterpret_cast<AUD_Reference<AUD_IFactory>*>(self->factory)));
                }
                catch(AUD_Exception& e)
                {
@@ -736,7 +736,7 @@ Factory_reverse(Factory* self)
 
                try
                {
-                       parent->factory = new AUD_ReverseFactory(self->factory);
+                       parent->factory = new AUD_Reference<AUD_IFactory>(new AUD_ReverseFactory(*reinterpret_cast<AUD_Reference<AUD_IFactory>*>(self->factory)));
                }
                catch(AUD_Exception& e)
                {
@@ -771,7 +771,7 @@ Factory_buffer(Factory* self)
        {
                try
                {
-                       parent->factory = new AUD_StreamBufferFactory(self->factory);
+                       parent->factory = new AUD_Reference<AUD_IFactory>(new AUD_StreamBufferFactory(*reinterpret_cast<AUD_Reference<AUD_IFactory>*>(self->factory)));
                }
                catch(AUD_Exception& e)
                {
@@ -813,7 +813,7 @@ Factory_square(Factory* self, PyObject* args)
 
                try
                {
-                       parent->factory = new AUD_SquareFactory(self->factory, threshold);
+                       parent->factory = new AUD_Reference<AUD_IFactory>(new AUD_SquareFactory(*reinterpret_cast<AUD_Reference<AUD_IFactory>*>(self->factory), threshold));
                }
                catch(AUD_Exception& e)
                {
@@ -910,7 +910,7 @@ Factory_filter(Factory* self, PyObject* args)
 
                try
                {
-                       parent->factory = new AUD_IIRFilterFactory(self->factory, b, a);
+                       parent->factory = new AUD_Reference<AUD_IFactory>(new AUD_IIRFilterFactory(*reinterpret_cast<AUD_Reference<AUD_IFactory>*>(self->factory), b, a));
                }
                catch(AUD_Exception& e)
                {
@@ -1050,7 +1050,7 @@ Handle_pause(Handle *self)
 
        try
        {
-               return PyBool_FromLong((long)device->device->pause(self->handle));
+               return PyBool_FromLong((long)(*reinterpret_cast<AUD_Reference<AUD_IDevice>*>(device->device))->pause(self->handle));
        }
        catch(AUD_Exception& e)
        {
@@ -1072,7 +1072,7 @@ Handle_resume(Handle *self)
 
        try
        {
-               return PyBool_FromLong((long)device->device->resume(self->handle));
+               return PyBool_FromLong((long)(*reinterpret_cast<AUD_Reference<AUD_IDevice>*>(device->device))->resume(self->handle));
        }
        catch(AUD_Exception& e)
        {
@@ -1095,7 +1095,7 @@ Handle_stop(Handle *self)
 
        try
        {
-               return PyBool_FromLong((long)device->device->stop(self->handle));
+               return PyBool_FromLong((long)(*reinterpret_cast<AUD_Reference<AUD_IDevice>*>(device->device))->stop(self->handle));
        }
        catch(AUD_Exception& e)
        {
@@ -1127,7 +1127,7 @@ Handle_get_position(Handle *self, void* nothing)
 
        try
        {
-               return Py_BuildValue("f", device->device->getPosition(self->handle));
+               return Py_BuildValue("f", (*reinterpret_cast<AUD_Reference<AUD_IDevice>*>(device->device))->getPosition(self->handle));
        }
        catch(AUD_Exception& e)
        {
@@ -1148,7 +1148,7 @@ Handle_set_position(Handle *self, PyObject* args, void* nothing)
 
        try
        {
-               if(device->device->seek(self->handle, position))
+               if((*reinterpret_cast<AUD_Reference<AUD_IDevice>*>(device->device))->seek(self->handle, position))
                        return 0;
                PyErr_SetString(AUDError, "Couldn't seek the sound!");
        }
@@ -1176,7 +1176,7 @@ Handle_get_keep(Handle *self, void* nothing)
 
        try
        {
-               return PyBool_FromLong((long)device->device->getKeep(self->handle));
+               return PyBool_FromLong((long)(*reinterpret_cast<AUD_Reference<AUD_IDevice>*>(device->device))->getKeep(self->handle));
        }
        catch(AUD_Exception& e)
        {
@@ -1199,7 +1199,7 @@ Handle_set_keep(Handle *self, PyObject* args, void* nothing)
 
        try
        {
-               if(device->device->setKeep(self->handle, keep))
+               if((*reinterpret_cast<AUD_Reference<AUD_IDevice>*>(device->device))->setKeep(self->handle, keep))
                        return 0;
                PyErr_SetString(AUDError, "Couldn't set keep of the sound!");
        }
@@ -1221,7 +1221,7 @@ Handle_get_status(Handle *self, void* nothing)
 
        try
        {
-               return PyBool_FromLong((long)device->device->getStatus(self->handle));
+               return PyBool_FromLong((long)(*reinterpret_cast<AUD_Reference<AUD_IDevice>*>(device->device))->getStatus(self->handle));
        }
        catch(AUD_Exception& e)
        {
@@ -1240,7 +1240,7 @@ Handle_get_volume(Handle *self, void* nothing)
 
        try
        {
-               return Py_BuildValue("f", device->device->getVolume(self->handle));
+               return Py_BuildValue("f", (*reinterpret_cast<AUD_Reference<AUD_IDevice>*>(device->device))->getVolume(self->handle));
        }
        catch(AUD_Exception& e)
        {
@@ -1261,7 +1261,7 @@ Handle_set_volume(Handle *self, PyObject* args, void* nothing)
 
        try
        {
-               if(device->device->setVolume(self->handle, volume))
+               if((*reinterpret_cast<AUD_Reference<AUD_IDevice>*>(device->device))->setVolume(self->handle, volume))
                        return 0;
                PyErr_SetString(AUDError, "Couldn't set the sound volume!");
        }
@@ -1283,7 +1283,7 @@ Handle_get_pitch(Handle *self, void* nothing)
 
        try
        {
-               return Py_BuildValue("f", device->device->getPitch(self->handle));
+               return Py_BuildValue("f", (*reinterpret_cast<AUD_Reference<AUD_IDevice>*>(device->device))->getPitch(self->handle));
        }
        catch(AUD_Exception& e)
        {
@@ -1304,7 +1304,7 @@ Handle_set_pitch(Handle *self, PyObject* args, void* nothing)
 
        try
        {
-               if(device->device->setPitch(self->handle, pitch))
+               if((*reinterpret_cast<AUD_Reference<AUD_IDevice>*>(device->device))->setPitch(self->handle, pitch))
                        return 0;
                PyErr_SetString(AUDError, "Couldn't set the sound pitch!");
        }
@@ -1326,7 +1326,7 @@ Handle_get_loop_count(Handle *self, void* nothing)
 
        try
        {
-               return Py_BuildValue("i", device->device->getLoopCount(self->handle));
+               return Py_BuildValue("i", (*reinterpret_cast<AUD_Reference<AUD_IDevice>*>(device->device))->getLoopCount(self->handle));
        }
        catch(AUD_Exception& e)
        {
@@ -1347,7 +1347,7 @@ Handle_set_loop_count(Handle *self, PyObject* args, void* nothing)
 
        try
        {
-               if(device->device->setLoopCount(self->handle, loops))
+               if((*reinterpret_cast<AUD_Reference<AUD_IDevice>*>(device->device))->setLoopCount(self->handle, loops))
                        return 0;
                PyErr_SetString(AUDError, "Couldn't set the loop count!");
        }
@@ -1369,7 +1369,7 @@ Handle_get_location(Handle *self, void* nothing)
 
        try
        {
-               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(dev->device);
+               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(reinterpret_cast<AUD_Reference<AUD_IDevice>*>(dev->device)->get());
                if(device)
                {
                        AUD_Vector3 v = device->getSourceLocation(self->handle);
@@ -1400,7 +1400,7 @@ Handle_set_location(Handle *self, PyObject* args, void* nothing)
 
        try
        {
-               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(dev->device);
+               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(reinterpret_cast<AUD_Reference<AUD_IDevice>*>(dev->device)->get());
                if(device)
                {
                        AUD_Vector3 location(x, y, z);
@@ -1429,7 +1429,7 @@ Handle_get_velocity(Handle *self, void* nothing)
 
        try
        {
-               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(dev->device);
+               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(reinterpret_cast<AUD_Reference<AUD_IDevice>*>(dev->device)->get());
                if(device)
                {
                        AUD_Vector3 v = device->getSourceVelocity(self->handle);
@@ -1460,7 +1460,7 @@ Handle_set_velocity(Handle *self, PyObject* args, void* nothing)
 
        try
        {
-               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(dev->device);
+               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(reinterpret_cast<AUD_Reference<AUD_IDevice>*>(dev->device)->get());
                if(device)
                {
                        AUD_Vector3 velocity(x, y, z);
@@ -1489,7 +1489,7 @@ Handle_get_orientation(Handle *self, void* nothing)
 
        try
        {
-               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(dev->device);
+               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(reinterpret_cast<AUD_Reference<AUD_IDevice>*>(dev->device)->get());
                if(device)
                {
                        AUD_Quaternion o = device->getSourceOrientation(self->handle);
@@ -1520,7 +1520,7 @@ Handle_set_orientation(Handle *self, PyObject* args, void* nothing)
 
        try
        {
-               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(dev->device);
+               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(reinterpret_cast<AUD_Reference<AUD_IDevice>*>(dev->device)->get());
                if(device)
                {
                        AUD_Quaternion orientation(w, x, y, z);
@@ -1549,7 +1549,7 @@ Handle_get_relative(Handle *self, void* nothing)
 
        try
        {
-               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(dev->device);
+               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(reinterpret_cast<AUD_Reference<AUD_IDevice>*>(dev->device)->get());
                if(device)
                {
                        return PyBool_FromLong((long)device->isRelative(self->handle));
@@ -1581,7 +1581,7 @@ Handle_set_relative(Handle *self, PyObject* args, void* nothing)
 
        try
        {
-               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(dev->device);
+               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(reinterpret_cast<AUD_Reference<AUD_IDevice>*>(dev->device)->get());
                if(device)
                {
                        if(device->setRelative(self->handle, relative))
@@ -1610,7 +1610,7 @@ Handle_get_volume_minimum(Handle *self, void* nothing)
 
        try
        {
-               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(dev->device);
+               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(reinterpret_cast<AUD_Reference<AUD_IDevice>*>(dev->device)->get());
                if(device)
                {
                        return Py_BuildValue("f", device->getVolumeMinimum(self->handle));
@@ -1640,7 +1640,7 @@ Handle_set_volume_minimum(Handle *self, PyObject* args, void* nothing)
 
        try
        {
-               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(dev->device);
+               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(reinterpret_cast<AUD_Reference<AUD_IDevice>*>(dev->device)->get());
                if(device)
                {
                        if(device->setVolumeMinimum(self->handle, volume))
@@ -1669,7 +1669,7 @@ Handle_get_volume_maximum(Handle *self, void* nothing)
 
        try
        {
-               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(dev->device);
+               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(reinterpret_cast<AUD_Reference<AUD_IDevice>*>(dev->device)->get());
                if(device)
                {
                        return Py_BuildValue("f", device->getVolumeMaximum(self->handle));
@@ -1699,7 +1699,7 @@ Handle_set_volume_maximum(Handle *self, PyObject* args, void* nothing)
 
        try
        {
-               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(dev->device);
+               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(reinterpret_cast<AUD_Reference<AUD_IDevice>*>(dev->device)->get());
                if(device)
                {
                        if(device->setVolumeMaximum(self->handle, volume))
@@ -1729,7 +1729,7 @@ Handle_get_distance_reference(Handle *self, void* nothing)
 
        try
        {
-               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(dev->device);
+               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(reinterpret_cast<AUD_Reference<AUD_IDevice>*>(dev->device)->get());
                if(device)
                {
                        return Py_BuildValue("f", device->getDistanceReference(self->handle));
@@ -1759,7 +1759,7 @@ Handle_set_distance_reference(Handle *self, PyObject* args, void* nothing)
 
        try
        {
-               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(dev->device);
+               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(reinterpret_cast<AUD_Reference<AUD_IDevice>*>(dev->device)->get());
                if(device)
                {
                        if(device->setDistanceReference(self->handle, distance))
@@ -1789,7 +1789,7 @@ Handle_get_distance_maximum(Handle *self, void* nothing)
 
        try
        {
-               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(dev->device);
+               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(reinterpret_cast<AUD_Reference<AUD_IDevice>*>(dev->device)->get());
                if(device)
                {
                        return Py_BuildValue("f", device->getDistanceMaximum(self->handle));
@@ -1819,7 +1819,7 @@ Handle_set_distance_maximum(Handle *self, PyObject* args, void* nothing)
 
        try
        {
-               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(dev->device);
+               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(reinterpret_cast<AUD_Reference<AUD_IDevice>*>(dev->device)->get());
                if(device)
                {
                        if(device->setDistanceMaximum(self->handle, distance))
@@ -1849,7 +1849,7 @@ Handle_get_attenuation(Handle *self, void* nothing)
 
        try
        {
-               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(dev->device);
+               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(reinterpret_cast<AUD_Reference<AUD_IDevice>*>(dev->device)->get());
                if(device)
                {
                        return Py_BuildValue("f", device->getAttenuation(self->handle));
@@ -1879,7 +1879,7 @@ Handle_set_attenuation(Handle *self, PyObject* args, void* nothing)
 
        try
        {
-               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(dev->device);
+               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(reinterpret_cast<AUD_Reference<AUD_IDevice>*>(dev->device)->get());
                if(device)
                {
                        if(device->setAttenuation(self->handle, factor))
@@ -1914,7 +1914,7 @@ Handle_get_cone_angle_inner(Handle *self, void* nothing)
 
        try
        {
-               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(dev->device);
+               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(reinterpret_cast<AUD_Reference<AUD_IDevice>*>(dev->device)->get());
                if(device)
                {
                        return Py_BuildValue("f", device->getConeAngleInner(self->handle));
@@ -1944,7 +1944,7 @@ Handle_set_cone_angle_inner(Handle *self, PyObject* args, void* nothing)
 
        try
        {
-               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(dev->device);
+               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(reinterpret_cast<AUD_Reference<AUD_IDevice>*>(dev->device)->get());
                if(device)
                {
                        if(device->setConeAngleInner(self->handle, angle))
@@ -1973,7 +1973,7 @@ Handle_get_cone_angle_outer(Handle *self, void* nothing)
 
        try
        {
-               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(dev->device);
+               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(reinterpret_cast<AUD_Reference<AUD_IDevice>*>(dev->device)->get());
                if(device)
                {
                        return Py_BuildValue("f", device->getConeAngleOuter(self->handle));
@@ -2003,7 +2003,7 @@ Handle_set_cone_angle_outer(Handle *self, PyObject* args, void* nothing)
 
        try
        {
-               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(dev->device);
+               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(reinterpret_cast<AUD_Reference<AUD_IDevice>*>(dev->device)->get());
                if(device)
                {
                        if(device->setConeAngleOuter(self->handle, angle))
@@ -2032,7 +2032,7 @@ Handle_get_cone_volume_outer(Handle *self, void* nothing)
 
        try
        {
-               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(dev->device);
+               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(reinterpret_cast<AUD_Reference<AUD_IDevice>*>(dev->device)->get());
                if(device)
                {
                        return Py_BuildValue("f", device->getConeVolumeOuter(self->handle));
@@ -2062,7 +2062,7 @@ Handle_set_cone_volume_outer(Handle *self, PyObject* args, void* nothing)
 
        try
        {
-               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(dev->device);
+               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(reinterpret_cast<AUD_Reference<AUD_IDevice>*>(dev->device)->get());
                if(device)
                {
                        if(device->setConeVolumeOuter(self->handle, volume))
@@ -2172,7 +2172,7 @@ static void
 Device_dealloc(Device* self)
 {
        if(self->device)
-               delete self->device;
+               delete reinterpret_cast<AUD_Reference<AUD_IDevice>*>(self->device);
        Py_TYPE(self)->tp_free((PyObject*)self);
 }
 
@@ -2215,21 +2215,21 @@ Device_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
                        {
                        case AUD_DEVICE_NULL:
                                (void)specs; /* quiet warning when others disabled */
-                               self->device = new AUD_NULLDevice();
+                               self->device = new AUD_Reference<AUD_IDevice>(new AUD_NULLDevice());
                                break;
                        case AUD_DEVICE_OPENAL:
 #ifdef WITH_OPENAL
-                               self->device = new AUD_OpenALDevice(specs, buffersize);
+                               self->device = new AUD_Reference<AUD_IDevice>(new AUD_OpenALDevice(specs, buffersize));
 #endif
                                break;
                        case AUD_DEVICE_SDL:
 #ifdef WITH_SDL
-                               self->device = new AUD_SDLDevice(specs, buffersize);
+                               self->device = new AUD_Reference<AUD_IDevice>(new AUD_SDLDevice(specs, buffersize));
 #endif
                                break;
                        case AUD_DEVICE_JACK:
 #ifdef WITH_JACK
-                               self->device = new AUD_JackDevice(name, specs, buffersize);
+                               self->device = new AUD_Reference<AUD_IDevice>(new AUD_JackDevice(name, specs, buffersize));
 #endif
                                break;
                        case AUD_DEVICE_READ:
@@ -2307,7 +2307,7 @@ Device_play(Device *self, PyObject *args, PyObject *kwds)
 
                try
                {
-                       handle->handle = self->device->play(sound->factory, keep);
+                       handle->handle = (*reinterpret_cast<AUD_Reference<AUD_IDevice>*>(self->device))->play(*reinterpret_cast<AUD_Reference<AUD_IFactory>*>(sound->factory), keep);
                }
                catch(AUD_Exception& e)
                {
@@ -2336,7 +2336,7 @@ Device_lock(Device *self)
 {
        try
        {
-               self->device->lock();
+               (*reinterpret_cast<AUD_Reference<AUD_IDevice>*>(self->device))->lock();
                Py_RETURN_NONE;
        }
        catch(AUD_Exception& e)
@@ -2356,7 +2356,7 @@ Device_unlock(Device *self)
 {
        try
        {
-               self->device->unlock();
+               (*reinterpret_cast<AUD_Reference<AUD_IDevice>*>(self->device))->unlock();
                Py_RETURN_NONE;
        }
        catch(AUD_Exception& e)
@@ -2387,7 +2387,7 @@ Device_get_rate(Device *self, void* nothing)
 {
        try
        {
-               AUD_DeviceSpecs specs = self->device->getSpecs();
+               AUD_DeviceSpecs specs = (*reinterpret_cast<AUD_Reference<AUD_IDevice>*>(self->device))->getSpecs();
                return Py_BuildValue("i", specs.rate);
        }
        catch(AUD_Exception& e)
@@ -2405,7 +2405,7 @@ Device_get_format(Device *self, void* nothing)
 {
        try
        {
-               AUD_DeviceSpecs specs = self->device->getSpecs();
+               AUD_DeviceSpecs specs = (*reinterpret_cast<AUD_Reference<AUD_IDevice>*>(self->device))->getSpecs();
                return Py_BuildValue("i", specs.format);
        }
        catch(AUD_Exception& e)
@@ -2423,7 +2423,7 @@ Device_get_channels(Device *self, void* nothing)
 {
        try
        {
-               AUD_DeviceSpecs specs = self->device->getSpecs();
+               AUD_DeviceSpecs specs = (*reinterpret_cast<AUD_Reference<AUD_IDevice>*>(self->device))->getSpecs();
                return Py_BuildValue("i", specs.channels);
        }
        catch(AUD_Exception& e)
@@ -2441,7 +2441,7 @@ Device_get_volume(Device *self, void* nothing)
 {
        try
        {
-               return Py_BuildValue("f", self->device->getVolume());
+               return Py_BuildValue("f", (*reinterpret_cast<AUD_Reference<AUD_IDevice>*>(self->device))->getVolume());
        }
        catch(AUD_Exception& e)
        {
@@ -2460,7 +2460,7 @@ Device_set_volume(Device *self, PyObject* args, void* nothing)
 
        try
        {
-               self->device->setVolume(volume);
+               (*reinterpret_cast<AUD_Reference<AUD_IDevice>*>(self->device))->setVolume(volume);
                return 0;
        }
        catch(AUD_Exception& e)
@@ -2478,7 +2478,7 @@ Device_get_listener_location(Device *self, void* nothing)
 {
        try
        {
-               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(self->device);
+               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(reinterpret_cast<AUD_Reference<AUD_IDevice>*>(self->device)->get());
                if(device)
                {
                        AUD_Vector3 v = device->getListenerLocation();
@@ -2507,7 +2507,7 @@ Device_set_listener_location(Device *self, PyObject* args, void* nothing)
 
        try
        {
-               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(self->device);
+               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(reinterpret_cast<AUD_Reference<AUD_IDevice>*>(self->device)->get());
                if(device)
                {
                        AUD_Vector3 location(x, y, z);
@@ -2533,7 +2533,7 @@ Device_get_listener_velocity(Device *self, void* nothing)
 {
        try
        {
-               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(self->device);
+               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(reinterpret_cast<AUD_Reference<AUD_IDevice>*>(self->device)->get());
                if(device)
                {
                        AUD_Vector3 v = device->getListenerVelocity();
@@ -2562,7 +2562,7 @@ Device_set_listener_velocity(Device *self, PyObject* args, void* nothing)
 
        try
        {
-               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(self->device);
+               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(reinterpret_cast<AUD_Reference<AUD_IDevice>*>(self->device)->get());
                if(device)
                {
                        AUD_Vector3 velocity(x, y, z);
@@ -2588,7 +2588,7 @@ Device_get_listener_orientation(Device *self, void* nothing)
 {
        try
        {
-               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(self->device);
+               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(reinterpret_cast<AUD_Reference<AUD_IDevice>*>(self->device)->get());
                if(device)
                {
                        AUD_Quaternion o = device->getListenerOrientation();
@@ -2617,7 +2617,7 @@ Device_set_listener_orientation(Device *self, PyObject* args, void* nothing)
 
        try
        {
-               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(self->device);
+               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(reinterpret_cast<AUD_Reference<AUD_IDevice>*>(self->device)->get());
                if(device)
                {
                        AUD_Quaternion orientation(w, x, y, z);
@@ -2644,7 +2644,7 @@ Device_get_speed_of_sound(Device *self, void* nothing)
 {
        try
        {
-               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(self->device);
+               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(reinterpret_cast<AUD_Reference<AUD_IDevice>*>(self->device)->get());
                if(device)
                {
                        return Py_BuildValue("f", device->getSpeedOfSound());
@@ -2672,7 +2672,7 @@ Device_set_speed_of_sound(Device *self, PyObject* args, void* nothing)
 
        try
        {
-               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(self->device);
+               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(reinterpret_cast<AUD_Reference<AUD_IDevice>*>(self->device)->get());
                if(device)
                {
                        device->setSpeedOfSound(speed);
@@ -2700,7 +2700,7 @@ Device_get_doppler_factor(Device *self, void* nothing)
 {
        try
        {
-               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(self->device);
+               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(reinterpret_cast<AUD_Reference<AUD_IDevice>*>(self->device)->get());
                if(device)
                {
                        return Py_BuildValue("f", device->getDopplerFactor());
@@ -2728,7 +2728,7 @@ Device_set_doppler_factor(Device *self, PyObject* args, void* nothing)
 
        try
        {
-               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(self->device);
+               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(reinterpret_cast<AUD_Reference<AUD_IDevice>*>(self->device)->get());
                if(device)
                {
                        device->setDopplerFactor(factor);
@@ -2754,7 +2754,7 @@ Device_get_distance_model(Device *self, void* nothing)
 {
        try
        {
-               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(self->device);
+               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(reinterpret_cast<AUD_Reference<AUD_IDevice>*>(self->device)->get());
                if(device)
                {
                        return Py_BuildValue("i", int(device->getDistanceModel()));
@@ -2782,7 +2782,7 @@ Device_set_distance_model(Device *self, PyObject* args, void* nothing)
 
        try
        {
-               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(self->device);
+               AUD_I3DDevice* device = dynamic_cast<AUD_I3DDevice*>(reinterpret_cast<AUD_Reference<AUD_IDevice>*>(self->device)->get());
                if(device)
                {
                        device->setDistanceModel(AUD_DistanceModel(model));
index 6e217b072130dbb44774fea2e50d3517bfd223d4..d1a70ce892d80f5bd2262a6b1a8c5bc64d9e2c70 100644 (file)
 
 #ifdef __cplusplus
 extern "C" {
-#include "AUD_IDevice.h"
+struct AUD_Handle;
 #else
 typedef void AUD_IFactory;
 typedef void AUD_IDevice;
 typedef void AUD_Handle;
 #endif
 
+typedef void AUD_Reference_AUD_IFactory;
+typedef void AUD_Reference_AUD_IDevice;
+
 typedef struct {
        PyObject_HEAD
        PyObject* child_list;
-       AUD_IFactory* factory;
+       AUD_Reference_AUD_IFactory* factory;
 } Factory;
 
 typedef struct {
@@ -57,7 +60,7 @@ typedef struct {
 
 typedef struct {
        PyObject_HEAD
-       AUD_IDevice* device;
+       AUD_Reference_AUD_IDevice* device;
 } Device;
 
 PyMODINIT_FUNC
index 17cf09efc1dbe29c4397944e42b4cf9343c8aa9f..ca9c71e73b88d1f2dc90f81016663112c843f147 100644 (file)
 #include "AUD_SRCResampleFactory.h"
 #include "AUD_SRCResampleReader.h"
 
-AUD_SRCResampleFactory::AUD_SRCResampleFactory(AUD_IFactory* factory,
+AUD_SRCResampleFactory::AUD_SRCResampleFactory(AUD_Reference<AUD_IFactory> factory,
                                                                                           AUD_DeviceSpecs specs) :
                AUD_ResampleFactory(factory, specs)
 {
 }
 
-AUD_IReader* AUD_SRCResampleFactory::createReader() const
+AUD_Reference<AUD_IReader> AUD_SRCResampleFactory::createReader() const
 {
-       AUD_IReader* reader = getReader();
+       AUD_Reference<AUD_IReader> reader = getReader();
 
        if(reader->getSpecs().rate != m_specs.rate)
                reader = new AUD_SRCResampleReader(reader, m_specs.specs);
index 716def960fde31f879db7ee3197127bf3737eb3d..5d21584b4dc590aa9b85c19020765c541e4dc3db 100644 (file)
@@ -46,9 +46,9 @@ private:
        AUD_SRCResampleFactory& operator=(const AUD_SRCResampleFactory&);
 
 public:
-       AUD_SRCResampleFactory(AUD_IFactory* factory, AUD_DeviceSpecs specs);
+       AUD_SRCResampleFactory(AUD_Reference<AUD_IFactory> factory, AUD_DeviceSpecs specs);
 
-       virtual AUD_IReader* createReader() const;
+       virtual AUD_Reference<AUD_IReader> createReader() const;
 };
 
 #endif //AUD_SRCRESAMPLEFACTORY
index 1026514a9b89eef6b5a6195a0df22934590d5720..e9a94418b6057e749bd93ecb9d880dae1af0624c 100644 (file)
@@ -43,7 +43,7 @@ static long src_callback(void *cb_data, float **data)
 static const char* state_error = "AUD_SRCResampleReader: SRC State couldn't be "
                                                                 "created.";
 
-AUD_SRCResampleReader::AUD_SRCResampleReader(AUD_IReader* reader,
+AUD_SRCResampleReader::AUD_SRCResampleReader(AUD_Reference<AUD_IReader> reader,
                                                                                         AUD_Specs specs) :
                AUD_EffectReader(reader),
                m_sspecs(reader->getSpecs()),
index 27019c0ed9ffddc1d7fc56b71f8f4b4238dca5aa..21193661911a5418429152e446daa53c1c80d8cf 100644 (file)
@@ -85,7 +85,7 @@ public:
         * \exception AUD_Exception Thrown if the source specification cannot be
         *            resampled to the target specification.
         */
-       AUD_SRCResampleReader(AUD_IReader* reader, AUD_Specs specs);
+       AUD_SRCResampleReader(AUD_Reference<AUD_IReader> reader, AUD_Specs specs);
 
        /**
         * Destroys the reader.
index 38de3e8867a31417e955de7f92bf04ec2b3e29f0..4e1eedd29ee6ffaf41329960579578a8ea8a5b8d 100644 (file)
@@ -46,13 +46,13 @@ AUD_FFMPEGFactory::AUD_FFMPEGFactory(std::string filename) :
 AUD_FFMPEGFactory::AUD_FFMPEGFactory(const data_t* buffer, int size) :
                m_buffer(new AUD_Buffer(size))
 {
-       memcpy(m_buffer.get()->getBuffer(), buffer, size);
+       memcpy(m_buffer->getBuffer(), buffer, size);
 }
 
-AUD_IReader* AUD_FFMPEGFactory::createReader() const
+AUD_Reference<AUD_IReader> AUD_FFMPEGFactory::createReader() const
 {
-       if(m_buffer.get())
-               return new AUD_FFMPEGReader(m_buffer);
-       else
+       if(m_buffer.isNull())
                return new AUD_FFMPEGReader(m_filename);
+       else
+               return new AUD_FFMPEGReader(m_buffer);
 }
index 12687402fb654a3e9bb83d173bc21e9206d64e0d..8033836e80b452655e6051ed55ef7e66ddb8fd8e 100644 (file)
@@ -74,7 +74,7 @@ public:
         */
        AUD_FFMPEGFactory(const data_t* buffer, int size);
 
-       virtual AUD_IReader* createReader() const;
+       virtual AUD_Reference<AUD_IReader> createReader() const;
 };
 
 #endif //AUD_FFMPEGFACTORY
index 4597432e7d14b500a11f786167d649cfb191fa92..ed6ca5d142ff04991a5aab3a7d7c5264dbb17c31 100644 (file)
@@ -255,12 +255,12 @@ int AUD_FFMPEGReader::read_packet(void* opaque, uint8_t* buf, int buf_size)
 {
        AUD_FFMPEGReader* reader = reinterpret_cast<AUD_FFMPEGReader*>(opaque);
 
-       int size = AUD_MIN(buf_size, reader->m_membuffer.get()->getSize() - reader->m_membufferpos);
+       int size = AUD_MIN(buf_size, reader->m_membuffer->getSize() - reader->m_membufferpos);
 
        if(size < 0)
                return -1;
 
-       memcpy(buf, ((data_t*)reader->m_membuffer.get()->getBuffer()) + reader->m_membufferpos, size);
+       memcpy(buf, ((data_t*)reader->m_membuffer->getBuffer()) + reader->m_membufferpos, size);
        reader->m_membufferpos += size;
 
        return size;
@@ -276,10 +276,10 @@ int64_t AUD_FFMPEGReader::seek_packet(void* opaque, int64_t offset, int whence)
                reader->m_membufferpos = 0;
                break;
        case SEEK_END:
-               reader->m_membufferpos = reader->m_membuffer.get()->getSize();
+               reader->m_membufferpos = reader->m_membuffer->getSize();
                break;
        case AVSEEK_SIZE:
-               return reader->m_membuffer.get()->getSize();
+               return reader->m_membuffer->getSize();
        }
 
        return (reader->m_membufferpos += offset);
index 78111ba104c5a4e80dfd949bc00653a443d2cea7..0ac967b29b0d412984694c4302e4253731f04515 100644 (file)
@@ -51,7 +51,7 @@ void AUD_BufferReader::seek(int position)
 
 int AUD_BufferReader::getLength() const
 {
-       return m_buffer.get()->getSize() / AUD_SAMPLE_SIZE(m_specs);
+       return m_buffer->getSize() / AUD_SAMPLE_SIZE(m_specs);
 }
 
 int AUD_BufferReader::getPosition() const
@@ -68,11 +68,11 @@ void AUD_BufferReader::read(int & length, sample_t* & buffer)
 {
        int sample_size = AUD_SAMPLE_SIZE(m_specs);
 
-       buffer = m_buffer.get()->getBuffer() + m_position * m_specs.channels;
+       buffer = m_buffer->getBuffer() + m_position * m_specs.channels;
 
        // in case the end of the buffer is reached
-       if(m_buffer.get()->getSize() < (m_position + length) * sample_size)
-               length = m_buffer.get()->getSize() / sample_size - m_position;
+       if(m_buffer->getSize() < (m_position + length) * sample_size)
+               length = m_buffer->getSize() / sample_size - m_position;
 
        if(length < 0)
                length = 0;
index 0119bb105d80065f10ed48bb69b2fa9b582ca053..3d78a5945dff18530777dadf6be55dcae943ed1c 100644 (file)
@@ -37,9 +37,6 @@
 #ifdef WITH_PYTHON
 #include "AUD_PyInit.h"
 #include "AUD_PyAPI.h"
-
-Device* g_device;
-bool g_pyinitialized = false;
 #endif
 
 #include <cstdlib>
@@ -90,9 +87,10 @@ extern "C" {
 
 #include <cassert>
 
-typedef AUD_IFactory AUD_Sound;
-typedef AUD_ReadDevice AUD_Device;
+typedef AUD_Reference<AUD_IFactory> AUD_Sound;
+typedef AUD_Reference<AUD_ReadDevice> AUD_Device;
 typedef AUD_Handle AUD_Channel;
+typedef AUD_Reference<AUD_SequencerEntry> AUD_SEntry;
 
 #define AUD_CAPI_IMPLEMENTATION
 #include "AUD_C-API.h"
@@ -101,8 +99,8 @@ typedef AUD_Handle AUD_Channel;
 #define NULL 0
 #endif
 
-static AUD_IDevice* AUD_device = NULL;
-static AUD_I3DDevice* AUD_3ddevice = NULL;
+static AUD_Reference<AUD_IDevice> AUD_device;
+static AUD_I3DDevice* AUD_3ddevice;
 
 void AUD_initOnce()
 {
@@ -113,9 +111,9 @@ void AUD_initOnce()
 
 int AUD_init(AUD_DeviceType device, AUD_DeviceSpecs specs, int buffersize)
 {
-       AUD_IDevice* dev = NULL;
+       AUD_Reference<AUD_IDevice> dev = NULL;
 
-       if(AUD_device)
+       if(!AUD_device.isNull())
                AUD_exit();
 
        try
@@ -145,18 +143,7 @@ int AUD_init(AUD_DeviceType device, AUD_DeviceSpecs specs, int buffersize)
                }
 
                AUD_device = dev;
-               AUD_3ddevice = dynamic_cast<AUD_I3DDevice*>(AUD_device);
-
-#ifdef WITH_PYTHON
-               if(g_pyinitialized)
-               {
-                       g_device = (Device*)Device_empty();
-                       if(g_device != NULL)
-                       {
-                               g_device->device = dev;
-                       }
-               }
-#endif
+               AUD_3ddevice = dynamic_cast<AUD_I3DDevice*>(AUD_device.get());
 
                return true;
        }
@@ -168,16 +155,6 @@ int AUD_init(AUD_DeviceType device, AUD_DeviceSpecs specs, int buffersize)
 
 void AUD_exit()
 {
-#ifdef WITH_PYTHON
-       if(g_device)
-       {
-               Py_XDECREF(g_device);
-               g_device = NULL;
-       }
-       else
-#endif
-       if(AUD_device)
-               delete AUD_device;
        AUD_device = NULL;
        AUD_3ddevice = NULL;
 }
@@ -185,11 +162,16 @@ void AUD_exit()
 #ifdef WITH_PYTHON
 static PyObject* AUD_getCDevice(PyObject* self)
 {
-       if(g_device)
+       if(!AUD_device.isNull())
        {
-               Py_INCREF(g_device);
-               return (PyObject*)g_device;
+               Device* device = (Device*)Device_empty();
+               if(device != NULL)
+               {
+                       device->device = new AUD_Reference<AUD_IDevice>(AUD_device);
+                       return (PyObject*)device;
+               }
        }
+
        Py_RETURN_NONE;
 }
 
@@ -204,15 +186,6 @@ PyObject* AUD_initPython()
        PyObject* module = PyInit_aud();
        PyModule_AddObject(module, "device", (PyObject *)PyCFunction_New(meth_getcdevice, NULL));
        PyDict_SetItemString(PyImport_GetModuleDict(), "aud", module);
-       if(AUD_device)
-       {
-               g_device = (Device*)Device_empty();
-               if(g_device != NULL)
-               {
-                       g_device->device = AUD_device;
-               }
-       }
-       g_pyinitialized = true;
 
        return module;
 }
@@ -220,13 +193,11 @@ PyObject* AUD_initPython()
 
 void AUD_lock()
 {
-       assert(AUD_device);
        AUD_device->lock();
 }
 
 void AUD_unlock()
 {
-       assert(AUD_device);
        AUD_device->unlock();
 }
 
@@ -241,13 +212,12 @@ AUD_SoundInfo AUD_getInfo(AUD_Sound* sound)
 
        try
        {
-               AUD_IReader* reader = sound->createReader();
+               AUD_Reference<AUD_IReader> reader = (*sound)->createReader();
 
-               if(reader)
+               if(!reader.isNull())
                {
                        info.specs = reader->getSpecs();
                        info.length = reader->getLength() / (float) info.specs.rate;
-                       delete reader;
                }
        }
        catch(AUD_Exception&)
@@ -260,13 +230,13 @@ AUD_SoundInfo AUD_getInfo(AUD_Sound* sound)
 AUD_Sound* AUD_load(const char* filename)
 {
        assert(filename);
-       return new AUD_FileFactory(filename);
+       return new AUD_Sound(new AUD_FileFactory(filename));
 }
 
 AUD_Sound* AUD_loadBuffer(unsigned char* buffer, int size)
 {
        assert(buffer);
-       return new AUD_FileFactory(buffer, size);
+       return new AUD_Sound(new AUD_FileFactory(buffer, size));
 }
 
 AUD_Sound* AUD_bufferSound(AUD_Sound* sound)
@@ -275,7 +245,7 @@ AUD_Sound* AUD_bufferSound(AUD_Sound* sound)
 
        try
        {
-               return new AUD_StreamBufferFactory(sound);
+               return new AUD_Sound(new AUD_StreamBufferFactory(*sound));
        }
        catch(AUD_Exception&)
        {
@@ -289,7 +259,7 @@ AUD_Sound* AUD_delaySound(AUD_Sound* sound, float delay)
 
        try
        {
-               return new AUD_DelayFactory(sound, delay);
+               return new AUD_Sound(new AUD_DelayFactory(*sound, delay));
        }
        catch(AUD_Exception&)
        {
@@ -303,7 +273,7 @@ AUD_Sound* AUD_limitSound(AUD_Sound* sound, float start, float end)
 
        try
        {
-               return new AUD_LimiterFactory(sound, start, end);
+               return new AUD_Sound(new AUD_LimiterFactory(*sound, start, end));
        }
        catch(AUD_Exception&)
        {
@@ -317,7 +287,7 @@ AUD_Sound* AUD_pingpongSound(AUD_Sound* sound)
 
        try
        {
-               return new AUD_PingPongFactory(sound);
+               return new AUD_Sound(new AUD_PingPongFactory(*sound));
        }
        catch(AUD_Exception&)
        {
@@ -331,7 +301,7 @@ AUD_Sound* AUD_loopSound(AUD_Sound* sound)
 
        try
        {
-               return new AUD_LoopFactory(sound);
+               return new AUD_Sound(new AUD_LoopFactory(*sound));
        }
        catch(AUD_Exception&)
        {
@@ -360,7 +330,7 @@ AUD_Sound* AUD_rectifySound(AUD_Sound* sound)
 
        try
        {
-               return new AUD_RectifyFactory(sound);
+               return new AUD_Sound(new AUD_RectifyFactory(*sound));
        }
        catch(AUD_Exception&)
        {
@@ -376,11 +346,10 @@ void AUD_unload(AUD_Sound* sound)
 
 AUD_Channel* AUD_play(AUD_Sound* sound, int keep)
 {
-       assert(AUD_device);
        assert(sound);
        try
        {
-               return AUD_device->play(sound, keep);
+               return AUD_device->play(*sound, keep);
        }
        catch(AUD_Exception&)
        {
@@ -390,51 +359,43 @@ AUD_Channel* AUD_play(AUD_Sound* sound, int keep)
 
 int AUD_pause(AUD_Channel* handle)
 {
-       assert(AUD_device);
        return AUD_device->pause(handle);
 }
 
 int AUD_resume(AUD_Channel* handle)
 {
-       assert(AUD_device);
        return AUD_device->resume(handle);
 }
 
 int AUD_stop(AUD_Channel* handle)
 {
-       if(AUD_device)
+       if(!AUD_device.isNull())
                return AUD_device->stop(handle);
        return false;
 }
 
 int AUD_setKeep(AUD_Channel* handle, int keep)
 {
-       assert(AUD_device);
        return AUD_device->setKeep(handle, keep);
 }
 
 int AUD_seek(AUD_Channel* handle, float seekTo)
 {
-       assert(AUD_device);
        return AUD_device->seek(handle, seekTo);
 }
 
 float AUD_getPosition(AUD_Channel* handle)
 {
-       assert(AUD_device);
        return AUD_device->getPosition(handle);
 }
 
 AUD_Status AUD_getStatus(AUD_Channel* handle)
 {
-       assert(AUD_device);
        return AUD_device->getStatus(handle);
 }
 
 int AUD_setListenerLocation(const float* location)
 {
-       assert(AUD_device);
-
        if(AUD_3ddevice)
        {
                AUD_Vector3 v(location[0], location[1], location[2]);
@@ -447,8 +408,6 @@ int AUD_setListenerLocation(const float* location)
 
 int AUD_setListenerVelocity(const float* velocity)
 {
-       assert(AUD_device);
-
        if(AUD_3ddevice)
        {
                AUD_Vector3 v(velocity[0], velocity[1], velocity[2]);
@@ -461,8 +420,6 @@ int AUD_setListenerVelocity(const float* velocity)
 
 int AUD_setListenerOrientation(const float* orientation)
 {
-       assert(AUD_device);
-
        if(AUD_3ddevice)
        {
                AUD_Quaternion q(orientation[3], orientation[0], orientation[1], orientation[2]);
@@ -475,8 +432,6 @@ int AUD_setListenerOrientation(const float* orientation)
 
 int AUD_setSpeedOfSound(float speed)
 {
-       assert(AUD_device);
-
        if(AUD_3ddevice)
        {
                AUD_3ddevice->setSpeedOfSound(speed);
@@ -488,8 +443,6 @@ int AUD_setSpeedOfSound(float speed)
 
 int AUD_setDopplerFactor(float factor)
 {
-       assert(AUD_device);
-
        if(AUD_3ddevice)
        {
                AUD_3ddevice->setDopplerFactor(factor);
@@ -501,8 +454,6 @@ int AUD_setDopplerFactor(float factor)
 
 int AUD_setDistanceModel(AUD_DistanceModel model)
 {
-       assert(AUD_device);
-
        if(AUD_3ddevice)
        {
                AUD_3ddevice->setDistanceModel(model);
@@ -514,8 +465,6 @@ int AUD_setDistanceModel(AUD_DistanceModel model)
 
 int AUD_setSourceLocation(AUD_Channel* handle, const float* location)
 {
-       assert(AUD_device);
-
        if(AUD_3ddevice)
        {
                AUD_Vector3 v(location[0], location[1], location[2]);
@@ -527,8 +476,6 @@ int AUD_setSourceLocation(AUD_Channel* handle, const float* location)
 
 int AUD_setSourceVelocity(AUD_Channel* handle, const float* velocity)
 {
-       assert(AUD_device);
-
        if(AUD_3ddevice)
        {
                AUD_Vector3 v(velocity[0], velocity[1], velocity[2]);
@@ -540,8 +487,6 @@ int AUD_setSourceVelocity(AUD_Channel* handle, const float* velocity)
 
 int AUD_setSourceOrientation(AUD_Channel* handle, const float* orientation)
 {
-       assert(AUD_device);
-
        if(AUD_3ddevice)
        {
                AUD_Quaternion q(orientation[3], orientation[0], orientation[1], orientation[2]);
@@ -553,8 +498,6 @@ int AUD_setSourceOrientation(AUD_Channel* handle, const float* orientation)
 
 int AUD_setRelative(AUD_Channel* handle, int relative)
 {
-       assert(AUD_device);
-
        if(AUD_3ddevice)
        {
                return AUD_3ddevice->setRelative(handle, relative);
@@ -565,8 +508,6 @@ int AUD_setRelative(AUD_Channel* handle, int relative)
 
 int AUD_setVolumeMaximum(AUD_Channel* handle, float volume)
 {
-       assert(AUD_device);
-
        if(AUD_3ddevice)
        {
                return AUD_3ddevice->setVolumeMaximum(handle, volume);
@@ -577,8 +518,6 @@ int AUD_setVolumeMaximum(AUD_Channel* handle, float volume)
 
 int AUD_setVolumeMinimum(AUD_Channel* handle, float volume)
 {
-       assert(AUD_device);
-
        if(AUD_3ddevice)
        {
                return AUD_3ddevice->setVolumeMinimum(handle, volume);
@@ -589,8 +528,6 @@ int AUD_setVolumeMinimum(AUD_Channel* handle, float volume)
 
 int AUD_setDistanceMaximum(AUD_Channel* handle, float distance)
 {
-       assert(AUD_device);
-
        if(AUD_3ddevice)
        {
                return AUD_3ddevice->setDistanceMaximum(handle, distance);
@@ -601,8 +538,6 @@ int AUD_setDistanceMaximum(AUD_Channel* handle, float distance)
 
 int AUD_setDistanceReference(AUD_Channel* handle, float distance)
 {
-       assert(AUD_device);
-
        if(AUD_3ddevice)
        {
                return AUD_3ddevice->setDistanceReference(handle, distance);
@@ -613,8 +548,6 @@ int AUD_setDistanceReference(AUD_Channel* handle, float distance)
 
 int AUD_setAttenuation(AUD_Channel* handle, float factor)
 {
-       assert(AUD_device);
-
        if(AUD_3ddevice)
        {
                return AUD_3ddevice->setAttenuation(handle, factor);
@@ -625,8 +558,6 @@ int AUD_setAttenuation(AUD_Channel* handle, float factor)
 
 int AUD_setConeAngleOuter(AUD_Channel* handle, float angle)
 {
-       assert(AUD_device);
-
        if(AUD_3ddevice)
        {
                return AUD_3ddevice->setConeAngleOuter(handle, angle);
@@ -637,8 +568,6 @@ int AUD_setConeAngleOuter(AUD_Channel* handle, float angle)
 
 int AUD_setConeAngleInner(AUD_Channel* handle, float angle)
 {
-       assert(AUD_device);
-
        if(AUD_3ddevice)
        {
                return AUD_3ddevice->setConeAngleInner(handle, angle);
@@ -649,8 +578,6 @@ int AUD_setConeAngleInner(AUD_Channel* handle, float angle)
 
 int AUD_setConeVolumeOuter(AUD_Channel* handle, float volume)
 {
-       assert(AUD_device);
-
        if(AUD_3ddevice)
        {
                return AUD_3ddevice->setConeVolumeOuter(handle, volume);
@@ -663,8 +590,6 @@ int AUD_setSoundVolume(AUD_Channel* handle, float volume)
 {
        if(handle)
        {
-               assert(AUD_device);
-
                try
                {
                        return AUD_device->setVolume(handle, volume);
@@ -678,8 +603,6 @@ int AUD_setSoundPitch(AUD_Channel* handle, float pitch)
 {
        if(handle)
        {
-               assert(AUD_device);
-
                try
                {
                        return AUD_device->setPitch(handle, pitch);
@@ -693,7 +616,7 @@ AUD_Device* AUD_openReadDevice(AUD_DeviceSpecs specs)
 {
        try
        {
-               return new AUD_ReadDevice(specs);
+               return new AUD_Device(new AUD_ReadDevice(specs));
        }
        catch(AUD_Exception&)
        {
@@ -708,8 +631,8 @@ AUD_Channel* AUD_playDevice(AUD_Device* device, AUD_Sound* sound, float seek)
 
        try
        {
-               AUD_Channel* handle = device->play(sound);
-               device->seek(handle, seek);
+               AUD_Channel* handle = (*device)->play(*sound);
+               (*device)->seek(handle, seek);
                return handle;
        }
        catch(AUD_Exception&)
@@ -724,7 +647,7 @@ int AUD_setDeviceVolume(AUD_Device* device, float volume)
 
        try
        {
-               device->setVolume(volume);
+               (*device)->setVolume(volume);
                return true;
        }
        catch(AUD_Exception&) {}
@@ -741,7 +664,7 @@ int AUD_setDeviceSoundVolume(AUD_Device* device, AUD_Channel* handle,
 
                try
                {
-                       return device->setVolume(handle, volume);
+                       return (*device)->setVolume(handle, volume);
                }
                catch(AUD_Exception&) {}
        }
@@ -755,7 +678,7 @@ int AUD_readDevice(AUD_Device* device, data_t* buffer, int length)
 
        try
        {
-               return device->read(buffer, length);
+               return (*device)->read(buffer, length);
        }
        catch(AUD_Exception&)
        {
@@ -785,38 +708,34 @@ float* AUD_readSoundBuffer(const char* filename, float low, float high,
        AUD_DeviceSpecs specs;
        specs.channels = AUD_CHANNELS_MONO;
        specs.rate = (AUD_SampleRate)samplerate;
-       AUD_Sound* sound;
+       AUD_Reference<AUD_IFactory> sound;
 
-       AUD_FileFactory file(filename);
+       AUD_Reference<AUD_IFactory> file = new AUD_FileFactory(filename);
 
-       AUD_IReader* reader = file.createReader();
+       AUD_Reference<AUD_IReader> reader = file->createReader();
        AUD_SampleRate rate = reader->getSpecs().rate;
-       delete reader;
 
-       AUD_ChannelMapperFactory mapper(&file, specs);
-       sound = &mapper;
-       AUD_LowpassFactory lowpass(sound, high);
+       sound = new AUD_ChannelMapperFactory(file, specs);
+
        if(high < rate)
-               sound = &lowpass;
-       AUD_HighpassFactory highpass(sound, low);
+               sound = new AUD_LowpassFactory(sound, high);
        if(low > 0)
-               sound = &highpass;
-       AUD_EnvelopeFactory envelope(sound, attack, release, threshold, 0.1f);
-       AUD_LinearResampleFactory resampler(&envelope, specs);
-       sound = &resampler;
-       AUD_SquareFactory squaref(sound, sthreshold);
+               sound = new AUD_HighpassFactory(sound, low);;
+
+       sound = new AUD_EnvelopeFactory(sound, attack, release, threshold, 0.1f);
+       sound = new AUD_LinearResampleFactory(sound, specs);
+
        if(square)
-               sound = &squaref;
-       AUD_AccumulatorFactory accumulator(sound, additive);
-       AUD_SumFactory sum(sound);
+               sound = new AUD_SquareFactory(sound, sthreshold);
+
        if(accumulate)
-               sound = &accumulator;
+               sound = new AUD_AccumulatorFactory(sound, additive);
        else if(additive)
-               sound = &sum;
+               sound = new AUD_SumFactory(sound);
 
        reader = sound->createReader();
 
-       if(reader == NULL)
+       if(reader.isNull())
                return NULL;
 
        int len;
@@ -830,7 +749,6 @@ float* AUD_readSoundBuffer(const char* filename, float low, float high,
                memcpy(buffer.getBuffer() + position, readbuffer, len * sizeof(float));
                position += len;
        } while(len != 0);
-       delete reader;
 
        float* result = (float*)malloc(position * sizeof(float));
        memcpy(result, buffer.getBuffer(), position * sizeof(float));
@@ -840,21 +758,17 @@ float* AUD_readSoundBuffer(const char* filename, float low, float high,
 
 static void pauseSound(AUD_Channel* handle)
 {
-       assert(AUD_device);
-
        AUD_device->pause(handle);
 }
 
 AUD_Channel* AUD_pauseAfter(AUD_Channel* handle, float seconds)
 {
-       assert(AUD_device);
-
-       AUD_SilenceFactory silence;
-       AUD_LimiterFactory limiter(&silence, 0, seconds);
+       AUD_Reference<AUD_IFactory> silence = new AUD_SilenceFactory;
+       AUD_Reference<AUD_IFactory> limiter = new AUD_LimiterFactory(silence, 0, seconds);
 
        try
        {
-               AUD_Channel* channel = AUD_device->play(&limiter);
+               AUD_Channel* channel = AUD_device->play(limiter);
                AUD_device->setStopCallback(channel, (stopCallback)pauseSound, handle);
                return channel;
        }
@@ -874,39 +788,42 @@ AUD_Sound* AUD_createSequencer(int muted, void* data, AUD_volumeFunction volume)
        AUD_Specs specs;
        specs.channels = AUD_CHANNELS_STEREO;
        specs.rate = AUD_RATE_44100;
-       return new AUD_SequencerFactory(specs, muted, data, volume);
+       AUD_Reference<AUD_SequencerFactory>* sequencer = new AUD_Reference<AUD_SequencerFactory>(new AUD_SequencerFactory(specs, muted, data, volume));
+       (*sequencer)->setThis(sequencer);
+       return reinterpret_cast<AUD_Sound*>(sequencer);
 }
 
 void AUD_destroySequencer(AUD_Sound* sequencer)
 {
-       delete ((AUD_SequencerFactory*)sequencer);
+       delete sequencer;
 }
 
 void AUD_setSequencerMuted(AUD_Sound* sequencer, int muted)
 {
-       ((AUD_SequencerFactory*)sequencer)->mute(muted);
+       ((AUD_SequencerFactory*)sequencer->get())->mute(muted);
 }
 
-AUD_SequencerEntry* AUD_addSequencer(AUD_Sound** sequencer, AUD_Sound* sound,
+AUD_Reference<AUD_SequencerEntry>* AUD_addSequencer(AUD_Sound* sequencer, AUD_Sound** sound,
                                                                 float begin, float end, float skip, void* data)
 {
-       return ((AUD_SequencerFactory*)sequencer)->add((AUD_IFactory**) sound, begin, end, skip, data);
+       return new AUD_Reference<AUD_SequencerEntry>(((AUD_SequencerFactory*)sequencer->get())->add(sound, begin, end, skip, data));
 }
 
-void AUD_removeSequencer(AUD_Sound* sequencer, AUD_SequencerEntry* entry)
+void AUD_removeSequencer(AUD_Sound* sequencer, AUD_Reference<AUD_SequencerEntry>* entry)
 {
-       ((AUD_SequencerFactory*)sequencer)->remove(entry);
+       ((AUD_SequencerFactory*)sequencer->get())->remove(*entry);
+       delete entry;
 }
 
-void AUD_moveSequencer(AUD_Sound* sequencer, AUD_SequencerEntry* entry,
+void AUD_moveSequencer(AUD_Sound* sequencer, AUD_Reference<AUD_SequencerEntry>* entry,
                                   float begin, float end, float skip)
 {
-       ((AUD_SequencerFactory*)sequencer)->move(entry, begin, end, skip);
+       ((AUD_SequencerFactory*)sequencer->get())->move(*entry, begin, end, skip);
 }
 
-void AUD_muteSequencer(AUD_Sound* sequencer, AUD_SequencerEntry* entry, char mute)
+void AUD_muteSequencer(AUD_Sound* sequencer, AUD_Reference<AUD_SequencerEntry>* entry, char mute)
 {
-       ((AUD_SequencerFactory*)sequencer)->mute(entry, mute);
+       ((AUD_SequencerFactory*)sequencer->get())->mute(*entry, mute);
 }
 
 int AUD_readSound(AUD_Sound* sound, sample_t* buffer, int length)
@@ -918,9 +835,7 @@ int AUD_readSound(AUD_Sound* sound, sample_t* buffer, int length)
        specs.channels = AUD_CHANNELS_MONO;
        specs.format = AUD_FORMAT_INVALID;
 
-       AUD_ChannelMapperFactory mapper(sound, specs);
-
-       AUD_IReader* reader = mapper.createReader();
+       AUD_Reference<AUD_IReader> reader = AUD_ChannelMapperFactory(*sound, specs).createReader();
 
        int len = reader->getLength();
        float samplejump = (float)len / (float)length;
@@ -949,15 +864,13 @@ int AUD_readSound(AUD_Sound* sound, sample_t* buffer, int length)
                }
        }
 
-       delete reader;
-
        return length;
 }
 
 void AUD_startPlayback()
 {
 #ifdef WITH_JACK
-       AUD_JackDevice* device = dynamic_cast<AUD_JackDevice*>(AUD_device);
+       AUD_JackDevice* device = dynamic_cast<AUD_JackDevice*>(AUD_device.get());
        if(device)
                device->startPlayback();
 #endif
@@ -966,7 +879,7 @@ void AUD_startPlayback()
 void AUD_stopPlayback()
 {
 #ifdef WITH_JACK
-       AUD_JackDevice* device = dynamic_cast<AUD_JackDevice*>(AUD_device);
+       AUD_JackDevice* device = dynamic_cast<AUD_JackDevice*>(AUD_device.get());
        if(device)
                device->stopPlayback();
 #endif
@@ -975,7 +888,7 @@ void AUD_stopPlayback()
 void AUD_seekSequencer(AUD_Channel* handle, float time)
 {
 #ifdef WITH_JACK
-       AUD_JackDevice* device = dynamic_cast<AUD_JackDevice*>(AUD_device);
+       AUD_JackDevice* device = dynamic_cast<AUD_JackDevice*>(AUD_device.get());
        if(device)
                device->seekPlayback(time);
        else
@@ -988,7 +901,7 @@ void AUD_seekSequencer(AUD_Channel* handle, float time)
 float AUD_getSequencerPosition(AUD_Channel* handle)
 {
 #ifdef WITH_JACK
-       AUD_JackDevice* device = dynamic_cast<AUD_JackDevice*>(AUD_device);
+       AUD_JackDevice* device = dynamic_cast<AUD_JackDevice*>(AUD_device.get());
        if(device)
                return device->getPlaybackPosition();
        else
@@ -1001,7 +914,7 @@ float AUD_getSequencerPosition(AUD_Channel* handle)
 #ifdef WITH_JACK
 void AUD_setSyncCallback(AUD_syncFunction function, void* data)
 {
-       AUD_JackDevice* device = dynamic_cast<AUD_JackDevice*>(AUD_device);
+       AUD_JackDevice* device = dynamic_cast<AUD_JackDevice*>(AUD_device.get());
        if(device)
                device->setSyncCallback(function, data);
 }
@@ -1010,7 +923,7 @@ void AUD_setSyncCallback(AUD_syncFunction function, void* data)
 int AUD_doesPlayback()
 {
 #ifdef WITH_JACK
-       AUD_JackDevice* device = dynamic_cast<AUD_JackDevice*>(AUD_device);
+       AUD_JackDevice* device = dynamic_cast<AUD_JackDevice*>(AUD_device.get());
        if(device)
                return device->doesPlayback();
 #endif
index b2242f09547f904fb13c63f1d036f6e9b462f4b5..47dadd05555670f635c872c08848e05bdc6a2579 100644 (file)
@@ -55,7 +55,7 @@ typedef struct
        typedef void AUD_Sound;
        typedef void AUD_Channel;
        typedef void AUD_Device;
-       typedef void AUD_SequencerEntry;
+       typedef void AUD_SEntry;
        typedef float (*AUD_volumeFunction)(void*, void*, float);
        typedef void (*AUD_syncFunction)(void*, int, float);
 #endif
@@ -465,15 +465,15 @@ extern void AUD_destroySequencer(AUD_Sound* sequencer);
 
 extern void AUD_setSequencerMuted(AUD_Sound* sequencer, int muted);
 
-extern AUD_SequencerEntry* AUD_addSequencer(AUD_Sound** sequencer, AUD_Sound* sound,
+extern AUD_SEntry* AUD_addSequencer(AUD_Sound* sequencer, AUD_Sound** sound,
                                                                                float begin, float end, float skip, void* data);
 
-extern void AUD_removeSequencer(AUD_Sound* sequencer, AUD_SequencerEntry* entry);
+extern void AUD_removeSequencer(AUD_Sound* sequencer, AUD_SEntry* entry);
 
-extern void AUD_moveSequencer(AUD_Sound* sequencer, AUD_SequencerEntry* entry,
+extern void AUD_moveSequencer(AUD_Sound* sequencer, AUD_SEntry* entry,
                                                  float begin, float end, float skip);
 
-extern void AUD_muteSequencer(AUD_Sound* sequencer, AUD_SequencerEntry* entry,
+extern void AUD_muteSequencer(AUD_Sound* sequencer, AUD_SEntry* entry,
                                                  char mute);
 
 extern int AUD_readSound(AUD_Sound* sound, sample_t* buffer, int length);
index b474fbad4444dcccb9957dfd9c5d9bab059962cf..ea5e9519729d7e5695f593a55e4ccebc015f2f77 100644 (file)
@@ -34,7 +34,7 @@
 
 #include <cstring>
 
-AUD_ChannelMapperFactory::AUD_ChannelMapperFactory(AUD_IFactory* factory,
+AUD_ChannelMapperFactory::AUD_ChannelMapperFactory(AUD_Reference<AUD_IFactory> factory,
                                                                                                   AUD_DeviceSpecs specs) :
                AUD_MixerFactory(factory, specs)
 {
@@ -102,9 +102,9 @@ void AUD_ChannelMapperFactory::deleteMapping(int ic)
        }
 }
 
-AUD_IReader* AUD_ChannelMapperFactory::createReader() const
+AUD_Reference<AUD_IReader> AUD_ChannelMapperFactory::createReader() const
 {
-       AUD_IReader* reader = getReader();
+       AUD_Reference<AUD_IReader> reader = getReader();
        int ic = reader->getSpecs().channels;
 
        return new AUD_ChannelMapperReader(reader,
index 9d622f5e322c00d5b34202313c4673a6e1c0b6cf..25b3e091d8d324530a6cee79702094d983088f9b 100644 (file)
@@ -51,7 +51,7 @@ private:
        AUD_ChannelMapperFactory& operator=(const AUD_ChannelMapperFactory&);
 
 public:
-       AUD_ChannelMapperFactory(AUD_IFactory* factory, AUD_DeviceSpecs specs);
+       AUD_ChannelMapperFactory(AUD_Reference<AUD_IFactory> factory, AUD_DeviceSpecs specs);
 
        virtual ~AUD_ChannelMapperFactory();
 
@@ -67,7 +67,7 @@ public:
         */
        void deleteMapping(int ic);
 
-       virtual AUD_IReader* createReader() const;
+       virtual AUD_Reference<AUD_IReader> createReader() const;
 };
 
 #endif //AUD_CHANNELMAPPERFACTORY
index dec70aaecf66f921e0544dd194683d47e46b8351..3079d31c9e9d76f729e03adc008d1f38ca08242d 100644 (file)
@@ -31,7 +31,7 @@
 
 #include "AUD_ChannelMapperReader.h"
 
-AUD_ChannelMapperReader::AUD_ChannelMapperReader(AUD_IReader* reader,
+AUD_ChannelMapperReader::AUD_ChannelMapperReader(AUD_Reference<AUD_IReader> reader,
                                                                                                 float **mapping) :
                AUD_EffectReader(reader)
 {
index 091ed06db158d68120c72cd5c9789dbc4849c7d9..1c7dba1df7c851a68647ec87c05e0066694e20d6 100644 (file)
@@ -72,7 +72,7 @@ public:
         * \param reader The reader to map.
         * \param mapping The mapping specification as two dimensional float array.
         */
-       AUD_ChannelMapperReader(AUD_IReader* reader, float **mapping);
+       AUD_ChannelMapperReader(AUD_Reference<AUD_IReader> reader, float **mapping);
 
        /**
         * Destroys the reader.
index cce0f2736167356f21c48d1869ca06dd07c37ac8..78602d2cfa9c6ad8efe44b2ded6a588bd11b06e7 100644 (file)
 #include "AUD_ConverterFactory.h"
 #include "AUD_ConverterReader.h"
 
-AUD_ConverterFactory::AUD_ConverterFactory(AUD_IFactory* factory,
+AUD_ConverterFactory::AUD_ConverterFactory(AUD_Reference<AUD_IFactory> factory,
                                                                                   AUD_DeviceSpecs specs) :
                AUD_MixerFactory(factory, specs)
 {
 }
 
-AUD_IReader* AUD_ConverterFactory::createReader() const
+AUD_Reference<AUD_IReader> AUD_ConverterFactory::createReader() const
 {
-       AUD_IReader* reader = getReader();
+       AUD_Reference<AUD_IReader> reader = getReader();
 
        if(m_specs.format != AUD_FORMAT_FLOAT32)
                reader = new AUD_ConverterReader(reader, m_specs);
index b9eac94de401dcca5a808c0f4b206b5eed6a0bd4..cc1fedb2a1077cc2a3c6f77969a0ae0df075a503 100644 (file)
@@ -46,9 +46,9 @@ private:
        AUD_ConverterFactory& operator=(const AUD_ConverterFactory&);
 
 public:
-       AUD_ConverterFactory(AUD_IFactory* factory, AUD_DeviceSpecs specs);
+       AUD_ConverterFactory(AUD_Reference<AUD_IFactory> factory, AUD_DeviceSpecs specs);
 
-       virtual AUD_IReader* createReader() const;
+       virtual AUD_Reference<AUD_IReader> createReader() const;
 };
 
 #endif //AUD_CONVERTERFACTORY
index 70297b8f5e8358e328c13f03ec520a2b769936e2..6927f3e969c339b20de0afd2e3bc8e2cfee68c15 100644 (file)
@@ -31,7 +31,7 @@
 
 #include "AUD_ConverterReader.h"
 
-AUD_ConverterReader::AUD_ConverterReader(AUD_IReader* reader,
+AUD_ConverterReader::AUD_ConverterReader(AUD_Reference<AUD_IReader> reader,
                                                                                 AUD_DeviceSpecs specs) :
                AUD_EffectReader(reader)
 {
index a7a425adc546912fa1d32dbbc03e230ab9a783ed..6f252b5f9f921cba328d89926a96de7bc2c99013 100644 (file)
@@ -67,7 +67,7 @@ public:
         * \param reader The reader to convert.
         * \param specs The target specification.
         */
-       AUD_ConverterReader(AUD_IReader* reader, AUD_DeviceSpecs specs);
+       AUD_ConverterReader(AUD_Reference<AUD_IReader> reader, AUD_DeviceSpecs specs);
 
        virtual AUD_Specs getSpecs() const;
        virtual void read(int & length, sample_t* & buffer);
index 20471d6e874efbf5b3a2a78a8f2952e45638f04c..24fea6527ba5962026aa49df8a85e062540c3006 100644 (file)
@@ -45,7 +45,7 @@ AUD_DefaultMixer::AUD_DefaultMixer(AUD_DeviceSpecs specs) :
 {
 }
 
-AUD_IReader* AUD_DefaultMixer::prepare(AUD_IReader* reader)
+AUD_Reference<AUD_IReader> AUD_DefaultMixer::prepare(AUD_Reference<AUD_IReader> reader)
 {
        // hacky for now, until a better channel mapper reader is available
        AUD_ChannelMapperFactory cmf(NULL, m_specs);
index a347141b5e0451c2b9f547adea6ea3e9f5561891..2600a6fc05d777775a792ee02c72c451d130f5b7 100644 (file)
@@ -53,7 +53,7 @@ public:
         * \param reader The reader to prepare.
         * \return The reader that should be used for playback.
         */
-       virtual AUD_IReader* prepare(AUD_IReader* reader);
+       virtual AUD_Reference<AUD_IReader> prepare(AUD_Reference<AUD_IReader> reader);
 };
 
 #endif //AUD_DEFAULTMIXER
index 1c8bb03bc92dcccd1871590194e5c7ac45ffaec1..2f02d4a55e159a26f81a36b632a216838ea60ec5 100644 (file)
@@ -54,20 +54,20 @@ AUD_FileFactory::AUD_FileFactory(std::string filename) :
 AUD_FileFactory::AUD_FileFactory(const data_t* buffer, int size) :
        m_buffer(new AUD_Buffer(size))
 {
-       memcpy(m_buffer.get()->getBuffer(), buffer, size);
+       memcpy(m_buffer->getBuffer(), buffer, size);
 }
 
 static const char* read_error = "AUD_FileFactory: File couldn't be read.";
 
-AUD_IReader* AUD_FileFactory::createReader() const
+AUD_Reference<AUD_IReader> AUD_FileFactory::createReader() const
 {
 #ifdef WITH_SNDFILE
        try
        {
-               if(m_buffer.get())
-                       return new AUD_SndFileReader(m_buffer);
-               else
+               if(m_buffer.isNull())
                        return new AUD_SndFileReader(m_filename);
+               else
+                       return new AUD_SndFileReader(m_buffer);
        }
        catch(AUD_Exception&) {}
 #endif
@@ -75,10 +75,10 @@ AUD_IReader* AUD_FileFactory::createReader() const
 #ifdef WITH_FFMPEG
        try
        {
-               if(m_buffer.get())
-                       return new AUD_FFMPEGReader(m_buffer);
-               else
+               if(m_buffer.isNull())
                        return new AUD_FFMPEGReader(m_filename);
+               else
+                       return new AUD_FFMPEGReader(m_buffer);
        }
        catch(AUD_Exception&) {}
 #endif
index a2ab94ae14844522d8fe97873479872fc4cabfdb..c63e50b3b0dda0fec7e5451c5ad414c0e12d682d 100644 (file)
@@ -72,7 +72,7 @@ public:
         */
        AUD_FileFactory(const data_t* buffer, int size);
 
-       virtual AUD_IReader* createReader() const;
+       virtual AUD_Reference<AUD_IReader> createReader() const;
 };
 
 #endif //AUD_FILEFACTORY
index 4856b913b380304248d007459adf9c152093b233..88c9aa5e8d9e445f0dfb4b0738ca3230a9578a81 100644 (file)
@@ -33,6 +33,7 @@
 #define AUD_IDEVICE
 
 #include "AUD_Space.h"
+#include "AUD_Reference.h"
 class AUD_IFactory;
 class AUD_IReader;
 
@@ -74,7 +75,7 @@ public:
         * \exception AUD_Exception Thrown if there's an unexpected (from the
         *            device side) error during creation of the reader.
         */
-       virtual AUD_Handle* play(AUD_IReader* reader, bool keep = false)=0;
+       virtual AUD_Handle* play(AUD_Reference<AUD_IReader> reader, bool keep = false)=0;
 
        /**
         * Plays a sound source.
@@ -86,7 +87,7 @@ public:
         * \exception AUD_Exception Thrown if there's an unexpected (from the
         *            device side) error during creation of the reader.
         */
-       virtual AUD_Handle* play(AUD_IFactory* factory, bool keep = false)=0;
+       virtual AUD_Handle* play(AUD_Reference<AUD_IFactory> factory, bool keep = false)=0;
 
        /**
         * Pauses a played back sound.
index 40a61279a55c5933c83c0f160431ebdd8e5c2977..48f2802f8710f920dd250ea9ed603922786bb3f3 100644 (file)
@@ -33,6 +33,7 @@
 #define AUD_IFACTORY
 
 #include "AUD_Space.h"
+#include "AUD_Reference.h"
 class AUD_IReader;
 
 /**
@@ -55,7 +56,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() const=0;
+       virtual AUD_Reference<AUD_IReader> createReader() const=0;
 };
 
 #endif //AUD_IFACTORY
index a90dc5cb86052ff6d4493468055b0bc458a7e306..f7ac9e1e83e32221a0ea2f82cd20c7db2ca4127f 100644 (file)
 #include "AUD_LinearResampleFactory.h"
 #include "AUD_LinearResampleReader.h"
 
-AUD_LinearResampleFactory::AUD_LinearResampleFactory(AUD_IFactory* factory,
+AUD_LinearResampleFactory::AUD_LinearResampleFactory(AUD_Reference<AUD_IFactory> factory,
                                                                                                         AUD_DeviceSpecs specs) :
                AUD_ResampleFactory(factory, specs)
 {
 }
 
-AUD_IReader* AUD_LinearResampleFactory::createReader() const
+AUD_Reference<AUD_IReader> AUD_LinearResampleFactory::createReader() const
 {
-       AUD_IReader* reader = getReader();
+       AUD_Reference<AUD_IReader> reader = getReader();
 
        if(reader->getSpecs().rate != m_specs.rate)
                reader = new AUD_LinearResampleReader(reader, m_specs.specs);
index 678aa0b80cb06a5a84cc2ce1b48d34cbe5cbfdc2..6a593b11f284a9ed23fcd34232e737fc98c37a36 100644 (file)
@@ -45,9 +45,9 @@ private:
        AUD_LinearResampleFactory& operator=(const AUD_LinearResampleFactory&);
 
 public:
-       AUD_LinearResampleFactory(AUD_IFactory* factory, AUD_DeviceSpecs specs);
+       AUD_LinearResampleFactory(AUD_Reference<AUD_IFactory> factory, AUD_DeviceSpecs specs);
 
-       virtual AUD_IReader* createReader() const;
+       virtual AUD_Reference<AUD_IReader> createReader() const;
 };
 
 #endif //AUD_LINEARRESAMPLEFACTORY
index 05fb39b2cca5c1a817f0e8051b495e2a5ed9838d..6217826eeec942d886c293988338b831f06df4c5 100644 (file)
@@ -36,7 +36,7 @@
 
 #define CC channels + channel
 
-AUD_LinearResampleReader::AUD_LinearResampleReader(AUD_IReader* reader,
+AUD_LinearResampleReader::AUD_LinearResampleReader(AUD_Reference<AUD_IReader> reader,
                                                                                                   AUD_Specs specs) :
        AUD_EffectReader(reader),
        m_sspecs(reader->getSpecs()),
index 419c96be2faef550b2fe6ade14186d4e608f6888..fdf7858f97f7b43e852cbc99f5e89ca06b8a6df9 100644 (file)
@@ -86,7 +86,7 @@ public:
         * \param reader The reader to mix.
         * \param specs The target specification.
         */
-       AUD_LinearResampleReader(AUD_IReader* reader, AUD_Specs specs);
+       AUD_LinearResampleReader(AUD_Reference<AUD_IReader> reader, AUD_Specs specs);
 
        virtual void seek(int position);
        virtual int getLength() const;
index 277d5bfe2bdc33e8785051dad93270f725358ea6..d8c4dde26856e5f57f5bc7b2d79bd3d155a0e3af 100644 (file)
@@ -34,6 +34,7 @@
 
 #include "AUD_ConverterFunctions.h"
 #include "AUD_Buffer.h"
+#include "AUD_Reference.h"
 class AUD_IReader;
 #include <list>
 
@@ -94,7 +95,7 @@ public:
         * \param reader The reader to prepare.
         * \return The reader that should be used for playback.
         */
-       virtual AUD_IReader* prepare(AUD_IReader* reader)=0;
+       virtual AUD_Reference<AUD_IReader> prepare(AUD_Reference<AUD_IReader> reader)=0;
 
        /**
         * Adds a buffer for superposition.
index e65b149b94c28b3ac22bf7e6f9cad691e255c15c..c3bf6b4fa991355be9c62187adf47b4dd558933e 100644 (file)
 #include "AUD_MixerFactory.h"
 #include "AUD_IReader.h"
 
-AUD_IReader* AUD_MixerFactory::getReader() const
+AUD_Reference<AUD_IReader> AUD_MixerFactory::getReader() const
 {
        return m_factory->createReader();
 }
 
-AUD_MixerFactory::AUD_MixerFactory(AUD_IFactory* factory,
+AUD_MixerFactory::AUD_MixerFactory(AUD_Reference<AUD_IFactory> factory,
                                                                   AUD_DeviceSpecs specs) :
        m_specs(specs), m_factory(factory)
 {
@@ -48,7 +48,7 @@ AUD_DeviceSpecs AUD_MixerFactory::getSpecs() const
        return m_specs;
 }
 
-AUD_IFactory* AUD_MixerFactory::getFactory() const
+AUD_Reference<AUD_IFactory> AUD_MixerFactory::getFactory() const
 {
        return m_factory;
 }
index 2adabbd13ca253429278edb9565543870e81e35e..27c703b18988e5b6727fae195b5931c060746fc6 100644 (file)
@@ -48,7 +48,7 @@ protected:
        /**
         * If there is no reader it is created out of this factory.
         */
-       AUD_IFactory* m_factory;
+       AUD_Reference<AUD_IFactory> m_factory;
 
        /**
         * Returns the reader created out of the factory.
@@ -56,7 +56,7 @@ protected:
         * classes.
         * \return The reader to mix.
         */
-       AUD_IReader* getReader() const;
+       AUD_Reference<AUD_IReader> getReader() const;
 
 public:
        /**
@@ -64,7 +64,7 @@ public:
         * \param factory The factory to create the readers to mix out of.
         * \param specs The target specification.
         */
-       AUD_MixerFactory(AUD_IFactory* factory, AUD_DeviceSpecs specs);
+       AUD_MixerFactory(AUD_Reference<AUD_IFactory> factory, AUD_DeviceSpecs specs);
 
        /**
         * Returns the target specification for resampling.
@@ -75,7 +75,7 @@ public:
         * Returns the saved factory.
         * \return The factory.
         */
-       AUD_IFactory* getFactory() const;
+       AUD_Reference<AUD_IFactory> getFactory() const;
 };
 
 #endif //AUD_MIXERFACTORY
index ab824799d88edc7011d5f5e940e319c32b078194..09fc483597850af56aa1bf8adeec9d23cacdc2b8 100644 (file)
@@ -48,12 +48,12 @@ AUD_DeviceSpecs AUD_NULLDevice::getSpecs() const
        return specs;
 }
 
-AUD_Handle* AUD_NULLDevice::play(AUD_IReader* reader, bool keep)
+AUD_Handle* AUD_NULLDevice::play(AUD_Reference<AUD_IReader> reader, bool keep)
 {
        return 0;
 }
 
-AUD_Handle* AUD_NULLDevice::play(AUD_IFactory* factory, bool keep)
+AUD_Handle* AUD_NULLDevice::play(AUD_Reference<AUD_IFactory> factory, bool keep)
 {
        return 0;
 }
index f700bea477b405d78bbbce43dff0e4092c576bc4..6a10267bbe03766b4dcbaaff3abbedbe4e31ee67 100644 (file)
@@ -32,6 +32,7 @@
 #ifndef AUD_NULLDEVICE
 #define AUD_NULLDEVICE
 
+#include "AUD_IReader.h"
 #include "AUD_IDevice.h"
 
 /**
@@ -46,8 +47,8 @@ public:
        AUD_NULLDevice();
 
        virtual AUD_DeviceSpecs getSpecs() const;
-       virtual AUD_Handle* play(AUD_IReader* reader, bool keep = false);
-       virtual AUD_Handle* play(AUD_IFactory* factory, bool keep = false);
+       virtual AUD_Handle* play(AUD_Reference<AUD_IReader> reader, bool keep = false);
+       virtual AUD_Handle* play(AUD_Reference<AUD_IFactory> factory, bool keep = false);
        virtual bool pause(AUD_Handle* handle);
        virtual bool resume(AUD_Handle* handle);
        virtual bool stop(AUD_Handle* handle);
index 3232ca3b609644fa66fdb2984e6ac5e7b71feef2..22abb29bdbbeea1ec058ec19d0cebc33488dbcdc 100644 (file)
@@ -75,10 +75,7 @@ public:
                (*m_refcount)--;
                if(*m_refcount == 0)
                {
-                       if(m_reference)
-                       {
-                               delete m_reference;
-                       }
+                       delete m_reference;
                        delete m_refcount;
                }
        }
@@ -95,10 +92,7 @@ public:
                (*m_refcount)--;
                if(*m_refcount == 0)
                {
-                       if(m_reference)
-                       {
-                               delete m_reference;
-                       }
+                       delete m_reference;
                        delete m_refcount;
                }
 
@@ -109,6 +103,14 @@ public:
                return *this;
        }
 
+       /**
+        * Returns whether the reference is NULL.
+        */
+       bool isNull() const
+       {
+               return m_reference == 0;
+       }
+
        /**
         * Returns the reference.
         */
@@ -116,6 +118,56 @@ public:
        {
                return m_reference;
        }
+
+       /**
+        * Returns the reference.
+        */
+       T& operator*() const
+       {
+               return *m_reference;
+       }
+
+       /**
+        * Returns the reference.
+        */
+       T* operator->() const
+       {
+               return m_reference;
+       }
+
+       template <class U>
+       explicit AUD_Reference(U* reference, int* refcount)
+       {
+               m_reference = dynamic_cast<T*>(reference);
+               if(m_reference)
+               {
+                       m_refcount = refcount;
+                       (*m_refcount)++;
+               }
+               else
+               {
+                       m_refcount = new int;
+                       *m_refcount = 1;
+               }
+       }
+
+       template <class U>
+       AUD_Reference<U> convert()
+       {
+               return AUD_Reference<U>(m_reference, m_refcount);
+       }
 };
 
+template<class T, class U>
+bool operator==(const AUD_Reference<T>& a, const AUD_Reference<U>& b)
+{
+       return a.get() == b.get();
+}
+
+template<class T, class U>
+bool operator!=(const AUD_Reference<T>& a, const AUD_Reference<U>& b)
+{
+       return a.get() == b.get();
+}
+
 #endif // AUD_REFERENCE
index f49dd94fe111c62c140717766538fd901c867b80..ee0af900b04b8dbd791211e50f30171750ac7246 100644 (file)
@@ -32,7 +32,7 @@
 #include "AUD_SequencerFactory.h"
 #include "AUD_SequencerReader.h"
 
-typedef std::list<AUD_SequencerReader*>::iterator AUD_ReaderIterator;
+typedef std::list<AUD_Reference<AUD_SequencerReader> >::iterator AUD_ReaderIterator;
 
 AUD_SequencerFactory::AUD_SequencerFactory(AUD_Specs specs, bool muted,
                                                                                   void* data,
@@ -46,22 +46,11 @@ AUD_SequencerFactory::AUD_SequencerFactory(AUD_Specs specs, bool muted,
 
 AUD_SequencerFactory::~AUD_SequencerFactory()
 {
-       AUD_SequencerReader* reader;
-       AUD_SequencerEntry* entry;
-
-       while(!m_readers.empty())
-       {
-               reader = m_readers.front();
-               m_readers.pop_front();
-               reader->destroy();
-       }
-
-       while(!m_entries.empty())
-       {
-               entry = m_entries.front();
-               m_entries.pop_front();
-               delete entry;
-       }
+}
+
+void AUD_SequencerFactory::setThis(AUD_Reference<AUD_SequencerFactory>* self)
+{
+       m_this = self;
 }
 
 void AUD_SequencerFactory::mute(bool muted)
@@ -74,19 +63,19 @@ bool AUD_SequencerFactory::getMute() const
        return m_muted;
 }
 
-AUD_IReader* AUD_SequencerFactory::newReader()
+AUD_Reference<AUD_IReader> AUD_SequencerFactory::newReader()
 {
-       AUD_SequencerReader* reader = new AUD_SequencerReader(this, m_entries,
+       AUD_Reference<AUD_SequencerReader> reader = new AUD_SequencerReader(*m_this, m_entries,
                                                                                                                  m_specs, m_data,
                                                                                                                  m_volume);
        m_readers.push_front(reader);
 
-       return reader;
+       return reader.convert<AUD_IReader>();
 }
 
-AUD_SequencerEntry* AUD_SequencerFactory::add(AUD_IFactory** sound, float begin, float end, float skip, void* data)
+AUD_Reference<AUD_SequencerEntry> AUD_SequencerFactory::add(AUD_Reference<AUD_IFactory>** sound, float begin, float end, float skip, void* data)
 {
-       AUD_SequencerEntry* entry = new AUD_SequencerEntry;
+       AUD_Reference<AUD_SequencerEntry> entry = new AUD_SequencerEntry;
        entry->sound = sound;
        entry->begin = begin;
        entry->skip = skip;
@@ -102,34 +91,32 @@ AUD_SequencerEntry* AUD_SequencerFactory::add(AUD_IFactory** sound, float begin,
        return entry;
 }
 
-void AUD_SequencerFactory::remove(AUD_SequencerEntry* entry)
+void AUD_SequencerFactory::remove(AUD_Reference<AUD_SequencerEntry> entry)
 {
        for(AUD_ReaderIterator i = m_readers.begin(); i != m_readers.end(); i++)
                (*i)->remove(entry);
 
        m_entries.remove(entry);
-
-       delete entry;
 }
 
-void AUD_SequencerFactory::move(AUD_SequencerEntry* entry, float begin, float end, float skip)
+void AUD_SequencerFactory::move(AUD_Reference<AUD_SequencerEntry> entry, float begin, float end, float skip)
 {
        entry->begin = begin;
        entry->skip = skip;
        entry->end = end;
 }
 
-void AUD_SequencerFactory::mute(AUD_SequencerEntry* entry, bool mute)
+void AUD_SequencerFactory::mute(AUD_Reference<AUD_SequencerEntry> entry, bool mute)
 {
        entry->muted = mute;
 }
 
-AUD_IReader* AUD_SequencerFactory::createReader() const
+AUD_Reference<AUD_IReader> AUD_SequencerFactory::createReader() const
 {
        return const_cast<AUD_SequencerFactory*>(this)->newReader();
 }
 
-void AUD_SequencerFactory::removeReader(AUD_SequencerReader* reader)
+void AUD_SequencerFactory::removeReader(AUD_Reference<AUD_SequencerReader> reader)
 {
        m_readers.remove(reader);
 }
index 8f3466f75ce6830f23df015680ba1f9e58354ece..b03932976223c47a47a8bb47626643ac54c25473 100644 (file)
@@ -40,7 +40,7 @@ typedef float (*AUD_volumeFunction)(void*, void*, float);
 
 struct AUD_SequencerEntry
 {
-       AUD_IFactory** sound;
+       AUD_Reference<AUD_IFactory>** sound;
        float begin;
        float end;
        float skip;
@@ -61,13 +61,14 @@ private:
         */
        AUD_Specs m_specs;
 
-       std::list<AUD_SequencerEntry*> m_entries;
-       std::list<AUD_SequencerReader*> m_readers;
+       std::list<AUD_Reference<AUD_SequencerEntry> > m_entries;
+       std::list<AUD_Reference<AUD_SequencerReader> > m_readers;
        bool m_muted;
        void* m_data;
        AUD_volumeFunction m_volume;
+       AUD_Reference<AUD_SequencerFactory>* m_this;
 
-       AUD_IReader* newReader();
+       AUD_Reference<AUD_IReader> newReader();
 
        // hide copy constructor and operator=
        AUD_SequencerFactory(const AUD_SequencerFactory&);
@@ -77,16 +78,18 @@ public:
        AUD_SequencerFactory(AUD_Specs specs, bool muted, void* data, AUD_volumeFunction volume);
        ~AUD_SequencerFactory();
 
+       void setThis(AUD_Reference<AUD_SequencerFactory>* self);
+
        void mute(bool muted);
        bool getMute() const;
-       AUD_SequencerEntry* add(AUD_IFactory** sound, float begin, float end, float skip, void* data);
-       void remove(AUD_SequencerEntry* entry);
-       void move(AUD_SequencerEntry* entry, float begin, float end, float skip);
-       void mute(AUD_SequencerEntry* entry, bool mute);
+       AUD_Reference<AUD_SequencerEntry> add(AUD_Reference<AUD_IFactory>** sound, float begin, float end, float skip, void* data);
+       void remove(AUD_Reference<AUD_SequencerEntry> entry);
+       void move(AUD_Reference<AUD_SequencerEntry> entry, float begin, float end, float skip);
+       void mute(AUD_Reference<AUD_SequencerEntry> entry, bool mute);
 
-       virtual AUD_IReader* createReader() const;
+       virtual AUD_Reference<AUD_IReader> createReader() const;
 
-       void removeReader(AUD_SequencerReader* reader);
+       void removeReader(AUD_Reference<AUD_SequencerReader> reader);
 };
 
 #endif //AUD_SEQUENCERFACTORY
index 95e0dca63238e0efcbfda2481442e396f82c6c70..b7cbdda544e980832f6de804998e74d73f6fb220 100644 (file)
 
 #include <math.h>
 
-typedef std::list<AUD_SequencerStrip*>::iterator AUD_StripIterator;
-typedef std::list<AUD_SequencerEntry*>::iterator AUD_EntryIterator;
+typedef std::list<AUD_Reference<AUD_SequencerStrip> >::iterator AUD_StripIterator;
+typedef std::list<AUD_Reference<AUD_SequencerEntry> >::iterator AUD_EntryIterator;
 
-AUD_SequencerReader::AUD_SequencerReader(AUD_SequencerFactory* factory,
-                       std::list<AUD_SequencerEntry*> &entries, AUD_Specs specs,
-                       void* data, AUD_volumeFunction volume)
+AUD_SequencerReader::AUD_SequencerReader(AUD_Reference<AUD_SequencerFactory> factory,
+                       std::list<AUD_Reference<AUD_SequencerEntry> > &entries, AUD_Specs specs,
+                       void* data, AUD_volumeFunction volume) :
+       m_position(0), m_factory(factory), m_data(data), m_volume(volume)
 {
        AUD_DeviceSpecs dspecs;
        dspecs.specs = specs;
        dspecs.format = AUD_FORMAT_FLOAT32;
 
        m_mixer = new AUD_DefaultMixer(dspecs);
-       m_factory = factory;
-       m_data = data;
-       m_volume = volume;
 
-       AUD_SequencerStrip* strip;
+       AUD_Reference<AUD_SequencerStrip> strip;
 
        for(AUD_EntryIterator i = entries.begin(); i != entries.end(); i++)
        {
@@ -58,84 +56,33 @@ AUD_SequencerReader::AUD_SequencerReader(AUD_SequencerFactory* factory,
                strip->entry = *i;
                strip->old_sound = NULL;
 
-               if(strip->old_sound)
-                       strip->reader = m_mixer->prepare(strip->old_sound->createReader());
-               else
-                       strip->reader = NULL;
-
                m_strips.push_front(strip);
        }
-
-       m_position = 0;
 }
 
 AUD_SequencerReader::~AUD_SequencerReader()
 {
-       if(m_factory != NULL)
-               m_factory->removeReader(this);
-
-       AUD_SequencerStrip* strip;
-
-       while(!m_strips.empty())
-       {
-               strip = m_strips.front();
-               m_strips.pop_front();
-               if(strip->reader)
-               {
-                       delete strip->reader;
-               }
-               delete strip;
-       }
-
-       delete m_mixer;
-}
-
-void AUD_SequencerReader::destroy()
-{
-       m_factory = NULL;
-       AUD_SequencerStrip* strip;
-
-       while(!m_strips.empty())
-       {
-               strip = m_strips.front();
-               m_strips.pop_front();
-               delete strip;
-       }
+       m_factory->removeReader(this);
 }
 
-void AUD_SequencerReader::add(AUD_SequencerEntry* entry)
+void AUD_SequencerReader::add(AUD_Reference<AUD_SequencerEntry> entry)
 {
-       AUD_SequencerStrip* strip = new AUD_SequencerStrip;
+       AUD_Reference<AUD_SequencerStrip> strip = new AUD_SequencerStrip;
        strip->entry = entry;
 
-       if(*strip->entry->sound)
-       {
-               strip->old_sound = *strip->entry->sound;
-               strip->reader = m_mixer->prepare(strip->old_sound->createReader());
-       }
-       else
-       {
-               strip->reader = NULL;
-               strip->old_sound = NULL;
-       }
        m_strips.push_front(strip);
 }
 
-void AUD_SequencerReader::remove(AUD_SequencerEntry* entry)
+void AUD_SequencerReader::remove(AUD_Reference<AUD_SequencerEntry> entry)
 {
-       AUD_SequencerStrip* strip;
+       AUD_Reference<AUD_SequencerStrip> strip;
        for(AUD_StripIterator i = m_strips.begin(); i != m_strips.end(); i++)
        {
                strip = *i;
                if(strip->entry == entry)
                {
                        i++;
-                       if(strip->reader)
-                       {
-                               delete strip->reader;
-                       }
                        m_strips.remove(strip);
-                       delete strip;
                        return;
                }
        }
@@ -175,7 +122,7 @@ void AUD_SequencerReader::read(int & length, sample_t* & buffer)
        int size = length * samplesize;
 
        int start, end, current, skip, len;
-       AUD_SequencerStrip* strip;
+       AUD_Reference<AUD_SequencerStrip> strip;
        sample_t* buf;
 
        if(m_buffer.getSize() < size)
@@ -192,14 +139,12 @@ void AUD_SequencerReader::read(int & length, sample_t* & buffer)
                                if(strip->old_sound != *strip->entry->sound)
                                {
                                        strip->old_sound = *strip->entry->sound;
-                                       if(strip->reader)
-                                               delete strip->reader;
 
                                        if(strip->old_sound)
                                        {
                                                try
                                                {
-                                                       strip->reader = m_mixer->prepare(strip->old_sound->createReader());
+                                                       strip->reader = m_mixer->prepare((*strip->old_sound)->createReader());
                                                }
                                                catch(AUD_Exception)
                                                {
@@ -210,7 +155,7 @@ void AUD_SequencerReader::read(int & length, sample_t* & buffer)
                                                strip->reader = NULL;
                                }
 
-                               if(strip->reader)
+                               if(!strip->reader.isNull())
                                {
                                        end = floor(strip->entry->end * rate);
                                        if(m_position < end)
index 53baf521acc8e6a801c98132ec1e9624bb7003f3..2efb94aa1fbafcd8b4dd593c529d047a6b5545bc 100644 (file)
@@ -39,9 +39,9 @@ class AUD_Mixer;
 
 struct AUD_SequencerStrip
 {
-       AUD_IFactory* old_sound;
-       AUD_IReader* reader;
-       AUD_SequencerEntry* entry;
+       AUD_Reference<AUD_IReader> reader;
+       AUD_Reference<AUD_SequencerEntry> entry;
+       AUD_Reference<AUD_IFactory>* old_sound;
 };
 
 /**
@@ -63,14 +63,14 @@ private:
        /**
         * The target specification.
         */
-       AUD_Mixer* m_mixer;
+       AUD_Reference<AUD_Mixer> m_mixer;
 
        /**
         * Saves the SequencerFactory the reader belongs to.
         */
-       AUD_SequencerFactory* m_factory;
+       AUD_Reference<AUD_SequencerFactory> m_factory;
 
-       std::list<AUD_SequencerStrip*> m_strips;
+       std::list<AUD_Reference<AUD_SequencerStrip> > m_strips;
 
        void* m_data;
        AUD_volumeFunction m_volume;
@@ -85,17 +85,15 @@ public:
         * \param reader The reader to mix.
         * \param specs The target specification.
         */
-       AUD_SequencerReader(AUD_SequencerFactory* factory, std::list<AUD_SequencerEntry*> &entries, const AUD_Specs specs, void* data, AUD_volumeFunction volume);
+       AUD_SequencerReader(AUD_Reference<AUD_SequencerFactory> factory, std::list<AUD_Reference<AUD_SequencerEntry> > &entries, const AUD_Specs specs, void* data, AUD_volumeFunction volume);
 
        /**
         * Destroys the reader.
         */
        ~AUD_SequencerReader();
 
-       void destroy();
-
-       void add(AUD_SequencerEntry* entry);
-       void remove(AUD_SequencerEntry* entry);
+       void add(AUD_Reference<AUD_SequencerEntry> entry);
+       void remove(AUD_Reference<AUD_SequencerEntry> entry);
 
        virtual bool isSeekable() const;
        virtual void seek(int position);
index dc3f0626591341ef4ddc0617cf52355dc2ae932c..f1eae1889a232a3ea225b14a6e6fdea0cd35ff28 100644 (file)
@@ -37,7 +37,7 @@ AUD_SilenceFactory::AUD_SilenceFactory()
 {
 }
 
-AUD_IReader* AUD_SilenceFactory::createReader() const
+AUD_Reference<AUD_IReader> AUD_SilenceFactory::createReader() const
 {
        return new AUD_SilenceReader();
 }
index fb6afc341895e6f9393c8e3e6a265e5b12c0dddc..0920c1267ab8c37c03364c051d18938eb37afa49 100644 (file)
@@ -50,7 +50,7 @@ public:
         */
        AUD_SilenceFactory();
 
-       virtual AUD_IReader* createReader() const;
+       virtual AUD_Reference<AUD_IReader> createReader() const;
 };
 
 #endif //AUD_SILENCEFACTORY
index 9ea7a031b161f12eb8693e6a92ae45da99e57200..8276856b9e205901b25a05b9ac88ebb2237809d8 100644 (file)
@@ -44,7 +44,7 @@ float AUD_SinusFactory::getFrequency() const
        return m_frequency;
 }
 
-AUD_IReader* AUD_SinusFactory::createReader() const
+AUD_Reference<AUD_IReader> AUD_SinusFactory::createReader() const
 {
        return new AUD_SinusReader(m_frequency, m_sampleRate);
 }
index 6d8b355784bfdc437e5de3faa2f51f9a51c7ead0..a440d7b7535eb17c569d997b488c1a49a18031ab 100644 (file)
@@ -68,7 +68,7 @@ public:
         */
        float getFrequency() const;
 
-       virtual AUD_IReader* createReader() const;
+       virtual AUD_Reference<AUD_IReader> createReader() const;
 };
 
 #endif //AUD_SINUSFACTORY
index b44b2f02d295aa0b1a84cdeb2a7cb5400ffb3b91..82bb584158014c29ab84a349601b9486ffb8f6f3 100644 (file)
@@ -41,7 +41,7 @@
 struct AUD_SoftwareHandle : AUD_Handle
 {
        /// The reader source.
-       AUD_IReader* reader;
+       AUD_Reference<AUD_IReader> reader;
 
        /// Whether to keep the source if end of it is reached.
        bool keep;
@@ -81,8 +81,6 @@ void AUD_SoftwareDevice::destroy()
        if(m_playback)
                playing(m_playback = false);
 
-       delete m_mixer;
-
        AUD_SoftwareHandle* handle;
 
        // delete all playing sounds
@@ -90,7 +88,6 @@ void AUD_SoftwareDevice::destroy()
        {
                handle = m_playingSounds.front();
                m_playingSounds.pop_front();
-               delete handle->reader;
                delete handle;
        }
 
@@ -99,7 +96,6 @@ void AUD_SoftwareDevice::destroy()
        {
                handle = m_pausedSounds.front();
                m_pausedSounds.pop_front();
-               delete handle->reader;
                delete handle;
        }
 
@@ -213,11 +209,11 @@ AUD_DeviceSpecs AUD_SoftwareDevice::getSpecs() const
        return m_specs;
 }
 
-AUD_Handle* AUD_SoftwareDevice::play(AUD_IReader* reader, bool keep)
+AUD_Handle* AUD_SoftwareDevice::play(AUD_Reference<AUD_IReader> reader, bool keep)
 {
        // prepare the reader
        reader = m_mixer->prepare(reader);
-       if(reader == NULL)
+       if(reader.isNull())
                return NULL;
 
        // play sound
@@ -239,7 +235,7 @@ AUD_Handle* AUD_SoftwareDevice::play(AUD_IReader* reader, bool keep)
        return sound;
 }
 
-AUD_Handle* AUD_SoftwareDevice::play(AUD_IFactory* factory, bool keep)
+AUD_Handle* AUD_SoftwareDevice::play(AUD_Reference<AUD_IFactory> factory, bool keep)
 {
        return play(factory->createReader(), keep);
 }
@@ -307,7 +303,6 @@ bool AUD_SoftwareDevice::stop(AUD_Handle* handle)
        {
                if(*i == handle)
                {
-                       delete (*i)->reader;
                        delete *i;
                        m_playingSounds.erase(i);
                        if(m_playingSounds.empty())
@@ -323,7 +318,6 @@ bool AUD_SoftwareDevice::stop(AUD_Handle* handle)
                {
                        if(*i == handle)
                        {
-                               delete (*i)->reader;
                                delete *i;
                                m_pausedSounds.erase(i);
                                result = true;
@@ -376,7 +370,7 @@ bool AUD_SoftwareDevice::seek(AUD_Handle* handle, float position)
 
        if(isValid(handle))
        {
-               AUD_IReader* reader = ((AUD_SoftwareHandle*)handle)->reader;
+               AUD_Reference<AUD_IReader> reader = ((AUD_SoftwareHandle*)handle)->reader;
                reader->seek((int)(position * reader->getSpecs().rate));
                result = true;
        }
index 1f6a5ead6e0e6281e83c0afc6562820cb9ebf42a..6cbc6e3ddc66a057754662de9b8fc6a7bb3c05b5 100644 (file)
@@ -33,8 +33,8 @@
 #define AUD_SOFTWAREDEVICE
 
 #include "AUD_IDevice.h"
+#include "AUD_Mixer.h"
 struct AUD_SoftwareHandle;
-class AUD_Mixer;
 class AUD_Buffer;
 
 #include <list>
@@ -59,7 +59,7 @@ protected:
        /**
         * The mixer.
         */
-       AUD_Mixer* m_mixer;
+       AUD_Reference<AUD_Mixer> m_mixer;
 
        /**
         * Initializes member variables.
@@ -119,8 +119,8 @@ private:
 
 public:
        virtual AUD_DeviceSpecs getSpecs() const;
-       virtual AUD_Handle* play(AUD_IReader* reader, bool keep = false);
-       virtual AUD_Handle* play(AUD_IFactory* factory, bool keep = false);
+       virtual AUD_Handle* play(AUD_Reference<AUD_IReader> reader, bool keep = false);
+       virtual AUD_Handle* play(AUD_Reference<AUD_IFactory> factory, bool keep = false);
        virtual bool pause(AUD_Handle* handle);
        virtual bool resume(AUD_Handle* handle);
        virtual bool stop(AUD_Handle* handle);
index c25442b6f26a92e479a4a63456792c331c6200ee..5c4e024917be1a46141ea822249777c6d42ea44b 100644 (file)
 
 #include <cstring>
 
-AUD_StreamBufferFactory::AUD_StreamBufferFactory(AUD_IFactory* factory) :
+AUD_StreamBufferFactory::AUD_StreamBufferFactory(AUD_Reference<AUD_IFactory> factory) :
        m_buffer(new AUD_Buffer())
 {
-       AUD_IReader* reader = factory->createReader();
+       AUD_Reference<AUD_IReader> reader = factory->createReader();
 
        m_specs = reader->getSpecs();
 
@@ -56,26 +56,25 @@ AUD_StreamBufferFactory::AUD_StreamBufferFactory(AUD_IFactory* factory) :
                size += m_specs.rate;
 
        // as long as we fill our buffer to the end
-       while(index == m_buffer.get()->getSize() / sample_size)
+       while(index == m_buffer->getSize() / sample_size)
        {
                // increase
-               m_buffer.get()->resize(size*sample_size, true);
+               m_buffer->resize(size*sample_size, true);
 
                // read more
                length = size-index;
                reader->read(length, buffer);
-               memcpy(m_buffer.get()->getBuffer() + index * m_specs.channels,
+               memcpy(m_buffer->getBuffer() + index * m_specs.channels,
                           buffer,
                           length * sample_size);
                size += AUD_BUFFER_RESIZE_BYTES / sample_size;
                index += length;
        }
 
-       m_buffer.get()->resize(index * sample_size, true);
-       delete reader;
+       m_buffer->resize(index * sample_size, true);
 }
 
-AUD_IReader* AUD_StreamBufferFactory::createReader() const
+AUD_Reference<AUD_IReader> AUD_StreamBufferFactory::createReader() const
 {
        return new AUD_BufferReader(m_buffer, m_specs);
 }
index b6a44d9574422d302e0b94296bb1405b5879eea4..fc5f103d99bdfa44e09cd063e844237170f6d573 100644 (file)
@@ -64,9 +64,9 @@ public:
         * \param factory The factory that creates the reader for buffering.
         * \exception AUD_Exception Thrown if the reader cannot be created.
         */
-       AUD_StreamBufferFactory(AUD_IFactory* factory);
+       AUD_StreamBufferFactory(AUD_Reference<AUD_IFactory> factory);
 
-       virtual AUD_IReader* createReader() const;
+       virtual AUD_Reference<AUD_IReader> createReader() const;
 };
 
 #endif //AUD_STREAMBUFFERFACTORY
index 2d1d29e50f50893103cf392a8cf39290f74eb78f..7ab3308f01b3c7213d68fa3da511ad131af92a7a 100644 (file)
@@ -43,13 +43,13 @@ AUD_SndFileFactory::AUD_SndFileFactory(std::string filename) :
 AUD_SndFileFactory::AUD_SndFileFactory(const data_t* buffer, int size) :
        m_buffer(new AUD_Buffer(size))
 {
-       memcpy(m_buffer.get()->getBuffer(), buffer, size);
+       memcpy(m_buffer->getBuffer(), buffer, size);
 }
 
-AUD_IReader* AUD_SndFileFactory::createReader() const
+AUD_Reference<AUD_IReader> AUD_SndFileFactory::createReader() const
 {
-       if(m_buffer.get())
-               return new AUD_SndFileReader(m_buffer);
-       else
+       if(m_buffer.isNull())
                return new AUD_SndFileReader(m_filename);
+       else
+               return new AUD_SndFileReader(m_buffer);
 }
index 9c747e1df014abae7ef6c33ebf312fb411e9ebdc..3a1037e55870a073a485390ddb18889cf559c527 100644 (file)
@@ -72,7 +72,7 @@ public:
         */
        AUD_SndFileFactory(const data_t* buffer, int size);
 
-       virtual AUD_IReader* createReader() const;
+       virtual AUD_Reference<AUD_IReader> createReader() const;
 };
 
 #endif //AUD_SNDFILEFACTORY
index f226d2eee4dd7ea4b884149aa34ac93b45ff8a24..7b5fd7b0f4564bcdbe3d1ff365aa9a3e8fee420f 100644 (file)
@@ -36,7 +36,7 @@
 sf_count_t AUD_SndFileReader::vio_get_filelen(void *user_data)
 {
        AUD_SndFileReader* reader = (AUD_SndFileReader*)user_data;
-       return reader->m_membuffer.get()->getSize();
+       return reader->m_membuffer->getSize();
 }
 
 sf_count_t AUD_SndFileReader::vio_seek(sf_count_t offset, int whence,
@@ -53,7 +53,7 @@ sf_count_t AUD_SndFileReader::vio_seek(sf_count_t offset, int whence,
                reader->m_memoffset = reader->m_memoffset + offset;
                break;
        case SEEK_END:
-               reader->m_memoffset = reader->m_membuffer.get()->getSize() + offset;
+               reader->m_memoffset = reader->m_membuffer->getSize() + offset;
                break;
        }
 
@@ -65,10 +65,10 @@ sf_count_t AUD_SndFileReader::vio_read(void *ptr, sf_count_t count,
 {
        AUD_SndFileReader* reader = (AUD_SndFileReader*)user_data;
 
-       if(reader->m_memoffset + count > reader->m_membuffer.get()->getSize())
-               count = reader->m_membuffer.get()->getSize() - reader->m_memoffset;
+       if(reader->m_memoffset + count > reader->m_membuffer->getSize())
+               count = reader->m_membuffer->getSize() - reader->m_memoffset;
 
-       memcpy(ptr, ((data_t*)reader->m_membuffer.get()->getBuffer()) +
+       memcpy(ptr, ((data_t*)reader->m_membuffer->getBuffer()) +
                   reader->m_memoffset, count);
        reader->m_memoffset += count;