Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Microphone input

Posted on 1997-09-14
5
845 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
ID: 1169765
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
ID: 1169766
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
ID: 1169767
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
ID: 1169768
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
ID: 1169769
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

840 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