mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-27 07:55:09 +02:00
out of line inline members for coding standard
This commit is contained in:
parent
90379ee7eb
commit
1b2ee4023a
6 changed files with 456 additions and 374 deletions
|
@ -26,7 +26,52 @@ protected:
|
||||||
|
|
||||||
T** _frameBuffer;
|
T** _frameBuffer;
|
||||||
|
|
||||||
void allocateFrames() {
|
void allocateFrames();
|
||||||
|
void deallocateFrames();
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
AudioFrameBuffer();
|
||||||
|
AudioFrameBuffer(const uint32_t channelCount, const uint32_t frameCount);
|
||||||
|
virtual ~AudioFrameBuffer();
|
||||||
|
|
||||||
|
void initialize(const uint32_t channelCount, const uint32_t frameCount);
|
||||||
|
void finalize();
|
||||||
|
|
||||||
|
T**& getFrameData();
|
||||||
|
uint32_t getChannelCount();
|
||||||
|
uint32_t getFrameCount();
|
||||||
|
|
||||||
|
template< typename S >
|
||||||
|
void copyFrames(uint32_t channelCount, const uint32_t frameCount, S* frames, const bool copyOut = false);
|
||||||
|
void zeroFrames();
|
||||||
|
};
|
||||||
|
|
||||||
|
template< typename T >
|
||||||
|
AudioFrameBuffer< T >::AudioFrameBuffer() :
|
||||||
|
_channelCount(0),
|
||||||
|
_frameCount(0),
|
||||||
|
_frameCountMax(0),
|
||||||
|
_frameBuffer(NULL) {
|
||||||
|
}
|
||||||
|
|
||||||
|
template< typename T >
|
||||||
|
AudioFrameBuffer< T >::AudioFrameBuffer(const uint32_t channelCount, const uint32_t frameCount) :
|
||||||
|
_channelCount(channelCount),
|
||||||
|
_channelCountMax(channelCount),
|
||||||
|
_frameCount(frameCount),
|
||||||
|
_frameCountMax(frameCount),
|
||||||
|
_frameBuffer(NULL) {
|
||||||
|
allocateFrames();
|
||||||
|
}
|
||||||
|
|
||||||
|
template< typename T >
|
||||||
|
AudioFrameBuffer< T >::~AudioFrameBuffer() {
|
||||||
|
finalize();
|
||||||
|
}
|
||||||
|
|
||||||
|
template< typename T >
|
||||||
|
void AudioFrameBuffer< T >::allocateFrames() {
|
||||||
_frameBuffer = new T*[_channelCountMax];
|
_frameBuffer = new T*[_channelCountMax];
|
||||||
if (_frameBuffer) {
|
if (_frameBuffer) {
|
||||||
for (uint32_t i = 0; i < _channelCountMax; ++i) {
|
for (uint32_t i = 0; i < _channelCountMax; ++i) {
|
||||||
|
@ -35,7 +80,8 @@ protected:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void deallocateFrames() {
|
template< typename T >
|
||||||
|
void AudioFrameBuffer< T >::deallocateFrames() {
|
||||||
if (_frameBuffer) {
|
if (_frameBuffer) {
|
||||||
for (uint32_t i = 0; i < _channelCountMax; ++i) {
|
for (uint32_t i = 0; i < _channelCountMax; ++i) {
|
||||||
delete _frameBuffer[i];
|
delete _frameBuffer[i];
|
||||||
|
@ -45,29 +91,8 @@ protected:
|
||||||
_frameBuffer = NULL;
|
_frameBuffer = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
template< typename T >
|
||||||
|
void AudioFrameBuffer< T >::initialize(const uint32_t channelCount, const uint32_t frameCount) {
|
||||||
AudioFrameBuffer() :
|
|
||||||
_channelCount(0),
|
|
||||||
_frameCount(0),
|
|
||||||
_frameCountMax(0),
|
|
||||||
_frameBuffer(NULL) {
|
|
||||||
}
|
|
||||||
|
|
||||||
AudioFrameBuffer(const uint32_t channelCount, const uint32_t frameCount) :
|
|
||||||
_channelCount(channelCount),
|
|
||||||
_channelCountMax(channelCount),
|
|
||||||
_frameCount(frameCount),
|
|
||||||
_frameCountMax(frameCount),
|
|
||||||
_frameBuffer(NULL) {
|
|
||||||
allocateFrames();
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~AudioFrameBuffer() {
|
|
||||||
finalize();
|
|
||||||
}
|
|
||||||
|
|
||||||
void initialize(const uint32_t channelCount, const uint32_t frameCount) {
|
|
||||||
if (_frameBuffer) {
|
if (_frameBuffer) {
|
||||||
finalize();
|
finalize();
|
||||||
}
|
}
|
||||||
|
@ -78,7 +103,8 @@ public:
|
||||||
allocateFrames();
|
allocateFrames();
|
||||||
}
|
}
|
||||||
|
|
||||||
void finalize() {
|
template< typename T >
|
||||||
|
void AudioFrameBuffer< T >::finalize() {
|
||||||
deallocateFrames();
|
deallocateFrames();
|
||||||
_channelCount = 0;
|
_channelCount = 0;
|
||||||
_channelCountMax = 0;
|
_channelCountMax = 0;
|
||||||
|
@ -86,19 +112,23 @@ public:
|
||||||
_frameCountMax = 0;
|
_frameCountMax = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
T**& getFrameData() {
|
template< typename T >
|
||||||
|
inline T**& AudioFrameBuffer< T >::getFrameData() {
|
||||||
return _frameBuffer;
|
return _frameBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t getChannelCount() {
|
template< typename T >
|
||||||
|
inline uint32_t AudioFrameBuffer< T >::getChannelCount() {
|
||||||
return _channelCount;
|
return _channelCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t getFrameCount() {
|
template< typename T >
|
||||||
|
inline uint32_t AudioFrameBuffer< T >::getFrameCount() {
|
||||||
return _frameCount;
|
return _frameCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
void zeroFrames() {
|
template< typename T >
|
||||||
|
inline void AudioFrameBuffer< T >::zeroFrames() {
|
||||||
if (!_frameBuffer) {
|
if (!_frameBuffer) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -107,8 +137,9 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template< typename T >
|
||||||
template< typename S >
|
template< typename S >
|
||||||
void copyFrames(uint32_t channelCount, const uint32_t frameCount, S* frames, const bool copyOut = false) {
|
inline void AudioFrameBuffer< T >::copyFrames(uint32_t channelCount, const uint32_t frameCount, S* frames, const bool copyOut) {
|
||||||
if ( !_frameBuffer || !frames) {
|
if ( !_frameBuffer || !frames) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -205,7 +236,6 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
typedef AudioFrameBuffer< float32_t > AudioBufferFloat32;
|
typedef AudioFrameBuffer< float32_t > AudioBufferFloat32;
|
||||||
typedef AudioFrameBuffer< int32_t > AudioBufferSInt32;
|
typedef AudioFrameBuffer< int32_t > AudioBufferSInt32;
|
||||||
|
|
|
@ -13,21 +13,13 @@
|
||||||
#define hifi_AudioEditBuffer_h
|
#define hifi_AudioEditBuffer_h
|
||||||
|
|
||||||
template< typename T >
|
template< typename T >
|
||||||
class AudioEditBuffer
|
class AudioEditBuffer : public AudioFrameBuffer<T> {
|
||||||
: public AudioFrameBuffer<T> {
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
AudioEditBuffer() :
|
AudioEditBuffer();
|
||||||
AudioFrameBuffer<T>() {
|
AudioEditBuffer(const uint32_t channelCount, const uint32_t frameCount);
|
||||||
}
|
~AudioEditBuffer();
|
||||||
|
|
||||||
AudioEditBuffer(const uint32_t channelCount, const uint32_t frameCount) :
|
|
||||||
AudioFrameBuffer<T>(channelCount, frameCount) {
|
|
||||||
}
|
|
||||||
|
|
||||||
~AudioEditBuffer() {
|
|
||||||
}
|
|
||||||
|
|
||||||
bool getZeroCrossing(uint32_t start, bool direction, float32_t epsilon, uint32_t& zero);
|
bool getZeroCrossing(uint32_t start, bool direction, float32_t epsilon, uint32_t& zero);
|
||||||
|
|
||||||
|
@ -36,7 +28,21 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
template< typename T >
|
template< typename T >
|
||||||
bool AudioEditBuffer<T>::getZeroCrossing(uint32_t start, bool direction, float32_t epsilon, uint32_t& zero) {
|
AudioEditBuffer<T>::AudioEditBuffer() :
|
||||||
|
AudioFrameBuffer<T>() {
|
||||||
|
}
|
||||||
|
|
||||||
|
template< typename T >
|
||||||
|
AudioEditBuffer<T>::AudioEditBuffer(const uint32_t channelCount, const uint32_t frameCount) :
|
||||||
|
AudioFrameBuffer<T>(channelCount, frameCount) {
|
||||||
|
}
|
||||||
|
|
||||||
|
template< typename T >
|
||||||
|
AudioEditBuffer<T>::~AudioEditBuffer() {
|
||||||
|
}
|
||||||
|
|
||||||
|
template< typename T >
|
||||||
|
inline bool AudioEditBuffer<T>::getZeroCrossing(uint32_t start, bool direction, float32_t epsilon, uint32_t& zero) {
|
||||||
|
|
||||||
zero = this->_frameCount;
|
zero = this->_frameCount;
|
||||||
|
|
||||||
|
@ -69,7 +75,7 @@ bool AudioEditBuffer<T>::getZeroCrossing(uint32_t start, bool direction, float32
|
||||||
}
|
}
|
||||||
|
|
||||||
template< typename T >
|
template< typename T >
|
||||||
void AudioEditBuffer<T>::linearFade(uint32_t start, uint32_t stop, bool slope) {
|
inline void AudioEditBuffer<T>::linearFade(uint32_t start, uint32_t stop, bool slope) {
|
||||||
|
|
||||||
if (start >= stop || start > this->_frameCount || stop > this->_frameCount ) {
|
if (start >= stop || start > this->_frameCount || stop > this->_frameCount ) {
|
||||||
return;
|
return;
|
||||||
|
@ -97,7 +103,7 @@ void AudioEditBuffer<T>::linearFade(uint32_t start, uint32_t stop, bool slope) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template< typename T >
|
template< typename T >
|
||||||
void AudioEditBuffer<T>::exponentialFade(uint32_t start, uint32_t stop, bool slope) {
|
inline void AudioEditBuffer<T>::exponentialFade(uint32_t start, uint32_t stop, bool slope) {
|
||||||
// TBD
|
// TBD
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
48
libraries/audio/src/AudioGain.cpp
Normal file
48
libraries/audio/src/AudioGain.cpp
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
//
|
||||||
|
// AudioGain.cpp
|
||||||
|
// hifi
|
||||||
|
//
|
||||||
|
// Created by Craig Hansen-Sturm on 9/10/14.
|
||||||
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <SharedUtil.h>
|
||||||
|
#include "AudioRingBuffer.h"
|
||||||
|
#include "AudioFormat.h"
|
||||||
|
#include "AudioBuffer.h"
|
||||||
|
#include "AudioGain.h"
|
||||||
|
|
||||||
|
AudioGain::AudioGain() {
|
||||||
|
initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
AudioGain::~AudioGain() {
|
||||||
|
finalize();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AudioGain::initialize() {
|
||||||
|
setParameters(1.0f,0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AudioGain::finalize() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void AudioGain::reset() {
|
||||||
|
initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AudioGain::setParameters(const float gain, const float mute) {
|
||||||
|
_gain = std::min(std::max(gain, 0.0f), 1.0f);
|
||||||
|
_mute = mute != 0.0f;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void AudioGain::getParameters(float& gain, float& mute) {
|
||||||
|
gain = _gain;
|
||||||
|
mute = _mute ? 1.0f : 0.0f;
|
||||||
|
}
|
|
@ -18,37 +18,21 @@ class AudioGain
|
||||||
bool _mute;
|
bool _mute;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AudioGain() {
|
AudioGain();
|
||||||
initialize();
|
~AudioGain();
|
||||||
}
|
|
||||||
|
|
||||||
~AudioGain() {
|
void initialize();
|
||||||
finalize();
|
void finalize();
|
||||||
}
|
void reset();
|
||||||
|
|
||||||
void initialize() {
|
void setParameters(const float gain, const float mute);
|
||||||
setParameters(1.0f,0.0f);
|
void getParameters(float& gain, float& mute);
|
||||||
}
|
|
||||||
|
|
||||||
void finalize() {
|
void render(AudioBufferFloat32& frameBuffer);
|
||||||
}
|
};
|
||||||
|
|
||||||
void reset() {
|
|
||||||
initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
void setParameters(const float gain, const float mute) {
|
inline void AudioGain::render(AudioBufferFloat32& frameBuffer) {
|
||||||
_gain = std::min(std::max(gain, 0.0f), 1.0f);
|
|
||||||
_mute = mute != 0.0f;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void getParameters(float& gain, float& mute) {
|
|
||||||
gain = _gain;
|
|
||||||
mute = _mute ? 1.0f : 0.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
void render(AudioBufferFloat32& frameBuffer) {
|
|
||||||
if (_mute) {
|
if (_mute) {
|
||||||
frameBuffer.zeroFrames();
|
frameBuffer.zeroFrames();
|
||||||
return;
|
return;
|
||||||
|
@ -130,7 +114,6 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
#endif // AudioGain_h
|
#endif // AudioGain_h
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
//
|
//
|
||||||
// AudioSourceTone.cpp
|
// AudioPan.cpp
|
||||||
// hifi
|
// hifi
|
||||||
//
|
//
|
||||||
// Created by Craig Hansen-Sturm on 8/10/14.
|
// Created by Craig Hansen-Sturm on 9/10/14.
|
||||||
// Copyright 2014 High Fidelity, Inc.
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
//
|
//
|
||||||
// Distributed under the Apache License, Version 2.0.
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
@ -21,3 +21,32 @@ float32_t AudioPan::ONE_MINUS_EPSILON = 1.0f - EPSILON;
|
||||||
float32_t AudioPan::ZERO_PLUS_EPSILON = 0.0f + EPSILON;
|
float32_t AudioPan::ZERO_PLUS_EPSILON = 0.0f + EPSILON;
|
||||||
float32_t AudioPan::ONE_HALF_MINUS_EPSILON = 0.5f - EPSILON;
|
float32_t AudioPan::ONE_HALF_MINUS_EPSILON = 0.5f - EPSILON;
|
||||||
float32_t AudioPan::ONE_HALF_PLUS_EPSILON = 0.5f + EPSILON;
|
float32_t AudioPan::ONE_HALF_PLUS_EPSILON = 0.5f + EPSILON;
|
||||||
|
|
||||||
|
AudioPan::AudioPan() {
|
||||||
|
initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
AudioPan::~AudioPan() {
|
||||||
|
finalize();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AudioPan::initialize() {
|
||||||
|
setParameters(0.5f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AudioPan::finalize() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void AudioPan::reset() {
|
||||||
|
initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AudioPan::setParameters(const float32_t pan) {
|
||||||
|
// pan ranges between 0.0 and 1.0f inclusive. 0.5f is midpoint between full left and full right
|
||||||
|
_pan = std::min(std::max(pan, 0.0f), 1.0f);
|
||||||
|
updateCoefficients();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AudioPan::getParameters(float32_t& pan) {
|
||||||
|
pan = _pan;
|
||||||
|
}
|
||||||
|
|
|
@ -23,59 +23,24 @@ class AudioPan
|
||||||
static float32_t ONE_HALF_MINUS_EPSILON;
|
static float32_t ONE_HALF_MINUS_EPSILON;
|
||||||
static float32_t ONE_HALF_PLUS_EPSILON;
|
static float32_t ONE_HALF_PLUS_EPSILON;
|
||||||
|
|
||||||
void updateCoefficients() {
|
void updateCoefficients();
|
||||||
|
|
||||||
// implement constant power sin^2 + cos^2 = 1 panning law
|
|
||||||
|
|
||||||
if (_pan >= ONE_MINUS_EPSILON) { // full right
|
|
||||||
_gainLeft = 0.0f;
|
|
||||||
_gainRight = 1.0f;
|
|
||||||
}
|
|
||||||
else if (_pan <= ZERO_PLUS_EPSILON) { // full left
|
|
||||||
_gainLeft = 1.0f;
|
|
||||||
_gainRight = 0.0f;
|
|
||||||
}
|
|
||||||
else if ((_pan >= ONE_HALF_MINUS_EPSILON) && (_pan <= ONE_HALF_PLUS_EPSILON)) { // center
|
|
||||||
_gainLeft = 1.0f / SQUARE_ROOT_OF_2;
|
|
||||||
_gainRight = 1.0f / SQUARE_ROOT_OF_2;
|
|
||||||
}
|
|
||||||
else { // intermediate cases
|
|
||||||
_gainLeft = cosf( TWO_PI * _pan );
|
|
||||||
_gainRight = sinf( TWO_PI * _pan );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AudioPan() {
|
AudioPan();
|
||||||
initialize();
|
~AudioPan();
|
||||||
}
|
|
||||||
|
|
||||||
~AudioPan() {
|
void initialize();
|
||||||
finalize();
|
void finalize();
|
||||||
}
|
void reset();
|
||||||
|
|
||||||
void initialize() {
|
void setParameters(const float32_t pan);
|
||||||
setParameters(0.5f);
|
void getParameters(float32_t& pan);
|
||||||
}
|
|
||||||
|
|
||||||
void finalize() {
|
void render(AudioBufferFloat32& frameBuffer);
|
||||||
}
|
};
|
||||||
|
|
||||||
void reset() {
|
|
||||||
initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
void setParameters(const float32_t pan) {
|
inline void AudioPan::render(AudioBufferFloat32& frameBuffer) {
|
||||||
// pan ranges between 0.0 and 1.0f inclusive. 0.5f is midpoint between full left and full right
|
|
||||||
_pan = std::min(std::max(pan, 0.0f), 1.0f);
|
|
||||||
updateCoefficients();
|
|
||||||
}
|
|
||||||
|
|
||||||
void getParameters(float32_t& pan) {
|
|
||||||
pan = _pan;
|
|
||||||
}
|
|
||||||
|
|
||||||
void render(AudioBufferFloat32& frameBuffer) {
|
|
||||||
|
|
||||||
if (frameBuffer.getChannelCount() != 2) {
|
if (frameBuffer.getChannelCount() != 2) {
|
||||||
return;
|
return;
|
||||||
|
@ -134,7 +99,28 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
inline void AudioPan::updateCoefficients() {
|
||||||
|
|
||||||
|
// implement constant power sin^2 + cos^2 = 1 panning law
|
||||||
|
|
||||||
|
if (_pan >= ONE_MINUS_EPSILON) { // full right
|
||||||
|
_gainLeft = 0.0f;
|
||||||
|
_gainRight = 1.0f;
|
||||||
|
}
|
||||||
|
else if (_pan <= ZERO_PLUS_EPSILON) { // full left
|
||||||
|
_gainLeft = 1.0f;
|
||||||
|
_gainRight = 0.0f;
|
||||||
|
}
|
||||||
|
else if ((_pan >= ONE_HALF_MINUS_EPSILON) && (_pan <= ONE_HALF_PLUS_EPSILON)) { // center
|
||||||
|
_gainLeft = 1.0f / SQUARE_ROOT_OF_2;
|
||||||
|
_gainRight = 1.0f / SQUARE_ROOT_OF_2;
|
||||||
|
}
|
||||||
|
else { // intermediate cases
|
||||||
|
_gainLeft = cosf( TWO_PI * _pan );
|
||||||
|
_gainRight = sinf( TWO_PI * _pan );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif // AudioPan_h
|
#endif // AudioPan_h
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue