[CLAM] SMSTools linking problems

Xavier Amatriain xamat at iua.upf.es
Mon Jul 26 04:20:32 PDT 2004


I just made a quick addition to the SMSBatch version that may help you. 
Now if you run SMSBatch with no arguments you will still get the menu
with the following options:

1: analyze, transform, synthesize (New!!)
2: analyze, synthesize
3: only analyze
4: only synthesize
0: exit

But I added the option of running the program with two arguments, the
first being the folder (and its subfolders) you want to process and the
second one being the option from the above list.

If you choose the 1st option, the program will take all files with
".xml" extension as configuration files and will look for files with the
same name but with ".xmltr" extension as the associated transformation
file (I know it is a dirty hack but it is the best I can do before going
on holydays ;). So if you want to analyze, transform and synthesize a
given file you will have to have myFile.xml and myFile.xmltr in the same
folder.

Just overwrite the files CLAM/examples/SMS/SMSBatch.cxx and
CLAM/build/Examples/SMS/Batch/settings.cfg with the attached, compile
and please report any bug.

> What would be great would be something like an old sms package I used to
> use, where you could do like "sms analysis," and "sms synthesis," where
> the former would automatically load a config file and output an analysis
> file, and the latter would automatically load a config file, an analysis
> file and a transformation score, and output the sound.  All three of the
> SMS programs in the current package all require user input at runtime,
> which makes it impossible to script with.  I'm sure a solution could be
> hacked by making an easy transformation to the main program for
> SMSConsole, but I am as yet unfamiliar with C++...
> 
> Matt
> 
> 
> _______________________________________________
> CLAM mailing list
> CLAM at iua.upf.es
> http://www.iua.upf.es/mtg/clam
-- 
/**********************************
********* Xavier Amatriain ********
****** Music Technology Group *****
** IUA- Universitat Pompeu Fabra **
****** www.iua.upf.es/~xamat ******
***********************************/
-------------- next part --------------
/*
 * Copyright (c) 2001-2002 MUSIC TECHNOLOGY GROUP (MTG)
 *                         UNIVERSITAT POMPEU FABRA
 *
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

#include "SMSBase.hxx"
#include <iostream>
#include <stdio.h>
#include "StdOutProgress.hxx"
#include "StdOutWaitMessage.hxx"
#include "TraverseDirectory.hxx"

#include <iostream>
#include <algorithm>


namespace CLAM{

/** Declaration of the concrete Traverse directory class to apply to all files*/
class SMSBatch:public TraverseDirectory,public SMSBase
{
public:
	CLAMGUI::Progress* CreateProgress(const char* title,float from,float to)
	{
		return new CLAMGUI::StdOutProgress(title,from,to);
	}
	CLAMGUI::WaitMessage* CreateWaitMessage(const char* title)
	{
		return new CLAMGUI::StdOutWaitMessage(title);
	}
	void OnFile(const std::string& filename);
	void Run(void);
		void Run(const char* folder,const char* option);

private:
	std::string ChangeExtension(const std::string& filename,const std::string& newExtension);
	int mOption;
};


//Auxiliary function to change the .mid extension to .xml in a given filename
std::string SMSBatch::ChangeExtension(const std::string& filename,const std::string& newExtension)
{
	std::string result=filename.substr(0,filename.rfind('.')+1);
	result.append(newExtension);
	return result;
}


//Function where the process related to every file is actually implemented
void SMSBatch::OnFile(const std::string& filename)
{      
	std::string xml("xml");
	std::string tr("tr");
	
	//First we ensure that it is an XML file looking at the extension
	if(GetExtension(filename)!=xml) 
		return;
	std::cout<<"\n"<<"Processing file: "<<filename<<"\n";
	LoadConfig(filename);
	switch(mOption)
	{
		case 1://Analyze, synthesize and store output sound + sinusoidal componet + residual component
		{
			std::string transformationScore(filename);
			transformationScore+=tr;
			FILE *f;
			bool haveTransformationScore=true;
			if((f = fopen(transformationScore.c_str(),"rt")) == NULL)
			{
				std::cout<<"Transformation score does not exist on specified directory.";
				haveTransformationScore=false;
			}
			fclose(f);
			if(haveTransformationScore)	LoadTransformationScore(transformationScore);
			LoadInputSound();
			Analyze();
			if(haveTransformationScore) Transform();
			Synthesize();
			StoreOutputSound();
			StoreOutputSoundSinusoidal();
			StoreOutputSoundResidual();
			break;
		}
	    case 2://Analyze, synthesize and store output sound + sinusoidal componet + residual component
		{
			LoadInputSound();
			Analyze();
			Synthesize();
			StoreOutputSound();
			StoreOutputSoundSinusoidal();
			StoreOutputSoundResidual();
			break;
		}
		case 3://Analyze content of a given folder and store output .sdif or .xml files
		{
			LoadInputSound();
			Analyze();
			StoreAnalysis( mGlobalConfig.GetOutputAnalysisFile() );			
			break;
		}
		case 4://Synthesize previously analyzed .sdif or .xml files
		{
			LoadAnalysis(mGlobalConfig.GetInputAnalysisFile());
			Synthesize();
			StoreOutputSound();
			StoreOutputSoundSinusoidal();
			StoreOutputSoundResidual();
			break;
		}
		default:
		{
			std::cout<<"\n"<<"\n"<<"Error, not a valid option"<<"\n"<<"\n"<<"\n";
			break;
		}
	}
}


