ITANetAudioStreamingServerTest.cpp 2.58 KB
Newer Older
1 2
#include <ITANetAudioStreamingServer.h>
#include <ITANetAudioServer.h>
3
#include <ITAStreamFunctionGenerator.h>
4
#include <ITAStreamMultiplier1N.h>
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
5
#include <ITAFileDataSource.h>
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
6
#include <VistaBase/VistaTimeUtils.h>
7

8 9 10 11
#include <iostream>
#include <string>
#include <sstream>

12 13
using namespace std;

Anne Heimes's avatar
Anne Heimes committed
14
string g_sServerName = "137.226.61.85";
15 16
int g_iServerPort = 12480;
double g_dSampleRate = 44100.0;
Anne Heimes's avatar
Anne Heimes committed
17
int g_iBlockLength = 32;
18
int g_iChannels = 2;
Anne Heimes's avatar
Anne Heimes committed
19
int g_iTargetLatencySamples = 4 * g_iBlockLength; // 1.4512ms
Anne Heimes's avatar
Anne Heimes committed
20 21
int g_iRingBufferSize = 2 * g_iTargetLatencySamples;
double g_dClientStatusMessageTimeout = 0.001; // seconds
22 23 24
string g_sFileName = "gershwin-mono.wav";

int main( int argc, char** argv )
25
{
Anne Heimes's avatar
Anne Heimes committed
26 27

	if ( argc >= 8 )
Anne Heimes's avatar
Anne Heimes committed
28
	{
29
		g_sServerName = argv[ 1 ];
Anne Heimes's avatar
Anne Heimes committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44

		if ( argc >= 3 )
		{
			g_iServerPort = atoi( argv[ 2 ] );
			g_dSampleRate = strtod( argv[ 3 ], NULL );
			g_iBlockLength = atoi( argv[ 4 ] );
			g_iChannels = atoi( argv[ 5 ] );
			g_iTargetLatencySamples = atoi( argv[ 6 ] );
			g_iRingBufferSize = atoi( argv[ 7 ] );
		}
	}
	else
	{
		cout << "Syntax: ServerName ServerPort SampleRate BufferSize Channel TargetLatencySamples RingBufferSize" << endl;
		cout << "Using default values ..." << endl;
Anne Heimes's avatar
Anne Heimes committed
45
	}
46

47 48 49 50 51 52 53 54 55 56
	ITADatasource* pSource = NULL;
	try
	{
		pSource = new ITAFileDatasource( g_sFileName, g_iBlockLength );
		static_cast< ITAFileDatasource* >( pSource )->SetIsLooping( true );
		cout << "Found file " << g_sFileName << ", will use it for playback." << endl;

	}
	catch( ITAException& )
	{
57
		cout << "Could not find file " << g_sFileName << ", will use SINE signal instead." << endl;
58 59
		pSource = new ITAStreamFunctionGenerator( 1, g_dSampleRate, g_iBlockLength, ITAStreamFunctionGenerator::SINE, 250.0f, 0.7171f, true );
	}
Anne Heimes's avatar
Anne Heimes committed
60

61
	ITAStreamMultiplier1N oMuliplier( pSource, g_iChannels );
62
	CITANetAudioStreamingServer oStreamingServer;
63 64

	stringstream ss;
Jonas Stienen's avatar
Jonas Stienen committed
65
	ss << "ITANetAudioStreamingServerTest";
66 67 68
	ss << "_C" << g_iChannels;
	ss << "_B" << g_iBlockLength;
	ss << "_TL" << g_iTargetLatencySamples;
Anne Heimes's avatar
Anne Heimes committed
69
	ss << "_RB" << g_iRingBufferSize;
70 71
	oStreamingServer.SetServerLogBaseName( ss.str() );

72
	oStreamingServer.SetInputStream( &oMuliplier );
73
	oStreamingServer.SetTargetLatencySamples( g_iTargetLatencySamples );
74

75 76
	cout << "Starting net audio server and waiting for connections on '" << g_sServerName << "' on port " << g_iServerPort << endl;
	oStreamingServer.Start( g_sServerName, g_iServerPort, g_dClientStatusMessageTimeout );
Dipl.-Ing. Jonas Stienen's avatar
Stuff  
Dipl.-Ing. Jonas Stienen committed
77

78 79 80 81 82 83 84
	while( !oStreamingServer.IsClientConnected() )
		VistaTimeUtils::Sleep( 100 );

	while( oStreamingServer.IsClientConnected() )
		VistaTimeUtils::Sleep( 100 );
	
	VistaTimeUtils::Sleep( 2000 );
85

86
	delete pSource;
Anne Heimes's avatar
Anne Heimes committed
87

88 89
	return 0;
}