diff options
author | Joerg Mueller <nexyon@gmail.com> | 2011-06-22 00:29:02 +0400 |
---|---|---|
committer | Joerg Mueller <nexyon@gmail.com> | 2011-06-22 00:29:02 +0400 |
commit | fba07308bf939352f6db4abbc19983a1d435060e (patch) | |
tree | 73ba8b2759dbb0c41b475324ac145394b6f82aa3 /intern | |
parent | d5eaffda23274271e28bf499bd8d4555b0077079 (diff) |
3D Audio GSoC:
- Converting AUD_SampleRate to a double
- Removing AUD_DefaultMixer
- Introducing AUD_ResampleReader as base class for all resampling readers.
Diffstat (limited to 'intern')
17 files changed, 82 insertions, 91 deletions
diff --git a/intern/audaspace/CMakeLists.txt b/intern/audaspace/CMakeLists.txt index 9c75cd67e6a..df9597612d5 100644 --- a/intern/audaspace/CMakeLists.txt +++ b/intern/audaspace/CMakeLists.txt @@ -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 diff --git a/intern/audaspace/FX/AUD_PitchReader.cpp b/intern/audaspace/FX/AUD_PitchReader.cpp index 7f8b8b53105..84a76c64ef9 100644 --- a/intern/audaspace/FX/AUD_PitchReader.cpp +++ b/intern/audaspace/FX/AUD_PitchReader.cpp @@ -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; } diff --git a/intern/audaspace/Python/AUD_PyAPI.cpp b/intern/audaspace/Python/AUD_PyAPI.cpp index 2a4cee4dd0e..12bb19644f0 100644 --- a/intern/audaspace/Python/AUD_PyAPI.cpp +++ b/intern/audaspace/Python/AUD_PyAPI.cpp @@ -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; diff --git a/intern/audaspace/SRC/AUD_SRCResampleReader.cpp b/intern/audaspace/SRC/AUD_SRCResampleReader.cpp index cd6b0ef8c50..a72d8ba393b 100644 --- a/intern/audaspace/SRC/AUD_SRCResampleReader.cpp +++ b/intern/audaspace/SRC/AUD_SRCResampleReader.cpp @@ -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) { diff --git a/intern/audaspace/SRC/AUD_SRCResampleReader.h b/intern/audaspace/SRC/AUD_SRCResampleReader.h index 896a742356b..dddfeb6a452 100644 --- a/intern/audaspace/SRC/AUD_SRCResampleReader.h +++ b/intern/audaspace/SRC/AUD_SRCResampleReader.h @@ -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: /** @@ -49,11 +49,6 @@ private: AUD_Buffer m_buffer; /** - * The target sampling rate. - */ - AUD_SampleRate m_rate; - - /** * The reader channels. */ AUD_Channels m_channels; diff --git a/intern/audaspace/intern/AUD_C-API.cpp b/intern/audaspace/intern/AUD_C-API.cpp index 62888da14c3..b52243c3fe0 100644 --- a/intern/audaspace/intern/AUD_C-API.cpp +++ b/intern/audaspace/intern/AUD_C-API.cpp @@ -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; diff --git a/intern/audaspace/intern/AUD_C-API.h b/intern/audaspace/intern/AUD_C-API.h index fad54cdb721..b818140a571 100644 --- a/intern/audaspace/intern/AUD_C-API.h +++ b/intern/audaspace/intern/AUD_C-API.h @@ -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); /** diff --git a/intern/audaspace/intern/AUD_LinearResampleReader.cpp b/intern/audaspace/intern/AUD_LinearResampleReader.cpp index c227baad73b..c33017e912a 100644 --- a/intern/audaspace/intern/AUD_LinearResampleReader.cpp +++ b/intern/audaspace/intern/AUD_LinearResampleReader.cpp @@ -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), diff --git a/intern/audaspace/intern/AUD_LinearResampleReader.h b/intern/audaspace/intern/AUD_LinearResampleReader.h index 8e0eac612fa..2d92d106697 100644 --- a/intern/audaspace/intern/AUD_LinearResampleReader.h +++ b/intern/audaspace/intern/AUD_LinearResampleReader.h @@ -32,21 +32,16 @@ #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. */ AUD_Channels m_channels; diff --git a/intern/audaspace/intern/AUD_Mixer.h b/intern/audaspace/intern/AUD_Mixer.h index 9e2be461452..a68d86dcb83 100644 --- a/intern/audaspace/intern/AUD_Mixer.h +++ b/intern/audaspace/intern/AUD_Mixer.h @@ -82,33 +82,26 @@ 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. * \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 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 diff --git a/intern/audaspace/intern/AUD_ReadDevice.cpp b/intern/audaspace/intern/AUD_ReadDevice.cpp index eb5177330bb..5c1876aeb34 100644 --- a/intern/audaspace/intern/AUD_ReadDevice.cpp +++ b/intern/audaspace/intern/AUD_ReadDevice.cpp @@ -29,7 +29,6 @@ */ -#include "AUD_DefaultMixer.h" #include "AUD_ReadDevice.h" #include "AUD_IReader.h" diff --git a/intern/audaspace/intern/AUD_DefaultMixer.cpp b/intern/audaspace/intern/AUD_ResampleReader.cpp index 62992b0201d..e74d21eb743 100644 --- a/intern/audaspace/intern/AUD_DefaultMixer.cpp +++ b/intern/audaspace/intern/AUD_ResampleReader.cpp @@ -24,38 +24,24 @@ * ***** 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; } diff --git a/intern/audaspace/intern/AUD_DefaultMixer.h b/intern/audaspace/intern/AUD_ResampleReader.h index 2600a6fc05d..4c1a1ece9d9 100644 --- a/intern/audaspace/intern/AUD_DefaultMixer.h +++ b/intern/audaspace/intern/AUD_ResampleReader.h @@ -24,36 +24,28 @@ * ***** 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 diff --git a/intern/audaspace/intern/AUD_SequencerReader.cpp b/intern/audaspace/intern/AUD_SequencerReader.cpp index 40ac7f3134b..9ee0b39c50d 100644 --- a/intern/audaspace/intern/AUD_SequencerReader.cpp +++ b/intern/audaspace/intern/AUD_SequencerReader.cpp @@ -30,7 +30,14 @@ #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) { diff --git a/intern/audaspace/intern/AUD_SinusReader.cpp b/intern/audaspace/intern/AUD_SinusReader.cpp index 288e86bb8d3..bb5477ed5cf 100644 --- a/intern/audaspace/intern/AUD_SinusReader.cpp +++ b/intern/audaspace/intern/AUD_SinusReader.cpp @@ -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; diff --git a/intern/audaspace/intern/AUD_SoftwareDevice.cpp b/intern/audaspace/intern/AUD_SoftwareDevice.cpp index 8ca735e9ad9..836fbd724d0 100644 --- a/intern/audaspace/intern/AUD_SoftwareDevice.cpp +++ b/intern/audaspace/intern/AUD_SoftwareDevice.cpp @@ -31,8 +31,14 @@ #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; diff --git a/intern/audaspace/intern/AUD_Space.h b/intern/audaspace/intern/AUD_Space.h index 00bc22b97c6..308e032ff7f 100644 --- a/intern/audaspace/intern/AUD_Space.h +++ b/intern/audaspace/intern/AUD_Space.h @@ -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 { |