ITANetAudioStreamingClientTest.cpp 3.52 KB
Newer Older
Anne Heimes's avatar
Anne Heimes committed
1 2 3 4 5 6 7
#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
8
#include <ITAFileDataSource.h>
Anne Heimes's avatar
Anne Heimes committed
9
#include <ITAStreamProbe.h>
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
10
#include <ITAStreamPatchBay.h>
Anne Heimes's avatar
Anne Heimes committed
11
#include <ITAAsioInterface.h>
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
12
#include <VistaBase/VistaTimeUtils.h>
Anne Heimes's avatar
Anne Heimes committed
13 14 15 16

using namespace std;

//static string g_sServerName = "137.226.61.163";
Anne Heimes's avatar
Anne Heimes committed
17
static string g_sServerName = "137.226.61.85";
Anne Heimes's avatar
Anne Heimes committed
18 19
static int g_iServerPort = 12480;
static double g_dSampleRate = 44100;
Anne Heimes's avatar
Anne Heimes committed
20 21
static int g_iBufferSize = 32;
static int g_iChannels = 10;
Anne Heimes's avatar
Anne Heimes committed
22 23 24

int main( int , char** )
{
Anne Heimes's avatar
Anne Heimes committed
25 26 27 28 29 30
	std::cout << "BufferSize: " << endl;
	cin >> g_iBufferSize;
	cout << "ChannelAnzahl: " << endl;
	cin >> g_iChannels;


31
	CITANetAudioStream oNetAudioStream( g_iChannels, g_dSampleRate, g_iBufferSize, 1 * g_iBufferSize );
Anne Heimes's avatar
Anne Heimes committed
32
	
Anne's avatar
Anne committed
33 34 35 36 37 38 39 40 41
	ITAStreamPatchbay oPatchbay( g_dSampleRate, g_iBufferSize );
	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" );
Anne Heimes's avatar
Anne Heimes committed
42 43


Anne Heimes's avatar
Anne Heimes committed
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
	ITAsioInitializeLibrary();

	try {

		cout << "Will now connect to '" << g_sServerName << "' on port " << g_iServerPort << endl;

		if (ITAsioInitializeDriver("ASIO MADIface USB") != ASE_OK) {
			ITAsioFinalizeLibrary();
			fprintf(stderr, "Fehler: ITAsioInit schlug fehl!\n");

			return 255;
		}

		long lBuffersize, lDummy;
		if (ITAsioGetBufferSize(&lDummy, &lDummy, &lBuffersize, &lDummy) != ASE_OK) {
			ITAsioFinalizeLibrary();
			fprintf(stderr, "Fehler: ITAsioGetBufferSize schlug fehl!\n");

			return 255;
		}


		if (ITAsioSetSampleRate((ASIOSampleRate)g_dSampleRate) != ASE_OK) {
			ITAsioFinalizeLibrary();
			fprintf(stderr, "Fehler: ITAsioSetSamplerate schlug fehl!\n");

			return 255;
		}

		long lNumInputChannels, lNumOutputChannels;
		ASIOError ae;
		if ((ae = ITAsioGetChannels(&lNumInputChannels, &lNumOutputChannels)) != ASE_OK)
		{
			cerr << "Error in ITAsioGetChannels, ASIO error " << ae << " encountered" << endl;
			ITAsioFinalizeLibrary();
			return 255;
		}

		if ((ae = ITAsioCreateBuffers(0, 2, lBuffersize)) != ASE_OK)
		{
			cerr << "Error in ITAsioCreateBuffers, ASIO error " << ae << " encountered" << endl;
			ITAsioFinalizeLibrary();
			return 255;
		}
Anne Heimes's avatar
Anne Heimes committed
88

Anne Heimes's avatar
Anne Heimes committed
89 90
		
		ITAsioSetPlaybackDatasource(&oProbe);
Anne Heimes's avatar
Anne Heimes committed
91

Anne Heimes's avatar
Anne Heimes committed
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
		if (ITAsioStart() != ASE_OK) {
			ITAsioFinalizeLibrary();
			fprintf(stderr, "Fehler: ITAsioStart schlug fehl!\n");

			return 255;
		}

		if (!oNetAudioStream.Connect(g_sServerName, g_iServerPort))
			ITA_EXCEPT1(INVALID_PARAMETER, "Could not connect to server");
		VistaTimeUtils::Sleep(2 * 1000);
		printf("Wiedergabe gestartet ...\n");
		VistaTimeUtils::Sleep(20 * 1000);

		if (ITAsioStop() != ASE_OK) {
			ITAsioFinalizeLibrary();
			fprintf(stderr, "Fehler: ITAsioStop schlug fehl!\n");

			return 255;
		}

		printf("Wiedergabe beendet!\n");

		if (ITAsioDisposeBuffers() != ASE_OK) {
			ITAsioFinalizeLibrary();
			fprintf(stderr, "Fehler: ITAsioDisposeBuffers schlug fehl!\n");

			return 255;
		}

		if (ITAsioFinalizeDriver() != ASE_OK) {
			ITAsioFinalizeLibrary();
			fprintf(stderr, "Fehler: ITAsioExit schlug fehl!\n");

			return 255;
		}
Anne Heimes's avatar
Anne Heimes committed
127
	}
Anne Heimes's avatar
Anne Heimes committed
128 129
	catch (ITAException e) {
		ITAsioFinalizeLibrary();
Anne Heimes's avatar
Anne Heimes committed
130
		cerr << e << endl;
Anne Heimes's avatar
Anne Heimes committed
131

Anne Heimes's avatar
Anne Heimes committed
132 133 134
		return 255;
	}

Anne Heimes's avatar
Anne Heimes committed
135
	ITAsioFinalizeLibrary();
Anne Heimes's avatar
Anne Heimes committed
136 137 138
	
	return 0;
}