ITANetAudioStreamingPortaudioClientTest.cpp 2.63 KB
Newer Older
Anne's avatar
Anne committed
1
2
3
4
5
6
#include <iostream>
#include <string>
#include <ITANetAudioStream.h>
#include <ITAPortaudioInterface.h>
#include <ITAStreamMultiplier1N.h>
#include <ITAException.h>
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
7
#include <ITAFileDataSource.h>
Anne's avatar
Anne committed
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
33
#include <ITAStreamProbe.h>
#include <ITAStreamPatchbay.h>
using namespace std;

int main(int argc, char* argv[])
{
	
	if (argc != 7)
	{
		cout << "argc = " << argc << endl;
		cout << "sServerName = " << argv[1] << endl;
		cout << "iServerPort = " << argv[2] << endl;
		cout << "dSampleRate = " << argv[3] << endl;
		cout << "iBlockLength = " << argv[4] << endl;
		cout << "iChannels = " << argv[5] << endl;
		cout << "iBufferSize = " << argv[6] << endl;
		fprintf(stderr, "Fehler: Syntax = ServerName ServerPort SampleRate BufferSize Channel RingBufferSize!\n");
	}	

	string sServerName = argv[1];
	unsigned int iServerPort = atoi(argv[2]);
	double dSampleRate = strtod(argv[3], NULL);
	int iBlockLength = atoi(argv[4]);
	int iChannels = atoi(argv[5]);
	int iBufferSize = atoi(argv[6]);
	
Anne's avatar
Anne committed
34
	CITANetAudioStream oNetAudioStream( iChannels, dSampleRate, iBlockLength, iBlockLength*16 );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
35
	oNetAudioStream.SetDebuggingEnabled( true );
Anne's avatar
Anne committed
36
	ITAStreamPatchbay oPatchbay( dSampleRate, iBlockLength );
Anne's avatar
Anne committed
37
38
39
40
41
42
43
44
	oPatchbay.AddInput( &oNetAudioStream );
	int iOutputID = oPatchbay.AddOutput( 2 );
	int N = int( oNetAudioStream.GetNumberOfChannels( ) );
	for ( int i = 0; i < N; i++ )
		oPatchbay.ConnectChannels( 0, i, 0, i % 2, 1 / double( N ) );
	ITAStreamProbe oProbe( oPatchbay.GetOutputDatasource( iOutputID ), "ITANetAudioTest.stream.wav" );
	ITAPortaudioInterface ITAPA( dSampleRate, iBufferSize );
	ITAPA.Initialize();
45
	ITAPA.SetPlaybackDatasource( &oNetAudioStream );
Anne's avatar
Anne committed
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
	ITAPA.Open();
	ITAPA.Start(); 
	cout << "Waiting 3 seconds (net audio stream not connected and returning zeros)" << endl;
	ITAPA.Sleep( 2.0f );
	cout << "Will now connect to '" << sServerName << "' on port " << iServerPort << endl;
	try
	{
		if( !oNetAudioStream.Connect( sServerName, iServerPort ) )
			ITA_EXCEPT1( INVALID_PARAMETER, "Could not connect to server" );
	}
	catch( ITAException e )
	{
		cout << "Connection failed." << endl;
		cerr << e << endl;
		return 255;
	}
	cout << "Connected." << endl;
	// Playback
Anne's avatar
Anne committed
64
	float fSeconds = 10.0f; // 15min
Anne's avatar
Anne committed
65
66
67
68
69
70
71
72
73
74
75
	cout << "Playback started, waiting " << fSeconds << " seconds" << endl;
	ITAPA.Sleep( fSeconds ); // blocking
	cout << "Done." << endl;
	cout << "Will now disconnect from '" << sServerName << "' and port " << iServerPort << endl;
	cout << "Closing in 3 seconds (net audio stream not connected and returning zeros)" << endl;
	ITAPA.Sleep( 1.0f );
	ITAPA.Stop();
	ITAPA.Close();
	ITAPA.Finalize();
	
	return 0;
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
76
}