46 #pragma mark main function 55 int main(
int argc ,
char *argv[])
82 prob_silen = (MyType)0.75,
83 prob_audio = (MyType)0.25;
116 snd_pcm_t *SoundHandle=NULL;
117 snd_pcm_uframes_t SoundBufferSize;
122 RecorderStruct recorder = {0};
123 AudioQueueRef queue = {0};
128 lo_address DirOSC[MaxOSC];
134 STempoRL TEMPORL={.NextFrame=0, .PrevState=0, .AudioTimeAP[0]=0, .ScoreTimeAP[0]=0, .SynthSpeed=1.0,
135 .SoloSpeed=1.0, .SynthTime=0.0, .numap=1, .matched=1};
139 bool UseOSC=
false, UseMic=
false;
147 int i, j, NumTramas=0;
154 BETA=strtof(argv[1], NULL);
156 BETA=strtod(argv[1], NULL);
161 #if defined(ALSA) || defined(CAUDIO) 167 BETA=strtof(argv[1], NULL);
169 BETA=strtod(argv[1], NULL);
171 UseOSC=atoi(argv[3]);
172 UseMic=atoi(argv[4]);
175 printf(
"General usage: %s <BETA> <configuration file>\n", argv[0]);
176 printf(
" Example: %s 1.5 parametes.dat\n\n", argv[0]);
177 printf(
"Docker usage: %s <BETA> <configuration file> <OSC yes|no [1|0]> <Microphone yes|no [1|0]>\n", argv[0]);
178 printf(
" Example: %s 1.5 parametes.dat 1 1\n\n", argv[0]);
186 CHECKERR(
AllocDataCPU(&v_hanning, &states_time_i, &states_time_e, &states_seq, &states_corr, &I_SxD, &DTWSize, TAMTRAMA, Param.
N_STATES, NameFiles));
189 DTWSizePlusPad =(DTWSize + N_COSTS) * (N_COSTS + 1);
190 CHECKERR(
AllocDTWCPU(&pD, &v_SxD, DTWSize, DTWSizePlusPad, 1));
196 CHECKERR(
AllocFFTCPU(&plan, &X_fft, &Out_fft, &Mod_fft, kmin_fft, kmax_fft, N_FFT, NameFiles));
199 CHECKERR(
AllocAuxiCPU(&norms, &frame, &v_cfreq, &v_dxState, Param.
N_BASES, TAMTRAMA, N_MIDI));
211 CHECKNULL(preload=(
int *)calloc(DTWSize,
sizeof(
int)));
213 for (i=0; i<DTWSize; i++)
215 if (i > states_time_e[j]) j++;
222 for (i=0; i<Param.
NCliOSC; i++)
225 CHECKERR(lo_address_errno(DirOSC[i]=lo_address_new(Param.
HostIP[i], Param.
HostPort[i])));
236 SoundBufferSize=SetMicParams(&SoundHandle, Param);
237 if (SoundBufferSize <=0) CHECKERR(ErrAlsaHw);
240 CHECKNULL(fp=fopen(
"FramesMicRecorded.pcm",
"w"));
242 NumTramas = (Param.
Time_MIC * AlsaRate) / TAMMUESTRA;
244 CHECKNULL(fp=fopen(NameFiles.
file_frame,
"rb"));
247 NumTramas = (WavHeader.
num_samples - TAMTRAMA) / TAMMUESTRA;
253 ConfigureAndAllocAudioQueues(&recorder, &queue);
254 recorder.running = TRUE;
255 CheckError(AudioQueueStart(queue, NULL),
"AudioQueueStart failed");
258 CHECKNULL(fp=fopen(
"FramesMicRecorded.pcm",
"wb"));
260 NumTramas = (Param.
Time_MIC * AQRate) / TAMMUESTRA;
262 CHECKNULL(fp=fopen(NameFiles.
file_frame,
"rb"));
265 NumTramas = (WavHeader.
num_samples - TAMTRAMA) / TAMMUESTRA;
268 CHECKNULL(fp=fopen(NameFiles.
file_frame,
"rb"));
271 NumTramas = (WavHeader.
num_samples - TAMTRAMA) / TAMMUESTRA;
281 CHECKERR(ReadAlsaCPU1st(frame, SoundHandle, fp));
287 CHECKERR(ReadAudioQueue1st(frame, &recorder, fp));
296 printf(
"Listening ...\n");
304 CHECKERR(ReadAlsaCPU(frame, SoundHandle, fp));
310 CHECKERR(ReadAudioQueue(frame, &recorder, fp));
319 ApplyWindow(X_fft, frame, v_hanning, TAMTRAMA, N_FFT);
320 FFT (v_cfreq, kmin_fft, kmax_fft, X_fft, Mod_fft, Out_fft, plan, N_FFT, N_MIDI);
322 ComputeDist(v_cfreq, v_dxState, tauxi, norms, s_fk, ts_fk, BETA, Param.
N_BASES, N_MIDI);
323 Silence =
DetectSilence((v_dxState[1]-v_dxState[0]), &prob_silen, &prob_audio);
328 if (UseOSC)
for (i=0; i<Param.
NCliOSC; i++) { CHECKERR(SendPlay(DirOSC[i])); CHECKERR(SendTempo(DirOSC[i], 110)); }
332 time=omp_get_wtime();
336 for(i=1; i<=NumTramas; i++)
338 ApplyWindow(X_fft, frame, v_hanning, TAMTRAMA, N_FFT);
339 FFT (v_cfreq, kmin_fft, kmax_fft, X_fft, Mod_fft, Out_fft, plan, N_FFT, N_MIDI);
340 ComputeDist(v_cfreq, v_dxState, tauxi, norms, s_fk, ts_fk, BETA, Param.
N_BASES, N_MIDI);
344 DTWWhere=(i % TBLOCK) * (N_COSTS + DTWSize) + N_COSTS;
345 pos_min=
DTWProc(v_SxD, Costs, pD, i, DTWWhere, DTWSize);
348 printf(
"Frame %d, PosMin %d\n", i, pos_min);
356 CHECKERR(ComputeTempoOSCRL(&TEMPORL, i, pos_min, preload[pos_min], states_corr, DirOSC, Param.
NCliOSC));
361 ComputeTempoRL(&TEMPORL, i, pos_min, preload[pos_min], states_corr);
365 ComputeTempoRL(&TEMPORL, i, pos_min, preload[pos_min], states_corr);
368 #if !defined(ALSA) && !defined(CAUDIO) 376 CHECKERR(ReadAlsaCPU(frame, SoundHandle, fp));
382 CHECKERR(ReadAudioQueue(frame, &recorder, fp));
392 time=omp_get_wtime() - time;
393 printf(
"%f sec.\n", time);
399 for (i=0; i<Param.
NCliOSC; i++) { CHECKERR(SendTempo(DirOSC[i], 100)); CHECKERR(SendPlay(DirOSC[i])); }
410 CHECKERR(snd_pcm_close(SoundHandle));
411 }
else { fclose(fp); }
419 recorder.running = FALSE;
420 CheckError(AudioQueueStop(queue, TRUE),
"AudioQueueStop failed");
421 AudioQueueDispose(queue, TRUE);
422 }
else { fclose(fp); }
429 if (!(BETA>=(MyType)0.0 && BETA<=(MyType)0.0) && !(BETA>=(MyType)1.0 && BETA<=(MyType)1.0)) {
451 fftwf_destroy_plan(plan);
453 fftwf_cleanup_threads();
457 fftw_destroy_plan(plan);
459 fftw_cleanup_threads();
Struct for store the name of input/verificaton files. Each composition needs a file with values for ...
Struct for Compute tempos.
File with TEMPO and auxiliar functions using by ReMAS, both CPU and GPU.
File with sound (using ALSA) and auxiliar functions using by ReMAS, both CPU and GPU.
void ApplyDist(const MyType *v_dxState, MyType *v_SxD, const int *I_SxD, const int size, const MyType ALPHA)
ApplyDist applies distortion.
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...
int ReadWavCPU1st(short *frame, FILE *fp)
ReadWavCPU1st reads first audio (frame) from WAV file when ARM is used.
void BetaNorm(MyType *v_cfreq, const int nmidi, MyType BETA)
BetaNorm normalizes v_cfreq vector to have beta-norm 1.
int Read_WAVHeader(WAVHeader *, FILE *)
Read_WAVHeader reads header of a WAVE file, checks its compability and fill Header struct...
File with functions used by ReMAS, both CPU and GPU, for management communications.
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.
File with functions used by ReMAS, both CPU and GPU, for management the time.
Header file with auxiliar functions using by ReMAS, both CPU and GPU.
void FreeFiles(DTWfiles *NameFiles)
FreeFiles frees the reserved memory of a struct.
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.
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.
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.
void ComputeNorms(MyType *norms, MyType *ts_fk, const MyType *s_fk, const int nmidi, const int nbases, const MyType beta)
ComputeNorms fills norms vector.
void ComputeTempoRL(STempoRL *, int, int, int, int *)
ComputeTempoRL calculates tempo and controls synthesizer speed using linear regression.
int main(int argc, char *argv[])
main is the entry point to ReMAS, classical C main program.
bool DetectSilence(MyType, MyType *, MyType *)
DetectSilence checks whether audio (frame) is silence or audio.
int ReadParameters(DTWconst *Param, DTWfiles *NameFiles, const char *filename)
ReadParameters reads ReMAS global parameters from file.
int ReadWavCPU(short *frame, FILE *fp)
ReadWavCPU reads current audio (frame) from WAV file when ARM is used.
Struct for store global information of the problem. Each composition needs a file with values for th...
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.
File with sound (using CoreAudio) to access to default input audio, both CPU and GPU.
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...
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.
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.