Merge with trunk r37677
authorJoerg Mueller <nexyon@gmail.com>
Mon, 20 Jun 2011 22:55:18 +0000 (22:55 +0000)
committerJoerg Mueller <nexyon@gmail.com>
Mon, 20 Jun 2011 22:55:18 +0000 (22:55 +0000)
221 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/ffmpeg/AUD_FFMPEGReader.h
intern/audaspace/intern/AUD_BufferReader.cpp
intern/audaspace/intern/AUD_BufferReader.h
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_ConverterFunctions.cpp
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_IReader.h
intern/audaspace/intern/AUD_LinearResampleFactory.cpp
intern/audaspace/intern/AUD_LinearResampleFactory.h
intern/audaspace/intern/AUD_LinearResampleReader.cpp
intern/audaspace/intern/AUD_LinearResampleReader.h
intern/audaspace/intern/AUD_Mixer.cpp
intern/audaspace/intern/AUD_Mixer.h
intern/audaspace/intern/AUD_MixerFactory.cpp
intern/audaspace/intern/AUD_MixerFactory.h
intern/audaspace/intern/AUD_NULLDevice.cpp
intern/audaspace/intern/AUD_NULLDevice.h
intern/audaspace/intern/AUD_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_SilenceReader.cpp
intern/audaspace/intern/AUD_SilenceReader.h
intern/audaspace/intern/AUD_SinusFactory.cpp
intern/audaspace/intern/AUD_SinusFactory.h
intern/audaspace/intern/AUD_SinusReader.cpp
intern/audaspace/intern/AUD_SinusReader.h
intern/audaspace/intern/AUD_SoftwareDevice.cpp
intern/audaspace/intern/AUD_SoftwareDevice.h
intern/audaspace/intern/AUD_StreamBufferFactory.cpp
intern/audaspace/intern/AUD_StreamBufferFactory.h
intern/audaspace/jack/AUD_JackDevice.cpp
intern/audaspace/sndfile/AUD_SndFileFactory.cpp
intern/audaspace/sndfile/AUD_SndFileFactory.h
intern/audaspace/sndfile/AUD_SndFileReader.cpp
intern/audaspace/sndfile/AUD_SndFileReader.h
release/scripts/modules/bpy_types.py
release/scripts/modules/mocap_tools.py [new file with mode: 0644]
release/scripts/modules/retarget.py [new file with mode: 0644]
release/scripts/startup/bl_operators/nla.py
release/scripts/startup/bl_operators/object.py
release/scripts/startup/bl_ui/properties_object_constraint.py
release/scripts/startup/bl_ui/properties_scene.py
release/scripts/startup/bl_ui/space_sequencer.py
release/scripts/startup/bl_ui/space_userpref.py
release/scripts/startup/bl_ui/space_view3d.py
source/blender/blenfont/BLF_api.h
source/blender/blenfont/intern/blf.c
source/blender/blenkernel/BKE_constraint.h
source/blender/blenkernel/BKE_sound.h
source/blender/blenkernel/intern/action.c
source/blender/blenkernel/intern/constraint.c
source/blender/blenkernel/intern/fcurve.c
source/blender/blenkernel/intern/fmodifier.c
source/blender/blenkernel/intern/seqeffects.c
source/blender/blenkernel/intern/sequencer.c
source/blender/blenkernel/intern/sound.c
source/blender/blenloader/intern/readfile.c
source/blender/blenloader/intern/writefile.c
source/blender/collada/AnimationExporter.cpp [new file with mode: 0644]
source/blender/collada/AnimationExporter.h [new file with mode: 0644]
source/blender/collada/AnimationImporter.cpp
source/blender/collada/AnimationImporter.h
source/blender/collada/ArmatureImporter.cpp
source/blender/collada/ArmatureImporter.h
source/blender/collada/CMakeLists.txt
source/blender/collada/DocumentExporter.cpp
source/blender/collada/DocumentImporter.cpp
source/blender/collada/SkinInfo.cpp
source/blender/editors/animation/anim_channels_edit.c
source/blender/editors/animation/anim_markers.c
source/blender/editors/animation/fmodifier_ui.c
source/blender/editors/animation/keyframes_general.c
source/blender/editors/animation/keyingsets.c
source/blender/editors/armature/poseobject.c
source/blender/editors/include/ED_markers.h
source/blender/editors/interface/interface_style.c
source/blender/editors/interface/resources.c
source/blender/editors/object/object_constraint.c
source/blender/editors/space_action/action_ops.c
source/blender/editors/space_graph/graph_buttons.c
source/blender/editors/space_graph/graph_edit.c
source/blender/editors/space_graph/graph_ops.c
source/blender/editors/space_logic/logic_window.c
source/blender/editors/space_nla/nla_ops.c
source/blender/editors/space_sequencer/sequencer_draw.c
source/blender/editors/space_sequencer/sequencer_edit.c
source/blender/editors/space_text/text_draw.c
source/blender/editors/space_view3d/drawarmature.c
source/blender/editors/transform/transform.c
source/blender/editors/transform/transform_conversions.c
source/blender/editors/transform/transform_ops.c
source/blender/makesdna/DNA_actuator_types.h
source/blender/makesdna/DNA_anim_types.h
source/blender/makesdna/DNA_armature_types.h
source/blender/makesdna/DNA_constraint_types.h
source/blender/makesdna/DNA_sequence_types.h
source/blender/makesdna/DNA_userdef_types.h
source/blender/makesrna/RNA_access.h
source/blender/makesrna/intern/rna_access.c
source/blender/makesrna/intern/rna_actuator.c
source/blender/makesrna/intern/rna_animation.c
source/blender/makesrna/intern/rna_armature.c
source/blender/makesrna/intern/rna_constraint.c
source/blender/makesrna/intern/rna_fcurve.c
source/blender/makesrna/intern/rna_sequencer.c
source/blender/makesrna/intern/rna_userdef.c
source/blender/windowmanager/intern/wm_files.c
source/gameengine/Converter/BL_ActionActuator.cpp
source/gameengine/Converter/BL_ActionActuator.h
source/gameengine/Converter/KX_BlenderScalarInterpolator.cpp
source/gameengine/Converter/KX_BlenderScalarInterpolator.h
source/gameengine/Converter/KX_ConvertActuators.cpp
source/gameengine/Converter/KX_IpoConvert.cpp
source/gameengine/Converter/KX_IpoConvert.h
source/gameengine/Expressions/PyObjectPlus.h
source/gameengine/Ketsji/BL_Action.cpp [new file with mode: 0644]
source/gameengine/Ketsji/BL_Action.h [new file with mode: 0644]
source/gameengine/Ketsji/BL_ActionManager.cpp [new file with mode: 0644]
source/gameengine/Ketsji/BL_ActionManager.h [new file with mode: 0644]
source/gameengine/Ketsji/CMakeLists.txt
source/gameengine/Ketsji/KX_GameObject.cpp
source/gameengine/Ketsji/KX_GameObject.h
source/gameengine/Ketsji/KX_Scene.cpp
source/gameengine/Ketsji/KX_SoundActuator.cpp
source/gameengine/Ketsji/KX_SoundActuator.h
source/gameengine/Ketsji/SConscript
source/gameengine/SceneGraph/SG_IObject.cpp
source/gameengine/SceneGraph/SG_IObject.h

index d609249..b0996eb 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()
 {
        return new AUD_CallbackIIRFilterReader(getReader(), 2, 2,
                                                        m_additive ? accumulatorFilterAdditive : accumulatorFilter);
index 3c3b32c..c147d12 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();
 };
 
 #endif //AUD_ACCUMULATORFACTORY
index 563722d..9ddd8af 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),
@@ -55,24 +55,15 @@ AUD_BaseIIRFilterReader::~AUD_BaseIIRFilterReader()
        delete[] m_y;
 }
 
