...
 
Commits (26)
Copyright 2015-2016 Institute of Technical Acoustics, RWTH Aachen University. Any usage and distribution is prohibited, unless explicitly granted by the authors.
\ No newline at end of file
Copyright 2015-2017 Institute of Technical Acoustics, RWTH Aachen University. Any usage and distribution is prohibited, unless explicitly granted by the authors.
\ No newline at end of file
/*
* ----------------------------------------------------------------
*
* ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2017
*
* ----------------------------------------------------------------
* ____ __________ _______
* // / //__ ___/ // _ |
* // / // / // /_| |
* // / // / // ___ |
* //__/ //__/ //__/ |__|
*
* ----------------------------------------------------------------
*
*/
#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>
#include <ITANetAudioProtocol.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 > );
void WriteStreamingParameters( const CITANetAudioProtocol::StreamingParameters &);
std::string ReadString();
int ReadInt();
bool ReadBool();
ITAException ReadException();
float ReadFloat();
double ReadDouble();
std::vector< int > ReadIntVector();
std::vector< float > ReadFloatVector();
CITANetAudioProtocol::StreamingParameters ReadStreamingParameters();
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-2017
*
* ----------------------------------------------------------------
* ____ __________ _______
* // / //__ ___/ // _ |
* // / // / // /_| |
* // / // / // ___ |
* //__/ //__/ //__/ |__|
*
* ----------------------------------------------------------------
*
*/
#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>
#include <ITANetAudioProtocol.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 > );
void WriteStreamingParameters(const CITANetAudioProtocol::StreamingParameters &);
void WriteRingBufferSize(const int);
void WriteRingBufferFree(const int);
void WriteSampleFrame(ITASampleFrame*);
std::string ReadString();
int ReadInt();
bool ReadBool();
ITAException ReadException();
float ReadFloat();
double ReadDouble();
std::vector< int > ReadIntVector();
std::vector< float > ReadFloatVector();
CITANetAudioProtocol::StreamingParameters ReadStreamingParameters();
int ReadRingBufferSize();
int ReadRingBufferFree();
void ReadSampleFrame(ITASampleFrame* pSampleFrame);
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
......@@ -21,6 +21,8 @@
#include <ITADataSourcesDefinitions.h>
#include <ITANetAudioProtocol.h>
#include <ITASampleFrame.h>
#include <string>
......
......@@ -26,6 +26,10 @@
#include <string>
#include <vector>
#include <iostream>
#include <fstream>
using namespace std;
class CITANetAudioStreamingClient;
......@@ -41,10 +45,26 @@ public:
CITANetAudioStream( int iChannels, double dSamplingRate, int iBufferSize, int iRingBufferCapacity = 2048 );
virtual ~CITANetAudioStream();
enum StreamingStatus
{
INVALID = -1,
STOPPED,
CONNECTED,
STREAMING,
BUFFER_UNDERRUN,
};
bool Connect( const std::string& sAddress, int iPort );
bool GetIsConnected() const;
//! Returns (static) size of ring buffer
int GetRingBufferSize() const;
//! Returns true if ring buffer is full
bool GetIsRingBufferFull() const;
//! Returns true if ring buffer is empty
bool GetIsRingBufferEmpty() const;
unsigned int GetBlocklength() const;
unsigned int GetNumberOfChannels() const;
......@@ -62,7 +82,8 @@ protected:
*/
int Transmit( const ITASampleFrame& sfNewSamples, int iNumSamples );
int GetRingbufferFreeSamples();
//! Returns free samples between write and read cursor
int GetRingBufferFreeSamples() const;
private:
CITANetAudioStreamingClient* m_pNetAudioStreamingClient;
......@@ -71,10 +92,14 @@ private:
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
int m_iWriteCursor; //!< Cursor where samples will be fed into ring buffer from net audio producer (always ahead)
bool m_bRingBufferFull; //!< Indicator if ring buffer is full (and read cursor equals write cursor)
ITASampleFrame m_sfRingBuffer; //!< Buffer incoming data
friend class CITANetAudioStreamingClient;
int m_iStreamingStatus; //!< Current streaming status
friend class CITANetAudioStreamingClient;
ofstream outputFile;
};
#endif // INCLUDE_WATCHER_ITA_NET_AUDIO_STREAM
......@@ -24,6 +24,7 @@
#include <ITANetAudioProtocol.h>
#include <ITASampleFrame.h>
#include <ITAStreamProbe.h>
#include <VistaInterProcComm/Concurrency/VistaThreadEvent.h>
#include <VistaInterProcComm/Concurrency/VistaThreadLoop.h>
......@@ -61,6 +62,7 @@ protected:
private:
CITANetAudioClient* m_pClient;
CITANetAudioStream* m_pStream;
ITAStreamProbe* m_pStreamProbe;
CITANetAudioProtocol* m_pProtocol;
CITANetAudioMessage* m_pMessage;
......@@ -70,8 +72,7 @@ private:
ITASampleFrame m_sfReceivingBuffer; //!< Buffer incoming data
CITANetAudioProtocol::StreamingParameters m_oClientParams;
CITANetAudioProtocol::StreamingParameters m_oServerParams;
CITANetAudioProtocol::StreamingParameters m_oParams;
bool m_bStopIndicated;
......
......@@ -26,10 +26,14 @@
#include <string>
#include <vector>
#include <ITANetAudioProtocol.h>
#include <VistaInterProcComm/Concurrency/VistaThreadLoop.h>
#include <ITASampleFrame.h>
class ITADatasource;
class CITANetAudioMessage;
class CITANetAudioProtocol;
class CITANetAudioServer;
class CITANetAudioMessage;
class VistaTCPSocket;
......@@ -59,6 +63,7 @@ public:
bool IsClientConnected() const;
std::string GetNetworkAddress() const;
int GetNetworkPort() const;
bool LoopBody();
void Stop();
void SetInputStream( ITADatasource* pInStream );
......@@ -69,8 +74,6 @@ public:
void SetAutomaticUpdateRate();
bool LoopBody();
protected:
int Transmit( const ITASampleFrame& sfNewSamples, int iNumSamples );
ITADatasource* GetInputStream() const;
......@@ -81,6 +84,7 @@ private:
ITADatasource* m_pInputStream;
VistaConnectionIP* m_pConnection;
CITANetAudioProtocol::StreamingParameters m_oServerParams;
CITANetAudioMessage* m_pMessage;
int m_iUpdateStrategy;
......
This diff is collapsed.
......@@ -31,6 +31,7 @@ CITANetAudioServer::~CITANetAudioServer()
{
delete m_pConnection;
delete m_pServer;
delete m_pSocket;
}
std::string CITANetAudioServer::GetServerAddress() const
......
......@@ -7,11 +7,14 @@
// STL
#include <cmath>
#include <iostream>
CITANetAudioStream::CITANetAudioStream( int iChannels, double dSamplingRate, int iBufferSize, int iRingBufferCapacity )
: m_sfOutputStreamBuffer( iChannels, iBufferSize, true )
, m_dSampleRate( dSamplingRate )
, m_sfRingBuffer( iChannels, iRingBufferCapacity, true )
, m_bRingBufferFull( false )
, m_iStreamingStatus( INVALID )
{
if( iBufferSize > iRingBufferCapacity )
......@@ -19,17 +22,24 @@ CITANetAudioStream::CITANetAudioStream( int iChannels, double dSamplingRate, int
m_pNetAudioStreamingClient = new CITANetAudioStreamingClient( this );
m_iReadCursor = 0;
m_iWriteCursor = 0;
m_iWriteCursor = 0; // always ahead, i.e. iWriteCursor >= iReadCursor if unwrapped
m_iStreamingStatus = STOPPED;
outputFile.open( "program3data.txt" );
}
CITANetAudioStream::~CITANetAudioStream()
{
delete m_pNetAudioStreamingClient;
delete m_pNetAudioStreamingClient;
outputFile.close( );
}
bool CITANetAudioStream::Connect( const std::string& sAddress, int iPort )
{
return m_pNetAudioStreamingClient->Connect( sAddress, iPort );
bool bConnected = m_pNetAudioStreamingClient->Connect( sAddress, iPort );
if( bConnected )
m_iStreamingStatus = CONNECTED;
return bConnected;
}
bool CITANetAudioStream::GetIsConnected() const
......@@ -39,49 +49,102 @@ bool CITANetAudioStream::GetIsConnected() const
const float* CITANetAudioStream::GetBlockPointer( unsigned int uiChannel, const ITAStreamInfo* )
{
// @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();
}
ITASampleBuffer& sbOutputStreamBuffer( m_sfOutputStreamBuffer[ uiChannel ] );
sbOutputStreamBuffer.Zero();
const float* pfBlockPointer = sbOutputStreamBuffer.GetData();
if( !GetIsConnected() )
return pfBlockPointer;
m_iStreamingStatus = STREAMING;
return m_sfOutputStreamBuffer[ uiChannel ].GetData();
int iCurrentWriteCursor = m_iWriteCursor; // local copy
if( iCurrentWriteCursor <= m_iReadCursor && GetRingBufferFreeSamples() > 0 ) // Wrap around?
iCurrentWriteCursor += GetRingBufferSize(); // Write pointer always ahead, so unwrap first
int iReadableSamples = iCurrentWriteCursor - m_iReadCursor;
if ( iReadableSamples > int( GetBlocklength( ) ) ) // samples can be cyclic-copied safely from ring buffer
{
m_sfRingBuffer[ uiChannel ].cyclic_read( sbOutputStreamBuffer.GetData( ), sbOutputStreamBuffer.GetLength( ), m_iReadCursor );
pfBlockPointer = sbOutputStreamBuffer.GetData( );
}
else if( iReadableSamples > 0)
{
// @todo: fade with ITAFade
//std::cerr << "Should fade right now, but skipping samples." << std::endl;
}
return pfBlockPointer;
}
void CITANetAudioStream::IncrementBlockPointer()
{
// Increment read cursor by one audio block and wrap around if exceeding ring buffer
m_iReadCursor = ( m_iReadCursor + m_sfOutputStreamBuffer.GetLength() ) % m_sfRingBuffer.GetLength();
if ( ( GetRingBufferSize() - GetRingBufferFreeSamples( )) >= int( GetBlocklength( ) ) )
{
m_iReadCursor = ( m_iReadCursor + m_sfOutputStreamBuffer.GetLength() ) % m_sfRingBuffer.GetLength();
m_iStreamingStatus = STREAMING;
//outputFile << "incRead ";
}
else if ( GetIsRingBufferEmpty( ) )
{
//outputFile << "buffer empty ";
}
else
{
m_iStreamingStatus = BUFFER_UNDERRUN;
m_iReadCursor = m_iWriteCursor;
//outputFile << "BufferOverrun ";
}
m_bRingBufferFull = false;
//outputFile << "\tRead: " << m_iReadCursor;
//outputFile << "\tWrite : " << m_iWriteCursor;
//outputFile << "\tFreeSamples: " << GetRingBufferFreeSamples ()<< endl;
m_pNetAudioStreamingClient->TriggerBlockIncrement();
}
int CITANetAudioStream::Transmit( const ITASampleFrame& sfNewSamples, int iNumSamples )
{
// Take local copies (concurrent access)
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;
int iCurrentWriteCursor = m_iWriteCursor;
if( iCurrentWriteCursor < iCurrentReadCursor )
iCurrentWriteCursor += GetRingBufferSize(); // Unwrap, because write cursor always ahead
if( GetRingBufferFreeSamples() < iNumSamples )
{
// @todo: only partly write
//std::cerr << "BUFFER_OVERRUN! Would partly write samples because ring buffer will be full then." << std::endl;
m_iWriteCursor = m_iReadCursor;
m_bRingBufferFull = false;
//outputFile << " incSomeWrite: ";
}
else
{
// write samples into ring buffer
m_sfRingBuffer.cyclic_write( sfNewSamples, iNumSamples, 0, iCurrentWriteCursor );
// set write curser
m_iWriteCursor = ( m_iWriteCursor + iNumSamples ) % GetRingBufferSize( );
m_bRingBufferFull = true;
//outputFile << " IncWrite: ";
}
else {
return m_sfRingBuffer.GetLength() - m_iWriteCursor + iCurrentReadCursor;
}
//outputFile << "\tRead: " << m_iReadCursor;
//outputFile << "\tWrite : " << m_iWriteCursor;
//outputFile << "\tFreeSamples: " << GetRingBufferFreeSamples( ) << endl;
return GetRingBufferFreeSamples();
}
int CITANetAudioStream::GetRingbufferFreeSamples()
int CITANetAudioStream::GetRingBufferFreeSamples() const
{
int iFreeSamples = ( m_iWriteCursor - m_iReadCursor + GetRingBufferSize() ) % GetRingBufferSize();
if( m_bRingBufferFull )
return 0;
int iFreeSamples = GetRingBufferSize() - ( ( m_iWriteCursor - m_iReadCursor + GetRingBufferSize() ) % GetRingBufferSize() );
assert( iFreeSamples > 0 );
return iFreeSamples;
}
......@@ -90,6 +153,16 @@ int CITANetAudioStream::GetRingBufferSize() const
return m_sfRingBuffer.GetLength();
}
bool CITANetAudioStream::GetIsRingBufferFull() const
{
return m_bRingBufferFull;
}
bool CITANetAudioStream::GetIsRingBufferEmpty() const
{
return ( !m_bRingBufferFull && m_iReadCursor == m_iWriteCursor );
}
unsigned int CITANetAudioStream::GetBlocklength() const
{
return ( unsigned int ) m_sfOutputStreamBuffer.GetLength();
......
......@@ -12,11 +12,13 @@ CITANetAudioStreamingClient::CITANetAudioStreamingClient( CITANetAudioStream* pP
, m_pConnection( NULL )
, m_bStopIndicated( false )
{
m_pStreamProbe = new ITAStreamProbe( pParent, "output.wav" );
m_pClient = new CITANetAudioClient();
m_oClientParams.iChannels = pParent->GetNumberOfChannels();
m_oClientParams.dSampleRate = pParent->GetSampleRate();
m_oClientParams.iBlockSize = pParent->GetBlocklength();
m_oParams.iChannels = pParent->GetNumberOfChannels();
m_oParams.dSampleRate = pParent->GetSampleRate();
m_oParams.iBlockSize = pParent->GetBlocklength();
m_pMessage = new CITANetAudioMessage( VistaSerializingToolset::SWAPS_MULTIBYTE_VALUES );
}
......@@ -49,13 +51,18 @@ bool CITANetAudioStreamingClient::Connect( const std::string& sAddress, int iPor
// Validate streaming parameters of server and client
m_pMessage->SetMessageType( CITANetAudioProtocol::NP_CLIENT_OPEN );
m_pMessage->WriteStreamingParameters( m_oClientParams );
m_pMessage->WriteStreamingParameters( m_oParams );
m_pMessage->WriteMessage();
m_pMessage->ReadAnswer();
assert( m_pMessage->GetAnswerType() == CITANetAudioProtocol::NP_SERVER_OPEN );
bool bOK = m_pMessage->ReadBool();
/* Not yet
CITANetAudioProtocol::StreamingParameters oServerParams = m_pMessage->ReadStreamingParameters();
if (!(oServerParams == m_oParams))
ITA_EXCEPT1( INVALID_PARAMETER, "Streaming parameters of network audio server and client do not match." );
*/
if( !bOK )
ITA_EXCEPT1( INVALID_PARAMETER, "Streaming server declined connection, detected streaming parameter mismatch." );
......@@ -73,7 +80,7 @@ bool CITANetAudioStreamingClient::LoopBody()
m_pMessage->ResetMessage();
m_pMessage->SetConnection( m_pConnection );
m_pMessage->SetMessageType( CITANetAudioProtocol::NP_CLIENT_WAITING_FOR_SAMPLES );
m_pMessage->WriteInt( m_pStream->GetRingbufferFreeSamples() );
m_pMessage->WriteInt( m_pStream->GetRingBufferFreeSamples() );
m_pMessage->WriteMessage();
// Wait for answer of server
......@@ -84,20 +91,27 @@ bool CITANetAudioStreamingClient::LoopBody()
case CITANetAudioProtocol::NP_INVALID:
// Something went wrong
std::cerr << "Received invalid message type" << std::endl;
break;
case CITANetAudioProtocol::NP_SERVER_WAITING_FOR_TRIGGER:
// Wait until block increment is triggered by audio context (more free samples in ring buffer)
//std::cout << "Will wait for block increment" << std::endl;
m_oBlockIncrementEvent.WaitForEvent( true );
break;
case CITANetAudioProtocol::NP_SERVER_SEND_SAMPLES:
// Receive samples from net message and forward them to the stream ring buffer
m_pMessage->ReadSampleFrame( &m_sfReceivingBuffer );
//std::cout << "Receiving " << m_sfReceivingBuffer.GetLength() << " samples from streaming server" << std::endl;
if ( m_pStream->GetRingBufferFreeSamples( ) >= m_sfReceivingBuffer.GetLength( ) )
m_pStream->Transmit( m_sfReceivingBuffer, m_sfReceivingBuffer.GetLength( ) );
//else
// Fehler
//int iNumSamples = m_pMessage->ReadSampleFrame( &m_sfReceivingBuffer );
//if( m_pStream->GetRingbufferFreeSamples() >= iNumSamples )
// m_pStream->Transmit( m_sfReceivingBuffer, iNumSamples );
break;
case CITANetAudioProtocol::NP_SERVER_GET_RINGBUFFER_FREE :
break;
}
......
......@@ -4,6 +4,7 @@
// ITA includes
#include <ITADataSource.h>
#include <ITANetAudioMessage.h>
#include <ITAException.h>
#include <ITAStreamInfo.h>
......@@ -31,7 +32,7 @@ bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort
if( !m_pInputStream )
ITA_EXCEPT1( MODAL_EXCEPTION, "Can not start server without a valid input stream" );
// TODO: vorrckgabe noch anfangen zu senden (Samples)
// TODO: vorrckgabe noch anfangen zu senden (Samples)
if( !m_pNetAudioServer->Start( sAddress, iPort ) ) // blocking
return false;
......@@ -46,10 +47,20 @@ bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort
CITANetAudioProtocol::StreamingParameters oClientParams = m_pMessage->ReadStreamingParameters();
bool bOK = false;
if( m_pInputStream->GetNumberOfChannels() == oClientParams.iChannels &&
if (m_pInputStream->GetNumberOfChannels() == oClientParams.iChannels &&
m_pInputStream->GetSampleRate() == oClientParams.dSampleRate &&
m_pInputStream->GetBlocklength() == oClientParams.iBlockSize )
m_pInputStream->GetBlocklength() == oClientParams.iBlockSize)
{
bOK = true;
}
std::cout << " Client Data: \nAnzahl Channel: " << oClientParams.iChannels << std::endl;
std::cout << "SampleRate: " << oClientParams.dSampleRate << std::endl;
std::cout << "Blockgroesse: " << oClientParams.iBlockSize << std::endl;
std::cout << " Server Data: \nAnzahl Channel: " << m_pInputStream->GetNumberOfChannels() << std::endl;
std::cout << "SampleRate: " << m_pInputStream->GetSampleRate() << std::endl;
std::cout << "Blockgroesse: " << m_pInputStream->GetBlocklength() << std::endl;
m_pMessage->SetAnswerType( CITANetAudioProtocol::NP_SERVER_OPEN );
m_pMessage->WriteBool( bOK );
......@@ -111,31 +122,46 @@ bool CITANetAudioStreamingServer::LoopBody()
m_pMessage->SetConnection( m_pConnection );
m_pMessage->ReadMessage(); // blocking
switch( m_pMessage->GetMessageType() )
int iMsgType = m_pMessage->GetMessageType();
switch( iMsgType )
{
case CITANetAudioProtocol::NP_CLIENT_WAITING_FOR_SAMPLES:
{
int iFreeSamples = m_pMessage->ReadInt();
if( iFreeSamples >= m_pInputStream->GetBlocklength() )
{
// Send Samples
for( int i = 0; i < m_pInputStream->GetNumberOfChannels(); i++ )
{
ITAStreamInfo oStreamInfo;
oStreamInfo.nSamples = m_sfTempTransmitBuffer.GetLength();
const float* pfData = m_pInputStream->GetBlockPointer( i, &oStreamInfo );
m_sfTempTransmitBuffer[ i ].write( pfData, m_pInputStream->GetBlocklength() );
if( pfData != 0 )
m_sfTempTransmitBuffer[ i ].write( pfData, m_sfTempTransmitBuffer.GetLength() );
}
m_pInputStream->IncrementBlockPointer();
m_pMessage->SetAnswerType( CITANetAudioProtocol::NP_SERVER_SEND_SAMPLES );
//m_pMessage->WriteSampleFrame( &m_sfTempTransmitBuffer );
m_pMessage->WriteSampleFrame( &m_sfTempTransmitBuffer );
m_pMessage->WriteAnswer();
//std::cout << "Transmitted " << m_pInputStream->GetBlocklength() << " samples, because there where " << iFreeSamples << " free samples on client side" << std::endl;
}
else
{
//std::cout << "Could not transmitt, because there where only " << iFreeSamples << " free samples on client side" << std::endl;
// Waiting for Trigger
m_pMessage->SetAnswerType( CITANetAudioProtocol::NP_SERVER_WAITING_FOR_TRIGGER );
m_pMessage->WriteAnswer();
break;
}
m_pMessage->WriteAnswer();
float fTimeOut = m_pInputStream->GetBlocklength() / m_pInputStream->GetSampleRate();
//VistaTimeUtils::Sleep( (int) ( 1 * 100 ) );
break;
}
case CITANetAudioProtocol::NP_CLIENT_CLOSE:
{
m_pMessage->WriteAnswer();
m_pConnection = NULL;
StopGently( true );
......@@ -143,6 +169,12 @@ bool CITANetAudioStreamingServer::LoopBody()
return false;
}
default:
{
std::cout << "Unkown protocol type: " << iMsgType << std::endl;
break;
}
}
return true;
}
......
......@@ -6,12 +6,13 @@ include( VistaCommon )
vista_use_package( ITADataSources REQUIRED FIND_DEPENDENCIES )
if( ITA_CORE_LIBS_BUILD_STATIC AND DEFINED ITA_CORE_LIBS_BUILD_STATIC )
if( ITA_CORE_LIBS_BUILD_STATIC )
add_definitions( -DITA_BASE_STATIC -DITA_DATA_SOURCES_STATIC )
endif( )
# todo fix with if( vista_staic )!
add_definitions( -DVISTABASE_STATIC -DVISTAMATH_STATIC -DVISTAASPECTS_STATIC -DVISTATOOLS_STATIC -DVISTAINTERPROCCOMM_STATIC )
if( ITA_VISTA_BUILD_STATIC )
add_definitions( -DVISTABASE_STATIC -DVISTAMATH_STATIC -DVISTAASPECTS_STATIC -DVISTATOOLS_STATIC -DVISTAINTERPROCCOMM_STATIC )
endif( )
add_executable( BufferDataSourceTest BufferDataSourceTest.cpp )
target_link_libraries( BufferDataSourceTest ${VISTA_USE_PACKAGE_LIBRARIES} )
......
cmake_minimum_required( VERSION 2.8 )
if( NOT ITADATASOURCES_COMMON_BUILD )
project( ITADataSourcesTest )
list( APPEND CMAKE_MODULE_PATH "$ENV{VISTA_CMAKE_COMMON}" )
include( VistaCommon )
project( ITADataSourcesTest )
list( APPEND CMAKE_MODULE_PATH "$ENV{VISTA_CMAKE_COMMON}" )
include( VistaCommon )
endif()
vista_use_package( ITADataSources REQUIRED FIND_DEPENDENCIES )
......
cmake_minimum_required( VERSION 2.8 )
if( NOT ITADATASOURCES_COMMON_BUILD )
project( ITADataSourcesTest )
list( APPEND CMAKE_MODULE_PATH "$ENV{VISTA_CMAKE_COMMON}" )
include( VistaCommon )
endif()
project( ITADataSourcesTest )
list( APPEND CMAKE_MODULE_PATH "$ENV{VISTA_CMAKE_COMMON}" )
include( VistaCommon )
vista_use_package( ITADataSources REQUIRED FIND_DEPENDENCIES )
add_definitions( -DITA_DATA_SOURCES_DLL )
# Loopback
add_executable( ITAJackLoopback ITAJackLoopback.cpp )
target_link_libraries( ITAJackLoopback ${VISTA_USE_PACKAGE_LIBRARIES} )
......
cmake_minimum_required( VERSION 2.8 )
if( NOT ITADATASOURCES_COMMON_BUILD )
project( ITADataSourcesTest )
list( APPEND CMAKE_MODULE_PATH "$ENV{VISTA_CMAKE_COMMON}" )
include( VistaCommon )
endif()
project( ITADataSourcesTest )
list( APPEND CMAKE_MODULE_PATH "$ENV{VISTA_CMAKE_COMMON}" )
include( VistaCommon )
vista_use_package( ITADataSources REQUIRED FIND_DEPENDENCIES )
add_definitions( -DITA_DATA_SOURCES_DLL )
add_executable( ITAPortaudioInterfaceRecorder ITAPortaudioInterfaceRecorder.cpp )
target_link_libraries( ITAPortaudioInterfaceRecorder ${VISTA_USE_PACKAGE_LIBRARIES} )
......
cmake_minimum_required( VERSION 2.9 )
if( NOT ITADATASOURCES_COMMON_BUILD )
project( ITANetAudioTests )
list( APPEND CMAKE_MODULE_PATH "$ENV{VISTA_CMAKE_COMMON}" )
include( VistaCommon )
endif()
project( ITANetAudioTests )
list( APPEND CMAKE_MODULE_PATH "$ENV{VISTA_CMAKE_COMMON}" )
include( VistaCommon )
vista_use_package( VistaCoreLibs REQUIRED COMPONENTS VistaInterProcComm FIND_DEPENDENCIES )
vista_use_package( ITADataSources REQUIRED FIND_DEPENDENCIES )
......
......@@ -5,22 +5,25 @@
#include <ITAPortaudioInterface.h>
#include <ITAStreamMultiplier1N.h>
#include <ITAException.h>
#include <ITAFileDatasource.h>
#include <ITAStreamProbe.h>
using namespace std;
static string g_sServerName = "localhost";
static int g_iServerPort = 12480;
static double g_dSampleRate = 44.1e3;
static double g_dSampleRate = 44100;
static int g_iBufferSize = 256;
int main( int , char** )
{
CITANetAudioStream oNetAudioStream( 1, g_dSampleRate, g_iBufferSize, 4 * g_iBufferSize );
ITAStreamMultiplier1N oMultiplier( &oNetAudioStream, 2 );
CITANetAudioStream oNetAudioStream( 2, g_dSampleRate, g_iBufferSize, 100 * g_iBufferSize );
ITAStreamProbe oProbe( &oNetAudioStream, "out_gutentag.wav" );
//ITAStreamMultiplier1N oMultiplier( &oProbe, 2 );
ITAPortaudioInterface ITAPA( g_dSampleRate, g_iBufferSize );
ITAPA.Initialize();
ITAPA.SetPlaybackDatasource( &oMultiplier );
ITAPA.SetPlaybackDatasource( &oProbe );
ITAPA.Open();
ITAPA.Start();
......@@ -55,6 +58,8 @@ int main( int , char** )
ITAPA.Stop();
ITAPA.Close();
ITAPA.Finalize();
return 0;
}
......@@ -4,26 +4,27 @@
#include <ITANetAudioStreamingServer.h>
#include <ITANetAudioServer.h>
#include <ITAStreamFunctionGenerator.h>
#include <ITAFileDatasource.h>
using namespace std;
static string g_sServerName = "localhost";
static int g_iServerPort = 12480;
static double g_dSampleRate = 44.1e3;
static double g_dSampleRate = 44100;
static int g_iBlockLength = 256;
int main( int , char** )
{
ITAStreamFunctionGenerator oGenerator( 1, g_dSampleRate, g_iBlockLength, ITAStreamFunctionGenerator::SINE, 456.78f, 0.81f, true );
ITAStreamFunctionGenerator oGenerator( 2, g_dSampleRate, g_iBlockLength, ITAStreamFunctionGenerator::SINE, 456.78f, 0.81f, true );
ITAFileDatasource oDatei("01_Empfang_Guten_Tag.wav", g_iBlockLength);
CITANetAudioStreamingServer oStreamingServer;
oStreamingServer.SetInputStream( &oGenerator );
oStreamingServer.SetInputStream(&oDatei);
cout << "Starting server and waiting for connections on '" << g_sServerName << "' on port " << g_iServerPort << endl;
oStreamingServer.Start( g_sServerName, g_iServerPort );
int iKey;
cin >> iKey;
std::cin >> iKey;
return 0;
}
cmake_minimum_required( VERSION 2.9 )
if( NOT ITADATASOURCES_COMMON_BUILD )
project( ITADataSourcesTest )
list( APPEND CMAKE_MODULE_PATH "$ENV{VISTA_CMAKE_COMMON}" )
include( VistaCommon )
endif()
project( ITADataSourcesTest )
list( APPEND CMAKE_MODULE_PATH "$ENV{VISTA_CMAKE_COMMON}" )
include( VistaCommon )
vista_use_package( VistaCoreLibs REQUIRED COMPONENTS VistaInterProcComm FIND_DEPENDENCIES )
vista_use_package( ITABase REQUIRED FIND_DEPENDENCIES )
......