Hi,
Attached a patch that places the AudioSources/Sinks in the
Networkplayer, thus separating them from the actual backend - which have
it's own details, but the loops are all the same.
It passes all tests (unit, functional, back2back) and networks play.
However, I am not happy with two things:
- the timing: the copy is done in SetNetworkBackLink
- it's a copy, so it does not reflect changes in the network
So, second try was with GetAudioSources/Sinks (which gives an up to date
copy). It works, but now it is called a lot in loops in the player -
which I don't think it was meant for. However, this was the case in the
PA backend, so it might be fine.
The question that I have more or less is 'who should own who', I mean
the network has a pointer to a player and the player has a pointer to
the network. This feels a bit circular.
Code example:
void testAnalysisSynthesisInaNetwork()
{
//CLAM::ErrAssertionFailed::breakpointInCLAMAssertEnabled = true;
CLAM::Network net;
CLAM::MonoOfflineNetworkPlayer * player = new
CLAM::MonoOfflineNetworkPlayer;
*net.SetPlayer( player );* // network owns the player memory
(and sets backlink!)
net.AddProcessing( "Source", new CLAM::AudioSource );
net.AddProcessing( "Sink", new CLAM::AudioSink );
net.AddProcessing( "Analysis", new CLAM::SMSAnalysisCore );
net.AddProcessing( "Synthesis", new CLAM::SMSSynthesis );
net.ConnectPorts("Source.1", "Analysis.Input Audio");
net.ConnectPorts("Analysis.Sinusoidal Peaks",
"Synthesis.InputSinPeaks");
net.ConnectPorts("Analysis.Residual Spectrum",
"Synthesis.InputResSpectrum");
net.ConnectPorts("Synthesis.OutputAudio", "Sink.1");
net.ConfigureProcessing("Analysis",
helperAnalysisConfigInstance() );
net.ConfigureProcessing("Synthesis",
helperSynthesisConfigInstance() );
std::string inputFile = GetTestDataDirectory("Elvis.wav");
std::string baseOutputFile =
GetTestDataDirectory("SMSTests/out_sms_net_stream");
player->AddInputFile(inputFile);
player->AddOutputFile(baseOutputFile+"_result.wav");
net.Start();
net.Stop();
Why does not the player start things:
player->AddInputFile(inputFile);
player->AddOutputFile(baseOutputFile+"_result.wav");
player->Start();
player->Stop();
Then the code then becomes
CLAM::Network net;
net.AddProcessing( "Source", new CLAM::AudioSource );
net.AddProcessing( "Sink", new CLAM::AudioSink );
net.AddProcessing( "Analysis", new CLAM::SMSAnalysisCore );
net.AddProcessing( "Synthesis", new CLAM::SMSSynthesis );
net.ConnectPorts("Source.1", "Analysis.Input Audio");
net.ConnectPorts("Analysis.Sinusoidal Peaks",
"Synthesis.InputSinPeaks");
net.ConnectPorts("Analysis.Residual Spectrum",
"Synthesis.InputResSpectrum");
net.ConnectPorts("Synthesis.OutputAudio", "Sink.1");
net.ConfigureProcessing("Analysis",
helperAnalysisConfigInstance() );
net.ConfigureProcessing("Synthesis",
helperSynthesisConfigInstance() );
std::string inputFile = GetTestDataDirectory("Elvis.wav");
std::string baseOutputFile =
GetTestDataDirectory("SMSTests/out_sms_net_stream");
CLAM::MonoOfflineNetworkPlayer player(net); // on the stack and
by reference
player->AddInputFile(inputFile);
player->AddOutputFile(baseOutputFile+"_result.wav");
player->Start();
player->Stop();
And the player could set references to sources/sinks in its constructor
(not shown). But I probably am missing something here.
The second question is 'how to update jack to reflect changes in the
network dynamically'.
This can be solved either way: the network changes so it calls the player:
- if the player owns the net then the net would call into the player
on_change (I would use boost::function (to decouple) but a backlink
would work the same)
- if the net owns the player then it calls registerports on the player
(but you need the networkbacklink in the player)
What would be preferable?
Dirk
Index: CLAM/src/Flow/Networks/NetworkPlayer.cxx
===================================================================
--- CLAM/src/Flow/Networks/NetworkPlayer.cxx (revision 13302)
+++ CLAM/src/Flow/Networks/NetworkPlayer.cxx (working copy)
@@ -24,22 +24,22 @@
namespace CLAM
{
- std::string NetworkPlayer::SourcesAndSinksToString()
- {
- std::string sourceNames;
- std::string sinkNames;
- const Network & net = GetNetwork();
- const Network::AudioSources & sources = GetAudioSources();
- const Network::AudioSinks & sinks = GetAudioSinks();
- for (Network::AudioSources::const_iterator it=sources.begin(); it!=sources.end(); ++it)
- sourceNames += " * source:\t"+net.GetNetworkId( *it )+"\n";
+std::string NetworkPlayer::SourcesAndSinksToString()
+{
+ std::string sourceNames;
+ std::string sinkNames;
+ const Network & net = GetNetwork();
+ const Network::AudioSources & sources = GetAudioSources();
+ const Network::AudioSinks & sinks = GetAudioSinks();
+ for (Network::AudioSources::const_iterator it=sources.begin(); it!=sources.end(); ++it)
+ sourceNames += " * source:\t"+net.GetNetworkId( *it )+"\n";
- for (Network::AudioSinks::const_iterator it=sinks.begin(); it!=sinks.end(); ++it)
- sinkNames += " * sink:\t"+net.GetNetworkId( *it )+"\n";
-
+ for (Network::AudioSinks::const_iterator it=sinks.begin(); it!=sinks.end(); ++it)
+ sinkNames += " * sink:\t"+net.GetNetworkId( *it )+"\n";
+
- return (sourceNames+sinkNames);
- }
+ return (sourceNames+sinkNames);
+}
} //namespace
Index: CLAM/src/Flow/Networks/BackEnds/JACKNetworkPlayer.cxx
===================================================================
--- CLAM/src/Flow/Networks/BackEnds/JACKNetworkPlayer.cxx (revision 13302)
+++ CLAM/src/Flow/Networks/BackEnds/JACKNetworkPlayer.cxx (working copy)
@@ -89,84 +89,67 @@
void JACKNetworkPlayer::RegisterInputPorts(const Network& net)
{
- const Network::AudioSources & sources = net.getOrderedSources();
-
- CLAM_ASSERT( _sourceJackBindings.empty(),
+ CLAM_ASSERT( _sourceJackPorts.empty(),
"JACKNetworkPlayer::RegisterInputPorts() : there are already registered input ports");
- //Get them from the Network and add it to local list
- for (Network::AudioSources::const_iterator it=sources.begin(); it!=sources.end(); it++)
+ for(unsigned i = 0; i < GetAudioSources().size(); ++i)
{
- std::string processingName = net.GetNetworkId(*it);
+ AudioSource* audioSource = GetAudioSources()[i];
+ std::string processingName = net.GetNetworkId(audioSource);
- const AudioSource::Ports & ports = (*it)->GetPorts();
+ const AudioSource::Ports & ports = audioSource->GetPorts();
+
for(unsigned port = 0; port < ports.size(); ++port)
{
- //Get Processing address
- SourceJackBinding pair;
- pair.processing=*it;
- pair.processing->SetFrameAndHopSize(_jackBufferSize, port);
+ JackPort jp;
+ std::stringstream portName;
+ if (ports.size() == 1)
+ portName << processingName;
+ else
+ portName << processingName << "_" << ports[port].mAudioOut->GetName();
- //Register port on the JACK server
- std::stringstream portName;
- if (ports.size() == 1)
- portName << processingName;
- else
- portName << processingName << "_" << ports[port].mAudioOut->GetName();
+ jp.jackPort = jack_port_register(_jackClient, portName.str().c_str(),
+ JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
+ _sourceJackPorts.push_back(jp);
- pair.jackPort = jack_port_register(_jackClient, portName.str().c_str(),
- JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
-
- // the index is used when there are more ports in an audiosource
- // to decide which port should receive the data
- pair.port = port;
-
- //Add the pair (jack port, clam jack receiver) to the list
- _sourceJackBindings.push_back(pair);
+ audioSource->SetFrameAndHopSize(_jackBufferSize, port);
}
}
}
void JACKNetworkPlayer::RegisterOutputPorts(const Network& net)
{
- const Network::AudioSinks & sinks = net.getOrderedSinks();
-
- CLAM_ASSERT( _sinkJackBindings.empty(),
+ CLAM_ASSERT( _sinkJackPorts.empty(),
"JACKNetworkPlayer::RegisterOutputPorts() : there are already registered output ports");
- for (Network::AudioSinks::const_iterator it=sinks.begin(); it!=sinks.end(); it++)
+ for(unsigned i = 0; i < GetAudioSinks().size(); ++i)
{
- std::string processingName = net.GetNetworkId( *it );
+ AudioSink* audioSink = GetAudioSinks()[i];
+ std::string processingName = net.GetNetworkId(audioSink);
- const AudioSink::Ports & ports = (*it)->GetPorts();
+ const AudioSink::Ports & ports = audioSink->GetPorts();
+
for(unsigned port = 0; port < ports.size(); ++port)
{
- //Get Processing address
- SinkJackBinding pair;
- pair.processing=*it;
- pair.processing->SetFrameAndHopSize(_jackBufferSize, port);
+ JackPort jp;
+ std::stringstream portName;
+ if (ports.size() == 1)
+ portName << processingName;
+ else
+ portName << processingName << "_" << ports[port].mAudioIn->GetName();
- //Register port on the JACK server
- std::stringstream portName;
- if (ports.size() == 1)
- portName << processingName;
- else
- portName << processingName << "_" << ports[port].mAudioIn->GetName();
+ jp.jackPort=jack_port_register(_jackClient, portName.str().c_str(),
+ JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
+ _sinkJackPorts.push_back(jp);
- pair.jackPort=jack_port_register (_jackClient, portName.str().c_str(),
- JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
-
- pair.port = port;
-
- //Add the pair (jack port, clam jack receiver) to the list
- _sinkJackBindings.push_back(pair);
+ audioSink->SetFrameAndHopSize(_jackBufferSize, port);
}
}
}
void JACKNetworkPlayer::UnRegisterPorts()
{
- for (SinkJackBindings::iterator it=_sinkJackBindings.begin(); it!=_sinkJackBindings.end(); it++)
+ for (SinkJackPorts::iterator it=_sinkJackPorts.begin(); it!=_sinkJackPorts.end(); it++)
{
if ( jack_port_unregister ( _jackClient, it->jackPort) )
{
@@ -174,9 +157,9 @@
exit(1);
}
}
- _sinkJackBindings.clear();
+ _sinkJackPorts.clear();
- for (SourceJackBindings::iterator it=_sourceJackBindings.begin(); it!=_sourceJackBindings.end(); it++)
+ for (SourceJackPorts::iterator it=_sourceJackPorts.begin(); it!=_sourceJackPorts.end(); it++)
{
if ( jack_port_unregister ( _jackClient, it->jackPort) )
{
@@ -184,36 +167,38 @@
exit(1);
}
}
- _sourceJackBindings.clear();
+ _sourceJackPorts.clear();
}
void JACKNetworkPlayer::CopyJackBuffersToGenerators(const jack_nframes_t nframes)
{
- for (SourceJackBindings::iterator it=_sourceJackBindings.begin(); it!=_sourceJackBindings.end(); it++)
+ for (unsigned i = 0; i < _sourceJackPorts.size(); ++i)
{
//Retrieve JACK buffer location
jack_default_audio_sample_t *jackInBuffer =
- (jack_default_audio_sample_t*) jack_port_get_buffer ( it->jackPort, nframes);
+ (jack_default_audio_sample_t*) jack_port_get_buffer(_sourceJackPorts[i].jackPort, nframes);
+
//Tell the AudioSource where to look for data in its Do()
- it->processing->SetExternalBuffer( jackInBuffer, nframes, it->port);
+ GetAudioSources()[i]->SetExternalBuffer( jackInBuffer, nframes, i);
}
}
void JACKNetworkPlayer::CopySinksToJackBuffers(const jack_nframes_t nframes)
{
- for (SinkJackBindings::iterator it=_sinkJackBindings.begin(); it!=_sinkJackBindings.end(); it++)
+ for (unsigned i = 0; i < _sinkJackPorts.size(); ++i)
{
//Retrieve JACK buffer location
- jack_default_audio_sample_t *jackOutBuffer =
- (jack_default_audio_sample_t*) jack_port_get_buffer ( it->jackPort, nframes);
+ jack_default_audio_sample_t* jackOutBuffer =
+ (jack_default_audio_sample_t*) jack_port_get_buffer(_sinkJackPorts[i].jackPort, nframes);
+
//Tell the AudioSource where to copy data consumed in its Do()
- it->processing->SetExternalBuffer( jackOutBuffer, nframes, it->port);
+ GetAudioSinks()[i]->SetExternalBuffer(jackOutBuffer, nframes, i);
}
}
void JACKNetworkPlayer::BlankJackBuffers(const jack_nframes_t nframes)
{
- for (SinkJackBindings::iterator it=_sinkJackBindings.begin(); it!=_sinkJackBindings.end(); it++)
+ for (SinkJackPorts::iterator it=_sinkJackPorts.begin(); it!=_sinkJackPorts.end(); it++)
{
jack_default_audio_sample_t *jackOutBuffer =
(jack_default_audio_sample_t*) jack_port_get_buffer ( it->jackPort, nframes);
@@ -257,8 +242,8 @@
if (not _jackClient) return;
BeStopped();
GetNetwork().Stop();
- _sinkJackBindings.clear(); // TODO: May we save them?
- _sourceJackBindings.clear(); // TODO: May we save them?;
+ _sinkJackPorts.clear(); // TODO: May we save them?
+ _sourceJackPorts.clear(); // TODO: May we save them?;
_jackClient=0;
}
@@ -292,7 +277,7 @@
//Saves the connections made to our local in/out jack ports
void JACKNetworkPlayer::StoreConnections()
{
- for (SourceJackBindings::iterator it=_sourceJackBindings.begin(); it!=_sourceJackBindings.end(); it++)
+ for (SourceJackPorts::iterator it=_sourceJackPorts.begin(); it!=_sourceJackPorts.end(); it++)
{
JackConnection connection;
connection.processingName = it->PortName();
@@ -300,7 +285,7 @@
_incomingJackConnections.push_back(connection);
}
- for (SinkJackBindings::iterator it=_sinkJackBindings.begin(); it!=_sinkJackBindings.end(); it++)
+ for (SinkJackPorts::iterator it=_sinkJackPorts.begin(); it!=_sinkJackPorts.end(); it++)
{
JackConnection connection;
connection.processingName = it->PortName();
@@ -359,7 +344,7 @@
int i=0;
//Double iterate AudioSources & found JACK out ports
- for ( SourceJackBindings::iterator it= _sourceJackBindings.begin(); it!=_sourceJackBindings.end(); it++)
+ for ( SourceJackPorts::iterator it= _sourceJackPorts.begin(); it!=_sourceJackPorts.end(); it++)
{
std::cout << "- Connecting " << portnames[i] << " -> "
<< it->PortName() << std::endl;
@@ -385,7 +370,7 @@
int i=0;
//Double iterate found JACK in ports & ExterSinks
- for (SinkJackBindings::iterator it= _sinkJackBindings.begin(); it!=_sinkJackBindings.end(); it++)
+ for (SinkJackPorts::iterator it= _sinkJackPorts.begin(); it!=_sinkJackPorts.end(); it++)
{
std::cout << "- Connecting "<< it->PortName()
<< " -> " << portnames[i] << std::endl;
Index: CLAM/src/Flow/Networks/BackEnds/JACKNetworkPlayer.hxx
===================================================================
--- CLAM/src/Flow/Networks/BackEnds/JACKNetworkPlayer.hxx (revision 13302)
+++ CLAM/src/Flow/Networks/BackEnds/JACKNetworkPlayer.hxx (working copy)
@@ -10,34 +10,25 @@
namespace CLAM
{
+
class JACKNetworkPlayer : public NetworkPlayer
{
private:
- //Structures to keep information about every external input and output processing
- //TODO use mAudioSources/Sinks in the parent class instead.
- template<typename T>
- struct JackBinding
+ struct JackPort
{
- const char* PortName()
- {
- return jack_port_name(jackPort);
- }
+ const char* PortName() { return jack_port_name(jackPort); }
jack_port_t* jackPort;
- T* processing;
- unsigned port;
};
- typedef JackBinding<AudioSource> SourceJackBinding;
- typedef std::vector<SourceJackBinding> SourceJackBindings;
-
- typedef JackBinding<AudioSink> SinkJackBinding;
- typedef std::vector<SinkJackBinding> SinkJackBindings;
+ typedef std::vector<JackPort> SourceJackPorts;
+ typedef std::vector<JackPort> SinkJackPorts;
struct JackConnection
{
std::string processingName;
const char ** outsideConnections;
};
+
typedef std::list<JackConnection> JackConnections;
private:
@@ -45,12 +36,12 @@
int _jackBufferSize;
bool _autoConnect;
+ SourceJackPorts _sourceJackPorts;
+ SinkJackPorts _sinkJackPorts;
+
JackConnections _incomingJackConnections;
JackConnections _outgoingJackConnections;
- SourceJackBindings _sourceJackBindings;
- SinkJackBindings _sinkJackBindings;
-
std::string _jackOutPortAutoConnectList;
std::string _jackInPortAutoConnectList;
@@ -84,10 +75,12 @@
virtual void Start();
virtual void Stop();
virtual void Init();
+
virtual unsigned BackendBufferSize()
{
return _jackBufferSize;
}
+
virtual unsigned BackendSampleRate() { return _jackSampleRate; }
void Do(const jack_nframes_t nframes);
Index: CLAM/src/Flow/Networks/BackEnds/PANetworkPlayer.cxx
===================================================================
--- CLAM/src/Flow/Networks/BackEnds/PANetworkPlayer.cxx (revision 13302)
+++ CLAM/src/Flow/Networks/BackEnds/PANetworkPlayer.cxx (working copy)
@@ -38,6 +38,7 @@
return 0;
}
+namespace {
void displayPADevices()
{
@@ -70,6 +71,8 @@
}
}
+}
+
PANetworkPlayer::PANetworkPlayer()
: mPreferredBufferSize(paFramesPerBufferUnspecified)
, mSamplingRate(48000)
@@ -94,8 +97,8 @@
if (CheckPaError(Pa_Initialize())) return;
displayPADevices();
- int nInChannels = GetSourcesSize();
- int nOutChannels = GetSinksSize();
+ int nInChannels = GetSize<Network::AudioSources>(GetAudioSources());
+ int nOutChannels = GetSize<Network::AudioSinks>(GetAudioSinks());
PaHostApiTypeId apiTryList[] = {
paDirectSound,
@@ -113,6 +116,7 @@
paOSS,
paInDevelopment
};
+
// int defaultApi = Pa_GetDefaultHostApi();
// const PaHostApiInfo * apiInfo = Pa_GetHostApiInfo( defaultApi );
const PaHostApiInfo * apiInfo = 0;
@@ -126,6 +130,7 @@
break;
}
CLAM_ASSERT(apiInfo, "PortAudio: No API available.");
+
//Create configuration for input&output and then register the stream
PaStreamParameters inputParameters;
PaStreamParameters * inParams = 0;
@@ -178,6 +183,7 @@
outputParameters.hostApiSpecificStreamInfo = NULL;
outParams = &outputParameters;
}
+
CLAM_ASSERT(!mPortAudioStream, "Portaudio: Previous stream not closed");
if (CheckPaError(
Pa_OpenStream(
@@ -194,6 +200,7 @@
mErrorMessage = "Audio i/o devices requirements not fullfilled";
return;
}
+
BePlaying();
const PaStreamInfo * streamInfo = Pa_GetStreamInfo(mPortAudioStream);
std::cout << "Sample rate: " << streamInfo->sampleRate << std::endl;
@@ -276,36 +283,29 @@
void PANetworkPlayer::DoInPorts(float** input, unsigned long nframes)
{
- int i=0;
- const Network::AudioSources & sources=GetAudioSources();
- for ( Network::AudioSources::const_iterator it=sources.begin(); it!=sources.end(); it++ )
+ for(unsigned i = 0; i < _audioSources.size(); ++i)
{
- unsigned ports_size = (*it)->GetPorts().size();
+ AudioSource* audioSource = _audioSources[i];
+ unsigned ports_size = audioSource->GetPorts().size();
for (unsigned port = 0; port < ports_size; ++port)
- (*it)->SetExternalBuffer( input[i++], nframes, port);
+ audioSource->SetExternalBuffer( input[port], nframes, port);
}
}
void PANetworkPlayer::DoOutPorts(float** output, unsigned long nframes)
{
- int i=0;
- const Network::AudioSinks & sinks=GetAudioSinks();
- for (Network::AudioSinks::const_iterator it=sinks.begin(); it!=sinks.end(); it++)
+ for(unsigned i = 0; i < _audioSinks.size(); ++i)
{
- unsigned ports_size = (*it)->GetPorts().size();
+ AudioSink* audioSink = _audioSinks[i];
+ unsigned ports_size = audioSink->GetPorts().size();
for (unsigned port = 0; port < ports_size; ++port)
- (*it)->SetExternalBuffer(output[i++], nframes, port);
+ audioSink->SetExternalBuffer(output[port], nframes, port);
}
}
void PANetworkPlayer::MuteOutBuffers(float** output, unsigned long nframes)
{
- unsigned nSinks = 0;
-
- const Network::AudioSinks & sinks = GetAudioSinks();
- for (Network::AudioSinks::const_iterator it=sinks.begin(); it!=sinks.end(); ++it)
- nSinks += (*it)->GetPorts().size();
-
+ unsigned nSinks = GetSize<Network::AudioSinks>(GetAudioSinks());
for (unsigned i=0; i<nSinks; i++)
std::memset(output[i], 0, nframes*sizeof(float));
}
Index: CLAM/src/Flow/Networks/BackEnds/OfflineNetworkPlayer.cxx
===================================================================
--- CLAM/src/Flow/Networks/BackEnds/OfflineNetworkPlayer.cxx (revision 13302)
+++ CLAM/src/Flow/Networks/BackEnds/OfflineNetworkPlayer.cxx (working copy)
@@ -13,14 +13,15 @@
bool OfflineNetworkPlayer::IsWorking()
{
- return (_outFileNames.size() != GetSourcesSize()) && (_inFileNames.size() != GetSinksSize());
+ return (_outFileNames.size() != GetSize<Network::AudioSources>(GetAudioSources()))
+ && (_inFileNames.size() != GetSize<Network::AudioSinks>(GetAudioSinks()));
}
std::string OfflineNetworkPlayer::NonWorkingReason()
{
std::stringstream ss;
- ss << GetSourcesSize() << " inputs and "
- << GetSinksSize() << " outputs needed but just "
+ ss << GetSize<Network::AudioSources>(GetAudioSources()) << " inputs and "
+ << GetSize<Network::AudioSinks>(GetAudioSinks()) << " outputs needed but just "
<< _inFileNames.size() << " input files provided"
<< _outFileNames.size() << " output files provided"
<< std::ends;
@@ -45,7 +46,6 @@
const AudioSource::Ports & ports = (*it)->GetPorts();
for(unsigned port = 0; port < ports.size(); ++port)
{
- //Register port on the JACK server
std::stringstream portName;
if (ports.size() == 1)
portName << processingName;
@@ -138,10 +138,11 @@
}
// Check that the number of input channels matches the network
- if( inputChannelsCount != GetSourcesSize())
+ unsigned nInChannels = GetSize<Network::AudioSources>(GetAudioSources());
+ if( inputChannelsCount != nInChannels)
{
std::cout <<"The number of input channels is different than the number of sources in the provided network." << std::endl
- <<"There are "<<GetSourcesSize()<<" sources and "
+ <<"There are "<<nInChannels<<" sources and "
<<inputChannelsCount<<" input channels summing all channels in "<<infiles.size()<<" input files"<<std::endl;
exit(-1);
}
@@ -163,10 +164,11 @@
}
// Check that the number of output channels matches the network
- if( outputChannelsCount != GetSinksSize())
+ unsigned nOutChannels = GetSize<Network::AudioSinks>(GetAudioSinks());
+ if( outputChannelsCount != nOutChannels)
{
std::cout <<"The number of output channels is different than the number of sinks in the provided network." << std::endl
- <<"There are "<<GetSinksSize()<<" sinks and "
+ <<"There are "<<nOutChannels<<" sinks and "
<<outputChannelsCount<<" output channels summing all channels in "<<outfiles.size()<<" output files"<<std::endl;
exit(-1);
}
@@ -178,13 +180,13 @@
std::vector<DataArray> inbuffers(inputChannelsCount);
unsigned sourceIndex=0;
unsigned fileIndex = 0;
- while(sourceIndex<GetAudioSources().size())
+ while(sourceIndex<_audioSources.size())
{
if(fileIndex>=infiles.size())
{
std::cout
<< "The number of sources is greater than the intput files. "
- << "There are " << GetSourcesSize() <<" sources and "
+ << "There are " << GetSize<Network::AudioSources>(GetAudioSources()) <<" sources and "
<< infiles.size() << "input files"
<< std::endl;
exit(-1);
@@ -194,7 +196,7 @@
{
inbuffers[sourceIndex].Resize( frameSize );
inbuffers[sourceIndex].SetSize( frameSize );
- AudioSource& source = *GetAudioSources()[sourceIndex];
+ AudioSource& source = *_audioSources[sourceIndex];
const AudioSource::Ports & ports = source.GetPorts();
for(unsigned port = 0; port < ports.size(); ++port)
@@ -210,28 +212,29 @@
std::vector<DataArray> outbuffers(outputChannelsCount);
fileIndex = 0;
unsigned sinkIndex = 0;
- while(sinkIndex < GetAudioSinks().size())
+ while(sinkIndex < _audioSinks.size())
{
if(fileIndex >= outfiles.size())
{
std::cout << "The number of sinks is greater than the output files. "
- << "There are " <<GetSinksSize() << " sinks " << " and "
+ << "There are " << GetSize<Network::AudioSinks>(GetAudioSinks()) << " sinks and "
<< outfiles.size() <<"output files" << std::endl;
exit(-1);
}
for(int channel = 0;channel < outfiles[fileIndex]->channels(); channel++)
{
- if(fileIndex+channel >= GetSinksSize())
+ unsigned sinkSize = GetSize<Network::AudioSinks>(GetAudioSinks());
+ if(fileIndex+channel >= sinkSize)
{
std::cout << "The number of output channels is greater than the sinks. "
- << "There are " << GetSinksSize() << " sinks and "
+ << "There are " << sinkSize << " sinks and "
<< fileIndex+channel << " ouput channels" << std::endl;
exit(-1);
}
outbuffers[sinkIndex].Resize( frameSize );
outbuffers[sinkIndex].SetSize( frameSize );
- AudioSink& sink = *GetAudioSinks()[sinkIndex];
+ AudioSink& sink = *_audioSinks[sinkIndex];
const AudioSink::Ports & ports = sink.GetPorts();
for(unsigned port = 0; port < ports.size(); ++port)
Index: CLAM/src/Flow/Networks/NetworkPlayer.hxx
===================================================================
--- CLAM/src/Flow/Networks/NetworkPlayer.hxx (revision 13302)
+++ CLAM/src/Flow/Networks/NetworkPlayer.hxx (working copy)
@@ -31,14 +31,11 @@
namespace {
-template<typename Container>
-unsigned GetSize(Container const& t)
+template<typename Container> unsigned GetSize(Container const& t)
{
unsigned nrOfPorts = 0;
for (typename Container::const_iterator it = t.begin(); it != t.end(); ++it)
- {
nrOfPorts += (*it)->GetPorts().size();
- }
return nrOfPorts;
}
@@ -56,6 +53,10 @@
{
protected:
enum Status { Playing=0, Stopped=1, Paused=2 };
+
+ Network::AudioSources _audioSources;
+ Network::AudioSinks _audioSinks;
+
public:
NetworkPlayer()
: _network(NULL)
@@ -91,21 +92,28 @@
void SetNetworkBackLink( Network& net )
{
_network=&net;
+
+ _audioSources = GetAudioSources();
+ _audioSinks = GetAudioSinks();
}
+
void BePaused() { _status=Paused; }
void BeStopped() { _status=Stopped; }
void BePlaying() { _status=Playing; }
bool IsPaused() const { return _status==Paused; }
bool IsStopped() const { return _status==Stopped; }
bool IsPlaying() const { return _status==Playing; }
+
virtual unsigned BackendBufferSize()
{
return 512;
}
+
virtual unsigned BackendSampleRate()
{
return 44100;
}
+
std::string SourcesAndSinksToString();
protected:
@@ -119,25 +127,17 @@
{
return GetNetwork().getOrderedSources();
}
+
Network::AudioSinks GetAudioSinks()
{
return GetNetwork().getOrderedSinks();
}
- unsigned GetSourcesSize()
- {
- return GetSize<Network::AudioSources>(GetAudioSources());
- }
-
- unsigned GetSinksSize()
- {
- return GetSize<Network::AudioSinks>(GetAudioSinks());
- }
-
private:
Network *_network;
volatile Status _status;
};
+
} //namespace CLAM
#endif // NetworkPlayer_hxx
Index: CLAM/src/Processing/AudioSource.hxx
===================================================================
--- CLAM/src/Processing/AudioSource.hxx (revision 13302)
+++ CLAM/src/Processing/AudioSource.hxx (working copy)
@@ -115,7 +115,8 @@
return true;
}
- Ports & GetPorts() { return _ports; }
+ Ports& GetPorts() { return _ports; }
+ Ports const& GetPorts() const { return _ports; }
private:
void ResizePorts(unsigned sources)
_______________________________________________
Clam-devel mailing list
[email protected]
https://llistes.projectes.lafarga.org/cgi-bin/mailman/listinfo/clam-devel