-void AUD_BaseIIRFilterReader::read(int & length, sample_t* buffer)
+void AUD_BaseIIRFilterReader::read(int & length, sample_t* buffer)
 {
-       sample_t* buf;
-
-       int samplesize = AUD_SAMPLE_SIZE(m_reader->getSpecs());
-
-       m_reader->read(length, buf);
-
-       if(m_buffer.getSize() < length * samplesize)
-               m_buffer.resize(length * samplesize);
-
-       buffer = m_buffer.getBuffer();
+       m_reader->read(length, buffer);
 
        for(m_channel = 0; m_channel < m_channels; m_channel++)
        {
                for(int i = 0; i < length; i++)
                {
-                       m_x[m_xpos * CC] = buf[i * CC];
+                       m_x[m_xpos * CC] = buffer[i * CC];
                        m_y[m_ypos * CC] = buffer[i * CC] = filter();
 
                        m_xpos = (m_xpos + 1) % m_xlen;
index 436e646..2d1f214 100644 (file)
@@ -56,11 +56,6 @@ private:
         */
        const int m_ylen;
 
-       /**
-        * The playback buffer.
-        */
-       AUD_Buffer m_buffer;
-
        /**
         * The last in samples array.
         */
@@ -97,7 +92,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)
@@ -112,7 +107,7 @@ public:
 
        virtual ~AUD_BaseIIRFilterReader();
 
-       virtual void read(int & length, sample_t* buffer);
+       virtual void read(int & length, sample_t* buffer);
 
        virtual sample_t filter()=0;
 };
index ea957c8..2d6e14a 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()
 {
-       AUD_IReader* reader = getReader();
+       AUD_Reference<AUD_IReader> reader = getReader();
 
        // calculate coefficients
        float omega = 2 * tan(m_frequency * M_PI / reader->getSpecs().rate);
index c8b7314..be98fd8 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();
 };
 
 #endif //AUD_BUTTERWORTHFACTORY
index 2f9bb77..e6c8332 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 a969db7..6d53ede 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 1d2d99a..e452870 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()
 {
        return new AUD_DelayReader(getReader(), m_delay);
 }
index 1e67cd6..5ab7f85 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();
 };
 
 #endif //AUD_DELAYFACTORY
index 374b876..2e93184 100644 (file)
 
 #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)),
-               m_empty(true)
+               m_remdelay(int(delay * reader->getSpecs().rate))
 {
 }
 
@@ -70,46 +69,28 @@ int AUD_DelayReader::getPosition() const
        return m_reader->getPosition() + m_delay;
 }
 
-void AUD_DelayReader::read(int & length, sample_t* buffer)
+void AUD_DelayReader::read(int & length, sample_t* buffer)
 {
        if(m_remdelay > 0)
        {
                AUD_Specs specs = m_reader->getSpecs();
                int samplesize = AUD_SAMPLE_SIZE(specs);
 
-               if(m_buffer.getSize() < length * samplesize)
-               {
-                       m_buffer.resize(length * samplesize);
-                       m_empty = false;
-               }
-
-               buffer = m_buffer.getBuffer();
-
                if(length > m_remdelay)
                {
-                       if(!m_empty)
-                               memset(buffer, 0, m_remdelay * samplesize);
+                       memset(buffer, 0, m_remdelay * samplesize);
 
                        int len = length - m_remdelay;
-                       sample_t* buf;
-                       m_reader->read(len, buf);
-
-                       memcpy(buffer + m_remdelay * specs.channels,
-                                  buf, len * samplesize);
+                       m_reader->read(len, buffer + m_remdelay * specs.channels);
 
                        if(len < length-m_remdelay)
                                length = m_remdelay + len;
 
                        m_remdelay = 0;
-                       m_empty = false;
                }
                else
                {
-                       if(!m_empty)
-                       {
-                               memset(buffer, 0, length * samplesize);
-                               m_empty = true;
-                       }
+                       memset(buffer, 0, length * samplesize);
                        m_remdelay -= length;
                }
        }
index 5f0af66..cb0ec9b 100644 (file)
 class AUD_DelayReader : public AUD_EffectReader
 {
 private:
-       /**
-        * The playback buffer.
-        */
-       AUD_Buffer m_buffer;
-
        /**
         * The delay level.
         */
@@ -56,11 +51,6 @@ private:
         */
        int m_remdelay;
 
-       /**
-        * Whether the buffer is currently filled with zeros.
-        */
-       bool m_empty;
-
        // hide copy constructor and operator=
        AUD_DelayReader(const AUD_DelayReader&);
        AUD_DelayReader& operator=(const AUD_DelayReader&);
@@ -71,12 +61,12 @@ 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;
        virtual int getPosition() const;
-       virtual void read(int & length, sample_t* buffer);
+       virtual void read(int & length, sample_t* buffer);
 };
 
 #endif //AUD_DELAYREADER
index 7a40f1f..e1e6ba5 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()
 {
-       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 52a299c..f2be713 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();
 };
 
 #endif //AUD_DOUBLEFACTORY
index 113bed1..605c490 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
@@ -93,7 +89,7 @@ AUD_Specs AUD_DoubleReader::getSpecs() const
        return m_reader1->getSpecs();
 }
 
-void AUD_DoubleReader::read(int & length, sample_t* buffer)
+void AUD_DoubleReader::read(int & length, sample_t* buffer)
 {
        if(!m_finished1)
        {
@@ -102,23 +98,12 @@ void AUD_DoubleReader::read(int & length, sample_t* & buffer)
 
                if(len < length)
                {
-                       AUD_Specs specs = m_reader1->getSpecs();
-                       int samplesize = AUD_SAMPLE_SIZE(specs);
-
-                       if(m_buffer.getSize() < length * samplesize)
-                               m_buffer.resize(length * samplesize);
-
-                       sample_t* buf = buffer;
-                       buffer = m_buffer.getBuffer();
-
-                       memcpy(buffer, buf, len * samplesize);
+                       const AUD_Specs specs = m_reader1->getSpecs();
 
                        len = length - len;
                        length -= len;
-                       m_reader2->read(len, buf);
 
-                       memcpy(buffer + length * specs.channels, buf,
-                                  len * samplesize);
+                       m_reader2->read(len, buffer + length * specs.channels);
 
                        length += len;
 
index 7b3b812..d68000f 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.
@@ -84,7 +85,7 @@ public:
        virtual int getLength() const;
        virtual int getPosition() const;
        virtual AUD_Specs getSpecs() const;
-       virtual void read(int & length, sample_t* buffer);
+       virtual void read(int & length, sample_t* buffer);
 };
 
 #endif //AUD_DOUBLEREADER
index a0d9256..6173ffb 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 a6a28ee..72fdb3f 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 3ad9f67..aa8fe7a 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
@@ -66,7 +65,7 @@ AUD_Specs AUD_EffectReader::getSpecs() const
        return m_reader->getSpecs();
 }
 
-void AUD_EffectReader::read(int & length, sample_t* buffer)
+void AUD_EffectReader::read(int & length, sample_t* buffer)
 {
        m_reader->read(length, buffer);
 }
index fb8066f..cfb8e5b 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.
@@ -68,7 +69,7 @@ public:
        virtual int getLength() const;
        virtual int getPosition() const;
        virtual AUD_Specs getSpecs() const;
-       virtual void read(int & length, sample_t* buffer);
+       virtual void read(int & length, sample_t* buffer);
 };
 
 #endif //AUD_EFFECTREADER
index 069317d..53378ef 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()
 {
-       AUD_IReader* reader = getReader();
+       AUD_Reference<AUD_IReader> reader = getReader();
 
        EnvelopeParameters* param = new EnvelopeParameters();
        param->arthreshold = m_arthreshold;
index 45ee811..acf3b13 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();
 };
 
 #endif //AUD_ENVELOPEFACTORY
index d887e9e..635873e 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()
 {
        return new AUD_FaderReader(getReader(), m_type, m_start, m_length);
 }
index b85475b..d8314c7 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();
 };
 
 #endif //AUD_FADERFACTORY
index 6114bb4..7fe5c50 100644 (file)
 
 #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),
                m_start(start),
-               m_length(length),
-               m_empty(true)
+               m_length(length)
 {
 }
 
-void AUD_FaderReader::read(int & length, sample_t* buffer)
+void AUD_FaderReader::read(int & length, sample_t* buffer)
 {
        int position = m_reader->getPosition();
        AUD_Specs specs = m_reader->getSpecs();
@@ -55,46 +54,18 @@ void AUD_FaderReader::read(int & length, sample_t* & buffer)
        {
                if(m_type != AUD_FADE_OUT)
                {
-                       if(m_buffer.getSize() < length * samplesize)
-                       {
-                               m_buffer.resize(length * samplesize);
-                               m_empty = false;
-                       }
-
-                       buffer = m_buffer.getBuffer();
-
-                       if(!m_empty)
-                       {
-                               memset(buffer, 0, length * samplesize);
-                               m_empty = true;
-                       }
+                       memset(buffer, 0, length * samplesize);
                }
        }
        else if(position / (float)specs.rate >= m_start+m_length)
        {
                if(m_type == AUD_FADE_OUT)
                {
-                       if(m_buffer.getSize() < length * samplesize)
-                       {
-                               m_buffer.resize(length * samplesize);
-                               m_empty = false;
-                       }
-
-                       buffer = m_buffer.getBuffer();
-
-                       if(!m_empty)
-                       {
-                               memset(buffer, 0, length * samplesize);
-                               m_empty = true;
-                       }
+                       memset(buffer, 0, length * samplesize);
                }
        }
        else
        {
-               if(m_buffer.getSize() < length * samplesize)
-                       m_buffer.resize(length * samplesize);
-
-               sample_t* buf = m_buffer.getBuffer();
                float volume = 1.0f;
 
                for(int i = 0; i < length * specs.channels; i++)
@@ -111,10 +82,7 @@ void AUD_FaderReader::read(int & length, sample_t* & buffer)
                                        volume = 1.0f - volume;
                        }
 
-                       buf[i] = buffer[i] * volume;
+                       buffer[i] = buffer[i] * volume;
                }
