Commit e8fbe298 authored by Anne's avatar Anne
Browse files

Merged ba_2016_heimes into develop

parents a811a6c3 240e54d3
CMakeCache.txt
*.suo
CMakeFiles
*.bat
*.exe
\ No newline at end of file
CMakeFiles
*.suo
*.bat
*.exe
*.wav
\ No newline at end of file
......@@ -54,6 +54,7 @@ set( ITADataSourcesHeader
"include/ITANetAudioStream.h"
"include/ITANetAudioStreamingClient.h"
"include/ITANetAudioStreamingServer.h"
"include/ITANetAudioStreamingClient.h"
"include/ITAPeakDetector.h"
"include/ITARMSDetector.h"
"include/ITAStreamAmplifier.h"
......
......@@ -23,7 +23,6 @@
#include <ITASampleFrame.h>
#include <VistaInterProcComm/Concurrency/VistaThreadLoop.h>
#include <string>
#include <vector>
......@@ -37,16 +36,19 @@ class VistaTCPServer;
* Can be connected to an ITADataSource as a streaming source
* or to a user-implemented sample producer, i.e. an audio sythesizer.
*/
class ITA_DATA_SOURCES_API CITANetAudioServer : public VistaThreadLoop
class ITA_DATA_SOURCES_API CITANetAudioServer
{
public:
CITANetAudioServer( CITANetAudioStreamingServer* pParent );
CITANetAudioServer();
virtual ~CITANetAudioServer();
std::string GetServerAddress() const;
int GetNetworkPort() const;
bool Start( const std::string& sAddress, int iPort );
void Disconnect(); bool IsConnected() const; bool LoopBody();
VistaTCPSocket* GetSocket() const;
void Disconnect();
bool IsConnected() const;
private:
VistaTCPServer* m_pServer;
......@@ -55,16 +57,5 @@ private:
int m_iServerPort;
std::string m_sServerAddress;
CITANetAudioStreamingServer* m_pParent;
ITASampleFrame m_sfReceivingBuffer;
bool m_bStopIndicated;
int m_iClientChannels;
int m_iClientRingBufferSize;
int m_iClientBufferSize;
int m_iClientRingBufferFreeSamples;
double m_dClientSampleRate;
};
#endif // INCLUDE_WATCHER_ITA_NET_AUDIO_SERVER
......@@ -24,10 +24,12 @@
#include <string>
#include <vector>
#include <VistaInterProcComm/Concurrency/VistaThreadLoop.h>
#include <ITASampleFrame.h>
class ITADatasource;
class CITANetAudioServer;
class VistaTCPSocket;
//! Network audio sample server (for connecting a net audio stream)
/**
......@@ -36,7 +38,7 @@ class CITANetAudioServer;
* \sa CITANetAudioStream
* \note not thread-safe
*/
class ITA_DATA_SOURCES_API CITANetAudioStreamingServer
class ITA_DATA_SOURCES_API CITANetAudioStreamingServer : public VistaThreadLoop
{
public:
......@@ -54,7 +56,7 @@ public:
bool IsClientConnected() const;
std::string GetNetworkAddress() const;
int GetNetworkPort() const;
int Stop();
void Stop();
void SetInputStream( ITADatasource* pInStream );
......@@ -72,10 +74,20 @@ private:
CITANetAudioServer* m_pNetAudioServer;
ITASampleFrame m_sfTempTransmitBuffer;
ITADatasource* m_pInputStream;
VistaTCPSocket* m_pSocket;
int m_iUpdateStrategy;
int m_iClientRingBufferFreeSamples;
friend class CITANetAudioServer;
// TODO: in einem Struct speichern
struct InitData {
int iClientChannels;
int iClientRingBufferSize;
int iClientBufferSize;
double dClientSampleRate;
} m_initData;
};
#endif // INCLUDE_WATCHER_ITA_NET_AUDIO_STREAMING_SERVER
......@@ -19,15 +19,9 @@
#include <cmath>
#include <cassert>
CITANetAudioServer::CITANetAudioServer( CITANetAudioStreamingServer* pParent )
: m_pParent( pParent )
, m_bStopIndicated( false )
, m_pServer( NULL )
CITANetAudioServer::CITANetAudioServer()
: m_pServer( NULL )
, m_pSocket( NULL )
, m_iClientRingBufferSize( -1 )
, m_iClientBufferSize( -1 )
, m_iClientRingBufferFreeSamples( 0 )
, m_dClientSampleRate( -1 )
, m_iServerPort( -1 )
{
};
......@@ -46,7 +40,7 @@ int CITANetAudioServer::GetNetworkPort() const
return m_iServerPort;
}
bool CITANetAudioServer::Start( const std::string& sAddress, int iPort )
bool CITANetAudioServer::Start(const std::string& sAddress, int iPort)
{
if( m_pServer )
ITA_EXCEPT1( MODAL_EXCEPTION, "This net sample server is already started" );
......@@ -57,33 +51,22 @@ bool CITANetAudioServer::Start( const std::string& sAddress, int iPort )
// blocking wait for connection
m_pSocket = m_pServer->GetNextClient();
if (m_pSocket != NULL)
return true;
return false;
}
long nIncomingBytes = m_pSocket->WaitForIncomingData( 0 );
int iBytesReceived = m_pSocket->ReceiveRaw( &m_iClientChannels, sizeof( int ) );
iBytesReceived = m_pSocket->ReceiveRaw( &m_dClientSampleRate, sizeof( double ) );
iBytesReceived = m_pSocket->ReceiveRaw( &m_iClientBufferSize, sizeof( int ) );
iBytesReceived = m_pSocket->ReceiveRaw( &m_iClientRingBufferSize, sizeof( int ) );
m_iClientRingBufferFreeSamples = m_iClientRingBufferFreeSamples;
int iMessageID = 1;
m_pSocket->SendRaw( &iMessageID, sizeof( int ) );
Run();
return true;
VistaTCPSocket* CITANetAudioServer::GetSocket() const
{
return m_pSocket;
}
void CITANetAudioServer::Disconnect()
{
m_bStopIndicated = true;
StopGently( true );
m_pSocket = NULL;
delete m_pServer;
m_pServer = NULL;
m_bStopIndicated = false;
}
bool CITANetAudioServer::IsConnected() const
......@@ -92,28 +75,4 @@ bool CITANetAudioServer::IsConnected() const
return false;
return m_pSocket->GetIsConnected();
}
bool CITANetAudioServer::LoopBody()
{
if( m_bStopIndicated )
return true;
if( m_pSocket->GetIsConnected() == false )
{
StopGently( true );
return false;
}
ITAStreamInfo oStreamInfo;
ITADatasource* pIn = m_pParent->GetInputStream();
for( int iChannelIndex = 0; iChannelIndex < int( m_pParent->GetInputStream()->GetNumberOfChannels() ); iChannelIndex++ )
{
const float* pfData = pIn->GetBlockPointer( iChannelIndex, &oStreamInfo );
int iNumSamples = pIn->GetBlocklength();
m_pSocket->SendRaw( pfData, iNumSamples * sizeof( float ) );
}
return true;
}
\ No newline at end of file
......@@ -18,6 +18,8 @@ CITANetAudioStream::CITANetAudioStream( int iChannels, double dSamplingRate, int
ITA_EXCEPT1( INVALID_PARAMETER, "Ring buffer capacity can not be smaller than buffer size." );
m_pNetAudioStreamingClient = new CITANetAudioStreamingClient( this );
m_iReadCursor = 0;
m_iWriteCursor = 0;
}
CITANetAudioStream::~CITANetAudioStream()
......@@ -37,7 +39,15 @@ bool CITANetAudioStream::GetIsConnected() const
const float* CITANetAudioStream::GetBlockPointer( unsigned int uiChannel, const ITAStreamInfo* )
{
// @todo: implement cyclic read from ring buffer
// @todo: is connected?
int iCurrentWritePointer = m_iWriteCursor;
if (iCurrentWritePointer > m_iReadCursor) {
m_sfOutputStreamBuffer[uiChannel].cyclic_write(&m_sfRingBuffer[uiChannel],
m_sfOutputStreamBuffer.GetLength(), m_iReadCursor, iCurrentWritePointer);
} else {
// in diesem Block alle Kanaele auf 0 setzen
m_sfOutputStreamBuffer[uiChannel].Zero();
}
return m_sfOutputStreamBuffer[ uiChannel ].GetData();
}
......@@ -50,7 +60,22 @@ void CITANetAudioStream::IncrementBlockPointer()
int CITANetAudioStream::Transmit( const ITASampleFrame& sfNewSamples, int iNumSamples )
{
ITA_EXCEPT0( NOT_IMPLEMENTED );
int iCurrentReadCursor = m_iReadCursor;
//kopiert Samples in den RingBuffer
m_sfRingBuffer.cyclic_write(sfNewSamples, iNumSamples,
iCurrentReadCursor, m_iWriteCursor);
// Schreibpointer weiter setzen
m_iWriteCursor = ( m_iWriteCursor + iNumSamples ) % m_sfRingBuffer.GetLength();
// Gibt freien Platz im RingBuffer zurueck
if (iCurrentReadCursor > m_iWriteCursor) {
return m_iWriteCursor - iCurrentReadCursor;
}
else {
return m_sfRingBuffer.GetLength() - m_iWriteCursor + iCurrentReadCursor;
}
}
int CITANetAudioStream::GetRingbufferFreeSamples()
......
#include <ITANetAudioStreamingServer.h>
#include <ITANetAudioServer.h>
// ITA includes
#include <ITADataSource.h>
#include <ITAException.h>
#include <ITAStreamInfo.h>
// 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>
#include <cassert>
CITANetAudioStreamingServer::CITANetAudioStreamingServer()
: m_pInputStream( NULL )
, m_iUpdateStrategy( AUTO )
{
m_pNetAudioServer = new CITANetAudioServer( this );
}
bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort )
{
return m_pNetAudioServer->Start( sAddress, iPort );
}
bool CITANetAudioStreamingServer::IsClientConnected() const
{
return m_pNetAudioServer->IsConnected();
}
std::string CITANetAudioStreamingServer::GetNetworkAddress() const
{
return m_pNetAudioServer->GetServerAddress();
}
int CITANetAudioStreamingServer::GetNetworkPort() const
{
return m_pNetAudioServer->GetNetworkPort();
}
void CITANetAudioStreamingServer::SetInputStream( ITADatasource* pInStream )
{
m_pInputStream = pInStream;
}
void CITANetAudioStreamingServer::SetAutomaticUpdateRate()
{
m_iUpdateStrategy = AUTO;
}
ITADatasource* CITANetAudioStreamingServer::GetInputStream() const
{
return m_pInputStream;
}
#include <ITANetAudioStreamingServer.h>
#include <ITANetAudioServer.h>
// ITA includes
#include <ITADataSource.h>
#include <ITAException.h>
#include <ITAStreamInfo.h>
// 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>
#include <cassert>
CITANetAudioStreamingServer::CITANetAudioStreamingServer()
: m_pInputStream( NULL )
, m_iUpdateStrategy( AUTO )
, m_pSocket( NULL )
{
m_pNetAudioServer = new CITANetAudioServer();
// TODO: Init members
}
bool CITANetAudioStreamingServer::Start(const std::string& sAddress, int iPort)
{
// TODO: vorrckgabe noch anfangen zu senden (Samples)
if (m_pNetAudioServer->Start(sAddress, iPort))
{
m_pSocket = m_pNetAudioServer->GetSocket();
// TODO: Init neu mit Netmessage
long nIncomingBytes = m_pSocket->WaitForIncomingData(0);
int iBytesReceived = m_pSocket->ReceiveRaw(&m_initData, sizeof( InitData ));
m_iClientRingBufferFreeSamples = m_iClientRingBufferFreeSamples;
int iMessageID = 1;
m_pSocket->SendRaw(&iMessageID, sizeof(int));
Run();
return true;
return true;
}
return false;
}
bool CITANetAudioStreamingServer::IsClientConnected() const
{
return m_pNetAudioServer->IsConnected();
}
std::string CITANetAudioStreamingServer::GetNetworkAddress() const
{
return m_pNetAudioServer->GetServerAddress();
}
int CITANetAudioStreamingServer::GetNetworkPort() const
{
return m_pNetAudioServer->GetNetworkPort();
}
void CITANetAudioStreamingServer::Stop()
{
m_pNetAudioServer->Disconnect();
}
void CITANetAudioStreamingServer::SetInputStream( ITADatasource* pInStream )
{
m_pInputStream = pInStream;
}
int CITANetAudioStreamingServer::GetNetStreamBlocklength() const
{
return m_sfTempTransmitBuffer.GetLength();
}
int CITANetAudioStreamingServer::GetNetStreamNumberOfChannels() const
{
return m_sfTempTransmitBuffer.channels();
}
double CITANetAudioStreamingServer::GetNetStreamSampleRate() const
{
return m_initData.dClientSampleRate;
}
void CITANetAudioStreamingServer::SetAutomaticUpdateRate()
{
m_iUpdateStrategy = AUTO;
}
ITADatasource* CITANetAudioStreamingServer::GetInputStream() const
{
return m_pInputStream;
}
int CITANetAudioStreamingServer::Transmit(const ITASampleFrame& sfNewSamples, int iNumSamples)
{
return 0;
}
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