00001
00002
00003
00004
00005 using namespace std;
00006
00007 #include<cstdlib>
00008 #include<cstring>
00009 #include<string>
00010 #include<vector>
00011
00012 #ifndef PARAMETERSINCLUDED
00013 #include "parameters.cpp"
00014 #endif
00015
00016 #ifndef FRAMEINCLUDED
00017 #include "frame.cpp"
00018 #endif
00019
00020 #ifndef PARAMETERSINCLUDED
00021 #include "parameters.cpp"
00022 #endif
00023
00024 #define REPOSITORYMANAGERINCLUDED
00025
00026 class repositorymanager{
00027 private:
00028 string emailid;
00029 string path;
00030
00031
00032 public:
00033
00034 repositorymanager()
00035 {
00036 path=(string)REP_PATH;
00037 emailid="";
00038 }
00039
00040 repositorymanager(string email_id, int create=NOCREATE)
00041 {
00042 string temp_path;
00043 FILE* fptr;
00044 path=(string)REP_PATH;
00045 emailid=email_id;
00046 temp_path=path+emailid;
00047 temp_path=temp_path+(string)CODEBOOK;
00048 fptr=fopen(temp_path.c_str(),"r");
00049 int size=0;
00050 if(fptr!=NULL)
00051 size=fseek(fptr,0L,SEEK_END);
00052 if(fptr)
00053 {
00054 fclose(fptr);
00055 }
00056 else
00057 {
00058 if(create==CREATE)
00059 {
00060 temp_path=(string)"mkdir "+path+emailid;
00061 system(temp_path.c_str());
00062 temp_path=path+emailid;
00063 temp_path=temp_path+(string)CODEBOOK;
00064 }
00065 else
00066 {
00067 cerr<<"The desired repository could not be found"<<endl;
00068 exit(1);
00069 }
00070 }
00071 }
00072
00073 string makeNewFileName(int i)
00074 {
00075 string filename;
00076 string temp;
00077 char tmp[60];
00078 sprintf(tmp,"%d",i);
00079 filename=path +emailid+"/"+tmp+".wav";
00080 return filename;
00081 }
00082
00083 vector<double> getClusterCenter(unsigned int i)
00084 {
00085 FILE* fptr;
00086 vector<double> a;
00087 string temp_path=path+emailid;
00088 temp_path=temp_path+(string)CODEBOOK;
00089 fptr=fopen(temp_path.c_str(),"r+");
00090 if(fptr!=NULL)
00091 {
00092 fseek(fptr,i*sizeof(double)*MAX_DIM,SEEK_SET);
00093 double b;
00094 for(int j=0;j<MAX_DIM;j++)
00095 {
00096 fread((double*)&b,sizeof(double),1,fptr);
00097 a.push_back(b);
00098 }
00099 fclose(fptr);
00100 }
00101 else
00102 cout<<"You don't possess the desired repository at the appropriate location";
00103 return a;
00104 }
00105
00106 int addMFCC(vector<double> mfcc)
00107 {
00108 FILE* fptr;
00109 double temp_param;
00110 string temp_path;
00111 temp_path=path+emailid+(string)CODEBOOK;
00112 fptr=fopen(temp_path.c_str(),"a+");
00113 int bytes;
00114 for(int j=0;j<MAX_DIM;j++)
00115 {
00116 temp_param=mfcc[j];
00117 bytes=fwrite((double*)&temp_param,sizeof(double),1,fptr);
00118 }
00119 fclose(fptr);
00120 return SUCCESS;
00121 }
00122
00123
00124 string getFrameName(unsigned int code)
00125 {
00126 string filename;
00127 char tmp[60];
00128 sprintf(tmp,"%d",code);
00129 filename=path +emailid+"/"+tmp+".wav";
00130 return filename;
00131 }
00132
00133 ~repositorymanager() {
00134 }
00135
00136 };
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155