-
-               buffer = buf;
-               m_empty = false;
        }
 }
index fb92719..c0eb3d2 100644 (file)
@@ -58,16 +58,6 @@ private:
         */
        const float m_length;
 
-       /**
-        * The playback buffer.
-        */
-       AUD_Buffer m_buffer;
-
-       /**
-        * Whether the buffer is empty.
-        */
-       bool m_empty;
-
        // hide copy constructor and operator=
        AUD_FaderReader(const AUD_FaderReader&);
        AUD_FaderReader& operator=(const AUD_FaderReader&);
@@ -79,10 +69,10 @@ 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);
+       virtual void read(int & length, sample_t* buffer);
 };
 
 #endif //AUD_FADERREADER
index 61008ee..2104158 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()
 {
-       AUD_IReader* reader = getReader();
+       AUD_Reference<AUD_IReader> reader = getReader();
 
        // calculate coefficients
        float w0 = 2 * M_PI * m_frequency / reader->getSpecs().rate;
index 48f4c1b..de646e7 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();
 };
 
 #endif //AUD_HIGHPASSFACTORY
index ff90ce6..f6ccda6 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()
 {
        return new AUD_IIRFilterReader(getReader(), m_b, m_a);
 }
index d48ad45..0e92ab1 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();
 };
 
 #endif //AUD_IIRFILTERFACTORY
index 0d55421..80252e6 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 af50b6f..db813d6 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 62ea01b..8d1dd14 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()
 {
        return new AUD_LimiterReader(getReader(), m_start, m_end);
 }
index f93f4b3..c04bfe8 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();
 };
 
 #endif //AUD_LIMITERFACTORY
index d67fbb4..0f87679 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)),
@@ -48,14 +48,14 @@ AUD_LimiterReader::AUD_LimiterReader(AUD_IReader* reader,
                {
                        // skip first m_start samples by reading them
                        int length = AUD_DEFAULT_BUFFER_SIZE;
-                       sample_t* buffer;
+                       AUD_Buffer buffer(AUD_DEFAULT_BUFFER_SIZE * AUD_SAMPLE_SIZE(m_reader->getSpecs()));
                        for(int len = m_start;
                                length == AUD_DEFAULT_BUFFER_SIZE;
                                len -= AUD_DEFAULT_BUFFER_SIZE)
                        {
                                if(len < AUD_DEFAULT_BUFFER_SIZE)
                                        length = len;
-                               m_reader->read(length, buffer);
+                               m_reader->read(length, buffer.getBuffer());
                        }
                }
        }
@@ -80,7 +80,7 @@ int AUD_LimiterReader::getPosition() const
        return AUD_MIN(pos, m_end) - m_start;
 }
 
-void AUD_LimiterReader::read(int & length, sample_t* buffer)
+void AUD_LimiterReader::read(int & length, sample_t* buffer)
 {
        if(m_end >= 0)
        {
index 4375ed9..660dc26 100644 (file)
@@ -62,12 +62,12 @@ 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;
        virtual int getPosition() const;
-       virtual void read(int & length, sample_t* buffer);
+       virtual void read(int & length, sample_t* buffer);
 };
 
 #endif //AUD_LIMITERREADER
index 49d3481..fd39ac9 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()
 {
        return new AUD_LoopReader(getReader(), m_loop);
 }
index dfbbbe4..03c00dc 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();
 };
 
 #endif //AUD_LOOPFACTORY
index b2e8e97..0efee5b 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)
 {
 }
@@ -68,10 +68,9 @@ int AUD_LoopReader::getPosition() const
        return m_reader->getPosition() * (m_count < 0 ? 1 : m_count);
 }
 
-void AUD_LoopReader::read(int & length, sample_t* buffer)
+void AUD_LoopReader::read(int & length, sample_t* buffer)
 {
        AUD_Specs specs = m_reader->getSpecs();
-       int samplesize = AUD_SAMPLE_SIZE(specs);
 
        int len = length;
 
@@ -81,13 +80,6 @@ void AUD_LoopReader::read(int & length, sample_t* & buffer)
        {
                int pos = 0;
 
-               if(m_buffer.getSize() < length * samplesize)
-                       m_buffer.resize(length * samplesize);
-
-               sample_t* buf = m_buffer.getBuffer();
-
-               memcpy(buf + pos * specs.channels, buffer, len * samplesize);
-
                pos += len;
 
                while(pos < length && m_left)
@@ -98,19 +90,16 @@ void AUD_LoopReader::read(int & length, sample_t* & buffer)
                        m_reader->seek(0);
 
                        len = length - pos;
-                       m_reader->read(len, buffer);
+                       m_reader->read(len, buffer + pos * specs.channels);
 
                        // prevent endless loop
                        if(!len)
                                break;
 
-                       memcpy(buf + pos * specs.channels, buffer, len * samplesize);
-
                        pos += len;
                }
 
                length = pos;
-               buffer = buf;
        }
        else
                length = len;
index 4501790..d133824 100644 (file)
 class AUD_LoopReader : public AUD_EffectReader
 {
 private:
-       /**
-        * The playback buffer.
-        */
-       AUD_Buffer m_buffer;
-
        /**
         * The loop count.
         */
@@ -68,12 +63,12 @@ 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;
        virtual int getPosition() const;
-       virtual void read(int & length, sample_t* buffer);
+       virtual void read(int & length, sample_t* buffer);
 };
 
 #endif //AUD_LOOPREADER
index d24a04b..9bc8d7c 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()
 {
-       AUD_IReader* reader = getReader();
+       AUD_Reference<AUD_IReader> reader = getReader();
 
        // calculate coefficients
        float w0 = 2 * M_PI * m_frequency / reader->getSpecs().rate;
index d60c0bd..43d47dc 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();
 };
 
 #endif //AUD_LOWPASSFACTORY
index fa14055..e5f2193 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()
 {
-       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 4ae0c49..908591a 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();
 };
 
 #endif //AUD_PINGPONGFACTORY
index b4ae858..e520287 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()
 {
        return new AUD_PitchReader(getReader(), m_pitch);
 }
index 8fa5be9..2642d41 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();
 };
 
 #endif //AUD_PITCHFACTORY
index e2e89e2..7f8b8b5 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 120cebc..7939027 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 609d827..1e500da 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()
 {
        return new AUD_CallbackIIRFilterReader(getReader(), 1, 1, rectifyFilter);
 }
index c3529c7..d7dc236 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();
 };
 
 #endif //AUD_RECTIFYFACTORY
index 22b12e3..060a618 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()
 {
        return new AUD_ReverseReader(getReader());
 }
index 7b20546..b501b4e 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();
 };
 
 #endif //AUD_REVERSEFACTORY
index a4a0393..3d5828d 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)
@@ -60,7 +60,7 @@ int AUD_ReverseReader::getPosition() const
        return m_position;
 }
 
-void AUD_ReverseReader::read(int & length, sample_t* buffer)
+void AUD_ReverseReader::read(int & length, sample_t* buffer)
 {
        // first correct the length
        if(m_position + length > m_length)
@@ -72,36 +72,34 @@ void AUD_ReverseReader::read(int & length, sample_t* & buffer)
                return;
        }
 
-       AUD_Specs specs = getSpecs();
-       int samplesize = AUD_SAMPLE_SIZE(specs);
+       const AUD_Specs specs = getSpecs();
+       const int samplesize = AUD_SAMPLE_SIZE(specs);
 
-       // resize buffer if needed
-       if(m_buffer.getSize() < length * samplesize)
-               m_buffer.resize(length * samplesize);
+       sample_t temp[10];
 
-       buffer = m_buffer.getBuffer();
-
-       sample_t* buf;
        int len = length;
 
        // read from reader
        m_reader->seek(m_length - m_position - len);
-       m_reader->read(len, buf);
+       m_reader->read(len, buffer);
 
        // set null if reader didn't give enough data
        if(len < length)
-       {
                memset(buffer, 0, (length - len) * samplesize);
-               buffer += (length - len) * specs.channels;
-       }
 
        // copy the samples reverted
-       for(int i = 0; i < len; i++)
+       for(int i = 0; i < length / 2; i++)
+       {
+               memcpy(temp,
+                          buffer + (len - 1 - i) * specs.channels,
+                          samplesize);
+               memcpy(buffer + (len - 1 - i) * specs.channels,
+                          buffer + i * specs.channels,
+                          samplesize);
                memcpy(buffer + i * specs.channels,
-                          buf + (len - 1 - i) * specs.channels,
+                          temp,
                           samplesize);
+       }
 
        m_position += length;
