Commit a521732e authored by Dipl.-Ing. Jonas Stienen's avatar Dipl.-Ing. Jonas Stienen
Browse files

Fixing non-zero zero init, refactoring, style.

parent 275a500f
/*
* ----------------------------------------------------------------
*
* ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2016
*
* ----------------------------------------------------------------
* ____ __________ _______
* // / //__ ___/ // _ |
* // / // / // /_| |
* // / // / // ___ |
* //__/ //__/ //__/ |__|
*
* ----------------------------------------------------------------
*
*/
// $Id: ITASampleBuffer.h 4124 2015-07-14 13:00:26Z fwefers $
* ----------------------------------------------------------------
*
* ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2016
*
* ----------------------------------------------------------------
* ____ __________ _______
* // / //__ ___/ // _ |
* // / // / // /_| |
* // / // / // ___ |
* //__/ //__/ //__/ |__|
*
* ----------------------------------------------------------------
*
*/
#ifndef INCLUDE_WATCHER_ITA_SAMPLE_BUFFER
#define INCLUDE_WATCHER_ITA_SAMPLE_BUFFER
......@@ -42,7 +41,7 @@ public:
/**
* \param iLength Length (size) of buffer in samples
*/
explicit ITASampleBuffer( int iLength, bool bZeroinit = true );
explicit ITASampleBuffer( int iLength, bool bZeroInit = true );
//! Copy constructor as pointer
/**
......@@ -61,14 +60,24 @@ public:
bool IsEmpty() const;
//! Deprecated
inline int length() { return GetLength() ; };
inline int length()
{
return GetLength();
};
//! Length (size) of buffer (number of samples)
int GetLength() const;
//! Deprecated
inline const float* data() const { return GetData(); };
inline float* data() { return GetData(); };
inline const float* data() const
{
return GetData();
};
inline float* data()
{
return GetData();
};
//! Data pointer read-only
const float* GetData() const;
......@@ -79,11 +88,11 @@ public:
//! Initialize
/**
* (Re-)Initialize a sample buffer
*
* \param iLength Number of new samples
* \param bZeroinit Init with zeros
*
* \param iLength Number of new samples
* \param bZeroInit Init with zeros
*/
void Init( int iLength, bool bZeroinit = true );
void Init( int iLength, bool bZeroInit = true );
//! Free allocated samples
void Free();
......@@ -97,13 +106,13 @@ public:
* \param iCount Anzahl Samples
* \param fFloat Wert
*/
void Fill(int iOffset, int iCount, float fValue );
void Fill( int iOffset, int iCount, float fValue );
//! Sets all samples to zero
void Zero();
//! Sets given samples to zero
void Zero(int iOffset, int iCount, float fValue);
void Zero( int iOffset, int iCount );
//! Sets a Cronecker-Delta function (diskrete Dirac impulse)
void Identity();
......@@ -112,7 +121,7 @@ public:
/**
* Fades in sample region [iOffset, iOffset+iCount] using given fading function
*/
void Fade(int iOffset, int iCount, int iFadeDirection, int iFadeFunction);
void Fade( int iOffset, int iCount, int iFadeDirection, int iFadeFunction );
//! Crossfade
/**
......@@ -124,17 +133,17 @@ public:
* Danach werden iCount Samples zwischen den beiden Puffern kreuzgeblendet.
* Dahinter folgen nur noch Samples dieses Puffers.
*/
void Crossfade(const ITASampleBuffer* psbSrc, int iOffset, int iCount, int iFadeDirection, int iFadeFunction);
void Crossfade(const ITASampleBuffer& sbSrc, int iOffset, int iCount, int iFadeDirection, int iFadeFunction);
void Crossfade( const ITASampleBuffer* psbSrc, int iOffset, int iCount, int iFadeDirection, int iFadeFunction );
void Crossfade( const ITASampleBuffer& sbSrc, int iOffset, int iCount, int iFadeDirection, int iFadeFunction );
//! Envelope
/**
/* Wendet eine lineare Einhllende (envelope) auf den Puffer an.
*
* \param fGain0 Startwert [0..1]
* \param fGain1 Endwert [0..1]
*/
void Envelope(float fGain0, float fGain1);
*
* \param fGain0 Startwert [0..1]
* \param fGain1 Endwert [0..1]
*/
void Envelope( float fGain0, float fGain1 );
//! Samples in ein Array kopieren
/**
......@@ -148,12 +157,12 @@ public:
* TODO: Memory alignment fr SSE?
* \note Kein Lesen ber das Pufferende hinaus!
*/
void read(float* pfDest, int iCount, int iSrcOffset=0) const;
void read( float* pfDest, int iCount, int iSrcOffset = 0 ) const;
//! Samples aus einem Array in den Puffer kopieren
/**
* Kopiert iCount Samples aus angegebenen Array beginnend bei Leseposition 0
* in den Puffer (SampleBuffer), dort beginnend ab Schreibposition iDestOffset.
* in den Puffer (SampleBuffer), dort beginnend ab Schreibposition iDestOffset.
*
* \param pfSrc Quellarray
* \param iCount Anzahl zu kopierender Samples
......@@ -161,12 +170,12 @@ public:
*
* \note Kein Schreiben ber das Pufferende hinaus!
*/
void write(const float* pfSrc, int iCount, int iDestOffset=0);
void write( const float* pfSrc, int iCount, int iDestOffset = 0 );
//! Samples aus einem anderen Puffer in den Puffer kopieren
/**
* Kopiert iCount Samples aus angegebenen Puffer beginnend bei Leseposition iSrcOffset
* in disen Puffer, dort beginnend ab Schreibposition iDestOffset.
* in disen Puffer, dort beginnend ab Schreibposition iDestOffset.
*
* \param psbSrc Quellpuffer
* \param iCount Anzahl zu kopierender Samples
......@@ -175,8 +184,8 @@ public:
*
* \note Kein Schreiben ber das Pufferende hinaus!
*/
void write(const ITASampleBuffer* psbSrc, int iCount, int iSrcOffset=0, int iDestOffset=0);
void write(const ITASampleBuffer& sbSrc, int iCount, int iSrcOffset=0, int iDestOffset=0);
void write( const ITASampleBuffer* psbSrc, int iCount, int iSrcOffset = 0, int iDestOffset = 0 );
void write( const ITASampleBuffer& sbSrc, int iCount, int iSrcOffset = 0, int iDestOffset = 0 );
//! Zyklisches Lesen
/**
......@@ -192,7 +201,7 @@ public:
*
* TODO: Memory alignment fr SSE?
*/
void cyclic_read(float* pfDest, int iCount, int iSrcOffset=0) const;
void cyclic_read( float* pfDest, int iCount, int iSrcOffset = 0 ) const;
//! Zyklisches Schreiben
/**
......@@ -208,7 +217,7 @@ public:
*
* TODO: Memory alignment fr SSE?
*/
void cyclic_write(const float* pfSrc, int iCount, int iDestOffset=0);
void cyclic_write( const float* pfSrc, int iCount, int iDestOffset = 0 );
//! Zyklisches Schreiben
/**
......@@ -225,26 +234,26 @@ public:
*
* TODO: Memory alignment fr SSE?
*/
void cyclic_write(const ITASampleBuffer* psbSrc, int iCount, int iSrcOffset=0, int iDestOffset=0);
void cyclic_write(const ITASampleBuffer& sbSrc, int iCount, int iSrcOffset=0, int iDestOffset=0);
void cyclic_write( const ITASampleBuffer* psbSrc, int iCount, int iSrcOffset = 0, int iDestOffset = 0 );
void cyclic_write( const ITASampleBuffer& sbSrc, int iCount, int iSrcOffset = 0, int iDestOffset = 0 );
//! Cyclic shifting of samples
/**
* @param [in] iCount Shifts the samples in buffer by given count
*/
void CyclicShift(int iCount);
void CyclicShift( int iCount );
//! In-place Addition: Jedem Sample einen konstanten Wert addieren
void add_scalar(float fValue);
void add_scalar( float fValue );
//! In-place Subtraktion: Jedem Sample einen konstanten Wert subtrahieren
void sub_scalar(float fValue);
void sub_scalar( float fValue );
//! In-place Multiplikation: Jedes Sample mit einem konstanten Wert multiplizieren
void mul_scalar(float fValue);
void mul_scalar( float fValue );
//! In-place Division: Jedes Sample durch einen konstanten Wert dividieren
void div_scalar(float fValue);
void div_scalar( float fValue );
// TODO: Bereiche Addieren usw.
......@@ -252,21 +261,21 @@ public:
/*
* - Mssen gleiche Lngen haben!
*/
void add_buf(const ITASampleBuffer* pSource, const int iCount);
void add_buf(const ITASampleBuffer* pSource);
void sub_buf(const ITASampleBuffer* pSource);
void mul_buf(const ITASampleBuffer* pSource);
void div_buf(const ITASampleBuffer* pSource);
void add_buf( const ITASampleBuffer* pSource, int iCount );
void add_buf( const ITASampleBuffer* pSource );
void sub_buf( const ITASampleBuffer* pSource );
void mul_buf( const ITASampleBuffer* pSource );
void div_buf( const ITASampleBuffer* pSource );
void add_buf_pos(const ITASampleBuffer* pSource, const int iPos);
void add_buf_pos(float* fSource,const int iSize, const int iPos);
void add_buf_pos( const ITASampleBuffer* pSource, int iPos );
void add_buf_pos( float* fSource, int iSize, int iPos );
// Implementierung mittels Referenzen
void add_buf(const ITASampleBuffer& sbSource, const int iCount);
void add_buf(const ITASampleBuffer& sbSource);
void sub_buf(const ITASampleBuffer& sbSource);
void mul_buf(const ITASampleBuffer& sbSource);
void div_buf(const ITASampleBuffer& sbSource);
void add_buf( const ITASampleBuffer& sbSource, int iCount );
void add_buf( const ITASampleBuffer& sbSource );
void sub_buf( const ITASampleBuffer& sbSource );
void mul_buf( const ITASampleBuffer& sbSource );
void div_buf( const ITASampleBuffer& sbSource );
// Spezial-Operatoren
......@@ -278,8 +287,8 @@ public:
// iSrcOffset = Leseposition im Quellpuffer
// iDestOffset = Schreibposition in diesem Puffer
// iCount = Anzahl Samples
void MulAdd(const ITASampleBuffer* pSource, float fScalar, int iSrcOffset, int iDestOffset, int iCount);
void MulAdd(const ITASampleBuffer& sbSource, float fScalar, int iSrcOffset, int iDestOffset, int iCount);
void MulAdd( const ITASampleBuffer* pSource, float fScalar, int iSrcOffset, int iDestOffset, int iCount );
void MulAdd( const ITASampleBuffer& sbSource, float fScalar, int iSrcOffset, int iDestOffset, int iCount );
//! Spitzenwert suchen
/**
......@@ -287,16 +296,16 @@ public:
* Auf Wunsch wird auch der Index der ersten Samples zurckgegeben, das diesen
* Spitzenwert erreichte (erste Fundstelle).
*/
float FindPeak(int* piPeakIndex=NULL);
float FindPeak( int* piPeakIndex = NULL );
//! Negieren (Multiplikation mit -1 bzw. Phasendrehungum 180)
void Negate();
//! Read/Write Indizierungsoperator
float& operator[](int iSample);
float& operator[]( int iSample );
//! Read-only Indizierungsoperator
const float& operator[](int iSample) const;
const float& operator[]( int iSample ) const;
//! Zuweisungsoperator
/**
......@@ -304,17 +313,17 @@ public:
* Hierzu wird zunchst die Lnge des Puffer der des Quellpuffers angepasst.
* Anschlieend werden alle Samples kopiert.
*/
ITASampleBuffer& operator=(const ITASampleBuffer& rhs);
ITASampleBuffer& operator=( const ITASampleBuffer& rhs );
//! Arithemtische Operatoren (Aliase fr arithmetische Methoden - siehe oben)
ITASampleBuffer& operator+=(const float rhs);
ITASampleBuffer& operator-=(const float rhs);
ITASampleBuffer& operator*=(const float rhs);
ITASampleBuffer& operator/=(const float rhs);
ITASampleBuffer& operator+=(const ITASampleBuffer& rhs);
ITASampleBuffer& operator-=(const ITASampleBuffer& rhs);
ITASampleBuffer& operator*=(const ITASampleBuffer& rhs);
ITASampleBuffer& operator/=(const ITASampleBuffer& rhs);
ITASampleBuffer& operator+=( float rhs );
ITASampleBuffer& operator-=( float rhs );
ITASampleBuffer& operator*=( float rhs );
ITASampleBuffer& operator/=( float rhs );
ITASampleBuffer& operator+=( const ITASampleBuffer& rhs );
ITASampleBuffer& operator-=( const ITASampleBuffer& rhs );
ITASampleBuffer& operator*=( const ITASampleBuffer& rhs );
ITASampleBuffer& operator/=( const ITASampleBuffer& rhs );
//! Informationen ber den Puffer als Zeichenkette zurckgeben
std::string toString() const;
......@@ -323,18 +332,21 @@ public:
std::string valuesToString() const;
//! berblendfunktionen
enum {
enum
{
LINEAR = 0, //!< Lineare berblendung aka. Rampe
COSINE_SQUARE = 1 //!< Cosinus-Quadrat berblendung (aka Hanning-Fenster)
};
//! berblendrichtungen
enum {
enum
{
FADE_IN = 0, //!< Einblenden
FADE_OUT = 1 //!< Ausblenden
};
enum {
enum
{
CROSSFADE_TO_SOURCE = 0, //!< Kreuzblende hin zum Quellsignal
CROSSFADE_FROM_SOURCE = 1 //!< Kreuzblende weg vom Quellsignal
};
......
......@@ -140,7 +140,7 @@ public:
void zero();
//! Setzt einen Bereich von Samples aller Kanle zu Null
void zero(int iOffset, int iCount, float fValue);
void zero(int iOffset, int iCount);
//! Setzt Einheitsimpulse in jedem Kanal
void identity();
......
This diff is collapsed.
......@@ -180,8 +180,9 @@ void ITASampleFrame::zero() {
fill(0);
}
void ITASampleFrame::zero(int iOffset, int iCount, float fValue) {
fill(iOffset, iCount, 0);
void ITASampleFrame::zero(int iOffset, int iCount )
{
fill(iOffset, iCount, 0.0f);
}
void ITASampleFrame::identity() {
......@@ -365,29 +366,39 @@ void ITASampleFrame::muladd_frame(const ITASampleFrame& sfSource, float fScalar,
muladd_frame( &sfSource, fScalar, iSrcOffset, iDestOffset, iCount );
}
float ITASampleFrame::findPeak(int* piChannel, int* piPeakIndex) {
if ((m_iChannels == 0) || (m_iLength == 0)) {
if (piChannel) *piChannel = 0;
if (piPeakIndex) *piPeakIndex = 0;
float ITASampleFrame::findPeak(int* piChannel, int* piPeakIndex)
{
if ((m_iChannels == 0) || (m_iLength == 0))
{
if (piChannel)
*piChannel = 0;
if (piPeakIndex)
*piPeakIndex = 0;
return 0;
}
float fPeak = 0;
int iChannel = 0;
int iPeakIndex;
int iPeakIndex = 0;
for (int i=0; i<m_iChannels; i++) {
for( int i = 0; i < m_iChannels; i++ )
{
int k;
float x = m_vChannels[i].FindPeak(&k);
if (x > fPeak) {
float x = m_vChannels[ i ].FindPeak( &k );
if( x > fPeak )
{
fPeak = x;
iChannel = i;
iPeakIndex = k;
}
}
if (piChannel) *piChannel = iChannel;
if (piPeakIndex) *piPeakIndex = iPeakIndex;
if (piChannel)
*piChannel = iChannel;
if (piPeakIndex)
*piPeakIndex = iPeakIndex;
return fPeak;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment