Click here to Skip to main content
15,916,463 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Using c++ to write c++ Pin
Bob Stanneveld24-Oct-05 23:25
Bob Stanneveld24-Oct-05 23:25 
GeneralRe: Using c++ to write c++ Pin
Jordan C. Atlas25-Oct-05 5:06
Jordan C. Atlas25-Oct-05 5:06 
GeneralRe: Using c++ to write c++ Pin
Bob Stanneveld25-Oct-05 6:39
Bob Stanneveld25-Oct-05 6:39 
QuestionHelp needed for speech capture project! Pin
student_eng24-Oct-05 14:57
student_eng24-Oct-05 14:57 
AnswerRe: Help needed for speech capture project! Pin
Christian Graus24-Oct-05 15:28
protectorChristian Graus24-Oct-05 15:28 
GeneralRe: Help needed for speech capture project! Pin
student_eng24-Oct-05 15:31
student_eng24-Oct-05 15:31 
GeneralRe: Help needed for speech capture project! Pin
Christian Graus24-Oct-05 15:37
protectorChristian Graus24-Oct-05 15:37 
AnswerRe: Help needed for speech capture project! Pin
normanS24-Oct-05 20:24
normanS24-Oct-05 20:24 
I pulled the following lines from my C program, which captures video and audio, and saves it to a file.

I have an array of video and audio buffers, each 33.3 mSec (NTSC) or 40 mSec (PAL), and I capture to these in turn, wrapping round to the first when I finish the last buffer. When the user stops capture, the buffers can be stored as an AVI file with sound.

I have NOT done any audio output stuff, so I cannot give sample code there!

Use the code given below as hints - I found all of this on the MSDN CDs that came with Visual Studio 6. I have left out most of the error detection code.

// Check that we actually have an Audio input device<br />
uiNumWaveInDevices = waveInGetNumDevs();<br />
<br />
waveInGetDevCaps(0, &WaveInCaps, sizeof(WaveInCaps));  // I always use device 0<br />
<br />
// Check that the audio device supports 16-bit mono 11.025 kHz<br />
if (!(WaveInCaps.dwFormats & WAVE_FORMAT_1M16))<br />
	// Abort audio capture<br />
<br />
// Hard-code the wave format!<br />
AudioFormat.wFormatTag = WAVE_FORMAT_PCM;<br />
AudioFormat.nChannels = 1; // Mono<br />
AudioFormat.nSamplesPerSec = 11025; // 11.025 kHz<br />
AudioFormat.nBlockAlign = 2; // 2 bytes per sample<br />
AudioFormat.wBitsPerSample = 16; // 16 bits per sample<br />
AudioFormat.nAvgBytesPerSec = 11025 * 2; // obvious<br />
AudioFormat.cbSize = 0; // no additional data<br />
<br />
hAudioInDevice = NULL;<br />
<br />
// Open wave in device number 0<br />
uiReturn = waveInOpen(&hAudioInDevice, 0, &AudioFormat, 0, 0, CALLBACK_NULL);<br />
if (uiReturn != MMSYSERR_NOERROR)<br />
	// Abort audio capture<br />
<br />
uiAudioBufferMaxSize = AudioFormat.nSamplesPerSec * 	AudioFormat.nBlockAlign * AudioFormat.nChannels / 25;<br />
// 25 = number video & audio frames per second for PAL<br />
<br />
AudioHeader[uiCounter].lpData = GlobalLock(GlobalAlloc(GMEM_FIXED, uiAudioBufferMaxSize));<br />
<br />
for(uiCounter = 1; uiCounter<uiMaxNumOfFrames; uiCounter++)<br />
	pAudioDataBlock[uiCounter] = pAudioDataBlock[0] + uiCounter * uiAudioBufferMaxSize;<br />
<br />
// Prepare the buffers<br />
uiAudioBufferActualSize = uiAudioBufferMaxSize;<br />
for(uiCounter = 0; uiCounter<DEF_NumberAudioDeviceBuffers; uiCounter++)<br />
{<br />
	AudioHeader[uiCounter].dwBufferLength = uiAudioBufferActualSize;<br />
	AudioHeader[uiCounter].dwBytesRecorded = 0;<br />
	AudioHeader[uiCounter].dwUser = 0;<br />
	AudioHeader[uiCounter].dwFlags = 0;<br />
	AudioHeader[uiCounter].dwLoops = 0;<br />
	uiResult = waveInPrepareHeader(hAudioInDevice, &(AudioHeader[uiCounter]), sizeof(WAVEHDR));<br />
}<br />
<br />
// Start capture - initially queue about 5 audio buffers, to keep the audio capture busy if the<br />
// processor is busy on other stuff - I think this is handled by the audio hardware.<br />
<br />
// Queue the corresponding audio buffer<br />
for (i = 1 to 5)<br />
	waveInAddBuffer(hAudioInDevice, &(AudioHeader[uiNextIndexToQueue]), sizeof(WAVEHDR))<br />
