/* Driver de captura e manipulação do som*/ #include #include #include "audio_capture_driver.h" #include "analitic_tools.h" #include "neuralshooter.h" #define ERR_MSG #define N_BYTES 2 /* * Requisitos do driver: * - Tamanho do buffer * - buffer * - formato * - frequencia * - framesize */ typedef char SAMPLE_T; const snd_pcm_format_t format = SND_PCM_FORMAT_S16_LE; #define S_BUFFER 1000 static SAMPLE_T frameBuffer[ S_BUFFER ]; static snd_pcm_t* device_handle = NULL; static snd_pcm_uframes_t realFrameBufSize = 0; static UINT tm_period = 0; static snd_pcm_uframes_t size_period = 0; /* * Setting the capture device up! * @default values */ INT setup_device(){ const INT N_CHANNELS = 1; INT rc= 0; snd_pcm_uframes_t nframes = 32; UINT frequency = 16000; snd_pcm_uframes_t val = 0; UINT valp = 0; INT dir = 0; snd_pcm_hw_params_t *params; /* Open PCM device for recording (capture). */ rc = snd_pcm_open(&device_handle, "default", SND_PCM_STREAM_CAPTURE, 0); if (rc < 0) { #ifdef ERR_MSG fprintf(stderr,"unable to open pcm device: %s\n", snd_strerror(rc)); #endif exit(1); } /* Allocate a hardware parameters object. */ snd_pcm_hw_params_alloca(¶ms); /* Fill it in with default values. */ snd_pcm_hw_params_any(device_handle, params); /* Set the desired hardware parameters. */ /* Interleaved mode */ snd_pcm_hw_params_set_access(device_handle, params, SND_PCM_ACCESS_RW_INTERLEAVED); /* little-endian format */ snd_pcm_hw_params_set_format(device_handle, params, format); /* Two channels (stereo) */ snd_pcm_hw_params_set_channels(device_handle, params, N_CHANNELS); /* 16000 bits/second sampling rate */ snd_pcm_hw_params_set_rate_near(device_handle, params, &frequency, &dir); /* Set period size to 32 frames. */ snd_pcm_hw_params_set_period_size_near(device_handle, params, &nframes, &dir); /* Write the parameters to the driver */ rc = snd_pcm_hw_params(device_handle, params); if (rc < 0) { #ifdef ERR_MSG fprintf(stderr, "unable to set hw parameters: %s\n", snd_strerror(rc)); #endif exit(1); } val = nframes; /* Get period size to 32 frames */ snd_pcm_hw_params_get_period_size(params, &val, &dir); size_period = val; realFrameBufSize = val*N_BYTES; valp = frequency; snd_pcm_hw_params_get_period_time(params, &valp, &dir); tm_period = valp; return 0; } void save_buffer(SAMPLE_T buf[], INT tam){ FILE * f; INT i; f = fopen("samples.txt", "a"); if(f != NULL){ for(i=0;i=cicles){ ans = sim(resultBuf, cicles); if(ans >= 0.9) system("beep -f 880 -l 20"); else printf("OK \n"); i=0; } /* rc = write(1, frameBuffer, realFrameBufSize); if (rc != realFrameBufSize) fprintf(stderr, "short write: wrote %d bytes\n", rc); */ } //save_buffer(resultBuf, i); } int main(void){ setup_device(); start_capture(); return 0; }