Cleanups

implemented parameter setting for server when connection a data source
switching to vista output stream (works with concurrent writes from different threads)
parent b7547986
......@@ -83,7 +83,9 @@ public:
{
if( ( iChannels == rhs.iChannels ) && ( dSampleRate == rhs.dSampleRate ) && ( iBlockSize == rhs.iBlockSize ) )
return true;
}
else
return false;
};
};
};
......
......@@ -64,7 +64,6 @@ protected:
private:
CITANetAudioClient* m_pClient;
CITANetAudioStream* m_pStream;
ITAStreamProbe* m_pStreamProbe;
CITANetAudioProtocol* m_pProtocol;
CITANetAudioMessage* m_pMessage;
......
......@@ -9,12 +9,13 @@
#include <ITAClock.h>
#include <iomanip>
// STL
// Vista includes
#include <VistaBase/VistaStreamUtils.h>
// STL includes
#include <cmath>
#include <iostream>
#define NET_AUDIO_SHOW_TRAFFIC 0;
//! Audio streaming log item
struct ITAStreamLog : public ITALogDataBase
{
......@@ -190,7 +191,7 @@ const float* CITANetAudioStream::GetBlockPointer( unsigned int uiChannel, const
m_sfOutputStreamBuffer[ uiChannel ].Zero();
m_iStreamingStatus = BUFFER_UNDERRUN;
#if NET_AUDIO_SHOW_TRAFFIC
std::cout << "[ Stream ] Buffer underrun" << std::endl;
vstr::out() << "[ Stream ] Buffer underrun" << std::endl;
#endif
}
else
......@@ -201,7 +202,7 @@ const float* CITANetAudioStream::GetBlockPointer( unsigned int uiChannel, const
m_sfRingBuffer[ uiChannel ].Zero();
m_iStreamingStatus = BUFFER_UNDERRUN;
#if NET_AUDIO_SHOW_TRAFFIC
std::cout << "[ Stream ] Buffer underrun" << std::endl;
vstr::out() << "[ Stream ] Buffer underrun" << std::endl;
#endif
}
else
......@@ -210,7 +211,7 @@ const float* CITANetAudioStream::GetBlockPointer( unsigned int uiChannel, const
m_sfRingBuffer[ uiChannel ].cyclic_read( m_sfOutputStreamBuffer[ uiChannel ].GetData(), GetBlocklength(), m_iReadCursor );
m_iStreamingStatus = STREAMING;
#if NET_AUDIO_SHOW_TRAFFIC
std::cout << "[ Stream ] Streaming" << std::endl;
vstr::out() << "[ Stream ] Streaming" << std::endl;
#endif
}
}
......@@ -233,21 +234,21 @@ void CITANetAudioStream::IncrementBlockPointer()
m_iReadCursor = ( m_iReadCursor + m_sfOutputStreamBuffer.GetLength() ) % m_sfRingBuffer.GetLength();
m_iStreamingStatus = STREAMING;
#if NET_AUDIO_SHOW_TRAFFIC
std::cout << "[ Stream ] Streaming" << std::endl;
vstr::out() << "[ Stream ] Streaming" << std::endl;
#endif
}
else if ( GetIsRingBufferEmpty( ) )
{
m_iStreamingStatus = BUFFER_UNDERRUN;
#if NET_AUDIO_SHOW_TRAFFIC
std::cout << "[ Stream ] Buffer underrun" << std::endl;
vstr::out() << "[ Stream ] Buffer underrun" << std::endl;
#endif
}
else
{
m_iStreamingStatus = BUFFER_OVERRUN;
#if NET_AUDIO_SHOW_TRAFFIC
std::cout << "[ Stream ] Buffer overrun" << std::endl;
vstr::out() << "[ Stream ] Buffer overrun" << std::endl;
#endif
m_iReadCursor = m_iWriteCursor;
}
......@@ -279,7 +280,7 @@ int CITANetAudioStream::Transmit( const ITASampleFrame& sfNewSamples, int iNumSa
// BufferFull
oLog.iBufferStatus = 1;
#if NET_AUDIO_SHOW_TRAFFIC
std::cout << "[ NetAudio ] Buffer overrun" << std::endl;
vstr::out() << "[ NetAudio ] Buffer overrun" << std::endl;
#endif
}
else if( GetRingBufferFreeSamples() < iNumSamples )
......@@ -297,7 +298,7 @@ int CITANetAudioStream::Transmit( const ITASampleFrame& sfNewSamples, int iNumSa
m_bRingBufferFull = false;
oLog.iBufferStatus = 1;
#if NET_AUDIO_SHOW_TRAFFIC
std::cout << "[ NetAudio ] Buffer write" << std::endl;
vstr::out() << "[ NetAudio ] Buffer write" << std::endl;
#endif
// set write curser
......@@ -307,7 +308,7 @@ int CITANetAudioStream::Transmit( const ITASampleFrame& sfNewSamples, int iNumSa
m_bRingBufferFull = true;
oLog.iBufferStatus = 1;
#if NET_AUDIO_SHOW_TRAFFIC
std::cout << "[ NetAudio ] Buffer overrun" << std::endl;
vstr::out() << "[ NetAudio ] Buffer overrun" << std::endl;
#endif
}
}
......@@ -321,7 +322,6 @@ int CITANetAudioStream::Transmit( const ITASampleFrame& sfNewSamples, int iNumSa
return GetRingBufferFreeSamples();
}
int CITANetAudioStream::GetRingBufferAvailableSamples() const
{
return GetRingBufferSize() - GetRingBufferFreeSamples();
......
......@@ -5,6 +5,7 @@
#include <ITANetAudioStream.h>
#include <VistaInterProcComm/Connections/VistaConnectionIP.h>
#include <VistaBase/VistaStreamUtils.h>
CITANetAudioStreamingClient::CITANetAudioStreamingClient( CITANetAudioStream* pParent )
: m_oBlockIncrementEvent( VistaThreadEvent::WAITABLE_EVENT )
......@@ -12,8 +13,6 @@ CITANetAudioStreamingClient::CITANetAudioStreamingClient( CITANetAudioStream* pP
, m_pConnection( NULL )
, m_bStopIndicated( false )
{
m_pStreamProbe = new ITAStreamProbe( pParent, "output.wav" );
m_pClient = new CITANetAudioClient();
m_oParams.iChannels = pParent->GetNumberOfChannels();
......@@ -57,11 +56,6 @@ bool CITANetAudioStreamingClient::Connect( const std::string& sAddress, int iPor
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." );
......@@ -93,7 +87,7 @@ bool CITANetAudioStreamingClient::LoopBody()
case CITANetAudioProtocol::NP_INVALID:
// Something went wrong
std::cerr << "Received invalid message type" << std::endl;
vstr::err() << "Received invalid message type" << std::endl;
break;
case CITANetAudioProtocol::NP_SERVER_WAITING_FOR_TRIGGER:
......
......@@ -14,6 +14,7 @@
#include <VistaInterProcComm/IPNet/VistaTCPSocket.h>
#include <VistaBase/VistaTimeUtils.h>
#include <VistaInterProcComm/IPNet/VistaIPAddress.h>
#include <VistaBase/VistaStreamUtils.h>
// STL
#include <cmath>
......@@ -32,7 +33,6 @@ 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: vorr�ckgabe noch anfangen zu senden (Samples)
if( !m_pNetAudioServer->Start( sAddress, iPort ) ) // blocking
return false;
......@@ -47,28 +47,26 @@ bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort
CITANetAudioProtocol::StreamingParameters oClientParams = m_pMessage->ReadStreamingParameters();
bool bOK = false;
if (m_pInputStream->GetNumberOfChannels() == oClientParams.iChannels &&
m_pInputStream->GetSampleRate() == oClientParams.dSampleRate &&
m_pInputStream->GetBlocklength() == oClientParams.iBlockSize)
if( m_oServerParams == oClientParams )
{
bOK = true;
#ifdef NET_AUDIO_SHOW_TRAFFIC
vstr::out() << "Server and client parameters matched. Will resume with streaming" << std::endl;
}
else
{
vstr::out() << "Server and client parameters mismatch detected. Will notify client and stop." << std::endl;
#endif
}
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 );
m_pMessage->WriteAnswer();
Run();
if( bOK )
Run();
return true;
return bOK;
}
bool CITANetAudioStreamingServer::IsClientConnected() const
......@@ -98,7 +96,9 @@ void CITANetAudioStreamingServer::SetInputStream( ITADatasource* pInStream )
m_pInputStream = pInStream;
m_sfTempTransmitBuffer.init( m_pInputStream->GetNumberOfChannels(), m_pInputStream->GetBlocklength(), true );
m_oServerParams.dSampleRate = m_pInputStream->GetSampleRate();
m_oServerParams.iBlockSize = m_pInputStream->GetBlocklength();
m_oServerParams.iChannels = m_pInputStream->GetNumberOfChannels();
}
int CITANetAudioStreamingServer::GetNetStreamBlocklength() const
......@@ -181,5 +181,6 @@ ITADatasource* CITANetAudioStreamingServer::GetInputStream() const
int CITANetAudioStreamingServer::Transmit(const ITASampleFrame& sfNewSamples, int iNumSamples)
{
assert( false );
return 0;
}
......@@ -11,119 +11,105 @@
#include <ITAException.h>
#include <ITAFileDatasource.h>
#include <ITAStreamProbe.h>
#include <ITAStreamPatchbay.h>
#include <ITAStreamPatchbay.h>
#include <VistaBase/VistaStreamUtils.h>
using namespace std;
static string g_sServerName = "localhost";
static int g_iServerPort = 12480;
static double g_dSampleRate = 44100;
static int g_iBlockLength = 1024;
static int g_iChannels = 2;
const static string g_sServerName = "localhost";
const static string g_sInputFilePath = "gershwin-mono.wav";
const static int g_iServerPort = 12480;
const static double g_dSampleRate = 44100;
const static int g_iBlockLength = 1024;
const static int g_iChannels = 2;
class CServer : public VistaThread
{
public:
CServer( )
{
pGenerator = new ITAStreamFunctionGenerator( 2, g_dSampleRate, g_iBlockLength, ITAStreamFunctionGenerator::SINE, 456.78f, 0.81f, true );
pDatei = new ITAFileDatasource( "gershwin-mono.wav", g_iBlockLength );
pMuliplier = new ITAStreamMultiplier1N( pDatei, g_iChannels );
inline CServer( const string& sInputFilePath )
{
pInputFile = new ITAFileDatasource( sInputFilePath, g_iBlockLength );
assert( pInputFile->GetNumberOfChannels() == 1 );
pMuliplier = new ITAStreamMultiplier1N( pInputFile, g_iChannels );
pStreamingServer = new CITANetAudioStreamingServer;
pStreamingServer->SetInputStream( pMuliplier );
cout << "[ Server ] Starting server and waiting for connections on '" << g_sServerName << "' on port " << g_iServerPort << endl;
pStreamingServer->SetInputStream( pMuliplier );
Run();
};
~CServer( )
inline ~CServer( )
{
delete pGenerator;
delete pDatei;
delete pInputFile;
delete pMuliplier;
delete pStreamingServer;
};
void ThreadBody( )
{
pStreamingServer->Start( g_sServerName, g_iServerPort );
void ThreadBody( )
{
vstr::out() << "[ Server ] Starting net audio server and waiting for client connections on '" << g_sServerName << "' on port " << g_iServerPort << endl;
pStreamingServer->Start( g_sServerName, g_iServerPort );
};
private:
ITAStreamFunctionGenerator *pGenerator;
ITAFileDatasource* pDatei;
ITAFileDatasource* pInputFile;
ITAStreamMultiplier1N* pMuliplier;
CITANetAudioStreamingServer* pStreamingServer;
};
int main( int, char** )
{
// Server-Kram
CServer oServer;
// Sample server (forked away into a thread)
CServer oServer( g_sInputFilePath );
// Client-Kram
// Client dumping received stream and mixing down to two channels
CITANetAudioStream oNetAudioStream( g_iChannels, g_dSampleRate, g_iBlockLength, 100 * g_iBlockLength );
ITAStreamProbe oProbe( &oNetAudioStream, "ITANetAudioTest.stream.wav" );
ITAStreamPatchbay oPatchbay( g_dSampleRate, g_iBlockLength );
oPatchbay.AddInput( &oNetAudioStream );
ITADatasource* pOutput;
oPatchbay.AddOutput( 1 );
/*
for ( int i = 0; i < oNetAudioStream.GetNumberOfChannels( ); i++ )
{
if ( i % 2 == 0 )
oPatchbay.ConnectChannels( 0, i, 0, 0 );
else
oPatchbay.ConnectChannels( 0, i, 0, 1 );
*/
oPatchbay.ConnectChannels( 0, 0, 0, 0, 1.0f );
pOutput = oPatchbay.GetOutputDatasource( 0 );
ITAStreamProbe oProbe( pOutput, "output.wav" );
ITAStreamMultiplier1N oMultiplier( &oProbe, 2 );
oPatchbay.AddInput( &oProbe );
int iOutputID = oPatchbay.AddOutput( 2 );
for ( unsigned int i = 0; i < oNetAudioStream.GetNumberOfChannels( ); i++ )
oPatchbay.ConnectChannels( 0, i, 0, i % 1 );
ITAPortaudioInterface ITAPA( g_dSampleRate, g_iBlockLength );
ITAPA.Initialize( );
ITAPA.SetPlaybackDatasource( &oMultiplier );
ITAPA.Open( );
ITAPA.Start( );
ITAPA.Initialize();
ITAPA.SetPlaybackDatasource( oPatchbay.GetOutputDatasource( iOutputID ) );
ITAPA.Open();
ITAPA.Start();
cout << "[ Client ] Waiting 3 seconds (net audio stream not connected and returning zeros)" << endl;
ITAPA.Sleep( 3.0f );
vstr::out() << "[ Client ] Waiting 1 second (net audio stream not connected and playing back zeros)" << endl;
ITAPA.Sleep( 1.0f );
cout << "[ Client ] Will now connect to '" << g_sServerName << "' on port " << g_iServerPort << endl;
vstr::out() << "[ Client ] Will now connect to net audio server '" << g_sServerName << "' on port " << g_iServerPort << endl;
try
{
if ( !oNetAudioStream.Connect( g_sServerName, g_iServerPort ) )
ITA_EXCEPT1( INVALID_PARAMETER, "Could not connect to server" );
ITA_EXCEPT1( INVALID_PARAMETER, "Could not connect to net audio server" );
}
catch ( ITAException e )
{
cout << "[ Client ] Connection failed." << endl;
cerr << e << endl;
vstr::warn() << "[ Client ] Connection failed." << endl;
vstr::err() << e << endl;
return 255;
}
cout << "[ Client ] Connected." << endl;
vstr::out() << "[ Client ] Connected." << endl;
// Playback
float fSeconds = 10.0f;
cout << "[ Client ] Playback started, waiting " << fSeconds << " seconds" << endl;
float fSeconds = 5.0f;
vstr::out() << "[ Client ] Playback started, waiting " << fSeconds << " seconds" << endl;
ITAPA.Sleep( fSeconds ); // blocking
cout << "[ Client ] Done." << endl;
vstr::out() << "[ Client ] Done." << endl;
cout << "[ Client ] Will now disconnect from '" << g_sServerName << "' and port " << g_iServerPort << endl;
cout << "[ Client ] Closing in 3 seconds (net audio stream not connected and returning zeros)" << endl;
ITAPA.Sleep( 3.0f );
vstr::out() << "[ Client ] Will now disconnect from net audio server '" << g_sServerName << "' and port " << g_iServerPort << endl;
vstr::out() << "[ Client ] Closing in 1 second (net audio stream not connected and playing back zeros)" << endl;
ITAPA.Sleep( 1.0f );
ITAPA.Stop( );
ITAPA.Close( );
ITAPA.Finalize( );
return 0;
}
......@@ -31,7 +31,7 @@ public:
void ThreadBody()
{
cout << "[ Server ] Waiting for connections" << endl;
vstr::out() << "[ Server ] Waiting for connections" << endl;
VistaTCPSocket* pSocket = m_pServer->GetNextClient();
vstr::out() << "[ Server ] Connected." << endl;
......
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