3D Audio GSoC:
authorJoerg Mueller <nexyon@gmail.com>
Tue, 21 Jun 2011 20:29:02 +0000 (20:29 +0000)
committerJoerg Mueller <nexyon@gmail.com>
Tue, 21 Jun 2011 20:29:02 +0000 (20:29 +0000)
- Converting AUD_SampleRate to a double
- Removing AUD_DefaultMixer
- Introducing AUD_ResampleReader as base class for all resampling readers.

17 files changed:
intern/audaspace/CMakeLists.txt
intern/audaspace/FX/AUD_PitchReader.cpp
intern/audaspace/Python/AUD_PyAPI.cpp
intern/audaspace/SRC/AUD_SRCResampleReader.cpp
intern/audaspace/SRC/AUD_SRCResampleReader.h
intern/audaspace/intern/AUD_C-API.cpp
intern/audaspace/intern/AUD_C-API.h
intern/audaspace/intern/AUD_LinearResampleReader.cpp
intern/audaspace/intern/AUD_LinearResampleReader.h
intern/audaspace/intern/AUD_Mixer.h
intern/audaspace/intern/AUD_ReadDevice.cpp
intern/audaspace/intern/AUD_ResampleReader.cpp [moved from intern/audaspace/intern/AUD_DefaultMixer.cpp with 56% similarity]
intern/audaspace/intern/AUD_ResampleReader.h [moved from intern/audaspace/intern/AUD_DefaultMixer.h with 57% similarity]
intern/audaspace/intern/AUD_SequencerReader.cpp
intern/audaspace/intern/AUD_SinusReader.cpp
intern/audaspace/intern/AUD_SoftwareDevice.cpp
intern/audaspace/intern/AUD_Space.h

