Click here to Skip to main content
15,896,118 members

how to code input audio signal using " mmsystem.h" waveinopen and playback the audio at the same time.

Fefifu Funk asked:

Open original thread
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. =)
Tags: Audio

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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