ReMAS  1.5
Real-time Musical Accompaniment System
CPUFunctions.c
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright (C) 2017 by "Information Retrieval and Parallel Computing" *
3  * group (University of Oviedo, Spain), "Interdisciplinary Computation *
4  * and Communication" group (Polytechnic University of Valencia, Spain) *
5  * and "Signal Processing and Telecommunication Systems Research" group *
6  * (University of Jaen, Spain) *
7  * Contact: remaspack@gmail.com *
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  * This program is distributed in the hope that it will be useful, *
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
17  * GNU General Public License for more details. *
18  * *
19  * You should have received a copy of the GNU General Public License *
20  * along with this program; if not, write to the *
21  * Free Software Foundation, Inc., *
22  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
23  **************************************************************************
24 */
34 #include "CPUFunctions.h"
35 #include "FileFunctions.h"
36 
37 
48 void ApplyWindow(MyType * __restrict X_fft, const short *frame, const MyType *v_hanning,
49  const int framesize, const int xfftsize)
50 {
51  int i;
52 
53  #ifdef OMP
54  #pragma omp parallel for
55  #endif
56  for(i=0; i<framesize; i++) { X_fft[i]=(MyType)frame[i] * Scaling * v_hanning[i]; }
57 
58  memset(&X_fft[framesize], 0, sizeof(MyType)*(xfftsize - framesize));
59 }
60 
61 
73 void ComputeNorms(MyType *norms, MyType *ts_fk, const MyType *s_fk, const int nmidi,
74  const int nbases, const MyType beta)
75 {
76  int i;
77 
78  if (beta>=(MyType)0.0 && beta<=(MyType)0.0)
79  for(i=0; i<nbases; i++) { norms[i]=(MyType)nmidi; }
80  else if (beta>=(MyType)1.0 && beta<=(MyType)1.0)
81  {
82  #ifdef OMP
83  #pragma omp parallel for
84  #endif
85  for(i=0; i<nbases; i++)
86  {
87  int k;
88  #ifndef CBLAS
89  int j;
90  MyType data;
91  #endif
92 
93  k=i*N_MIDI_PAD;
94 
95  #ifdef CBLAS
96  #ifdef SIMPLE
97  norms[i]=cblas_sasum(nmidi, &s_fk[k], 1);
98  #else
99  norms[i]=cblas_dasum(nmidi, &s_fk[k], 1);
100  #endif
101  #else
102  data=(MyType)0.0;
103  for(j=0; j<nmidi; j++)
104  data += s_fk[k+j];
105  norms[i] = data;
106  #endif
107  }
108  }
109  else
110  {
111  #ifdef CBLAS
112  for(i=0; i<nbases; i++)
113  #ifdef SIMPLE
114  norms[i]=cblas_sdot(nmidi, &ts_fk[i*N_MIDI_PAD], 1, &s_fk[i*N_MIDI_PAD], 1);
115  #else
116  norms[i]=cblas_ddot(nmidi, &ts_fk[i*N_MIDI_PAD], 1, &s_fk[i*N_MIDI_PAD], 1);
117  #endif
118  #else
119  #ifdef OMP
120  #pragma omp parallel for
121  #endif
122  for(i=0; i<nbases; i++)
123  {
124  int j, k;
125  MyType data;
126 
127  k=i*N_MIDI_PAD;
128 
129  data=(MyType)0.0;
130 
131  for(j=0; j<nmidi; j++)
132  data += ts_fk[k+j]*s_fk[k+j];
133  norms[i]=data;
134  }
135  #endif
136  }
137 }
138 
139 
152 int AllocAuxiCPU(MyType **norms, short **frame, MyType **v_cfreq, MyType **v_dxState, const int nbases,
153  const int tamframe, const int nmidi)
154 {
155  CHECKNULL((*norms) =(MyType *)calloc(nbases, sizeof(MyType)));
156  CHECKNULL((*v_dxState)=(MyType *)calloc(nbases, sizeof(MyType)));
157  CHECKNULL((*frame) =(short *) calloc(tamframe, sizeof(short)));
158  CHECKNULL((*v_cfreq) =(MyType *)calloc(nmidi, sizeof(MyType)));
159 
160  return OK;
161 }
162 
163 
177 int AllocFFTCPU(MyFFTCPUType *plan, MyType **X_fft, MyType **Out_fft, MyType **Mod_fft, int *kmin_fft,
178  int *kmax_fft, const int nfft, DTWfiles NameFiles)
179 {
180 
181  CHECKNULL((*X_fft) =(MyType *)calloc(2*nfft+1, sizeof(MyType)));
182  CHECKNULL((*Mod_fft)=(MyType *)calloc(nfft, sizeof(MyType)));
183 
184  #ifdef SIMPLE
185  CHECKNULL((*Out_fft)=(MyType *)fftwf_malloc(sizeof(MyType)*nfft));
186 
187  #ifdef PARFFTW
188  fftwf_init_threads();
189  #ifdef OMP
190  fftwf_plan_with_nthreads(omp_get_max_threads());
191  #else
192  fftwf_plan_with_nthreads(sysconf(_SC_NPROCESSORS_CONF));
193  #endif
194  #endif
195 
196  CHECKNULL((*plan)=fftwf_plan_r2r_1d(nfft, (*X_fft), (*Out_fft), FFTW_R2HC, FFTW_MEASURE));
197  #else
198  CHECKNULL((*Out_fft)=(MyType *)fftw_malloc(sizeof(MyType)*nfft));
199 
200  #ifdef PARFFTW
201  fftw_init_threads();
202  #ifdef OMP
203  fftw_plan_with_nthreads(omp_get_max_threads());
204  #else
205  fftw_plan_with_nthreads(sysconf(_SC_NPROCESSORS_CONF));
206  #endif
207  #endif
208 
209  CHECKNULL((*plan)= fftw_plan_r2r_1d(nfft, (*X_fft), (*Out_fft), FFTW_R2HC, FFTW_MEASURE));
210  #endif
211 
212  CHECKERR(ReadVectorInt64(kmax_fft, N_MIDI, NameFiles.file_kmax));
213  CHECKERR(ReadVectorInt64(kmin_fft, N_MIDI, NameFiles.file_kmin));
214 
215  return OK;
216 }
217 
218 
231 int AllocS_fkCPU(MyType **s_fk, MyType **tauxi, MyType **ts_fk, const MyType BETA, const int nmidi,
232  const int nbases, DTWfiles NameFiles)
233 {
234  int i;
235 
236  CHECKNULL((*s_fk)=(MyType *)calloc(nmidi*nbases, sizeof(MyType)));
237 
238  CHECKERR(ReadS_fk((*s_fk), nbases, NameFiles.file_partitura));
239 
240  if (!(BETA>=(MyType)0.0 && BETA<=(MyType)0.0) && !(BETA>=(MyType)1.0 && BETA<=(MyType)1.0))
241  {
242  CHECKNULL((*tauxi)=(MyType *)calloc(nmidi, sizeof(MyType)));
243  CHECKNULL((*ts_fk)=(MyType *)calloc(nmidi*nbases, sizeof(MyType)));
244 
245  #ifdef OMP
246  #pragma omp parallel for
247  #endif
248  for (i=0; i<nmidi*nbases; i++)
249  #ifdef SIMPLE
250  (*ts_fk)[i]=powf((*s_fk)[i], BETA-1.0f);
251  #else
252  (*ts_fk)[i]= pow((*s_fk)[i], BETA-1.0);
253  #endif
254  }
255 
256  return OK;
257 }
258 
259 
270 int AllocDTWCPU(MyType **pV, MyType **v_SxD, const int DTWSize, const int DTWSizePlusPad, const int startin)
271 {
272  int i;
273 
274  CHECKNULL((*pV) =(MyType *)malloc(sizeof(MyType)*DTWSizePlusPad));
275  CHECKNULL((*v_SxD)=(MyType *)calloc(DTWSize, sizeof(MyType)));
276 
277  for (i=0; i<DTWSizePlusPad; i++)
278  #ifdef SIMPLE
279  (*pV)[i]=FLT_MAX;
280  #else
281  (*pV)[i]=DBL_MAX;
282  #endif
283 
284  /* Where we start to store data within circular-buffer */
285  i = startin % TBLOCK;
286  if (i==0)
287  (*pV)[DTWSizePlusPad-DTWSize] = 0.0;
288  else
289  (*pV)[i*(DTWSize + N_COSTS) - DTWSize] = 0.0;
290 
291  return OK;
292 }
293 
294 
310 int AllocDataCPU(MyType **v_hanning, int **states_time_i, int **states_time_e, int **states_seq, int **states_corr,
311  int **I_SxD, int *DTWSize, const int tamframe, const int nstates, DTWfiles NameFiles)
312 {
313  int
314  i, j, pos;
315 
316  CHECKNULL((*v_hanning) =(MyType *)calloc(tamframe, sizeof(MyType)));
317  CHECKNULL((*states_time_i)= (int *)calloc(nstates, sizeof(int)));
318  CHECKNULL((*states_time_e)= (int *)calloc(nstates, sizeof(int)));
319  CHECKNULL((*states_seq) = (int *)calloc(nstates, sizeof(int)));
320  CHECKNULL((*states_corr) = (int *)calloc(nstates, sizeof(int)));
321 
322  CHECKERR( ReadVector((*v_hanning), tamframe, NameFiles.file_hanning));
323  CHECKERR(ReadVectorInt64((*states_seq), nstates, NameFiles.fileStates_seq));
324  CHECKERR(ReadVectorInt64((*states_time_i), nstates, NameFiles.fileStates_Time_i));
325  CHECKERR(ReadVectorInt64((*states_time_e), nstates, NameFiles.fileStates_Time_e));
326  CHECKERR(ReadVectorInt64((*states_corr), nstates, NameFiles.fileStates_corr));
327 
328  (*DTWSize) = (*states_time_e)[nstates - 1] + 1;
329 
330  CHECKNULL((*I_SxD)=(int *)calloc((*DTWSize), sizeof(int)));
331 
332  pos=0;
333  for (i=0; i<nstates; i++)
334  for (j=(*states_time_i)[i]; j<=(*states_time_e)[i]; j++)
335  {
336  (*I_SxD)[pos]=(*states_seq)[i];
337  pos++;
338  }
339  return OK;
340 }
341 
356 void FFT(MyType *v_cfreq, const int *kmin, const int *kmax, MyType *X_fft, MyType *Mod_fft,
357  MyType *Out_fft, MyFFTCPUType plan, const int nfft, const int nmidi)
358 {
359  int i;
360 
361  #ifdef SIMPLE
362  fftwf_execute(plan);
363  #else
364  fftw_execute(plan);
365  #endif
366 
367  Mod_fft[0] = Out_fft[0] * Out_fft[0];
368  Mod_fft[nfft/2]= Out_fft[nfft/2]* Out_fft[nfft/2];
369 
370  #ifdef OMP
371  #pragma omp parallel for
372  #endif
373  for(i=1; i<nfft/2; i++)
374  Mod_fft[i]=Out_fft[i]*Out_fft[i] + Out_fft[nfft-i]*Out_fft[nfft-i];
375 
376  #ifdef CBLAS
377  for(i=0;i<nmidi;i++)
378  #ifdef SIMPLE
379  v_cfreq[i]=sqrtf(cblas_sasum(kmax[i]-kmin[i]+1, &Mod_fft[kmin[i]], 1));
380  #else
381  v_cfreq[i]= sqrt(cblas_dasum(kmax[i]-kmin[i]+1, &Mod_fft[kmin[i]], 1));
382  #endif
383  #else
384  #ifdef OMP
385  #pragma omp parallel for
386  #endif
387  for(i=0;i<nmidi;i++)
388  {
389  int j;
390  MyType value;
391 
392  value=0.0;
393  for(j=kmin[i];j<=kmax[i];j++) value+=Mod_fft[j];
394 
395  #ifdef SIMPLE
396  v_cfreq[i]=sqrtf(value);
397  #else
398  v_cfreq[i]= sqrt(value);
399  #endif
400  }
401  #endif
402 }
403 
404 
405 #ifdef OMP
406 
413 int ParIdamin(const int N, const MyType *v)
414 {
415  int i;
416 
417  #ifdef OMP4
418  PosMin data ={DBL_MAX, 0};
419 
420  #pragma omp parallel for reduction(MIN: data)
421  for (i=0; i<N; i++)
422  if (v[i] < data.val) { data.val=v[i]; data.pos=i; }
423 
424  return data.pos;
425  #else
426  int pos_min = 0;
427  MyType val_min = v[0];
428 
429  #pragma omp parallel
430  {
431  int pos=1;
432  #ifdef SIMPLE
433  MyType val = FLT_MAX;
434  #else
435  MyType val = DBL_MAX;
436  #endif
437 
438  #pragma omp for nowait
439  for(i=1; i<N; i++)
440  if (v[i]<val) { val=v[i]; pos=i; }
441 
442  #pragma omp critical (ZonaCritica1)
443  {
444  if (val < val_min) { val_min=val; pos_min=pos; }
445  else if ((val==val_min) && (pos < pos_min)) pos_min=pos;
446  }
447  }
448  return pos_min;
449  #endif
450 }
451 #endif
452 
453 
462 int SeqIdamin(const int N, const MyType *v)
463 {
464  int i, pos=0;
465  MyType val=v[0];
466 
467  for(i=1; i<N; i++)
468  if (v[i]<val) { pos=i; val=v[i]; }
469 
470  return pos;
471 }
472 
473 
485 int DTWProc(const MyType *Sequence, const MyType *Costs, MyType * __restrict pD, const int NSeq, const int Where, const int NST)
486 {
487  int NSTplusNC, Ref_Pos, j;
488 
489  /* Some auxilar varibles */
490  NSTplusNC = N_COSTS + NST;
491  Ref_Pos = ((NSeq + N_COSTS) % TBLOCK) * NSTplusNC + N_COSTS - 1;
492 
493  #ifdef OMP
494  #pragma omp parallel for
495  #endif
496  for(j=0; j<NST; j++)
497  {
498  MyType d, d2;
499  int k, Pos;
500 
501  #ifdef SIMPLE
502  d=FLT_MAX;
503  #else
504  d=DBL_MAX;
505  #endif
506 
507  Pos=Ref_Pos + j;
508 
509  for(k=0; k<N_COSTS; k++)
510  {
511  d2 = Sequence[j]*Costs[k]+pD[Pos-k];
512  if (d2 < d) d=d2;
513  }
514 
515  for (k=N_COSTS; k<T_COSTS; k++)
516  {
517  Pos=((NSeq + (T_COSTS-k)) % TBLOCK) * NSTplusNC + N_COSTS + j - 1;
518 
519  d2 = Sequence[j]*Costs[k]+pD[Pos];
520 
521  if (d2 < d) d=d2;
522  }
523 
524  pD[Where+j] = d;
525  }
526  #ifdef OMP
527  j = ParIdamin(NST, &pD[Where]);
528  #else
529  j = SeqIdamin(NST, &pD[Where]);
530  #endif
531 
532  #ifdef TALK
533  //printf("\t\tAt %d frame the postion of the minimum is %d\n", NSeq, j);
534  #endif
535 
536  return j;
537 }
538 
539 
550 void ApplyDist(const MyType *v_dxState, MyType *v_SxD, const int *I_SxD, const int size, const MyType ALPHA)
551 {
552  int i;
553 
554  MyType vnorm=(MyType)0.0;
555 
556  #ifdef OMP
557  #pragma omp parallel for reduction(+: vnorm)
558  #endif
559  for(i=0; i<size; i++)
560  {
561  v_SxD[i] = v_dxState[I_SxD[i]];
562  vnorm += (v_SxD[i]*v_SxD[i]);
563  }
564  #ifdef SIMPLE
565  vnorm = 1.0f / (sqrtf(vnorm) + FLT_EPSILON);
566 
567  /* ALPHA is defined as (-1.0)*ALPHA in function ReadParameters */
568  #ifdef OMP
569  #pragma omp parallel for
570  #endif
571  for(i=0;i<size;i++)
572  v_SxD[i] = 1.0f - expf(ALPHA*fabsf(v_SxD[i]*vnorm));
573  #else
574  vnorm = 1.0 / (sqrt(vnorm) + DBL_EPSILON);
575 
576  /* ALPHA is defined as (-1.0)*ALPHA in function ReadParameters */
577  #ifdef OMP
578  #pragma omp parallel for
579  #endif
580  for(i=0;i<size;i++)
581  v_SxD[i] = 1.0 - exp(ALPHA*fabs(v_SxD[i]*vnorm));
582  #endif
583 }
584 
585 
600 void ComputeDist(const MyType *v_cfreq, MyType * __restrict v_dxStates, MyType *tauxi,
601  const MyType *norms, const MyType *s_fk, const MyType *ts_fk, const MyType BETA,
602  const int nbases, const int nmidi)
603 {
604  int i;
605 
606  if (BETA>=(MyType)0.0 && BETA<=(MyType)0.0)
607  {
608  #ifdef OMP
609  #pragma omp parallel for
610  #endif
611  for (i=0;i<nbases;i++)
612  {
613  int j, itmp;
614  MyType A_kt, dsum, dtmp;
615 
616  itmp = i * N_MIDI_PAD;
617  A_kt = (MyType)0.0;
618  dsum = (MyType)0.0;
619 
620  /* BETA=0 --> a^(BETA-1) = a^-1 = 1/a */
621  for (j=0; j<nmidi; j++)
622  A_kt += v_cfreq[j] / s_fk[itmp+j];
623  A_kt = A_kt / norms[i];
624 
625  for (j=0;j<nmidi;j++)
626  {
627  dtmp = v_cfreq[j] / (s_fk[itmp+j] * A_kt);
628  #ifdef SIMPLE
629  dsum += dtmp - logf(dtmp) - 1.0f;
630  #else
631  dsum += dtmp - log(dtmp) - 1.0;
632  #endif
633  }
634  v_dxStates[i] = dsum;
635  }
636  }
637  else if (BETA>=(MyType)1.0 && BETA<=(MyType)1.0)
638  {
639  MyType A_kt=(MyType)0.0;
640 
641  /* BETA=1 --> a^(BETA-1) = a^0 = 1 due to a>=0. So next inner-loop */
642  /* is moved here (out) because it not depend on index i, is always */
643  /* the same result/operation/value */
644  #ifdef CBLAS
645  #ifdef SIMPLE
646  A_kt=cblas_sasum(nmidi, v_cfreq, 1);
647  #else
648  A_kt=cblas_dasum(nmidi, v_cfreq, 1);
649  #endif
650  #else
651  for (i=0; i<nmidi; i++) { A_kt += v_cfreq[i]; }
652  #endif
653 
654  #ifdef OMP
655  #pragma omp parallel for
656  #endif
657  for (i=0;i<nbases;i++)
658  {
659  int itmp, j;
660  MyType dsum, dtmp, dtmp2, dtmp3;
661 
662  itmp = i * N_MIDI_PAD;
663  dsum = (MyType)0.0;
664  dtmp2 = A_kt / norms[i];
665 
666  for (j=0;j<nmidi;j++)
667  {
668  dtmp = s_fk[itmp+j] * dtmp2;
669  dtmp3= v_cfreq[j];
670  #ifdef SIMPLE
671  dsum += dtmp3*logf(dtmp3/dtmp) + dtmp - dtmp3;
672  #else
673  dsum += dtmp3* log(dtmp3/dtmp) + dtmp - dtmp3;
674  #endif
675  }
676  v_dxStates[i] = dsum;
677  }
678  }
679  else
680  {
681  MyType
682  BetaMinusOne=BETA-(MyType)1.0,
683  dConst=(MyType)1.0/(BETA*(BETA-(MyType)1.0));
684 
685  for (i=0; i<nmidi; i++)
686  #ifdef SIMPLE
687  tauxi[i]=powf(v_cfreq[i], BETA);
688  #else
689  tauxi[i]= pow(v_cfreq[i], BETA);
690  #endif
691 
692  #ifdef OMP
693  #pragma omp parallel for
694  #endif
695  for (i=0;i<nbases;i++)
696  {
697  int j, itmp;
698  MyType A_kt, dsum, dtmp, dtmp2, dtmp3;
699 
700  itmp = i * N_MIDI_PAD;
701  A_kt = (MyType)0.0;
702  dsum = (MyType)0.0;
703 
704  #ifdef CBLAS
705  #ifdef SIMPLE
706  A_kt =cblas_sdot(nmidi, v_cfreq, 1, &ts_fk[itmp], 1) / norms[i];
707  dtmp3=powf(A_kt, BetaMinusOne);
708  #else
709  A_kt =cblas_ddot(nmidi, v_cfreq, 1, &ts_fk[itmp], 1) / norms[i];
710  dtmp3=pow(A_kt,BetaMinusOne);
711  #endif
712  #else
713  for (j=0; j<nmidi; j++)
714  A_kt += v_cfreq[j] * ts_fk[itmp+j];
715  A_kt = A_kt / norms[i];
716  #ifdef SIMPLE
717  dtmp3=powf(A_kt, BetaMinusOne);
718  #else
719  dtmp3= pow(A_kt, BetaMinusOne);
720  #endif
721  #endif
722 
723  for (j=0;j<nmidi;j++)
724  {
725  dtmp = s_fk[itmp+j] * A_kt;
726  dtmp2 = ts_fk[itmp+j] * dtmp3;
727  dsum += (tauxi[j] + BetaMinusOne*dtmp2*dtmp - BETA*v_cfreq[j]*dtmp2)*dConst;
728  }
729  v_dxStates[i] = dsum;
730  }
731  }
732 }
733 
734 
742 int ReadWavCPU1st(short *frame, FILE *fp)
743 {
744  if (fread(&frame[TAMMUESTRA], sizeof(short), TTminusTM, fp) != TTminusTM)
745  return ErrReadFile;
746  return OK;
747 }
748 
756 int ReadWavCPU(short *frame, FILE *fp)
757 {
758  memmove(frame, &frame[TAMMUESTRA], sizeof(short)*TTminusTM);
759  if (fread(&frame[TTminusTM], sizeof(short), TAMMUESTRA, fp) != TAMMUESTRA) return ErrReadFile;
760  return OK;
761 }
762 
763 
764 #ifdef ALSA
765 
774  int ReadAlsaCPU1st(short *frame, snd_pcm_t *DeviceID, FILE *fpdump)
775  {
776  if (snd_pcm_readi(DeviceID, &frame[TAMMUESTRA], TTminusTM) != TTminusTM) return ErrReadDevice;
777 
778  #ifdef DUMP
779  if (fwrite(&frame[TAMMUESTRA], sizeof(short), TTminusTM, fpdump) != TTminusTM) return ErrWriteFile;
780  #endif
781 
782  return OK;
783  }
784 
794  int ReadAlsaCPU(short *frame, snd_pcm_t *DeviceID, FILE *fpdump)
795  {
796  memmove(frame, &frame[TAMMUESTRA], sizeof(short)*TTminusTM);
797 
798  if (snd_pcm_readi(DeviceID, &frame[TTminusTM], TAMMUESTRA) != TAMMUESTRA) return ErrReadDevice;
799 
800  #ifdef DUMP
801  if (fwrite(&frame[TTminusTM], sizeof(short), TAMMUESTRA, fpdump) != TAMMUESTRA) return ErrWriteFile;
802  #endif
803 
804  return OK;
805  }
806 #endif
807 
808 
817 void BetaNorm(MyType *v_cfreq, const int nmidi, MyType BETA)
818 {
819  /* nmidi is small and this procedure is only used at the beginning, we do not spend time with openmp and blas */
820  int i;
821  MyType value = 0.0;
822 
823  if (BETA>=(MyType)0.0 && BETA<=(MyType)0.0)
824  /* function not defined. Changed to BETA=1.0 */
825  BETA=1.0;
826 
827  if (BETA>=(MyType)1.0 && BETA<=(MyType)1.0)
828  {
829  #ifdef OMP
830  #pragma omp parallel for reduction(+: value)
831  #endif
832  for(i=0; i<nmidi; i++)
833  value += v_cfreq[i];
834  }
835  else
836  {
837  #ifdef SIMPLE
838  #ifdef OMP
839  #pragma omp parallel for reduction(+: value)
840  #endif
841  for(i=0; i<nmidi; i++)
842  value += powf(v_cfreq[i], BETA);
843  value = powf(value, 1.0/BETA);
844  #else
845  #ifdef OMP
846  #pragma omp parallel for reduction(+: value)
847  #endif
848  for(i=0; i<nmidi; i++)
849  value += pow(v_cfreq[i], BETA);
850  value = pow(value, 1.0/BETA);
851  #endif
852  }
853 
854  #ifdef OMP
855  #pragma omp parallel for
856  #endif
857  for(i=0; i<nmidi; i++)
858  v_cfreq[i] = v_cfreq[i]/ value;
859 }
char * fileStates_Time_i
Definition: defines.h:237
Struct for store the name of input/verificaton files. Each composition needs a file with values for ...
Definition: defines.h:228
void ApplyDist(const MyType *v_dxState, MyType *v_SxD, const int *I_SxD, const int size, const MyType ALPHA)
ApplyDist applies distortion.
Definition: CPUFunctions.c:550
int AllocS_fkCPU(MyType **s_fk, MyType **tauxi, MyType **ts_fk, const MyType BETA, const int nmidi, const int nbases, DTWfiles NameFiles)
AllocS_fkCPU Allocates memory for S_fk vector, read its data from file and initializes other auxiliar...
Definition: CPUFunctions.c:231
int ReadWavCPU1st(short *frame, FILE *fp)
ReadWavCPU1st reads first audio (frame) from WAV file when ARM is used.
Definition: CPUFunctions.c:742
void BetaNorm(MyType *v_cfreq, const int nmidi, MyType BETA)
BetaNorm normalizes v_cfreq vector to have beta-norm 1.
Definition: CPUFunctions.c:817
int DTWProc(const MyType *Sequence, const MyType *Costs, MyType *__restrict pD, const int NSeq, const int Where, const int NST)
DTWProc performs the Online-DTW process for the current frame.
Definition: CPUFunctions.c:485
Header file with auxiliar functions using by ReMAS, both CPU and GPU.
int ReadVectorInt64(int *vector, const int size, const char *filename)
ReadVectorInt64 fills a int vector with the int64 info stores in a file.
int SeqIdamin(const int N, const MyType *v)
SeqIdamin returns the pos of the minimum in a vector.
Definition: CPUFunctions.c:462
int ReadVector(MyType *vector, const int size, const char *filename)
ReadVector fills a MyType vector with the MyType info stores in a file.
Header file for using ReMAS with CPU, both x86_64 and ARM.
int AllocDTWCPU(MyType **pV, MyType **v_SxD, const int DTWSize, const int DTWSizePlusPad, const int startin)
AllocDTWCPU Allocates memory for DTW vectors and initializes them.
Definition: CPUFunctions.c:270
char * file_kmax
Definition: defines.h:234
char * fileStates_corr
Definition: defines.h:239
void FFT(MyType *v_cfreq, const int *kmin, const int *kmax, MyType *X_fft, MyType *Mod_fft, MyType *Out_fft, MyFFTCPUType plan, const int nfft, const int nmidi)
FFT computes FFT and updates v_cfreq vector.
Definition: CPUFunctions.c:356
int ReadS_fk(MyType *s_fk, const int BASES, const char *filename)
ReadS_fk fills the vector s_fk with the info stores in a file.
int AllocFFTCPU(MyFFTCPUType *plan, MyType **X_fft, MyType **Out_fft, MyType **Mod_fft, int *kmin_fft, int *kmax_fft, const int nfft, DTWfiles NameFiles)
AllocFFTCPU Allocates memory for FFT vector and reads some fft information from files.
Definition: CPUFunctions.c:177
void ComputeNorms(MyType *norms, MyType *ts_fk, const MyType *s_fk, const int nmidi, const int nbases, const MyType beta)
ComputeNorms fills norms vector.
Definition: CPUFunctions.c:73
int ReadWavCPU(short *frame, FILE *fp)
ReadWavCPU reads current audio (frame) from WAV file when ARM is used.
Definition: CPUFunctions.c:756
int AllocDataCPU(MyType **v_hanning, int **states_time_i, int **states_time_e, int **states_seq, int **states_corr, int **I_SxD, int *DTWSize, const int tamframe, const int nstates, DTWfiles NameFiles)
AllocDataCPU creates and initializes some structures reading info from files.
Definition: CPUFunctions.c:310
char * fileStates_Time_e
Definition: defines.h:236
void ApplyWindow(MyType *__restrict X_fft, const short *frame, const MyType *v_hanning, const int framesize, const int xfftsize)
ApplyWindow applies hanning window to the current frame and store the result en vector X_fft...
Definition: CPUFunctions.c:48
int AllocAuxiCPU(MyType **norms, short **frame, MyType **v_cfreq, MyType **v_dxState, const int nbases, const int tamframe, const int nmidi)
AllocAuxiCPU Memory reservation for norms, frame, v_cfreq and v_dxState vectors.
Definition: CPUFunctions.c:152
char * fileStates_seq
Definition: defines.h:238
char * file_kmin
Definition: defines.h:235
char * file_partitura
Definition: defines.h:233
void ComputeDist(const MyType *v_cfreq, MyType *__restrict v_dxStates, MyType *tauxi, const MyType *norms, const MyType *s_fk, const MyType *ts_fk, const MyType BETA, const int nbases, const int nmidi)
ComputeDist computes distortion.
Definition: CPUFunctions.c:600
char * file_hanning
Definition: defines.h:231