Solved

Microphone input

Posted on 1997-09-14
5
841 Views
Last Modified: 2010-05-18
How do I receive microphone input using C++?
0
Comment
Question by:snkpilot
5 Comments
 
LVL 10

Expert Comment

by:RONSLOW
Comment Utility
I know of some C code that does this - I can point you to this if you like?
0
 
LVL 23

Expert Comment

by:chensu
Comment Utility
What platform? Win32, Win16? Do you want to record it or just get the signal?
0
 
LVL 2

Accepted Solution

by:
alexxx earned 25 total points
Comment Utility
Use wave in and mixer manager APIs, do something like that:

mixerOpen(...);   //open mixer device
mixerSetControlDetails(...);   //set microphone mixer control for recording

waveInOpen(...);   //open wave in device with callback to get recorded data
waveInPrepareBuffer(...);
waveInAddBuffer(...);
waveInStart(...);   //start recording

0
 

Author Comment

by:snkpilot
Comment Utility
Ronslow,
     alexxx's answer I think is going to do it for me but I
would always appreciate some more advice.  If you could point
me to the code that would be great.
0
 

Expert Comment

by:garethl
Comment Utility
the waveIn system is nice, and much more powerful, but that
means you have to use low level stuff. To do it under win32
the simlest way is to use mci:

(mciHandleError is at the end)

// first you open the device :
      MCIERROR ret;

      ret = mciSendString ("open new type waveaudio alias wavedev",NULL,0,NULL);
      mciHandleError ("open",ret);

// Then if you need too, you can set the info.
      ret = mciSendString ("set wavedev channels 1 samplespersec 11025 bitspersample 8 format tag pcm time format milliseconds",NULL,0,NULL);
      mciHandleError ("set",ret);

// Then you start recording
// say you want 400 ms of sound, the notify will be later.
      mciHandleError ("record",mciSendString ("record wavedev from 0 to 400 overwrite notify",NULL,0,hwnd));      

// Now when it is finished it will notify you :
// ( In a wndproc )
      case MM_MCINOTIFY:
          mciHandleError ("stop",mciSendString ("stop wavedev",NULL,0,NULL));
        break;

// And you can save it to disk
      mciHandleError ("save",mciSendString ("save wavedev c:\\temp\\1.wav ",NULL,0,NULL));

// To make it simple, there is this :
static void mciHandleError (char *cmd,MCIERROR ret)
{
      if (ret==0)
            return;

      char errorstr[101];
      char outstr[101];

      mciGetErrorString (ret,errorstr,100);

      sprintf (outstr,"[%s] %s",cmd,errorstr);

      MessageBox (hWndTruster,outstr,"ERROR",MB_ICONSTOP|MB_OK);
}

0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now