Add Chromium-only Blender WebEngine parity work

This commit is contained in:
mes123456
2026-08-12 04:47:48 -04:00
commit 9fd26010f6
18225 changed files with 11622124 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
/*******************************************************************************
* Copyright 2009-2016 Jörg Müller
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
#pragma once
/**
* @file ChannelMapper.h
* @ingroup respec
* The ChannelMapper class.
*/
#include "respec/SpecsChanger.h"
AUD_NAMESPACE_BEGIN
/**
* This sound creates a reader that maps a sound source's channels to a
* specific output channel count.
*/
class AUD_API ChannelMapper : public SpecsChanger
{
private:
// delete copy constructor and operator=
ChannelMapper(const ChannelMapper&) = delete;
ChannelMapper& operator=(const ChannelMapper&) = delete;
public:
/**
* Creates a new sound.
* \param sound The input sound.
* \param specs The target specifications.
*/
ChannelMapper(std::shared_ptr<ISound> sound, DeviceSpecs specs);
virtual std::shared_ptr<IReader> createReader();
};
AUD_NAMESPACE_END

View File

@@ -0,0 +1,151 @@
/*******************************************************************************
* Copyright 2009-2016 Jörg Müller
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
#pragma once
/**
* @file ChannelMapperReader.h
* @ingroup respec
* The ChannelMapperReader class.
*/
#include "fx/EffectReader.h"
#include "util/Buffer.h"
AUD_NAMESPACE_BEGIN
/**
* This class maps a sound source's channels to a specific output channel count.
* \note The input sample format must be float.
*/
class AUD_API ChannelMapperReader : public EffectReader
{
private:
/**
* The sound reading buffer.
*/
Buffer m_buffer;
/**
* The output specification.
*/
Channels m_target_channels;
/**
* The channel count of the reader.
*/
Channels m_source_channels;
/**
* The mapping specification.
*/
float* m_mapping;
/**
* The size of the mapping.
*/
int m_map_size;
/**
* The mono source angle.
*/
float m_mono_angle;
static const Channel MONO_MAP[];
static const Channel STEREO_MAP[];
static const Channel STEREO_LFE_MAP[];
static const Channel SURROUND4_MAP[];
static const Channel SURROUND5_MAP[];
static const Channel SURROUND51_MAP[];
static const Channel SURROUND61_MAP[];
static const Channel SURROUND71_MAP[];
static const Channel* CHANNEL_MAPS[];
static const float MONO_ANGLES[];
static const float STEREO_ANGLES[];
static const float STEREO_LFE_ANGLES[];
static const float SURROUND4_ANGLES[];
static const float SURROUND5_ANGLES[];
static const float SURROUND51_ANGLES[];
static const float SURROUND61_ANGLES[];
static const float SURROUND71_ANGLES[];
static const float* CHANNEL_ANGLES[];
// delete copy constructor and operator=
ChannelMapperReader(const ChannelMapperReader&) = delete;
ChannelMapperReader& operator=(const ChannelMapperReader&) = delete;
/**
* Calculates the mapping matrix.
*/
void AUD_LOCAL calculateMapping();
/**
* Calculates the distance between two angles.
*/
float AUD_LOCAL angleDistance(float alpha, float beta);
public:
/**
* Creates a channel mapper reader.
* \param reader The reader to map.
* \param channels The target channel count this reader should map to.
*/
ChannelMapperReader(std::shared_ptr<IReader> reader, Channels channels);
/**
* Destroys the reader.
*/
~ChannelMapperReader();
/**
* Returns the channel configuration of the source reader.
* @return The channel configuration of the reader.
*/
Channels getSourceChannels() const;
/**
* Returns the target channel configuration.
* Equals getSpecs().channels.
* @return The target channel configuration.
*/
Channels getChannels() const;
/**
* Sets the requested channel output count.
* \param channels The channel output count.
*/
void setChannels(Channels channels);
/**
* Returns the mapping of the source channel to the target channel.
* @param source The number of the source channel. Should be in the range [0, source channels).
* @param target The number of the target channel. Should be in the range [0, target channels).
* @return The mapping value which should be between 0.0 and 1.0. If source or target are out of range, NaN is returned.
*/
float getMapping(int source, int target);
/**
* Sets the angle for mono sources.
* \param angle The angle for mono sources.
*/
void setMonoAngle(float angle);
virtual Specs getSpecs() const;
virtual void read(int& length, bool& eos, sample_t* buffer);
};
AUD_NAMESPACE_END

