Solved

Microphone input

Posted on 1997-09-14
5
847 Views
Last Modified: 2010-05-18
How do I receive microphone input using C++?
0
Comment
Question by:snkpilot
[X]
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
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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

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. …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

688 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