index 9c75cd67e6aca0e98761c37dc0ddbd85eed0057e..df9597612d5d5f14b2f563458b08cccce91dbe8b 100644 (file)
@@ -82,8 +82,6 @@ set(SRC
        intern/AUD_ConverterFunctions.h
        intern/AUD_ConverterReader.cpp
        intern/AUD_ConverterReader.h
-       intern/AUD_DefaultMixer.cpp
-       intern/AUD_DefaultMixer.h
        intern/AUD_FileFactory.cpp
        intern/AUD_FileFactory.h
        intern/AUD_I3DDevice.h
@@ -108,6 +106,8 @@ set(SRC
        intern/AUD_Reference.h
        intern/AUD_ReferenceHandler.cpp
        intern/AUD_ResampleFactory.h
+       intern/AUD_ResampleReader.cpp
+       intern/AUD_ResampleReader.h
        intern/AUD_SequencerFactory.cpp
        intern/AUD_SequencerFactory.h
        intern/AUD_SequencerReader.cpp
index 7f8b8b53105621b716a708d6eaaad446fb3e6658..84a76c64ef914792532ba8677813cebbf770a51c 100644 (file)
@@ -39,6 +39,6 @@ AUD_PitchReader::AUD_PitchReader(AUD_Reference<AUD_IReader> reader, float pitch)
 AUD_Specs AUD_PitchReader::getSpecs() const
 {
        AUD_Specs specs = m_reader->getSpecs();
-       specs.rate = (AUD_SampleRate)((int)(specs.rate * m_pitch));
+       specs.rate *= m_pitch;
        return specs;
 }
index 2a4cee4dd0e645cd175c7fd94e4483c85a2349f0..12bb19644f0ef9be0058de07d8a10d239f419b20 100644 (file)
@@ -2111,13 +2111,13 @@ Device_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 
        static const char *kwlist[] = {"type", "rate", "channels", "format", "buffer_size", "name", NULL};
        int device;
-       int rate = AUD_RATE_44100;
+       double rate = AUD_RATE_44100;
        int channels = AUD_CHANNELS_STEREO;
        int format = AUD_FORMAT_FLOAT32;
        int buffersize = AUD_DEFAULT_BUFFER_SIZE;
        const char* name = "Audaspace";
 
-       if(!PyArg_ParseTupleAndKeywords(args, kwds, "i|iiiis:Device", const_cast<char**>(kwlist),
+       if(!PyArg_ParseTupleAndKeywords(args, kwds, "i|diiis:Device", const_cast<char**>(kwlist),
                                                                        &device, &rate, &channels, &format, &buffersize, &name))
                return NULL;
 
index cd6b0ef8c502a5068335e730ef074ced3780a557..a72d8ba393b34ec85d6775053fcd97f6850401e0 100644 (file)
@@ -45,8 +45,7 @@ static const char* state_error = "AUD_SRCResampleReader: SRC State couldn't be "
 
 AUD_SRCResampleReader::AUD_SRCResampleReader(AUD_Reference<AUD_IReader> reader,
                                                                                         AUD_Specs specs) :
-               AUD_EffectReader(reader),
-               m_rate(specs.rate),
+               AUD_ResampleReader(reader, specs.rate),
                m_channels(reader->getSpecs().channels),
                m_position(0)
 {
index 896a742356b94d392a2d92a7efa6674118d0324a..dddfeb6a452962ff1484411a76f8966018efc6e1 100644 (file)
@@ -32,7 +32,7 @@
 #ifndef AUD_SRCRESAMPLEREADER
 #define AUD_SRCRESAMPLEREADER
 
-#include "AUD_EffectReader.h"
+#include "AUD_ResampleReader.h"
 #include "AUD_Buffer.h"
 
 #include <samplerate.h>
@@ -40,7 +40,7 @@
 /**
  * This resampling reader uses libsamplerate for resampling.
  */
-class AUD_SRCResampleReader : public AUD_EffectReader
+class AUD_SRCResampleReader : public AUD_ResampleReader
 {
 private:
        /**
@@ -48,11 +48,6 @@ private:
         */
        AUD_Buffer m_buffer;
 
-       /**
-        * The target sampling rate.
-        */
-       AUD_SampleRate m_rate;
-
        /**
         * The reader channels.
         */
index 62888da14c337c5031c8566c7e15d2ee2562b258..b52243c3fe0b6c121d63dd68385bd65d32af8409 100644 (file)
@@ -795,7 +795,7 @@ void AUD_closeReadDevice(AUD_Device* device)
 float* AUD_readSoundBuffer(const char* filename, float low, float high,
                                                   float attack, float release, float threshold,
                                                   int accumulate, int additive, int square,
-                                                  float sthreshold, int samplerate, int* length)
+                                                  float sthreshold, double samplerate, int* length)
 {
        AUD_Buffer buffer;
        AUD_DeviceSpecs specs;
index fad54cdb7212a3a394c0a2c6fe37d2652496edbb..b818140a5715e978401974197c7a9d1912670af2 100644 (file)
@@ -441,7 +441,7 @@ extern void AUD_closeReadDevice(AUD_Device* device);
 extern float* AUD_readSoundBuffer(const char* filename, float low, float high,
                                                                  float attack, float release, float threshold,
                                                                  int accumulate, int additive, int square,
-                                                                 float sthreshold, int samplerate,
+                                                                 float sthreshold, double samplerate,
                                                                  int* length);
 
 /**
index c227baad73b4dc4b4e7639a7d805274938199949..c33017e912ac9108b4264946d83691284ff58c7d 100644 (file)
@@ -38,8 +38,7 @@
 
 AUD_LinearResampleReader::AUD_LinearResampleReader(AUD_Reference<AUD_IReader> reader,
                                                                                                   AUD_Specs specs) :
-       AUD_EffectReader(reader),
-       m_rate(specs.rate),
+       AUD_ResampleReader(reader, specs.rate),
        m_channels(reader->getSpecs().channels),
        m_position(0),
        m_cache_pos(0),
index 8e0eac612fa151a7c67fe495f1657ff5161581d0..2d92d106697c9bc3d8509fc15d647677b8f178ee 100644 (file)
 #ifndef AUD_LINEARRESAMPLEREADER
 #define AUD_LINEARRESAMPLEREADER
 
-#include "AUD_EffectReader.h"
+#include "AUD_ResampleReader.h"
 #include "AUD_Buffer.h"
 
 /**
  * This resampling reader uses libsamplerate for resampling.
  */
-class AUD_LinearResampleReader : public AUD_EffectReader
+class AUD_LinearResampleReader : public AUD_ResampleReader
 {
 private:
-       /**
-        * The target specification.
-        */
-       AUD_SampleRate m_rate;
-
        /**
         * The reader channels.
         */
index 9e2be46145290cdf339512853194b1164f3894ad..a68d86dcb8328100ba19f953248f3f8e4082fca1 100644 (file)
@@ -81,13 +81,6 @@ public:
         */
        AUD_DeviceSpecs getSpecs() const;
 
-       /**
-        * This funuction prepares a reader for playback.
-        * \param reader The reader to prepare.
-        * \return The reader that should be used for playback.
-        */
-       virtual AUD_Reference<AUD_IReader> prepare(AUD_Reference<AUD_IReader> reader)=0;
-
        /**
         * Mixes a buffer.
         * \param buffer The buffer to superpose.
@@ -95,20 +88,20 @@ public:
         * \param length The length of the buffer in samples.
         * \param volume The mixing volume. Must be a value between 0.0 and 1.0.
         */
-       virtual void mix(sample_t* buffer, int start, int length, float volume);
+       void mix(sample_t* buffer, int start, int length, float volume);
 
        /**
         * Writes the mixing buffer into an output buffer.
         * \param buffer The target buffer for superposing.
         * \param volume The mixing volume. Must be a value between 0.0 and 1.0.
         */
-       virtual void read(data_t* buffer, float volume);
+       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);
+       void clear(int length);
 };
 
 #endif //AUD_MIXER
index eb5177330bb0c16cf555d8e499b2c692fad4968c..5c1876aeb34002eb8b3d3540baa432bbc036c9f7 100644 (file)
@@ -29,7 +29,6 @@
  */
 
 
-#include "AUD_DefaultMixer.h"
 #include "AUD_ReadDevice.h"
 #include "AUD_IReader.h"
 
similarity index 56%
rename from intern/audaspace/intern/AUD_DefaultMixer.cpp
rename to intern/audaspace/intern/AUD_ResampleReader.cpp
index 62992b0201d721d5bb6a178c0d1ade52af5b0782..e74d21eb7438aa3c3ec0b93075f73bc8a766654a 100644 (file)
  * ***** END GPL LICENSE BLOCK *****
  */
 
-/** \file audaspace/intern/AUD_DefaultMixer.cpp
+/** \file audaspace/intern/AUD_ResampleReader.cpp
  *  \ingroup audaspaceintern
  */
 
 
-#include "AUD_DefaultMixer.h"
-#ifdef WITH_SAMPLERATE
-#include "AUD_SRCResampleReader.h"
-#else
-#include "AUD_LinearResampleReader.h"
-#endif
-#include "AUD_ChannelMapperReader.h"
-#include "AUD_ChannelMapperFactory.h"
+#include "AUD_ResampleReader.h"
 
-#include <cstring>
-
-AUD_DefaultMixer::AUD_DefaultMixer(AUD_DeviceSpecs specs) :
-       AUD_Mixer(specs)
+AUD_ResampleReader::AUD_ResampleReader(AUD_Reference<AUD_IReader> reader, AUD_SampleRate rate) :
+       AUD_EffectReader(reader), m_rate(rate)
 {
 }
 
-AUD_Reference<AUD_IReader> AUD_DefaultMixer::prepare(AUD_Reference<AUD_IReader> reader)
+void AUD_ResampleReader::setRate(AUD_SampleRate rate)
 {
-       // resample
-#ifdef WITH_SAMPLERATE
-       reader = new AUD_SRCResampleReader(reader, m_specs.specs);
-#else
-       reader = new AUD_LinearResampleReader(reader, m_specs.specs);
-#endif
-       
-       // rechannel
-       reader = new AUD_ChannelMapperReader(reader, m_specs.channels);
+       m_rate = rate;
+}
 
-       return reader;
+AUD_SampleRate AUD_ResampleReader::getRate()
+{
+       return m_rate;
 }
similarity index 57%
rename from intern/audaspace/intern/AUD_DefaultMixer.h
rename to intern/audaspace/intern/AUD_ResampleReader.h
index 2600a6fc05d777775a792ee02c72c451d130f5b7..4c1a1ece9d92ed9249ed2ab2b4fe32c1806f0d28 100644 (file)
  * ***** END GPL LICENSE BLOCK *****
  */
 
-/** \file audaspace/intern/AUD_DefaultMixer.h
+/** \file audaspace/intern/AUD_ResampleReader.h
  *  \ingroup audaspaceintern
  */
 
+#ifndef AUD_RESAMPLEREADER
+#define AUD_RESAMPLEREADER
 
-#ifndef AUD_DEFAULTMIXER
-#define AUD_DEFAULTMIXER
+#include "AUD_EffectReader.h"
 
-#include "AUD_Mixer.h"
-
-/**
- * This class is able to mix audiosignals of different channel count and sample
- * rate and convert it to a specific output format.
- * It uses a default ChannelMapperFactory and a SRCResampleFactory for
- * the perparation.
- */
-class AUD_DefaultMixer : public AUD_Mixer
+class AUD_ResampleReader : public AUD_EffectReader
 {
-public:
+protected:
        /**
-        * Creates the mixer.
+        * The target sampling rate.
         */
-       AUD_DefaultMixer(AUD_DeviceSpecs specs);
+       AUD_SampleRate m_rate;
 
-       /**
-        * This funuction prepares a reader for playback.
-        * \param reader The reader to prepare.
-        * \return The reader that should be used for playback.
-        */
-       virtual AUD_Reference<AUD_IReader> prepare(AUD_Reference<AUD_IReader> reader);
+       AUD_ResampleReader(AUD_Reference<AUD_IReader> reader, AUD_SampleRate rate);
+
+public:
+       virtual void setRate(AUD_SampleRate rate);
+       AUD_SampleRate getRate();
 };
 
-#endif //AUD_DEFAULTMIXER
+#endif // AUD_RESAMPLEREADER
index 40ac7f3134ba79f20e661a36ab9c4e12b8f6ccaf..9ee0b39c50dbefe99082544817393c311b0f1b96 100644 (file)
 
 
 #include "AUD_SequencerReader.h"
-#include "AUD_DefaultMixer.h"
+#include "AUD_Mixer.h"
+
+#ifdef WITH_SAMPLERATE
+#include "AUD_SRCResampleReader.h"
+#else
+#include "AUD_LinearResampleReader.h"
+#endif
+#include "AUD_ChannelMapperReader.h"
 
 #include <math.h>
 
@@ -46,7 +53,7 @@ AUD_SequencerReader::AUD_SequencerReader(AUD_Reference<AUD_SequencerFactory> fac
        dspecs.specs = specs;
        dspecs.format = AUD_FORMAT_FLOAT32;
 
-       m_mixer = new AUD_DefaultMixer(dspecs);
+       m_mixer = new AUD_Mixer(dspecs);
 
        AUD_Reference<AUD_SequencerStrip> strip;
 
@@ -139,7 +146,16 @@ void AUD_SequencerReader::read(int& length, bool& eos, sample_t* buffer)
                                        {
                                                try
                                                {
-                                                       strip->reader = m_mixer->prepare((*strip->old_sound)->createReader());
+                                                       strip->reader = (*strip->old_sound)->createReader();
+                                                       // resample
+                                                       #ifdef WITH_SAMPLERATE
+                                                               strip->reader = new AUD_SRCResampleReader(strip->reader, m_mixer->getSpecs().specs);
+                                                       #else
+                                                               strip->reader = new AUD_LinearResampleReader(strip->reader, m_mixer->getSpecs().specs);
+                                                       #endif
+
+                                                       // rechannel
+                                                       strip->reader = new AUD_ChannelMapperReader(strip->reader, m_mixer->getSpecs().channels);
                                                }
                                                catch(AUD_Exception)
                                                {
index 288e86bb8d32c653f094be2dcab586d088647fdf..bb5477ed5cfc4f728fb7327b02d8ddb66809db5c 100644 (file)
@@ -77,8 +77,7 @@ void AUD_SinusReader::read(int& length, bool& eos, sample_t* buffer)
        // fill with sine data
        for(int i = 0; i < length; i++)
        {
-               buffer[i] = sin((m_position + i) * 2 * M_PI * m_frequency /
-                                               (float)m_sampleRate);
+               buffer[i] = sin((m_position + i) * 2 * M_PI * m_frequency / m_sampleRate);
        }
 
        m_position += length;
index 8ca735e9ad923f87536383eb261390002b6e6e42..836fbd724d0b920acf3aedb604d39080235f85db 100644 (file)
 
 #include "AUD_SoftwareDevice.h"
 #include "AUD_IReader.h"
-#include "AUD_DefaultMixer.h"
+#include "AUD_Mixer.h"
 #include "AUD_IFactory.h"
+#ifdef WITH_SAMPLERATE
+#include "AUD_SRCResampleReader.h"
+#else
+#include "AUD_LinearResampleReader.h"
+#endif
+#include "AUD_ChannelMapperReader.h"
 
 #include <cstring>
 #include <limits>
@@ -238,7 +244,7 @@ void AUD_SoftwareDevice::create()
 {
        m_playback = false;
        m_volume = 1.0f;
-       m_mixer = new AUD_DefaultMixer(m_specs);
+       m_mixer = new AUD_Mixer(m_specs);
 
        pthread_mutexattr_t attr;
        pthread_mutexattr_init(&attr);
@@ -352,7 +358,16 @@ AUD_DeviceSpecs AUD_SoftwareDevice::getSpecs() const
 AUD_Reference<AUD_IHandle> AUD_SoftwareDevice::play(AUD_Reference<AUD_IReader> reader, bool keep)
 {
        // prepare the reader
-       reader = m_mixer->prepare(reader);
+       // resample
+       #ifdef WITH_SAMPLERATE
+               reader = new AUD_SRCResampleReader(reader, m_specs.specs);
+       #else
+               reader = new AUD_LinearResampleReader(reader, m_specs.specs);
+       #endif
+
+       // rechannel
+       reader = new AUD_ChannelMapperReader(reader, m_specs.channels);
+
        if(reader.isNull())
                return NULL;
 
index 00bc22b97c652d09d2a4176873f4ba1618b9a1fa..308e032ff7f50d99bfe2bf8941c8ba2957334dfc 100644 (file)
@@ -117,7 +117,7 @@ typedef enum
        AUD_RATE_88200   = 88200,               /// 88200 Hz.
        AUD_RATE_96000   = 96000,               /// 96000 Hz.
        AUD_RATE_192000  = 192000               /// 192000 Hz.
-} AUD_SampleRate;
+} AUD_DefaultSampleRate;
 
 /// Status of a playback handle.
 typedef enum
@@ -166,6 +166,9 @@ typedef float sample_t;
 /// Sample data type (format samples)
 typedef unsigned char data_t;
 
+/// Sample rate type.
+typedef double AUD_SampleRate;
+
 /// Specification of a sound source.
 typedef struct
 {