View File

@@ -0,0 +1,51 @@
/*******************************************************************************
* Copyright 2009-2016 Jörg Müller
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
#pragma once
/**
* @file Converter.h
* @ingroup respec
* The Converter class.
*/
#include "respec/SpecsChanger.h"
AUD_NAMESPACE_BEGIN
/**
* This sound creates a converter reader that is able to convert from one
* audio format to another.
*/
class AUD_API Converter : public SpecsChanger
{
private:
// delete copy constructor and operator=
Converter(const Converter&) = delete;
Converter& operator=(const Converter&) = delete;
public:
/**
* Creates a new sound.
* \param sound The input sound.
* \param specs The target specifications.
*/
Converter(std::shared_ptr<ISound> sound, DeviceSpecs specs);
virtual std::shared_ptr<IReader> createReader();
};
AUD_NAMESPACE_END

View File

@@ -0,0 +1,377 @@
/*******************************************************************************
* Copyright 2009-2016 Jörg Müller
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
#pragma once
/**
* @file ConverterFunctions.h
* @ingroup respec
* Defines several conversion functions between different sample formats.
*/
#include "Audaspace.h"
#include <cstring>
AUD_NAMESPACE_BEGIN
/**
* The function template for functions converting from one sample format
* to another, having the same parameter order as std::memcpy.
*/
typedef void (*convert_f)(data_t* target, data_t* source, int length);
/**
* The copy conversion function simply calls std::memcpy.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
template <class T>
void convert_copy(data_t* target, data_t* source, int length)
{
std::memcpy(target, source, length*sizeof(T));
}
/**
* @brief Converts from FORMAT_U8 to FORMAT_S16.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_u8_s16(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_U8 to FORMAT_S24 big endian.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_u8_s24_be(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_U8 to FORMAT_S24 little endian.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_u8_s24_le(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_U8 to FORMAT_S32.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_u8_s32(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_U8 to FORMAT_FLOAT32.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_u8_float(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_U8 to FORMAT_FLOAT64.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_u8_double(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S16 to FORMAT_U8.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s16_u8(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S16 to FORMAT_S24 big endian.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s16_s24_be(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S16 to FORMAT_S24 little endian.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s16_s24_le(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S16 to FORMAT_S32.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s16_s32(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S16 to FORMAT_FLOAT32.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s16_float(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S16 to FORMAT_FLOAT64.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s16_double(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S24 big endian to FORMAT_U8.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s24_u8_be(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S24 little endian to FORMAT_U8.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s24_u8_le(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S24 big endian to FORMAT_S16.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s24_s16_be(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S24 little endian to FORMAT_S16.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s24_s16_le(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S24 to FORMAT_S24 simply using std::memcpy.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s24_s24(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S24 big endian to FORMAT_S32.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s24_s32_be(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S24 little endian to FORMAT_S32.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s24_s32_le(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S24 big endian to FORMAT_FLOAT32.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s24_float_be(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S24 little endian to FORMAT_FLOAT32.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s24_float_le(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S24 big endian to FORMAT_FLOAT64.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s24_double_be(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S24 little endian to FORMAT_FLOAT64.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s24_double_le(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S32 to FORMAT_U8.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s32_u8(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S32 to FORMAT_S16.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s32_s16(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S32 to FORMAT_S24 big endian.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s32_s24_be(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S32 to FORMAT_S24 little endian.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s32_s24_le(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S32 to FORMAT_FLOAT32.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s32_float(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_S32 to FORMAT_FLOAT64.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_s32_double(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_FLOAT32 to FORMAT_U8.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_float_u8(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_FLOAT32 to FORMAT_S16.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_float_s16(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_FLOAT32 to FORMAT_S24 big endian.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_float_s24_be(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_FLOAT32 to FORMAT_S24 little endian.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_float_s24_le(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_FLOAT32 to FORMAT_S32.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_float_s32(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_FLOAT32 to FORMAT_FLOAT64.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_float_double(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_FLOAT64 to FORMAT_U8.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_double_u8(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_FLOAT64 to FORMAT_S16.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_double_s16(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_FLOAT64 to FORMAT_S24 big endian.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_double_s24_be(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_FLOAT64 to FORMAT_S24 little endian.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_double_s24_le(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_FLOAT64 to FORMAT_S32.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_double_s32(data_t* target, data_t* source, int length);
/**
* @brief Converts from FORMAT_FLOAT64 to FORMAT_FLOAT32.
* @param target The target buffer.
* @param source The source buffer.
* @param length The amount of samples to be converted.
*/
void AUD_API convert_double_float(data_t* target, data_t* source, int length);
AUD_NAMESPACE_END

