Skip to content
Snippets Groups Projects
Commit b179addd authored by Jonas Stienen's avatar Jonas Stienen
Browse files

Fixing some problems with ita_convoi and the ITAPA usage, streaming is now running

parent a38eb579
No related tags found
No related merge requests found
...@@ -37,8 +37,6 @@ ...@@ -37,8 +37,6 @@
#include <VistaTools/VistaFileSystemFile.h> #include <VistaTools/VistaFileSystemFile.h>
using namespace std;
class ITAStreamConvolver : public ITADatasourceRealizationEventHandler, public DSMBCConvolver class ITAStreamConvolver : public ITADatasourceRealizationEventHandler, public DSMBCConvolver
{ {
public: public:
...@@ -76,24 +74,25 @@ private: ...@@ -76,24 +74,25 @@ private:
ITADatasourceRealization* m_pdsOutput; ITADatasourceRealization* m_pdsOutput;
}; };
string ita_convoi_syntax(); std::string ita_convoi_syntax();
string ita_convoi_commands(); std::string ita_convoi_commands();
void ita_convio_exchange_channel( ITAStreamConvolver*, const ITASampleFrame&, const int iChannelIndex ); void ita_convio_exchange_channel( ITAStreamConvolver*, const ITASampleFrame&, const int iChannelIndex );
void ita_convio_dirac_channel( ITAStreamConvolver* );
int main( int argc, char* argv[] ) int main( int argc, char* argv[] )
{ {
if( argc < 3 ) if( argc < 3 )
{ {
cout << ita_convoi_syntax() << endl; std::cout << ita_convoi_syntax() << std::endl;
return 255; return 255;
} }
// Input wav file // Input wav file
string sInputFilePath = string( argv[ 1 ] ); std::string sInputFilePath = std::string( argv[ 1 ] );
VistaFileSystemFile oInputFile( sInputFilePath ); VistaFileSystemFile oInputFile( sInputFilePath );
if( !oInputFile.Exists() || !oInputFile.IsFile() ) if( !oInputFile.Exists() || !oInputFile.IsFile() )
{ {
cerr << "Input file '" << oInputFile.GetName() << "' not found or invalid" << endl; std::cerr << "Input file '" << oInputFile.GetName() << "' not found or invalid" << std::endl;
return 255; return 255;
} }
...@@ -104,7 +103,7 @@ int main( int argc, char* argv[] ) ...@@ -104,7 +103,7 @@ int main( int argc, char* argv[] )
} }
catch( ITAException& e ) catch( ITAException& e )
{ {
cerr << "Could not read input file: " << e << endl; std::cerr << "Could not read input file: " << e << std::endl;
return 255; return 255;
} }
...@@ -112,11 +111,11 @@ int main( int argc, char* argv[] ) ...@@ -112,11 +111,11 @@ int main( int argc, char* argv[] )
delete pSample; delete pSample;
// IR filter file // IR filter file
string sIRFilePath = string( argv[ 2 ] ); std::string sIRFilePath = std::string( argv[ 2 ] );
VistaFileSystemFile oIRFile( sIRFilePath ); VistaFileSystemFile oIRFile( sIRFilePath );
if( !oIRFile.Exists() || !oIRFile.IsFile() ) if( !oIRFile.Exists() || !oIRFile.IsFile() )
{ {
cerr << "IR filter file '" << oIRFile.GetName() << "' not found or invalid" << endl; std::cerr << "IR filter file '" << oIRFile.GetName() << "' not found or invalid" << std::endl;
return 255; return 255;
} }
...@@ -127,7 +126,7 @@ int main( int argc, char* argv[] ) ...@@ -127,7 +126,7 @@ int main( int argc, char* argv[] )
} }
catch( ITAException& e ) catch( ITAException& e )
{ {
cerr << "Could not read IR filter file: " << e << endl; std::cerr << "Could not read IR filter file: " << e << std::endl;
return 255; return 255;
} }
double dSamplingRateFilter = pIRAudioFile->getSamplerate(); double dSamplingRateFilter = pIRAudioFile->getSamplerate();
...@@ -138,7 +137,7 @@ int main( int argc, char* argv[] ) ...@@ -138,7 +137,7 @@ int main( int argc, char* argv[] )
// Require matching sampling rates // Require matching sampling rates
if( dSamplingRate != dSamplingRateFilter ) if( dSamplingRate != dSamplingRateFilter )
{ {
cerr << "Sampling rate of input file (" << dSamplingRate << ") and IR filter (" << dSamplingRateFilter << ") does not match" << endl; std::cerr << "Sampling rate of input file (" << dSamplingRate << ") and IR filter (" << dSamplingRateFilter << ") does not match" << std::endl;
return 255; return 255;
} }
...@@ -149,25 +148,25 @@ int main( int argc, char* argv[] ) ...@@ -149,25 +148,25 @@ int main( int argc, char* argv[] )
} }
// Start audio streaming // Start audio streaming
ITAPortaudioInterface::ITA_PA_ERRORCODE iError;
ITAPortaudioInterface oITAPA( dSamplingRate, iBlockLength ); ITAPortaudioInterface oITAPA( dSamplingRate, iBlockLength );
int iPortaudioDeviceID = oITAPA.GetDefaultOutputDevice(); int iPortaudioDeviceID = oITAPA.GetDefaultOutputDevice();
if( argc > 4 ) if( argc > 4 )
iPortaudioDeviceID = int( *argv[ 4 ] ); iPortaudioDeviceID = int( *argv[ 4 ] );
ITAPortaudioInterface::ITA_PA_ERRORCODE iError;
if( ( iError = oITAPA.Initialize( iPortaudioDeviceID ) ) != ITAPortaudioInterface::ITA_PA_NO_ERROR ) if( ( iError = oITAPA.Initialize( iPortaudioDeviceID ) ) != ITAPortaudioInterface::ITA_PA_NO_ERROR )
{ {
cerr << "Could not initialize Portaudio, encountered error: " << ITAPortaudioInterface::GetErrorCodeString( iError ) << endl; std::cerr << "Could not initialize Portaudio, encountered error: " << ITAPortaudioInterface::GetErrorCodeString( iError ) << std::endl;
return 255; return 255;
} }
// Streaming chaing // Streaming chaing
ITAStreamConvolver oConvolver( dSamplingRate, iBlockLength, iFilterLength ); ITAStreamConvolver oConvolver( dSamplingRate, iBlockLength, iFilterLength );
ITAFileDatasource oSample( oInputFile.GetName(), iBlockLength, true ); ITAFileDatasource oSample( oInputFile.GetName(), iBlockLength, true );
if( oSample.GetNumberOfChannels() != 1 ) if( oSample.GetNumberOfChannels() != 1 )
{ {
cout << "Warning ... input file has multiple channels, mixing to mono." << endl; std::cout << "Warning ... input file has multiple channels, mixing to mono." << std::endl;
} }
ITAStreamPatchbay oPatchBay( dSamplingRate, iBlockLength ); ITAStreamPatchbay oPatchBay( dSamplingRate, iBlockLength );
...@@ -179,16 +178,32 @@ int main( int argc, char* argv[] ) ...@@ -179,16 +178,32 @@ int main( int argc, char* argv[] )
oPatchBay.ConnectChannels( iInputID, n, iOutputID, 0 ); oPatchBay.ConnectChannels( iInputID, n, iOutputID, 0 );
ITAStreamMultiplier1N oMultiplier( oConvolver.GetOutputDataSource(), oITAPA.GetNumOutputChannels( iPortaudioDeviceID ) ); ITAStreamMultiplier1N oMultiplier( oConvolver.GetOutputDataSource(), oITAPA.GetNumOutputChannels( iPortaudioDeviceID ) );
oITAPA.SetPlaybackDatasource( &oMultiplier );
if( ( iError = oITAPA.SetPlaybackDatasource( &oMultiplier ) ) != ITAPortaudioInterface::ITA_PA_NO_ERROR )
{
std::cerr << "Could not set streaming playback for Portaudio, encountered error: " << ITAPortaudioInterface::GetErrorCodeString( iError ) << std::endl;
return 255;
}
oITAPA.Start(); if( ( iError = oITAPA.Open() ) != ITAPortaudioInterface::ITA_PA_NO_ERROR )
{
std::cerr << "Could not open streaming over Portaudio, encountered error: " << ITAPortaudioInterface::GetErrorCodeString( iError ) << std::endl;
return 255;
}
if( ( iError = oITAPA.Start() ) != ITAPortaudioInterface::ITA_PA_NO_ERROR )
{
std::cerr << "Could not start streaming, encountered error: " << ITAPortaudioInterface::GetErrorCodeString( iError ) << std::endl;
return 255;
}
int iCurrentIRChannelIndex = 0; int iCurrentIRChannelIndex = 0;
ITASampleFrame sfIR( oIRFile.GetName() ); ITASampleFrame sfIR( oIRFile.GetName() );
ita_convio_exchange_channel( &oConvolver, sfIR, iCurrentIRChannelIndex ); ita_convio_exchange_channel( &oConvolver, sfIR, iCurrentIRChannelIndex );
// Start user interaction // Start user interaction
cout << ita_convoi_commands() << endl; std::cout << ita_convoi_commands() << std::endl;
int iKey; int iKey;
while( ( iKey = _getch() ) != 'q' ) while( ( iKey = _getch() ) != 'q' )
{ {
...@@ -198,6 +213,10 @@ int main( int argc, char* argv[] ) ...@@ -198,6 +213,10 @@ int main( int argc, char* argv[] )
{ {
// Toggle // Toggle
oPatchBay.SetOutputMuted( iOutputID, !oPatchBay.IsOutputMuted( iOutputID ) ); oPatchBay.SetOutputMuted( iOutputID, !oPatchBay.IsOutputMuted( iOutputID ) );
if( oPatchBay.IsOutputMuted( iOutputID ) )
std::cout << "Output is now muted" << std::endl;
else
std::cout << "Output is loud" << std::endl;
break; break;
} }
case( 'n' ) : case( 'n' ) :
...@@ -210,61 +229,70 @@ int main( int argc, char* argv[] ) ...@@ -210,61 +229,70 @@ int main( int argc, char* argv[] )
} }
else else
{ {
cout << "Only one channel available, doing nothing." << endl; std::cout << "Only one channel available, doing nothing." << std::endl;
} }
break; break;
} }
case( 1 ) : case( 'd' ) :
case( 2 ) : {
case( 3 ) : ita_convio_dirac_channel( &oConvolver );
case( 4 ) : break;
case( 5 ) : }
case( 6 ) : case( 48 + 1 ) :
case( 7 ) : case( 48 + 2 ) :
case( 8 ) : case( 48 + 3 ) :
case( 9 ) : case( 48 + 4 ) :
case( 48 + 5 ) :
case( 48 + 6 ) :
case( 48 + 7 ) :
case( 48 + 8 ) :
case( 48 + 9 ) :
{ {
// Switch to next channel // Switch to next channel
if( iFilterChannels <= iKey ) int iRequestedChannelIndex = iKey - 1 - 48;
if( iFilterChannels > iRequestedChannelIndex )
{ {
iCurrentIRChannelIndex = iKey - 1; iCurrentIRChannelIndex = iRequestedChannelIndex;
ita_convio_exchange_channel( &oConvolver, sfIR, iCurrentIRChannelIndex ); ita_convio_exchange_channel( &oConvolver, sfIR, iCurrentIRChannelIndex );
} }
else else
{ {
cerr << "Requested channel is out of range, maximum IR channel number is " << iFilterChannels << endl; std::cerr << "Requested channel is out of range, maximum IR channel number is " << iFilterChannels << std::endl;
} }
break; break;
} }
default: default:
{ {
cerr << "Unrecognized key command '" << char( iKey ) << "'" << endl; std::cerr << "Unrecognized key command '" << char( iKey ) << "'" << std::endl;
cout << ita_convoi_commands() << endl; std::cout << ita_convoi_commands() << std::endl;
break; break;
} }
} }
} }
oITAPA.Stop(); oITAPA.Stop();
oITAPA.Close();
oITAPA.Finalize();
return 0; return 0;
} }
string ita_convoi_syntax() std::string ita_convoi_syntax()
{ {
stringstream ss; std::stringstream ss;
ss << "Syntax: ita_convoi SAMPLE_INPUT_WAV_MONO IR_FILTER_WAV_MULTICHANNEL [BLOCKLENGTH] [PORTAUDIO_DEVICE]" << endl; ss << "Syntax: ita_convoi SAMPLE_INPUT_WAV_MONO IR_FILTER_WAV_MULTICHANNEL [BLOCKLENGTH] [PORTAUDIO_DEVICE]" << std::endl;
return ss.str(); return ss.str();
} }
string ita_convoi_commands() std::string ita_convoi_commands()
{ {
stringstream ss; std::stringstream ss;
ss << "Commands:\t'q' quit" << endl; ss << "Commands:\t'q' quit" << std::endl;
ss << "\t\t\t'm' toggle mute" << endl; ss << "\t\t'm' toggle mute" << std::endl;
ss << "\t\t'n' switch to next IR channel" << endl; ss << "\t\t'n' switch to next IR channel" << std::endl;
ss << "\t\t1-9 exchange IR filter to given channel, if available" << endl; ss << "\t\t'd' exchange a Dirac filter" << std::endl;
ss << "\t\t1-9 exchange IR filter to given channel, if available" << std::endl;
return ss.str(); return ss.str();
} }
...@@ -275,4 +303,15 @@ void ita_convio_exchange_channel( ITAStreamConvolver* pSC, const ITASampleFrame& ...@@ -275,4 +303,15 @@ void ita_convio_exchange_channel( ITAStreamConvolver* pSC, const ITASampleFrame&
pFilter->load( sfIR[ iChannelIndex ].GetData(), sfIR.GetLength() ); pFilter->load( sfIR[ iChannelIndex ].GetData(), sfIR.GetLength() );
pSC->exchangeFilter( pFilter ); pSC->exchangeFilter( pFilter );
pSC->releaseFilter( pFilter ); pSC->releaseFilter( pFilter );
std::cout << "Exchanged filter, now streaming channel " << iChannelIndex + 1 << std::endl;
}
void ita_convio_dirac_channel( ITAStreamConvolver* pSC )
{
DSMBCFilter* pFilter = pSC->requestFilter();
pFilter->identity();
pSC->exchangeFilter( pFilter );
pSC->releaseFilter( pFilter );
std::cout << "Exchanged Dirac filter" << std::endl;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment