ITANetAudioStreamingServerTest.cpp 3.23 KB
Newer Older
1
#include <ITANetAudioStreamingServer.h>
2
#include <ITAStreamFunctionGenerator.h>
3
#include <ITAStreamMultiplier1N.h>
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
4
#include <ITAFileDataSource.h>
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
5
6
#include <ITAException.h>

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
7
#include <VistaBase/VistaTimeUtils.h>
8

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

13
14
using namespace std;

Anne Heimes's avatar
Anne Heimes committed
15
string g_sServerName = "137.226.61.85";
16
17
int g_iServerPort = 12480;
double g_dSampleRate = 44100.0;
Anne Heimes's avatar
Anne Heimes committed
18
19
20
int g_iBlockLength = 32;
int g_iChannels = 100;
int g_iTargetLatencySamples = 10 * g_iBlockLength; // 1.4512ms
Anne Heimes's avatar
Anne Heimes committed
21
int g_iRingBufferSize = 2 * g_iTargetLatencySamples;
22
int g_iSendingBlockLength = 8;
Anne Heimes's avatar
Anne Heimes committed
23
double g_dClientStatusMessageTimeout = 0.001; // seconds
Anne Heimes's avatar
Anne Heimes committed
24
double g_dEstimatiedCorrFactor = 1;
25
string g_sFileName = "gershwin-mono.wav";
26
bool g_bDebuggingEnabled = true;
27
28

int main( int argc, char** argv )
29
{
Anne Heimes's avatar
Anne Heimes committed
30

Anne Heimes's avatar
Anne Heimes committed
31
	if ( argc >= 9 )
Anne Heimes's avatar
Anne Heimes committed
32
	{
33
		g_sServerName = argv[ 1 ];
Anne Heimes's avatar
Anne Heimes committed
34
35
36
37
38
39
40

		if ( argc >= 3 )
		{
			g_iServerPort = atoi( argv[ 2 ] );
			g_dSampleRate = strtod( argv[ 3 ], NULL );
			g_iBlockLength = atoi( argv[ 4 ] );
			g_iChannels = atoi( argv[ 5 ] );
41
42
43
			g_iTargetLatencySamples = atoi(argv[6]);
			g_iRingBufferSize = atoi(argv[7]);
			g_iSendingBlockLength = atoi(argv[8]);
Anne Heimes's avatar
Anne Heimes committed
44
		}
Anne Heimes's avatar
Anne Heimes committed
45
46
		if (argc >= 9)
			g_dEstimatiedCorrFactor = atoi(argv[9]);
Anne Heimes's avatar
Anne Heimes committed
47
48
49
	}
	else
	{
Anne Heimes's avatar
Anne Heimes committed
50
		cout << "Syntax: ServerName ServerPort SampleRate BufferSize Channel TargetLatencySamples RingBufferSize SnedingBlockLength EstimatiedCorrFactor" << endl;
Anne Heimes's avatar
Anne Heimes committed
51
		cout << "Using default values ..." << endl;
Anne Heimes's avatar
Anne Heimes committed
52
	}
53

54
55
56
57
58
59
60
61
62
63
	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& )
	{
64
		cout << "Could not find file " << g_sFileName << ", will use SINE signal instead." << endl;
65
66
		pSource = new ITAStreamFunctionGenerator( 1, g_dSampleRate, g_iBlockLength, ITAStreamFunctionGenerator::SINE, 250.0f, 0.7171f, true );
	}
Anne Heimes's avatar
Anne Heimes committed
67

68
	ITAStreamMultiplier1N oMuliplier( pSource, g_iChannels );
69
	CITANetAudioStreamingServer oStreamingServer;
70
71

	stringstream ss;
Jonas Stienen's avatar
Jonas Stienen committed
72
	ss << "ITANetAudioStreamingServerTest";
73
74
75
	ss << "_C" << g_iChannels;
	ss << "_B" << g_iBlockLength;
	ss << "_TL" << g_iTargetLatencySamples;
Anne Heimes's avatar
Anne Heimes committed
76
	ss << "_RB" << g_iRingBufferSize;
77
	ss << "_SB" << g_iSendingBlockLength;
Anne Heimes's avatar
Anne Heimes committed
78
	ss << "_EC" << g_dEstimatiedCorrFactor;
79
	oStreamingServer.SetServerLogBaseName( ss.str() );
80
	oStreamingServer.SetDebuggingEnabled( g_bDebuggingEnabled );
Anne Heimes's avatar
Anne Heimes committed
81
	oStreamingServer.SetEstimatedCorrFactor( g_dEstimatiedCorrFactor );
82
	oStreamingServer.SetInputStream( &oMuliplier );
83
	oStreamingServer.SetTargetLatencySamples( g_iTargetLatencySamples );
84
	oStreamingServer.SetSendingBlockLength( g_iSendingBlockLength );
85

86
	cout << "Starting net audio server and waiting for connections on '" << g_sServerName << "' on port " << g_iServerPort << endl;
87
88
89
90
91
92
93
	if( oStreamingServer.Start( g_sServerName, g_iServerPort, g_dClientStatusMessageTimeout ) )
		cout << "Client connected, sending samples." << endl;
	else
	{
		cerr << "Connection failed or streaming refused, aborting." << endl;
		return 255;
	}
Dipl.-Ing. Jonas Stienen's avatar
Stuff    
Dipl.-Ing. Jonas Stienen committed
94

95
96
97
98
99
100
101
	while( !oStreamingServer.IsClientConnected() )
		VistaTimeUtils::Sleep( 100 );

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

103
	delete pSource;
Anne Heimes's avatar
Anne Heimes committed
104

105
106
	return 0;
}