View File

@@ -0,0 +1,67 @@
/*******************************************************************************
* Copyright 2009-2016 Jörg Müller
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
#pragma once
/**
* @file ConverterReader.h
* @ingroup respec
* The ConverterReader class.
*/
#include "fx/EffectReader.h"
#include "respec/ConverterFunctions.h"
#include "util/Buffer.h"
AUD_NAMESPACE_BEGIN
/**
* This class converts a sound source from one to another format.
*/
class AUD_API ConverterReader : public EffectReader
{
private:
/**
* The sound output buffer.
*/
Buffer m_buffer;
/**
* The target specification.
*/
SampleFormat m_format;
/**
* Converter function.
*/
convert_f m_convert;
// delete copy constructor and operator=
ConverterReader(const ConverterReader&) = delete;
ConverterReader& operator=(const ConverterReader&) = delete;
public:
/**
* Creates a converter reader.
* \param reader The reader to convert.
* \param specs The target specification.
*/
ConverterReader(std::shared_ptr<IReader> reader, DeviceSpecs specs);
virtual void read(int& length, bool& eos, sample_t* buffer);
};
AUD_NAMESPACE_END

View File

@@ -0,0 +1,52 @@
/*******************************************************************************
* Copyright 2009-2016 Jörg Müller
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
#pragma once
/**
* @file JOSResample.h
* @ingroup respec
* The JOSResample class.
*/
#include "respec/SpecsChanger.h"
AUD_NAMESPACE_BEGIN
/**
* This sound creates a resampling reader that does Julius O. Smith's resampling algorithm.
*/
class AUD_API JOSResample : public SpecsChanger
{
private:
// delete copy constructor and operator=
JOSResample(const JOSResample&) = delete;
JOSResample& operator=(const JOSResample&) = delete;
ResampleQuality m_quality;
public:
/**
* Creates a new sound.
* \param sound The input sound.
* \param specs The target specifications.
*/
JOSResample(std::shared_ptr<ISound> sound, DeviceSpecs specs, ResampleQuality quality = ResampleQuality::HIGH);
virtual std::shared_ptr<IReader> createReader();
};
AUD_NAMESPACE_END

View File

