1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
| #include <iostream>
#include "portaudio.h"
#include <vector>
#include<windows.h>
using namespace std;
struct pilote_parameters{
PaStream *stream;
unsigned long framesPerBuffer;
PaTime timestart;
int compteur;
};
#define SAMPLE_RATE 8000 //frequence d'echantillonage
#define SAMPLE_TYPE paInt16 //Type de codage de l'echantillon paInt16 16bit
#define FRAMES_PER_BUFFER 8 //8 pour tes avec la somme
static int CaptureDuSon( const void *inputBuffer, void *outputBuffer,unsigned long framesPerBuffer,
const PaStreamCallbackTimeInfo* timeInfo,
PaStreamCallbackFlags statusFlags, void *userData ){
PaTime a=0;
static int pass=1;
short int *t=(short int*)inputBuffer; // short int = lecture en 16 bit
pilote_parameters *param=(pilote_parameters*)userData;
for(int i=0; i<8;i++)
cout<<"tab"<<i+1<<" : "<<t[i]<<endl;
//ici je ferais ma fonction qui calcule, la frequence
return 0; // 0=paContinue: keeping processing
}
void portaudio()
{
PaError err;
PaStreamParameters inputParameters;
pilote_parameters param;
param.framesPerBuffer=FRAMES_PER_BUFFER;
param.compteur=0;
err = Pa_Initialize();
if( err != paNoError )
printf("PortAudio error: %s\n", Pa_GetErrorText( err ) );
inputParameters.channelCount = 1;
inputParameters.device = Pa_GetDefaultInputDevice();
inputParameters.hostApiSpecificStreamInfo = NULL;
inputParameters.sampleFormat = SAMPLE_TYPE;
inputParameters.suggestedLatency = Pa_GetDeviceInfo(Pa_GetDefaultInputDevice())->defaultLowInputLatency ;
// Ouverture du canal du port audio Open an audio I/O stream.
err = Pa_OpenStream( &(param.stream),
&inputParameters, // input
NULL, // no output
SAMPLE_RATE,
param.framesPerBuffer,
paNoFlag,
CaptureDuSon, /* this is your callback function */
¶m); /*This is a pointer that will be passed to
your callback*/
if( err != paNoError )
printf( "PortAudio error: %s\n", Pa_GetErrorText( err ) );
//param.timestart=Pa_GetStreamTime(param.stream);
printf("\ncommencer l'acquistion");
fflush(stdin);
err = Pa_StartStream( param.stream );
if( err != paNoError )
printf( "PortAudio error: %s\n", Pa_GetErrorText( err ) );
Sleep(100);
printf("\narreter l'acquistion");
err = Pa_StopStream( param.stream );
if( err != paNoError )
printf( "PortAudio error: %s\n", Pa_GetErrorText( err ) );
err = Pa_CloseStream( param.stream );
if( err != paNoError )
printf( "PortAudio error: %s\n", Pa_GetErrorText( err ) );
err = Pa_Terminate();
if( err != paNoError )
printf( "PortAudio error: %s\n", Pa_GetErrorText( err ) );
}
void main(){
portaudio();//ira calculer la frequence obtenue.
} |
Partager