jamulus/src/buffer.h

99 lines
3.2 KiB
C
Raw Normal View History

/******************************************************************************\
* Copyright (c) 2004-2008
*
* Author(s):
* Volker Fischer
*
******************************************************************************
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
\******************************************************************************/
2007-09-08 12:45:14 +02:00
#if !defined ( BUFFER_H__3B123453_4344_BB23945IUHF1912__INCLUDED_ )
#define BUFFER_H__3B123453_4344_BB23945IUHF1912__INCLUDED_
#include "util.h"
#include "global.h"
2006-01-28 12:29:22 +01:00
/* Definitions ****************************************************************/
2007-09-08 12:45:14 +02:00
// time for fading effect for masking drop outs
2008-08-11 20:30:37 +02:00
#define FADE_IN_OUT_TIME ( (double) 2 ) // ms
2008-08-05 22:59:01 +02:00
#define FADE_IN_OUT_NUM_SAM ( (int) ( SYSTEM_SAMPLE_RATE * FADE_IN_OUT_TIME ) / 1000 )
2006-01-28 12:29:22 +01:00
2007-09-08 12:45:14 +02:00
// for extrapolation a shorter time for fading
2008-08-11 20:30:37 +02:00
#define FADE_IN_OUT_NUM_SAM_EXTRA 10 // samples
2006-01-28 12:29:22 +01:00
/* Classes ********************************************************************/
class CNetBuf
{
public:
CNetBuf() {}
virtual ~CNetBuf() {}
2007-09-08 12:45:14 +02:00
void Init ( const int iNewBlockSize, const int iNewNumBlocks );
int GetSize() { return iMemSize / iBlockSize; }
2007-09-08 12:45:14 +02:00
bool Put ( CVector<double>& vecdData );
bool Get ( CVector<double>& vecdData );
protected:
2007-09-08 12:45:14 +02:00
enum EBufState { BS_OK, BS_FULL, BS_EMPTY };
enum EClearType { CT_PUT, CT_GET };
void Clear ( const EClearType eClearType );
int GetAvailSpace() const;
int GetAvailData() const;
2007-09-08 12:45:14 +02:00
void FadeInAudioDataBlock ( CVector<double>& vecdData );
void FadeOutExtrapolateAudioDataBlock ( CVector<double>& vecdData,
const double dExPDiff, const double dExPLastV );
CVector<double> vecdMemory;
int iMemSize;
int iBlockSize;
int iGetPos, iPutPos;
EBufState eBufState;
bool bFadeInNewPutData;
int iNumSamFading;
int iNumSamFadingExtra;
2006-01-28 12:29:22 +01:00
2007-09-08 12:45:14 +02:00
// extrapolation parameters
double dExPDiff;
double dExPLastV;
};
2006-01-28 12:29:22 +01:00
2007-09-08 12:45:14 +02:00
// conversion buffer (very simple buffer)
2006-01-28 12:29:22 +01:00
class CConvBuf
{
public:
2007-09-08 12:45:14 +02:00
CConvBuf() {}
virtual ~CConvBuf() {}
2006-01-28 12:29:22 +01:00
void Init ( const int iNewMemSize );
int GetSize() { return iMemSize; }
2006-01-28 12:29:22 +01:00
bool Put ( const CVector<short>& vecsData );
2007-09-08 12:45:14 +02:00
CVector<short> Get();
2006-01-28 12:29:22 +01:00
protected:
CVector<short> vecsMemory;
int iMemSize;
int iPutPos;
2006-01-28 12:29:22 +01:00
};
2007-09-08 12:45:14 +02:00
#endif /* !defined ( BUFFER_H__3B123453_4344_BB23945IUHF1912__INCLUDED_ ) */