@@ -0,0 +1,170 @@
/*******************************************************************************
* Copyright 2009-2016 Jörg Müller
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
#pragma once
/**
* @file JOSResampleReader.h
* @ingroup respec
* The JOSResampleReader class.
*/
#include "respec/ResampleReader.h"
#include "util/Buffer.h"
AUD_NAMESPACE_BEGIN
/**
* This resampling reader uses Julius O. Smith's resampling algorithm.
*/
class AUD_API JOSResampleReader : public ResampleReader
{
private:
typedef void (JOSResampleReader::*resample_f)(double target_factor, int length, sample_t* buffer);
/**
* The half filter length for HIGH quality setting.
*/
static const int m_len_high;
/**
* The half filter length for MEDIUM quality setting.
*/
static const int m_len_medium;
/**
* The half filter length for LOW quality setting.
*/
static const int m_len_low;
/**
* The filter sample step size for HIGH quality setting.
*/
static const int m_L_high;
/**
* The filter sample step size for MEDIUM quality setting.
*/
static const int m_L_medium;
/**
* The filter sample step size for LOW quality setting.
*/
static const int m_L_low;
/**
* The filter coefficients for HIGH quality setting.
*/
static const float m_coeff_high[];
/**
* The filter coefficients for MEDIUM quality setting.
*/
static const float m_coeff_medium[];
/**
* The filter coefficients for LOW quality setting.
*/
static const float m_coeff_low[];
/**
* The half filter length.
*/
int m_len;
/**
* The sample step size for the filter.
*/
int m_L;
/**
* The filter coefficients.
*/
const float* m_coeff;
/**
* The reader channels.
*/
Channels m_channels;
/**
* The sample position in the cache.
*/
unsigned int m_n;
/**
* The subsample position in the cache.
*/
double m_P;
/**
* The input data buffer.
*/
Buffer m_buffer;
/**
* Double buffer for the sums.
*/
Buffer m_sums;
/**
* How many samples in the cache are valid.
*/
int m_cache_valid;
/**
* Resample function.
*/
resample_f m_resample;
/**
* Last resampling factor.
*/
double m_last_factor;
// delete copy constructor and operator=
JOSResampleReader(const JOSResampleReader&) = delete;
JOSResampleReader& operator=(const JOSResampleReader&) = delete;
/**
* Resets the resampler to its initial state.
*/
void AUD_LOCAL reset();
/**
* Updates the buffer to be as small as possible for the coming reading.
* \param size The size of samples to be read.
* \param factor The next resampling factor.
* \param samplesize The size of a sample.
*/
void AUD_LOCAL updateBuffer(int size, double factor, int samplesize);
void AUD_LOCAL resample_generic(double target_factor, int length, sample_t* buffer);
void AUD_LOCAL resample_mono(double target_factor, int length, sample_t* buffer);
void AUD_LOCAL resample_stereo(double target_factor, int length, sample_t* buffer);
template <typename T>
void AUD_LOCAL resample(double target_factor, int length, sample_t* buffer);
public:
/**
* Creates a resampling reader.
* \param reader The reader to mix.
* \param rate The target sampling rate.
*/
JOSResampleReader(std::shared_ptr<IReader> reader, SampleRate rate, ResampleQuality quality = ResampleQuality::HIGH);
virtual void seek(int position);
virtual int getLength() const;
virtual int getPosition() const;
virtual Specs getSpecs() const;
virtual void read(int& length, bool& eos, sample_t* buffer);
};
AUD_NAMESPACE_END

View File

@@ -0,0 +1,50 @@
/*******************************************************************************
* Copyright 2009-2016 Jörg Müller
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
#pragma once
/**
* @file LinearResample.h
* @ingroup respec
* The LinearResample class.
*/
#include "respec/SpecsChanger.h"
AUD_NAMESPACE_BEGIN
/**
* This sound creates a resampling reader that does simple linear resampling.
*/
class AUD_API LinearResample : public SpecsChanger
{
private:
// delete copy constructor and operator=
LinearResample(const LinearResample&) = delete;
LinearResample& operator=(const LinearResample&) = delete;
public:
/**
* Creates a new sound.
* \param sound The input sound.
* \param specs The target specifications.
*/
LinearResample(std::shared_ptr<ISound> sound, DeviceSpecs specs);
virtual std::shared_ptr<IReader> createReader();
};
AUD_NAMESPACE_END

View File

@@ -0,0 +1,80 @@
/*******************************************************************************
* Copyright 2009-2016 Jörg Müller
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
#pragma once
/**
* @file LinearResampleReader.h
* @ingroup respec
* The LinearResampleReader class.
*/
#include "respec/ResampleReader.h"
#include "util/Buffer.h"
AUD_NAMESPACE_BEGIN
/**
* This resampling reader does simple first-order hold resampling.
*/
class AUD_API LinearResampleReader : public ResampleReader
{
private:
/**
* The reader channels.
*/
Channels m_channels;
/**
* The position in the cache.
*/
float m_cache_pos;
/**
* The sound output buffer.
*/
Buffer m_buffer;
/**
* The input caching buffer.
*/
Buffer m_cache;
/**
* Whether the cache contains valid data.
*/
bool m_cache_ok;
// delete copy constructor and operator=
LinearResampleReader(const LinearResampleReader&) = delete;
LinearResampleReader& operator=(const LinearResampleReader&) = delete;
public:
/**
* Creates a resampling reader.
* \param reader The reader to mix.
* \param rate The target sampling rate.
*/
LinearResampleReader(std::shared_ptr<IReader> reader, SampleRate rate);
virtual void seek(int position);
virtual int getLength() const;
virtual int getPosition() const;
virtual Specs getSpecs() const;
virtual void read(int& length, bool& eos, sample_t* buffer);
};
AUD_NAMESPACE_END

View File

