Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am just copying this code in other guy coding with waveinopen function and the codes capturing audio from any input like microphone and it works fine.

here is the code
C++
#include <windows.h> 
#include <mmsystem.h>
#include <stdio.h>
#define SOUNDBUFF 65536;
#pragma comment(lib,"libwinmm.a")//this will make the linker links 
                                  //with this library
    WAVEFORMATEX wf;
    WAVEHDR whdr;
    HWAVEIN hWaveIn;
    HWAVEOUT hWaveOut;
    LPSTR lpData;
int main(void)
{
    char clpData[65536];
    lpData=clpData;
    wf.wFormatTag=WAVE_FORMAT_PCM;
    wf.nChannels=1;
    wf.nSamplesPerSec=8000;
    wf.nAvgBytesPerSec=wf.nSamplesPerSec;
    wf.nBlockAlign=1;
    wf.wBitsPerSample=8;
    wf.cbSize=0;
    waveInOpen((LPHWAVEIN)&hWaveIn,WAVE_MAPPER,&wf,0,0,CALLBACK_NULL);
     
    whdr.lpData = lpData;
    whdr.dwBufferLength = SOUNDBUFF;
    whdr.dwBytesRecorded = 0;
    whdr.dwFlags = 0L;
    whdr.dwLoops = 0L;
    waveInPrepareHeader(hWaveIn,&whdr,sizeof(whdr));
    waveInAddBuffer(hWaveIn,&whdr,sizeof(whdr));
    waveInStart(hWaveIn);
    int n=0;
    
    do {
    } while (!(whdr.dwFlags & WHDR_DONE));
    waveInUnprepareHeader((HWAVEIN)hWaveOut,&whdr,sizeof(whdr));
    waveInClose(hWaveIn);
    waveOutOpen(&hWaveOut,WAVE_MAPPER,&wf,0,0,CALLBACK_NULL);
    waveOutPrepareHeader(hWaveOut,&whdr,sizeof(whdr));
    waveOutWrite(hWaveOut,&whdr,sizeof(whdr));
    n=0;
    
    do {
    } while (!(whdr.dwFlags & WHDR_DONE));
    waveOutUnprepareHeader(hWaveOut,&whdr,sizeof(whdr));
    waveOutClose(hWaveOut);
    return 0;

}

But i am wondering how could i code the audio input and play at the same time?

any help would be appreciated thanks guys. =)
Posted
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900