ITANetAudioStream.cpp 2.14 KB
Newer Older
1
2
3
4
#include <ITANetAudioStream.h>

// ITA includes
#include <ITAException.h>
5
6
#include <ITANetAudioMessage.h>
#include <ITANetAudioProtocol.h>
7
#include <ITANetAudioConnection.h>
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

// Vista includes
#include <VistaInterProcComm/Concurrency/VistaThreadLoop.h>
#include <VistaInterProcComm/Connections/VistaConnectionIP.h>
#include <VistaInterProcComm/IPNet/VistaTCPServer.h>
#include <VistaInterProcComm/IPNet/VistaTCPSocket.h>
//#include <VistaBase/VistaTimeUtils.h>
#include <VistaInterProcComm/IPNet/VistaIPAddress.h>

// STL
#include <cmath>

CITANetAudioStream::CITANetAudioStream( int iChannels, double dSamplingRate, int iBufferSize, int iRingBufferCapacity )
	: m_sfOutputStreamBuffer( iChannels, iBufferSize, true )
	, m_dSampleRate( dSamplingRate )
	, m_sfRingBuffer( iChannels, iRingBufferCapacity, true )
	
{
	m_pNetAudioProducer = new CITANetAudioStreamConnection( this );
}

29
30
31
32
33
CITANetAudioStream::~CITANetAudioStream()
{
	delete m_pNetAudioProducer;
}

34
35
36
37
38
bool CITANetAudioStream::Connect( const std::string& sAddress, int iPort )
{
	return m_pNetAudioProducer->Connect( sAddress, iPort );
}

39
bool CITANetAudioStream::GetIsConnected() const
40
{
41
	return m_pNetAudioProducer->GetIsConnected();
42
43
}

44
const float* CITANetAudioStream::GetBlockPointer( unsigned int uiChannel, const ITAStreamInfo* )
45
{
46
47
48
	// @todo: implement cyclic read from ring buffer
	
	return m_sfOutputStreamBuffer[ uiChannel ].GetData();
49
50
}

51
void CITANetAudioStream::IncrementBlockPointer()
52
{
53
54
	// Increment read cursor by one audio block and wrap around if exceeding ring buffer
	m_iReadCursor = ( m_iReadCursor + m_sfOutputStreamBuffer.GetLength() ) % m_sfRingBuffer.GetLength();
55
56
}

57
int CITANetAudioStream::Transmit( const ITASampleFrame& sfNewSamples, int iNumSamples )
58
{
59
	ITA_EXCEPT0( NOT_IMPLEMENTED );
60
61
}

62
int CITANetAudioStream::GetRingBufferSize() const
63
{
64
	return m_sfRingBuffer.GetLength();
65
66
}

67
unsigned int CITANetAudioStream::GetBlocklength() const
68
{
69
	return  ( unsigned int ) m_sfOutputStreamBuffer.GetLength();
70
71
}

72
unsigned int CITANetAudioStream::GetNumberOfChannels() const
73
{
74
	return ( unsigned int ) m_sfOutputStreamBuffer.channels();
75
76
}

77
double CITANetAudioStream::GetSampleRate() const
78
{
79
	return m_dSampleRate;
80
}