@@ -0,0 +1,129 @@
/*******************************************************************************
* Copyright 2009-2016 Jörg Müller
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
#pragma once
/**
* @file Mixer.h
* @ingroup respec
* The Mixer class.
*/
#include "respec/Specification.h"
#include "respec/ConverterFunctions.h"
#include "util/Buffer.h"
#include <memory>
AUD_NAMESPACE_BEGIN
class IReader;
/**
* This abstract class is able to mix audiosignals with same channel count
* and sample rate and convert it to a specific output format.
*/
class AUD_API Mixer
{
private:
// delete copy constructor and operator=
Mixer(const Mixer&) = delete;
Mixer& operator=(const Mixer&) = delete;
protected:
/**
* The output specification.
*/
DeviceSpecs m_specs;
/**
* The length of the mixing buffer.
*/
int m_length;
/**
* The mixing buffer.
*/
Buffer m_buffer;
/**
* Converter function.
*/
convert_f m_convert;
public:
/**
* Creates the mixer.
*/
Mixer(DeviceSpecs specs);
/**
* Destroys the mixer.
*/
virtual ~Mixer() {}
/**
* Returns the target specification for superposing.
* \return The target specification.
*/
DeviceSpecs getSpecs() const;
/**
* Sets the target specification for superposing.
* \param specs The target specification.
*/
void setSpecs(Specs specs);
/**
* Sets the target specification for superposing.
* \param specs The target specification.
*/
void setSpecs(DeviceSpecs specs);
/**
* 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.
*/
void mix(sample_t* buffer, int start, int length, float volume);
/**
* Mixes a buffer with linear volume interpolation.
* \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_to The target mixing volume. Must be a value between 0.0 and 1.0.
* \param volume_from The start mixing volume. Must be a value between 0.0 and 1.0.
*/
void mix(sample_t* buffer, int start, int length, float volume_to, float volume_from);
/**
* 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.
*/
void read(data_t* buffer, float volume);
/**
* Clears the mixing buffer.
* \param length The length of the buffer in samples.
*/
void clear(int length);
};
AUD_NAMESPACE_END

View File

@@ -0,0 +1,61 @@
/*******************************************************************************
* Copyright 2009-2016 Jörg Müller
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
#pragma once
/**
* @file ResampleReader.h
* @ingroup respec
* The ResampleReader class.
*/
#include "fx/EffectReader.h"
AUD_NAMESPACE_BEGIN
/**
* This is the base class for all resampling readers.
*/
class AUD_API ResampleReader : public EffectReader
{
protected:
/**
* The target sampling rate.
*/
SampleRate m_rate;
/**
* Creates a resampling reader.
* \param reader The reader to mix.
* \param rate The target sampling rate.
*/
ResampleReader(std::shared_ptr<IReader> reader, SampleRate rate);
public:
/**
* Sets the sample rate.
* \param rate The target sampling rate.
*/
virtual void setRate(SampleRate rate);
/**
* Retrieves the sample rate.
* \return The target sampling rate.
*/
virtual SampleRate getRate();
};
AUD_NAMESPACE_END

View File

