Commit 8fe503af authored by Anne's avatar Anne
Browse files

merge

parents c3440ab0 f0a169e0
......@@ -47,12 +47,15 @@ set( ITADataSourcesHeader
"include/ITADataSourcesDefinitions.h"
"include/ITAFileDataSink.h"
"include/ITAFileDataSource.h"
"include/ITANetAudioClient.h"
"include/ITANetAudioMessage.h"
"include/ITANetAudioProtocol.h"
"include/ITANetAudioServer.h"
"include/ITANetAudioStream.h"
"include/ITANetAudioSampleServer.h"
"include/ITANetAudioStreamingServer.h"
"include/ITAPeakDetector.h"
"include/ITARMSDetector.h"
"include/ITAStreamAmplifier.h"
#"include/ITAStreamFilter.h"
"include/ITAStreamFunctionGenerator.h"
"include/ITAStreamModalSynthesizer.h"
"include/ITAStreamMultiplier1N.h"
......@@ -69,11 +72,15 @@ set( ITADataSourcesSources
"src/ITADataSourceRealization.cpp"
"src/ITAFileDataSink.cpp"
"src/ITAFileDataSource.cpp"
"src/ITANetAudioClient.cpp"
"src/ITANetAudioMessage.cpp"
"src/ITANetAudioProtocol.cpp"
"src/ITANetAudioStream.cpp"
"src/ITANetAudioStreamingServer.cpp"
"src/ITANetAudioServer.cpp"
"src/ITAPeakDetector.cpp"
"src/ITARMSDetector.cpp"
"src/ITAStreamAmplifier.cpp"
#"src/ITAStreamFilter.cpp"
"src/ITAStreamFunctionGenerator.cpp"
"src/ITAStreamModalSynthesizer.cpp"
"src/ITAStreamMultiplier1N.cpp"
......
/*
* ----------------------------------------------------------------
*
* ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2016
*
* ----------------------------------------------------------------
* ____ __________ _______
* // / //__ ___/ // _ |
* // / // / // /_| |
* // / // / // ___ |
* //__/ //__/ //__/ |__|
*
* ----------------------------------------------------------------
*
*/
#ifndef INCLUDE_WATCHER_ITA_NET_AUDIO_CONNECTION
#define INCLUDE_WATCHER_ITA_NET_AUDIO_CONNECTION
#include <ITADataSourcesDefinitions.h>
#include <ITADataSource.h>
#include <ITASampleFrame.h>
#include <VistaInterProcComm/Concurrency/VistaThreadLoop.h>
#include <string>
#include <vector>
class CITANetAudioStream;
class VistaConnectionIP;
class CITANetAudioMessage;
class CITANetAudioProtocol;
class CITANetAudioClient : public VistaThreadLoop
{
public:
CITANetAudioClient( CITANetAudioStream* pParent );
~CITANetAudioClient();
bool Connect( const std::string& sAddress, int iPort );
void Disconnect();
bool LoopBody();
bool GetIsConnected();
private:
CITANetAudioStream* m_pParent;
VistaConnectionIP* m_pConnection;
CITANetAudioProtocol* m_pProtocol;
CITANetAudioMessage* m_pMessage;
ITASampleFrame m_sfReceivingBuffer;
bool m_bStopIndicated;
};
#endif // INCLUDE_WATCHER_ITA_NET_AUDIO_CONNECTION
/*
* ----------------------------------------------------------------
*
* ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2016
*
* ----------------------------------------------------------------
* ____ __________ _______
* // / //__ ___/ // _ |
* // / // / // /_| |
* // / // / // ___ |
* //__/ //__/ //__/ |__|
*
* ----------------------------------------------------------------
*
*/
#ifndef INCLUDE_WATCHER_ITA_NET_AUDIO_MESSAGE
#define INCLUDE_WATCHER_ITA_NET_AUDIO_MESSAGE
#include <ITADataSourcesDefinitions.h>
// ITA includes
#include <ITAException.h>
#include <ITASampleBuffer.h>
#include <ITASampleFrame.h>
// Vista includes
#include <VistaInterProcComm/Connections/VistaByteBufferSerializer.h>
#include <VistaInterProcComm/Connections/VistaByteBufferDeSerializer.h>
// STL includes
#include <string>
#include <vector>
class VistaConnectionIP;
//! Network audio messages
/*
* Messages consist of a message part and an answer part, each read or written
* separately. Messages have a two-int-header (SIZE, MSGTYPE), and
* answers have a two-int header (SIZE; ANSWERTYPE)
*/
class ITA_DATA_SOURCES_API CITANetAudioMessage
{
public:
CITANetAudioMessage( VistaSerializingToolset::ByteOrderSwapBehavior bSwapBuffers );
void SetConnection( VistaConnectionIP* );
VistaConnectionIP* GetConnection() const;
void ClearConnection();
void WriteMessage();
void ReadMessage();
void WriteAnswer();
void ReadAnswer();
void ResetMessage();
int GetIncomingMessageSize() const;
int GetOutgoingMessageSize() const;
bool GetOutgoingMessageHasData() const;
void SetMessageType( int nType );
void SetAnswerType( int nType );
int GetMessageType() const;
int GetAnswerType() const;
void WriteInt( const int );
void WriteBool( const bool );
void WriteDouble( const double );
void WriteException( const ITAException& );
void WriteFloat( const float );
void WriteString( const std::string& );
void WriteIntVector( const std::vector< int > );
void WriteFloatVector( const std::vector< float > );
std::string ReadString();
int ReadInt();
bool ReadBool();
ITAException ReadException();
float ReadFloat();
double ReadDouble();
std::vector< int > ReadIntVector();
std::vector< float > ReadFloatVector();
private:
int m_nMessageType;
int m_nMessageId;
int m_nAnswerType;
VistaByteBufferSerializer m_oOutgoing;
VistaByteBufferDeSerializer m_oIncoming;
std::vector< VistaType::byte > m_vecIncomingBuffer;
VistaConnectionIP* m_pConnection;
};
#endif // INCLUDE_WATCHER_ITA_NET_AUDIO_MESSAGE
/*
* ----------------------------------------------------------------
*
* ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2016
*
* ----------------------------------------------------------------
* ____ __________ _______
* // / //__ ___/ // _ |
* // / // / // /_| |
* // / // / // ___ |
* //__/ //__/ //__/ |__|
*
* ----------------------------------------------------------------
*
*/
#ifndef INCLUDE_WATCHER_ITA_NET_AUDIO_PROTOCOL
#define INCLUDE_WATCHER_ITA_NET_AUDIO_PROTOCOL
#include <ITADataSourcesDefinitions.h>
// ITA includes
#include <ITAException.h>
#include <ITASampleBuffer.h>
#include <ITASampleFrame.h>
// Vista includes
#include <VistaBase/VistaBaseTypes.h>
#include <VistaInterProcComm/Connections/VistaByteBufferSerializer.h>
#include <VistaInterProcComm/Connections/VistaByteBufferDeSerializer.h>
// STL includes
#include <string>
#include <vector>
// Forward declarations
class VistaConnectionIP;
class CITANetAudioStreamingServer;
class CITANetAudioStream;
//! Network audio protocol
/**
* Declaration of message types
*/
class ITA_DATA_SOURCES_API CITANetAudioProtocol
{
public:
static const int NET_AUDIO_VERSION = 1;
static const int NP_INVALID = -1;
static const int NP_GET_VERSION_INFO = 1;
static const int NP_CLIENT_OPEN = 100;
static const int NP_CLIENT_CLOSE = 101;
static const int NP_SERVER_CLOSE = 200;
static const int NP_SERVER_OPEN = 201;
static const int NP_SERVER_GET_RINGBUFFER_SIZE = 210;
static const int NP_SERVER_GET_RINGBUFFER_FREE = 211;
static const int NP_SERVER_SEND_SAMPLES = 222;
CITANetAudioProtocol();
virtual ~CITANetAudioProtocol();
};
#endif // INCLUDE_WATCHER_ITA_NET_AUDIO_PROTOCOL
/*
* ----------------------------------------------------------------
*
* ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2016
*
* ----------------------------------------------------------------
* ____ __________ _______
* // / //__ ___/ // _ |
* // / // / // /_| |
* // / // / // ___ |
* //__/ //__/ //__/ |__|
*
* ----------------------------------------------------------------
*
*/
#ifndef INCLUDE_WATCHER_ITA_NET_AUDIO_SERVER
#define INCLUDE_WATCHER_ITA_NET_AUDIO_SERVER
#include <ITADataSourcesDefinitions.h>
#include <ITASampleFrame.h>
#include <VistaInterProcComm/Concurrency/VistaThreadLoop.h>
#include <string>
#include <vector>
class VistaTCPSocket;
class CITANetAudioStreamingServer;
class VistaTCPServer;
//! Realizes server functionality for network audio streaming
/**
* Can be connected to an ITADataSource as a streaming source
* or to a user-implemented sample producer, i.e. an audio sythesizer.
*/
class CITANetAudioServer : public VistaThreadLoop
{
public:
CITANetAudioServer( CITANetAudioStreamingServer* pParent );
virtual ~CITANetAudioServer();
std::string GetServerAddress() const;
int GetNetworkPort() const;
bool Start( const std::string& sAddress, int iPort );
void Disconnect(); bool IsConnected() const; bool LoopBody();
private:
VistaTCPServer* m_pServer;
VistaTCPSocket* m_pSocket;
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
......@@ -27,7 +27,7 @@
#include <string>
#include <vector>
class ITA_DATA_SOURCES_API CITANetAudioStreamConnection;
class CITANetAudioClient;
//! Network audio stream
/**
......@@ -35,16 +35,14 @@ class ITA_DATA_SOURCES_API CITANetAudioStreamConnection;
*
* \note not thread-safe
*/
class CITANetAudioStream : public ITADatasource
class ITA_DATA_SOURCES_API CITANetAudioStream : public ITADatasource
{
public:
CITANetAudioStream( int iChannels, double dSamplingRate, int iBufferSize, int iRingBufferCapacity );
virtual ~CITANetAudioStream();
bool Connect( const std::string& sAddress, int iPort );
bool IsConnected() const;
std::string GetNetworkAddress() const;
int GetNetworkPort() const;
bool GetIsConnected() const;
int GetRingBufferSize() const;
......@@ -58,16 +56,16 @@ protected:
int Transmit( const ITASampleFrame& sfNewSamples, int iNumSamples );
private:
CITANetAudioStreamConnection* m_pNetAudioProducer;
CITANetAudioClient* m_pNetAudioProducer;
double m_dSampleRate;
ITASampleFrame m_sfOutputStreamBuffer;
int m_iReadCursor; //!< Cursor where samples will be consumed from ring buffer on next block
int m_iWriteCursor; //!< Cursor where samples will feeded into ring buffer from net audio producer
ITASampleFrame m_sfRingBuffer;
ITASampleFrame m_sfRingBuffer; //!< Buffer incoming data
friend class CITANetAudioStreamConnection;
friend class CITANetAudioClient;
};
#endif // INCLUDE_WATCHER_ITA_NET_AUDIO_STREAM
......@@ -16,8 +16,8 @@
*
*/
#ifndef INCLUDE_WATCHER_ITA_NET_AUDIO_SAMPLE_SERVER
#define INCLUDE_WATCHER_ITA_NET_AUDIO_SAMPLE_SERVER
#ifndef INCLUDE_WATCHER_ITA_NET_AUDIO_STREAMING_SERVER
#define INCLUDE_WATCHER_ITA_NET_AUDIO_STREAMING_SERVER
#include <ITADataSourcesDefinitions.h>
......@@ -27,7 +27,7 @@
#include <ITASampleFrame.h>
class ITADatasource;
class CITANetAudioStreamServer;
class CITANetAudioServer;
//! Network audio sample server (for connecting a net audio stream)
/**
......@@ -36,11 +36,19 @@ class CITANetAudioStreamServer;
* \sa CITANetAudioStream
* \note not thread-safe
*/
class ITA_DATA_SOURCES_API CITANetAudioSampleServer
class ITA_DATA_SOURCES_API CITANetAudioStreamingServer
{
public:
CITANetAudioSampleServer();
virtual ~CITANetAudioSampleServer();
enum UpdateStrategy
{
AUTO = 1, //!< Automatic update rate based on sample rate and block length of client (default)
ADAPTIVE, //!< Adaptive update rate, adjusts for drifting clocks
CONSTANT, //!< Set a user-defined update rate (may cause forced pausing of sample feeding or dropouts on client side)
};
CITANetAudioStreamingServer();
virtual ~CITANetAudioStreamingServer() {};
bool Start( const std::string& sAddress, int iPort );
bool IsClientConnected() const;
......@@ -54,15 +62,20 @@ public:
int GetNetStreamNumberOfChannels() const;
double GetNetStreamSampleRate() const;
void SetAutomaticUpdateRate();
protected:
int Transmit( const ITASampleFrame& sfNewSamples, int iNumSamples );
ITADatasource* GetInputStream() const;
private:
CITANetAudioStreamServer* m_pNetAudioServer;
CITANetAudioServer* m_pNetAudioServer;
ITASampleFrame m_sfTempTransmitBuffer;
ITADatasource* m_pInputStream;
friend class CITANetAudioStreamServer;
int m_iUpdateStrategy;
friend class CITANetAudioServer;
};
#endif // INCLUDE_WATCHER_ITA_NET_AUDIO_SAMPLE_SERVER
#endif // INCLUDE_WATCHER_ITA_NET_AUDIO_STREAMING_SERVER
/*
* ----------------------------------------------------------------
*
* ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2016
*
* ----------------------------------------------------------------
* ____ __________ _______
* // / //__ ___/ // _ |
* // / // / // /_| |
* // / // / // ___ |
* //__/ //__/ //__/ |__|
*
* ----------------------------------------------------------------
*
*/
// $Id: ITAStreamFunctionGenerator.h 2900 2012-09-17 08:42:42Z stienen $
#ifndef INCLUDE_WATCHER_ITA_STREAM_FILTER
#define INCLUDE_WATCHER_ITA_STREAM_FILTER
#include <ITADataSourcesDefinitions.h>
#include <ITADataSource.h>
#include <ITATypes.h>
#include <vector>
class ITAStreamFilter : public ITADatasource
{
public:
//! Konstruktor
ITAStreamFilter(ITADatasource* pdsInput=NULL);
//! Destruktor
virtual ~ITAStreamFilter();
//! Eingangsdatenquelle zurckgeben
ITADatasource* GetInputDatasource() const;
// TODO: Erstmal aus...
//! Eingangsdatenquelle setzen
//void SetInputDatasource(ITADatasource* pdsInput);
// -= Realisierung der abstrakten Methoden von "ITADatasource" =-
const float* GetBlockPointer(unsigned int uiChannel, bool bWaitForData=true);
void IncrementBlockPointer();
protected:
//! Verarbeitungsmethode
/**
* In dieser Methode werden die neue Eingangsdaten aller Kanle verarbeitet und das Filter berechnet.
*/
virtual void ProcessAllChannels(const float** ppfInputData, float** ppfOutputData) {
/*
Hinweis: Diese Vorgabe-Implementierung setzt den Methodenaufruf in die kanalweise
Verarbeitung mittels der Methode "ProcessChannel" um. Diese Verfahrensweise
ist adquat fr Filter welche eine kanal-unabhngige Verarbeitung erlauben.
Mchten Sie einen Filter mit kanal-abhngiger Verarbeitung bauen,
so muss diese Methode entsprechend angepasst werden.
Hierbei mssen Sie nicht zwangslufig die Methode "ProcessChannel" involvieren.
*/
for (unsigned int i=0; i<m_uiChannels; i++) ProcessChannel(i, ppfInputData[i], ppfOutputData[i]);
}
//! Verarbeitungsmethode
/**
* In dieser Methode werden fr einen Kanal neue Eingangsdaten verarbeitet und das Filter berechnet.
* Diese Methode wird die kanal-unabhngige Datenverarbeitung des Filters realisiert. Kanal-unabhngig
* bedeutet, dass die Ausgangsdaten dieses Kanals einzig aus den Eingangsdaten des selben Kanals
* berechnet werden knnen.
*/
virtual void ProcessChannel(unsigned int uiChannel, const float* pfInputData, float* pfOutputData) {
// Dies ist eine Vorgabe-Implementierung, welche die Eingangsdaten unverndert in die Ausgabe kopiert
//fm_copy(pfOutputData, pfInputData, m_uiBlocklength);
memcpy(pfOutputData, pfInputData, m_uiBlocklength * sizeof(float));
}
private:
ITADatasource* m_pdsInput; // Eingangsdatenquelle
std::vector<const float*> m_vpfInputData; // Eingangsdatenzeiger
std::vector<float*> m_vpfOutputBuffer; // Ausgabepuffer
bool m_bGBPCalled; // Flag die Anzeigt ob seit dem letzten IncrementBlockPointer (IBP)
// bereits ein erneuter Eintritt in GetBlockPointer (GBP) erfolgt ist
};
#endif // INCLUDE_WATCHER_ITA_STREAM_FILTER
\ No newline at end of file
......@@ -37,16 +37,6 @@ public:
WHITE_NOISE //!< White noise
};
//! Constructor
/**
* Creates a new function generator.
*
* \param uiChannels Number of output channels
* \param dSamplerate Sampling rate [Hz]
* \param uiBlocklength Blocklength [samples]
*/
ITAStreamFunctionGenerator( unsigned int uiChannels, double dSamplerate, unsigned int uiBlocklength );
//! Constructor
/**
* Creates a new function generator with specific parameters
......@@ -62,7 +52,7 @@ public:
ITAStreamFunctionGenerator( unsigned int uiChannels, double dSamplerate, unsigned int uiBlocklength, int iSignalFunction, double dFrequency, float fAmplitude, bool bPeriodic );
//! Destructor
virtual ~ITAStreamFunctionGenerator();
inline virtual ~ITAStreamFunctionGenerator() {};
//! Reset
/**
......
#include <ITANetAudioClient.h>
#include <ITANetAudioStream.h>
#include <ITANetAudioProtocol.h>
#include <VistaInterProcComm/Connections/VistaConnectionIP.h>
CITANetAudioClient::CITANetAudioClient( CITANetAudioStream* pParent )
: m_pParent( pParent )
, m_pConnection( NULL )
, m_bStopIndicated( false )
{
}
CITANetAudioClient::~CITANetAudioClient()
{
if( m_pConnection )
{
int iMessageType = CITANetAudioProtocol::NP_CLIENT_CLOSE;
m_pConnection->Send( &iMessageType, sizeof( int ) );
}
}
bool CITANetAudioClient::Connect( const std::string& sAddress, int iPort )
{
if( m_pConnection )
ITA_EXCEPT1( MODAL_EXCEPTION, "This net stream is already connected" );
// Attempt to connect and check parameters
m_pConnection = new VistaConnectionIP( VistaConnectionIP::CT_TCP, sAddress, iPort );
if( !m_pConnection->GetIsConnected() )
{
delete m_pConnection;
m_pConnection = NULL;
return false;
}
int iMessageType = CITANetAudioProtocol::NP_CLIENT_OPEN;
m_pConnection->Send( &iMessageType, sizeof( int ) );
int iNumChannels = ( int ) m_pParent->GetNumberOfChannels();
m_pConnection->Send( &iNumChannels, sizeof( int ) );
double dSampleRate = m_pParent->GetSampleRate();
m_pConnection->Send( &dSampleRate, sizeof( double ) );
int iBlockLength = ( int ) m_pParent->GetBlocklength();
m_pConnection->Send( &iBlockLength, sizeof( int ) );
int iRingBufferSize = ( int ) m_pParent->GetRingBufferSize();
m_pConnection->Send( &iRingBufferSize, sizeof( int ) );
m_pConnection->WaitForSendFinish();
int iServerMessageType;
m_pConnection->Receive( &iServerMessageType, sizeof( int ) );
Run();
return true;
}
void CITANetAudioClient::Disconnect()
{
m_bStopIndicated = true;
StopGently( true );