-
-       buffer = m_buffer.getBuffer();
 }
index e12f2b2..8525aca 100644 (file)
@@ -52,11 +52,6 @@ private:
         */
        int m_position;
 
-       /**
-        * The playback buffer.
-        */
-       AUD_Buffer m_buffer;
-
        // hide copy constructor and operator=
        AUD_ReverseReader(const AUD_ReverseReader&);
        AUD_ReverseReader& operator=(const AUD_ReverseReader&);
@@ -68,12 +63,12 @@ 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;
        virtual int getPosition() const;
-       virtual void read(int & length, sample_t* buffer);
+       virtual void read(int & length, sample_t* buffer);
 };
 
 #endif //AUD_REVERSEREADER
index a075773..3e94107 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()
 {
        return new AUD_CallbackIIRFilterReader(getReader(), 1, 1,
                                                                                   (doFilterIIR) squareFilter,
index 8060e98..31f2261 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();
 };
 
 #endif //AUD_SQUAREFACTORY
index 6d8368d..befcc30 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()
 {
        std::vector<float> a, b;
        a.push_back(1);
index ed19a0f..cdb4caf 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();
 };
 
 #endif //AUD_SUMFACTORY
index c13a0d0..d514bfd 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()
 {
-       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 3223201..ac7ec08 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();
 };
 
 #endif //AUD_SUPERPOSEFACTORY
index e64cf79..3ad2420 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
@@ -94,24 +82,22 @@ AUD_Specs AUD_SuperposeReader::getSpecs() const
        return m_reader1->getSpecs();
 }
 
-void AUD_SuperposeReader::read(int & length, sample_t* buffer)
+void AUD_SuperposeReader::read(int & length, sample_t* buffer)
 {
        AUD_Specs specs = m_reader1->getSpecs();
        int samplesize = AUD_SAMPLE_SIZE(specs);
 
        if(m_buffer.getSize() < length * samplesize)
                m_buffer.resize(length * samplesize);
-       buffer = m_buffer.getBuffer();
 
        int len1 = length;
-       sample_t* buf;
-       m_reader1->read(len1, buf);
-       memcpy(buffer, buf, len1 * samplesize);
+       m_reader1->read(len1, buffer);
 
        if(len1 < length)
                memset(buffer + len1 * specs.channels, 0, (length - len1) * samplesize);
 
        int len2 = length;
+       sample_t* buf = m_buffer.getBuffer();
        m_reader2->read(len2, buf);
 
        for(int i = 0; i < len2 * specs.channels; i++)
index b256aad..5a2a2a1 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.
@@ -79,7 +80,7 @@ public:
        virtual int getLength() const;
        virtual int getPosition() const;
        virtual AUD_Specs getSpecs() const;
-       virtual void read(int & length, sample_t* buffer);
+       virtual void read(int & length, sample_t* buffer);
 };
 
 #endif //AUD_SUPERPOSEREADER
index 166fbf6..17cefd4 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()
 {
        std::vector<float> a, b;
        a.push_back(1);
index fa40ca1..bcc08e7 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();
 };
 
 #endif //AUD_VOLUMEFACTORY
index b9e30bb..2780f10 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;
@@ -130,7 +130,6 @@ void AUD_OpenALDevice::updateStreams()
        AUD_OpenALHandle* sound;
 
        int length;
-       sample_t* buffer;
 
        ALint info;
        AUD_DeviceSpecs specs = m_specs;
@@ -161,6 +160,8 @@ void AUD_OpenALDevice::updateStreams()
                                        if(info)
                                        {
                                                specs.specs = sound->reader->getSpecs();
+                                               if(m_buffer.getSize() < m_buffersize * AUD_DEVICE_SAMPLE_SIZE(specs))
+                                                       m_buffer.resize(m_buffersize * AUD_DEVICE_SAMPLE_SIZE(specs));
 
                                                // for all empty buffers
                                                while(info--)
@@ -170,7 +171,7 @@ void AUD_OpenALDevice::updateStreams()
                                                        {
                                                                // read data
                                                                length = m_buffersize;
-                                                               sound->reader->read(length, buffer);
+                                                               sound->reader->read(length, m_buffer.getBuffer());
 
                                                                // looping necessary?
                                                                if(length == 0 && sound->loopcount)
@@ -181,7 +182,7 @@ void AUD_OpenALDevice::updateStreams()
                                                                        sound->reader->seek(0);
 
                                                                        length = m_buffersize;
-                                                                       sound->reader->read(length, buffer);
+                                                                       sound->reader->read(length, m_buffer.getBuffer());
                                                                }
 
                                                                // read nothing?
@@ -204,7 +205,7 @@ void AUD_OpenALDevice::updateStreams()
                                                                // fill with new data
                                                                alBufferData(sound->buffers[sound->current],
                                                                                         sound->format,
-                                                                                        buffer, length *
+                                                                                        m_buffer.getBuffer(), length *
                                                                                         AUD_DEVICE_SAMPLE_SIZE(specs),
                                                                                         specs.rate);
 
@@ -382,7 +383,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 +396,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 +538,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 +567,6 @@ AUD_Handle* AUD_OpenALDevice::play(AUD_IReader* reader, bool keep)
        if(!valid)
        {
                delete sound;
-               delete reader;
                return NULL;
        }
 
@@ -584,14 +582,15 @@ AUD_Handle* AUD_OpenALDevice::play(AUD_IReader* reader, bool keep)
 
                try
                {
-                       sample_t* buf;
+                       if(m_buffer.getSize() < m_buffersize * AUD_DEVICE_SAMPLE_SIZE(specs))
+                               m_buffer.resize(m_buffersize * AUD_DEVICE_SAMPLE_SIZE(specs));
                        int length;
 
                        for(int i = 0; i < AUD_OPENAL_CYCLE_BUFFERS; i++)
                        {
                                length = m_buffersize;
-                               reader->read(length, buf);
-                               alBufferData(sound->buffers[i], sound->format, buf,
+                               reader->read(length, m_buffer.getBuffer());
+                               alBufferData(sound->buffers[i], sound->format, m_buffer.getBuffer(),
                                                         length * AUD_DEVICE_SAMPLE_SIZE(specs),
                                                         specs.rate);
                                if(alGetError() != AL_NO_ERROR)
@@ -624,7 +623,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 +640,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 +712,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 +784,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 +803,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;
@@ -884,17 +881,18 @@ bool AUD_OpenALDevice::seek(AUD_Handle* handle, float position)
                                ALenum err;
                                if((err = alGetError()) == AL_NO_ERROR)
                                {
-                                       sample_t* buf;
                                        int length;
                                        AUD_DeviceSpecs specs = m_specs;
                                        specs.specs = alhandle->reader->getSpecs();
+                                       if(m_buffer.getSize() < m_buffersize * AUD_DEVICE_SAMPLE_SIZE(specs))
+                                               m_buffer.resize(m_buffersize * AUD_DEVICE_SAMPLE_SIZE(specs));
 
                                        for(int i = 0; i < AUD_OPENAL_CYCLE_BUFFERS; i++)
                                        {
                                                length = m_buffersize;
-                                               alhandle->reader->read(length, buf);
+                                               alhandle->reader->read(length, m_buffer.getBuffer());
                                                alBufferData(alhandle->buffers[i], alhandle->format,
-                                                                        buf,
+                                                                        m_buffer.getBuffer(),
                                                                         length * AUD_DEVICE_SAMPLE_SIZE(specs),
                                                                         specs.rate);
 
@@ -1109,7 +1107,6 @@ bool AUD_OpenALDevice::bufferFactory(void *value)
 
                if(!getFormat(format, specs.specs))
                {
-                       delete reader;
                        return false;
                }
 
@@ -1147,7 +1144,6 @@ bool AUD_OpenALDevice::bufferFactory(void *value)
                catch(AUD_Exception&)
                {
                        delete bf;
-                       delete reader;
                        alcProcessContext(m_context);
                        unlock();
                        return false;
index 3bbbe85..d5db598 100644 (file)
@@ -34,6 +34,7 @@
 
 #include "AUD_IDevice.h"
 #include "AUD_I3DDevice.h"
+#include "AUD_Buffer.h"
 struct AUD_OpenALHandle;
 struct AUD_OpenALBufferedFactory;
 
@@ -103,6 +104,11 @@ private:
         */
        int m_buffersize;
 
+       /**
+        * Device buffer.
+        */
+       AUD_Buffer m_buffer;
+
        /**
         * Starts the streaming thread.
         */
@@ -147,8 +153,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 22376a2..b6e336e 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));
@@ -2875,6 +2875,25 @@ Device_empty()
        return DeviceType.tp_alloc(&DeviceType, 0);
 }
 
+PyObject *
+Factory_empty()
+{
+       return FactoryType.tp_alloc(&FactoryType, 0);
+}
+
+Factory*
+checkFactory(PyObject* factory)
+{
+       if(!PyObject_TypeCheck(factory, &FactoryType))
+       {
+               PyErr_SetString(PyExc_TypeError, "Object is not of type Factory!");
+               return NULL;
+       }
+
+       return (Factory*)factory;
+}
+
+
 // ====================================================================
 
 PyDoc_STRVAR(M_aud_doc,
index 6e217b0..822aec0 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,14 +60,15 @@ typedef struct {
 
 typedef struct {
        PyObject_HEAD
-       AUD_IDevice* device;
+       AUD_Reference_AUD_IDevice* device;
 } Device;
 
 PyMODINIT_FUNC
 PyInit_aud(void);
 
-extern PyObject *
-Device_empty();
+extern PyObject* Device_empty();
+extern PyObject* Factory_empty();
+extern Factory* checkFactory(PyObject* factory);
 
 #ifdef __cplusplus
 }
index 17cf09e..15e96f6 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()
 {
-       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 716def9..d3e7acf 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();
 };
 
 #endif //AUD_SRCRESAMPLEFACTORY
index 1026514..42696a1 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()),
@@ -75,11 +75,10 @@ AUD_SRCResampleReader::~AUD_SRCResampleReader()
 long AUD_SRCResampleReader::doCallback(float** data)
 {
        int length = m_buffer.getSize() / AUD_SAMPLE_SIZE(m_tspecs);
-       sample_t* buffer;
 
-       m_reader->read(length, buffer);
+       *data = m_buffer.getBuffer();
+       m_reader->read(length, *data);
 
-       *data = buffer;
        return length;
 }
 
@@ -105,15 +104,13 @@ AUD_Specs AUD_SRCResampleReader::getSpecs() const
        return m_tspecs;
 }
 
-void AUD_SRCResampleReader::read(int & length, sample_t* buffer)
+void AUD_SRCResampleReader::read(int & length, sample_t* buffer)
 {
        int size = length * AUD_SAMPLE_SIZE(m_tspecs);
 
        if(m_buffer.getSize() < size)
                m_buffer.resize(size);
 
-       buffer = m_buffer.getBuffer();
-
        length = src_callback_read(m_src, m_factor, length, buffer);
 
        m_position += length;
index 27019c0..2d67e63 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.
@@ -104,7 +104,7 @@ public:
        virtual int getLength() const;
        virtual int getPosition() const;
        virtual AUD_Specs getSpecs() const;
-       virtual void read(int & length, sample_t* buffer);
+       virtual void read(int & length, sample_t* buffer);
 };
 
 #endif //AUD_SRCRESAMPLEREADER
index 38de3e8..909f413 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()
 {
-       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 1268740..af95e3a 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();
 };
 
 #endif //AUD_FFMPEGFACTORY
index 4597432..bacbbf2 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);
@@ -341,14 +341,14 @@ void AUD_FFMPEGReader::seek(int position)
                                                {
                                                        // read until we're at the right position
                                                        int length = AUD_DEFAULT_BUFFER_SIZE;
-                                                       sample_t* buffer;
+                                                       AUD_Buffer buffer(length * AUD_SAMPLE_SIZE(m_specs));
                                                        for(int len = position - m_position;
                                                                length == AUD_DEFAULT_BUFFER_SIZE;
                                                                len -= AUD_DEFAULT_BUFFER_SIZE)
                                                        {
                                                                if(len < AUD_DEFAULT_BUFFER_SIZE)
                                                                        length = len;
-                                                               read(length, buffer);
+                                                               read(length, buffer.getBuffer());
                                                        }
                                                }
                                        }
@@ -381,7 +381,7 @@ AUD_Specs AUD_FFMPEGReader::getSpecs() const
        return m_specs.specs;
 }
 
