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 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
// ********************************************************
// Déclaration des variables Globales
// ********************************************************
// Handle de la carte son
static HWAVEIN hwi = NULL;
// Structure pour les functions waveIn
static WAVEFORMATEX wfx;
static WAVEHDR wh[NB_BUFFER];
// Buffers de capture
static short Buffer[NB_BUFFER][TAILLE_BUFFER / 2], BufferTmp[TAILLE_BUFFER / 2] = {0};
int Enregistrement=0;
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int i;
Enregistrement = 1;
// On regarde s'il y a au moins une carte son
if ( waveInGetNumDevs() <= 0)
{
Memo3->Lines->Add("ERREUR\r\nIl n'y a pas de carte son");
}
else
{
Memo3->Lines->Add("OK\r\nCarte son détectée");
}
// Preparation des formats pour la carte son
wfx.wFormatTag = WAVE_FORMAT_PCM;
wfx.nChannels = 1; // Mono
wfx.nSamplesPerSec = 44100; // Frequence d'echantillonnage
wfx.wBitsPerSample = 16; // Dynamique
wfx.nBlockAlign = (wfx.nChannels * wfx.wBitsPerSample) / 8; // C'est MSDN qui l'a dit
wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign; // Ca aussi
// Ouverture de la carte son
if ( waveInOpen(&hwi, 0, &wfx, 0, 0, WAVE_MAPPED) != MMSYSERR_NOERROR )
{
Memo3->Lines->Add("ERREUR\r\nProblème a l'ouverture de la carte son");
}
else
{
Memo3->Lines->Add("OK\r\nCarte son ouverte");
}
// Pour chaque buffer
for(i=0; i<NB_BUFFER; i++)
{
// Preparation de la structure
wh[i].lpData = (char*)Buffer[i];
wh[i].dwBufferLength = TAILLE_BUFFER;
wh[i].dwBytesRecorded = 0;
wh[i].dwUser = 0;
wh[i].dwFlags = 0;
wh[i].dwLoops = 0;
wh[i].lpNext = 0;
wh[i].reserved = 0;
// Preparation des entetes
if ( waveInPrepareHeader(hwi, &wh[i], sizeof(wh[i])) == MMSYSERR_NOERROR)
{
Memo3->Lines->Add("OK\r\nPréparation des buffers ok");
}
else
{
Memo3->Lines->Add("ERREUR\r\nImpossible de préparer les buffers");
}
// Ajout
if ( waveInAddBuffer(hwi, &wh[i], sizeof(wh[i])) == MMSYSERR_NOERROR)
{
Memo3->Lines->Add("OK\r\nAjout des buffers");
}
else
{
Memo3->Lines->Add("ERREUR\r\nImpossible d'ajouter les buffers");
}
}
//commencer l'acquisition
if ( waveInStart(hwi) != MMSYSERR_NOERROR )
{
Memo3->Lines->Add("ERREUR\r\nProblème d'acquisition");
}
else
{
Memo3->Lines->Add("OK\r\nEn cours d'acquisition");
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Enregistrement=0;
//arréter l'acquisition
if ( waveInReset(hwi) != MMSYSERR_NOERROR )
{
Memo3->Lines->Add("ERREUR\r\nImpossible de reset la carte son");
}
else
{
Memo3->Lines->Add("OK\r\nReset de la carte son");
}
if ( waveInStop(hwi) != MMSYSERR_NOERROR )
{
Memo3->Lines->Add("ERREUR\r\nImpossible d'arréter l'acquisition");
}
else
{
Memo3->Lines->Add("OK\r\nAcquisition arréter");
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
int i = 0;
if ( Enregistrement == 1 )
{
for (i=0; i<NB_BUFFER; i++)
{
if ( wh[i].dwFlags == 3 ) //normalement if ( wh[i].dwFlags == WHDR_DONE )
{
Memo4->Lines->Add(wh[i].lpData);
wh[i].lpData="";
wh[i].dwFlags = 0;
waveInAddBuffer(hwi, &wh[i], sizeof(wh[i]));
}
}
}
}
//--------------------------------------------------------------------------- |
Partager