<br />
// If this is the first audio buffer, start the waveIn device<br />
if (bThisIsFirstBuffer)<br />
	waveInStart(hAudioInDevice);<br />
<br />
// Now, in the main capture loop, wait for audio (and video) buffers to be ready<br />
<br />
while (!(AudioHeader[uiAudioNextIndexToProcess].dwFlags & WHDR_DONE))<br />
	;<br />
<br />
// Copy the completed device audio block to our program audio data storage area<br />
// The block which is ready to be saved is in<br />
// AudioHeader[uiAudioNextIndexToProcess]<br />
// and we need to copy uiAudioBufferActualSize bytes<br />
// to the memory pointed to by <br />
// pAudioDataBlock[uiNextIndexToProcess]<br />
<br />
memcpy(pAudioDataBlock[uiNextIndexToProcess], AudioHeader[uiAudioNextIndexToProcess].lpData, uiAudioBufferActualSize);<br />
 // You can process this with your algorithm<br />
<br />
// Queue the next audio buffer<br />
waveInAddBuffer(hAudioInDevice, &(AudioHeader[uiAudioNextIndexToQueue]), sizeof(WAVEHDR))<br />
// Don't queue any more if you are stopping capture, of course!<br />
<br />
//End of main capture loop<br />
<br />
// And when you have finished capturing, stop capture device<br />
waveInStop(hAudioInDevice);<br />
<br />
// Once all capture is finished (i.e. when closing the program), do clean-up<br />
// First UnPrepare the audio buffers<br />
for(uiCounter = 0; uiCounter<DEF_NumberAudioDeviceBuffers; uiCounter++)<br />
{<br />
	while (!(AudioHeader[uiCounter ].dwFlags & WHDR_DONE))<br />
		;<br />
	waveInUnprepareHeader(hAudioInDevice, &(AudioHeader[uiCounter]), sizeof(WAVEHDR)))<br />
	GlobalFree(GlobalHandle(AudioHeader[uiCounter].lpData));<br />
}<br />
<br />
GlobalFree(GlobalHandle(pAudioDataBlock[0]));<br />
<br />
GlobalFree(GlobalHandle(pAudioDataBlock));<br />
<br />
waveInClose(hAudioInDevice);

QuestionChunk data trasmfer between two thread. Pin
LeeeNN24-Oct-05 13:39
LeeeNN24-Oct-05 13:39 
AnswerRe: Chunk data trasmfer between two thread. Pin
PJ Arends24-Oct-05 15:17
professionalPJ Arends24-Oct-05 15:17 
GeneralRe: Chunk data trasmfer between two thread. Pin
LeeeNN24-Oct-05 15:51
LeeeNN24-Oct-05 15:51 
AnswerRe: Chunk data trasmfer between two thread. Pin
John R. Shaw24-Oct-05 18:32
John R. Shaw24-Oct-05 18:32 
GeneralRe: Chunk data trasmfer between two thread. Pin
LeeeNN25-Oct-05 8:01
LeeeNN25-Oct-05 8:01 
QuestionEvent Handling Pin
suezzz0024-Oct-05 12:42
suezzz0024-Oct-05 12:42 
AnswerRe: Event Handling Pin
khan++24-Oct-05 19:36
khan++24-Oct-05 19:36 
GeneralRe: Event Handling Pin
S. Senthil Kumar24-Oct-05 20:08
S. Senthil Kumar24-Oct-05 20:08 
GeneralRe: Event Handling Pin
khan++24-Oct-05 20:36
khan++24-Oct-05 20:36 
AnswerRe: Event Handling Pin
S. Senthil Kumar24-Oct-05 21:09
S. Senthil Kumar24-Oct-05 21:09 
Questiondrawing on mouse move Pin
Ann6624-Oct-05 11:37
sussAnn6624-Oct-05 11:37 
AnswerRe: drawing on mouse move Pin
Christian Graus24-Oct-05 12:42
protectorChristian Graus24-Oct-05 12:42 
AnswerRe: drawing on mouse move Pin
vikas amin24-Oct-05 19:53
vikas amin24-Oct-05 19:53 
QuestionGet the folder of current application Pin
ddmcr24-Oct-05 9:24
ddmcr24-Oct-05 9:24 
AnswerRe: Get the folder of current application Pin
Ghasrfakhri24-Oct-05 9:42
Ghasrfakhri24-Oct-05 9:42 
GeneralRe: Get the folder of current application Pin
ddmcr24-Oct-05 9:56
ddmcr24-Oct-05 9:56 
GeneralRe: Get the folder of current application Pin
Blake Miller24-Oct-05 12:17
Blake Miller24-Oct-05 12:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.