ReMAS  1.5
Real-time Musical Accompaniment System
defines.h
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 */
35 #pragma once
36 
37 
38 #ifndef DATA_H
39 #define DATA_H
40 
41 
42 /* Problem constants */
43 #define N_MIDI 114 /* For now, N_MIDI = 114 */
44 #define N_MIDI_PAD 128 /* Para que esté alineado */
45 #define N_FFT 16384 /* For now, N_FFT = 16384 */
46 #define TAMTRAMA 5700 /* For now, TAMTRAMA = 10*TAMMUESTRA */
47 #define TAMMUESTRA 570 /* For now, TAMMUESTRA = 570 */
48 #define TTminusTM (TAMTRAMA-TAMMUESTRA)
49 
50 #define N_COSTS 4 /* For now 2 dimensins and 4 costs per dimension */
51 #define T_COSTS (2*N_COSTS-1) /* Thereby total number of costs used is this value */
52 #define TBLOCK (N_COSTS+1) /* another used derivate value */
53 
54 #define Scaling 0.000030517578125 /* This is 1/32768, scaling factor for conversion */
55 
56 /* GPU constants */
57 #define sizeWarp 32
58 #define maxThreads 512
59 #define maxBlocks 256
60 
61 /* Local types */
62 #ifdef SIMPLE
63  #define MyType float
64  #define MyFFTCPUType fftwf_plan
65 #else
66  #define MyType double
67  #define MyFFTCPUType fftw_plan
68 #endif
69 #define MyFFTGPUType cufftHandle
70 
71 #define WAVHeaderLength 44
72 
73 /* ALSA sound parameters configuration */
74 #ifdef ALSA
75  #define AlsaAccessMode SND_PCM_ACCESS_RW_INTERLEAVED /* Value 3 see /usr/include/alsa/pcm.h) */
76  #define AlsaChannels 1 /* Number of channels 1=mono */
77  #define AlsaRate 44100 /* Rate */
78  #define AlsaAccessFormat SND_PCM_FORMAT_S16_LE /* Signed 16 bit little endian */
79 #endif
80 
81 /* Apple Audio Queue parameters configuration */
82 #ifdef CAUDIO
83  #define AQRate 44100
84  #define AQBufferSize TAMMUESTRA
85  #define AQChannels 1
86  #define AQBitsPerChannel 16
87  #define kNumberRecordBuffers 4
88  #define MiddleBufferSize (TAMTRAMA*2)
89 #endif
90 
91 /* OSC */
92 #define MaxOSC 5 /* Maximum number of OSC clients supported */
93 
94 /* Tempo */
95 #define RunJumpTime 0.012925 /* 0.012925=(TAMMUESTRA / {AlsaRate or AQRate}), seconds */
96 #define TrainJumpTime 0.012925 /* This depends on traning, seconds */
97 #define DelayTimeMidi 1 /* Delay midi time for matching */
98 #define NUMAPMAX 12 /* Number of anchor points for tempo estimation */
99 #define NUMAPPAIRS (NUMAPMAX*(NUMAPMAX-1)/2) /* Number of AP pairs for tempo estimation */
100 
101 /* Silence detection */
102 #define HMMchange 0.20 /* change state probability */
103 #define HMMremain 0.80 /* 1-HMMchange */
104 
105 /* For check errors */
106 #define OK 0
107 #define ErrReadFile -1
108 #define ErrWriteFile -2
109 #define ErrInfoReaded -3
110 #define ErrGpuWrong -4
111 #define ErrFFTSched -5
112 #define ErrReadDevice -6
113 #define ErrSendOSC -7
114 #define ErrAlsaHw -8
115 #define ErrWavFormat -9
116 #define ErrNULL -10;
117 #define ErrTimer -11;
118 
119 #define CHECKERR(x) do { if((x)<0) { \
120  printf("Error %d calling %s line %d\n", x, __FILE__, __LINE__);\
121  return x;}} while(0)
122 
123 #define CHECKNULL(x) do { if((x)==NULL) { \
124  printf("NULL (when open file or memory allocation calling %s line %d\n", __FILE__, __LINE__);\
125  return ErrNULL;}} while(0)
126 
127 #define CUDAERR(x) do { if((x)!=cudaSuccess) { \
128  printf("CUDA error: %s : %s, line %d\n", cudaGetErrorString(x), __FILE__, __LINE__);\
129  return EXIT_FAILURE;}} while(0)
130 
131 #define CUBLASERR(x) do { if((x)!=CUBLAS_STATUS_SUCCESS) { \
132  printf("CUBLAS error: %s, line %d\n", __FILE__, __LINE__);\
133  return EXIT_FAILURE;}} while(0)
134 
135 #define CUFFTERR(x) do { if((x)!=CUFFT_SUCCESS) { \
136  printf("CUFFT error: %s, line %d\n", __FILE__, __LINE__);\
137  return EXIT_FAILURE;}} while(0)
138 
139 #ifndef min
140  #define min(x,y) ((x < y) ? x : y)
141 #endif
142 
143 #ifdef OMP4
144  #include <float.h>
145 
149  struct PosMin {
150  MyType val;
151  int pos;
152  };
153  typedef struct PosMin PosMin;
154 
155  #ifdef SIMPLE
156  #pragma omp declare reduction(MIN : PosMin : \
157  omp_out = ((omp_in.val < omp_out.val) || ((omp_in.val == omp_out.val) && (omp_in.pos < omp_out.pos))) ? omp_in : omp_out) \
158  initializer(omp_priv = { FLT_MAX, 0 })
159  #else
160  #pragma omp declare reduction(MIN : PosMin : \
161  omp_out = ((omp_in.val < omp_out.val) || ((omp_in.val == omp_out.val) && (omp_in.pos < omp_out.pos))) ? omp_in : omp_out) \
162  initializer(omp_priv = { DBL_MAX, 0 })
163  #endif
164 #endif
165 
190 struct DTWconst
191 {
192  int N_BASES;
193  int N_STATES;
194  MyType NoteLen;
195  MyType ALPHA;
196  int WAVorMIC;
197  char SoundID[32];
198  int Time_MIC;
199  int NCliOSC;
200  char HostIP[MaxOSC][16];
201  char HostPort[MaxOSC][5];
202 };
203 
228 struct DTWfiles
229 {
230  /* Files with input data for the problem */
231  char *file_hanning;
232  char *file_frame;
234  char *file_kmax;
235  char *file_kmin;
240 };
241 typedef struct DTWconst DTWconst;
242 typedef struct DTWfiles DTWfiles;
243 
251 struct WAVHeader
252 {
253  char riff[4];
254  unsigned int size;
255  char wave[4];
256  char fmt[4];
257  unsigned int fmt_length;
258  unsigned int format_type;
259  unsigned int channels;
260  unsigned int sample_rate;
261  unsigned int byte_rate;
262  unsigned int block_align;
263  unsigned int bits_per_sample;
264  char data_header[4];
265  unsigned int data_size;
266  long num_samples;
267  unsigned int bytes_per_sample;
268 };
269 typedef struct WAVHeader WAVHeader;
270 
271 
276 struct STempo
277 {
278  int MidiFrame;
279  int RealFrame;
280  int NextFrame;
281  int PrevState;
282  MyType SynthSpeed;
283  MyType SoloSpeed;
284  MyType SynthTime;
285 };
286 typedef struct STempo STempo;
287 
292 struct STempoRL
293 {
294  int NextFrame;
295  int PrevState;
296  int numap;
297  int matched;
298  int AudioTimeAP[NUMAPMAX];
299  int ScoreTimeAP[NUMAPMAX];
300  MyType SynthSpeed;
301  MyType SynthTime;
302  MyType SoloSpeed;
303 };
304 typedef struct STempoRL STempoRL;
305 
306 #endif
int NCliOSC
Definition: defines.h:199
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
Struct for Compute tempos.
Definition: defines.h:292
int N_BASES
Definition: defines.h:192
Struct for WAVE file header. WAV files definitions. Note that we only work with 1 channel...
Definition: defines.h:251
unsigned int format_type
Definition: defines.h:258
unsigned int byte_rate
Definition: defines.h:261
char * file_kmax
Definition: defines.h:234
int Time_MIC
Definition: defines.h:198
char * fileStates_corr
Definition: defines.h:239
unsigned int fmt_length
Definition: defines.h:257
int N_STATES
Definition: defines.h:193
long num_samples
Definition: defines.h:266
Struct for Compute tempos.
Definition: defines.h:276
unsigned int block_align
Definition: defines.h:262
unsigned int sample_rate
Definition: defines.h:260
unsigned int channels
Definition: defines.h:259
int WAVorMIC
Definition: defines.h:196
Struct for store global information of the problem. Each composition needs a file with values for th...
Definition: defines.h:190
char * fileStates_Time_e
Definition: defines.h:236
char * file_frame
Definition: defines.h:232
unsigned int size
Definition: defines.h:254
unsigned int bits_per_sample
Definition: defines.h:263
unsigned int data_size
Definition: defines.h:265
char * fileStates_seq
Definition: defines.h:238
char * file_kmin
Definition: defines.h:235
char * file_partitura
Definition: defines.h:233
unsigned int bytes_per_sample
Definition: defines.h:267
char * file_hanning
Definition: defines.h:231