/[marvin]/marvin/src/gui/identify_user.cc
ViewVC logotype

Diff of /marvin/src/gui/identify_user.cc

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by castor_fou, Thu Sep 11 16:25:31 2003 UTC revision 1.4 by castor_fou, Tue Sep 16 20:25:36 2003 UTC
# Line 32  Line 32 
32  *******************************************************************/  *******************************************************************/
33  #include <iostream>  #include <iostream>
34  #include <stdlib.h>  #include <stdlib.h>
35    #include <crypt.h>
36    #include <stdio.h>
37    
38    #include "algo/mfcc.hh"
39    #include "signal.hh"
40  #include "user.hh"  #include "user.hh"
41  #include "misc.hh"  #include "misc.hh"
42  #include "language/language.hh"  #include "language/language.hh"
43    
44  int check_password(std::string password)  int check_password(std::string password, class c_list_user *list_user)
45  {  {
46    std::string answer;    std::string answer, mdp_crypt;
47    int tentative = 0;    int tentative = 0;
48    
   // entre mdp et vérifie  
49    do    do
50      {      {
51        std::cout << ENTERPASSWORD;        std::cout << ENTERPASSWORD;
52        answer = get_stdin();        answer = get_stdin("");
53        std::cout << std::endl;        std::cout << std::endl;
54        if (answer.compare(password) == 0)  
55          return 0;        mdp_crypt = crypt(answer.c_str(), "$1$9a");
56    //       tmp = crypt(answer.c_str(), "$1$9a");
57    //      std::cout << "answer    " << answer << std::endl;
58    //       std::cout << "password  " << password << std::endl;
59    //       std::cout << "mdp_crypt " << mdp_crypt << std::endl;
60    //       std::cout << "tmp       " << tmp << std::endl;
61    
62          if (mdp_crypt.compare(password) == 0)
63            {
64              list_user->get_list_user()
65                [list_user->get_id_user()]->get_password()->set_passphrase_clear(answer);
66              return 0;
67            }
68        tentative++;        tentative++;
69      }      }
70    while (tentative < 3);    while (tentative < 3);
71    return 1;    return 1;
72  }  }
73    
74    int check_voice()
75    {
76      // enregistre la voix et la compare avec le reseau de neurone
77      return 0;
78    }
79    
80  int c_list_user::identify_user()  int c_list_user::identify_user()
81  {  {
82    std::string answer;    std::string answer;
# Line 66  int c_list_user::identify_user() Line 87  int c_list_user::identify_user()
87      {      {
88        print_list();        print_list();
89        std::cout << std::endl << WHICHUSER;        std::cout << std::endl << WHICHUSER;
90        answer = get_stdin();        answer = get_stdin("0");
91        std::cout << std::endl;              std::cout << std::endl;      
92        tmp = atoi(answer.c_str());        tmp = atoi(answer.c_str());
93        _id_user = tmp;        _id_user = tmp;
94        //      std::cout << "#" << tmp << "#" << std::endl;        //      std::cout << "#" << tmp << "#" << std::endl;
95      }      }
96    while (tmp > (_list_user.size() - 1));    while (tmp > (_list_user.size() - 1));
97    std::cout << "utilisateur choisi : " << _list_user[tmp]->get_name_user() << std::endl;    //  std::cout << "utilisateur choisi : " << _list_user[tmp]->get_name_user() << std::endl;
98    if (check_password(_list_user[tmp]->get_password()->get_passphrase()))    if (check_password(_list_user[tmp]->get_password()->get_passphrase(), this))
99      return 1;      if (check_voice())
100          return 1;
101    return 0;    return 0;
102  }  }
103    
104    
105    DiscSignal *open_wav_file(const char *file)
106    {
107      void          *buf;
108      double        *data;
109      FILE          *fd;
110      char          *buffer, step = 0;
111    
112      int           canal, frequence, size = 0, sample_s, nread = 2, i;
113      
114    
115      std::cout << "file open : " << file << std::endl;
116      fd = fopen(file, "r");
117      assert(fd);
118      std::cout << "fichier ouvert avec succes" << std::endl;
119      fseek(fd, 22, SEEK_SET);
120      while (fread(buffer = (char *)malloc(nread), 1, nread, fd))
121        {
122          std::cout << "In the loop" << std::endl;
123          switch (step)
124            {
125            case 0:
126              canal = (int)(buffer[0]);
127              nread = 4;
128              break;
129            case 1:
130              frequence = ((int*)buffer)[0];
131              nread = 6;
132              break;
133            case 2:
134              nread = 4;
135              break;
136            case 3:
137              sample_s = 16;//= ((int*)buffer)[0];
138              nread = 24;
139              break;
140            case 4:
141              nread = sample_s / 8;
142              break;
143            case 5:
144              step--;
145              size++;
146              break;
147            default:
148              assert(0);
149            }
150          step++;
151          free(buffer);
152        }
153    
154      data = (double *)malloc(sizeof(double) * size);
155      fseek(fd, 58, SEEK_SET);
156    
157    
158      std::cout << "canal: " << canal << " fr: " << frequence << " sample: " <<sample_s << " size :" << std::endl;
159      sample_s = 16;
160      for (i = 0; i < size; i++)
161        {
162          fread(buf = malloc(sample_s / 8), 1, sample_s / 8, fd);
163          if (sample_s == 8)
164            data[i] = (double)(((char*)buf)[0]) - 128;
165          else
166            if (sample_s == 16)
167              data[i] = (double)(((short*)buf)[0]);
168            else
169              assert (0);
170        }
171    
172        std::cout << " fr: " << frequence
173                << " canal: " << canal
174                << " size: " << size
175                << " sample_s: " << sample_s
176                << std::endl;
177    
178        std::cout << " XXX " << std::endl;
179    
180    
181      return (new DiscSignal(data, size));
182    }
183    
184    static DiscSignal *create_mfcc(std::string path)
185    {
186      DiscSignal    *wav, *window, *res;
187      unsigned      max;
188      mfcc          *make;
189      
190      std::cout << "Dans create mfcc" << std::endl;
191      wav = open_wav_file(path.c_str());
192      std::cout << "open wav file" << std::endl;
193      wav->perl_capture();
194      max = -wav->min() > wav->max() ?
195        wav->min() :
196        wav->max();
197      std::cout << "Mouarf !!!" << std::endl;
198      if (max < 512)
199        {
200          std::cerr << "Sorry: max(" << max<< ") < 512" << std::endl;
201          assert(0);
202        }
203      std::cout << "max calcule" << std::endl;
204      window = &wav->windowing(max - 512, max + 512);
205      std::cout << "windowing fait" << std::endl;
206      std::cout << max << " "<<window->length() << std::endl;
207      window->perl_capture();
208      std::cout << "perl capture" << std::endl;
209      make = new mfcc(*window);
210      std::cout << "mfcc faite" << std::endl;
211      *res = make->get_result();
212      std::cout << "resultat acquis" << std::endl;
213      return res;
214    }
215    
216    double *create_tab()
217    {
218      std::string file;
219      double *tmp = (double *)calloc(sizeof (double), 12 * NB_RECORD);
220      DiscSignal *res;
221      int k, i;
222    
223      if (tmp == NULL)
224        return NULL;
225      for (i = 0, k = 0; i < NB_RECORD; i++)
226        {
227          file = "/tmp/file_";
228          file += (i + 48);
229          file += ".wav";
230          std::cout << "path crée" << std::endl;
231          res = create_mfcc(file);
232          std::cout << "mfcc create" << std::endl;
233          if (res == NULL)
234            {
235              std::cerr << "DiscSignal null" << std::endl;
236              exit(1);
237            }
238          for (int j = 1; j < res->length(); j++, k++)
239            tmp[k] = res->get_data()[j];
240          std::cout << "tab rempli" << std::endl;
241        }
242      std::cout << "tab\n" << tmp << std::endl;
243      return tmp;
244    }

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26