Commit 2051bbd0 authored by Anne Heimes's avatar Anne Heimes
Browse files

write only the 2 output channels

parent 697d306e
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <ITANetAudioStreamingServer.h> #include <ITANetAudioStreamingServer.h>
#include <ITANetAudioServer.h> #include <ITANetAudioServer.h>
#include <ITANetAudioStream.h> #include <ITANetAudioStream.h>
#include <ITAPortaudioInterface.h> #include <ITAPortaudioInterface.h>
#include <ITAStreamFunctionGenerator.h> #include <ITAStreamFunctionGenerator.h>
#include <ITAStreamMultiplier1N.h> #include <ITAStreamMultiplier1N.h>
#include <ITAFileDatasource.h> #include <ITAFileDatasource.h>
#include <ITAException.h> #include <ITAException.h>
#include <ITAFileDatasource.h> #include <ITAFileDatasource.h>
#include <ITAStreamProbe.h> #include <ITAStreamProbe.h>
#include <ITAStreamPatchbay.h> #include <ITAStreamPatchbay.h>
#include <VistaBase/VistaStreamUtils.h> #include <VistaBase/VistaStreamUtils.h>
using namespace std; using namespace std;
const static string g_sServerName = "localhost"; const static string g_sServerName = "localhost";
const static string g_sInputFilePath = "gershwin-mono.wav"; const static string g_sInputFilePath = "gershwin-mono.wav";
const static int g_iServerPort = 12480; const static int g_iServerPort = 12480;
const static double g_dSampleRate = 44100; const static double g_dSampleRate = 44100;
const static int g_iBlockLength = 1024; const static int g_iBlockLength = 1024;
const static int g_iChannels = 20; const static int g_iChannels = 300;
class CServer : public VistaThread class CServer : public VistaThread
{ {
public: public:
inline CServer( const string& sInputFilePath ) inline CServer( const string& sInputFilePath )
{ {
pInputFile = new ITAFileDatasource( sInputFilePath, g_iBlockLength ); pInputFile = new ITAFileDatasource( sInputFilePath, g_iBlockLength );
assert( pInputFile->GetNumberOfChannels() == 1 ); assert( pInputFile->GetNumberOfChannels() == 1 );
pMuliplier = new ITAStreamMultiplier1N( pInputFile, g_iChannels ); pMuliplier = new ITAStreamMultiplier1N( pInputFile, g_iChannels );
pStreamingServer = new CITANetAudioStreamingServer; pStreamingServer = new CITANetAudioStreamingServer;
pStreamingServer->SetInputStream( pMuliplier ); pStreamingServer->SetInputStream( pMuliplier );
Run(); Run();
}; };
...@@ -47,7 +47,7 @@ public: ...@@ -47,7 +47,7 @@ public:
}; };
void ThreadBody( ) void ThreadBody( )
{ {
vstr::out() << "[ NetAudioTestServer ] Starting net audio server and waiting for client connections on '" << g_sServerName << "' on port " << g_iServerPort << endl; vstr::out() << "[ NetAudioTestServer ] Starting net audio server and waiting for client connections on '" << g_sServerName << "' on port " << g_iServerPort << endl;
pStreamingServer->Start( g_sServerName, g_iServerPort ); pStreamingServer->Start( g_sServerName, g_iServerPort );
}; };
...@@ -56,61 +56,62 @@ private: ...@@ -56,61 +56,62 @@ private:
ITAFileDatasource* pInputFile; ITAFileDatasource* pInputFile;
ITAStreamMultiplier1N* pMuliplier; ITAStreamMultiplier1N* pMuliplier;
CITANetAudioStreamingServer* pStreamingServer; CITANetAudioStreamingServer* pStreamingServer;
}; };
int main( int, char** ) int main( int, char** )
{ {
// Sample server (forked away into a thread) // Sample server (forked away into a thread)
CServer oServer( g_sInputFilePath ); CServer oServer( g_sInputFilePath );
// Client dumping received stream and mixing down to two channels // Client dumping received stream and mixing down to two channels
CITANetAudioStream oNetAudioStream( g_iChannels, g_dSampleRate, g_iBlockLength, 100 * g_iBlockLength ); CITANetAudioStream oNetAudioStream( g_iChannels, g_dSampleRate, g_iBlockLength, 100 * g_iBlockLength );
ITAStreamProbe oProbe( &oNetAudioStream, "ITANetAudioTest.stream.wav" );
ITAStreamPatchbay oPatchbay( g_dSampleRate, g_iBlockLength );
ITAStreamPatchbay oPatchbay( g_dSampleRate, g_iBlockLength ); oPatchbay.AddInput( &oNetAudioStream );
oPatchbay.AddInput( &oProbe ); int iOutputID = oPatchbay.AddOutput( 2 );
int iOutputID = oPatchbay.AddOutput( 2 );
int N = int( oNetAudioStream.GetNumberOfChannels() );
int N = int( oNetAudioStream.GetNumberOfChannels() ); for ( int i = 0; i < N ; i++ )
for ( int i = 0; i < N ; i++ ) oPatchbay.ConnectChannels( 0, i, 0, i % 2, 1 / double( N ) );
oPatchbay.ConnectChannels( 0, i, 0, i % 2, 1 / double( N ) );
ITAStreamProbe oProbe( oPatchbay.GetOutputDatasource( iOutputID ), "ITANetAudioTest.stream.wav" );
ITAPortaudioInterface ITAPA( g_dSampleRate, g_iBlockLength );
ITAPA.Initialize(); ITAPortaudioInterface ITAPA( g_dSampleRate, g_iBlockLength );
ITAPA.SetPlaybackDatasource( oPatchbay.GetOutputDatasource( iOutputID ) ); ITAPA.Initialize();
ITAPA.Open(); ITAPA.SetPlaybackDatasource( &oProbe );
ITAPA.Start(); ITAPA.Open();
ITAPA.Start();
vstr::out() << "[ NetAudioTestClient ] Waiting 1 second (net audio stream not connected and playing back zeros)" << endl;
ITAPA.Sleep( 1.0f ); vstr::out() << "[ NetAudioTestClient ] Waiting 1 second (net audio stream not connected and playing back zeros)" << endl;
ITAPA.Sleep( 1.0f );
vstr::out() << "[ NetAudioTestClient ] Will now connect to net audio server '" << g_sServerName << "' on port " << g_iServerPort << endl;
try vstr::out() << "[ NetAudioTestClient ] Will now connect to net audio server '" << g_sServerName << "' on port " << g_iServerPort << endl;
{ try
if ( !oNetAudioStream.Connect( g_sServerName, g_iServerPort ) ) {
ITA_EXCEPT1( INVALID_PARAMETER, "Could not connect to net audio server" ); if ( !oNetAudioStream.Connect( g_sServerName, g_iServerPort ) )
} ITA_EXCEPT1( INVALID_PARAMETER, "Could not connect to net audio server" );
catch ( ITAException e ) }
{ catch ( ITAException e )
vstr::warn() << "[ NetAudioTestClient ] Connection failed." << endl; {
vstr::err() << e << endl; vstr::warn() << "[ NetAudioTestClient ] Connection failed." << endl;
return 255; vstr::err() << e << endl;
} return 255;
vstr::out() << "[ NetAudioTestClient ] Connected." << endl; }
vstr::out() << "[ NetAudioTestClient ] Connected." << endl;
// Playback
float fSeconds = 5.0f; // Playback
vstr::out() << "[ NetAudioTestClient ] Playback started, waiting " << fSeconds << " seconds" << endl; float fSeconds = 5.0f;
ITAPA.Sleep( fSeconds ); // blocking vstr::out() << "[ NetAudioTestClient ] Playback started, waiting " << fSeconds << " seconds" << endl;
vstr::out() << "[ NetAudioTestClient ] Done." << endl; ITAPA.Sleep( fSeconds ); // blocking
vstr::out() << "[ NetAudioTestClient ] Done." << endl;
vstr::out() << "[ NetAudioTestClient ] Will now disconnect from net audio server '" << g_sServerName << "' and port " << g_iServerPort << endl;
vstr::out() << "[ NetAudioTestClient ] Closing in 1 second (net audio stream not connected and playing back zeros)" << endl; vstr::out() << "[ NetAudioTestClient ] Will now disconnect from net audio server '" << g_sServerName << "' and port " << g_iServerPort << endl;
ITAPA.Sleep( 1.0f ); vstr::out() << "[ NetAudioTestClient ] Closing in 1 second (net audio stream not connected and playing back zeros)" << endl;
ITAPA.Sleep( 1.0f );
ITAPA.Stop( );
ITAPA.Close( ); ITAPA.Stop( );
ITAPA.Finalize( ); ITAPA.Close( );
ITAPA.Finalize( );
return 0;
} return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment