25 <<
GetNSinks() <<
" outputs needed but just "
26 << _inFileNames.size() <<
" input files provided"
27 << _outFileNames.size() <<
" output files provided"
34 std::ostringstream result;
36 unsigned inFileIndex = 0;
37 unsigned inChannel = 0;
41 result <<
" * source:\t" <<
SourceName(i) <<
"\t";
42 result <<
"In:\t" << _inFileNames[inFileIndex] <<
"\tchannel " << inChannel <<
"\n";
45 if((
unsigned)infiles[inFileIndex]->channels() == inChannel)
52 unsigned outFileIndex = 0;
53 unsigned outChannel = 0;
57 result <<
" * sink:\t" <<
SinkName(i) <<
"\t";
58 result <<
"Out:\t" << _outFileNames[outFileIndex] <<
"\tchannel " << outChannel <<
"\n";
61 if((
unsigned)outfiles[outFileIndex]->channels() == outChannel)
80 const int frameSize = 512;
84 unsigned inputChannelsCount = 0;
87 for(
unsigned fileIndex = 0; fileIndex < _inFileNames.size(); fileIndex++)
90 "Not all the network inputs could be fullfiled. Have you checked the IsWorking() method?");
91 std::ifstream checkfile(_inFileNames[fileIndex].c_str());
93 CLAM_ASSERT(checkfile.is_open(),std::string(
"Could not open one of the input files: "+_inFileNames[fileIndex]).c_str());
94 SndfileHandle* infile =
new SndfileHandle(_inFileNames[fileIndex].c_str(), SFM_READ );
97 inputChannelsCount += infile->channels();
100 sampleRate = infile->samplerate();
103 "All the input audio files have to have the same sample rate");
105 infiles.push_back(infile);
110 "The number of input channels is different than the number of sourceports in the provided network.");
113 unsigned outputChannelsCount=0;
115 for(
unsigned fileIndex=0;fileIndex<_outFileNames.size();fileIndex++)
117 if (fileIndex>=_outFileNames.size())
119 std::cerr <<
"Not all the network outputs could be fullfiled.";
123 SndfileHandle* outfile =
new SndfileHandle(_outFileNames[fileIndex].c_str(), SFM_WRITE,
124 _format,_outChannelsFiles[fileIndex],sampleRate);
125 CLAM_ASSERT(*outfile,
"Can not create the outfile ");
126 outputChannelsCount +=_outChannelsFiles[fileIndex];
127 outfiles.push_back(outfile);
132 "The number of output channels is different than the number of sinkports in the provided network.");
134 std::cout <<
"Sources and Sinks list:" <<std::endl;
141 std::vector<DataArray> inbuffers(inputChannelsCount);
144 inbuffers[i].Resize( frameSize );
145 inbuffers[i].SetSize( frameSize );
146 const TData * data = &inbuffers[i][0];
154 std::vector<DataArray> outbuffers(outputChannelsCount);
155 for(
unsigned i = 0; i <
GetNSinks(); ++i)
157 outbuffers[i].Resize( frameSize );
158 outbuffers[i].SetSize( frameSize );
160 TData * data = &outbuffers[i][0];
165 long iterationIndex = 0;
166 bool timeLimitedMode = _resultWavsTime > 0.001;
170 std::cout <<
"." << std::flush;
171 unsigned inAudioIndex =0;
172 bool someInputFinished=
false;
173 for(SndFileHandles::iterator it = infiles.begin(); it != infiles.end(); ++it)
175 SndfileHandle * sndfileHandle = (*it);
176 unsigned int nChannels = sndfileHandle->channels();
177 CLAM_ASSERT(nChannels,
"The audio had no channels");
178 int bufferReaderSize = nChannels*frameSize;
179 float * bufferReader =
new float[bufferReaderSize];
180 int readSize = sndfileHandle->read(bufferReader,bufferReaderSize);
183 if(readSize<bufferReaderSize)
185 for(
int i = readSize; i < bufferReaderSize; i++)
189 if(_enableLoopInputWavs)
190 sndfileHandle->seek(0,SEEK_SET);
191 someInputFinished =
true;
194 for(
int frameIndex=0; frameIndex <frameSize; frameIndex ++)
196 for(
unsigned channel=0; channel < nChannels; channel++)
198 inbuffers[inAudioIndex+channel][frameIndex] = bufferReader[(frameIndex*nChannels)+channel];
201 inAudioIndex += nChannels;
203 delete[] bufferReader;
208 unsigned outAudioIndex = 0;
209 for(SndFileHandles::iterator it = outfiles.begin(); it != outfiles.end(); ++it)
211 SndfileHandle * sndfileHandle = (*it);
212 unsigned int nChannels = sndfileHandle->channels();
213 int bufferWriterSize = nChannels*frameSize;
214 float* bufferWriter =
new float[bufferWriterSize];
217 for(
int frameIndex = 0; frameIndex < frameSize; frameIndex ++)
219 for(
unsigned channel = 0; channel < nChannels; channel++)
221 bufferWriter[(frameIndex*nChannels) + channel] =
222 outbuffers[outAudioIndex + channel][frameIndex];
225 int writeSize = sndfileHandle->write(bufferWriter, bufferWriterSize);
226 CLAM_ASSERT(writeSize == bufferWriterSize,
"The outfile has not been written correctly");
227 outAudioIndex += nChannels;
228 delete[] bufferWriter;
231 if (timeLimitedMode and
float(iterationIndex * frameSize) / sampleRate > _resultWavsTime)
233 std::cout <<
"REACHED MAX TIME - finalizing"<< std::endl;
238 if (someInputFinished and not _enableLoopInputWavs )
243 for(SndFileHandles::iterator it = infiles.begin(); it != infiles.end(); ++it)
246 for(SndFileHandles::iterator it = outfiles.begin(); it != outfiles.end(); ++it)
266 _inFileNames.push_back(filename);
271 _outFileNames.push_back(filename);
276 _outChannelsFiles.push_back(channel);