void SMSBatch::Run(const char* folder,const char* option)
{
	int nOption=atoi(option);
	if(nOption<5)
		mOption=nOption;	
	else mOption=0;

	if (!mOption) return;
		
	std::string folderName(folder);
	Traverse(folderName);

}

void SMSBatch::Run(void)
{
	bool finish = false;
	while(!finish){
		std::cout <<"\n" << "\n";
		std::cout << "SMS Analysis/Synthesis Batch Aplication" << "\n";
		std::cout << "MTG - UPF (Barcelona, Spain)"<<"\n" << "\n";
		std::cout << "Please choose one of the following options:" << "\n" << "\n";
		std::cout << "1. Analyze, Transform, and Synthesize" << "\n";
		std::cout << "2. Analyze and Synthesize" << "\n";
		std::cout << "3. Only Analyze" << "\n";
		std::cout << "4. Only Synthesize" << "\n";
		std::cout << "0. Finish" << "\n" << "\n";

		mOption=0;
		std::cin>>mOption;

		if (!mOption) return;
		
		std::string folderName;
		std::cout<<"\n"<<"\n"<<"Enter folder name where xml configuration files are located (note that all subdirectories will be scanned recursively): \n";
		std::cin>>folderName;
		
		Traverse(folderName);

	}
}

};//namespace CLAM

int main(int argc,char** argv)
{
	try{
		CLAM::SMSBatch example;
		if(argc!=3)
			example.Run();
		else
			example.Run(argv[1],argv[2]);	
	}
	catch(CLAM::Err error)
	{
		error.Print();
		std::cerr << "Abnormal Program Termination" << std::endl;
	}
	catch (std::exception e)
	{
		std::cout << e.what() << std::endl;
	}
	
	std::clog << "Finished successfully!";
	return 0;
}

-------------- next part --------------
TOP = ../../../..

PROGRAM = SMSBatch

include $(TOP)/build/defaults.cfg

CLAM_DOUBLE = 0 
# whether to use double (1) or float (0) for TData

CLAM_USE_XML = 1 
# whether to compile XML dependant code, and link agains Xerces

CLAM_DISABLE_CHECKS = 0
# whether to disable all the CLAM checks, both debug and normal

CLAM_USE_RELEASE_ASSERTS = 0
# whether to simulate release checks being in debug mode

USE_ALSA = 1
USE_FFTW = 1
USE_FLTK = 1
USE_DIRECTX = 1
USE_PORTAUDIO = 0
USE_RTAUDIO = 1
USE_PTHREADS = 1
USE_PORTMIDI = 0
USE_QT = 0

PRJ_SEARCH_INCLUDES =
PRJ_SEARCH_RECURSE_INCLUDES = $(TOP)/examples/SMS

include $(TOP)/build/system.cfg

# just some variables for making easier to specify new Transformations and Transformation Configurators
SMS_TRANSFORMS_DIR = $(TOP)/src/Processing/Transformations/SMS

SOURCES = \
	$(CLAM_PATH)/examples/SMS/SMSBatch.cxx \
	$(SMS_TRANSFORMS_DIR)/SMSFreqShift.cxx \
	$(SMS_TRANSFORMS_DIR)/SMSGenderChange.cxx \
	$(SMS_TRANSFORMS_DIR)/SMSHarmonizer.cxx \
	$(SMS_TRANSFORMS_DIR)/SMSMorph.cxx \
	$(SMS_TRANSFORMS_DIR)/SMSOddEvenHarmonicRatio.cxx \
	$(SMS_TRANSFORMS_DIR)/SMSPitchDiscretization.cxx \
	$(SMS_TRANSFORMS_DIR)/SMSSineFilter.cxx \
	$(SMS_TRANSFORMS_DIR)/SMSSinusoidalGain.cxx \
	$(SMS_TRANSFORMS_DIR)/SMSSpectralShapeShift.cxx \
	$(SMS_TRANSFORMS_DIR)/SMSTransformationChainIO.cxx \
	$(SMS_TRANSFORMS_DIR)/SMSResidualGain.cxx \
	$(SMS_TRANSFORMS_DIR)/SMSPitchShift.cxx \
	$(SMS_TRANSFORMS_DIR)/SMSTimeStretch.cxx \
	$(SOURCES_AUDIODEVICE) \
	$(SOURCES_MIDIDEVICE)


More information about the clam-users mailing list