@@ -0,0 +1,147 @@
/*******************************************************************************
* Copyright 2009-2016 Jörg Müller
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
#pragma once
/**
* @file Specification.h
* @ingroup respec
* Defines all important macros and basic data structures for stream format descriptions.
*/
#include "Audaspace.h"
/// The size of a format in bytes.
#define AUD_FORMAT_SIZE(format) (format & 0x0F)
/// The size of a sample in the specified device format in bytes.
#define AUD_DEVICE_SAMPLE_SIZE(specs) (specs.channels * (specs.format & 0x0F))
/// The size of a sample in the specified format in bytes.
#define AUD_SAMPLE_SIZE(specs) (specs.channels * sizeof(sample_t))
/// Compares two audio data specifications.
#define AUD_COMPARE_SPECS(s1, s2) ((s1.rate == s2.rate) && (s1.channels == s2.channels))
/// Returns the bit for a channel mask.
#define AUD_CHANNEL_BIT(channel) (0x01 << channel)
AUD_NAMESPACE_BEGIN
/**
* The format of a sample.
* The last 4 bit save the byte count of the format.
*/
enum SampleFormat
{
FORMAT_INVALID = 0x00, /// Invalid sample format.
FORMAT_U8 = 0x01, /// 1 byte unsigned byte.
FORMAT_S16 = 0x12, /// 2 byte signed integer.
FORMAT_S24 = 0x13, /// 3 byte signed integer.
FORMAT_S32 = 0x14, /// 4 byte signed integer.
FORMAT_FLOAT32 = 0x24, /// 4 byte float.
FORMAT_FLOAT64 = 0x28 /// 8 byte float.
};
/// The channel count.
enum Channels
{
CHANNELS_INVALID = 0, /// Invalid channel count.
CHANNELS_MONO = 1, /// Mono.
CHANNELS_STEREO = 2, /// Stereo.
CHANNELS_STEREO_LFE = 3, /// Stereo with LFE channel.
CHANNELS_SURROUND4 = 4, /// 4 channel surround sound.
CHANNELS_SURROUND5 = 5, /// 5 channel surround sound.
CHANNELS_SURROUND51 = 6, /// 5.1 surround sound.
CHANNELS_SURROUND61 = 7, /// 6.1 surround sound.
CHANNELS_SURROUND71 = 8 /// 7.1 surround sound.
};
/// The channel names.
enum Channel
{
CHANNEL_FRONT_LEFT = 0,
CHANNEL_FRONT_RIGHT,
CHANNEL_FRONT_CENTER,
CHANNEL_LFE,
CHANNEL_REAR_LEFT,
CHANNEL_REAR_RIGHT,
CHANNEL_REAR_CENTER,
CHANNEL_SIDE_LEFT,
CHANNEL_SIDE_RIGHT,
CHANNEL_MAX
};
/// Resampling algorithm and quality.
enum class ResampleQuality
{
FASTEST = 0, /// Linear resample, very fast but lowest quality.
LOW, /// JOS resample at low quality preset.
MEDIUM, /// JOS resample at medium quality preset.
HIGH /// JOS resample at high quality preset.
};
/**
* The sample rate tells how many samples are played back within one second.
* Some exotic formats may use other sample rates than provided here.
*/
enum DefaultSampleRate
{
RATE_INVALID = 0, /// Invalid sample rate.
RATE_8000 = 8000, /// 8000 Hz.
RATE_16000 = 16000, /// 16000 Hz.
RATE_11025 = 11025, /// 11025 Hz.
RATE_22050 = 22050, /// 22050 Hz.
RATE_32000 = 32000, /// 32000 Hz.
RATE_44100 = 44100, /// 44100 Hz.
RATE_48000 = 48000, /// 48000 Hz.
RATE_88200 = 88200, /// 88200 Hz.
RATE_96000 = 96000, /// 96000 Hz.
RATE_192000 = 192000 /// 192000 Hz.
};
/// Sample rate type.
typedef double SampleRate;
/// Specification of a sound source.
struct Specs
{
/// Sample rate in Hz.
SampleRate rate;
/// Channel count.
Channels channels;
};
/// Specification of a sound device.
struct DeviceSpecs
{
/// Sample format.
SampleFormat format;
union
{
struct
{
/// Sample rate in Hz.
SampleRate rate;
/// Channel count.
Channels channels;
};
Specs specs;
};
};
AUD_NAMESPACE_END

View File

@@ -0,0 +1,74 @@
/*******************************************************************************
* Copyright 2009-2016 Jörg Müller
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
#pragma once
/**
* @file SpecsChanger.h
* @ingroup respec
* The SpecsChanger class.
*/
#include "ISound.h"
#include "respec/Specification.h"
AUD_NAMESPACE_BEGIN
/**
* This sound is a base class for all mixer factories.
*/
class AUD_API SpecsChanger : public ISound
{
protected:
/**
* The target specification for resampling.
*/
const DeviceSpecs m_specs;
/**
* If there is no reader it is created out of this sound.
*/
std::shared_ptr<ISound> m_sound;
/**
* Returns the reader created out of the sound.
* This method can be used for the createReader function of the implementing
* classes.
* \return The reader to mix.
*/
std::shared_ptr<IReader> getReader() const;
public:
/**
* Creates a new sound.
* \param sound The sound to create the readers to mix out of.
* \param specs The target specification.
*/
SpecsChanger(std::shared_ptr<ISound> sound, DeviceSpecs specs);
/**
* Returns the target specification for resampling.
*/
DeviceSpecs getSpecs() const;
/**
* Returns the saved sound.
* \return The sound.
*/
std::shared_ptr<ISound> getSound() const;
};
AUD_NAMESPACE_END