-void AUD_FFMPEGReader::read(int & length, sample_t* buffer)
+void AUD_FFMPEGReader::read(int & length, sample_t* buffer)
 {
        // read packages and decode them
        AVPacket packet;
@@ -390,11 +390,7 @@ void AUD_FFMPEGReader::read(int & length, sample_t* & buffer)
        int left = length;
        int sample_size = AUD_DEVICE_SAMPLE_SIZE(m_specs);
 
-       // resize output buffer if necessary
-       if(m_buffer.getSize() < length * AUD_SAMPLE_SIZE(m_specs))
-               m_buffer.resize(length * AUD_SAMPLE_SIZE(m_specs));
-
-       buffer = m_buffer.getBuffer();
+       sample_t* buf = buffer;
        pkgbuf_pos = m_pkgbuf_left;
        m_pkgbuf_left = 0;
 
@@ -402,9 +398,9 @@ void AUD_FFMPEGReader::read(int & length, sample_t* & buffer)
        if(pkgbuf_pos > 0)
        {
                data_size = AUD_MIN(pkgbuf_pos, left * sample_size);
-               m_convert((data_t*) buffer, (data_t*) m_pkgbuf.getBuffer(),
+               m_convert((data_t*) buf, (data_t*) m_pkgbuf.getBuffer(),
                                  data_size / AUD_FORMAT_SIZE(m_specs.format));
-               buffer += data_size / AUD_FORMAT_SIZE(m_specs.format);
+               buf += data_size / AUD_FORMAT_SIZE(m_specs.format);
                left -= data_size/sample_size;
        }
 
@@ -419,9 +415,9 @@ void AUD_FFMPEGReader::read(int & length, sample_t* & buffer)
 
                        // copy to output buffer
                        data_size = AUD_MIN(pkgbuf_pos, left * sample_size);
-                       m_convert((data_t*) buffer, (data_t*) m_pkgbuf.getBuffer(),
+                       m_convert((data_t*) buf, (data_t*) m_pkgbuf.getBuffer(),
                                          data_size / AUD_FORMAT_SIZE(m_specs.format));
-                       buffer += data_size / AUD_FORMAT_SIZE(m_specs.format);
+                       buf += data_size / AUD_FORMAT_SIZE(m_specs.format);
                        left -= data_size/sample_size;
                }
                av_free_packet(&packet);
@@ -435,8 +431,6 @@ void AUD_FFMPEGReader::read(int & length, sample_t* & buffer)
                                pkgbuf_pos-data_size);
        }
 
-       buffer = m_buffer.getBuffer();
-
        if(left > 0)
                length -= left;
        m_position += length;
index 26e6685..c5bfd11 100644 (file)
@@ -60,11 +60,6 @@ private:
         */
        int m_position;
 
-       /**
-        * The playback buffer.
-        */
-       AUD_Buffer m_buffer;
-
        /**
         * The specification of the audio data.
         */
@@ -167,7 +162,7 @@ public:
        virtual int getLength() const;
        virtual int getPosition() const;
        virtual AUD_Specs getSpecs() const;
-       virtual void read(int & length, sample_t* buffer);
+       virtual void read(int & length, sample_t* buffer);
 };
 
 #endif //AUD_FFMPEGREADER
index 78111ba..08ed52e 100644 (file)
@@ -33,6 +33,8 @@
 #include "AUD_Buffer.h"
 #include "AUD_Space.h"
 
+#include <cstring>
+
 AUD_BufferReader::AUD_BufferReader(AUD_Reference<AUD_Buffer> buffer,
                                                                   AUD_Specs specs) :
        m_position(0), m_buffer(buffer), m_specs(specs)
@@ -51,7 +53,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
@@ -64,17 +66,22 @@ AUD_Specs AUD_BufferReader::getSpecs() const
        return m_specs;
 }
 
-void AUD_BufferReader::read(int & length, sample_t* buffer)
+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;
+       sample_t* buf = 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;
+               return;
+       }
+
        m_position += length;
+       memcpy(buffer, buf, length * sample_size);
 }
index 3369672..16d7136 100644 (file)
@@ -76,7 +76,7 @@ public:
        virtual int getLength() const;
        virtual int getPosition() const;
        virtual AUD_Specs getSpecs() const;
-       virtual void read(int & length, sample_t* buffer);
+       virtual void read(int & length, sample_t* buffer);
 };
 
 #endif //AUD_BUFFERREADER
index 0119bb1..61d7616 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;
 }
 
@@ -199,34 +181,87 @@ static PyMethodDef meth_getcdevice[] = {{ "device", (PyCFunction)AUD_getCDevice,
                                                                                  ":return: The application's :class:`Device`.\n"
                                                                                  ":rtype: :class:`Device`"}};
 
