Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Microphone input

Posted on 1997-09-14
5
Medium Priority
?
849 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 50 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

636 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