[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 850
  • Last Modified:

Microphone input

How do I receive microphone input using C++?
0
snkpilot
Asked:
snkpilot
1 Solution
 
RONSLOWCommented:
I know of some C code that does this - I can point you to this if you like?
0
 
chensuCommented:
What platform? Win32, Win16? Do you want to record it or just get the signal?
0
 
alexxxCommented:
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
 
snkpilotAuthor Commented:
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
 
garethlCommented:
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now