+extern "C" {
+extern void* sound_get_factory(void* sound);
+}
+
+static PyObject* AUD_getSoundFromPointer(PyObject* self, PyObject* args)
+{
+       long int lptr;
+
+       if(PyArg_Parse(args, "l:_sound_from_pointer", &lptr))
+       {
+               if(lptr)
+               {
+                       AUD_Reference<AUD_IFactory>* factory = (AUD_Reference<AUD_IFactory>*) sound_get_factory((void*) lptr);
+
+                       if(factory)
+                       {
+                               Factory* obj = (Factory*) Factory_empty();
+                               if(obj)
+                               {
+                                       obj->factory = new AUD_Reference<AUD_IFactory>(*factory);
+                                       return (PyObject*) obj;
+                               }
+                       }
+               }
+       }
+
+       Py_RETURN_NONE;
+}
+
+static PyMethodDef meth_sound_from_pointer[] = {{ "_sound_from_pointer", (PyCFunction)AUD_getSoundFromPointer, METH_O,
+                                                                                 "_sound_from_pointer(pointer)\n\n"
+                                                                                 "Returns the corresponding :class:`Factory` object.\n\n"
+                                                                                 ":arg pointer: The pointer to the bSound object as long.\n"
+                                                                                 ":type pointer: long\n"
+                                                                                 ":return: The corresponding :class:`Factory` object.\n"
+                                                                                 ":rtype: :class:`Factory`"}};
+
 PyObject* AUD_initPython()
 {
        PyObject* module = PyInit_aud();
-       PyModule_AddObject(module, "device", (PyObject *)PyCFunction_New(meth_getcdevice, NULL));
+       PyModule_AddObject(module, "device", (PyObject*)PyCFunction_New(meth_getcdevice, NULL));
+       PyModule_AddObject(module, "_sound_from_pointer", (PyObject*)PyCFunction_New(meth_sound_from_pointer, NULL));
        PyDict_SetItemString(PyImport_GetModuleDict(), "aud", module);
-       if(AUD_device)
+
+       return module;
+}
+
+PyObject* AUD_getPythonFactory(AUD_Sound* sound)
+{
+       if(sound)
        {
-               g_device = (Device*)Device_empty();
-               if(g_device != NULL)
+               Factory* obj = (Factory*) Factory_empty();
+               if(obj)
                {
-                       g_device->device = AUD_device;
+                       obj->factory = new AUD_Reference<AUD_IFactory>(*sound);
+                       return (PyObject*) obj;
                }
        }
-       g_pyinitialized = true;
 
-       return module;
+       return NULL;
 }
+
+AUD_Sound* AUD_getPythonSound(PyObject* sound)
+{
+       Factory* factory = checkFactory(sound);
+
+       if(!factory)
+               return NULL;
+
+       return new AUD_Reference<AUD_IFactory>(*reinterpret_cast<AUD_Reference<AUD_IFactory>*>(factory->factory));
+}
+
 #endif
 
 void AUD_lock()
 {
-       assert(AUD_device);
        AUD_device->lock();
 }
 
 void AUD_unlock()
 {
-       assert(AUD_device);
        AUD_device->unlock();
 }
 
