Hey there,
is there any recommendation for a library (c++, Win32, open source) to get the sound from a microphone?
Thanks
Hey there,
is there any recommendation for a library (c++, Win32, open source) to get the sound from a microphone?
Thanks
I found some code at CodeProject (standard warning: Please review every bit of code you take from CodeProject carefully! It's useful, but I often find horrifying bugs in samples I get there!). That should give you a good clue as to the APIs and how to start using them. From there you can Google for references and related topics.
Try having a look at OpenAL[1] it might be overkill, but should be able to record from microphone as you wanted. There exists some pretty good articles about it on Gamedev.net[2] although I'm afraid none of them tells you how to record from a microphone. You should however be able to find the answer for that in the documentation. :) good luck,
[1] http://connect.creativelabs.com/openal/default.aspx
[2] http://www.gamedev.net/reference/articles/article2008.asp
PortAudio - portable cross-platform Audio API
PortAudio provides a very simple API for recording and/or playing sound using a simple callback function.
If you don't need cross platform, DirectShow works well. Although it is not open source, I believe you can distribute open source projects that require the DirectShow libraries.
You don't say that you need cross platform support, if cross platform support isn't necessary, I'd use the wave APIs or DirectSound - both are fairly straighforward to use.
I have used the mci functions to record in the past. Sorry, this doesn't show making sure the microphone is selected as a recording input, but once its selected manually, it will stay unless somebody changes it. This was in a dialog, so thats what the windows handle came from.
#define ALIAS "mci_alias"
char mci_command[100];
char ReturnString[300];
int mci_error;
// open the device
sprintf(mci_command, "open new type waveaudio alias %s", ALIAS);
mci_err = mciSendString(mci_command, ReturnString, sizeof(ReturnString), m_hWnd);
// set the time format
sprintf(mci_command,"set %s time format ms", ALIAS); // just set time format
mci_err = mciSendString(mci_command, ReturnString, sizeof(ReturnString), m_hWnd);
// start the record. specify notifications with a MM_MCINOTIFY message)
sprintf(mci_command, "record %s notify", ALIAS);
mci_err = mciSendString(mci_command, ReturnString, sizeof(ReturnString), m_hWnd);
// wait for a stop button, or an error to occur
sprintf(mci_command,"stop %s", ALIAS);
mci_err = mciSendString(mci_command, ReturnString, sizeof(ReturnString), m_hWnd);
// save the file
sprintf(mci_command, "save %s %s", ALIAS, m_filename);
mci_err = mciSendString(mci_command, ReturnString, sizeof(ReturnString), m_hWnd);
sprintf(mci_command,"stop %s", ALIAS);
mci_err = mciSendString(mci_command, ReturnString, sizeof(ReturnString), m_hWnd);
// close the device
sprintf(mci_command,"close %s", ALIAS);
mci_err = mciSendString(mci_command, ReturnString, sizeof(ReturnString), m_hWnd);