Progress, now also ASIO available for NetAudio test.

parent 44b290fe
......@@ -256,7 +256,6 @@ int CITANetAudioStream::Transmit( const ITASampleFrame& sfNewSamples, int iNumSa
int iCurrentReadCursor = m_iReadCursor;
int iCurrentWriteCursor = m_iWriteCursor;
ITANetworkStreamLog oLog;
if( iCurrentWriteCursor < iCurrentReadCursor )
iCurrentWriteCursor += GetRingBufferSize(); // Unwrap, because write cursor always ahead
......@@ -296,6 +295,8 @@ int CITANetAudioStream::Transmit( const ITASampleFrame& sfNewSamples, int iNumSa
#endif
}
}
ITANetworkStreamLog oLog;
oLog.sBufferStatus = GetStreamingStatusString( m_iStreamingStatus );
oLog.dWorldTimeStamp = ITAClock::getDefaultClock( )->getTime( );
oLog.uiBlockId = ++m_iAudioStreamingBlockID;
......
......@@ -7,6 +7,7 @@
#include <ITAClock.h>
#include <VistaInterProcComm/Connections/VistaConnectionIP.h>
#include <VistaInterProcComm/Concurrency/VistaPriority.h>
#include <VistaBase/VistaStreamUtils.h>
#include <VistaBase/VistaTimeUtils.h>
......@@ -67,6 +68,8 @@ CITANetAudioStreamingClient::CITANetAudioStreamingClient( CITANetAudioStream* pP
m_pClientLogger = new ITABufferedDataLoggerImplClient();
SetClientLoggerBaseName( "ITANetAudioStreamingClient" );
VistaThread::SetPriority( VistaPriority::VISTA_MID_PRIORITY );
}
CITANetAudioStreamingClient::~CITANetAudioStreamingClient()
......
......@@ -15,6 +15,7 @@
#include <VistaInterProcComm/IPNet/VistaTCPSocket.h>
#include <VistaBase/VistaTimeUtils.h>
#include <VistaInterProcComm/IPNet/VistaIPAddress.h>
#include <VistaInterProcComm/Concurrency/VistaPriority.h>
#include <VistaBase/VistaStreamUtils.h>
#include <ITADataLog.h>
......@@ -67,6 +68,8 @@ CITANetAudioStreamingServer::CITANetAudioStreamingServer()
iServerBlockId = 0;
m_iMaxSendBlocks = 40;
m_iEstimatedClientRingBufferFreeSamples = 0;
VistaThread::SetPriority( VistaPriority::VISTA_MID_PRIORITY );
}
CITANetAudioStreamingServer::~CITANetAudioStreamingServer()
......
......@@ -12,8 +12,11 @@
#include <ITAFileDataSource.h>
#include <ITAStreamProbe.h>
#include <ITAStreamPatchBay.h>
#include <ITAAsioInterface.h>
#include <VistaBase/VistaStreamUtils.h>
#include <VistaBase/VistaTimeUtils.h>
#include <VistaBase/VistaExceptionBase.h>
using namespace std;
......@@ -23,8 +26,11 @@ const static int g_iServerPort = 12480;
const static double g_dSampleRate = 44100;
const static int g_iBlockLength = 512;
const static int g_iChannels = 2;
const static int g_iTargetLatencySamples = g_iBlockLength * 4;
const static int g_iRingerBufferCapacity = g_iBlockLength * 8;
const static int g_iTargetLatencySamples = g_iBlockLength * 3;
const static int g_iRingerBufferCapacity = g_iBlockLength * 4;
const static double g_dDuration = 10.0f;
const static bool g_bUseASIO = true;
const static string g_sAudioInterface = "ASIO4ALL v2";
class CServer : public VistaThread
{
......@@ -36,6 +42,7 @@ public:
pStreamingServer->SetServerLogBaseName( "ITANetAudioTest_Server" );
pInputFile = new ITAFileDatasource( sInputFilePath, g_iBlockLength );
pInputFile->SetIsLooping( true );
assert( pInputFile->GetNumberOfChannels() == 1 );
pMuliplier = new ITAStreamMultiplier1N( pInputFile, g_iChannels );
pInputStreamProbe = new ITAStreamProbe( pMuliplier, "ITANetAudioTest.serverstream.wav" );
......@@ -66,8 +73,9 @@ private:
};
int main( int, char** )
void run_test()
{
// Sample server (forked away into a thread)
CServer* pServer = new CServer( g_sInputFilePath );
......@@ -80,51 +88,91 @@ int main( int, char** )
int iOutputID = oPatchbay.AddOutput( 2 );
int N = int( oNetAudioStream.GetNumberOfChannels() );
for ( int i = 0; i < N ; i++ )
for( int i = 0; i < N; i++ )
oPatchbay.ConnectChannels( 0, i, 0, i % 2, 1 / double( N ) );
ITAStreamProbe oProbe( oPatchbay.GetOutputDatasource( iOutputID ), "ITANetAudioTest.netstream.wav" );
ITAPortaudioInterface ITAPA( g_dSampleRate, g_iBlockLength );
ITAPA.Initialize();
ITAPA.SetPlaybackDatasource( &oProbe );
ITAPA.Open();
ITAPA.Start();
vstr::out() << "[ NetAudioTestClient ] Waiting 1 second (net audio stream not connected and playing back zeros)" << endl;
ITAPA.Sleep( 1.0f );
vstr::out() << "[ NetAudioTestClient ] Will now connect to net audio server '" << g_sServerName << "' on port " << g_iServerPort << endl;
try
if( g_bUseASIO )
{
if ( !oNetAudioStream.Connect( g_sServerName, g_iServerPort ) )
ITA_EXCEPT1( INVALID_PARAMETER, "Could not connect to net audio server" );
ITAsioInitializeLibrary();
ITAsioInitializeDriver( g_sAudioInterface );
long lBuffersize, lDummy;
ITAsioGetBufferSize( &lDummy, &lDummy, &lBuffersize, &lDummy );
ITAsioSetSampleRate( ( ASIOSampleRate ) g_dSampleRate );
long lNumInputChannels, lNumOutputChannels;
ITAsioGetChannels( &lNumInputChannels, &lNumOutputChannels );
ITAsioCreateBuffers( 0, 2, lBuffersize );
ITAsioSetPlaybackDatasource( &oProbe );
ITAsioStart();
}
catch ( ITAException e )
else
{
vstr::warn() << "[ NetAudioTestClient ] Connection failed." << endl;
vstr::err() << e << endl;
return 255;
ITAPA.Initialize();
ITAPA.SetPlaybackDatasource( &oProbe );
ITAPA.Open();
ITAPA.Start();
}
vstr::out() << "[ NetAudioTestClient ] Waiting 1 second (net audio stream not connected and playing back zeros)" << endl;
VistaTimeUtils::Sleep( int( 1.0f * 1.0e3 ) );
vstr::out() << "[ NetAudioTestClient ] Will now connect to net audio server '" << g_sServerName << "' on port " << g_iServerPort << endl;
if( !oNetAudioStream.Connect( g_sServerName, g_iServerPort ) )
ITA_EXCEPT1( INVALID_PARAMETER, "Could not connect to net audio server" );
vstr::out() << "[ NetAudioTestClient ] Connected." << endl;
// Playback
float fSeconds = 10.0f;
float fSeconds = float( g_dDuration );
vstr::out() << "[ NetAudioTestClient ] Playback started, waiting " << fSeconds << " seconds" << endl;
ITAPA.Sleep( fSeconds ); // blocking
VistaTimeUtils::Sleep( int( fSeconds * 1.0e3 ) ); // blocking
vstr::out() << "[ NetAudioTestClient ] Done." << endl;
oNetAudioStream.Disconnect();
vstr::out() << "[ NetAudioTestClient ] Will now disconnect from net audio server '" << g_sServerName << "' and port " << g_iServerPort << endl;
vstr::out() << "[ NetAudioTestClient ] Closing in 1 second (net audio stream not connected and playing back zeros)" << endl;
ITAPA.Sleep( 1.0f );
VistaTimeUtils::Sleep( int( 1.0f * 1.0e3 ) );
ITAPA.Stop( );
ITAPA.Close( );
ITAPA.Finalize( );
if( g_bUseASIO )
{
ITAsioStop();
ITAsioDisposeBuffers();
ITAsioFinalizeDriver();
ITAsioFinalizeLibrary();
}
else
{
ITAPA.Stop();
ITAPA.Close();
ITAPA.Finalize();
}
delete pServer;
};
int main( int, char** )
{
try
{
run_test();
}
catch( ITAException& ie )
{
vstr::err() << ie << endl;
return 255;
}
catch( VistaExceptionBase& ve )
{
vstr::err() << ve.GetBacktraceString() << endl;
return 255;
}
return 0;
}
......@@ -2,28 +2,38 @@
ITANetAudioTest_Client = readtable( 'ITANetAudioTest_Client.log', 'FileType', 'text', 'Delimiter', '\t');
ITANetAudioTest_Server = readtable( 'ITANetAudioTest_Server.log', 'FileType', 'text', 'Delimiter', '\t');
ITANetAudioTest_Client_AudioStream = readtable( 'ITANetAudioTest_Client_AudioStream.log', 'FileType', 'text', 'Delimiter', '\t');
ITANetAudioTest_Client_NetworkStream = readtable( 'ITANetAudioTest_Client_NetworkStream.log', 'FileType', 'text', 'Delimiter', '\t');
%% Settings
B = 512;
TL = 512*4;
RB = 512*8;
TL = B*3;
RB = B*4;
%% Analyse
TS = min( [ ITANetAudioTest_Client.WorldTimeStamp; ITANetAudioTest_Server.WorldTimeStamp; ITANetAudioTest_Client_AudioStream.WorldTimeStamp ] );
TE = max( [ ITANetAudioTest_Client.WorldTimeStamp; ITANetAudioTest_Server.WorldTimeStamp; ITANetAudioTest_Client_AudioStream.WorldTimeStamp ] );
all_times = [ ITANetAudioTest_Client.WorldTimeStamp; ITANetAudioTest_Server.WorldTimeStamp; ITANetAudioTest_Client_AudioStream.WorldTimeStamp; ITANetAudioTest_Client_NetworkStream.WorldTimeStamp ];
TS = min( all_times );
TE = max( all_times );
AudioStreamingUnderrunIndices = find( ITANetAudioTest_Client_AudioStream.FreeSamples == RB );
AudioStreamingOverrunIndices = find( ITANetAudioTest_Client_AudioStream.FreeSamples == 0 );
ClientTransmittedBufferInfoIndices = find( strcmpi( ITANetAudioTest_Client.TransmittedRingBufferFreeSamples,'true' ));
ServerNetCommTiming = diff( ITANetAudioTest_Server.WorldTimeStamp );
ClientNetCommTiming = diff( ITANetAudioTest_Client.WorldTimeStamp );
ClientAudioStreamTiming = diff( ITANetAudioTest_Client_AudioStream.WorldTimeStamp );
ClientNetStreamTiming = diff( ITANetAudioTest_Client_NetworkStream.WorldTimeStamp );
%% Plot
subplot( 2, 1, 1 )
% Client
plot( ITANetAudioTest_Client.WorldTimeStamp - TS, RB - ITANetAudioTest_Client.FreeSamples, 'LineWidth', 1 )
hold on
plot( ITANetAudioTest_Client.WorldTimeStamp( ClientTransmittedBufferInfoIndices ) - TS, RB - ITANetAudioTest_Client.FreeSamples( ClientTransmittedBufferInfoIndices ), '>' )
plot( ITANetAudioTest_Client.WorldTimeStamp( ClientTransmittedBufferInfoIndices ) - TS, RB - ITANetAudioTest_Client.FreeSamples( ClientTransmittedBufferInfoIndices ), '^' )
hold on
plot( ITANetAudioTest_Client_NetworkStream.WorldTimeStamp - TS, RB - ITANetAudioTest_Client_NetworkStream.FreeSamples )
% Estimated by server
plot( ITANetAudioTest_Server.WorldTimeStamp - TS, RB - ITANetAudioTest_Server.EstimatedFreeSamples, 'LineWidth', 1 )
......@@ -45,7 +55,26 @@ hold on
plot( ITANetAudioTest_Client_AudioStream.WorldTimeStamp( AudioStreamingOverrunIndices ) - TS, RB - ITANetAudioTest_Client_AudioStream.FreeSamples( AudioStreamingOverrunIndices ) , 'm*' )
hold on
legend( { 'RingBufferSamples', 'BufferInfoTransmit', 'Estimated', 'TargetLatency', 'RingBufferCapacity', 'Underruns', 'Overruns' } )
legend( { 'RealBufferStatus', 'BufferInfoTransmit', 'NetworkStreamBufferStatus', 'EstimatedBufferStatus', 'TargetLatency', 'RingBufferCapacity', 'Underruns', 'Overruns' } )
ylabel( 'NumSamples' )
xlabel( 'Time' )
ylim( [ -B/10 RB + B/10 ] );
hold off
% Timing
subplot( 2, 1, 2 )
plot( ITANetAudioTest_Client.WorldTimeStamp( 2:end ) - TS, ClientNetCommTiming )
hold on
plot( ITANetAudioTest_Client_AudioStream.WorldTimeStamp( 2:end ) - TS, ClientAudioStreamTiming )
hold on
plot( ITANetAudioTest_Client_NetworkStream.WorldTimeStamp( 2:end ) - TS, ClientNetStreamTiming )
hold on
plot( ITANetAudioTest_Server.WorldTimeStamp( 2:end ) - TS, ServerNetCommTiming )
hold on
title( 'Clock Timing' )
legend( { 'ClientNet', 'ClientAudioStream', 'ClientNetStream', 'ServerNet' } )
ylabel( 'Process timing' )
xlabel( 'Streaming time' )
hold off
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