@@ -241,13 +276,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 +294,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 +309,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 +323,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 +337,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 +351,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 +365,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 +394,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 +410,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 +423,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 +472,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 +484,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 +496,6 @@ int AUD_setListenerOrientation(const float* orientation)
 
 int AUD_setSpeedOfSound(float speed)
 {
-       assert(AUD_device);
-
        if(AUD_3ddevice)
        {
                AUD_3ddevice->setSpeedOfSound(speed);
@@ -488,8 +507,6 @@ int AUD_setSpeedOfSound(float speed)
 
 int AUD_setDopplerFactor(float factor)
 {
-       assert(AUD_device);
-
        if(AUD_3ddevice)
        {
                AUD_3ddevice->setDopplerFactor(factor);
@@ -501,8 +518,6 @@ int AUD_setDopplerFactor(float factor)
 
 int AUD_setDistanceModel(AUD_DistanceModel model)
 {
-       assert(AUD_device);
-
        if(AUD_3ddevice)
        {
                AUD_3ddevice->setDistanceModel(model);
@@ -514,8 +529,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 +540,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 +551,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 +562,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 +572,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 +582,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 +592,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 +602,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 +612,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 +622,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 +632,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 +642,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 +654,6 @@ int AUD_setSoundVolume(AUD_Channel* handle, float volume)
 {
        if(handle)
        {
-               assert(AUD_device);
-
                try
                {
                        return AUD_device->setVolume(handle, volume);
@@ -678,8 +667,6 @@ int AUD_setSoundPitch(AUD_Channel* handle, float pitch)
 {
        if(handle)
        {
-               assert(AUD_device);
-
                try
                {
                        return AUD_device->setPitch(handle, pitch);
@@ -693,7 +680,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 +695,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 +711,7 @@ int AUD_setDeviceVolume(AUD_Device* device, float volume)
 
        try
        {
-               device->setVolume(volume);
+               (*device)->setVolume(volume);
                return true;
        }
        catch(AUD_Exception&) {}
@@ -741,7 +728,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 +742,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,52 +772,45 @@ 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;
        int position = 0;
-       sample_t* readbuffer;
        do
        {
                len = samplerate;
                buffer.resize((position + len) * sizeof(float), true);
-               reader->read(len, readbuffer);
-               memcpy(buffer.getBuffer() + position, readbuffer, len * sizeof(float));
+               reader->read(len, buffer.getBuffer() + position);
                position += len;
        } while(len != 0);
-       delete reader;
 
        float* result = (float*)malloc(position * sizeof(float));
        memcpy(result, buffer.getBuffer(), position * sizeof(float));
@@ -840,21 +820,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,53 +850,55 @@ 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)
 {
        AUD_DeviceSpecs specs;
        sample_t* buf;
+       AUD_Buffer aBuffer;
 
        specs.rate = AUD_RATE_INVALID;
        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;
@@ -929,6 +907,13 @@ int AUD_readSound(AUD_Sound* sound, sample_t* buffer, int length)
        for(int i = 0; i < length; i++)
        {
                len = floor(samplejump * (i+1)) - floor(samplejump * i);
+
+               if(aBuffer.getSize() < len * AUD_SAMPLE_SIZE(reader->getSpecs()))
+               {
+                       aBuffer.resize(len * AUD_SAMPLE_SIZE(reader->getSpecs()));
+                       buf = aBuffer.getBuffer();
+               }
+
                reader->read(len, buf);
 
                if(len < 1)
@@ -949,15 +934,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 +949,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 +958,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 +971,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 +984,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,9 +993,14 @@ 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
        return -1;
 }
+
+AUD_Sound* AUD_copy(AUD_Sound* sound)
+{
+       return new AUD_Reference<AUD_IFactory>(*sound);
+}
index b2242f0..3fdb9e7 100644 (file)
 #ifndef AUD_CAPI
 #define AUD_CAPI
 
+#ifdef WITH_PYTHON
+#include "Python.h"
+#endif
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -55,7 +59,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 +469,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);
@@ -492,6 +496,14 @@ extern void AUD_setSyncCallback(AUD_syncFunction function, void* data);
 
 extern int AUD_doesPlayback(void);
 
+extern AUD_Sound* AUD_copy(AUD_Sound* sound);
+
+#ifdef WITH_PYTHON
+extern PyObject* AUD_getPythonFactory(AUD_Sound* sound);
+
+extern AUD_Sound* AUD_getPythonSound(PyObject* sound);
+#endif
+
 #ifdef __cplusplus
 }
 #endif
index b474fba..d8ed115 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()
 {
-       AUD_IReader* reader = getReader();
+       AUD_Reference<AUD_IReader> reader = getReader();
        int ic = reader->getSpecs().channels;
 
        return new AUD_ChannelMapperReader(reader,
index 9d622f5..7c48aa7 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();
 };
 
 #endif //AUD_CHANNELMAPPERFACTORY
index dec70aa..a70eebc 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)
 {
@@ -76,16 +76,15 @@ AUD_Specs AUD_ChannelMapperReader::getSpecs() const
        return m_specs;
 }
 
-void AUD_ChannelMapperReader::read(int & length, sample_t* buffer)
+void AUD_ChannelMapperReader::read(int & length, sample_t* buffer)
 {
-       sample_t* in = buffer;
+       if(m_buffer.getSize() < length * m_rch * sizeof(sample_t))
+               m_buffer.resize(length * m_rch * sizeof(sample_t));
 
-       m_reader->read(length, in);
+       sample_t* in = m_buffer.getBuffer();
 
-       if(m_buffer.getSize() < length * AUD_SAMPLE_SIZE(m_specs))
-               m_buffer.resize(length * AUD_SAMPLE_SIZE(m_specs));
+       m_reader->read(length, in);
 
-       buffer = m_buffer.getBuffer();
        sample_t sum;
 
        for(int i = 0; i < length; i++)
index 091ed06..31c22b8 100644 (file)
@@ -43,7 +43,7 @@ class AUD_ChannelMapperReader : public AUD_EffectReader
 {
 private:
        /**
-        * The sound output buffer.
+        * The sound reading buffer.
         */
        AUD_Buffer m_buffer;
 
@@ -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.
@@ -80,7 +80,7 @@ public:
        ~AUD_ChannelMapperReader();
 
        virtual AUD_Specs getSpecs() const;
-       virtual void read(int & length, sample_t* buffer);
+       virtual void read(int & length, sample_t* buffer);
 };
 
 #endif //AUD_CHANNELMAPPERREADER
index cce0f27..bf9a358 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()
 {
-       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 b9eac94..8f0221a 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();
 };
 
 #endif //AUD_CONVERTERFACTORY
index d3cc9fa..8f2ac21 100644 (file)
 void AUD_convert_u8_s16(data_t* target, data_t* source, int length)
 {
        int16_t* t = (int16_t*) target;
-       for(int i = 0; i < length; i++)
+       for(int i = length - 1; i >= 0; i++)
                t[i] = (((int16_t)source[i]) - AUD_U8_0) << 8;
 }
 
 void AUD_convert_u8_s24_be(data_t* target, data_t* source, int length)
 {
-       for(int i = 0; i < length; i++)
+       for(int i = length - 1; i >= 0; i++)
        {
                target[i*3] = source[i] - AUD_U8_0;
                target[i*3+1] = 0;
@@ -61,7 +61,7 @@ void AUD_convert_u8_s24_be(data_t* target, data_t* source, int length)
 
 void AUD_convert_u8_s24_le(data_t* target, data_t* source, int length)
 {
-       for(int i = 0; i < length; i++)
+       for(int i = length - 1; i >= 0; i++)
        {
                target[i*3+2] = source[i] - AUD_U8_0;
                target[i*3+1] = 0;
@@ -72,21 +72,21 @@ void AUD_convert_u8_s24_le(data_t* target, data_t* source, int length)
 void AUD_convert_u8_s32(data_t* target, data_t* source, int length)
 {
        int32_t* t = (int32_t*) target;
-       for(int i = 0; i < length; i++)
+       for(int i = length - 1; i >= 0; i++)
                t[i] = (((int32_t)source[i]) - AUD_U8_0) << 24;
 }
 
 void AUD_convert_u8_float(data_t* target, data_t* source, int length)
 {
        float* t = (float*) target;
-       for(int i = 0; i < length; i++)
+       for(int i = length - 1; i >= 0; i++)
                t[i] = (((int32_t)source[i]) - AUD_U8_0) / ((float)AUD_U8_0);
 }
 
 void AUD_convert_u8_double(data_t* target, data_t* source, int length)
 {
        double* t = (double*) target;
-       for(int i = 0; i < length; i++)
+       for(int i = length - 1; i >= 0; i++)
                t[i] = (((int32_t)source[i]) - AUD_U8_0) / ((double)AUD_U8_0);
 }
 
@@ -100,10 +100,12 @@ void AUD_convert_s16_u8(data_t* target, data_t* source, int length)
 void AUD_convert_s16_s24_be(data_t* target, data_t* source, int length)
 {
        int16_t* s = (int16_t*) source;
-       for(int i = 0; i < length; i++)
+       int16_t t;
+       for(int i = length - 1; i >= 0; i++)
        {
-               target[i*3] = s[i] >> 8 & 0xFF;
-               target[i*3+1] = s[i] & 0xFF;
+               t = s[i];
+               target[i*3] = t >> 8 & 0xFF;
+               target[i*3+1] = t & 0xFF;
                target[i*3+2] = 0;
        }
 }
@@ -111,10 +113,12 @@ void AUD_convert_s16_s24_be(data_t* target, data_t* source, int length)
 void AUD_convert_s16_s24_le(data_t* target, data_t* source, int length)
 {
        int16_t* s = (int16_t*) source;
-       for(int i = 0; i < length; i++)
+       int16_t t;
+       for(int i = length - 1; i >= 0; i++)
        {
-               target[i*3+2] = s[i] >> 8 & 0xFF;
-               target[i*3+1] = s[i] & 0xFF;
+               t = s[i];
+               target[i*3+2] = t >> 8 & 0xFF;
+               target[i*3+1] = t & 0xFF;
                target[i*3] = 0;
        }
 }
@@ -123,7 +127,7 @@ void AUD_convert_s16_s32(data_t* target, data_t* source, int length)
 {
        int16_t* s = (int16_t*) source;
        int32_t* t = (int32_t*) target;
-       for(int i = 0; i < length; i++)
+       for(int i = length - 1; i >= 0; i++)
                t[i] = ((int32_t)s[i]) << 16;
 }
 
@@ -131,7 +135,7 @@ void AUD_convert_s16_float(data_t* target, data_t* source, int length)
 {
        int16_t* s = (int16_t*) source;
        float* t = (float*) target;
-       for(int i = 0; i < length; i++)
+       for(int i = length - 1; i >= 0; i++)
                t[i] = s[i] / AUD_S16_FLT;
 }
 
@@ -139,7 +143,7 @@ void AUD_convert_s16_double(data_t* target, data_t* source, int length)
 {
        int16_t* s = (int16_t*) source;
        double* t = (double*) target;
-       for(int i = 0; i < length; i++)
+       for(int i = length - 1; i >= 0; i++)
                t[i] = s[i] / AUD_S16_FLT;
 }
 
@@ -177,14 +181,14 @@ void AUD_convert_s24_s24(data_t* target, data_t* source, int length)
 void AUD_convert_s24_s32_be(data_t* target, data_t* source, int length)
 {
        int32_t* t = (int32_t*) target;
-       for(int i = 0; i < length; i++)
+       for(int i = length - 1; i >= 0; i++)
                t[i] = source[i*3] << 24 | source[i*3+1] << 16 | source[i*3+2] << 8;
 }
 
 void AUD_convert_s24_s32_le(data_t* target, data_t* source, int length)
 {
        int32_t* t = (int32_t*) target;
-       for(int i = 0; i < length; i++)
+       for(int i = length - 1; i >= 0; i++)
                t[i] = source[i*3+2] << 24 | source[i*3+1] << 16 | source[i*3] << 8;
 }
 
@@ -192,7 +196,7 @@ void AUD_convert_s24_float_be(data_t* target, data_t* source, int length)
 {
        float* t = (float*) target;
        int32_t s;
-       for(int i = 0; i < length; i++)
+       for(int i = length - 1; i >= 0; i++)
        {
                s = source[i*3] << 24 | source[i*3+1] << 16 | source[i*3+2] << 8;
                t[i] = s / AUD_S32_FLT;
@@ -203,7 +207,7 @@ void AUD_convert_s24_float_le(data_t* target, data_t* source, int length)
 {
        float* t = (float*) target;
        int32_t s;
-       for(int i = 0; i < length; i++)
+       for(int i = length - 1; i >= 0; i++)
        {
                s = source[i*3+2] << 24 | source[i*3+1] << 16 | source[i*3] << 8;
                t[i] = s / AUD_S32_FLT;
@@ -214,7 +218,7 @@ void AUD_convert_s24_double_be(data_t* target, data_t* source, int length)
 {
        double* t = (double*) target;
        int32_t s;
-       for(int i = 0; i < length; i++)
+       for(int i = length - 1; i >= 0; i++)
        {
                s = source[i*3] << 24 | source[i*3+1] << 16 | source[i*3+2] << 8;
                t[i] = s / AUD_S32_FLT;
@@ -225,7 +229,7 @@ void AUD_convert_s24_double_le(data_t* target, data_t* source, int length)
 {
        double* t = (double*) target;
        int32_t s;
-       for(int i = 0; i < length; i++)
+       for(int i = length - 1; i >= 0; i++)
        {
                s = source[i*3+2] << 24 | source[i*3+1] << 16 | source[i*3] << 8;
                t[i] = s / AUD_S32_FLT;
@@ -250,22 +254,26 @@ void AUD_convert_s32_s16(data_t* target, data_t* source, int length)
 void AUD_convert_s32_s24_be(data_t* target, data_t* source, int length)
 {
        int32_t* s = (int32_t*) source;
+       int32_t t;
        for(int i = 0; i < length; i++)
        {
-               target[i*3] = s[i] >> 24 & 0xFF;
-               target[i*3+1] = s[i] >> 16 & 0xFF;
-               target[i*3+2] = s[i] >> 8 & 0xFF;
+               t = s[i];
+               target[i*3] = t >> 24 & 0xFF;
+               target[i*3+1] = t >> 16 & 0xFF;
+               target[i*3+2] = t >> 8 & 0xFF;
        }
 }
 
 void AUD_convert_s32_s24_le(data_t* target, data_t* source, int length)
 {
-       int16_t* s = (int16_t*) source;
+       int32_t* s = (int32_t*) source;
+       int32_t t;
        for(int i = 0; i < length; i++)
        {
-               target[i*3+2] = s[i] >> 24 & 0xFF;
-               target[i*3+1] = s[i] >> 16 & 0xFF;
-               target[i*3] = s[i] >> 8 & 0xFF;
+               t = s[i];
+               target[i*3+2] = t >> 24 & 0xFF;
+               target[i*3+1] = t >> 16 & 0xFF;
+               target[i*3] = t >> 8 & 0xFF;
        }
 }
 
@@ -281,7 +289,7 @@ void AUD_convert_s32_double(data_t* target, data_t* source, int length)
 {
        int32_t* s = (int32_t*) source;
        double* t = (double*) target;
-       for(int i = 0; i < length; i++)
+       for(int i = length - 1; i >= 0; i++)
                t[i] = s[i] / AUD_S32_FLT;
 }
 
@@ -371,7 +379,7 @@ void AUD_convert_float_double(data_t* target, data_t* source, int length)
 {
        float* s = (float*) source;
        double* t = (double*) target;
-       for(int i = 0; i < length; i++)
+       for(int i = length - 1; i >= 0; i++)
                t[i] = s[i];
 }
 
index 70297b8..7e0246f 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)
 {
@@ -75,17 +75,15 @@ AUD_Specs AUD_ConverterReader::getSpecs() const
        return m_specs.specs;
 }
 
-void AUD_ConverterReader::read(int & length, sample_t* buffer)
+void AUD_ConverterReader::read(int & length, sample_t* buffer)
 {
-       m_reader->read(length, buffer);
-
-       int samplesize = AUD_SAMPLE_SIZE(m_specs);
+       int samplesize = AUD_SAMPLE_SIZE(m_reader->getSpecs());
 
        if(m_buffer.getSize() < length * samplesize)
                m_buffer.resize(length * samplesize);
 
-       m_convert((data_t*)m_buffer.getBuffer(), (data_t*)buffer,
-                         length * m_specs.channels);
+       m_reader->read(length, m_buffer.getBuffer());
 
-       buffer = m_buffer.getBuffer();
+       m_convert((data_t*)buffer, (data_t*)m_buffer.getBuffer(),
+                         length * m_specs.channels);
 }
index a7a425a..958fe6d 100644 (file)
@@ -67,10 +67,10 @@ 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);
+       virtual void read(int & length, sample_t* buffer);
 };
 
 #endif //AUD_CONVERTERREADER
index 20471d6..24fea65 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 a347141..2600a6f 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 1c8bb03..684fbb1 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()
 {
 #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 a2ab94a..dfca70b 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();
 };
 
 #endif //AUD_FILEFACTORY
index 4856b91..88c9aa5 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 40a6127..c1a9de7 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()=0;
 };
 
 #endif //AUD_IFACTORY
index 7c31c59..01baf13 100644 (file)
@@ -100,7 +100,7 @@ public:
         *                A smaller value also indicates the end of the reader.
         * \param[out] buffer The pointer to the buffer with the samples.
         */
-       virtual void read(int & length, sample_t* buffer)=0;
+       virtual void read(int & length, sample_t* buffer)=0;
 };
 
 #endif //AUD_IREADER
index a90dc5c..404281a 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()
 {
-       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 678aa0b..9f4e9e1 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();
 };
 
 #endif //AUD_LINEARRESAMPLEFACTORY
index 05fb39b..6cb1d94 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()),
@@ -71,18 +71,17 @@ AUD_Specs AUD_LinearResampleReader::getSpecs() const
        return m_tspecs;
 }
 
-void AUD_LinearResampleReader::read(int & length, sample_t* buffer)
+void AUD_LinearResampleReader::read(int & length, sample_t* buffer)
 {
        int samplesize = AUD_SAMPLE_SIZE(m_tspecs);
-       int size = length * samplesize;
+       int size = length * AUD_SAMPLE_SIZE(m_sspecs);
 
        if(m_buffer.getSize() < size)
                m_buffer.resize(size);
 
        int need = ceil((m_position + length) / m_factor) + 1 - m_sposition;
        int len = need;
-       sample_t* buf;
-       buffer = m_buffer.getBuffer();
+       sample_t* buf = m_buffer.getBuffer();
 
        m_reader->read(len, buf);
 
index 419c96b..f673cd0 100644 (file)
@@ -86,13 +86,13 @@ 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;
        virtual int getPosition() const;
        virtual AUD_Specs getSpecs() const;
-       virtual void read(int & length, sample_t* buffer);
+       virtual void read(int & length, sample_t* buffer);
 };
 
 #endif //AUD_LINEARRESAMPLEREADER
index 03488ac..880e9d2 100644 (file)
@@ -73,43 +73,33 @@ AUD_DeviceSpecs AUD_Mixer::getSpecs() const
        return m_specs;
 }
 
-void AUD_Mixer::add(sample_t* buffer, int start, int length, float volume)
+void AUD_Mixer::clear(int length)
 {
-       AUD_MixerBuffer buf;
-       buf.buffer = buffer;
-       buf.start = start;
-       buf.length = length;
-       buf.volume = volume;
-       m_buffers.push_back(buf);
-}
-
-void AUD_Mixer::superpose(data_t* buffer, int length, float volume)
-{
-       AUD_MixerBuffer buf;
+       if(m_buffer.getSize() < length * m_specs.channels * AUD_SAMPLE_SIZE(m_specs))
+               m_buffer.resize(length * m_specs.channels * AUD_SAMPLE_SIZE(m_specs));
 
-       int channels = m_specs.channels;
+       m_length = length;
 
-       if(m_buffer.getSize() < length * channels * 4)
-               m_buffer.resize(length * channels * 4);
+       memset(m_buffer.getBuffer(), 0, length * m_specs.channels * AUD_SAMPLE_SIZE(m_specs));
+}
 
+void AUD_Mixer::mix(sample_t* buffer, int start, int length, float volume)
+{
        sample_t* out = m_buffer.getBuffer();
-       sample_t* in;
-
-       memset(out, 0, length * channels * 4);
 
-       int end;
+       length = (AUD_MIN(m_length, length + start) - start) * m_specs.channels;
+       start += m_specs.channels;
 
-       while(!m_buffers.empty())
-       {
-               buf = m_buffers.front();
-               m_buffers.pop_front();
+       for(int i = 0; i < length; i++)
+               out[i + start] += buffer[i] * volume;
+}
 
-               end = buf.length * channels;
-               in = buf.buffer;
+void AUD_Mixer::read(data_t* buffer, float volume)
+{
+       sample_t* out = m_buffer.getBuffer();
 
-               for(int i = 0; i < end; i++)
-                       out[i + buf.start * channels] += in[i] * buf.volume * volume;
-       }
+       for(int i = 0; i < m_length * m_specs.channels; i++)
+               out[i] *= volume;
 
-       m_convert(buffer, (data_t*) out, length * channels);
+       m_convert(buffer, (data_t*) out, m_length * m_specs.channels);
 }
index 277d5bf..9e2be46 100644 (file)
 
 #include "AUD_ConverterFunctions.h"
 #include "AUD_Buffer.h"
+#include "AUD_Reference.h"
 class AUD_IReader;
-#include <list>
-
-struct AUD_MixerBuffer
-{
-       sample_t* buffer;
-       int start;
-       int length;
-       float volume;
-};
 
 /**
  * This abstract class is able to mix audiosignals of different channel count
@@ -53,17 +45,17 @@ class AUD_Mixer
 {
 protected:
        /**
-        * The list of buffers to superpose.
+        * The output specification.
         */
-       std::list<AUD_MixerBuffer> m_buffers;
+       const AUD_DeviceSpecs m_specs;
 
        /**
-        * The output specification.
+        * The length of the mixing buffer.
         */
-       const AUD_DeviceSpecs m_specs;
+       int m_length;
 
        /**
-        * The temporary mixing buffer.
+        * The mixing buffer.
         */
        AUD_Buffer m_buffer;
 
@@ -94,24 +86,29 @@ 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.
+        * Mixes a buffer.
         * \param buffer The buffer to superpose.
         * \param start The start sample of the buffer.
         * \param length The length of the buffer in samples.
         * \param volume The mixing volume. Must be a value between 0.0 and 1.0.
         */
-       virtual void add(sample_t* buffer, int start, int length, float volume);
+       virtual void mix(sample_t* buffer, int start, int length, float volume);
 
        /**
-        * Superposes all added buffers into an output buffer.
+        * Writes the mixing buffer into an output buffer.
         * \param buffer The target buffer for superposing.
-        * \param length The length of the buffer in samples.
         * \param volume The mixing volume. Must be a value between 0.0 and 1.0.
         */
-       virtual void superpose(data_t* buffer, int length, float volume);
+       virtual void read(data_t* buffer, float volume);
+
+       /**
+        * Clears the mixing buffer.
+        * \param length The length of the buffer in samples.
+        */
+       virtual void clear(int length);
 };
 
 #endif //AUD_MIXER
index e65b149..c3bf6b4 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 2adabbd..27c703b 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 ab82479..09fc483 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 f700bea..6a10267 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);