60 lines
2 KiB
C++
60 lines
2 KiB
C++
|
#include <cstdio>
|
||
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include "/usr/include/alsa/asoundlib.h"
|
||
|
|
||
|
int main() {
|
||
|
const int bufferSize = 4096 ;
|
||
|
short rightBuffer[bufferSize] ;
|
||
|
short leftBuffer[bufferSize] ;
|
||
|
short* bufs[2] ;
|
||
|
bufs[0] = rightBuffer ;
|
||
|
bufs[1] = leftBuffer ;
|
||
|
int err ;
|
||
|
|
||
|
/****** ATENTION ********/
|
||
|
snd_pcm_t* _capture_handle ;
|
||
|
/****** ATENTION ********/
|
||
|
snd_pcm_hw_params_t* hw_params ;
|
||
|
|
||
|
if ((err = snd_pcm_readn(_capture_handle, (void**) bufs, bufferSize)) != bufferSize) fprintf(stderr, "read from audio interface failed (%s)\n", snd_strerror(err)) ;
|
||
|
exit(1) ;
|
||
|
|
||
|
|
||
|
if ((err = snd_pcm_hw_params_malloc(&hw_params)) < 0) fprintf(stderr, "cannot allocate hardware parameter structure (%s)\n", snd_strerror(err)) ;
|
||
|
exit(1) ;
|
||
|
|
||
|
if ((err = snd_pcm_hw_params_any(_capture_handle, hw_params)) < 0) fprintf(stderr, "cannot initialize hardware parameter structure (%s)\n", snd_strerror(err)) ;
|
||
|
exit(1) ;
|
||
|
|
||
|
if ((err = snd_pcm_hw_params_set_access(_capture_handle, hw_params, SND_PCM_ACCESS_RW_NONINTERLEAVED)) < 0) fprintf(stderr, "cannot set access type (%s)\n", snd_strerror(err)) ;
|
||
|
exit(1) ;
|
||
|
|
||
|
if ((err = snd_pcm_hw_params_set_format(_capture_handle, hw_params, SND_PCM_FORMAT_S16_LE)) < 0) fprintf(stderr, "cannot set sample format (%s)\n", snd_strerror(err)) ;
|
||
|
exit(1) ;
|
||
|
|
||
|
|
||
|
int soundSamplingRate=44100 ;
|
||
|
|
||
|
|
||
|
if ((err = snd_pcm_hw_params_set_rate_near(_capture_handle, hw_params, &soundSamplingRate, 0)) < 0) fprintf(stderr, "cannot set sample rate (%s)\n", snd_strerror(err)) ;
|
||
|
exit(1) ;
|
||
|
|
||
|
if ((err = snd_pcm_hw_params_set_channels(_capture_handle, hw_params, 2)) < 0) fprintf(stderr, "cannot set channel count (%s)\n", snd_strerror(err)) ;
|
||
|
exit(1) ;
|
||
|
|
||
|
if ((err = snd_pcm_hw_params(_capture_handle, hw_params)) < 0) fprintf(stderr, "cannot set parameters (%s)\n", snd_strerror(err)) ;
|
||
|
exit(1) ;
|
||
|
|
||
|
snd_pcm_hw_params_free(hw_params) ;
|
||
|
|
||
|
if ((err = snd_pcm_prepare(_capture_handle)) < 0) fprintf(stderr, "cannot prepare audio interface for use (%s)\n", snd_strerror(err)) ;
|
||
|
exit(1) ;
|
||
|
|
||
|
/*
|
||
|
On obtient alors les echantillons avec:
|
||
|
*/
|
||
|
|
||
|
|
||
|
}
|