ITANetAudioStreamingClientTest.cpp 1.58 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
#include <string>

#include <ITANetAudioStream.h>
#include <ITAPortaudioInterface.h>
#include <ITAStreamMultiplier1N.h>
#include <ITAException.h>

using namespace std;

static string g_sServerName = "localhost";
static int g_iServerPort = 12480;
static double g_dSampleRate = 44.1e3;
static int g_iBufferSize = 256;

int main( int , char** )
{
	CITANetAudioStream oNetAudioStream( 1, g_dSampleRate, g_iBufferSize, 4 * g_iBufferSize );
	ITAStreamMultiplier1N oMultiplier( &oNetAudioStream, 2 );

	ITAPortaudioInterface ITAPA( g_dSampleRate, g_iBufferSize );
	ITAPA.Initialize();
	ITAPA.SetPlaybackDatasource( &oMultiplier );
	ITAPA.Open();
	ITAPA.Start(); 

	cout << "Waiting 3 seconds (net audio stream not connected and returning zeros)" << endl;
	ITAPA.Sleep( 3.0f );

	cout << "Will now connect to '" << g_sServerName << "' on port " << g_iServerPort << endl;
	try
	{
33
34
		if( !oNetAudioStream.Connect( g_sServerName, g_iServerPort ) )
			ITA_EXCEPT1( INVALID_PARAMETER, "Could not connect to server" );
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
	}
	catch( ITAException e )
	{
		cout << "Connection failed." << endl;
		cerr << e << endl;
		return 255;
	}
	cout << "Connected." << endl;

	// Playback
	float fSeconds = 10.0f;
	cout << "Playback started, waiting " << fSeconds << " seconds" << endl;
	ITAPA.Sleep( fSeconds ); // blocking
	cout << "Done." << endl;


	cout << "Will now disconnect from '" << g_sServerName << "' and port " << g_iServerPort << endl;
	cout << "Closing in 3 seconds (net audio stream not connected and returning zeros)" << endl;
	ITAPA.Sleep( 3.0f );

	ITAPA.Stop();
	ITAPA.Close();
	ITAPA.Finalize();

	return 0;
}